Mercurial > hg > truffle
comparison src/share/vm/graal/graalVMEntries.cpp @ 3685:5c8fc9f05960
Merge
author | Lukas Stadler <lukas.stadler@jku.at> |
---|---|
date | Fri, 18 Nov 2011 13:34:10 +0100 |
parents | 345c3bbf9c3c 8c46cdb684d4 |
children | 7958ebb561b0 |
comparison
equal
deleted
inserted
replaced
3684:1976ebe361c2 | 3685:5c8fc9f05960 |
---|---|
20 * or visit www.oracle.com if you need additional information or have any | 20 * or visit www.oracle.com if you need additional information or have any |
21 * questions. | 21 * questions. |
22 */ | 22 */ |
23 | 23 |
24 #include "precompiled.hpp" | 24 #include "precompiled.hpp" |
25 #include "runtime/fieldDescriptor.hpp" | |
25 #include "c1/c1_Runtime1.hpp" | 26 #include "c1/c1_Runtime1.hpp" |
26 #include "ci/ciMethodData.hpp" | 27 #include "ci/ciMethodData.hpp" |
27 #include "compiler/compileBroker.hpp" | 28 #include "compiler/compileBroker.hpp" |
28 #include "graal/graalVMEntries.hpp" | 29 #include "graal/graalVMEntries.hpp" |
29 #include "graal/graalCompiler.hpp" | 30 #include "graal/graalCompiler.hpp" |
31 #include "graal/graalEnv.hpp" | |
30 #include "graal/graalJavaAccess.hpp" | 32 #include "graal/graalJavaAccess.hpp" |
31 #include "graal/graalCodeInstaller.hpp" | 33 #include "graal/graalCodeInstaller.hpp" |
32 #include "graal/graalVMExits.hpp" | 34 #include "graal/graalVMExits.hpp" |
33 #include "graal/graalVmIds.hpp" | 35 #include "graal/graalVmIds.hpp" |
34 #include "memory/oopFactory.hpp" | 36 #include "memory/oopFactory.hpp" |
37 methodOop getMethodFromHotSpotMethod(jobject hotspot_method) { | 39 methodOop getMethodFromHotSpotMethod(jobject hotspot_method) { |
38 return getMethodFromHotSpotMethod(JNIHandles::resolve(hotspot_method)); | 40 return getMethodFromHotSpotMethod(JNIHandles::resolve(hotspot_method)); |
39 } | 41 } |
40 | 42 |
41 methodOop getMethodFromHotSpotMethod(oop hotspot_method) { | 43 methodOop getMethodFromHotSpotMethod(oop hotspot_method) { |
42 oop reflected = HotSpotMethodResolved::javaMirror(hotspot_method); | 44 return (methodOop)HotSpotMethodResolved::javaMirror(hotspot_method); |
43 assert(reflected != NULL, "NULL not expected"); | |
44 return (methodOop)reflected; | |
45 | |
46 // (tw) Cannot use reflection code, because then the compiler can dead lock with the user application (test using -Xcomp). | |
47 /* | |
48 // method is a handle to a java.lang.reflect.Method object | |
49 oop mirror = NULL; | |
50 int slot = 0; | |
51 | |
52 if (reflected->klass() == SystemDictionary::reflect_Constructor_klass()) { | |
53 mirror = java_lang_reflect_Constructor::clazz(reflected); | |
54 slot = java_lang_reflect_Constructor::slot(reflected); | |
55 } else { | |
56 assert(reflected->klass() == SystemDictionary::reflect_Method_klass(), "wrong type"); | |
57 mirror = java_lang_reflect_Method::clazz(reflected); | |
58 slot = java_lang_reflect_Method::slot(reflected); | |
59 } | |
60 klassOop k = java_lang_Class::as_klassOop(mirror); | |
61 | |
62 // Make sure class is initialized before handing id's out to methods | |
63 // assert(instanceKlass::cast(k)->is_initialized(), "only initialized classes expected"); | |
64 methodOop m = instanceKlass::cast(k)->method_with_idnum(slot); | |
65 assert(m != NULL, "deleted method?"); | |
66 return m;*/ | |
67 } | |
68 | |
69 oop getReflectedMethod(methodOop method, TRAPS) { | |
70 assert(method != NULL, "NULL not expected"); | |
71 | |
72 if (!method->is_initializer() || method->is_static()) { | |
73 return Reflection::new_method(method, true, true, CHECK_NULL); | |
74 } else { | |
75 return Reflection::new_constructor(method, CHECK_NULL); | |
76 } | |
77 } | 45 } |
78 | 46 |
79 // public byte[] RiMethod_code(HotSpotResolvedMethod method); | 47 // public byte[] RiMethod_code(HotSpotResolvedMethod method); |
80 JNIEXPORT jbyteArray JNICALL Java_com_oracle_graal_hotspot_VMEntries_RiMethod_1code(JNIEnv *env, jobject, jobject hotspot_method) { | 48 JNIEXPORT jbyteArray JNICALL Java_com_oracle_graal_hotspot_VMEntries_RiMethod_1code(JNIEnv *env, jobject, jobject hotspot_method) { |
81 TRACE_graal_3("VMEntries::RiMethod_code"); | 49 TRACE_graal_3("VMEntries::RiMethod_code"); |
97 | 65 |
98 // public RiExceptionHandler[] RiMethod_exceptionHandlers(long vmId); | 66 // public RiExceptionHandler[] RiMethod_exceptionHandlers(long vmId); |
99 JNIEXPORT jobjectArray JNICALL Java_com_oracle_graal_hotspot_VMEntries_RiMethod_1exceptionHandlers(JNIEnv *, jobject, jobject hotspot_method) { | 67 JNIEXPORT jobjectArray JNICALL Java_com_oracle_graal_hotspot_VMEntries_RiMethod_1exceptionHandlers(JNIEnv *, jobject, jobject hotspot_method) { |
100 TRACE_graal_3("VMEntries::RiMethod_exceptionHandlers"); | 68 TRACE_graal_3("VMEntries::RiMethod_exceptionHandlers"); |
101 VM_ENTRY_MARK | 69 VM_ENTRY_MARK |
70 ResourceMark rm; | |
102 methodHandle method = getMethodFromHotSpotMethod(hotspot_method); | 71 methodHandle method = getMethodFromHotSpotMethod(hotspot_method); |
103 typeArrayHandle handlers = method->exception_table(); | 72 typeArrayHandle handlers = method->exception_table(); |
104 int handler_count = handlers.is_null() ? 0 : handlers->length() / 4; | 73 int handler_count = handlers.is_null() ? 0 : handlers->length() / 4; |
105 | 74 |
106 instanceKlass::cast(HotSpotExceptionHandler::klass())->initialize(CHECK_NULL); | 75 instanceKlass::cast(HotSpotExceptionHandler::klass())->initialize(CHECK_NULL); |
118 | 87 |
119 if (catch_class_index == 0) { | 88 if (catch_class_index == 0) { |
120 HotSpotExceptionHandler::set_catchClass(entry, NULL); | 89 HotSpotExceptionHandler::set_catchClass(entry, NULL); |
121 } else { | 90 } else { |
122 constantPoolOop cp = instanceKlass::cast(method->method_holder())->constants(); | 91 constantPoolOop cp = instanceKlass::cast(method->method_holder())->constants(); |
123 ciInstanceKlass* loading_klass = (ciInstanceKlass *) CURRENT_ENV->get_object(method->method_holder()); | 92 KlassHandle loading_klass = method->method_holder(); |
124 bool is_accessible = false; | 93 Handle catch_class = GraalCompiler::get_RiType(cp, catch_class_index, loading_klass, CHECK_NULL); |
125 ciKlass *klass = CURRENT_ENV->get_klass_by_index(cp, catch_class_index, is_accessible, loading_klass); | 94 HotSpotExceptionHandler::set_catchClass(entry, catch_class()); |
126 oop catch_class = GraalCompiler::get_RiType(klass, method->method_holder(), CHECK_NULL); | |
127 | |
128 HotSpotExceptionHandler::set_catchClass(entry, catch_class); | |
129 } | 95 } |
130 array->obj_at_put(i, entry()); | 96 array->obj_at_put(i, entry()); |
131 } | 97 } |
132 | 98 |
133 return (jobjectArray) JNIHandles::make_local(array()); | 99 return (jobjectArray) JNIHandles::make_local(array()); |
168 oop reflection_method = JNIHandles::resolve(reflection_method_handle); | 134 oop reflection_method = JNIHandles::resolve(reflection_method_handle); |
169 oop reflection_holder = java_lang_reflect_Method::clazz(reflection_method); | 135 oop reflection_holder = java_lang_reflect_Method::clazz(reflection_method); |
170 int slot = java_lang_reflect_Method::slot(reflection_method); | 136 int slot = java_lang_reflect_Method::slot(reflection_method); |
171 klassOop holder = java_lang_Class::as_klassOop(reflection_holder); | 137 klassOop holder = java_lang_Class::as_klassOop(reflection_holder); |
172 methodOop method = instanceKlass::cast(holder)->method_with_idnum(slot); | 138 methodOop method = instanceKlass::cast(holder)->method_with_idnum(slot); |
173 oop ret = GraalCompiler::createHotSpotMethodResolved(method, CHECK_NULL); | 139 Handle ret = GraalCompiler::createHotSpotMethodResolved(method, CHECK_NULL); |
174 return JNIHandles::make_local(THREAD, ret); | 140 return JNIHandles::make_local(THREAD, ret()); |
175 } | 141 } |
176 | 142 |
177 // public boolean RiMethod_uniqueConcreteMethod(long vmId); | 143 // public boolean RiMethod_uniqueConcreteMethod(long vmId); |
178 JNIEXPORT jobject JNICALL Java_com_oracle_graal_hotspot_VMEntries_RiMethod_1uniqueConcreteMethod(JNIEnv *, jobject, jobject hotspot_method) { | 144 JNIEXPORT jobject JNICALL Java_com_oracle_graal_hotspot_VMEntries_RiMethod_1uniqueConcreteMethod(JNIEnv *, jobject, jobject hotspot_method) { |
179 TRACE_graal_3("VMEntries::RiMethod_uniqueConcreteMethod"); | 145 TRACE_graal_3("VMEntries::RiMethod_uniqueConcreteMethod"); |
180 | 146 |
181 VM_ENTRY_MARK; | 147 VM_ENTRY_MARK; |
182 methodOop method = getMethodFromHotSpotMethod(hotspot_method); | 148 methodHandle method = getMethodFromHotSpotMethod(hotspot_method); |
183 klassOop holder = method->method_holder(); | 149 KlassHandle holder = method->method_holder(); |
184 if (holder->klass_part()->is_interface()) { | 150 if (holder->is_interface()) { |
185 // Cannot trust interfaces. Because of: | 151 // Cannot trust interfaces. Because of: |
186 // interface I { void foo(); } | 152 // interface I { void foo(); } |
187 // class A { public void foo() {} } | 153 // class A { public void foo() {} } |
188 // class B extends A implements I { } | 154 // class B extends A implements I { } |
189 // class C extends B { public void foo() { } } | 155 // class C extends B { public void foo() { } } |
190 // class D extends B { } | 156 // class D extends B { } |
191 // Would lead to identify C.foo() as the unique concrete method for I.foo() without seeing A.foo(). | 157 // Would lead to identify C.foo() as the unique concrete method for I.foo() without seeing A.foo(). |
192 return false; | 158 return false; |
193 } | 159 } |
194 methodOop unique_concrete; | 160 methodHandle unique_concrete; |
195 { | 161 { |
196 ResourceMark rm; | 162 ResourceMark rm; |
197 MutexLocker locker(Compile_lock); | 163 MutexLocker locker(Compile_lock); |
198 unique_concrete = Dependencies::find_unique_concrete_method(holder, method); | 164 unique_concrete = Dependencies::find_unique_concrete_method(holder(), method()); |
199 } | 165 } |
200 if (unique_concrete == NULL) { | 166 if (unique_concrete.is_null()) { |
201 return NULL; | 167 return NULL; |
202 } else { | 168 } else { |
203 oop method_resolved = GraalCompiler::createHotSpotMethodResolved(unique_concrete, CHECK_NULL); | 169 Handle method_resolved = GraalCompiler::createHotSpotMethodResolved(unique_concrete, CHECK_NULL); |
204 return JNIHandles::make_local(THREAD, method_resolved); | 170 return JNIHandles::make_local(THREAD, method_resolved()); |
205 } | 171 } |
206 } | 172 } |
207 | 173 |
208 // public native int RiMethod_invocationCount(long vmId); | 174 // public native int RiMethod_invocationCount(long vmId); |
209 JNIEXPORT jint JNICALL Java_com_oracle_graal_hotspot_VMEntries_RiMethod_1invocationCount(JNIEnv *, jobject, jobject hotspot_method) { | 175 JNIEXPORT jint JNICALL Java_com_oracle_graal_hotspot_VMEntries_RiMethod_1invocationCount(JNIEnv *, jobject, jobject hotspot_method) { |
210 TRACE_graal_3("VMEntries::RiMethod_invocationCount"); | 176 TRACE_graal_3("VMEntries::RiMethod_invocationCount"); |
211 methodOop method = getMethodFromHotSpotMethod(hotspot_method); | 177 return getMethodFromHotSpotMethod(hotspot_method)->invocation_count(); |
212 return method->invocation_count(); | |
213 } | 178 } |
214 | 179 |
215 // public native int RiMethod_exceptionProbability(long vmId, int bci); | 180 // public native int RiMethod_exceptionProbability(long vmId, int bci); |
216 JNIEXPORT jint JNICALL Java_com_oracle_graal_hotspot_VMEntries_RiMethod_2exceptionProbability(JNIEnv *, jobject, jobject hotspot_method, jint bci) { | 181 JNIEXPORT jint JNICALL Java_com_oracle_graal_hotspot_VMEntries_RiMethod_2exceptionProbability(JNIEnv *, jobject, jobject hotspot_method, jint bci) { |
217 TRACE_graal_3("VMEntries::RiMethod_exceptionProbability"); | 182 TRACE_graal_3("VMEntries::RiMethod_exceptionProbability"); |
218 { | 183 VM_ENTRY_MARK; |
219 VM_ENTRY_MARK; | 184 ResourceMark rm; |
220 methodOop method = getMethodFromHotSpotMethod(hotspot_method); | 185 methodHandle method = getMethodFromHotSpotMethod(hotspot_method); |
221 methodDataOop method_data = method->method_data(); | 186 methodDataHandle method_data = method->method_data(); |
222 if (method_data == NULL || !method_data->is_mature()) { | 187 if (method_data == NULL || !method_data->is_mature()) { |
223 return -1; | 188 return -1; |
224 } | 189 } |
225 ProfileData* data = method_data->bci_to_data(bci); | 190 ProfileData* data = method_data->bci_to_data(bci); |
226 if (data == NULL) { | 191 if (data == NULL) { |
227 return 0; | 192 return 0; |
228 } | 193 } |
229 uint trap = Deoptimization::trap_state_is_recompiled(data->trap_state())? 1: 0; | 194 uint trap = Deoptimization::trap_state_is_recompiled(data->trap_state())? 1: 0; |
230 if (trap > 0) { | 195 if (trap > 0) { |
231 return 100; | 196 return 100; |
232 } else { | 197 } else { |
233 return trap; | 198 return trap; |
234 } | |
235 } | 199 } |
236 } | 200 } |
237 | 201 |
238 // ------------------------------------------------------------------ | 202 // ------------------------------------------------------------------ |
239 // Adjust a CounterData count to be commensurate with | 203 // Adjust a CounterData count to be commensurate with |
262 } | 226 } |
263 | 227 |
264 // public native RiTypeProfile RiMethod_typeProfile(long vmId, int bci); | 228 // public native RiTypeProfile RiMethod_typeProfile(long vmId, int bci); |
265 JNIEXPORT jobject JNICALL Java_com_oracle_graal_hotspot_VMEntries_RiMethod_2typeProfile(JNIEnv *, jobject, jobject hotspot_method, jint bci) { | 229 JNIEXPORT jobject JNICALL Java_com_oracle_graal_hotspot_VMEntries_RiMethod_2typeProfile(JNIEnv *, jobject, jobject hotspot_method, jint bci) { |
266 TRACE_graal_3("VMEntries::RiMethod_typeProfile"); | 230 TRACE_graal_3("VMEntries::RiMethod_typeProfile"); |
231 VM_ENTRY_MARK; | |
267 Handle obj; | 232 Handle obj; |
268 { | 233 |
269 VM_ENTRY_MARK; | 234 methodHandle method = getMethodFromHotSpotMethod(hotspot_method); |
270 methodHandle method = getMethodFromHotSpotMethod(hotspot_method); | 235 methodDataHandle method_data = method->method_data(); |
271 if (strstr(method->name_and_sig_as_C_string(), "factor") != NULL) { | 236 if (method_data == NULL || !method_data->is_mature()) { |
272 // tty->print_cr("here"); | 237 return NULL; |
273 } | 238 } |
274 if (bci == 123) { | 239 ResourceMark rm; |
275 // tty->print_cr("here2"); | 240 ProfileData* data = method_data->bci_to_data(bci); |
276 } | 241 if (data != NULL && data->is_ReceiverTypeData()) { |
277 methodDataHandle method_data = method->method_data(); | 242 ReceiverTypeData* recv = data->as_ReceiverTypeData(); |
278 if (method_data == NULL || !method_data->is_mature()) { | 243 GrowableArray<KlassHandle> receivers; |
279 return NULL; | 244 GrowableArray<int> counts; |
280 } | 245 // determine morphism |
281 ProfileData* data = method_data->bci_to_data(bci); | 246 uint total_count = 0; |
282 if (data != NULL && data->is_ReceiverTypeData()) { | 247 for (uint i = 0; i < recv->row_limit(); i++) { |
283 ReceiverTypeData* recv = data->as_ReceiverTypeData(); | 248 klassOop receiver = recv->receiver(i); |
284 // determine morphism | 249 if (receiver == NULL) continue; |
285 int morphism = 0; | 250 uint count = recv->receiver_count(i); |
286 uint total_count = 0; | 251 total_count += count; |
287 for (uint i = 0; i < recv->row_limit(); i++) { | 252 receivers.append(receiver); |
288 klassOop receiver = recv->receiver(i); | 253 counts.append(count); |
289 if (receiver == NULL) continue; | 254 } |
290 morphism++; | 255 |
291 total_count += recv->receiver_count(i); | 256 instanceKlass::cast(RiTypeProfile::klass())->initialize(CHECK_NULL); |
257 obj = instanceKlass::cast(RiTypeProfile::klass())->allocate_instance(CHECK_NULL); | |
258 assert(obj() != NULL, "must succeed in allocating instance"); | |
259 | |
260 int count = MAX2(total_count, recv->count()); | |
261 RiTypeProfile::set_count(obj, scale_count(method_data(), count)); | |
262 RiTypeProfile::set_morphism(obj, receivers.length()); | |
263 | |
264 if (receivers.length() > 0) { | |
265 typeArrayHandle probabilities = oopFactory::new_typeArray(T_FLOAT, receivers.length(), CHECK_NULL); | |
266 objArrayHandle types = oopFactory::new_objArray(SystemDictionary::RiType_klass(), receivers.length(), CHECK_NULL); | |
267 for (int i = 0; i < receivers.length(); i++) { | |
268 KlassHandle receiver = receivers.at(i); | |
269 | |
270 float prob = counts.at(i) / (float) total_count; | |
271 Handle type = GraalCompiler::get_RiType(receiver, CHECK_NULL); | |
272 | |
273 probabilities->float_at_put(i, prob); | |
274 types->obj_at_put(i, type()); | |
275 | |
292 } | 276 } |
293 | 277 |
294 instanceKlass::cast(RiTypeProfile::klass())->initialize(CHECK_NULL); | 278 RiTypeProfile::set_probabilities(obj, probabilities()); |
295 obj = instanceKlass::cast(RiTypeProfile::klass())->allocate_instance(CHECK_NULL); | 279 RiTypeProfile::set_types(obj, types()); |
296 assert(obj() != NULL, "must succeed in allocating instance"); | 280 } else { |
297 | 281 RiTypeProfile::set_probabilities(obj, NULL); |
298 int count = MAX2(total_count, recv->count()); | 282 RiTypeProfile::set_types(obj, NULL); |
299 RiTypeProfile::set_count(obj, scale_count(method_data(), count)); | 283 } |
300 RiTypeProfile::set_morphism(obj, morphism); | 284 } |
301 | |
302 if (morphism > 0) { | |
303 typeArrayHandle probabilities = oopFactory::new_typeArray(T_FLOAT, morphism, CHECK_NULL); | |
304 objArrayHandle types = oopFactory::new_objArray(SystemDictionary::RiType_klass(), morphism, CHECK_NULL); | |
305 int pos = 0; | |
306 for (uint i = 0; i < recv->row_limit(); i++) { | |
307 KlassHandle receiver = recv->receiver(i); | |
308 if (receiver.is_null()) continue; | |
309 | |
310 float prob = recv->receiver_count(i) / (float) total_count; | |
311 oop type = GraalCompiler::get_RiType(receiver, KlassHandle(), CHECK_NULL); | |
312 | |
313 probabilities->float_at_put(pos, prob); | |
314 types->obj_at_put(pos, type); | |
315 | |
316 pos++; | |
317 } | |
318 | |
319 RiTypeProfile::set_probabilities(obj, probabilities()); | |
320 RiTypeProfile::set_types(obj, types()); | |
321 } else { | |
322 RiTypeProfile::set_probabilities(obj, NULL); | |
323 RiTypeProfile::set_types(obj, NULL); | |
324 } | |
325 } | |
326 } | |
327 | |
328 return JNIHandles::make_local(obj()); | 285 return JNIHandles::make_local(obj()); |
329 } | 286 } |
330 | 287 |
331 JNIEXPORT jdouble JNICALL Java_com_oracle_graal_hotspot_VMEntries_RiMethod_2branchProbability(JNIEnv *, jobject, jobject hotspot_method, jint bci) { | 288 JNIEXPORT jdouble JNICALL Java_com_oracle_graal_hotspot_VMEntries_RiMethod_2branchProbability(JNIEnv *, jobject, jobject hotspot_method, jint bci) { |
332 TRACE_graal_3("VMEntries::RiMethod_typeProfile"); | 289 TRACE_graal_3("VMEntries::RiMethod_typeProfile"); |
333 ciMethodData* method_data; | 290 ResourceMark rm; |
334 ciMethod* cimethod; | 291 methodHandle method = getMethodFromHotSpotMethod(hotspot_method); |
335 { | 292 methodDataHandle method_data = method->method_data(); |
336 VM_ENTRY_MARK; | |
337 assert(hotspot_method != NULL, "must not be null"); | |
338 methodOop method = getMethodFromHotSpotMethod(hotspot_method); | |
339 assert(method != NULL, "method not found"); | |
340 if (CURRENT_ENV == NULL) { | |
341 return -1; | |
342 } | |
343 assert(CURRENT_ENV != NULL, "current environment must be present"); | |
344 cimethod = (ciMethod*)CURRENT_ENV->get_object(method); | |
345 } | |
346 assert(cimethod != NULL, "cimethod not found"); | |
347 method_data = cimethod->method_data(); | |
348 | |
349 jfloat probability = -1; | |
350 | 293 |
351 if (method_data == NULL || !method_data->is_mature()) return -1; | 294 if (method_data == NULL || !method_data->is_mature()) return -1; |
352 | 295 method_data->bci_to_data(bci); |
353 ciProfileData* data = method_data->bci_to_data(bci); | 296 |
297 ProfileData* data = method_data->bci_to_data(bci); | |
354 if (data == NULL || !data->is_JumpData()) return -1; | 298 if (data == NULL || !data->is_JumpData()) return -1; |
355 | 299 |
356 // get taken and not taken values | 300 // get taken and not taken values |
357 int taken = data->as_JumpData()->taken(); | 301 int taken = data->as_JumpData()->taken(); |
358 int not_taken = 0; | 302 int not_taken = 0; |
374 } | 318 } |
375 } | 319 } |
376 | 320 |
377 JNIEXPORT jobject JNICALL Java_com_oracle_graal_hotspot_VMEntries_RiMethod_2switchProbability(JNIEnv *, jobject, jobject hotspot_method, jint bci) { | 321 JNIEXPORT jobject JNICALL Java_com_oracle_graal_hotspot_VMEntries_RiMethod_2switchProbability(JNIEnv *, jobject, jobject hotspot_method, jint bci) { |
378 TRACE_graal_3("VMEntries::RiMethod_typeProfile"); | 322 TRACE_graal_3("VMEntries::RiMethod_typeProfile"); |
379 ciMethodData* method_data; | 323 VM_ENTRY_MARK; |
380 ciMethod* cimethod; | 324 ResourceMark rm; |
381 { | 325 methodHandle method = getMethodFromHotSpotMethod(hotspot_method); |
382 VM_ENTRY_MARK; | 326 methodDataHandle method_data = method->method_data(); |
383 methodOop method = getMethodFromHotSpotMethod(hotspot_method); | |
384 cimethod = (ciMethod*)CURRENT_ENV->get_object(method); | |
385 } | |
386 method_data = cimethod->method_data(); | |
387 | |
388 jfloat probability = -1; | |
389 | 327 |
390 if (method_data == NULL || !method_data->is_mature()) return NULL; | 328 if (method_data == NULL || !method_data->is_mature()) return NULL; |
391 | 329 |
392 ciProfileData* data = method_data->bci_to_data(bci); | 330 ProfileData* data = method_data->bci_to_data(bci); |
393 if (data == NULL || !data->is_MultiBranchData()) return NULL; | 331 if (data == NULL || !data->is_MultiBranchData()) return NULL; |
394 | 332 |
395 MultiBranchData* branch_data = data->as_MultiBranchData(); | 333 MultiBranchData* branch_data = data->as_MultiBranchData(); |
396 | 334 |
397 long sum = 0; | 335 long sum = 0; |
409 | 347 |
410 // Give up if too few (or too many, in which case the sum will overflow) counts to be meaningful. | 348 // Give up if too few (or too many, in which case the sum will overflow) counts to be meaningful. |
411 // We also check that individual counters are positive first, otherwise the sum can become positive. | 349 // We also check that individual counters are positive first, otherwise the sum can become positive. |
412 if (sum < 10 * (cases + 3)) return NULL; | 350 if (sum < 10 * (cases + 3)) return NULL; |
413 | 351 |
414 { | 352 typeArrayOop probability = oopFactory::new_typeArray(T_DOUBLE, cases + 1, CHECK_NULL); |
415 VM_ENTRY_MARK; | 353 for (int i = 0; i < cases + 1; i++) { |
416 typeArrayOop probability = oopFactory::new_typeArray(T_DOUBLE, cases + 1, CHECK_NULL); | 354 probability->double_at_put(i, counts->at(i) / (double) sum); |
417 for (int i = 0; i < cases + 1; i++) { | 355 } |
418 probability->double_at_put(i, counts->at(i) / (double) sum); | 356 return JNIHandles::make_local(probability); |
419 } | |
420 return JNIHandles::make_local(probability); | |
421 } | |
422 } | 357 } |
423 | 358 |
424 // public native boolean RiMethod_hasCompiledCode(HotSpotMethodResolved method); | 359 // public native boolean RiMethod_hasCompiledCode(HotSpotMethodResolved method); |
425 JNIEXPORT jboolean JNICALL Java_com_oracle_graal_hotspot_VMEntries_RiMethod_1hasCompiledCode(JNIEnv *, jobject, jobject hotspot_method) { | 360 JNIEXPORT jboolean JNICALL Java_com_oracle_graal_hotspot_VMEntries_RiMethod_1hasCompiledCode(JNIEnv *, jobject, jobject hotspot_method) { |
426 TRACE_graal_3("VMEntries::RiMethod_hasCompiledCode"); | 361 TRACE_graal_3("VMEntries::RiMethod_hasCompiledCode"); |
427 methodOop method = getMethodFromHotSpotMethod(hotspot_method); | 362 return getMethodFromHotSpotMethod(hotspot_method)->has_compiled_code(); |
428 return method->has_compiled_code(); | |
429 } | 363 } |
430 | 364 |
431 // public RiType RiSignature_lookupType(String returnType, HotSpotTypeResolved accessingClass); | 365 // public RiType RiSignature_lookupType(String returnType, HotSpotTypeResolved accessingClass); |
432 JNIEXPORT jobject JNICALL Java_com_oracle_graal_hotspot_VMEntries_RiSignature_1lookupType(JNIEnv *env, jobject, jstring jname, jobject accessingClass) { | 366 JNIEXPORT jobject JNICALL Java_com_oracle_graal_hotspot_VMEntries_RiSignature_1lookupType(JNIEnv *env, jobject, jstring jname, jobject accessingClass) { |
433 TRACE_graal_3("VMEntries::RiSignature_lookupType"); | 367 TRACE_graal_3("VMEntries::RiSignature_lookupType"); |
434 VM_ENTRY_MARK; | 368 VM_ENTRY_MARK; |
369 ResourceMark rm; | |
435 | 370 |
436 Symbol* nameSymbol = VmIds::toSymbol(jname); | 371 Symbol* nameSymbol = VmIds::toSymbol(jname); |
437 Handle name = JNIHandles::resolve(jname); | 372 Handle name = JNIHandles::resolve(jname); |
438 | 373 |
439 oop result; | 374 oop result; |
468 CLEAR_PENDING_EXCEPTION; | 403 CLEAR_PENDING_EXCEPTION; |
469 resolved_type = NULL; | 404 resolved_type = NULL; |
470 } | 405 } |
471 } | 406 } |
472 if (resolved_type != NULL) { | 407 if (resolved_type != NULL) { |
473 result = GraalCompiler::createHotSpotTypeResolved(resolved_type, name, CHECK_NULL); | 408 Handle type = GraalCompiler::createHotSpotTypeResolved(resolved_type, name, CHECK_NULL); |
409 result = type(); | |
474 } else { | 410 } else { |
475 result = VMExits::createRiTypeUnresolved(name, THREAD); | 411 Handle type = VMExits::createRiTypeUnresolved(name, THREAD); |
412 result = type(); | |
476 } | 413 } |
477 } | 414 } |
478 | 415 |
479 return JNIHandles::make_local(THREAD, result); | 416 return JNIHandles::make_local(THREAD, result); |
480 } | 417 } |
509 return NULL; | 446 return NULL; |
510 } | 447 } |
511 } | 448 } |
512 result = VMExits::createCiConstantObject(string, CHECK_0); | 449 result = VMExits::createCiConstantObject(string, CHECK_0); |
513 } else if (tag.is_klass() || tag.is_unresolved_klass()) { | 450 } else if (tag.is_klass() || tag.is_unresolved_klass()) { |
514 bool ignore; | 451 Handle type = GraalCompiler::get_RiType(cp, index, cp->pool_holder(), CHECK_NULL); |
515 ciInstanceKlass* accessor = (ciInstanceKlass*) ciEnv::current()->get_object(cp->pool_holder()); | 452 result = type(); |
516 ciKlass* klass = ciEnv::current()->get_klass_by_index(cp, index, ignore, accessor); | |
517 result = GraalCompiler::get_RiType(klass, cp->pool_holder(), CHECK_NULL); | |
518 } else if (tag.is_object()) { | 453 } else if (tag.is_object()) { |
519 oop obj = cp->object_at(index); | 454 oop obj = cp->object_at(index); |
520 assert(obj->is_instance(), "must be an instance"); | 455 assert(obj->is_instance(), "must be an instance"); |
521 result = VMExits::createCiConstantObject(obj, CHECK_NULL); | 456 result = VMExits::createCiConstantObject(obj, CHECK_NULL); |
522 } else { | 457 } else { |
529 // public RiMethod RiConstantPool_lookupMethod(long vmId, int cpi, byte byteCode); | 464 // public RiMethod RiConstantPool_lookupMethod(long vmId, int cpi, byte byteCode); |
530 JNIEXPORT jobject JNICALL Java_com_oracle_graal_hotspot_VMEntries_RiConstantPool_1lookupMethod(JNIEnv *env, jobject, jobject type, jint index, jbyte byteCode) { | 465 JNIEXPORT jobject JNICALL Java_com_oracle_graal_hotspot_VMEntries_RiConstantPool_1lookupMethod(JNIEnv *env, jobject, jobject type, jint index, jbyte byteCode) { |
531 TRACE_graal_3("VMEntries::RiConstantPool_lookupMethod"); | 466 TRACE_graal_3("VMEntries::RiConstantPool_lookupMethod"); |
532 VM_ENTRY_MARK; | 467 VM_ENTRY_MARK; |
533 index = GraalCompiler::to_cp_index_u2(index); | 468 index = GraalCompiler::to_cp_index_u2(index); |
534 constantPoolOop cp = instanceKlass::cast(java_lang_Class::as_klassOop(HotSpotTypeResolved::javaMirror(type)))->constants(); | 469 constantPoolHandle cp = instanceKlass::cast(java_lang_Class::as_klassOop(HotSpotTypeResolved::javaMirror(type)))->constants(); |
535 | 470 |
536 Bytecodes::Code bc = (Bytecodes::Code) (((int) byteCode) & 0xFF); | 471 Bytecodes::Code bc = (Bytecodes::Code) (((int) byteCode) & 0xFF); |
537 ciInstanceKlass* loading_klass = (ciInstanceKlass *) CURRENT_ENV->get_object(cp->pool_holder()); | 472 methodHandle method = GraalEnv::get_method_by_index(cp, index, bc, cp->pool_holder()); |
538 ciMethod *cimethod = CURRENT_ENV->get_method_by_index(cp, index, bc, loading_klass); | 473 if (!method.is_null()) { |
539 if (cimethod->is_loaded()) { | 474 Handle ret = GraalCompiler::createHotSpotMethodResolved(method, CHECK_NULL); |
540 methodOop method = (methodOop) cimethod->get_oop(); | 475 return JNIHandles::make_local(THREAD, ret()); |
541 oop ret = GraalCompiler::createHotSpotMethodResolved(method, CHECK_NULL); | |
542 return JNIHandles::make_local(THREAD, ret); | |
543 } else { | 476 } else { |
544 Handle name = VmIds::toString<Handle>(cimethod->name()->get_symbol(), CHECK_NULL); | 477 // Get the method's name and signature. |
545 Handle signature = VmIds::toString<Handle>(cimethod->signature()->as_symbol()->get_symbol(), CHECK_NULL); | 478 Handle name = VmIds::toString<Handle>(cp->name_ref_at(index), CHECK_NULL); |
546 Handle holder = GraalCompiler::get_RiType(cimethod->holder(), cp->klass(), THREAD); | 479 Handle signature = VmIds::toString<Handle>(cp->signature_ref_at(index), CHECK_NULL); |
547 return JNIHandles::make_local(THREAD, VMExits::createRiMethodUnresolved(name, signature, holder, THREAD)); | 480 int holder_index = cp->klass_ref_index_at(index); |
481 Handle type = GraalCompiler::get_RiType(cp, holder_index, cp->pool_holder(), CHECK_NULL); | |
482 return JNIHandles::make_local(THREAD, VMExits::createRiMethodUnresolved(name, signature, type, THREAD)); | |
548 } | 483 } |
549 } | 484 } |
550 | 485 |
551 // public RiType RiConstantPool_lookupType(long vmId, int cpi); | 486 // public RiType RiConstantPool_lookupType(long vmId, int cpi); |
552 JNIEXPORT jobject JNICALL Java_com_oracle_graal_hotspot_VMEntries_RiConstantPool_1lookupType(JNIEnv *env, jobject, jobject type, jint index) { | 487 JNIEXPORT jobject JNICALL Java_com_oracle_graal_hotspot_VMEntries_RiConstantPool_1lookupType(JNIEnv *env, jobject, jobject type, jint index) { |
553 TRACE_graal_3("VMEntries::RiConstantPool_lookupType"); | 488 TRACE_graal_3("VMEntries::RiConstantPool_lookupType"); |
554 VM_ENTRY_MARK; | 489 VM_ENTRY_MARK; |
555 | 490 |
556 constantPoolOop cp = instanceKlass::cast(java_lang_Class::as_klassOop(HotSpotTypeResolved::javaMirror(type)))->constants(); | 491 constantPoolOop cp = instanceKlass::cast(java_lang_Class::as_klassOop(HotSpotTypeResolved::javaMirror(type)))->constants(); |
557 | 492 Handle result = GraalCompiler::get_RiType(cp, index, cp->pool_holder(), CHECK_NULL); |
558 ciInstanceKlass* loading_klass = (ciInstanceKlass *) CURRENT_ENV->get_object(cp->pool_holder()); | 493 return JNIHandles::make_local(THREAD, result()); |
559 bool is_accessible = false; | |
560 ciKlass *klass = CURRENT_ENV->get_klass_by_index(cp, index, is_accessible, loading_klass); | |
561 return JNIHandles::make_local(THREAD, GraalCompiler::get_RiType(klass, cp->klass(), THREAD)); | |
562 } | 494 } |
563 | 495 |
564 // public void RiConstantPool_loadReferencedType(long vmId, int cpi); | 496 // public void RiConstantPool_loadReferencedType(long vmId, int cpi); |
565 JNIEXPORT void JNICALL Java_com_oracle_graal_hotspot_VMEntries_RiConstantPool_1loadReferencedType(JNIEnv *env, jobject, jobject type, jint index, jbyte op) { | 497 JNIEXPORT void JNICALL Java_com_oracle_graal_hotspot_VMEntries_RiConstantPool_1loadReferencedType(JNIEnv *env, jobject, jobject type, jint index, jbyte op) { |
566 TRACE_graal_3("VMEntries::RiConstantPool_lookupType"); | 498 TRACE_graal_3("VMEntries::RiConstantPool_lookupType"); |
584 } | 516 } |
585 } | 517 } |
586 } | 518 } |
587 | 519 |
588 // public RiField RiConstantPool_lookupField(long vmId, int cpi); | 520 // public RiField RiConstantPool_lookupField(long vmId, int cpi); |
589 JNIEXPORT jobject JNICALL Java_com_oracle_graal_hotspot_VMEntries_RiConstantPool_1lookupField(JNIEnv *env, jobject, jobject type, jint index, jbyte byteCode) { | 521 JNIEXPORT jobject JNICALL Java_com_oracle_graal_hotspot_VMEntries_RiConstantPool_1lookupField(JNIEnv *env, jobject, jobject constantPoolHolder, jint index, jbyte byteCode) { |
590 TRACE_graal_3("VMEntries::RiConstantPool_lookupField"); | 522 TRACE_graal_3("VMEntries::RiConstantPool_lookupField"); |
591 VM_ENTRY_MARK; | 523 VM_ENTRY_MARK; |
524 ResourceMark rm; | |
592 | 525 |
593 index = GraalCompiler::to_cp_index_u2(index); | 526 index = GraalCompiler::to_cp_index_u2(index); |
594 constantPoolOop cp = instanceKlass::cast(java_lang_Class::as_klassOop(HotSpotTypeResolved::javaMirror(type)))->constants(); | 527 constantPoolHandle cp = instanceKlass::cast(java_lang_Class::as_klassOop(HotSpotTypeResolved::javaMirror(constantPoolHolder)))->constants(); |
595 | 528 |
596 ciInstanceKlass* loading_klass = (ciInstanceKlass *) CURRENT_ENV->get_object(cp->pool_holder()); | 529 int nt_index = cp->name_and_type_ref_index_at(index); |
597 ciField *field = CURRENT_ENV->get_field_by_index(loading_klass, index); | 530 int sig_index = cp->signature_ref_index_at(nt_index); |
531 Symbol* signature = cp->symbol_at(sig_index); | |
532 int name_index = cp->name_ref_index_at(nt_index); | |
533 Symbol* name = cp->symbol_at(name_index); | |
534 int holder_index = cp->klass_ref_index_at(index); | |
535 Handle holder = GraalCompiler::get_RiType(cp, holder_index, cp->pool_holder(), CHECK_NULL); | |
536 instanceKlassHandle holder_klass; | |
598 | 537 |
599 Bytecodes::Code code = (Bytecodes::Code)(((int) byteCode) & 0xFF); | 538 Bytecodes::Code code = (Bytecodes::Code)(((int) byteCode) & 0xFF); |
600 Handle field_handle = GraalCompiler::get_RiField(field, loading_klass, cp->pool_holder(), code, THREAD); | 539 int offset = -1; |
601 bool is_constant = field->is_constant(); | 540 AccessFlags flags; |
602 if (is_constant && field->is_static()) { | 541 BasicType basic_type; |
603 ciConstant constant = field->constant_value(); | 542 if (holder->klass() == SystemDictionary::HotSpotTypeResolved_klass()) { |
604 oop constant_object = NULL; | 543 FieldAccessInfo result; |
605 switch (constant.basic_type()) { | 544 LinkResolver::resolve_field(result, cp, index, |
606 case T_OBJECT: | 545 Bytecodes::java_code(code), |
607 case T_ARRAY: | 546 true, false, Thread::current()); |
608 { | 547 if (HAS_PENDING_EXCEPTION) { |
609 ciObject* obj = constant.as_object(); | 548 CLEAR_PENDING_EXCEPTION; |
610 if (obj->is_null_object()) { | 549 } else { |
611 constant_object = VMExits::createCiConstantObject(NULL, CHECK_0); | 550 offset = result.field_offset(); |
612 } else if (obj->can_be_constant()) { | 551 flags = result.access_flags(); |
613 constant_object = VMExits::createCiConstantObject(constant.as_object()->get_oop(), CHECK_0); | 552 holder_klass = result.klass()->as_klassOop(); |
614 } | 553 basic_type = result.field_type(); |
615 } | 554 holder = GraalCompiler::get_RiType(holder_klass, CHECK_NULL); |
616 break; | 555 } |
617 case T_DOUBLE: | 556 } |
618 constant_object = VMExits::createCiConstantDouble(constant.as_double(), CHECK_0); | 557 |
619 break; | 558 Handle type = GraalCompiler::get_RiTypeFromSignature(cp, sig_index, cp->pool_holder(), CHECK_NULL); |
620 case T_FLOAT: | 559 Handle field_handle = GraalCompiler::get_RiField(offset, flags.as_int(), name, holder, type, code, THREAD); |
621 constant_object = VMExits::createCiConstantFloat(constant.as_float(), CHECK_0); | 560 |
622 break; | 561 oop constant_object = NULL; |
623 case T_LONG: | 562 // Check to see if the field is constant. |
624 constant_object = VMExits::createCiConstant(CiKind::Long(), constant.as_long(), CHECK_0); | 563 if (!holder_klass.is_null() && holder_klass->is_initialized() && flags.is_final() && flags.is_static()) { |
625 break; | 564 // This field just may be constant. The only cases where it will |
626 case T_INT: | 565 // not be constant are: |
627 constant_object = VMExits::createCiConstant(CiKind::Int(), constant.as_int(), CHECK_0); | 566 // |
628 break; | 567 // 1. The field holds a non-perm-space oop. The field is, strictly |
629 case T_SHORT: | 568 // speaking, constant but we cannot embed non-perm-space oops into |
630 constant_object = VMExits::createCiConstant(CiKind::Short(), constant.as_int(), CHECK_0); | 569 // generated code. For the time being we need to consider the |
631 break; | 570 // field to be not constant. |
632 case T_CHAR: | 571 // 2. The field is a *special* static&final field whose value |
633 constant_object = VMExits::createCiConstant(CiKind::Char(), constant.as_int(), CHECK_0); | 572 // may change. The three examples are java.lang.System.in, |
634 break; | 573 // java.lang.System.out, and java.lang.System.err. |
635 case T_BYTE: | 574 |
636 constant_object = VMExits::createCiConstant(CiKind::Byte(), constant.as_int(), CHECK_0); | 575 bool ok = true; |
637 break; | 576 assert( SystemDictionary::System_klass() != NULL, "Check once per vm"); |
638 case T_BOOLEAN: | 577 if( holder_klass->as_klassOop() == SystemDictionary::System_klass() ) { |
639 constant_object = VMExits::createCiConstant(CiKind::Boolean(), constant.as_int(), CHECK_0); | 578 // Check offsets for case 2: System.in, System.out, or System.err |
640 break; | 579 if( offset == java_lang_System::in_offset_in_bytes() || |
641 default: | 580 offset == java_lang_System::out_offset_in_bytes() || |
642 constant.print(); | 581 offset == java_lang_System::err_offset_in_bytes() ) { |
643 fatal("Unhandled constant"); | 582 ok = false; |
644 break; | 583 } |
645 } | 584 } |
646 if (constant_object != NULL) { | 585 |
647 HotSpotField::set_constant(field_handle, constant_object); | 586 if (ok) { |
648 } | 587 Handle mirror = holder_klass->java_mirror(); |
588 switch(basic_type) { | |
589 case T_OBJECT: | |
590 case T_ARRAY: | |
591 constant_object = VMExits::createCiConstantObject(mirror->obj_field(offset), CHECK_0); | |
592 break; | |
593 case T_DOUBLE: | |
594 constant_object = VMExits::createCiConstantDouble(mirror->double_field(offset), CHECK_0); | |
595 break; | |
596 case T_FLOAT: | |
597 constant_object = VMExits::createCiConstantFloat(mirror->float_field(offset), CHECK_0); | |
598 break; | |
599 case T_LONG: | |
600 constant_object = VMExits::createCiConstant(CiKind::Long(), mirror->long_field(offset), CHECK_0); | |
601 break; | |
602 case T_INT: | |
603 constant_object = VMExits::createCiConstant(CiKind::Int(), mirror->int_field(offset), CHECK_0); | |
604 break; | |
605 case T_SHORT: | |
606 constant_object = VMExits::createCiConstant(CiKind::Short(), mirror->short_field(offset), CHECK_0); | |
607 break; | |
608 case T_CHAR: | |
609 constant_object = VMExits::createCiConstant(CiKind::Char(), mirror->char_field(offset), CHECK_0); | |
610 break; | |
611 case T_BYTE: | |
612 constant_object = VMExits::createCiConstant(CiKind::Byte(), mirror->byte_field(offset), CHECK_0); | |
613 break; | |
614 case T_BOOLEAN: | |
615 constant_object = VMExits::createCiConstant(CiKind::Boolean(), mirror->bool_field(offset), CHECK_0); | |
616 break; | |
617 default: | |
618 fatal("Unhandled constant"); | |
619 break; | |
620 } | |
621 } | |
622 } | |
623 if (constant_object != NULL) { | |
624 HotSpotField::set_constant(field_handle, constant_object); | |
649 } | 625 } |
650 return JNIHandles::make_local(THREAD, field_handle()); | 626 return JNIHandles::make_local(THREAD, field_handle()); |
651 } | 627 } |
652 | 628 |
653 // public RiMethod RiType_resolveMethodImpl(HotSpotTypeResolved klass, String name, String signature); | 629 // public RiMethod RiType_resolveMethodImpl(HotSpotTypeResolved klass, String name, String signature); |
657 | 633 |
658 assert(JNIHandles::resolve(resolved_type) != NULL, ""); | 634 assert(JNIHandles::resolve(resolved_type) != NULL, ""); |
659 klassOop klass = java_lang_Class::as_klassOop(HotSpotTypeResolved::javaMirror(resolved_type)); | 635 klassOop klass = java_lang_Class::as_klassOop(HotSpotTypeResolved::javaMirror(resolved_type)); |
660 Symbol* name_symbol = VmIds::toSymbol(name); | 636 Symbol* name_symbol = VmIds::toSymbol(name); |
661 Symbol* signature_symbol = VmIds::toSymbol(signature); | 637 Symbol* signature_symbol = VmIds::toSymbol(signature); |
662 methodOop method = klass->klass_part()->lookup_method(name_symbol, signature_symbol); | 638 methodHandle method = klass->klass_part()->lookup_method(name_symbol, signature_symbol); |
663 if (method == NULL) { | 639 if (method == NULL) { |
664 if (TraceGraal >= 3) { | 640 if (TraceGraal >= 3) { |
665 ResourceMark rm; | 641 ResourceMark rm; |
666 tty->print_cr("Could not resolve method %s %s on klass %s", name_symbol->as_C_string(), signature_symbol->as_C_string(), klass->klass_part()->name()->as_C_string()); | 642 tty->print_cr("Could not resolve method %s %s on klass %s", name_symbol->as_C_string(), signature_symbol->as_C_string(), klass->klass_part()->name()->as_C_string()); |
667 } | 643 } |
668 return NULL; | 644 return NULL; |
669 } | 645 } |
670 oop ret = GraalCompiler::createHotSpotMethodResolved(method, CHECK_NULL); | 646 Handle ret = GraalCompiler::createHotSpotMethodResolved(method, CHECK_NULL); |
671 return JNIHandles::make_local(THREAD, ret); | 647 return JNIHandles::make_local(THREAD, ret()); |
672 } | 648 } |
673 | 649 |
674 // public boolean RiType_isSubtypeOf(HotSpotTypeResolved klass, RiType other); | 650 // public boolean RiType_isSubtypeOf(HotSpotTypeResolved klass, RiType other); |
675 JNIEXPORT jboolean JNICALL Java_com_oracle_graal_hotspot_VMEntries_RiType_2isSubtypeOf(JNIEnv *, jobject, jobject klass, jobject jother) { | 651 JNIEXPORT jboolean JNICALL Java_com_oracle_graal_hotspot_VMEntries_RiType_2isSubtypeOf(JNIEnv *, jobject, jobject klass, jobject jother) { |
676 TRACE_graal_3("VMEntries::RiType_isSubtypeOf"); | 652 TRACE_graal_3("VMEntries::RiType_isSubtypeOf"); |
690 } | 666 } |
691 | 667 |
692 // public RiType RiType_componentType(HotSpotResolvedType klass); | 668 // public RiType RiType_componentType(HotSpotResolvedType klass); |
693 JNIEXPORT jobject JNICALL Java_com_oracle_graal_hotspot_VMEntries_RiType_1componentType(JNIEnv *, jobject, jobject klass) { | 669 JNIEXPORT jobject JNICALL Java_com_oracle_graal_hotspot_VMEntries_RiType_1componentType(JNIEnv *, jobject, jobject klass) { |
694 TRACE_graal_3("VMEntries::RiType_componentType"); | 670 TRACE_graal_3("VMEntries::RiType_componentType"); |
695 ciArrayKlass* array_klass; | 671 VM_ENTRY_MARK; |
696 { | 672 KlassHandle array_klass = java_lang_Class::as_klassOop(HotSpotTypeResolved::javaMirror(klass)); |
697 VM_ENTRY_MARK; | 673 assert(array_klass->oop_is_objArray(), "just checking"); |
698 assert(JNIHandles::resolve(klass) != NULL, ""); | 674 klassOop element_type = objArrayKlass::cast(array_klass())->element_klass(); |
699 array_klass = (ciArrayKlass *) CURRENT_ENV->get_object(java_lang_Class::as_klassOop(HotSpotTypeResolved::javaMirror(klass))); | |
700 } | |
701 ciType* element_type = array_klass->element_type(); | |
702 | |
703 VM_ENTRY_MARK; | |
704 assert(JNIHandles::resolve(klass) != NULL, ""); | 675 assert(JNIHandles::resolve(klass) != NULL, ""); |
705 return JNIHandles::make_local(GraalCompiler::get_RiType(element_type, java_lang_Class::as_klassOop(HotSpotTypeResolved::javaMirror(klass)), THREAD)); | 676 return JNIHandles::make_local(GraalCompiler::get_RiType(element_type, THREAD)()); |
706 } | 677 } |
707 | 678 |
708 // public RiType RiType_superType(HotSpotResolvedType klass); | 679 // public RiType RiType_superType(HotSpotResolvedType klass); |
709 JNIEXPORT jobject JNICALL Java_com_oracle_graal_hotspot_VMEntries_RiType_1superType(JNIEnv *, jobject, jobject klass) { | 680 JNIEXPORT jobject JNICALL Java_com_oracle_graal_hotspot_VMEntries_RiType_1superType(JNIEnv *, jobject, jobject klass) { |
710 TRACE_graal_3("VMEntries::RiType_superType"); | 681 TRACE_graal_3("VMEntries::RiType_superType"); |
711 VM_ENTRY_MARK; | 682 VM_ENTRY_MARK; |
712 KlassHandle klass_handle(java_lang_Class::as_klassOop(HotSpotTypeResolved::javaMirror(klass))); | 683 KlassHandle klass_handle(java_lang_Class::as_klassOop(HotSpotTypeResolved::javaMirror(klass))); |
713 ciInstanceKlass* k = NULL; | 684 klassOop k; |
714 | 685 |
715 if (klass_handle->oop_is_array()) { | 686 if (klass_handle->oop_is_array()) { |
716 k = (ciInstanceKlass *) CURRENT_ENV->get_object(SystemDictionary::Object_klass()); | 687 k = SystemDictionary::Object_klass(); |
717 } else { | 688 } else { |
718 guarantee(klass_handle->oop_is_instance(), "must be instance klass"); | 689 guarantee(klass_handle->oop_is_instance(), "must be instance klass"); |
719 k = (ciInstanceKlass *) CURRENT_ENV->get_object(klass_handle()); | 690 k = klass_handle->super(); |
720 k = k->super(); | |
721 } | 691 } |
722 | 692 |
723 if (k != NULL) { | 693 if (k != NULL) { |
724 return JNIHandles::make_local(GraalCompiler::get_RiType(k, klass_handle, THREAD)); | 694 return JNIHandles::make_local(GraalCompiler::get_RiType(k, THREAD)()); |
725 } else { | 695 } else { |
726 return NULL; | 696 return NULL; |
727 } | 697 } |
728 } | 698 } |
729 | 699 |
730 // public RiType RiType_uniqueConcreteSubtype(HotSpotResolvedType klass); | 700 // public RiType RiType_uniqueConcreteSubtype(HotSpotResolvedType klass); |
731 JNIEXPORT jobject JNICALL Java_com_oracle_graal_hotspot_VMEntries_RiType_1uniqueConcreteSubtype(JNIEnv *, jobject, jobject klass) { | 701 JNIEXPORT jobject JNICALL Java_com_oracle_graal_hotspot_VMEntries_RiType_1uniqueConcreteSubtype(JNIEnv *, jobject, jobject klass) { |
732 TRACE_graal_3("VMEntries::RiType_uniqueConcreteSubtype"); | 702 TRACE_graal_3("VMEntries::RiType_uniqueConcreteSubtype"); |
733 Thread* THREAD = Thread::current(); | 703 VM_ENTRY_MARK; |
734 KlassHandle klass_handle(java_lang_Class::as_klassOop(HotSpotTypeResolved::javaMirror(klass))); | 704 KlassHandle klass_handle(java_lang_Class::as_klassOop(HotSpotTypeResolved::javaMirror(klass))); |
735 ciInstanceKlass* k = NULL; | 705 Klass *up_cast = klass_handle->up_cast_abstract(); |
736 { | 706 if (up_cast->is_leaf_class()) { |
737 VM_ENTRY_MARK; | 707 return JNIHandles::make_local(GraalCompiler::get_RiType(up_cast, THREAD)()); |
738 k = (ciInstanceKlass *) CURRENT_ENV->get_object(klass_handle()); | 708 } |
739 } | |
740 | |
741 if (k->is_abstract()) { | |
742 ciInstanceKlass* sub = k->unique_concrete_subklass(); | |
743 if (sub != NULL && sub->is_leaf_type()) { | |
744 VM_ENTRY_MARK; | |
745 return JNIHandles::make_local(GraalCompiler::get_RiType(sub, klass_handle, THREAD)); | |
746 } | |
747 } else if (k->is_leaf_type()) { | |
748 assert(!k->is_interface(), ""); | |
749 return klass; | |
750 } | |
751 | |
752 return NULL; | 709 return NULL; |
753 } | 710 } |
754 | 711 |
755 // public bool RiType_isInitialized(HotSpotResolvedType klass); | 712 // public bool RiType_isInitialized(HotSpotResolvedType klass); |
756 JNIEXPORT jboolean JNICALL Java_com_oracle_graal_hotspot_VMEntries_RiType_1isInitialized(JNIEnv *, jobject, jobject hotspot_klass) { | 713 JNIEXPORT jboolean JNICALL Java_com_oracle_graal_hotspot_VMEntries_RiType_1isInitialized(JNIEnv *, jobject, jobject hotspot_klass) { |
766 VM_ENTRY_MARK; | 723 VM_ENTRY_MARK; |
767 | 724 |
768 KlassHandle klass_handle(java_lang_Class::as_klassOop(HotSpotTypeResolved::javaMirror(klass))); | 725 KlassHandle klass_handle(java_lang_Class::as_klassOop(HotSpotTypeResolved::javaMirror(klass))); |
769 KlassHandle array = klass_handle->array_klass(THREAD); | 726 KlassHandle array = klass_handle->array_klass(THREAD); |
770 Handle name = VmIds::toString<Handle>(array->name(), CHECK_NULL); | 727 Handle name = VmIds::toString<Handle>(array->name(), CHECK_NULL); |
771 return JNIHandles::make_local(THREAD, GraalCompiler::createHotSpotTypeResolved(array, name, THREAD)); | 728 return JNIHandles::make_local(THREAD, GraalCompiler::createHotSpotTypeResolved(array, name, THREAD)()); |
772 } | 729 } |
773 | 730 |
774 // public RiField[] RiType_fields(HotSpotTypeResolved klass); | 731 // public RiField[] RiType_fields(HotSpotTypeResolved klass); |
775 JNIEXPORT jobject JNICALL Java_com_oracle_graal_hotspot_VMEntries_RiType_1fields(JNIEnv *, jobject, jobject klass) { | 732 JNIEXPORT jobject JNICALL Java_com_oracle_graal_hotspot_VMEntries_RiType_1fields(JNIEnv *, jobject, jobject klass) { |
776 TRACE_graal_3("VMEntries::RiType_fields"); | 733 TRACE_graal_3("VMEntries::RiType_fields"); |
777 KlassHandle klass_handle; | 734 VM_ENTRY_MARK; |
778 ciInstanceKlass* instance_klass; | 735 ResourceMark rm; |
779 objArrayHandle fieldsArray; | 736 |
780 HandleMark hm; | 737 instanceKlassHandle k = java_lang_Class::as_klassOop(HotSpotTypeResolved::javaMirror(klass)); |
781 { | 738 class MyFieldClosure : public FieldClosure { |
782 VM_ENTRY_MARK; | 739 public: |
783 klass_handle = java_lang_Class::as_klassOop(HotSpotTypeResolved::javaMirror(klass)); | 740 instanceKlassHandle _holder; |
784 instance_klass = (ciInstanceKlass *) CURRENT_ENV->get_object(klass_handle()); | 741 Handle _resolved_type_holder; |
785 } | 742 GrowableArray<Handle> _field_array; |
786 GrowableArray<ciField*>* fields = instance_klass->non_static_fields(); | 743 |
787 { | 744 MyFieldClosure(instanceKlassHandle& holder, Handle resolved_type_holder) : _holder(holder), _resolved_type_holder(resolved_type_holder) { } |
788 VM_ENTRY_MARK; | |
789 | 745 |
790 int count = 0; | 746 virtual void do_field(fieldDescriptor* fd) { |
791 for (int i = 0; i < fields->length(); i++) { | 747 if (!Thread::current()->has_pending_exception()) { |
792 ciField* field = fields->at(i); | 748 if (fd->field_holder() == _holder()) { |
793 if (field->holder() == instance_klass) { | 749 Handle type = GraalCompiler::get_RiTypeFromSignature(fd->constants(), fd->signature_index(), fd->field_holder(), Thread::current()); |
794 count++; | 750 Handle field = VMExits::createRiField(_resolved_type_holder, VmIds::toString<Handle>(fd->name(), Thread::current()), type, fd->offset(), fd->access_flags().as_int(), Thread::current()); |
751 _field_array.append(field()); | |
752 } | |
795 } | 753 } |
796 } | 754 } |
797 | 755 }; |
798 fieldsArray = oopFactory::new_objArray(SystemDictionary::RiField_klass(), count, CHECK_NULL); | 756 MyFieldClosure closure(k, JNIHandles::resolve(klass)); |
799 int z = 0; | 757 k->do_nonstatic_fields(&closure); |
800 for (int i = 0; i < fields->length(); i++) { | 758 objArrayHandle field_array = oopFactory::new_objArray(SystemDictionary::RiField_klass(), closure._field_array.length(), CHECK_NULL); |
801 ciField* field = fields->at(i); | 759 for (int i=0; i<closure._field_array.length(); ++i) { |
802 if (field->holder() == instance_klass) { | 760 field_array->obj_at_put(i, closure._field_array.at(i)()); |
803 Handle field_handle = GraalCompiler::get_RiField(field, instance_klass, klass_handle, Bytecodes::_illegal, CHECK_NULL); | 761 } |
804 fieldsArray->obj_at_put(z, field_handle()); | 762 return JNIHandles::make_local(field_array()); |
805 z++; | |
806 } | |
807 } | |
808 } | |
809 return JNIHandles::make_local(fieldsArray()); | |
810 } | 763 } |
811 | 764 |
812 // public RiType getPrimitiveArrayType(CiKind kind); | 765 // public RiType getPrimitiveArrayType(CiKind kind); |
813 JNIEXPORT jobject JNICALL Java_com_oracle_graal_hotspot_VMEntries_getPrimitiveArrayType(JNIEnv *env, jobject, jobject kind) { | 766 JNIEXPORT jobject JNICALL Java_com_oracle_graal_hotspot_VMEntries_getPrimitiveArrayType(JNIEnv *env, jobject, jobject kind) { |
814 TRACE_graal_3("VMEntries::VMEntries_getPrimitiveArrayType"); | 767 TRACE_graal_3("VMEntries::VMEntries_getPrimitiveArrayType"); |
815 VM_ENTRY_MARK; | 768 VM_ENTRY_MARK; |
816 BasicType type = GraalCompiler::kindToBasicType(CiKind::typeChar(kind)); | 769 BasicType type = GraalCompiler::kindToBasicType(CiKind::typeChar(kind)); |
817 assert(type != T_OBJECT, "primitive type expecteds"); | 770 assert(type != T_OBJECT, "primitive type expecteds"); |
818 ciKlass* klass = ciTypeArrayKlass::make(type); | 771 Handle result = GraalCompiler::get_RiType(Universe::typeArrayKlassObj(type), CHECK_NULL); |
819 return JNIHandles::make_local(THREAD, GraalCompiler::get_RiType(klass, KlassHandle(), THREAD)); | 772 return JNIHandles::make_local(THREAD, result()); |
820 } | 773 } |
821 | 774 |
822 // public long getMaxCallTargetOffset(CiRuntimeCall rtcall); | 775 // public long getMaxCallTargetOffset(CiRuntimeCall rtcall); |
823 JNIEXPORT jlong JNICALL Java_com_oracle_graal_hotspot_VMEntries_getMaxCallTargetOffset(JNIEnv *env, jobject, jobject rtcall) { | 776 JNIEXPORT jlong JNICALL Java_com_oracle_graal_hotspot_VMEntries_getMaxCallTargetOffset(JNIEnv *env, jobject, jobject rtcall) { |
824 TRACE_graal_3("VMEntries::VMEntries_getMaxCallTargetOffset"); | 777 TRACE_graal_3("VMEntries::VMEntries_getMaxCallTargetOffset"); |
846 return JNIHandles::make_local(THREAD, VMExits::createRiTypePrimitive((int) basicType, THREAD)); | 799 return JNIHandles::make_local(THREAD, VMExits::createRiTypePrimitive((int) basicType, THREAD)); |
847 } else { | 800 } else { |
848 KlassHandle klass = java_lang_Class::as_klassOop(javaClassOop); | 801 KlassHandle klass = java_lang_Class::as_klassOop(javaClassOop); |
849 Handle name = java_lang_String::create_from_symbol(klass->name(), CHECK_NULL); | 802 Handle name = java_lang_String::create_from_symbol(klass->name(), CHECK_NULL); |
850 | 803 |
851 oop type = GraalCompiler::createHotSpotTypeResolved(klass, name, CHECK_NULL); | 804 Handle type = GraalCompiler::createHotSpotTypeResolved(klass, name, CHECK_NULL); |
852 return JNIHandles::make_local(THREAD, type); | 805 return JNIHandles::make_local(THREAD, type()); |
853 } | 806 } |
854 } | 807 } |
855 | 808 |
856 | 809 |
857 // helpers used to set fields in the HotSpotVMConfig object | 810 // helpers used to set fields in the HotSpotVMConfig object |
973 | 926 |
974 // public HotSpotCompiledMethod installMethod(HotSpotTargetMethod targetMethod, boolean installCode); | 927 // public HotSpotCompiledMethod installMethod(HotSpotTargetMethod targetMethod, boolean installCode); |
975 JNIEXPORT jobject JNICALL Java_com_oracle_graal_hotspot_VMEntries_installMethod(JNIEnv *jniEnv, jobject, jobject targetMethod, jboolean install_code) { | 928 JNIEXPORT jobject JNICALL Java_com_oracle_graal_hotspot_VMEntries_installMethod(JNIEnv *jniEnv, jobject, jobject targetMethod, jboolean install_code) { |
976 VM_ENTRY_MARK; | 929 VM_ENTRY_MARK; |
977 nmethod* nm = NULL; | 930 nmethod* nm = NULL; |
978 if (CURRENT_ENV == NULL) { | 931 ciEnv* current_env = JavaThread::current()->env(); |
979 Arena arena; | 932 JavaThread::current()->set_env(NULL); |
980 ciEnv env(&arena); | 933 Arena arena; |
981 ResourceMark rm; | 934 ciEnv env(&arena); |
982 CodeInstaller installer(JNIHandles::resolve(targetMethod), nm, install_code != 0); | 935 ResourceMark rm; |
983 } else { | 936 CodeInstaller installer(JNIHandles::resolve(targetMethod), nm, install_code != 0); |
984 ResourceMark rm; | 937 JavaThread::current()->set_env(current_env); |
985 CodeInstaller installer(JNIHandles::resolve(targetMethod), nm, install_code != 0); | |
986 | |
987 if (CURRENT_ENV->failing()) { | |
988 tty->print_cr("failing: %s", CURRENT_ENV->failure_reason()); | |
989 } | |
990 } | |
991 | 938 |
992 // if install_code is true then we installed the code into the given method, no need to return an RiCompiledMethod | 939 // if install_code is true then we installed the code into the given method, no need to return an RiCompiledMethod |
993 if (!install_code && nm != NULL) { | 940 if (!install_code && nm != NULL) { |
994 instanceKlass::cast(HotSpotCompiledMethod::klass())->initialize(CHECK_NULL); | 941 instanceKlass::cast(HotSpotCompiledMethod::klass())->initialize(CHECK_NULL); |
995 Handle obj = instanceKlass::cast(HotSpotCompiledMethod::klass())->allocate_permanent_instance(CHECK_NULL); | 942 Handle obj = instanceKlass::cast(HotSpotCompiledMethod::klass())->allocate_permanent_instance(CHECK_NULL); |
1005 | 952 |
1006 // public HotSpotProxy installStub(HotSpotTargetMethod targetMethod, String name); | 953 // public HotSpotProxy installStub(HotSpotTargetMethod targetMethod, String name); |
1007 JNIEXPORT jlong JNICALL Java_com_oracle_graal_hotspot_VMEntries_installStub(JNIEnv *jniEnv, jobject, jobject targetMethod) { | 954 JNIEXPORT jlong JNICALL Java_com_oracle_graal_hotspot_VMEntries_installStub(JNIEnv *jniEnv, jobject, jobject targetMethod) { |
1008 VM_ENTRY_MARK; | 955 VM_ENTRY_MARK; |
1009 jlong id; | 956 jlong id; |
1010 if (CURRENT_ENV == NULL) { | 957 ciEnv* current_env = JavaThread::current()->env(); |
1011 Arena arena; | 958 JavaThread::current()->set_env(NULL); |
1012 ciEnv env(&arena); | 959 Arena arena; |
1013 ResourceMark rm; | 960 ciEnv env(&arena); |
1014 CodeInstaller installer(JNIHandles::resolve(targetMethod), id); | 961 ResourceMark rm; |
1015 } else { | 962 CodeInstaller installer(JNIHandles::resolve(targetMethod), id); |
1016 ResourceMark rm; | 963 JavaThread::current()->set_env(current_env); |
1017 CodeInstaller installer(JNIHandles::resolve(targetMethod), id); | |
1018 } | |
1019 return id; | 964 return id; |
1020 } | 965 } |
1021 | 966 |
1022 // public void recordBailout(String reason); | 967 // public void recordBailout(String reason); |
1023 JNIEXPORT void JNICALL Java_com_oracle_graal_hotspot_VMEntries_recordBailout(JNIEnv *jniEnv, jobject, jobject message) { | 968 JNIEXPORT void JNICALL Java_com_oracle_graal_hotspot_VMEntries_recordBailout(JNIEnv *jniEnv, jobject, jobject message) { |