1 /*
2 * Copyright (c) 2000, 2011, 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 *
31 import sun.jvm.hotspot.interpreter.*;
32 import sun.jvm.hotspot.memory.*;
33 import sun.jvm.hotspot.runtime.*;
34 import sun.jvm.hotspot.types.*;
35 import sun.jvm.hotspot.utilities.*;
36
37 // A Method represents a Java method
38
39 public class Method extends Oop {
40 static {
41 VM.registerVMInitializedObserver(new Observer() {
42 public void update(Observable o, Object data) {
43 initialize(VM.getVM().getTypeDataBase());
44 }
45 });
46 }
47
48 private static synchronized void initialize(TypeDataBase db) throws WrongTypeException {
49 Type type = db.lookupType("methodOopDesc");
50 constMethod = new OopField(type.getOopField("_constMethod"), 0);
51 constants = new OopField(type.getOopField("_constants"), 0);
52 methodData = new OopField(type.getOopField("_method_data"), 0);
53 methodSize = new CIntField(type.getCIntegerField("_method_size"), 0);
54 maxStack = new CIntField(type.getCIntegerField("_max_stack"), 0);
55 maxLocals = new CIntField(type.getCIntegerField("_max_locals"), 0);
56 sizeOfParameters = new CIntField(type.getCIntegerField("_size_of_parameters"), 0);
57 accessFlags = new CIntField(type.getCIntegerField("_access_flags"), 0);
58 code = type.getAddressField("_code");
59 vtableIndex = new CIntField(type.getCIntegerField("_vtable_index"), 0);
60 if (!VM.getVM().isCore()) {
61 invocationCounter = new CIntField(type.getCIntegerField("_invocation_counter"), 0);
62 backedgeCounter = new CIntField(type.getCIntegerField("_backedge_counter"), 0);
63 }
64 bytecodeOffset = type.getSize();
65
66 interpreterThrowoutCountField = new CIntField(type.getCIntegerField("_interpreter_throwout_count"), 0);
67 interpreterInvocationCountField = new CIntField(type.getCIntegerField("_interpreter_invocation_count"), 0);
68
69 /*
70 interpreterEntry = type.getAddressField("_interpreter_entry");
71 fromCompiledCodeEntryPoint = type.getAddressField("_from_compiled_code_entry_point");
72
73 */
74 objectInitializerName = null;
75 classInitializerName = null;
76 }
77
78 Method(OopHandle handle, ObjectHeap heap) {
79 super(handle, heap);
80 }
81
82 public boolean isMethod() { return true; }
83
84 // Fields
85 private static OopField constMethod;
86 private static OopField constants;
87 private static OopField methodData;
88 private static CIntField methodSize;
89 private static CIntField maxStack;
90 private static CIntField maxLocals;
91 private static CIntField sizeOfParameters;
92 private static CIntField accessFlags;
93 private static CIntField vtableIndex;
94 private static CIntField invocationCounter;
95 private static CIntField backedgeCounter;
96 private static long bytecodeOffset;
97
98 private static AddressField code;
99
100 private static CIntField interpreterThrowoutCountField;
101 private static CIntField interpreterInvocationCountField;
102
103 // constant method names - <init>, <clinit>
104 // Initialized lazily to avoid initialization ordering dependencies between Method and SymbolTable
105 private static Symbol objectInitializerName;
106 private static Symbol classInitializerName;
108 if (objectInitializerName == null) {
109 objectInitializerName = VM.getVM().getSymbolTable().probe("<init>");
110 }
111 return objectInitializerName;
112 }
113 private static Symbol classInitializerName() {
114 if (classInitializerName == null) {
115 classInitializerName = VM.getVM().getSymbolTable().probe("<clinit>");
116 }
117 return classInitializerName;
118 }
119
120
121 /*
122 private static AddressCField interpreterEntry;
123 private static AddressCField fromCompiledCodeEntryPoint;
124 */
125
126 // Accessors for declared fields
127 public ConstMethod getConstMethod() { return (ConstMethod) constMethod.getValue(this); }
128 public ConstantPool getConstants() { return (ConstantPool) constants.getValue(this); }
129 public MethodData getMethodData() { return (MethodData) methodData.getValue(this); }
130 public TypeArray getExceptionTable() { return getConstMethod().getExceptionTable(); }
131 /** WARNING: this is in words, not useful in this system; use getObjectSize() instead */
132 public long getMethodSize() { return methodSize.getValue(this); }
133 public long getMaxStack() { return maxStack.getValue(this); }
134 public long getMaxLocals() { return maxLocals.getValue(this); }
135 public long getSizeOfParameters() { return sizeOfParameters.getValue(this); }
136 public long getNameIndex() { return getConstMethod().getNameIndex(); }
137 public long getSignatureIndex() { return getConstMethod().getSignatureIndex(); }
138 public long getGenericSignatureIndex() { return getConstMethod().getGenericSignatureIndex(); }
139 public long getAccessFlags() { return accessFlags.getValue(this); }
140 public long getCodeSize() { return getConstMethod().getCodeSize(); }
141 public long getVtableIndex() { return vtableIndex.getValue(this); }
142 public long getInvocationCounter() {
143 if (Assert.ASSERTS_ENABLED) {
144 Assert.that(!VM.getVM().isCore(), "must not be used in core build");
145 }
146 return invocationCounter.getValue(this);
147 }
148 public long getBackedgeCounter() {
264 }
265
266 public OopMapCacheEntry getMaskFor(int bci) {
267 OopMapCacheEntry entry = new OopMapCacheEntry();
268 entry.fill(this, bci);
269 return entry;
270 }
271
272 public long getObjectSize() {
273 return getMethodSize() * getHeap().getOopSize();
274 }
275
276 public void printValueOn(PrintStream tty) {
277 tty.print("Method " + getName().asString() + getSignature().asString() + "@" + getHandle());
278 }
279
280 public void iterateFields(OopVisitor visitor, boolean doVMFields) {
281 super.iterateFields(visitor, doVMFields);
282 if (doVMFields) {
283 visitor.doOop(constMethod, true);
284 visitor.doOop(constants, true);
285 visitor.doCInt(methodSize, true);
286 visitor.doCInt(maxStack, true);
287 visitor.doCInt(maxLocals, true);
288 visitor.doCInt(sizeOfParameters, true);
289 visitor.doCInt(accessFlags, true);
290 }
291 }
292
293 public boolean hasLineNumberTable() {
294 return getConstMethod().hasLineNumberTable();
295 }
296
297 public int getLineNumberFromBCI(int bci) {
298 return getConstMethod().getLineNumberFromBCI(bci);
299 }
300
301 public LineNumberTableElement[] getLineNumberTable() {
302 return getConstMethod().getLineNumberTable();
303 }
304
|
1 /*
2 * Copyright (c) 2000, 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 *
31 import sun.jvm.hotspot.interpreter.*;
32 import sun.jvm.hotspot.memory.*;
33 import sun.jvm.hotspot.runtime.*;
34 import sun.jvm.hotspot.types.*;
35 import sun.jvm.hotspot.utilities.*;
36
37 // A Method represents a Java method
38
39 public class Method extends Oop {
40 static {
41 VM.registerVMInitializedObserver(new Observer() {
42 public void update(Observable o, Object data) {
43 initialize(VM.getVM().getTypeDataBase());
44 }
45 });
46 }
47
48 private static synchronized void initialize(TypeDataBase db) throws WrongTypeException {
49 Type type = db.lookupType("methodOopDesc");
50 constMethod = new OopField(type.getOopField("_constMethod"), 0);
51 methodData = new OopField(type.getOopField("_method_data"), 0);
52 methodSize = new CIntField(type.getCIntegerField("_method_size"), 0);
53 maxStack = new CIntField(type.getCIntegerField("_max_stack"), 0);
54 maxLocals = new CIntField(type.getCIntegerField("_max_locals"), 0);
55 sizeOfParameters = new CIntField(type.getCIntegerField("_size_of_parameters"), 0);
56 accessFlags = new CIntField(type.getCIntegerField("_access_flags"), 0);
57 code = type.getAddressField("_code");
58 vtableIndex = new CIntField(type.getCIntegerField("_vtable_index"), 0);
59 if (!VM.getVM().isCore()) {
60 invocationCounter = new CIntField(type.getCIntegerField("_invocation_counter"), 0);
61 backedgeCounter = new CIntField(type.getCIntegerField("_backedge_counter"), 0);
62 }
63 bytecodeOffset = type.getSize();
64
65 interpreterThrowoutCountField = new CIntField(type.getCIntegerField("_interpreter_throwout_count"), 0);
66 interpreterInvocationCountField = new CIntField(type.getCIntegerField("_interpreter_invocation_count"), 0);
67
68 /*
69 interpreterEntry = type.getAddressField("_interpreter_entry");
70 fromCompiledCodeEntryPoint = type.getAddressField("_from_compiled_code_entry_point");
71
72 */
73 objectInitializerName = null;
74 classInitializerName = null;
75 }
76
77 Method(OopHandle handle, ObjectHeap heap) {
78 super(handle, heap);
79 }
80
81 public boolean isMethod() { return true; }
82
83 // Fields
84 private static OopField constMethod;
85 private static OopField methodData;
86 private static CIntField methodSize;
87 private static CIntField maxStack;
88 private static CIntField maxLocals;
89 private static CIntField sizeOfParameters;
90 private static CIntField accessFlags;
91 private static CIntField vtableIndex;
92 private static CIntField invocationCounter;
93 private static CIntField backedgeCounter;
94 private static long bytecodeOffset;
95
96 private static AddressField code;
97
98 private static CIntField interpreterThrowoutCountField;
99 private static CIntField interpreterInvocationCountField;
100
101 // constant method names - <init>, <clinit>
102 // Initialized lazily to avoid initialization ordering dependencies between Method and SymbolTable
103 private static Symbol objectInitializerName;
104 private static Symbol classInitializerName;
106 if (objectInitializerName == null) {
107 objectInitializerName = VM.getVM().getSymbolTable().probe("<init>");
108 }
109 return objectInitializerName;
110 }
111 private static Symbol classInitializerName() {
112 if (classInitializerName == null) {
113 classInitializerName = VM.getVM().getSymbolTable().probe("<clinit>");
114 }
115 return classInitializerName;
116 }
117
118
119 /*
120 private static AddressCField interpreterEntry;
121 private static AddressCField fromCompiledCodeEntryPoint;
122 */
123
124 // Accessors for declared fields
125 public ConstMethod getConstMethod() { return (ConstMethod) constMethod.getValue(this); }
126 public ConstantPool getConstants() {
127 return getConstMethod().getConstants();
128 }
129 public MethodData getMethodData() { return (MethodData) methodData.getValue(this); }
130 public TypeArray getExceptionTable() { return getConstMethod().getExceptionTable(); }
131 /** WARNING: this is in words, not useful in this system; use getObjectSize() instead */
132 public long getMethodSize() { return methodSize.getValue(this); }
133 public long getMaxStack() { return maxStack.getValue(this); }
134 public long getMaxLocals() { return maxLocals.getValue(this); }
135 public long getSizeOfParameters() { return sizeOfParameters.getValue(this); }
136 public long getNameIndex() { return getConstMethod().getNameIndex(); }
137 public long getSignatureIndex() { return getConstMethod().getSignatureIndex(); }
138 public long getGenericSignatureIndex() { return getConstMethod().getGenericSignatureIndex(); }
139 public long getAccessFlags() { return accessFlags.getValue(this); }
140 public long getCodeSize() { return getConstMethod().getCodeSize(); }
141 public long getVtableIndex() { return vtableIndex.getValue(this); }
142 public long getInvocationCounter() {
143 if (Assert.ASSERTS_ENABLED) {
144 Assert.that(!VM.getVM().isCore(), "must not be used in core build");
145 }
146 return invocationCounter.getValue(this);
147 }
148 public long getBackedgeCounter() {
264 }
265
266 public OopMapCacheEntry getMaskFor(int bci) {
267 OopMapCacheEntry entry = new OopMapCacheEntry();
268 entry.fill(this, bci);
269 return entry;
270 }
271
272 public long getObjectSize() {
273 return getMethodSize() * getHeap().getOopSize();
274 }
275
276 public void printValueOn(PrintStream tty) {
277 tty.print("Method " + getName().asString() + getSignature().asString() + "@" + getHandle());
278 }
279
280 public void iterateFields(OopVisitor visitor, boolean doVMFields) {
281 super.iterateFields(visitor, doVMFields);
282 if (doVMFields) {
283 visitor.doOop(constMethod, true);
284 visitor.doCInt(methodSize, true);
285 visitor.doCInt(maxStack, true);
286 visitor.doCInt(maxLocals, true);
287 visitor.doCInt(sizeOfParameters, true);
288 visitor.doCInt(accessFlags, true);
289 }
290 }
291
292 public boolean hasLineNumberTable() {
293 return getConstMethod().hasLineNumberTable();
294 }
295
296 public int getLineNumberFromBCI(int bci) {
297 return getConstMethod().getLineNumberFromBCI(bci);
298 }
299
300 public LineNumberTableElement[] getLineNumberTable() {
301 return getConstMethod().getLineNumberTable();
302 }
303
|