1 /*
2 * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
33 import sun.jvm.hotspot.runtime.*;
34 import sun.jvm.hotspot.types.*;
35 import sun.jvm.hotspot.utilities.*;
36
37 public class ConstMethod extends Oop {
38 static {
39 VM.registerVMInitializedObserver(new Observer() {
40 public void update(Observable o, Object data) {
41 initialize(VM.getVM().getTypeDataBase());
42 }
43 });
44 }
45
46 // anon-enum constants for _flags.
47 private static int HAS_LINENUMBER_TABLE;
48 private static int HAS_CHECKED_EXCEPTIONS;
49 private static int HAS_LOCALVARIABLE_TABLE;
50
51 private static synchronized void initialize(TypeDataBase db) throws WrongTypeException {
52 Type type = db.lookupType("constMethodOopDesc");
53 // Backpointer to non-const methodOop
54 method = new OopField(type.getOopField("_method"), 0);
55 // The exception handler table. 4-tuples of ints [start_pc, end_pc,
56 // handler_pc, catch_type index] For methods with no exceptions the
57 // table is pointing to Universe::the_empty_int_array
58 exceptionTable = new OopField(type.getOopField("_exception_table"), 0);
59 constMethodSize = new CIntField(type.getCIntegerField("_constMethod_size"), 0);
60 flags = new ByteField(type.getJByteField("_flags"), 0);
61
62 // enum constants for flags
63 HAS_LINENUMBER_TABLE = db.lookupIntConstant("constMethodOopDesc::_has_linenumber_table").intValue();
64 HAS_CHECKED_EXCEPTIONS = db.lookupIntConstant("constMethodOopDesc::_has_checked_exceptions").intValue();
65 HAS_LOCALVARIABLE_TABLE = db.lookupIntConstant("constMethodOopDesc::_has_localvariable_table").intValue();
66
67 // Size of Java bytecodes allocated immediately after constMethodOop.
68 codeSize = new CIntField(type.getCIntegerField("_code_size"), 0);
69 nameIndex = new CIntField(type.getCIntegerField("_name_index"), 0);
70 signatureIndex = new CIntField(type.getCIntegerField("_signature_index"), 0);
71 genericSignatureIndex = new CIntField(type.getCIntegerField("_generic_signature_index"),0);
72
73 // start of byte code
74 bytecodeOffset = type.getSize();
75
76 type = db.lookupType("CheckedExceptionElement");
77 checkedExceptionElementSize = type.getSize();
78
79 type = db.lookupType("LocalVariableTableElement");
80 localVariableTableElementSize = type.getSize();
81 }
82
83 ConstMethod(OopHandle handle, ObjectHeap heap) {
84 super(handle, heap);
85 }
86
87 // Fields
88 private static OopField method;
89 private static OopField exceptionTable;
90 private static CIntField constMethodSize;
91 private static ByteField flags;
92 private static CIntField codeSize;
93 private static CIntField nameIndex;
94 private static CIntField signatureIndex;
95 private static CIntField genericSignatureIndex;
96
97 // start of bytecode
98 private static long bytecodeOffset;
99
100 private static long checkedExceptionElementSize;
101 private static long localVariableTableElementSize;
102
103 // Accessors for declared fields
104 public Method getMethod() {
105 return (Method) method.getValue(this);
106 }
107
108 public TypeArray getExceptionTable() {
109 return (TypeArray) exceptionTable.getValue(this);
110 }
111
112 public long getConstMethodSize() {
113 return constMethodSize.getValue(this);
114 }
115
116 public byte getFlags() {
117 return flags.getValue(this);
118 }
119
120 public long getCodeSize() {
121 return codeSize.getValue(this);
122 }
123
124 public long getNameIndex() {
125 return nameIndex.getValue(this);
126 }
127
128 public long getSignatureIndex() {
129 return signatureIndex.getValue(this);
130 }
131
132 public long getGenericSignatureIndex() {
133 return genericSignatureIndex.getValue(this);
134 }
135
136 public Symbol getName() {
137 return getMethod().getName();
138 }
139
140 public Symbol getSignature() {
141 return getMethod().getSignature();
142 }
143
144 public Symbol getGenericSignature() {
145 return getMethod().getGenericSignature();
146 }
147
148 // bytecode accessors
149
150 /** Get a bytecode or breakpoint at the given bci */
151 public int getBytecodeOrBPAt(int bci) {
152 return getHandle().getJByteAt(bytecodeOffset + bci) & 0xFF;
153 }
154
155 public byte getBytecodeByteArg(int bci) {
206 byte[] bc = new byte[ (int) getCodeSize() ];
207 for( int i=0; i < bc.length; i++ )
208 {
209 long offs = bytecodeOffset + i;
210 bc[i] = getHandle().getJByteAt( offs );
211 }
212 return bc;
213 }
214
215 public long getObjectSize() {
216 return getConstMethodSize() * getHeap().getOopSize();
217 }
218
219 public void printValueOn(PrintStream tty) {
220 tty.print("ConstMethod " + getName().asString() + getSignature().asString() + "@" + getHandle());
221 }
222
223 public void iterateFields(OopVisitor visitor, boolean doVMFields) {
224 super.iterateFields(visitor, doVMFields);
225 if (doVMFields) {
226 visitor.doOop(method, true);
227 visitor.doOop(exceptionTable, true);
228 visitor.doCInt(constMethodSize, true);
229 visitor.doByte(flags, true);
230 visitor.doCInt(codeSize, true);
231 visitor.doCInt(nameIndex, true);
232 visitor.doCInt(signatureIndex, true);
233 visitor.doCInt(genericSignatureIndex, true);
234 visitor.doCInt(codeSize, true);
235 }
236 }
237
238 // Accessors
239
240 public boolean hasLineNumberTable() {
241 return (getFlags() & HAS_LINENUMBER_TABLE) != 0;
242 }
243
244 public int getLineNumberFromBCI(int bci) {
245 if (!VM.getVM().isCore()) {
246 if (bci == DebugInformationRecorder.SYNCHRONIZATION_ENTRY_BCI) bci = 0;
|
1 /*
2 * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
33 import sun.jvm.hotspot.runtime.*;
34 import sun.jvm.hotspot.types.*;
35 import sun.jvm.hotspot.utilities.*;
36
37 public class ConstMethod extends Oop {
38 static {
39 VM.registerVMInitializedObserver(new Observer() {
40 public void update(Observable o, Object data) {
41 initialize(VM.getVM().getTypeDataBase());
42 }
43 });
44 }
45
46 // anon-enum constants for _flags.
47 private static int HAS_LINENUMBER_TABLE;
48 private static int HAS_CHECKED_EXCEPTIONS;
49 private static int HAS_LOCALVARIABLE_TABLE;
50
51 private static synchronized void initialize(TypeDataBase db) throws WrongTypeException {
52 Type type = db.lookupType("constMethodOopDesc");
53 constants = new OopField(type.getOopField("_constants"), 0);
54 // The exception handler table. 4-tuples of ints [start_pc, end_pc,
55 // handler_pc, catch_type index] For methods with no exceptions the
56 // table is pointing to Universe::the_empty_int_array
57 exceptionTable = new OopField(type.getOopField("_exception_table"), 0);
58 constMethodSize = new CIntField(type.getCIntegerField("_constMethod_size"), 0);
59 flags = new ByteField(type.getJByteField("_flags"), 0);
60
61 // enum constants for flags
62 HAS_LINENUMBER_TABLE = db.lookupIntConstant("constMethodOopDesc::_has_linenumber_table").intValue();
63 HAS_CHECKED_EXCEPTIONS = db.lookupIntConstant("constMethodOopDesc::_has_checked_exceptions").intValue();
64 HAS_LOCALVARIABLE_TABLE = db.lookupIntConstant("constMethodOopDesc::_has_localvariable_table").intValue();
65
66 // Size of Java bytecodes allocated immediately after constMethodOop.
67 codeSize = new CIntField(type.getCIntegerField("_code_size"), 0);
68 nameIndex = new CIntField(type.getCIntegerField("_name_index"), 0);
69 signatureIndex = new CIntField(type.getCIntegerField("_signature_index"), 0);
70 genericSignatureIndex = new CIntField(type.getCIntegerField("_generic_signature_index"),0);
71 idnum = new CIntField(type.getCIntegerField("_method_idnum"), 0);
72
73 // start of byte code
74 bytecodeOffset = type.getSize();
75
76 type = db.lookupType("CheckedExceptionElement");
77 checkedExceptionElementSize = type.getSize();
78
79 type = db.lookupType("LocalVariableTableElement");
80 localVariableTableElementSize = type.getSize();
81 }
82
83 ConstMethod(OopHandle handle, ObjectHeap heap) {
84 super(handle, heap);
85 }
86
87 // Fields
88 private static OopField constants;
89 private static OopField exceptionTable;
90 private static CIntField constMethodSize;
91 private static ByteField flags;
92 private static CIntField codeSize;
93 private static CIntField nameIndex;
94 private static CIntField signatureIndex;
95 private static CIntField genericSignatureIndex;
96 private static CIntField idnum;
97
98 // start of bytecode
99 private static long bytecodeOffset;
100
101 private static long checkedExceptionElementSize;
102 private static long localVariableTableElementSize;
103
104 public Method getMethod() {
105 InstanceKlass ik = (InstanceKlass)getConstants().getPoolHolder();
106 ObjArray methods = ik.getMethods();
107 return (Method)methods.getObjAt(getIdNum());
108 }
109
110 // Accessors for declared fields
111 public ConstantPool getConstants() {
112 return (ConstantPool) constants.getValue(this);
113 }
114
115 public TypeArray getExceptionTable() {
116 return (TypeArray) exceptionTable.getValue(this);
117 }
118
119 public long getConstMethodSize() {
120 return constMethodSize.getValue(this);
121 }
122
123 public byte getFlags() {
124 return flags.getValue(this);
125 }
126
127 public long getCodeSize() {
128 return codeSize.getValue(this);
129 }
130
131 public long getNameIndex() {
132 return nameIndex.getValue(this);
133 }
134
135 public long getSignatureIndex() {
136 return signatureIndex.getValue(this);
137 }
138
139 public long getGenericSignatureIndex() {
140 return genericSignatureIndex.getValue(this);
141 }
142
143 public long getIdNum() {
144 return idnum.getValue(this);
145 }
146
147 public Symbol getName() {
148 return getMethod().getName();
149 }
150
151 public Symbol getSignature() {
152 return getMethod().getSignature();
153 }
154
155 public Symbol getGenericSignature() {
156 return getMethod().getGenericSignature();
157 }
158
159 // bytecode accessors
160
161 /** Get a bytecode or breakpoint at the given bci */
162 public int getBytecodeOrBPAt(int bci) {
163 return getHandle().getJByteAt(bytecodeOffset + bci) & 0xFF;
164 }
165
166 public byte getBytecodeByteArg(int bci) {
217 byte[] bc = new byte[ (int) getCodeSize() ];
218 for( int i=0; i < bc.length; i++ )
219 {
220 long offs = bytecodeOffset + i;
221 bc[i] = getHandle().getJByteAt( offs );
222 }
223 return bc;
224 }
225
226 public long getObjectSize() {
227 return getConstMethodSize() * getHeap().getOopSize();
228 }
229
230 public void printValueOn(PrintStream tty) {
231 tty.print("ConstMethod " + getName().asString() + getSignature().asString() + "@" + getHandle());
232 }
233
234 public void iterateFields(OopVisitor visitor, boolean doVMFields) {
235 super.iterateFields(visitor, doVMFields);
236 if (doVMFields) {
237 visitor.doOop(constants, true);
238 visitor.doOop(exceptionTable, true);
239 visitor.doCInt(constMethodSize, true);
240 visitor.doByte(flags, true);
241 visitor.doCInt(codeSize, true);
242 visitor.doCInt(nameIndex, true);
243 visitor.doCInt(signatureIndex, true);
244 visitor.doCInt(genericSignatureIndex, true);
245 visitor.doCInt(codeSize, true);
246 }
247 }
248
249 // Accessors
250
251 public boolean hasLineNumberTable() {
252 return (getFlags() & HAS_LINENUMBER_TABLE) != 0;
253 }
254
255 public int getLineNumberFromBCI(int bci) {
256 if (!VM.getVM().isCore()) {
257 if (bci == DebugInformationRecorder.SYNCHRONIZATION_ENTRY_BCI) bci = 0;
|