com.sun.tools.classfile.ConstantPool Java Examples
The following examples show how to use
com.sun.tools.classfile.ConstantPool.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LVTHarness.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
void checkMethod(ConstantPool constantPool, Method method, AliveRanges ranges) throws InvalidIndex, UnexpectedEntry, ConstantPoolException { Code_attribute code = (Code_attribute) method.attributes.get(Attribute.Code); LocalVariableTable_attribute lvt = (LocalVariableTable_attribute) (code.attributes.get(Attribute.LocalVariableTable)); List<String> infoFromRanges = convertToStringList(ranges); List<String> infoFromLVT = convertToStringList(constantPool, lvt); // infoFromRanges most be contained in infoFromLVT int i = 0; int j = 0; while (i < infoFromRanges.size() && j < infoFromLVT.size()) { int comparison = infoFromRanges.get(i).compareTo(infoFromLVT.get(j)); if (comparison == 0) { i++; j++; } else if (comparison > 0) { j++; } else { break; } } if (i < infoFromRanges.size()) { error(infoFromLVT, infoFromRanges, method.getName(constantPool).toString()); } }
Example #2
Source File: LambdaAsm.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
static void checkMethod(String cname, String mname, ConstantPool cp, Code_attribute code) throws ConstantPool.InvalidIndex { for (Instruction i : code.getInstructions()) { String iname = i.getMnemonic(); if ("invokespecial".equals(iname) || "invokestatic".equals(iname)) { int idx = i.getByte(2); System.out.println("Verifying " + cname + ":" + mname + " instruction:" + iname + " index @" + idx); CPInfo cpinfo = cp.get(idx); if (cpinfo instanceof ConstantPool.CONSTANT_Methodref_info) { throw new RuntimeException("unexpected CP type expected " + "InterfaceMethodRef, got MethodRef, " + cname + ", " + mname); } } } }
Example #3
Source File: LVTHarness.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
void checkMethod(ConstantPool constantPool, Method method, AliveRanges ranges) throws InvalidIndex, UnexpectedEntry, ConstantPoolException { Code_attribute code = (Code_attribute) method.attributes.get(Attribute.Code); LocalVariableTable_attribute lvt = (LocalVariableTable_attribute) (code.attributes.get(Attribute.LocalVariableTable)); List<String> infoFromRanges = convertToStringList(ranges); List<String> infoFromLVT = convertToStringList(constantPool, lvt); // infoFromRanges most be contained in infoFromLVT int i = 0; int j = 0; while (i < infoFromRanges.size() && j < infoFromLVT.size()) { int comparison = infoFromRanges.get(i).compareTo(infoFromLVT.get(j)); if (comparison == 0) { i++; j++; } else if (comparison > 0) { j++; } else { break; } } if (i < infoFromRanges.size()) { error(infoFromLVT, infoFromRanges, method.getName(constantPool).toString()); } }
Example #4
Source File: LambdaAsm.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
static void checkMethod(String cname, String mname, ConstantPool cp, Code_attribute code) throws ConstantPool.InvalidIndex { for (Instruction i : code.getInstructions()) { String iname = i.getMnemonic(); if ("invokespecial".equals(iname) || "invokestatic".equals(iname)) { int idx = i.getByte(2); System.out.println("Verifying " + cname + ":" + mname + " instruction:" + iname + " index @" + idx); CPInfo cpinfo = cp.get(idx); if (cpinfo instanceof ConstantPool.CONSTANT_Methodref_info) { throw new RuntimeException("unexpected CP type expected " + "InterfaceMethodRef, got MethodRef, " + cname + ", " + mname); } } } }
Example #5
Source File: LVTHarness.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
void checkMethod(ConstantPool constantPool, Method method, AliveRanges ranges) throws InvalidIndex, UnexpectedEntry, ConstantPoolException { Code_attribute code = (Code_attribute) method.attributes.get(Attribute.Code); LocalVariableTable_attribute lvt = (LocalVariableTable_attribute) (code.attributes.get(Attribute.LocalVariableTable)); List<String> infoFromRanges = convertToStringList(ranges); List<String> infoFromLVT = convertToStringList(constantPool, lvt); // infoFromRanges most be contained in infoFromLVT int i = 0; int j = 0; while (i < infoFromRanges.size() && j < infoFromLVT.size()) { int comparison = infoFromRanges.get(i).compareTo(infoFromLVT.get(j)); if (comparison == 0) { i++; j++; } else if (comparison > 0) { j++; } else { break; } } if (i < infoFromRanges.size()) { error(infoFromLVT, infoFromRanges, method.getName(constantPool).toString()); } }
Example #6
Source File: LVTHarness.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
void checkClassFile(File file) throws IOException, ConstantPoolException, InvalidDescriptor { ClassFile classFile = ClassFile.read(file); ConstantPool constantPool = classFile.constant_pool; //lets get all the methods in the class file. for (Method method : classFile.methods) { for (ElementKey elementKey: aliveRangeMap.keySet()) { String methodDesc = method.getName(constantPool) + method.descriptor.getParameterTypes(constantPool).replace(" ", ""); if (methodDesc.equals(elementKey.elem.toString())) { checkMethod(constantPool, method, aliveRangeMap.get(elementKey)); seenAliveRanges.add(elementKey); } } } }
Example #7
Source File: LambdaAsm.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
static void checkMethod(String cname, String mname, ConstantPool cp, Code_attribute code) throws ConstantPool.InvalidIndex { for (Instruction i : code.getInstructions()) { String iname = i.getMnemonic(); if ("invokespecial".equals(iname) || "invokestatic".equals(iname)) { int idx = i.getByte(2); System.out.println("Verifying " + cname + ":" + mname + " instruction:" + iname + " index @" + idx); CPInfo cpinfo = cp.get(idx); if (cpinfo instanceof ConstantPool.CONSTANT_Methodref_info) { throw new RuntimeException("unexpected CP type expected " + "InterfaceMethodRef, got MethodRef, " + cname + ", " + mname); } } } }
Example #8
Source File: LambdaAsm.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
static void checkMethod(String cname, String mname, ConstantPool cp, Code_attribute code) throws ConstantPool.InvalidIndex { for (Instruction i : code.getInstructions()) { String iname = i.getMnemonic(); if ("invokespecial".equals(iname) || "invokestatic".equals(iname)) { int idx = i.getByte(2); System.out.println("Verifying " + cname + ":" + mname + " instruction:" + iname + " index @" + idx); CPInfo cpinfo = cp.get(idx); if (cpinfo instanceof ConstantPool.CONSTANT_Methodref_info) { throw new RuntimeException("unexpected CP type expected " + "InterfaceMethodRef, got MethodRef, " + cname + ", " + mname); } } } }
Example #9
Source File: LambdaAsm.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
static void checkMethod(String cname, String mname, ConstantPool cp, Code_attribute code) throws ConstantPool.InvalidIndex { for (Instruction i : code.getInstructions()) { String iname = i.getMnemonic(); if ("invokespecial".equals(iname) || "invokestatic".equals(iname)) { int idx = i.getByte(2); System.out.println("Verifying " + cname + ":" + mname + " instruction:" + iname + " index @" + idx); CPInfo cpinfo = cp.get(idx); if (cpinfo instanceof ConstantPool.CONSTANT_Methodref_info) { throw new RuntimeException("unexpected CP type expected " + "InterfaceMethodRef, got MethodRef, " + cname + ", " + mname); } } } }
Example #10
Source File: LVTHarness.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
void checkClassFile(File file) throws IOException, ConstantPoolException, InvalidDescriptor { ClassFile classFile = ClassFile.read(file); ConstantPool constantPool = classFile.constant_pool; //lets get all the methods in the class file. for (Method method : classFile.methods) { for (ElementKey elementKey: aliveRangeMap.keySet()) { String methodDesc = method.getName(constantPool) + method.descriptor.getParameterTypes(constantPool).replace(" ", ""); if (methodDesc.equals(elementKey.elem.toString())) { checkMethod(constantPool, method, aliveRangeMap.get(elementKey)); seenAliveRanges.add(elementKey); } } } }
Example #11
Source File: LambdaAsm.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
static void checkMethod(String cname, String mname, ConstantPool cp, Code_attribute code) throws ConstantPool.InvalidIndex { for (Instruction i : code.getInstructions()) { String iname = i.getMnemonic(); if ("invokespecial".equals(iname) || "invokestatic".equals(iname)) { int idx = i.getByte(2); System.out.println("Verifying " + cname + ":" + mname + " instruction:" + iname + " index @" + idx); CPInfo cpinfo = cp.get(idx); if (cpinfo instanceof ConstantPool.CONSTANT_Methodref_info) { throw new RuntimeException("unexpected CP type expected " + "InterfaceMethodRef, got MethodRef, " + cname + ", " + mname); } } } }
Example #12
Source File: LVTHarness.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
void checkMethod(ConstantPool constantPool, Method method, AliveRanges ranges) throws InvalidIndex, UnexpectedEntry { Code_attribute code = (Code_attribute) method.attributes.get(Attribute.Code); LocalVariableTable_attribute lvt = (LocalVariableTable_attribute) (code.attributes.get(Attribute.LocalVariableTable)); List<String> infoFromRanges = convertToStringList(ranges); List<String> infoFromLVT = convertToStringList(constantPool, lvt); // infoFromRanges most be contained in infoFromLVT int i = 0; int j = 0; while (i < infoFromRanges.size() && j < infoFromLVT.size()) { int comparison = infoFromRanges.get(i).compareTo(infoFromLVT.get(j)); if (comparison == 0) { i++; j++; } else if (comparison > 0) { j++; } else { break; } } if (i < infoFromRanges.size()) { error(infoFromLVT, infoFromRanges); } }
Example #13
Source File: LambdaAsm.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
static void checkMethod(String cname, String mname, ConstantPool cp, Code_attribute code) throws ConstantPool.InvalidIndex { for (Instruction i : code.getInstructions()) { String iname = i.getMnemonic(); if ("invokespecial".equals(iname) || "invokestatic".equals(iname)) { int idx = i.getByte(2); System.out.println("Verifying " + cname + ":" + mname + " instruction:" + iname + " index @" + idx); CPInfo cpinfo = cp.get(idx); if (cpinfo instanceof ConstantPool.CONSTANT_Methodref_info) { throw new RuntimeException("unexpected CP type expected " + "InterfaceMethodRef, got MethodRef, " + cname + ", " + mname); } } } }
Example #14
Source File: LVTHarness.java From hottub with GNU General Public License v2.0 | 6 votes |
void checkMethod(ConstantPool constantPool, Method method, AliveRanges ranges) throws InvalidIndex, UnexpectedEntry, ConstantPoolException { Code_attribute code = (Code_attribute) method.attributes.get(Attribute.Code); LocalVariableTable_attribute lvt = (LocalVariableTable_attribute) (code.attributes.get(Attribute.LocalVariableTable)); List<String> infoFromRanges = convertToStringList(ranges); List<String> infoFromLVT = convertToStringList(constantPool, lvt); // infoFromRanges most be contained in infoFromLVT int i = 0; int j = 0; while (i < infoFromRanges.size() && j < infoFromLVT.size()) { int comparison = infoFromRanges.get(i).compareTo(infoFromLVT.get(j)); if (comparison == 0) { i++; j++; } else if (comparison > 0) { j++; } else { break; } } if (i < infoFromRanges.size()) { error(infoFromLVT, infoFromRanges, method.getName(constantPool).toString()); } }
Example #15
Source File: LambdaAsm.java From hottub with GNU General Public License v2.0 | 6 votes |
static void checkMethod(String cname, String mname, ConstantPool cp, Code_attribute code) throws ConstantPool.InvalidIndex { for (Instruction i : code.getInstructions()) { String iname = i.getMnemonic(); if ("invokespecial".equals(iname) || "invokestatic".equals(iname)) { int idx = i.getByte(2); System.out.println("Verifying " + cname + ":" + mname + " instruction:" + iname + " index @" + idx); CPInfo cpinfo = cp.get(idx); if (cpinfo instanceof ConstantPool.CONSTANT_Methodref_info) { throw new RuntimeException("unexpected CP type expected " + "InterfaceMethodRef, got MethodRef, " + cname + ", " + mname); } } } }
Example #16
Source File: ConstantWriter.java From hottub with GNU General Public License v2.0 | 5 votes |
String stringValue(int constant_pool_index) { ClassFile classFile = classWriter.getClassFile(); try { return stringValue(classFile.constant_pool.get(constant_pool_index)); } catch (ConstantPool.InvalidIndex e) { return report(e); } }
Example #17
Source File: AttributeWriter.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
String getInnerName(ConstantPool constant_pool, InnerClasses_attribute.Info info) { try { return info.getInnerName(constant_pool); } catch (ConstantPoolException e) { return report(e); } }
Example #18
Source File: LVTHarness.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
List<String> convertToStringList(ConstantPool constantPool, LocalVariableTable_attribute lvt) throws InvalidIndex, UnexpectedEntry { List<String> result = new ArrayList<>(); for (Entry entry : lvt.local_variable_table) { String str = formatLocalVariableData(constantPool.getUTF8Value(entry.name_index), entry.start_pc, entry.length); result.add(str); } Collections.sort(result); return result; }
Example #19
Source File: StackMapWriter.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
void setStackMap(StackMapTable_attribute attr) { if (attr == null) { map = null; return; } Method m = classWriter.getMethod(); Descriptor d = m.descriptor; String[] args; try { ConstantPool cp = classWriter.getClassFile().constant_pool; String argString = d.getParameterTypes(cp); args = argString.substring(1, argString.length() - 1).split("[, ]+"); } catch (ConstantPoolException | InvalidDescriptor e) { return; } boolean isStatic = m.access_flags.is(AccessFlags.ACC_STATIC); verification_type_info[] initialLocals = new verification_type_info[(isStatic ? 0 : 1) + args.length]; if (!isStatic) initialLocals[0] = new CustomVerificationTypeInfo("this"); for (int i = 0; i < args.length; i++) { initialLocals[(isStatic ? 0 : 1) + i] = new CustomVerificationTypeInfo(args[i].replace(".", "/")); } map = new HashMap<>(); StackMapBuilder builder = new StackMapBuilder(); // using -1 as the pc for the initial frame effectively compensates for // the difference in behavior for the first stack map frame (where the // pc offset is just offset_delta) compared to subsequent frames (where // the pc offset is always offset_delta+1). int pc = -1; map.put(pc, new StackMap(initialLocals, empty)); for (int i = 0; i < attr.entries.length; i++) pc = attr.entries[i].accept(builder, pc); }
Example #20
Source File: AnnotationDefaultVerifier.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Override public void testElementValue( TestResult testCase, ClassFile classFile, Annotation.element_value element_value, String[] values) throws ConstantPool.InvalidIndex { Annotation.Primitive_element_value ev = (Annotation.Primitive_element_value) element_value; ConstantPool.CONSTANT_Utf8_info info = (ConstantPool.CONSTANT_Utf8_info) classFile.constant_pool.get(ev.const_value_index); testCase.checkEquals(info.value, values[0], "const_value_index"); }
Example #21
Source File: AttributeWriter.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public void write(Object owner, Attribute attr, ConstantPool constant_pool) { if (attr != null) { Assert.checkNonNull(constant_pool); Assert.checkNonNull(owner); this.constant_pool = constant_pool; this.owner = owner; attr.accept(this, null); } }
Example #22
Source File: TestAnnotationInfo.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Override public void testElementValue(TestResult testResult, ClassFile classFile, Annotation.element_value element_value) throws ConstantPoolException { testTag(testResult, element_value.tag); Annotation.Primitive_element_value ev = (Annotation.Primitive_element_value) element_value; ConstantPool.CONSTANT_Utf8_info info = (ConstantPool.CONSTANT_Utf8_info) classFile.constant_pool.get(ev.const_value_index); testResult.checkEquals(info.value, value, "const_value_index"); }
Example #23
Source File: TestAnnotationInfo.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Override public void testElementValue(TestResult testResult, ClassFile classFile, Annotation.element_value element_value) throws ConstantPoolException { testTag(testResult, element_value.tag); Annotation.Primitive_element_value ev = (Annotation.Primitive_element_value) element_value; ConstantPool.CONSTANT_Integer_info info = (ConstantPool.CONSTANT_Integer_info) classFile.constant_pool.get(ev.const_value_index); testResult.checkEquals(info.value, value ? 1 : 0, "const_value_index : " + value); }
Example #24
Source File: AttributeWriter.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public void write(Object owner, Attributes attrs, ConstantPool constant_pool) { if (attrs != null) { Assert.checkNonNull(constant_pool); Assert.checkNonNull(owner); this.constant_pool = constant_pool; this.owner = owner; for (Attribute attr: attrs) attr.accept(this, null); } }
Example #25
Source File: CreateSymbols.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
Object convertElementValue(ConstantPool cp, element_value val) throws InvalidIndex, ConstantPoolException { switch (val.tag) { case 'Z': return ((CONSTANT_Integer_info) cp.get(((Primitive_element_value) val).const_value_index)).value != 0; case 'B': return (byte) ((CONSTANT_Integer_info) cp.get(((Primitive_element_value) val).const_value_index)).value; case 'C': return (char) ((CONSTANT_Integer_info) cp.get(((Primitive_element_value) val).const_value_index)).value; case 'S': return (short) ((CONSTANT_Integer_info) cp.get(((Primitive_element_value) val).const_value_index)).value; case 'I': return ((CONSTANT_Integer_info) cp.get(((Primitive_element_value) val).const_value_index)).value; case 'J': return ((CONSTANT_Long_info) cp.get(((Primitive_element_value) val).const_value_index)).value; case 'F': return ((CONSTANT_Float_info) cp.get(((Primitive_element_value) val).const_value_index)).value; case 'D': return ((CONSTANT_Double_info) cp.get(((Primitive_element_value) val).const_value_index)).value; case 's': return ((CONSTANT_Utf8_info) cp.get(((Primitive_element_value) val).const_value_index)).value; case 'e': return new EnumConstant(cp.getUTF8Value(((Enum_element_value) val).type_name_index), cp.getUTF8Value(((Enum_element_value) val).const_name_index)); case 'c': return new ClassConstant(cp.getUTF8Value(((Class_element_value) val).class_info_index)); case '@': return annotation2Description(cp, ((Annotation_element_value) val).annotation_value); case '[': List<Object> values = new ArrayList<>(); for (element_value elem : ((Array_element_value) val).values) { values.add(convertElementValue(cp, elem)); } return values; default: throw new IllegalStateException("Currently unhandled tag: " + val.tag); } }
Example #26
Source File: CreateSymbols.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private AnnotationDescription annotation2Description(ConstantPool cp, Annotation a) throws ConstantPoolException { String annotationType = cp.getUTF8Value(a.type_index); Map<String, Object> values = new HashMap<>(); for (element_value_pair e : a.element_value_pairs) { values.put(cp.getUTF8Value(e.element_name_index), convertElementValue(cp, e.value)); } return new AnnotationDescription(annotationType, values); }
Example #27
Source File: AttributeWriter.java From hottub with GNU General Public License v2.0 | 5 votes |
public void write(Object owner, Attributes attrs, ConstantPool constant_pool) { if (attrs != null) { // null checks owner.getClass(); constant_pool.getClass(); this.constant_pool = constant_pool; this.owner = owner; for (Attribute attr: attrs) attr.accept(this, null); } }
Example #28
Source File: AnnotationDefaultVerifier.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Override public void testElementValue( TestResult testCase, ClassFile classFile, Annotation.element_value element_value, String[] values) throws ConstantPool.InvalidIndex { Annotation.Primitive_element_value ev = (Annotation.Primitive_element_value) element_value; ConstantPool.CONSTANT_Double_info info = (ConstantPool.CONSTANT_Double_info) classFile.constant_pool.get(ev.const_value_index); testCase.checkEquals(info.value, Double.parseDouble(values[0]), "const_value_index"); }
Example #29
Source File: AttributeWriter.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
public void write(Object owner, Attribute attr, ConstantPool constant_pool) { if (attr != null) { // null checks owner.getClass(); constant_pool.getClass(); this.constant_pool = constant_pool; this.owner = owner; attr.accept(this, null); } }
Example #30
Source File: ConstantWriter.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
String stringValue(int constant_pool_index) { ClassFile classFile = classWriter.getClassFile(); try { return stringValue(classFile.constant_pool.get(constant_pool_index)); } catch (ConstantPool.InvalidIndex e) { return report(e); } }