private void _initJIT2() { if (isAdvancedDebugging()) { buildLog = new StringAppender(); } cw = new ClassWriter(ClassWriter.COMPUTE_MAXS + ClassWriter.COMPUTE_FRAMES); synchronized (Runtime.getRuntime()) { cw.visit(OPCODES_VERSION, Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER, className = "ASMAccessorImpl_" + valueOf(cw.hashCode()).replaceAll("\\-", "_") + (System.currentTimeMillis() / 10) + ((int) Math.random() * 100), null, "java/lang/Object", new String[]{NAMESPACE + "compiler/Accessor"}); } MethodVisitor m = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null); m.visitCode(); m.visitVarInsn(Opcodes.ALOAD, 0); m.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V"); m.visitInsn(RETURN); m.visitMaxs(1, 1); m.visitEnd(); (mv = cw.visitMethod(ACC_PUBLIC, "setValue", "(Ljava/lang/Object;Ljava/lang/Object;L" + NAMESPACE + "integration/VariableResolverFactory;Ljava/lang/Object;)Ljava/lang/Object;", null, null)).visitCode(); }
private byte[] dumpWriter(final Class< ? > originalClass, final String className, final Method getterMethod, final Class< ? > fieldType, final boolean isInterface) throws Exception { final ClassWriter cw = new ClassWriter( ClassWriter.COMPUTE_MAXS ); final Class< ? > superClass = getWriterSuperClassFor( fieldType ); buildClassHeader( superClass, className, cw ); build3ArgConstructor( superClass, className, cw ); buildSetMethod( originalClass, className, superClass, getterMethod, fieldType, cw ); cw.visitEnd(); return cw.toByteArray(); }
public void write(ClassGenerator cg, ClassWriter cw) { cw.visitField(access, name, desc, signature, value).visitEnd(); } }
/** * Adds the given "uninitialized" type to {@link #typeTable} and returns its * index. This method is used for UNINITIALIZED types, made of an internal * name and a bytecode offset. * * @param type the internal name to be added to the type table. * @param offset the bytecode offset of the NEW instruction that created * this UNINITIALIZED type value. * @return the index of this internal name in the type table. */ int addUninitializedType(final String type, final int offset) { key.type = TYPE_UNINIT; key.intVal = offset; key.strVal1 = type; key.hashCode = 0x7FFFFFFF & (TYPE_UNINIT + type.hashCode() + offset); Item result = get(key); if (result == null) { result = addType(key); } return result.index; }
/** * Returns the index of the common super type of the two given types. This * method calls {@link #getCommonSuperClass} and caches the result in the * {@link #items} hash table to speedup future calls with the same * parameters. * * @param type1 index of an internal name in {@link #typeTable}. * @param type2 index of an internal name in {@link #typeTable}. * @return the index of the common super type of the two given types. */ int getMergedType(final int type1, final int type2) { key2.type = TYPE_MERGED; key2.longVal = type1 | (((long) type2) << 32); key2.hashCode = 0x7FFFFFFF & (TYPE_MERGED + type1 + type2); Item result = get(key2); if (result == null) { String t = typeTable[type1].strVal1; String u = typeTable[type2].strVal1; key2.intVal = addType(getCommonSuperClass(t, u)); result = new Item((short) 0, key2); put(result); } return result.intVal; }
/** * Adds a field reference to the constant pool of the class being build. * Does nothing if the constant pool already contains a similar item. * * @param owner the internal name of the field's owner class. * @param name the field's name. * @param desc the field's descriptor. * @return a new or already existing field reference item. */ Item newFieldItem(final String owner, final String name, final String desc) { key3.set(FIELD, owner, name, desc); Item result = get(key3); if (result == null) { put122(FIELD, newClass(owner), newNameType(name, desc)); result = new Item(index++, key3); put(result); } return result; }
ClassWriter cw = new ClassWriter( ClassWriter.COMPUTE_MAXS ); FieldVisitor fv; MethodVisitor mv; cw.visit( V1_5, ACC_PUBLIC + ACC_SUPER, internalWrapper, Type.getDescriptor( Object.class ) + Type.getDescriptor( Map.class ) + Type.getDescriptor( MapWrapper.class ), new String[]{ Type.getInternalName( Map.class ), Type.getInternalName( MapWrapper.class ), Type.getInternalName( Serializable.class ) } ); cw.visitInnerClass( Type.getInternalName( Map.Entry.class ), Type.getInternalName( Map.class ), "Entry", ACC_PUBLIC + ACC_STATIC + ACC_ABSTRACT + ACC_INTERFACE ); fv = cw.visitField( 0, "object", descrCore, null, null ); fv.visitEnd(); fv = cw.visitField( 0, "map", Type.getDescriptor( Map.class ), "Ljava/util/Map<Ljava/lang/String;Ljava/lang/Object;>;", null ); fv.visitEnd(); mv = cw.visitMethod( ACC_PUBLIC, "<init>", "(" + descrCore + Type.getDescriptor( Map.class ) + ")V", "(" + descrCore + "Ljava/util/Map<Ljava/lang/String;Ljava/lang/Object;>;)V", cw.visitEnd(); return cw.toByteArray();
mv.visitEnd(); mv = cw.visitMethod(ACC_PUBLIC, "getKnownEgressType", "()Ljava/lang/Class;", null, null); mv.visitCode(); visitConstantClass(returnType); cw.visitField(ACC_PUBLIC, "nullPropertyHandler", "L" + NAMESPACE + "integration/PropertyHandler;", null, null).visitEnd(); cw.visitField(ACC_PUBLIC, "nullMethodHandler", "L" + NAMESPACE + "integration/PropertyHandler;", null, null).visitEnd(); mv = cw.visitMethod(ACC_PUBLIC, "toString", "()Ljava/lang/String;", null, null); mv.visitCode(); Label l0 = new Label(); cw.visitEnd();
cw.visitField(ACC_PRIVATE, "p" + i, "L" + NAMESPACE + "compiler/ExecutableStatement;", null, null).visitEnd(); MethodVisitor cv = cw.visitMethod(ACC_PUBLIC, "<init>", constSig.toString(), null, null); cv.visitCode(); assert debug("ALOAD 0");
ClassWriter cw = new ClassWriter( ClassWriter.COMPUTE_MAXS ); cw.visit( V1_5, ACC_PUBLIC + ACC_ABSTRACT + ACC_INTERFACE, cName, genericTypes, AnnotationVisitor av0 = cw.visitAnnotation( Type.getDescriptor( Trait.class ), true); List<AnnotationDefinition> annotations = classDef.getAnnotations(); if ( annotations != null && ! annotations.isEmpty() ) { cw.visitEnd(); } catch ( Exception e ) { e.printStackTrace(); return cw.toByteArray();
protected void buildGetter( ClassWriter cw, FieldDefinition field, String name, String type, String generic ) { name = name.substring( 0, 1 ).toUpperCase() + name.substring( 1 ); MethodVisitor mv = cw.visitMethod( ACC_PUBLIC + ACC_ABSTRACT, BuildUtils.getterName( name, type ), "()" + BuildUtils.getTypeDescriptor( type ), generic == null ? null : "()" + BuildUtils.getTypeDescriptor( type ).replace( ";", "<" + BuildUtils.getTypeDescriptor( generic ) + ">;" ), null ); mv.visitEnd(); }
public byte[] generateBytecode() { if (bytecode == null) { ClassWriter cw = new InternalClassWriter(classLoader, ClassWriter.COMPUTE_MAXS); cw.visit(version, access, getClassDescriptor(), signature, getSuperClassDescriptor(), toInteralNames(interfaces)); for (int i = 0; i < classParts.size(); i++) { // don't use iterator to allow method visits to add more class fields and methods classParts.get(i).write(this, cw); } if (staticInitializer != null) { staticInitializer.write(this, cw); } cw.visitEnd(); bytecode = cw.toByteArray(); if (DUMP_GENERATED_CLASSES) { dumpGeneratedClass(bytecode); } } return bytecode; }
/** * Adds an integer to the constant pool of the class being build. Does * nothing if the constant pool already contains a similar item. * * @param value the int value. * @return a new or already existing int item. */ Item newInteger(final int value) { key.set(value); Item result = get(key); if (result == null) { pool.putByte(INT).putInt(value); result = new Item(index++, key); put(result); } return result; }
/** * Adds a name and type to the constant pool of the class being build. Does * nothing if the constant pool already contains a similar item. <i>This * method is intended for {@link Attribute} sub classes, and is normally not * needed by class generators or adapters.</i> * * @param name a name. * @param desc a type descriptor. * @return the index of a new or already existing name and type item. */ public int newNameType(final String name, final String desc) { key2.set(NAME_TYPE, name, desc, null); Item result = get(key2); if (result == null) { put122(NAME_TYPE, newUTF8(name), newUTF8(desc)); result = new Item(index++, key2); put(result); } return result.index; }
++attributeCount; size += 8; newUTF8("Signature"); newUTF8("SourceFile"); newUTF8("SourceDebugExtension"); newUTF8("EnclosingMethod"); newUTF8("Deprecated"); ++attributeCount; size += 6; newUTF8("Synthetic"); newUTF8("InnerClasses"); newUTF8("RuntimeVisibleAnnotations"); newUTF8("RuntimeInvisibleAnnotations"); out.putShort(newUTF8("Signature")).putInt(2).putShort(signature); out.putShort(newUTF8("SourceFile")).putInt(2).putShort(sourceFile); out.putShort(newUTF8("SourceDebugExtension")).putInt(len); out.putByteArray(sourceDebug.data, 2, len);
/** * Adds a string to the constant pool of the class being build. Does nothing * if the constant pool already contains a similar item. * * @param value the String value. * @return a new or already existing string item. */ private Item newString(final String value) { key2.set(STR, value, null, null); Item result = get(key2); if (result == null) { pool.put12(STR, newUTF8(value)); result = new Item(index++, key2); put(result); } return result; }
@Override public void endDocument() throws SAXException { try { os.write(cw.toByteArray()); } catch (IOException e) { throw new SAXException(e); } } };
public ASMAccessorOptimizer() { //do this to confirm we're running the correct version //otherwise should create a verification error in VM new ClassWriter(ClassWriter.COMPUTE_MAXS); }
/** * Builds the class header * * @param clazz The class to build the extractor for * @param className The extractor class name * @param cw */ protected void buildClassHeader(final Class< ? > superClass, final String className, final ClassWriter cw) { cw.visit( Opcodes.V1_5, Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER, className, null, Type.getInternalName( superClass ), null ); cw.visitSource( null, null ); }
if (local[i] instanceof String) { frame[frameIndex++] = Frame.OBJECT | cw.addType((String) local[i]); | cw.addUninitializedType("", ((Label) local[i]).position); if (stack[i] instanceof String) { frame[frameIndex++] = Frame.OBJECT | cw.addType((String) stack[i]); | cw.addUninitializedType("", ((Label) stack[i]).position);