Mercurial > hg > truffle
annotate src/share/vm/interpreter/linkResolver.hpp @ 1407:09e7826ecf01
Can now call to Java code from the VM.
Need to specify a JAR file with the classes from the Maxine subprojects C1X, CRI, and HotSpotVM in the bootclasspath.
See HotSpotVM/README.txt in the Maxine sources for details.
author | Thomas Wuerthinger <thomas.wuerthinger@gmail.com> |
---|---|
date | Tue, 11 May 2010 19:24:14 +0200 |
parents | e66fd840cb6b |
children | 2ffde6cfe049 |
rev | line source |
---|---|
0 | 1 /* |
710 | 2 * Copyright 1997-2009 Sun Microsystems, Inc. All Rights Reserved. |
0 | 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, | |
20 * CA 95054 USA or visit www.sun.com if you need additional information or | |
21 * have any questions. | |
22 * | |
23 */ | |
24 | |
25 // All the necessary definitions for run-time link resolution. | |
26 | |
27 // LinkInfo & its subclasses provide all the information gathered | |
28 // for a particular link after resolving it. A link is any reference | |
29 // made from within the bytecodes of a method to an object outside of | |
30 // that method. If the info is invalid, the link has not been resolved | |
31 // successfully. | |
32 | |
33 class LinkInfo VALUE_OBJ_CLASS_SPEC { | |
34 }; | |
35 | |
36 | |
37 // Link information for getfield/putfield & getstatic/putstatic bytecodes. | |
38 | |
39 class FieldAccessInfo: public LinkInfo { | |
40 protected: | |
41 KlassHandle _klass; | |
42 symbolHandle _name; | |
43 AccessFlags _access_flags; | |
44 int _field_index; // original index in the klass | |
45 int _field_offset; | |
46 BasicType _field_type; | |
47 | |
48 public: | |
49 void set(KlassHandle klass, symbolHandle name, int field_index, int field_offset, | |
50 BasicType field_type, AccessFlags access_flags); | |
51 KlassHandle klass() const { return _klass; } | |
52 symbolHandle name() const { return _name; } | |
53 int field_index() const { return _field_index; } | |
54 int field_offset() const { return _field_offset; } | |
55 BasicType field_type() const { return _field_type; } | |
56 AccessFlags access_flags() const { return _access_flags; } | |
57 | |
58 // debugging | |
59 void print() PRODUCT_RETURN; | |
60 }; | |
61 | |
62 | |
63 // Link information for all calls. | |
64 | |
65 class CallInfo: public LinkInfo { | |
66 private: | |
67 KlassHandle _resolved_klass; // static receiver klass | |
68 KlassHandle _selected_klass; // dynamic receiver class (same as static, or subklass) | |
69 methodHandle _resolved_method; // static target method | |
70 methodHandle _selected_method; // dynamic (actual) target method | |
71 int _vtable_index; // vtable index of selected method | |
72 | |
73 void set_static( KlassHandle resolved_klass, methodHandle resolved_method , TRAPS); | |
74 void set_interface(KlassHandle resolved_klass, KlassHandle selected_klass, methodHandle resolved_method, methodHandle selected_method , TRAPS); | |
75 void set_virtual( KlassHandle resolved_klass, KlassHandle selected_klass, methodHandle resolved_method, methodHandle selected_method, int vtable_index, TRAPS); | |
76 void set_common( KlassHandle resolved_klass, KlassHandle selected_klass, methodHandle resolved_method, methodHandle selected_method, int vtable_index, TRAPS); | |
77 | |
78 friend class LinkResolver; | |
79 | |
80 public: | |
81 KlassHandle resolved_klass() const { return _resolved_klass; } | |
82 KlassHandle selected_klass() const { return _selected_klass; } | |
83 methodHandle resolved_method() const { return _resolved_method; } | |
84 methodHandle selected_method() const { return _selected_method; } | |
85 | |
86 BasicType result_type() const { return selected_method()->result_type(); } | |
87 bool has_vtable_index() const { return _vtable_index >= 0; } | |
88 bool is_statically_bound() const { return _vtable_index == methodOopDesc::nonvirtual_vtable_index; } | |
89 int vtable_index() const { | |
90 // Even for interface calls the vtable index could be non-negative. | |
91 // See CallInfo::set_interface. | |
92 assert(has_vtable_index() || is_statically_bound(), ""); | |
93 return _vtable_index; | |
94 } | |
95 }; | |
96 | |
97 | |
98 // The LinkResolver is used to resolve constant-pool references at run-time. | |
99 // It does all necessary link-time checks & throws exceptions if necessary. | |
100 | |
101 class LinkResolver: AllStatic { | |
102 private: | |
103 static void lookup_method_in_klasses (methodHandle& result, KlassHandle klass, symbolHandle name, symbolHandle signature, TRAPS); | |
104 static void lookup_instance_method_in_klasses (methodHandle& result, KlassHandle klass, symbolHandle name, symbolHandle signature, TRAPS); | |
105 static void lookup_method_in_interfaces (methodHandle& result, KlassHandle klass, symbolHandle name, symbolHandle signature, TRAPS); | |
710 | 106 static void lookup_implicit_method (methodHandle& result, KlassHandle klass, symbolHandle name, symbolHandle signature, TRAPS); |
0 | 107 |
108 static int vtable_index_of_miranda_method(KlassHandle klass, symbolHandle name, symbolHandle signature, TRAPS); | |
109 | |
110 static void resolve_klass (KlassHandle& result, constantPoolHandle pool, int index, TRAPS); | |
111 static void resolve_klass_no_update (KlassHandle& result, constantPoolHandle pool, int index, TRAPS); // no update of constantPool entry | |
112 | |
113 static void resolve_pool (KlassHandle& resolved_klass, symbolHandle& method_name, symbolHandle& method_signature, KlassHandle& current_klass, constantPoolHandle pool, int index, TRAPS); | |
114 | |
115 static void resolve_interface_method(methodHandle& resolved_method, KlassHandle resolved_klass, symbolHandle method_name, symbolHandle method_signature, KlassHandle current_klass, bool check_access, TRAPS); | |
116 static void resolve_method (methodHandle& resolved_method, KlassHandle resolved_klass, symbolHandle method_name, symbolHandle method_signature, KlassHandle current_klass, bool check_access, TRAPS); | |
117 | |
118 static void linktime_resolve_static_method (methodHandle& resolved_method, KlassHandle resolved_klass, symbolHandle method_name, symbolHandle method_signature, KlassHandle current_klass, bool check_access, TRAPS); | |
119 static void linktime_resolve_special_method (methodHandle& resolved_method, KlassHandle resolved_klass, symbolHandle method_name, symbolHandle method_signature, KlassHandle current_klass, bool check_access, TRAPS); | |
120 static void linktime_resolve_virtual_method (methodHandle &resolved_method, KlassHandle resolved_klass, symbolHandle method_name, symbolHandle method_signature,KlassHandle current_klass, bool check_access, TRAPS); | |
121 static void linktime_resolve_interface_method (methodHandle& resolved_method, KlassHandle resolved_klass, symbolHandle method_name, symbolHandle method_signature, KlassHandle current_klass, bool check_access, TRAPS); | |
122 | |
123 static void runtime_resolve_special_method (CallInfo& result, methodHandle resolved_method, KlassHandle resolved_klass, KlassHandle current_klass, bool check_access, TRAPS); | |
124 static void runtime_resolve_virtual_method (CallInfo& result, methodHandle resolved_method, KlassHandle resolved_klass, Handle recv, KlassHandle recv_klass, bool check_null_and_abstract, TRAPS); | |
125 static void runtime_resolve_interface_method (CallInfo& result, methodHandle resolved_method, KlassHandle resolved_klass, Handle recv, KlassHandle recv_klass, bool check_null_and_abstract, TRAPS); | |
126 | |
127 static void check_field_accessability (KlassHandle ref_klass, KlassHandle resolved_klass, KlassHandle sel_klass, fieldDescriptor& fd, TRAPS); | |
128 static void check_method_accessability (KlassHandle ref_klass, KlassHandle resolved_klass, KlassHandle sel_klass, methodHandle sel_method, TRAPS); | |
129 | |
130 public: | |
131 // constant pool resolving | |
132 static void check_klass_accessability(KlassHandle ref_klass, KlassHandle sel_klass, TRAPS); | |
133 | |
134 // static resolving for all calls except interface calls | |
135 static void resolve_method (methodHandle& method_result, KlassHandle& klass_result, constantPoolHandle pool, int index, TRAPS); | |
1135
e66fd840cb6b
6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents:
726
diff
changeset
|
136 static void resolve_dynamic_method (methodHandle& resolved_method, KlassHandle& resolved_klass, constantPoolHandle pool, int index, TRAPS); |
0 | 137 static void resolve_interface_method(methodHandle& method_result, KlassHandle& klass_result, constantPoolHandle pool, int index, TRAPS); |
138 | |
139 // runtime/static resolving for fields | |
140 static void resolve_field(FieldAccessInfo& result, constantPoolHandle pool, int index, Bytecodes::Code byte, bool check_only, TRAPS); | |
141 // takes an extra bool argument "update_pool" to decide whether to update the constantPool during klass resolution. | |
142 static void resolve_field(FieldAccessInfo& result, constantPoolHandle pool, int index, Bytecodes::Code byte, bool check_only, bool update_pool, TRAPS); | |
143 | |
144 // runtime resolving: | |
145 // resolved_klass = specified class (i.e., static receiver class) | |
146 // current_klass = sending method holder (i.e., class containing the method containing the call being resolved) | |
147 static void resolve_static_call (CallInfo& result, KlassHandle& resolved_klass, symbolHandle method_name, symbolHandle method_signature, KlassHandle current_klass, bool check_access, bool initialize_klass, TRAPS); | |
148 static void resolve_special_call (CallInfo& result, KlassHandle resolved_klass, symbolHandle method_name, symbolHandle method_signature, KlassHandle current_klass, bool check_access, TRAPS); | |
149 static void resolve_virtual_call (CallInfo& result, Handle recv, KlassHandle recv_klass, KlassHandle resolved_klass, symbolHandle method_name, symbolHandle method_signature, KlassHandle current_klass, bool check_access, bool check_null_and_abstract, TRAPS); | |
150 static void resolve_interface_call(CallInfo& result, Handle recv, KlassHandle recv_klass, KlassHandle resolved_klass, symbolHandle method_name, symbolHandle method_signature, KlassHandle current_klass, bool check_access, bool check_null_and_abstract, TRAPS); | |
151 | |
152 // same as above for compile-time resolution; but returns null handle instead of throwing an exception on error | |
153 // also, does not initialize klass (i.e., no side effects) | |
154 static methodHandle resolve_virtual_call_or_null (KlassHandle receiver_klass, KlassHandle resolved_klass, symbolHandle method_name, symbolHandle method_signature, KlassHandle current_klass); | |
155 static methodHandle resolve_interface_call_or_null(KlassHandle receiver_klass, KlassHandle resolved_klass, symbolHandle method_name, symbolHandle method_signature, KlassHandle current_klass); | |
156 static methodHandle resolve_static_call_or_null (KlassHandle resolved_klass, symbolHandle method_name, symbolHandle method_signature, KlassHandle current_klass); | |
157 static methodHandle resolve_special_call_or_null (KlassHandle resolved_klass, symbolHandle method_name, symbolHandle method_signature, KlassHandle current_klass); | |
158 | |
159 // same as above for compile-time resolution; returns vtable_index if current_klass if linked | |
160 static int resolve_virtual_vtable_index (KlassHandle receiver_klass, KlassHandle resolved_klass, symbolHandle method_name, symbolHandle method_signature, KlassHandle current_klass); | |
161 | |
162 // static resolving for compiler (does not throw exceptions, returns null handle if unsuccessful) | |
163 static methodHandle linktime_resolve_virtual_method_or_null (KlassHandle resolved_klass, symbolHandle method_name, symbolHandle method_signature, KlassHandle current_klass, bool check_access); | |
164 static methodHandle linktime_resolve_interface_method_or_null(KlassHandle resolved_klass, symbolHandle method_name, symbolHandle method_signature, KlassHandle current_klass, bool check_access); | |
165 | |
166 // runtime resolving from constant pool | |
167 static void resolve_invokestatic (CallInfo& result, constantPoolHandle pool, int index, TRAPS); | |
168 static void resolve_invokespecial (CallInfo& result, constantPoolHandle pool, int index, TRAPS); | |
169 static void resolve_invokevirtual (CallInfo& result, Handle recv, constantPoolHandle pool, int index, TRAPS); | |
170 static void resolve_invokeinterface(CallInfo& result, Handle recv, constantPoolHandle pool, int index, TRAPS); | |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
710
diff
changeset
|
171 static void resolve_invokedynamic (CallInfo& result, constantPoolHandle pool, int index, TRAPS); |
0 | 172 |
173 static void resolve_invoke (CallInfo& result, Handle recv, constantPoolHandle pool, int index, Bytecodes::Code byte, TRAPS); | |
174 }; |