comparison src/share/vm/oops/instanceKlass.cpp @ 14518:d8041d695d19

Merged with jdk9/dev/hotspot changeset 3812c088b945
author twisti
date Tue, 11 Mar 2014 18:45:59 -0700
parents b270b954ba9a 16c705d792be
children 8762b6b8fbb6
comparison
equal deleted inserted replaced
14141:f97c5ec83832 14518:d8041d695d19
1 /* 1 /*
2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * 4 *
5 * This code is free software; you can redistribute it and/or modify it 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 6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
47 #include "oops/oop.inline.hpp" 47 #include "oops/oop.inline.hpp"
48 #include "oops/symbol.hpp" 48 #include "oops/symbol.hpp"
49 #include "prims/jvmtiExport.hpp" 49 #include "prims/jvmtiExport.hpp"
50 #include "prims/jvmtiRedefineClassesTrace.hpp" 50 #include "prims/jvmtiRedefineClassesTrace.hpp"
51 #include "prims/jvmtiRedefineClasses.hpp" 51 #include "prims/jvmtiRedefineClasses.hpp"
52 #include "prims/jvmtiThreadState.hpp"
52 #include "prims/methodComparator.hpp" 53 #include "prims/methodComparator.hpp"
53 #include "runtime/fieldDescriptor.hpp" 54 #include "runtime/fieldDescriptor.hpp"
54 #include "runtime/handles.inline.hpp" 55 #include "runtime/handles.inline.hpp"
55 #include "runtime/javaCalls.hpp" 56 #include "runtime/javaCalls.hpp"
56 #include "runtime/mutexLocker.hpp" 57 #include "runtime/mutexLocker.hpp"
75 #include "c1/c1_Compiler.hpp" 76 #include "c1/c1_Compiler.hpp"
76 #endif 77 #endif
77 78
78 #ifdef DTRACE_ENABLED 79 #ifdef DTRACE_ENABLED
79 80
80 #ifndef USDT2
81
82 HS_DTRACE_PROBE_DECL4(hotspot, class__initialization__required,
83 char*, intptr_t, oop, intptr_t);
84 HS_DTRACE_PROBE_DECL5(hotspot, class__initialization__recursive,
85 char*, intptr_t, oop, intptr_t, int);
86 HS_DTRACE_PROBE_DECL5(hotspot, class__initialization__concurrent,
87 char*, intptr_t, oop, intptr_t, int);
88 HS_DTRACE_PROBE_DECL5(hotspot, class__initialization__erroneous,
89 char*, intptr_t, oop, intptr_t, int);
90 HS_DTRACE_PROBE_DECL5(hotspot, class__initialization__super__failed,
91 char*, intptr_t, oop, intptr_t, int);
92 HS_DTRACE_PROBE_DECL5(hotspot, class__initialization__clinit,
93 char*, intptr_t, oop, intptr_t, int);
94 HS_DTRACE_PROBE_DECL5(hotspot, class__initialization__error,
95 char*, intptr_t, oop, intptr_t, int);
96 HS_DTRACE_PROBE_DECL5(hotspot, class__initialization__end,
97 char*, intptr_t, oop, intptr_t, int);
98
99 #define DTRACE_CLASSINIT_PROBE(type, clss, thread_type) \
100 { \
101 char* data = NULL; \
102 int len = 0; \
103 Symbol* name = (clss)->name(); \
104 if (name != NULL) { \
105 data = (char*)name->bytes(); \
106 len = name->utf8_length(); \
107 } \
108 HS_DTRACE_PROBE4(hotspot, class__initialization__##type, \
109 data, len, SOLARIS_ONLY((void *))(clss)->class_loader(), thread_type); \
110 }
111
112 #define DTRACE_CLASSINIT_PROBE_WAIT(type, clss, thread_type, wait) \
113 { \
114 char* data = NULL; \
115 int len = 0; \
116 Symbol* name = (clss)->name(); \
117 if (name != NULL) { \
118 data = (char*)name->bytes(); \
119 len = name->utf8_length(); \
120 } \
121 HS_DTRACE_PROBE5(hotspot, class__initialization__##type, \
122 data, len, SOLARIS_ONLY((void *))(clss)->class_loader(), thread_type, wait); \
123 }
124 #else /* USDT2 */
125 81
126 #define HOTSPOT_CLASS_INITIALIZATION_required HOTSPOT_CLASS_INITIALIZATION_REQUIRED 82 #define HOTSPOT_CLASS_INITIALIZATION_required HOTSPOT_CLASS_INITIALIZATION_REQUIRED
127 #define HOTSPOT_CLASS_INITIALIZATION_recursive HOTSPOT_CLASS_INITIALIZATION_RECURSIVE 83 #define HOTSPOT_CLASS_INITIALIZATION_recursive HOTSPOT_CLASS_INITIALIZATION_RECURSIVE
128 #define HOTSPOT_CLASS_INITIALIZATION_concurrent HOTSPOT_CLASS_INITIALIZATION_CONCURRENT 84 #define HOTSPOT_CLASS_INITIALIZATION_concurrent HOTSPOT_CLASS_INITIALIZATION_CONCURRENT
129 #define HOTSPOT_CLASS_INITIALIZATION_erroneous HOTSPOT_CLASS_INITIALIZATION_ERRONEOUS 85 #define HOTSPOT_CLASS_INITIALIZATION_erroneous HOTSPOT_CLASS_INITIALIZATION_ERRONEOUS
154 len = name->utf8_length(); \ 110 len = name->utf8_length(); \
155 } \ 111 } \
156 HOTSPOT_CLASS_INITIALIZATION_##type( \ 112 HOTSPOT_CLASS_INITIALIZATION_##type( \
157 data, len, (clss)->class_loader(), thread_type, wait); \ 113 data, len, (clss)->class_loader(), thread_type, wait); \
158 } 114 }
159 #endif /* USDT2 */
160 115
161 #else // ndef DTRACE_ENABLED 116 #else // ndef DTRACE_ENABLED
162 117
163 #define DTRACE_CLASSINIT_PROBE(type, clss, thread_type) 118 #define DTRACE_CLASSINIT_PROBE(type, clss, thread_type)
164 #define DTRACE_CLASSINIT_PROBE_WAIT(type, clss, thread_type, wait) 119 #define DTRACE_CLASSINIT_PROBE_WAIT(type, clss, thread_type, wait)
906 } 861 }
907 else { 862 else {
908 // Step 10 and 11 863 // Step 10 and 11
909 Handle e(THREAD, PENDING_EXCEPTION); 864 Handle e(THREAD, PENDING_EXCEPTION);
910 CLEAR_PENDING_EXCEPTION; 865 CLEAR_PENDING_EXCEPTION;
866 // JVMTI has already reported the pending exception
867 // JVMTI internal flag reset is needed in order to report ExceptionInInitializerError
868 JvmtiExport::clear_detected_exception((JavaThread*)THREAD);
911 { 869 {
912 EXCEPTION_MARK; 870 EXCEPTION_MARK;
913 this_oop->set_initialization_state_and_notify(initialization_error, THREAD); 871 this_oop->set_initialization_state_and_notify(initialization_error, THREAD);
914 CLEAR_PENDING_EXCEPTION; // ignore any exception thrown, class initialization error is thrown below 872 CLEAR_PENDING_EXCEPTION; // ignore any exception thrown, class initialization error is thrown below
873 // JVMTI has already reported the pending exception
874 // JVMTI internal flag reset is needed in order to report ExceptionInInitializerError
875 JvmtiExport::clear_detected_exception((JavaThread*)THREAD);
915 } 876 }
916 DTRACE_CLASSINIT_PROBE_WAIT(error, InstanceKlass::cast(this_oop()), -1,wait); 877 DTRACE_CLASSINIT_PROBE_WAIT(error, InstanceKlass::cast(this_oop()), -1,wait);
917 if (e->is_a(SystemDictionary::Error_klass())) { 878 if (e->is_a(SystemDictionary::Error_klass())) {
918 THROW_OOP(e()); 879 THROW_OOP(e());
919 } else { 880 } else {
1201 if (_oop_map_cache == NULL) { 1162 if (_oop_map_cache == NULL) {
1202 // Otherwise, allocate a new one. 1163 // Otherwise, allocate a new one.
1203 MutexLocker x(OopMapCacheAlloc_lock); 1164 MutexLocker x(OopMapCacheAlloc_lock);
1204 // First time use. Allocate a cache in C heap 1165 // First time use. Allocate a cache in C heap
1205 if (_oop_map_cache == NULL) { 1166 if (_oop_map_cache == NULL) {
1206 _oop_map_cache = new OopMapCache(); 1167 // Release stores from OopMapCache constructor before assignment
1168 // to _oop_map_cache. C++ compilers on ppc do not emit the
1169 // required memory barrier only because of the volatile
1170 // qualifier of _oop_map_cache.
1171 OrderAccess::release_store_ptr(&_oop_map_cache, new OopMapCache());
1207 } 1172 }
1208 } 1173 }
1209 // _oop_map_cache is constant after init; lookup below does is own locking. 1174 // _oop_map_cache is constant after init; lookup below does is own locking.
1210 _oop_map_cache->lookup(method, bci, entry_for); 1175 _oop_map_cache->lookup(method, bci, entry_for);
1211 } 1176 }
1496 return start; 1461 return start;
1497 } 1462 }
1498 return -1; 1463 return -1;
1499 } 1464 }
1500 1465
1501 // lookup_method searches both the local methods array and all superclasses methods arrays 1466 // uncached_lookup_method searches both the local class methods array and all
1467 // superclasses methods arrays, skipping any overpass methods in superclasses.
1502 Method* InstanceKlass::uncached_lookup_method(Symbol* name, Symbol* signature) const { 1468 Method* InstanceKlass::uncached_lookup_method(Symbol* name, Symbol* signature) const {
1503 Klass* klass = const_cast<InstanceKlass*>(this); 1469 Klass* klass = const_cast<InstanceKlass*>(this);
1470 bool dont_ignore_overpasses = true; // For the class being searched, find its overpasses.
1504 while (klass != NULL) { 1471 while (klass != NULL) {
1505 Method* method = InstanceKlass::cast(klass)->find_method(name, signature); 1472 Method* method = InstanceKlass::cast(klass)->find_method(name, signature);
1506 if (method != NULL) return method; 1473 if ((method != NULL) && (dont_ignore_overpasses || !method->is_overpass())) {
1474 return method;
1475 }
1507 klass = InstanceKlass::cast(klass)->super(); 1476 klass = InstanceKlass::cast(klass)->super();
1477 dont_ignore_overpasses = false; // Ignore overpass methods in all superclasses.
1508 } 1478 }
1509 return NULL; 1479 return NULL;
1510 } 1480 }
1511 1481
1512 // lookup a method in the default methods list then in all transitive interfaces 1482 // lookup a method in the default methods list then in all transitive interfaces
1517 if (default_methods() != NULL) { 1487 if (default_methods() != NULL) {
1518 m = find_method(default_methods(), name, signature); 1488 m = find_method(default_methods(), name, signature);
1519 } 1489 }
1520 // Look up interfaces 1490 // Look up interfaces
1521 if (m == NULL) { 1491 if (m == NULL) {
1522 m = lookup_method_in_all_interfaces(name, signature); 1492 m = lookup_method_in_all_interfaces(name, signature, false);
1523 } 1493 }
1524 return m; 1494 return m;
1525 } 1495 }
1526 1496
1527 // lookup a method in all the interfaces that this class implements 1497 // lookup a method in all the interfaces that this class implements
1528 // Do NOT return private or static methods, new in JDK8 which are not externally visible 1498 // Do NOT return private or static methods, new in JDK8 which are not externally visible
1529 // They should only be found in the initial InterfaceMethodRef 1499 // They should only be found in the initial InterfaceMethodRef
1530 Method* InstanceKlass::lookup_method_in_all_interfaces(Symbol* name, 1500 Method* InstanceKlass::lookup_method_in_all_interfaces(Symbol* name,
1531 Symbol* signature) const { 1501 Symbol* signature,
1502 bool skip_default_methods) const {
1532 Array<Klass*>* all_ifs = transitive_interfaces(); 1503 Array<Klass*>* all_ifs = transitive_interfaces();
1533 int num_ifs = all_ifs->length(); 1504 int num_ifs = all_ifs->length();
1534 InstanceKlass *ik = NULL; 1505 InstanceKlass *ik = NULL;
1535 for (int i = 0; i < num_ifs; i++) { 1506 for (int i = 0; i < num_ifs; i++) {
1536 ik = InstanceKlass::cast(all_ifs->at(i)); 1507 ik = InstanceKlass::cast(all_ifs->at(i));
1537 Method* m = ik->lookup_method(name, signature); 1508 Method* m = ik->lookup_method(name, signature);
1538 if (m != NULL && m->is_public() && !m->is_static()) { 1509 if (m != NULL && m->is_public() && !m->is_static() &&
1510 (!skip_default_methods || !m->is_default_method())) {
1539 return m; 1511 return m;
1540 } 1512 }
1541 } 1513 }
1542 return NULL; 1514 return NULL;
1543 } 1515 }
2225 2197
2226 void InstanceKlass::clean_method_data(BoolObjectClosure* is_alive) { 2198 void InstanceKlass::clean_method_data(BoolObjectClosure* is_alive) {
2227 for (int m = 0; m < methods()->length(); m++) { 2199 for (int m = 0; m < methods()->length(); m++) {
2228 MethodData* mdo = methods()->at(m)->method_data(); 2200 MethodData* mdo = methods()->at(m)->method_data();
2229 if (mdo != NULL) { 2201 if (mdo != NULL) {
2230 for (ProfileData* data = mdo->first_data(); 2202 mdo->clean_method_data(is_alive);
2231 mdo->is_valid(data);
2232 data = mdo->next_data(data)) {
2233 data->clean_weak_klass_links(is_alive);
2234 }
2235 ParametersTypeData* parameters = mdo->parameters_type_data();
2236 if (parameters != NULL) {
2237 parameters->clean_weak_klass_links(is_alive);
2238 }
2239 } 2203 }
2240 } 2204 }
2241 } 2205 }
2242 2206
2243 2207
2752 nmethod* cur = osr_nmethods_head(); 2716 nmethod* cur = osr_nmethods_head();
2753 int max_level = CompLevel_none; // Find the max comp level excluding n 2717 int max_level = CompLevel_none; // Find the max comp level excluding n
2754 Method* m = n->method(); 2718 Method* m = n->method();
2755 // Search for match 2719 // Search for match
2756 while(cur != NULL && cur != n) { 2720 while(cur != NULL && cur != n) {
2757 if (TieredCompilation) { 2721 if (TieredCompilation && m == cur->method()) {
2758 // Find max level before n 2722 // Find max level before n
2759 max_level = MAX2(max_level, cur->comp_level()); 2723 max_level = MAX2(max_level, cur->comp_level());
2760 } 2724 }
2761 last = cur; 2725 last = cur;
2762 cur = cur->osr_link(); 2726 cur = cur->osr_link();
2774 n->set_osr_link(NULL); 2738 n->set_osr_link(NULL);
2775 if (TieredCompilation) { 2739 if (TieredCompilation) {
2776 cur = next; 2740 cur = next;
2777 while (cur != NULL) { 2741 while (cur != NULL) {
2778 // Find max level after n 2742 // Find max level after n
2779 max_level = MAX2(max_level, cur->comp_level()); 2743 if (m == cur->method()) {
2744 max_level = MAX2(max_level, cur->comp_level());
2745 }
2780 cur = cur->osr_link(); 2746 cur = cur->osr_link();
2781 } 2747 }
2782 m->set_highest_osr_comp_level(max_level); 2748 m->set_highest_osr_comp_level(max_level);
2783 } 2749 }
2784 // Remember to unlock again 2750 // Remember to unlock again
3020 juint length = java_lang_String::length(obj); 2986 juint length = java_lang_String::length(obj);
3021 if (value->is_typeArray() && 2987 if (value->is_typeArray() &&
3022 offset <= (juint) value->length() && 2988 offset <= (juint) value->length() &&
3023 offset + length <= (juint) value->length()) { 2989 offset + length <= (juint) value->length()) {
3024 st->print(BULLET"string: "); 2990 st->print(BULLET"string: ");
3025 Handle h_obj(obj); 2991 java_lang_String::print(obj, st);
3026 java_lang_String::print(h_obj, st);
3027 st->cr(); 2992 st->cr();
3028 if (!WizardMode) return; // that is enough 2993 if (!WizardMode) return; // that is enough
3029 } 2994 }
3030 } 2995 }
3031 } 2996 }
3172 public: 3137 public:
3173 virtual void do_oop(oop* p) { VerifyFieldClosure::do_oop_work(p); } 3138 virtual void do_oop(oop* p) { VerifyFieldClosure::do_oop_work(p); }
3174 virtual void do_oop(narrowOop* p) { VerifyFieldClosure::do_oop_work(p); } 3139 virtual void do_oop(narrowOop* p) { VerifyFieldClosure::do_oop_work(p); }
3175 }; 3140 };
3176 3141
3177 void InstanceKlass::verify_on(outputStream* st, bool check_dictionary) { 3142 void InstanceKlass::verify_on(outputStream* st) {
3178 #ifndef PRODUCT 3143 #ifndef PRODUCT
3179 // Avoid redundant verifies, this really should be in product. 3144 // Avoid redundant verifies, this really should be in product.
3180 if (_verify_count == Universe::verify_count()) return; 3145 if (_verify_count == Universe::verify_count()) return;
3181 _verify_count = Universe::verify_count(); 3146 _verify_count = Universe::verify_count();
3182 #endif 3147 #endif
3183 3148
3184 // Verify Klass 3149 // Verify Klass
3185 Klass::verify_on(st, check_dictionary); 3150 Klass::verify_on(st);
3186 3151
3187 // Verify that klass is present in SystemDictionary if not already 3152 // Verify that klass is present in ClassLoaderData
3188 // verifying the SystemDictionary. 3153 guarantee(class_loader_data()->contains_klass(this),
3189 if (is_loaded() && !is_anonymous() && check_dictionary) { 3154 "this class isn't found in class loader data");
3190 Symbol* h_name = name();
3191 SystemDictionary::verify_obj_klass_present(h_name, class_loader_data());
3192 }
3193 3155
3194 // Verify vtables 3156 // Verify vtables
3195 if (is_linked()) { 3157 if (is_linked()) {
3196 ResourceMark rm; 3158 ResourceMark rm;
3197 // $$$ This used to be done only for m/s collections. Doing it 3159 // $$$ This used to be done only for m/s collections. Doing it