comparison src/share/vm/graal/graalCompilerToVM.cpp @ 4441:4e3aaf14cbc6

fixed graal to hotspot
author Christian Haeubl <christian.haeubl@oracle.com>
date Mon, 23 Jan 2012 13:22:43 -0800
parents f7251c729b31
children dc6f6e2f1a00
comparison
equal deleted inserted replaced
4440:271220b49abc 4441:4e3aaf14cbc6
180 JNIEXPORT jint JNICALL Java_com_oracle_max_graal_hotspot_bridge_CompilerToVMImpl_RiMethod_1invocationCount(JNIEnv *, jobject, jobject hotspot_method) { 180 JNIEXPORT jint JNICALL Java_com_oracle_max_graal_hotspot_bridge_CompilerToVMImpl_RiMethod_1invocationCount(JNIEnv *, jobject, jobject hotspot_method) {
181 TRACE_graal_3("CompilerToVM::RiMethod_invocationCount"); 181 TRACE_graal_3("CompilerToVM::RiMethod_invocationCount");
182 return getMethodFromHotSpotMethod(hotspot_method)->invocation_count(); 182 return getMethodFromHotSpotMethod(hotspot_method)->invocation_count();
183 } 183 }
184 184
185 // public native int RiMethod_exceptionProbability(long vmId, int bci); 185 JNIEXPORT jobject JNICALL Java_com_oracle_max_graal_hotspot_bridge_CompilerToVMImpl_RiMethod_1methodData(JNIEnv *, jobject, jobject hotspot_method) {
186 JNIEXPORT jint JNICALL Java_com_oracle_max_graal_hotspot_bridge_CompilerToVMImpl_RiMethod_2exceptionProbability(JNIEnv *, jobject, jobject hotspot_method, jint bci) { 186 TRACE_graal_3("CompilerToVM::RiMethod_methodData");
187 TRACE_graal_3("CompilerToVM::RiMethod_exceptionProbability"); 187 VM_ENTRY_MARK;
188 VM_ENTRY_MARK; 188
189 ResourceMark rm; 189 methodDataHandle method_data = getMethodFromHotSpotMethod(hotspot_method)->method_data();
190 methodHandle method = getMethodFromHotSpotMethod(hotspot_method); 190 Handle graalMethodData = GraalCompiler::createHotSpotMethodData(method_data, THREAD);
191 methodDataHandle method_data = method->method_data(); 191 return JNIHandles::make_local(THREAD, graalMethodData());
192 if (method_data == NULL || !method_data->is_mature()) {
193 return -1;
194 }
195 ProfileData* data = method_data->bci_to_data(bci);
196 if (data == NULL) {
197 return 0;
198 }
199 uint trap = Deoptimization::trap_state_is_recompiled(data->trap_state())? 1: 0;
200 if (trap > 0) {
201 return 100;
202 } else {
203 return trap;
204 }
205 } 192 }
206 193
207 // ------------------------------------------------------------------ 194 // ------------------------------------------------------------------
208 // Adjust a CounterData count to be commensurate with 195 // Adjust a CounterData count to be commensurate with
209 // interpreter_invocation_count. If the MDO exists for 196 // interpreter_invocation_count. If the MDO exists for
226 count = (int)((double)count * method_life / counter_life + 0.5); 213 count = (int)((double)count * method_life / counter_life + 0.5);
227 count = (count > 0) ? count : 1; 214 count = (count > 0) ? count : 1;
228 } 215 }
229 } 216 }
230 return count; 217 return count;
231 }
232
233 // public native RiTypeProfile RiMethod_typeProfile(long vmId, int bci);
234 JNIEXPORT jobject JNICALL Java_com_oracle_max_graal_hotspot_bridge_CompilerToVMImpl_RiMethod_2typeProfile(JNIEnv *, jobject, jobject hotspot_method, jint bci) {
235 TRACE_graal_3("CompilerToVM::RiMethod_typeProfile");
236 VM_ENTRY_MARK;
237 Handle obj;
238
239 methodHandle method = getMethodFromHotSpotMethod(hotspot_method);
240 methodDataHandle method_data = method->method_data();
241 if (method_data == NULL || !method_data->is_mature()) {
242 return NULL;
243 }
244 ResourceMark rm;
245 ProfileData* data = method_data->bci_to_data(bci);
246 if (data != NULL && data->is_ReceiverTypeData()) {
247 ReceiverTypeData* recv = data->as_ReceiverTypeData();
248 GrowableArray<KlassHandle> receivers;
249 GrowableArray<int> counts;
250 // determine morphism
251 uint total_count = 0;
252 for (uint i = 0; i < recv->row_limit(); i++) {
253 klassOop receiver = recv->receiver(i);
254 if (receiver == NULL) continue;
255 uint count = recv->receiver_count(i);
256 total_count += count;
257 receivers.append(receiver);
258 counts.append(count);
259 }
260
261 instanceKlass::cast(RiTypeProfile::klass())->initialize(CHECK_NULL);
262 obj = instanceKlass::cast(RiTypeProfile::klass())->allocate_instance(CHECK_NULL);
263 assert(obj() != NULL, "must succeed in allocating instance");
264
265 int count = MAX2(total_count, recv->count());
266 RiTypeProfile::set_count(obj, scale_count(method_data(), count));
267 RiTypeProfile::set_morphism(obj, receivers.length());
268
269 if (receivers.length() > 0) {
270 typeArrayHandle probabilities = oopFactory::new_typeArray(T_FLOAT, receivers.length(), CHECK_NULL);
271 objArrayHandle types = oopFactory::new_objArray(SystemDictionary::RiType_klass(), receivers.length(), CHECK_NULL);
272 for (int i = 0; i < receivers.length(); i++) {
273 KlassHandle receiver = receivers.at(i);
274
275 float prob = counts.at(i) / (float) total_count;
276 Handle type = GraalCompiler::get_RiType(receiver, CHECK_NULL);
277
278 probabilities->float_at_put(i, prob);
279 types->obj_at_put(i, type());
280
281 }
282
283 RiTypeProfile::set_probabilities(obj, probabilities());
284 RiTypeProfile::set_types(obj, types());
285 } else {
286 RiTypeProfile::set_probabilities(obj, NULL);
287 RiTypeProfile::set_types(obj, NULL);
288 }
289 }
290 return JNIHandles::make_local(obj());
291 }
292
293 JNIEXPORT jdouble JNICALL Java_com_oracle_max_graal_hotspot_bridge_CompilerToVMImpl_RiMethod_2branchProbability(JNIEnv *, jobject, jobject hotspot_method, jint bci) {
294 TRACE_graal_3("CompilerToVM::RiMethod_typeProfile");
295 ResourceMark rm;
296 methodHandle method = getMethodFromHotSpotMethod(hotspot_method);
297 methodDataHandle method_data = method->method_data();
298
299 if (method_data == NULL || !method_data->is_mature()) return -1;
300 method_data->bci_to_data(bci);
301
302 ProfileData* data = method_data->bci_to_data(bci);
303 if (data == NULL || !data->is_JumpData()) return -1;
304
305 // get taken and not taken values
306 int taken = data->as_JumpData()->taken();
307 int not_taken = 0;
308 if (data->is_BranchData()) {
309 not_taken = data->as_BranchData()->not_taken();
310 }
311
312 // Give up if too few (or too many, in which case the sum will overflow) counts to be meaningful.
313 // We also check that individual counters are positive first, otherwise the sum can become positive.
314 if (taken < 0 || not_taken < 0 || taken + not_taken < 40) return -1;
315
316 // Pin probability to sane limits
317 if (taken == 0)
318 return 0;
319 else if (not_taken == 0)
320 return 1;
321 else { // Compute probability of true path
322 return (jdouble)(taken) / (taken + not_taken);
323 }
324 }
325
326 JNIEXPORT jobject JNICALL Java_com_oracle_max_graal_hotspot_bridge_CompilerToVMImpl_RiMethod_2switchProbability(JNIEnv *, jobject, jobject hotspot_method, jint bci) {
327 TRACE_graal_3("CompilerToVM::RiMethod_typeProfile");
328 VM_ENTRY_MARK;
329 ResourceMark rm;
330 methodHandle method = getMethodFromHotSpotMethod(hotspot_method);
331 methodDataHandle method_data = method->method_data();
332
333 if (method_data == NULL || !method_data->is_mature()) return NULL;
334
335 ProfileData* data = method_data->bci_to_data(bci);
336 if (data == NULL || !data->is_MultiBranchData()) return NULL;
337
338 MultiBranchData* branch_data = data->as_MultiBranchData();
339
340 long sum = 0;
341 int cases = branch_data->number_of_cases();
342 GrowableArray<uint>* counts = new GrowableArray<uint>(cases + 1);
343
344 for (int i = 0; i < cases; i++) {
345 uint value = branch_data->count_at(i);
346 sum += value;
347 counts->append(value);
348 }
349 uint value = branch_data->default_count();
350 sum += value;
351 counts->append(value);
352
353 // Give up if too few (or too many, in which case the sum will overflow) counts to be meaningful.
354 // We also check that individual counters are positive first, otherwise the sum can become positive.
355 if (sum < 10 * (cases + 3)) return NULL;
356
357 typeArrayOop probability = oopFactory::new_typeArray(T_DOUBLE, cases + 1, CHECK_NULL);
358 for (int i = 0; i < cases + 1; i++) {
359 probability->double_at_put(i, counts->at(i) / (double) sum);
360 }
361 return JNIHandles::make_local(probability);
362 } 218 }
363 219
364 // public native boolean RiMethod_hasCompiledCode(HotSpotMethodResolved method); 220 // public native boolean RiMethod_hasCompiledCode(HotSpotMethodResolved method);
365 JNIEXPORT jboolean JNICALL Java_com_oracle_max_graal_hotspot_bridge_CompilerToVMImpl_RiMethod_1hasCompiledCode(JNIEnv *, jobject, jobject hotspot_method) { 221 JNIEXPORT jboolean JNICALL Java_com_oracle_max_graal_hotspot_bridge_CompilerToVMImpl_RiMethod_1hasCompiledCode(JNIEnv *, jobject, jobject hotspot_method) {
366 TRACE_graal_3("CompilerToVM::RiMethod_hasCompiledCode"); 222 TRACE_graal_3("CompilerToVM::RiMethod_hasCompiledCode");
871 set_int(env, config, "instanceHeaderPrototypeOffset", Klass::prototype_header_offset_in_bytes() + klassOopDesc::klass_part_offset_in_bytes()); 727 set_int(env, config, "instanceHeaderPrototypeOffset", Klass::prototype_header_offset_in_bytes() + klassOopDesc::klass_part_offset_in_bytes());
872 set_int(env, config, "threadExceptionOopOffset", in_bytes(JavaThread::exception_oop_offset())); 728 set_int(env, config, "threadExceptionOopOffset", in_bytes(JavaThread::exception_oop_offset()));
873 set_int(env, config, "threadExceptionPcOffset", in_bytes(JavaThread::exception_pc_offset())); 729 set_int(env, config, "threadExceptionPcOffset", in_bytes(JavaThread::exception_pc_offset()));
874 set_int(env, config, "threadMultiNewArrayStorage", in_bytes(JavaThread::graal_multinewarray_storage_offset())); 730 set_int(env, config, "threadMultiNewArrayStorage", in_bytes(JavaThread::graal_multinewarray_storage_offset()));
875 set_int(env, config, "classMirrorOffset", klassOopDesc::klass_part_offset_in_bytes() + Klass::java_mirror_offset_in_bytes()); 731 set_int(env, config, "classMirrorOffset", klassOopDesc::klass_part_offset_in_bytes() + Klass::java_mirror_offset_in_bytes());
876 set_int(env, config, "methodDataDataOffset", in_bytes(methodDataOopDesc::data_offset)); 732
733 set_int(env, config, "methodDataOopDataOffset", in_bytes(methodDataOopDesc::data_offset()));
734 set_int(env, config, "dataLayoutHeaderSize", DataLayout::header_size_in_bytes());
735 set_int(env, config, "dataLayoutTagOffset", in_bytes(DataLayout::tag_offset()));
736 set_int(env, config, "dataLayoutFlagsOffset", in_bytes(DataLayout::flags_offset()));
737 set_int(env, config, "dataLayoutBCIOffset", in_bytes(DataLayout::bci_offset()));
738 set_int(env, config, "dataLayoutCellsOffset", in_bytes(DataLayout::cell_offset(0)));
739 set_int(env, config, "dataLayoutCellSize", DataLayout::cell_size);
740 set_int(env, config, "bciProfileWidth", BciProfileWidth);
741 set_int(env, config, "typeProfileWidth", TypeProfileWidth);
877 742
878 set_long(env, config, "debugStub", VmIds::addStub((address)warning)); 743 set_long(env, config, "debugStub", VmIds::addStub((address)warning));
879 set_long(env, config, "instanceofStub", VmIds::addStub(Runtime1::entry_for(Runtime1::slow_subtype_check_id))); 744 set_long(env, config, "instanceofStub", VmIds::addStub(Runtime1::entry_for(Runtime1::slow_subtype_check_id)));
880 set_long(env, config, "verifyPointerStub", VmIds::addStub(Runtime1::entry_for(Runtime1::graal_verify_pointer_id))); 745 set_long(env, config, "verifyPointerStub", VmIds::addStub(Runtime1::entry_for(Runtime1::graal_verify_pointer_id)));
881 set_long(env, config, "newInstanceStub", VmIds::addStub(Runtime1::entry_for(Runtime1::fast_new_instance_init_check_id))); 746 set_long(env, config, "newInstanceStub", VmIds::addStub(Runtime1::entry_for(Runtime1::fast_new_instance_init_check_id)));
895 set_long(env, config, "fastMonitorEnterStub", VmIds::addStub(Runtime1::entry_for(Runtime1::graal_monitorenter_id))); 760 set_long(env, config, "fastMonitorEnterStub", VmIds::addStub(Runtime1::entry_for(Runtime1::graal_monitorenter_id)));
896 set_long(env, config, "fastMonitorExitStub", VmIds::addStub(Runtime1::entry_for(Runtime1::graal_monitorexit_id))); 761 set_long(env, config, "fastMonitorExitStub", VmIds::addStub(Runtime1::entry_for(Runtime1::graal_monitorexit_id)));
897 set_long(env, config, "safepointPollingAddress", (jlong)(os::get_polling_page() + (SafepointPollOffset % os::vm_page_size()))); 762 set_long(env, config, "safepointPollingAddress", (jlong)(os::get_polling_page() + (SafepointPollOffset % os::vm_page_size())));
898 set_int(env, config, "runtimeCallStackSize", (jint)frame::arg_reg_save_area_bytes); 763 set_int(env, config, "runtimeCallStackSize", (jint)frame::arg_reg_save_area_bytes);
899 set_int(env, config, "klassModifierFlagsOffset", Klass::modifier_flags_offset_in_bytes() + sizeof(oopDesc)); 764 set_int(env, config, "klassModifierFlagsOffset", Klass::modifier_flags_offset_in_bytes() + sizeof(oopDesc));
765 set_int(env, config, "klassOopGraalMirrorOffset", klassOopDesc::klass_part_offset_in_bytes() + Klass::java_mirror_offset_in_bytes());
900 set_int(env, config, "klassOopOffset", java_lang_Class::klass_offset_in_bytes()); 766 set_int(env, config, "klassOopOffset", java_lang_Class::klass_offset_in_bytes());
767
901 set_boolean(env, config, "isPollingPageFar", Assembler::is_polling_page_far()); 768 set_boolean(env, config, "isPollingPageFar", Assembler::is_polling_page_far());
902 769
903 set_int(env, config, "nmethodEntryOffset", nmethod::verified_entry_point_offset()); 770 set_int(env, config, "nmethodEntryOffset", nmethod::verified_entry_point_offset());
904 771
905 BarrierSet* bs = Universe::heap()->barrier_set(); 772 BarrierSet* bs = Universe::heap()->barrier_set();
984 #define TYPE "Lcom/oracle/max/cri/ri/RiType;" 851 #define TYPE "Lcom/oracle/max/cri/ri/RiType;"
985 #define RESOLVED_TYPE "Lcom/oracle/max/graal/hotspot/ri/HotSpotTypeResolved;" 852 #define RESOLVED_TYPE "Lcom/oracle/max/graal/hotspot/ri/HotSpotTypeResolved;"
986 #define METHOD "Lcom/oracle/max/cri/ri/RiMethod;" 853 #define METHOD "Lcom/oracle/max/cri/ri/RiMethod;"
987 #define RESOLVED_METHOD "Lcom/oracle/max/graal/hotspot/ri/HotSpotMethodResolved;" 854 #define RESOLVED_METHOD "Lcom/oracle/max/graal/hotspot/ri/HotSpotMethodResolved;"
988 #define REFLECT_METHOD "Ljava/lang/reflect/Method;" 855 #define REFLECT_METHOD "Ljava/lang/reflect/Method;"
989 #define PROFILING_INFO "Lcom/oracle/max/cri/ri/RiProfilingInfo;"
990 #define SIGNATURE "Lcom/oracle/max/cri/ri/RiSignature;" 856 #define SIGNATURE "Lcom/oracle/max/cri/ri/RiSignature;"
991 #define FIELD "Lcom/oracle/max/cri/ri/RiField;" 857 #define FIELD "Lcom/oracle/max/cri/ri/RiField;"
992 #define RESOLVED_FIELD "Lcom/oracle/max/cri/ri/RiResolvedField;" 858 #define RESOLVED_FIELD "Lcom/oracle/max/cri/ri/RiResolvedField;"
993 #define CONSTANT_POOL "Lcom/oracle/max/cri/ri/RiConstantPool;" 859 #define CONSTANT_POOL "Lcom/oracle/max/cri/ri/RiConstantPool;"
994 #define EXCEPTION_HANDLERS "[Lcom/oracle/max/cri/ri/RiExceptionHandler;" 860 #define EXCEPTION_HANDLERS "[Lcom/oracle/max/cri/ri/RiExceptionHandler;"
995 #define TARGET_METHOD "Lcom/oracle/max/graal/hotspot/HotSpotTargetMethod;" 861 #define TARGET_METHOD "Lcom/oracle/max/graal/hotspot/HotSpotTargetMethod;"
996 #define CONFIG "Lcom/oracle/max/graal/hotspot/HotSpotVMConfig;" 862 #define CONFIG "Lcom/oracle/max/graal/hotspot/HotSpotVMConfig;"
997 #define HS_METHOD "Lcom/oracle/max/graal/hotspot/ri/HotSpotMethod;" 863 #define HS_METHOD "Lcom/oracle/max/graal/hotspot/ri/HotSpotMethod;"
998 #define HS_COMP_METHOD "Lcom/oracle/max/graal/hotspot/ri/HotSpotCompiledMethod;" 864 #define HS_COMP_METHOD "Lcom/oracle/max/graal/hotspot/ri/HotSpotCompiledMethod;"
865 #define METHOD_DATA "Lcom/oracle/max/graal/hotspot/HotSpotMethodData;"
999 #define CI_CONSTANT "Lcom/oracle/max/cri/ci/CiConstant;" 866 #define CI_CONSTANT "Lcom/oracle/max/cri/ci/CiConstant;"
1000 #define CI_KIND "Lcom/oracle/max/cri/ci/CiKind;" 867 #define CI_KIND "Lcom/oracle/max/cri/ci/CiKind;"
1001 #define CI_RUNTIME_CALL "Lcom/oracle/max/cri/ci/CiRuntimeCall;" 868 #define CI_RUNTIME_CALL "Lcom/oracle/max/cri/ci/CiRuntimeCall;"
1002 #define STRING "Ljava/lang/String;" 869 #define STRING "Ljava/lang/String;"
1003 #define OBJECT "Ljava/lang/Object;" 870 #define OBJECT "Ljava/lang/Object;"
1008 {CC"RiMethod_signature", CC"("RESOLVED_METHOD")"STRING, FN_PTR(RiMethod_1signature)}, 875 {CC"RiMethod_signature", CC"("RESOLVED_METHOD")"STRING, FN_PTR(RiMethod_1signature)},
1009 {CC"RiMethod_exceptionHandlers", CC"("RESOLVED_METHOD")"EXCEPTION_HANDLERS, FN_PTR(RiMethod_1exceptionHandlers)}, 876 {CC"RiMethod_exceptionHandlers", CC"("RESOLVED_METHOD")"EXCEPTION_HANDLERS, FN_PTR(RiMethod_1exceptionHandlers)},
1010 {CC"RiMethod_hasBalancedMonitors", CC"("RESOLVED_METHOD")Z", FN_PTR(RiMethod_1hasBalancedMonitors)}, 877 {CC"RiMethod_hasBalancedMonitors", CC"("RESOLVED_METHOD")Z", FN_PTR(RiMethod_1hasBalancedMonitors)},
1011 {CC"RiMethod_uniqueConcreteMethod", CC"("RESOLVED_METHOD")"METHOD, FN_PTR(RiMethod_1uniqueConcreteMethod)}, 878 {CC"RiMethod_uniqueConcreteMethod", CC"("RESOLVED_METHOD")"METHOD, FN_PTR(RiMethod_1uniqueConcreteMethod)},
1012 {CC"getRiMethod", CC"("REFLECT_METHOD")"METHOD, FN_PTR(getRiMethod)}, 879 {CC"getRiMethod", CC"("REFLECT_METHOD")"METHOD, FN_PTR(getRiMethod)},
1013 {CC"RiMethod_typeProfile", CC"("RESOLVED_METHOD"I)"TYPE_PROFILE, FN_PTR(RiMethod_2typeProfile)}, 880 {CC"RiMethod_methodData", CC"("RESOLVED_METHOD"I)"METHOD_DATA, FN_PTR(RiMethod_1methodData)},
1014 {CC"RiMethod_branchProbability", CC"("RESOLVED_METHOD"I)D", FN_PTR(RiMethod_2branchProbability)},
1015 {CC"RiMethod_switchProbability", CC"("RESOLVED_METHOD"I)[D", FN_PTR(RiMethod_2switchProbability)},
1016 {CC"RiMethod_invocationCount", CC"("RESOLVED_METHOD")I", FN_PTR(RiMethod_1invocationCount)}, 881 {CC"RiMethod_invocationCount", CC"("RESOLVED_METHOD")I", FN_PTR(RiMethod_1invocationCount)},
1017 {CC"RiMethod_exceptionProbability", CC"("RESOLVED_METHOD"I)I", FN_PTR(RiMethod_2exceptionProbability)},
1018 {CC"RiMethod_hasCompiledCode", CC"("RESOLVED_METHOD")Z", FN_PTR(RiMethod_1hasCompiledCode)}, 882 {CC"RiMethod_hasCompiledCode", CC"("RESOLVED_METHOD")Z", FN_PTR(RiMethod_1hasCompiledCode)},
1019 {CC"RiSignature_lookupType", CC"("STRING RESOLVED_TYPE")"TYPE, FN_PTR(RiSignature_1lookupType)}, 883 {CC"RiSignature_lookupType", CC"("STRING RESOLVED_TYPE")"TYPE, FN_PTR(RiSignature_1lookupType)},
1020 {CC"RiConstantPool_lookupConstant", CC"("RESOLVED_TYPE"I)"OBJECT, FN_PTR(RiConstantPool_1lookupConstant)}, 884 {CC"RiConstantPool_lookupConstant", CC"("RESOLVED_TYPE"I)"OBJECT, FN_PTR(RiConstantPool_1lookupConstant)},
1021 {CC"RiConstantPool_lookupMethod", CC"("RESOLVED_TYPE"IB)"METHOD, FN_PTR(RiConstantPool_1lookupMethod)}, 885 {CC"RiConstantPool_lookupMethod", CC"("RESOLVED_TYPE"IB)"METHOD, FN_PTR(RiConstantPool_1lookupMethod)},
1022 {CC"RiConstantPool_lookupType", CC"("RESOLVED_TYPE"I)"TYPE, FN_PTR(RiConstantPool_1lookupType)}, 886 {CC"RiConstantPool_lookupType", CC"("RESOLVED_TYPE"I)"TYPE, FN_PTR(RiConstantPool_1lookupType)},