List of usage examples for org.objectweb.asm Opcodes ACC_SYNTHETIC
int ACC_SYNTHETIC
To view the source code for org.objectweb.asm Opcodes ACC_SYNTHETIC.
Click Source Link
From source file:asm.FindCallers.java
License:Apache License
@Override public MethodVisitor visitMethod(int arg0, String arg1, String arg2, String arg3, String[] arg4) { if ((arg0 & Opcodes.ACC_BRIDGE) == Opcodes.ACC_BRIDGE && (arg0 & Opcodes.ACC_SYNTHETIC) == Opcodes.ACC_SYNTHETIC) { return null; }//ww w . java 2 s . c o m this.currentMethod = new Annotated(className, baseClass, arg1, arg2, (arg0 & Opcodes.ACC_PUBLIC) == Opcodes.ACC_PUBLIC); return super.visitMethod(arg0, arg1, arg2, arg3, arg4); }
From source file:br.ufpr.gres.core.MethodInfo.java
License:Apache License
public boolean isSynthetic() { return ((this.access & Opcodes.ACC_SYNTHETIC) != 0); }
From source file:co.cask.cdap.internal.io.DatumWriterGenerator.java
License:Apache License
/** * Generates the {@link DatumWriter#encode(Object, co.cask.cdap.common.io.Encoder)} method. * @param outputType Type information of the data type for output * @param schema Schema to use for output. */// w w w. j a va2s. c om private void generateEncode(TypeToken<?> outputType, Schema schema) { TypeToken<?> callOutputType = getCallTypeToken(outputType, schema); Method encodeMethod = getMethod(void.class, "encode", callOutputType.getRawType(), Encoder.class); if (!Object.class.equals(callOutputType.getRawType())) { // Generate the synthetic method for the bridging Method method = getMethod(void.class, "encode", Object.class, Encoder.class); GeneratorAdapter mg = new GeneratorAdapter( Opcodes.ACC_PUBLIC + Opcodes.ACC_BRIDGE + Opcodes.ACC_SYNTHETIC, method, null, new Type[] { Type.getType(IOException.class) }, classWriter); mg.loadThis(); mg.loadArg(0); mg.checkCast(Type.getType(callOutputType.getRawType())); mg.loadArg(1); mg.invokeVirtual(classType, encodeMethod); mg.returnValue(); mg.endMethod(); } // Generate the top level public encode method String methodSignature = null; if (callOutputType.getType() instanceof ParameterizedType) { methodSignature = Signatures.getMethodSignature(encodeMethod, callOutputType, null); } GeneratorAdapter mg = new GeneratorAdapter(Opcodes.ACC_PUBLIC, encodeMethod, methodSignature, new Type[] { Type.getType(IOException.class) }, classWriter); // Delegate to the actual encode method(value, encoder, schema, Sets.newIdentityHashSet()); mg.loadThis(); mg.loadArg(0); mg.loadArg(1); mg.loadThis(); mg.getField(classType, "schema", Type.getType(Schema.class)); // seenRefs Set mg.invokeStatic(Type.getType(Sets.class), getMethod(Set.class, "newIdentityHashSet")); mg.invokeVirtual(classType, getEncodeMethod(outputType, schema)); mg.returnValue(); mg.endMethod(); }
From source file:co.cask.tigon.internal.io.DatumWriterGenerator.java
License:Apache License
/** * Generates the {@link DatumWriter#encode(Object, co.cask.tigon.io.Encoder)} method. * @param outputType Type information of the data type for output * @param schema Schema to use for output. *//*from w w w. j a v a 2 s . c om*/ private void generateEncode(TypeToken<?> outputType, Schema schema) { TypeToken<?> callOutputType = getCallTypeToken(outputType, schema); Method encodeMethod = getMethod(void.class, "encode", callOutputType.getRawType(), Encoder.class); if (!Object.class.equals(callOutputType.getRawType())) { // Generate the synthetic method for the bridging Method method = getMethod(void.class, "encode", Object.class, Encoder.class); GeneratorAdapter mg = new GeneratorAdapter( Opcodes.ACC_PUBLIC + Opcodes.ACC_BRIDGE + Opcodes.ACC_SYNTHETIC, method, null, new Type[] { Type.getType(IOException.class) }, classWriter); mg.loadThis(); mg.loadArg(0); mg.checkCast(Type.getType(callOutputType.getRawType())); mg.loadArg(1); mg.invokeVirtual(classType, encodeMethod); mg.returnValue(); mg.endMethod(); } // Generate the top level public encode method String methodSignature = null; if (callOutputType.getType() instanceof ParameterizedType) { methodSignature = Signatures.getMethodSignature(encodeMethod, new TypeToken[] { callOutputType, null }); } GeneratorAdapter mg = new GeneratorAdapter(Opcodes.ACC_PUBLIC, encodeMethod, methodSignature, new Type[] { Type.getType(IOException.class) }, classWriter); // Delegate to the actual encode method(value, encoder, schema, Sets.newIdentityHashSet()); mg.loadThis(); mg.loadArg(0); mg.loadArg(1); mg.loadThis(); mg.getField(classType, "schema", Type.getType(Schema.class)); // seenRefs Set mg.invokeStatic(Type.getType(Sets.class), getMethod(Set.class, "newIdentityHashSet")); mg.invokeVirtual(classType, getEncodeMethod(outputType, schema)); mg.returnValue(); mg.endMethod(); }
From source file:com.alibaba.hotswap.processor.constructor.ConstructorVisitor.java
License:Open Source License
private void addEmptyUniformConstructor() { int access = Opcodes.ACC_PUBLIC + Opcodes.ACC_SYNTHETIC; String name = HotswapConstants.INIT; String desc = HotswapConstants.UNIFORM_CONSTRUCTOR_DESC; MethodVisitor hotswapInit = cv.visitMethod(access, name, desc, null, null); GeneratorAdapter hotswapInitAdapter = new GeneratorAdapter(hotswapInit, access, name, desc); hotswapInitAdapter.visitCode();/* w w w . jav a 2 s . co m*/ hotswapInitAdapter.push(this.className); hotswapInitAdapter.loadArg(1); hotswapInitAdapter.invokeStatic(Type.getType(HotswapMethodUtil.class), Method.getMethod("Throwable noSuchMethodError(String, int)")); hotswapInitAdapter.throwException(); hotswapInitAdapter.endMethod(); }
From source file:com.alibaba.hotswap.processor.constructor.ConstructorVisitor.java
License:Open Source License
@SuppressWarnings({ "unchecked" }) private void addUniformConstructor(ClassMeta classMeta) { int access = Opcodes.ACC_PUBLIC + Opcodes.ACC_SYNTHETIC; String name = HotswapConstants.INIT; String desc = HotswapConstants.UNIFORM_CONSTRUCTOR_DESC; MethodVisitor hotswapInit = new ConstructorInvokeModifier(cv.visitMethod(access, name, desc, null, null), access, name, desc);/*from w w w . j ava2s. c o m*/ GeneratorAdapter hotswapInitAdapter = new GeneratorAdapter(hotswapInit, access, name, desc); hotswapInitAdapter.visitCode(); TreeMap<MethodMeta, MethodNode> initMethodMap = new TreeMap<MethodMeta, MethodNode>( new ConstructorIndexComparator()); for (MethodNode node : initNodes.values()) { MethodMeta meta = new MethodMeta(node.access, node.name, node.desc, node.signature, ((String[]) node.exceptions.toArray(new String[node.exceptions.size()]))); meta.setIndex(HotswapMethodIndexHolder.getMethodIndex(className, node.name, node.desc)); classMeta.refreshInitMeta(meta, true); initMethodMap.put(meta, node); } List<MethodMeta> keys = new ArrayList<MethodMeta>(initMethodMap.keySet()); List<MethodNode> values = new ArrayList<MethodNode>(initMethodMap.values()); Label defaultLabel = new Label(); int[] indexes = new int[keys.size()]; Label[] labels = new Label[keys.size()]; for (int i = 0; i < keys.size(); i++) { indexes[i] = keys.get(i).getIndex(); labels[i] = new Label(); } for (int i = 0; i < values.size(); i++) { MethodNode node = values.get(i); for (int j = 0; j < node.tryCatchBlocks.size(); j++) { ((TryCatchBlockNode) node.tryCatchBlocks.get(j)).accept(hotswapInitAdapter); } } hotswapInitAdapter.loadArg(1); hotswapInitAdapter.visitLookupSwitchInsn(defaultLabel, indexes, labels); for (int i = 0; i < keys.size(); i++) { MethodMeta methodMeta = keys.get(i); hotswapInitAdapter.visitLabel(labels[i]); MethodNode node = values.get(i); storeArgs(hotswapInitAdapter, hotswapInit, methodMeta); MethodVisitor methodVisitor = new ConstructorLVTAdjustModifier(hotswapInit, 3); node.instructions.accept(methodVisitor); for (int j = 0; j < (node.localVariables == null ? 0 : node.localVariables.size()); j++) { ((LocalVariableNode) node.localVariables.get(j)).accept(methodVisitor); } } hotswapInitAdapter.mark(defaultLabel); hotswapInitAdapter.push(this.className); hotswapInitAdapter.loadArg(1); hotswapInitAdapter.invokeStatic(Type.getType(HotswapMethodUtil.class), Method.getMethod("Throwable noSuchMethodError(String, int)")); hotswapInitAdapter.throwException(); hotswapInitAdapter.endMethod(); }
From source file:com.android.build.gradle.internal.incremental.IncrementalChangeVisitor.java
License:Apache License
/** * Turns this class into an override class that can be loaded by our custom class loader: *<ul>// ww w .j a v a 2s .c o m * <li>Make the class name be OriginalName$override</li> * <li>Ensure the class derives from java.lang.Object, no other inheritance</li> * <li>Ensure the class has a public parameterless constructor that is a noop.</li> *</ul> */ @Override public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) { super.visit(version, Opcodes.ACC_PUBLIC | Opcodes.ACC_SUPER, name + OVERRIDE_SUFFIX, signature, "java/lang/Object", new String[] { CHANGE_TYPE.getInternalName() }); if (DEBUG) { System.out.println(">>>>>>>> Processing " + name + "<<<<<<<<<<<<<"); } visitedClassName = name; visitedSuperName = superName; instanceToStaticDescPrefix = "(L" + visitedClassName + ";"; // Create empty constructor MethodVisitor mv = super.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, null); mv.visitCode(); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false); mv.visitInsn(Opcodes.RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); super.visitField(Opcodes.ACC_PUBLIC | Opcodes.ACC_SYNTHETIC | Opcodes.ACC_STATIC, "$obsolete", "Z", null, null); }
From source file:com.android.build.gradle.internal.incremental.IncrementalSupportVisitor.java
License:Apache License
/** * Ensures that the class contains a $change field used for referencing the IncrementalChange * dispatcher.// w ww. jav a2 s .co m * * <p>Also updates package_private visibility to public so we can call into this class from * outside the package. */ @Override public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) { visitedClassName = name; visitedSuperName = superName; super.visitField(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC | Opcodes.ACC_VOLATILE | Opcodes.ACC_SYNTHETIC | Opcodes.ACC_TRANSIENT, "$change", getRuntimeTypeName(CHANGE_TYPE), null, null); access = transformClassAccessForInstantRun(access); super.visit(version, access, name, signature, superName, interfaces); }
From source file:com.android.build.gradle.internal.incremental.IncrementalSupportVisitor.java
License:Apache License
/*** * Inserts a trampoline to this class so that the updated methods can make calls to super * class methods./*from w w w .j a v a 2s . c om*/ * <p> * Pseudo code for this trampoline: * <code> * Object access$super($classType instance, String name, object[] args) { * switch(name) { * case "firstMethod.(Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object;": * return super~instance.firstMethod((String)arg[0], arg[1]); * case "secondMethod.(Ljava/lang/String;I)V": * return super~instance.firstMethod((String)arg[0], arg[1]); * * default: * StringBuilder $local1 = new StringBuilder(); * $local1.append("Method not found "); * $local1.append(name); * $local1.append(" in " $classType $super implementation"); * throw new $package/InstantReloadException($local1.toString()); * } * </code> */ private void createAccessSuper() { int access = Opcodes.ACC_STATIC | Opcodes.ACC_PUBLIC | Opcodes.ACC_SYNTHETIC | Opcodes.ACC_VARARGS; Method m = new Method("access$super", "(L" + visitedClassName + ";Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/Object;"); MethodVisitor visitor = super.visitMethod(access, m.getName(), m.getDescriptor(), null, null); final GeneratorAdapter mv = new GeneratorAdapter(access, m, visitor); // Gather all methods from itself and its superclasses to generate a giant access$super // implementation. // This will work fine as long as we don't support adding methods to a class. final Map<String, MethodReference> uniqueMethods = new HashMap<>(); if (parentNodes.isEmpty()) { // if we cannot determine the parents for this class, let's blindly add all the // method of the current class as a gateway to a possible parent version. addAllNewMethods(classNode, classNode, uniqueMethods); } else { // otherwise, use the parent list. for (ClassNode parentNode : parentNodes) { addAllNewMethods(classNode, parentNode, uniqueMethods); } } new StringSwitch() { @Override void visitString() { mv.visitVarInsn(Opcodes.ALOAD, 1); } @Override void visitCase(String methodName) { MethodReference methodRef = uniqueMethods.get(methodName); mv.visitVarInsn(Opcodes.ALOAD, 0); Type[] args = Type.getArgumentTypes(methodRef.method.desc); int argc = 0; for (Type t : args) { mv.visitVarInsn(Opcodes.ALOAD, 2); mv.push(argc); mv.visitInsn(Opcodes.AALOAD); ByteCodeUtils.unbox(mv, t); argc++; } if (TRACING_ENABLED) { trace(mv, "super selected ", methodRef.owner.name, methodRef.method.name, methodRef.method.desc); } String parentName = findParentClassForMethod(methodRef); logger.verbose("Generating access$super for %1$s recev %2$s", methodRef.method.name, parentName); // Call super on the other object, yup this works cos we are on the right place to // call from. mv.visitMethodInsn(Opcodes.INVOKESPECIAL, parentName, methodRef.method.name, methodRef.method.desc, false); Type ret = Type.getReturnType(methodRef.method.desc); if (ret.getSort() == Type.VOID) { mv.visitInsn(Opcodes.ACONST_NULL); } else { mv.box(ret); } mv.visitInsn(Opcodes.ARETURN); } @Override void visitDefault() { writeMissingMessageWithHash(mv, visitedClassName); } }.visit(mv, uniqueMethods.keySet()); mv.visitMaxs(0, 0); mv.visitEnd(); }
From source file:com.android.build.gradle.internal.incremental.IncrementalSupportVisitor.java
License:Apache License
/*** * Inserts a trampoline to this class so that the updated methods can make calls to * constructors./*from w w w.ja v a 2s . c om*/ * * <p> * Pseudo code for this trampoline: * <code> * ClassName(Object[] args, Marker unused) { * String name = (String) args[0]; * if (name.equals( * "java/lang/ClassName.(Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object;")) { * this((String)arg[1], arg[2]); * return * } * if (name.equals("SuperClassName.(Ljava/lang/String;I)V")) { * super((String)arg[1], (int)arg[2]); * return; * } * ... * StringBuilder $local1 = new StringBuilder(); * $local1.append("Method not found "); * $local1.append(name); * $local1.append(" in " $classType $super implementation"); * throw new $package/InstantReloadException($local1.toString()); * } * </code> */ private void createDispatchingThis() { // Gather all methods from itself and its superclasses to generate a giant constructor // implementation. // This will work fine as long as we don't support adding constructors to classes. final Map<String, MethodNode> uniqueMethods = new HashMap<>(); addAllNewConstructors(uniqueMethods, classNode, true /*keepPrivateConstructors*/); for (ClassNode parentNode : parentNodes) { addAllNewConstructors(uniqueMethods, parentNode, false /*keepPrivateConstructors*/); } int access = Opcodes.ACC_PUBLIC | Opcodes.ACC_SYNTHETIC; Method m = new Method(ByteCodeUtils.CONSTRUCTOR, ConstructorRedirection.DISPATCHING_THIS_SIGNATURE); MethodVisitor visitor = super.visitMethod(0, m.getName(), m.getDescriptor(), null, null); final GeneratorAdapter mv = new GeneratorAdapter(access, m, visitor); mv.visitCode(); // Mark this code as redirection code Label label = new Label(); mv.visitLineNumber(0, label); // Get and store the constructor canonical name. mv.visitVarInsn(Opcodes.ALOAD, 1); mv.push(1); mv.visitInsn(Opcodes.AALOAD); mv.unbox(Type.getType("Ljava/lang/String;")); final int constructorCanonicalName = mv.newLocal(Type.getType("Ljava/lang/String;")); mv.storeLocal(constructorCanonicalName); new StringSwitch() { @Override void visitString() { mv.loadLocal(constructorCanonicalName); } @Override void visitCase(String canonicalName) { MethodNode methodNode = uniqueMethods.get(canonicalName); String owner = canonicalName.split("\\.")[0]; // Parse method arguments and mv.visitVarInsn(Opcodes.ALOAD, 0); Type[] args = Type.getArgumentTypes(methodNode.desc); int argc = 1; for (Type t : args) { mv.visitVarInsn(Opcodes.ALOAD, 1); mv.push(argc + 1); mv.visitInsn(Opcodes.AALOAD); ByteCodeUtils.unbox(mv, t); argc++; } mv.visitMethodInsn(Opcodes.INVOKESPECIAL, owner, ByteCodeUtils.CONSTRUCTOR, methodNode.desc, false); mv.visitInsn(Opcodes.RETURN); } @Override void visitDefault() { writeMissingMessageWithHash(mv, visitedClassName); } }.visit(mv, uniqueMethods.keySet()); mv.visitMaxs(1, 3); mv.visitEnd(); }