1.1 --- a/src/share/classes/com/sun/tools/classfile/ConstantPool.java Fri Jan 14 13:59:18 2011 -0800 1.2 +++ b/src/share/classes/com/sun/tools/classfile/ConstantPool.java Tue Jan 18 08:37:05 2011 -0800 1.3 @@ -1,5 +1,5 @@ 1.4 /* 1.5 - * Copyright (c) 2007, 2009, Oracle and/or its affiliates. All rights reserved. 1.6 + * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved. 1.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.8 * 1.9 * This code is free software; you can redistribute it and/or modify it 1.10 @@ -114,6 +114,54 @@ 1.11 public static final int CONSTANT_Methodref = 10; 1.12 public static final int CONSTANT_InterfaceMethodref = 11; 1.13 public static final int CONSTANT_NameAndType = 12; 1.14 + public static final int CONSTANT_MethodHandle = 15; 1.15 + public static final int CONSTANT_MethodType = 16; 1.16 + public static final int CONSTANT_InvokeDynamic = 18; 1.17 + 1.18 + public static enum RefKind { 1.19 + REF_getField(1, "getfield"), 1.20 + REF_getStatic(2, "getstatic"), 1.21 + REF_putField(3, "putfield"), 1.22 + REF_putStatic(4, "putstatic"), 1.23 + REF_invokeVirtual(5, "invokevirtual"), 1.24 + REF_invokeStatic(6, "invokestatic"), 1.25 + REF_invokeSpecial(7, "invokespecial"), 1.26 + REF_newInvokeSpecial(8, "newinvokespecial"), 1.27 + REF_invokeInterface(9, "invokeinterface"); 1.28 + 1.29 + public final int tag; 1.30 + public final String name; 1.31 + 1.32 + RefKind(int tag, String name) { 1.33 + this.tag = tag; 1.34 + this.name = name; 1.35 + } 1.36 + 1.37 + static RefKind getRefkind(int tag) { 1.38 + switch(tag) { 1.39 + case 1: 1.40 + return REF_getField; 1.41 + case 2: 1.42 + return REF_getStatic; 1.43 + case 3: 1.44 + return REF_putField; 1.45 + case 4: 1.46 + return REF_putStatic; 1.47 + case 5: 1.48 + return REF_invokeVirtual; 1.49 + case 6: 1.50 + return REF_invokeStatic; 1.51 + case 7: 1.52 + return REF_invokeSpecial; 1.53 + case 8: 1.54 + return REF_newInvokeSpecial; 1.55 + case 9: 1.56 + return REF_invokeInterface; 1.57 + default: 1.58 + return null; 1.59 + } 1.60 + } 1.61 + } 1.62 1.63 ConstantPool(ClassReader cr) throws IOException, InvalidEntry { 1.64 int count = cr.readUnsignedShort(); 1.65 @@ -146,11 +194,23 @@ 1.66 pool[i] = new CONSTANT_InterfaceMethodref_info(this, cr); 1.67 break; 1.68 1.69 + case CONSTANT_InvokeDynamic: 1.70 + pool[i] = new CONSTANT_InvokeDynamic_info(this, cr); 1.71 + break; 1.72 + 1.73 case CONSTANT_Long: 1.74 pool[i] = new CONSTANT_Long_info(cr); 1.75 i++; 1.76 break; 1.77 1.78 + case CONSTANT_MethodHandle: 1.79 + pool[i] = new CONSTANT_MethodHandle_info(this, cr); 1.80 + break; 1.81 + 1.82 + case CONSTANT_MethodType: 1.83 + pool[i] = new CONSTANT_MethodType_info(this, cr); 1.84 + break; 1.85 + 1.86 case CONSTANT_Methodref: 1.87 pool[i] = new CONSTANT_Methodref_info(this, cr); 1.88 break; 1.89 @@ -279,9 +339,12 @@ 1.90 R visitFloat(CONSTANT_Float_info info, P p); 1.91 R visitInteger(CONSTANT_Integer_info info, P p); 1.92 R visitInterfaceMethodref(CONSTANT_InterfaceMethodref_info info, P p); 1.93 + R visitInvokeDynamic(CONSTANT_InvokeDynamic_info info, P p); 1.94 R visitLong(CONSTANT_Long_info info, P p); 1.95 R visitNameAndType(CONSTANT_NameAndType_info info, P p); 1.96 R visitMethodref(CONSTANT_Methodref_info info, P p); 1.97 + R visitMethodHandle(CONSTANT_MethodHandle_info info, P p); 1.98 + R visitMethodType(CONSTANT_MethodType_info info, P p); 1.99 R visitString(CONSTANT_String_info info, P p); 1.100 R visitUtf8(CONSTANT_Utf8_info info, P p); 1.101 } 1.102 @@ -548,6 +611,44 @@ 1.103 } 1.104 } 1.105 1.106 + public static class CONSTANT_InvokeDynamic_info extends CPInfo { 1.107 + CONSTANT_InvokeDynamic_info(ConstantPool cp, ClassReader cr) throws IOException { 1.108 + super(cp); 1.109 + bootstrap_method_attr_index = cr.readUnsignedShort(); 1.110 + name_and_type_index = cr.readUnsignedShort(); 1.111 + } 1.112 + 1.113 + public CONSTANT_InvokeDynamic_info(ConstantPool cp, int bootstrap_method_index, int name_and_type_index) { 1.114 + super(cp); 1.115 + this.bootstrap_method_attr_index = bootstrap_method_index; 1.116 + this.name_and_type_index = name_and_type_index; 1.117 + } 1.118 + 1.119 + public int getTag() { 1.120 + return CONSTANT_InvokeDynamic; 1.121 + } 1.122 + 1.123 + public int byteLength() { 1.124 + return 5; 1.125 + } 1.126 + 1.127 + @Override 1.128 + public String toString() { 1.129 + return "CONSTANT_InvokeDynamic_info[bootstrap_method_index: " + bootstrap_method_attr_index + ", name_and_type_index: " + name_and_type_index + "]"; 1.130 + } 1.131 + 1.132 + public <R, D> R accept(Visitor<R, D> visitor, D data) { 1.133 + return visitor.visitInvokeDynamic(this, data); 1.134 + } 1.135 + 1.136 + public CONSTANT_NameAndType_info getNameAndTypeInfo() throws ConstantPoolException { 1.137 + return cp.getNameAndTypeInfo(name_and_type_index); 1.138 + } 1.139 + 1.140 + public final int bootstrap_method_attr_index; 1.141 + public final int name_and_type_index; 1.142 + } 1.143 + 1.144 public static class CONSTANT_Long_info extends CPInfo { 1.145 CONSTANT_Long_info(ClassReader cr) throws IOException { 1.146 value = cr.readLong(); 1.147 @@ -582,6 +683,87 @@ 1.148 public final long value; 1.149 } 1.150 1.151 + public static class CONSTANT_MethodHandle_info extends CPInfo { 1.152 + CONSTANT_MethodHandle_info(ConstantPool cp, ClassReader cr) throws IOException { 1.153 + super(cp); 1.154 + reference_kind = RefKind.getRefkind(cr.readUnsignedByte()); 1.155 + reference_index = cr.readUnsignedShort(); 1.156 + } 1.157 + 1.158 + public CONSTANT_MethodHandle_info(ConstantPool cp, RefKind ref_kind, int member_index) { 1.159 + super(cp); 1.160 + this.reference_kind = ref_kind; 1.161 + this.reference_index = member_index; 1.162 + } 1.163 + 1.164 + public int getTag() { 1.165 + return CONSTANT_MethodHandle; 1.166 + } 1.167 + 1.168 + public int byteLength() { 1.169 + return 4; 1.170 + } 1.171 + 1.172 + @Override 1.173 + public String toString() { 1.174 + return "CONSTANT_MethodHandle_info[ref_kind: " + reference_kind + ", member_index: " + reference_index + "]"; 1.175 + } 1.176 + 1.177 + public <R, D> R accept(Visitor<R, D> visitor, D data) { 1.178 + return visitor.visitMethodHandle(this, data); 1.179 + } 1.180 + 1.181 + public CPRefInfo getCPRefInfo() throws ConstantPoolException { 1.182 + int expected = CONSTANT_Methodref; 1.183 + int actual = cp.get(reference_index).getTag(); 1.184 + // allow these tag types also: 1.185 + switch (actual) { 1.186 + case CONSTANT_Fieldref: 1.187 + case CONSTANT_InterfaceMethodref: 1.188 + expected = actual; 1.189 + } 1.190 + return (CPRefInfo) cp.get(reference_index, expected); 1.191 + } 1.192 + 1.193 + public final RefKind reference_kind; 1.194 + public final int reference_index; 1.195 + } 1.196 + 1.197 + public static class CONSTANT_MethodType_info extends CPInfo { 1.198 + CONSTANT_MethodType_info(ConstantPool cp, ClassReader cr) throws IOException { 1.199 + super(cp); 1.200 + descriptor_index = cr.readUnsignedShort(); 1.201 + } 1.202 + 1.203 + public CONSTANT_MethodType_info(ConstantPool cp, int signature_index) { 1.204 + super(cp); 1.205 + this.descriptor_index = signature_index; 1.206 + } 1.207 + 1.208 + public int getTag() { 1.209 + return CONSTANT_MethodType; 1.210 + } 1.211 + 1.212 + public int byteLength() { 1.213 + return 3; 1.214 + } 1.215 + 1.216 + @Override 1.217 + public String toString() { 1.218 + return "CONSTANT_MethodType_info[signature_index: " + descriptor_index + "]"; 1.219 + } 1.220 + 1.221 + public <R, D> R accept(Visitor<R, D> visitor, D data) { 1.222 + return visitor.visitMethodType(this, data); 1.223 + } 1.224 + 1.225 + public String getType() throws ConstantPoolException { 1.226 + return cp.getUTF8Value(descriptor_index); 1.227 + } 1.228 + 1.229 + public final int descriptor_index; 1.230 + } 1.231 + 1.232 public static class CONSTANT_Methodref_info extends CPRefInfo { 1.233 CONSTANT_Methodref_info(ConstantPool cp, ClassReader cr) throws IOException { 1.234 super(cp, cr, CONSTANT_Methodref); 1.235 @@ -729,5 +911,4 @@ 1.236 public final String value; 1.237 } 1.238 1.239 - 1.240 }