comparison src/share/vm/classfile/javaClasses.cpp @ 2645:0b80db433fcb

7046490: Preallocated OOME objects should obey Throwable stack trace protocol Summary: Update the OOME stacktrace to contain Throwable.UNASSIGNED_STACK when the backtrace is filled in Reviewed-by: mchung, phh
author dholmes
date Fri, 22 Jul 2011 00:29:01 -0700
parents b16582d6c7db
children a32de5085326
comparison
equal deleted inserted replaced
43:7e77f4794fe2 44:1348cda3cd4c
1017 compute_offset(_vmAllowSuspension_offset, k, vmSymbols::vmAllowSuspension_name(), vmSymbols::bool_signature()); 1017 compute_offset(_vmAllowSuspension_offset, k, vmSymbols::vmAllowSuspension_name(), vmSymbols::bool_signature());
1018 compute_offset(_nthreads_offset, k, vmSymbols::nthreads_name(), vmSymbols::int_signature()); 1018 compute_offset(_nthreads_offset, k, vmSymbols::nthreads_name(), vmSymbols::int_signature());
1019 compute_offset(_ngroups_offset, k, vmSymbols::ngroups_name(), vmSymbols::int_signature()); 1019 compute_offset(_ngroups_offset, k, vmSymbols::ngroups_name(), vmSymbols::int_signature());
1020 } 1020 }
1021 1021
1022 oop java_lang_Throwable::unassigned_stacktrace() {
1023 instanceKlass* ik = instanceKlass::cast(SystemDictionary::Throwable_klass());
1024 address addr = ik->static_field_addr(static_unassigned_stacktrace_offset);
1025 if (UseCompressedOops) {
1026 return oopDesc::load_decode_heap_oop((narrowOop *)addr);
1027 } else {
1028 return oopDesc::load_decode_heap_oop((oop*)addr);
1029 }
1030 }
1031
1022 oop java_lang_Throwable::backtrace(oop throwable) { 1032 oop java_lang_Throwable::backtrace(oop throwable) {
1023 return throwable->obj_field_acquire(backtrace_offset); 1033 return throwable->obj_field_acquire(backtrace_offset);
1024 } 1034 }
1025 1035
1026 1036
1042 void java_lang_Throwable::set_message(oop throwable, oop value) { 1052 void java_lang_Throwable::set_message(oop throwable, oop value) {
1043 throwable->obj_field_put(detailMessage_offset, value); 1053 throwable->obj_field_put(detailMessage_offset, value);
1044 } 1054 }
1045 1055
1046 1056
1057 void java_lang_Throwable::set_stacktrace(oop throwable, oop st_element_array) {
1058 throwable->obj_field_put(stackTrace_offset, st_element_array);
1059 }
1060
1047 void java_lang_Throwable::clear_stacktrace(oop throwable) { 1061 void java_lang_Throwable::clear_stacktrace(oop throwable) {
1048 assert(JDK_Version::is_gte_jdk14x_version(), "should only be called in >= 1.4"); 1062 assert(JDK_Version::is_gte_jdk14x_version(), "should only be called in >= 1.4");
1049 throwable->obj_field_put(stackTrace_offset, NULL); 1063 set_stacktrace(throwable, NULL);
1050 } 1064 }
1051 1065
1052 1066
1053 void java_lang_Throwable::print(oop throwable, outputStream* st) { 1067 void java_lang_Throwable::print(oop throwable, outputStream* st) {
1054 ResourceMark rm; 1068 ResourceMark rm;
1338 // runs out of memory while allocating the stack trace 1352 // runs out of memory while allocating the stack trace
1339 set_backtrace(throwable(), NULL); 1353 set_backtrace(throwable(), NULL);
1340 if (JDK_Version::is_gte_jdk14x_version()) { 1354 if (JDK_Version::is_gte_jdk14x_version()) {
1341 // New since 1.4, clear lazily constructed Java level stacktrace if 1355 // New since 1.4, clear lazily constructed Java level stacktrace if
1342 // refilling occurs 1356 // refilling occurs
1357 // This is unnecessary in 1.7+ but harmless
1343 clear_stacktrace(throwable()); 1358 clear_stacktrace(throwable());
1344 } 1359 }
1345 1360
1346 int max_depth = MaxJavaStackTraceDepth; 1361 int max_depth = MaxJavaStackTraceDepth;
1347 JavaThread* thread = (JavaThread*)THREAD; 1362 JavaThread* thread = (JavaThread*)THREAD;
1539 chunk_count++; 1554 chunk_count++;
1540 1555
1541 // Bail-out for deep stacks 1556 // Bail-out for deep stacks
1542 if (chunk_count >= max_chunks) break; 1557 if (chunk_count >= max_chunks) break;
1543 } 1558 }
1559
1560 // For Java 7+ we support the Throwable immutability protocol defined for Java 7. This support
1561 // was missing in 7u0 so in 7u0 there is a workaround in the Throwable class. That workaround
1562 // can be removed in a JDK using this JVM version
1563 if (JDK_Version::is_gte_jdk17x_version()) {
1564 java_lang_Throwable::set_stacktrace(throwable(), java_lang_Throwable::unassigned_stacktrace());
1565 assert(java_lang_Throwable::unassigned_stacktrace() != NULL, "not initialized");
1566 }
1567
1544 } 1568 }
1545 1569
1546 1570
1547 int java_lang_Throwable::get_stack_trace_depth(oop throwable, TRAPS) { 1571 int java_lang_Throwable::get_stack_trace_depth(oop throwable, TRAPS) {
1548 if (throwable == NULL) { 1572 if (throwable == NULL) {
2768 int java_lang_Class::static_oop_field_count_offset; 2792 int java_lang_Class::static_oop_field_count_offset;
2769 int java_lang_Throwable::backtrace_offset; 2793 int java_lang_Throwable::backtrace_offset;
2770 int java_lang_Throwable::detailMessage_offset; 2794 int java_lang_Throwable::detailMessage_offset;
2771 int java_lang_Throwable::cause_offset; 2795 int java_lang_Throwable::cause_offset;
2772 int java_lang_Throwable::stackTrace_offset; 2796 int java_lang_Throwable::stackTrace_offset;
2797 int java_lang_Throwable::static_unassigned_stacktrace_offset;
2773 int java_lang_reflect_AccessibleObject::override_offset; 2798 int java_lang_reflect_AccessibleObject::override_offset;
2774 int java_lang_reflect_Method::clazz_offset; 2799 int java_lang_reflect_Method::clazz_offset;
2775 int java_lang_reflect_Method::name_offset; 2800 int java_lang_reflect_Method::name_offset;
2776 int java_lang_reflect_Method::returnType_offset; 2801 int java_lang_reflect_Method::returnType_offset;
2777 int java_lang_reflect_Method::parameterTypes_offset; 2802 int java_lang_reflect_Method::parameterTypes_offset;
2945 // Throwable Class 2970 // Throwable Class
2946 java_lang_Throwable::backtrace_offset = java_lang_Throwable::hc_backtrace_offset * x + header; 2971 java_lang_Throwable::backtrace_offset = java_lang_Throwable::hc_backtrace_offset * x + header;
2947 java_lang_Throwable::detailMessage_offset = java_lang_Throwable::hc_detailMessage_offset * x + header; 2972 java_lang_Throwable::detailMessage_offset = java_lang_Throwable::hc_detailMessage_offset * x + header;
2948 java_lang_Throwable::cause_offset = java_lang_Throwable::hc_cause_offset * x + header; 2973 java_lang_Throwable::cause_offset = java_lang_Throwable::hc_cause_offset * x + header;
2949 java_lang_Throwable::stackTrace_offset = java_lang_Throwable::hc_stackTrace_offset * x + header; 2974 java_lang_Throwable::stackTrace_offset = java_lang_Throwable::hc_stackTrace_offset * x + header;
2975 java_lang_Throwable::static_unassigned_stacktrace_offset = java_lang_Throwable::hc_static_unassigned_stacktrace_offset * x;
2950 2976
2951 // java_lang_boxing_object 2977 // java_lang_boxing_object
2952 java_lang_boxing_object::value_offset = java_lang_boxing_object::hc_value_offset + header; 2978 java_lang_boxing_object::value_offset = java_lang_boxing_object::hc_value_offset + header;
2953 java_lang_boxing_object::long_value_offset = align_size_up((java_lang_boxing_object::hc_value_offset + header), BytesPerLong); 2979 java_lang_boxing_object::long_value_offset = align_size_up((java_lang_boxing_object::hc_value_offset + header), BytesPerLong);
2954 2980