List of usage examples for org.objectweb.asm Opcodes ACC_STATIC
int ACC_STATIC
To view the source code for org.objectweb.asm Opcodes ACC_STATIC.
Click Source Link
From source file:org.jboss.byteman.check.RuleCheck.java
License:Open Source License
private void typeCheckAgainstMethodDeclaration(Rule rule, RuleScript script, Class targetClass, ClassLoader loader) {/*from ww w . j a v a2s . c om*/ // ok, we have a rule which cannot be used to transform its declared class, either because // it applies to an interface or it can inject into overriding methods but does not // apply to the parent method. so we need to find a candidate method for the rule and // then see if we can use it to set up the type info needed to type check the rule String targetMethodName = script.getTargetMethod(); String targetName = TypeHelper.parseMethodName(targetMethodName); String targetDesc = TypeHelper.parseMethodDescriptor(targetMethodName); if (targetName == "<clinit>") { warning("WARNING : Cannot type check <clinit> rule \"" + script.getName() + "\" loaded from " + script.getFile() + " line " + script.getLine()); return; } if (targetMethodName == "<init>") { // oops this is an error one way or another. firstly constructor rules don't make sense for either if (script.isInterface()) { error("ERROR : Invalid target method <init> for interface rule \"" + script.getName() + "\" loaded from " + script.getFile() + " line " + script.getLine()); return; } else { error("ERROR : Invalid target method <init> for overriding rule \"" + script.getName() + "\" loaded from " + script.getFile() + " line " + script.getLine()); return; } } else { // ok, search the class's methods for any method which matches Method[] candidates = targetClass.getDeclaredMethods(); int matchCount = 0; for (Method candidate : candidates) { String candidateName = candidate.getName(); String candidateDesc = makeDescriptor(candidate); if (targetName.equals(candidateName) && (targetDesc.equals("") || TypeHelper.equalDescriptors(targetDesc, candidateDesc))) { matchCount++; if (matchCount > 1) { // we need a new copy of the rule try { rule = Rule.create(script, loader, null); } catch (ParseException e) { // will not happen } catch (TypeException e) { // will not happen } catch (CompileException e) { // will not happen } } int access = 0; Class<?>[] exceptionClasses = candidate.getExceptionTypes(); int l = exceptionClasses.length; String[] exceptionNames = new String[l]; for (int i = 0; i < l; i++) { exceptionNames[i] = exceptionClasses[i].getCanonicalName(); } if ((candidate.getModifiers() & Modifier.STATIC) != 0) { access = Opcodes.ACC_STATIC; } rule.setTypeInfo(targetClass.getName(), access, candidateName, candidateDesc, exceptionNames); // we can set param types this way but we cannot verify mention of local variables // since we don't have an implementation int paramErrorCount = installParamTypes(rule, targetClass.getName(), access, candidateName, candidateDesc); if (paramErrorCount == 0) { try { rule.typeCheck(); } catch (TypeWarningException te) { typeWarning("WARNING : Unable to type check rule \"" + script.getName() + "\" loaded from " + script.getFile() + " line " + script.getLine(), te); System.out.println(te); System.out.println(); return; } catch (TypeException te) { typeError("ERROR : Failed to type check rule \"" + script.getName() + "\" loaded from " + script.getFile() + " line " + script.getLine(), te); System.out.println(te); System.out.println(); return; } if (script.isInterface()) { info("Type checked interface rule \"" + script.getName() + "\" against method declaration"); } else { info("Type checked overriding rule \"" + script.getName() + "\" against method declaration"); } } else { info("Failed to type check rule \"" + script.getName() + "\" loaded from " + script.getFile() + " line " + script.getLine()); } } } } }
From source file:org.jboss.byteman.rule.Rule.java
License:Open Source License
/** * type check this rule/* www. ja v a2s. c om*/ * @throws TypeException if the ruele contains type errors */ public void typeCheck() throws TypeException { String helperName = ruleScript.getTargetHelper(); // ensure that we have a valid helper class if (helperName != null) { try { helperClass = loader.loadClass(helperName); } catch (ClassNotFoundException e) { throw new TypeException( "Rule.typecheck : unknown helper class " + helperName + " for rule " + getName()); } } else { helperClass = Helper.class; } if (triggerExceptions != null) { // ensure that the type group includes the exception types typeGroup.addExceptionTypes(triggerExceptions); } // try to resolve all types in the type group to classes typeGroup.resolveTypes(); // use the descriptor to derive the method argument types and type any bindings for them // that are located in the bindings list installParameters((triggerAccess & Opcodes.ACC_STATIC) != 0, triggerClass); event.typeCheck(Type.VOID); condition.typeCheck(Type.Z); action.typeCheck(Type.VOID); }
From source file:org.jboss.byteman.rule.type.Type.java
License:Open Source License
/** * identify the local var slot used to store a method parameter identified by parameter index * @param access the access flags for the method including whether or not it is static * @param desc the intrenal form descriptor for the maethod * @param paramIdx the index of the parameter in the parameter lost starting with 0 for this or 1 for * actual parameters/*from w w w . j a v a 2 s .c o m*/ * @return the corresponding local var slot or -1 if there is no such parameter */ public static int paramSlotIdx(int access, String desc, int paramIdx) { boolean isStatic = (access & Opcodes.ACC_STATIC) != 0; if (paramIdx == 0) { if (isStatic) { return -1; } else { return 0; } } else { int slotIdx = (isStatic ? 0 : 1); int descIdx = 0; char[] chars = desc.toCharArray(); char next = chars[descIdx++]; // skip leading '(' if (next == '(') { next = chars[descIdx++]; } // skip all slots preceding the desired one for (int i = 1; i < paramIdx; i++) { switch (next) { case 'Z': case 'B': case 'S': case 'C': case 'I': case 'F': { slotIdx++; } break; case 'J': case 'D': { slotIdx += 2; } break; case 'L': { slotIdx++; // skip forward in descriptor up to ';' while (next != ';') { next = chars[descIdx++]; } } break; case '[': { slotIdx++; // skip any extra '[' chars to get to the base array type while (next == '[') { next = chars[descIdx++]; } if (next == 'L') { // skip forward in descriptor up to ';' while (next != ';') { next = chars[descIdx++]; } } } break; case ')': default: { // invalid param index or invalid descriptor --either way this is a problem return -1; } } next = chars[descIdx++]; } return slotIdx; } }
From source file:org.jboss.byteman.test.TestScript.java
License:Open Source License
/** * method called to deal with interface rules or with overriding rules which fail to match a method of the * declared class.//w ww . ja v a 2 s.co m * @param rule * @param script * @param targetClass * @param loader * @return */ private void typeCheckAgainstMethodDeclaration(Rule rule, RuleScript script, Class targetClass, ClassLoader loader) { // ok, we have a rule which cannot be used to transform its declared class, either because // it applies to an interface or it can inject into overriding methods but does not // apply to the parent method. so we need to find a candidate method for the rule and // then see if we can use it to set up the type info needed to type check the rule String targetMethodName = script.getTargetMethod(); String targetName = TypeHelper.parseMethodName(targetMethodName); String targetDesc = TypeHelper.parseMethodDescriptor(targetMethodName); if (targetName == "<clinit>") { System.err.println("WARNING : cannot type check <clinit> rule \"" + script.getName() + "\" loaded from " + script.getFile() + " line " + script.getLine()); System.err.println(); warningCount++; return; } if (targetMethodName == "<init>") { // oops this is an error one way or another. firstly constructor rules don't make sense for either if (script.isInterface()) { System.err.println("ERROR : invalid target method <init> for interface rule \"" + script.getName() + "\" loaded from " + script.getFile() + " line " + script.getLine()); System.err.println(); errorCount++; return; } else { System.err.println("ERROR : invalid target method <init> for overriding rule \"" + script.getName() + "\" loaded from " + script.getFile() + " line " + script.getLine()); System.err.println(); errorCount++; return; } } else { // ok, search the class's methods for any method which matches Method[] candidates = targetClass.getDeclaredMethods(); int matchCount = 0; for (Method candidate : candidates) { String candidateName = candidate.getName(); String candidateDesc = makeDescriptor(candidate); if (targetName.equals(candidateName) && (targetDesc.equals("") || TypeHelper.equalDescriptors(targetDesc, candidateDesc))) { matchCount++; if (matchCount > 1) { // we need a new copy of the rule try { rule = Rule.create(script, loader, null); } catch (ParseException e) { // will not happen } catch (TypeException e) { // will not happen } catch (CompileException e) { // will not happen } } int access = 0; Class<?>[] exceptionClasses = candidate.getExceptionTypes(); int l = exceptionClasses.length; String[] exceptionNames = new String[l]; for (int i = 0; i < l; i++) { exceptionNames[i] = exceptionClasses[i].getCanonicalName(); } if ((candidate.getModifiers() & Modifier.STATIC) != 0) { access = Opcodes.ACC_STATIC; } rule.setTypeInfo(targetClass.getName(), access, candidateName, candidateDesc, exceptionNames); // we can set param types this way but we cannot verify mention of local variables // since we don't have an implementation int paramErrorCount = installParamTypes(rule, targetClass.getName(), access, candidateName, candidateDesc); if (paramErrorCount == 0) { try { rule.typeCheck(); } catch (TypeWarningException te) { System.out.println("WARNING : Unable to type check rule \"" + script.getName() + "\" loaded from " + script.getFile() + " line " + script.getLine()); typeWarningCount++; warningCount++; te.printStackTrace(System.out); System.out.println(); return; } catch (TypeException te) { System.out.println("ERROR : Failed to type check rule \"" + script.getName() + "\" loaded from " + script.getFile() + " line " + script.getLine()); typeErrorCount++; errorCount++; te.printStackTrace(System.out); System.out.println(); return; } if (script.isInterface()) { System.err.println("type checked interface rule \"" + script.getName() + "\" against method declaration"); } else { System.err.println("type checked overriding rule \"" + script.getName() + "\" against method declaration"); } System.err.println(); } else { errorCount += paramErrorCount; typeErrorCount += paramErrorCount; System.out.println("ERROR : Failed to type check rule \"" + script.getName() + "\" loaded from " + script.getFile() + " line " + script.getLine()); System.err.println(); } } } } }
From source file:org.jooby.internal.RouteMetadata.java
License:Apache License
private static ClassVisitor visitor(final Map<String, Object> md) { return new ClassVisitor(Opcodes.ASM5) { @Override/*from w w w .j ava2s .c o m*/ public MethodVisitor visitMethod(final int access, final String name, final String desc, final String signature, final String[] exceptions) { boolean isPublic = ((access & Opcodes.ACC_PUBLIC) > 0) ? true : false; boolean isStatic = ((access & Opcodes.ACC_STATIC) > 0) ? true : false; if (!isPublic || isStatic) { // ignore return null; } final String seed = name + desc; Type[] args = Type.getArgumentTypes(desc); String[] names = args.length == 0 ? NO_ARG : new String[args.length]; md.put(paramsKey(seed), names); int minIdx = ((access & Opcodes.ACC_STATIC) > 0) ? 0 : 1; int maxIdx = Arrays.stream(args).mapToInt(Type::getSize).sum(); return new MethodVisitor(Opcodes.ASM5) { private int i = 0; private boolean skipLocalTable = false; @Override public void visitParameter(final String name, final int access) { skipLocalTable = true; // save current parameter names[i] = name; // move to next i += 1; } @Override public void visitLineNumber(final int line, final Label start) { // save line number md.putIfAbsent(startAtKey(seed), line); } @Override public void visitLocalVariable(final String name, final String desc, final String signature, final Label start, final Label end, final int index) { if (!skipLocalTable) { if (index >= minIdx && index <= maxIdx) { // save current parameter names[i] = name; // move to next i += 1; } } } }; } }; }
From source file:org.jruby.compiler.impl.StandardInvocationCompiler.java
License:LGPL
public void invokeDynamicSelfNoBlockSpecificArity(String name, ArgumentsCallback argsCallback) { methodCompiler.loadThis();//from w w w . j a v a 2 s . c o m methodCompiler.loadThreadContext(); methodCompiler.loadSelf(); argsCallback.call(methodCompiler); String thisClass = methodCompiler.getScriptCompiler().getClassname(); String signature1; switch (argsCallback.getArity()) { case 1: signature1 = sig(IRubyObject.class, "L" + thisClass + ";", ThreadContext.class, IRubyObject.class, IRubyObject.class); break; case 2: signature1 = sig(IRubyObject.class, "L" + thisClass + ";", ThreadContext.class, IRubyObject.class, IRubyObject.class, IRubyObject.class); break; case 3: signature1 = sig(IRubyObject.class, "L" + thisClass + ";", ThreadContext.class, IRubyObject.class, IRubyObject.class, IRubyObject.class, IRubyObject.class); break; default: throw new RuntimeException("invalid arity for inline dyncall: " + argsCallback.getArity()); } String synthMethodName = methodCompiler.getNativeMethodName() + "$call" + methodCompiler.getScriptCompiler().getAndIncrementMethodIndex(); SkinnyMethodAdapter m2 = new SkinnyMethodAdapter(methodCompiler.getScriptCompiler().getClassVisitor(), Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC | Opcodes.ACC_SYNTHETIC, synthMethodName, signature1, null, null); method.invokestatic(thisClass, synthMethodName, signature1); SkinnyMethodAdapter oldMethod = methodCompiler.method; methodCompiler.method = m2; m2.start(); methodCompiler.getScriptCompiler().getCacheCompiler().cacheMethod(methodCompiler, name); m2.aload(1); // ThreadContext m2.aload(2); // receiver m2.aload(2); // receiver m2.invokeinterface(p(IRubyObject.class), "getMetaClass", sig(RubyClass.class)); m2.ldc(name); String signature2; switch (argsCallback.getArity()) { case 1: signature2 = sig(IRubyObject.class, ThreadContext.class, IRubyObject.class, RubyModule.class, String.class, IRubyObject.class); m2.aload(3); break; case 2: signature2 = sig(IRubyObject.class, ThreadContext.class, IRubyObject.class, RubyModule.class, String.class, IRubyObject.class, IRubyObject.class); m2.aload(3); m2.aload(4); break; case 3: signature2 = sig(IRubyObject.class, ThreadContext.class, IRubyObject.class, RubyModule.class, String.class, IRubyObject.class, IRubyObject.class, IRubyObject.class); m2.aload(3); m2.aload(4); m2.aload(5); break; default: throw new RuntimeException("invalid arity for inline dyncall: " + argsCallback.getArity()); } m2.invokevirtual(p(DynamicMethod.class), "call", signature2); m2.areturn(); m2.end(); methodCompiler.method = oldMethod; }
From source file:org.jruby.javasupport.proxy.JavaProxyClassFactory.java
License:LGPL
private static ClassWriter beginProxyClass(final String targetClassName, final Class superClass, final Class[] interfaces) { ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS); int access = Opcodes.ACC_PUBLIC | Opcodes.ACC_FINAL | Opcodes.ACC_STATIC; String name = toInternalClassName(targetClassName); String signature = null;//from w ww.java 2s .c o m String supername = toInternalClassName(superClass); String[] interfaceNames = new String[interfaces.length + 1]; for (int i = 0; i < interfaces.length; i++) { interfaceNames[i] = toInternalClassName(interfaces[i]); } interfaceNames[interfaces.length] = toInternalClassName(InternalJavaProxy.class); // start class cw.visit(Opcodes.V1_3, access, name, signature, supername, interfaceNames); cw.visitField(Opcodes.ACC_PRIVATE, INVOCATION_HANDLER_FIELD_NAME, INVOCATION_HANDLER_TYPE.getDescriptor(), null, null).visitEnd(); cw.visitField(Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC, PROXY_CLASS_FIELD_NAME, PROXY_CLASS_TYPE.getDescriptor(), null, null).visitEnd(); return cw; }
From source file:org.jruby.javasupport.proxy.JavaProxyClassFactory.java
License:LGPL
private static GeneratorAdapter createClassInitializer(Type selfType, ClassVisitor cw) { GeneratorAdapter clazzInit;/*from w w w . j a v a2 s .c om*/ clazzInit = new GeneratorAdapter(Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC, new org.objectweb.asm.commons.Method("<clinit>", Type.VOID_TYPE, EMPTY_TYPE_ARR), null, EMPTY_TYPE_ARR, cw); clazzInit.visitLdcInsn(selfType.getClassName()); clazzInit.invokeStatic(JAVA_LANG_CLASS_TYPE, CLASS_FORNAME_METHOD); clazzInit.invokeStatic(PROXY_HELPER_TYPE, HELPER_GET_PROXY_CLASS_METHOD); clazzInit.dup(); clazzInit.putStatic(selfType, PROXY_CLASS_FIELD_NAME, PROXY_CLASS_TYPE); return clazzInit; }
From source file:org.jruby.javasupport.proxy.JavaProxyClassFactory.java
License:LGPL
private static void generateProxyMethod(Type selfType, Type superType, ClassVisitor cw, GeneratorAdapter clazzInit, MethodData md) { if (!md.generateProxyMethod()) { return;/* w ww. j av a 2s.c om*/ } org.objectweb.asm.commons.Method m = md.getMethod(); Type[] ex = toType(md.getExceptions()); String field_name = "__mth$" + md.getName() + md.scrambledSignature(); // create static private method field FieldVisitor fv = cw.visitField(Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC, field_name, PROXY_METHOD_TYPE.getDescriptor(), null, null); fv.visitEnd(); clazzInit.dup(); clazzInit.push(m.getName()); clazzInit.push(m.getDescriptor()); clazzInit.push(md.isImplemented()); clazzInit.invokeStatic(PROXY_HELPER_TYPE, PROXY_HELPER_GET_METHOD); clazzInit.putStatic(selfType, field_name, PROXY_METHOD_TYPE); org.objectweb.asm.commons.Method sm = new org.objectweb.asm.commons.Method("__super$" + m.getName(), m.getReturnType(), m.getArgumentTypes()); // // construct the proxy method // GeneratorAdapter ga = new GeneratorAdapter(Opcodes.ACC_PUBLIC, m, null, ex, cw); ga.loadThis(); ga.getField(selfType, INVOCATION_HANDLER_FIELD_NAME, INVOCATION_HANDLER_TYPE); // if the method is extending something, then we have // to test if the handler is initialized... if (md.isImplemented()) { ga.dup(); Label ok = ga.newLabel(); ga.ifNonNull(ok); ga.loadThis(); ga.loadArgs(); ga.invokeConstructor(superType, m); ga.returnValue(); ga.mark(ok); } ga.loadThis(); ga.getStatic(selfType, field_name, PROXY_METHOD_TYPE); if (m.getArgumentTypes().length == 0) { // load static empty array ga.getStatic(JAVA_PROXY_TYPE, "NO_ARGS", Type.getType(Object[].class)); } else { // box arguments ga.loadArgArray(); } Label before = ga.mark(); ga.invokeInterface(INVOCATION_HANDLER_TYPE, INVOCATION_HANDLER_INVOKE_METHOD); Label after = ga.mark(); ga.unbox(m.getReturnType()); ga.returnValue(); // this is a simple rethrow handler Label rethrow = ga.mark(); ga.visitInsn(Opcodes.ATHROW); for (int i = 0; i < ex.length; i++) { ga.visitTryCatchBlock(before, after, rethrow, ex[i].getInternalName()); } ga.visitTryCatchBlock(before, after, rethrow, "java/lang/Error"); ga.visitTryCatchBlock(before, after, rethrow, "java/lang/RuntimeException"); Type thr = Type.getType(Throwable.class); Label handler = ga.mark(); Type udt = Type.getType(UndeclaredThrowableException.class); int loc = ga.newLocal(thr); ga.storeLocal(loc, thr); ga.newInstance(udt); ga.dup(); ga.loadLocal(loc, thr); ga.invokeConstructor(udt, org.objectweb.asm.commons.Method.getMethod("void <init>(java.lang.Throwable)")); ga.throwException(); ga.visitTryCatchBlock(before, after, handler, "java/lang/Throwable"); ga.endMethod(); // // construct the super-proxy method // if (md.isImplemented()) { GeneratorAdapter ga2 = new GeneratorAdapter(Opcodes.ACC_PUBLIC, sm, null, ex, cw); ga2.loadThis(); ga2.loadArgs(); ga2.invokeConstructor(superType, m); ga2.returnValue(); ga2.endMethod(); } }
From source file:org.jtsan.MethodTransformer.java
License:Apache License
public MethodTransformer(Agent agent, MethodVisitor mv, int acc, String name, String fullName, String desc, String src, String className, MethodMapping methods, CodePos codePos, Set<String> volatileFields) { super(mv, acc, name, desc); this.agent = agent; this.fullName = fullName; this.methods = methods; this.srcFile = src; this.methodName = name; this.className = className; this.codePos = codePos; this.volatileFields = volatileFields; this.methodIsStatic = ((acc & Opcodes.ACC_STATIC) != 0); lazyDescr = new DescrCallback(); exceptionTableTop = new ArrayList<ExceptionTableEntry>(); exceptionTableBottom = new ArrayList<ExceptionTableEntry>(); }