< prev index next >

test/hotspot/jtreg/compiler/jvmci/common/CTVMUtilities.java

Print this page
rev 52456 : imported patch asm.additional


  94         ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
  95         ClassVisitor cv = new ClassVisitorForLabels(cw, labels, method);
  96         cr.accept(cv, ClassReader.EXPAND_FRAMES);
  97         labels.forEach((k, v) -> lineNumbers.put(k.getOffset(), v));
  98         boolean isEmptyMethod = Modifier.isAbstract(method.getModifiers())
  99                 || Modifier.isNative(method.getModifiers());
 100         if (lineNumbers.isEmpty() && !isEmptyMethod) {
 101             throw new Error(method + " doesn't contains the line numbers table "
 102                     +"(the method marked neither abstract nor native)");
 103         }
 104         return lineNumbers;
 105     }
 106 
 107     private static class ClassVisitorForLabels extends ClassVisitor {
 108         private final Map<Label, Integer> lineNumbers;
 109         private final String targetName;
 110         private final String targetDesc;
 111 
 112         public ClassVisitorForLabels(ClassWriter cw, Map<Label, Integer> lines,
 113                                      Executable target) {
 114             super(Opcodes.ASM5, cw);
 115             this.lineNumbers = lines;
 116 
 117             StringBuilder builder = new StringBuilder("(");
 118             for (Parameter parameter : target.getParameters()) {
 119                 builder.append(Utils.toJVMTypeSignature(parameter.getType()));
 120             }
 121             builder.append(")");
 122             if (target instanceof Constructor) {
 123                 targetName = "<init>";
 124                 builder.append("V");
 125             } else {
 126                 targetName = target.getName();
 127                 builder.append(Utils.toJVMTypeSignature(
 128                         ((Method) target).getReturnType()));
 129             }
 130             targetDesc = builder.toString();
 131         }
 132 
 133         @Override
 134         public final MethodVisitor visitMethod(int access, String name,
 135                                                String desc, String signature,
 136                                                String[] exceptions) {
 137             MethodVisitor mv = cv.visitMethod(access, name, desc, signature,
 138                     exceptions);
 139             if (targetDesc.equals(desc) && targetName.equals(name)) {
 140                 return new MethodVisitor(Opcodes.ASM5, mv) {
 141                     @Override
 142                     public void visitLineNumber(int i, Label label) {
 143                         super.visitLineNumber(i, label);
 144                         lineNumbers.put(label, i);
 145                     }
 146                 };
 147             }
 148             return  mv;
 149         }
 150     }
 151 }


  94         ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
  95         ClassVisitor cv = new ClassVisitorForLabels(cw, labels, method);
  96         cr.accept(cv, ClassReader.EXPAND_FRAMES);
  97         labels.forEach((k, v) -> lineNumbers.put(k.getOffset(), v));
  98         boolean isEmptyMethod = Modifier.isAbstract(method.getModifiers())
  99                 || Modifier.isNative(method.getModifiers());
 100         if (lineNumbers.isEmpty() && !isEmptyMethod) {
 101             throw new Error(method + " doesn't contains the line numbers table "
 102                     +"(the method marked neither abstract nor native)");
 103         }
 104         return lineNumbers;
 105     }
 106 
 107     private static class ClassVisitorForLabels extends ClassVisitor {
 108         private final Map<Label, Integer> lineNumbers;
 109         private final String targetName;
 110         private final String targetDesc;
 111 
 112         public ClassVisitorForLabels(ClassWriter cw, Map<Label, Integer> lines,
 113                                      Executable target) {
 114             super(Opcodes.ASM7, cw);
 115             this.lineNumbers = lines;
 116 
 117             StringBuilder builder = new StringBuilder("(");
 118             for (Parameter parameter : target.getParameters()) {
 119                 builder.append(Utils.toJVMTypeSignature(parameter.getType()));
 120             }
 121             builder.append(")");
 122             if (target instanceof Constructor) {
 123                 targetName = "<init>";
 124                 builder.append("V");
 125             } else {
 126                 targetName = target.getName();
 127                 builder.append(Utils.toJVMTypeSignature(
 128                         ((Method) target).getReturnType()));
 129             }
 130             targetDesc = builder.toString();
 131         }
 132 
 133         @Override
 134         public final MethodVisitor visitMethod(int access, String name,
 135                                                String desc, String signature,
 136                                                String[] exceptions) {
 137             MethodVisitor mv = cv.visitMethod(access, name, desc, signature,
 138                     exceptions);
 139             if (targetDesc.equals(desc) && targetName.equals(name)) {
 140                 return new MethodVisitor(Opcodes.ASM7, mv) {
 141                     @Override
 142                     public void visitLineNumber(int i, Label label) {
 143                         super.visitLineNumber(i, label);
 144                         lineNumbers.put(label, i);
 145                     }
 146                 };
 147             }
 148             return  mv;
 149         }
 150     }
 151 }
< prev index next >