comparison src/share/vm/oops/instanceKlass.cpp @ 18041:52b4284cb496

Merge with jdk8u20-b26
author Gilles Duboscq <duboscq@ssw.jku.at>
date Wed, 15 Oct 2014 16:02:50 +0200
parents 89152779163c bd4d69d9cb7d
children e6637891a870
comparison
equal deleted inserted replaced
17606:45d7b2c7029d 18041:52b4284cb496
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.
77 #endif // INCLUDE_ALL_GCS 77 #endif // INCLUDE_ALL_GCS
78 #ifdef COMPILER1 78 #ifdef COMPILER1
79 #include "c1/c1_Compiler.hpp" 79 #include "c1/c1_Compiler.hpp"
80 #endif 80 #endif
81 81
82 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
83
82 #ifdef DTRACE_ENABLED 84 #ifdef DTRACE_ENABLED
83 85
84 #ifndef USDT2 86 #ifndef USDT2
85 87
86 HS_DTRACE_PROBE_DECL4(hotspot, class__initialization__required, 88 HS_DTRACE_PROBE_DECL4(hotspot, class__initialization__required,
1238 if (_oop_map_cache == NULL) { 1240 if (_oop_map_cache == NULL) {
1239 // Otherwise, allocate a new one. 1241 // Otherwise, allocate a new one.
1240 MutexLocker x(OopMapCacheAlloc_lock); 1242 MutexLocker x(OopMapCacheAlloc_lock);
1241 // First time use. Allocate a cache in C heap 1243 // First time use. Allocate a cache in C heap
1242 if (_oop_map_cache == NULL) { 1244 if (_oop_map_cache == NULL) {
1243 _oop_map_cache = new OopMapCache(); 1245 // Release stores from OopMapCache constructor before assignment
1246 // to _oop_map_cache. C++ compilers on ppc do not emit the
1247 // required memory barrier only because of the volatile
1248 // qualifier of _oop_map_cache.
1249 OrderAccess::release_store_ptr(&_oop_map_cache, new OopMapCache());
1244 } 1250 }
1245 } 1251 }
1246 // _oop_map_cache is constant after init; lookup below does is own locking. 1252 // _oop_map_cache is constant after init; lookup below does is own locking.
1247 _oop_map_cache->lookup(method, bci, entry_for); 1253 _oop_map_cache->lookup(method, bci, entry_for);
1248 } 1254 }
1360 } 1366 }
1361 } 1367 }
1362 } 1368 }
1363 1369
1364 1370
1365 void InstanceKlass::do_local_static_fields(void f(fieldDescriptor*, TRAPS), TRAPS) { 1371 void InstanceKlass::do_local_static_fields(void f(fieldDescriptor*, Handle, TRAPS), Handle mirror, TRAPS) {
1366 instanceKlassHandle h_this(THREAD, this); 1372 instanceKlassHandle h_this(THREAD, this);
1367 do_local_static_fields_impl(h_this, f, CHECK); 1373 do_local_static_fields_impl(h_this, f, mirror, CHECK);
1368 } 1374 }
1369 1375
1370 1376
1371 void InstanceKlass::do_local_static_fields_impl(instanceKlassHandle this_oop, void f(fieldDescriptor* fd, TRAPS), TRAPS) { 1377 void InstanceKlass::do_local_static_fields_impl(instanceKlassHandle this_k,
1372 for (JavaFieldStream fs(this_oop()); !fs.done(); fs.next()) { 1378 void f(fieldDescriptor* fd, Handle mirror, TRAPS), Handle mirror, TRAPS) {
1379 for (JavaFieldStream fs(this_k()); !fs.done(); fs.next()) {
1373 if (fs.access_flags().is_static()) { 1380 if (fs.access_flags().is_static()) {
1374 fieldDescriptor& fd = fs.field_descriptor(); 1381 fieldDescriptor& fd = fs.field_descriptor();
1375 f(&fd, CHECK); 1382 f(&fd, mirror, CHECK);
1376 } 1383 }
1377 } 1384 }
1378 } 1385 }
1379 1386
1380 1387
1459 return -1; 1466 return -1;
1460 } 1467 }
1461 1468
1462 // find_method looks up the name/signature in the local methods array 1469 // find_method looks up the name/signature in the local methods array
1463 Method* InstanceKlass::find_method(Symbol* name, Symbol* signature) const { 1470 Method* InstanceKlass::find_method(Symbol* name, Symbol* signature) const {
1464 return InstanceKlass::find_method(methods(), name, signature); 1471 return find_method_impl(name, signature, false);
1472 }
1473
1474 Method* InstanceKlass::find_method_impl(Symbol* name, Symbol* signature, bool skipping_overpass) const {
1475 return InstanceKlass::find_method_impl(methods(), name, signature, skipping_overpass);
1465 } 1476 }
1466 1477
1467 // find_instance_method looks up the name/signature in the local methods array 1478 // find_instance_method looks up the name/signature in the local methods array
1468 // and skips over static methods 1479 // and skips over static methods
1469 Method* InstanceKlass::find_instance_method( 1480 Method* InstanceKlass::find_instance_method(
1476 } 1487 }
1477 1488
1478 // find_method looks up the name/signature in the local methods array 1489 // find_method looks up the name/signature in the local methods array
1479 Method* InstanceKlass::find_method( 1490 Method* InstanceKlass::find_method(
1480 Array<Method*>* methods, Symbol* name, Symbol* signature) { 1491 Array<Method*>* methods, Symbol* name, Symbol* signature) {
1481 int hit = find_method_index(methods, name, signature); 1492 return InstanceKlass::find_method_impl(methods, name, signature, false);
1493 }
1494
1495 Method* InstanceKlass::find_method_impl(
1496 Array<Method*>* methods, Symbol* name, Symbol* signature, bool skipping_overpass) {
1497 int hit = find_method_index(methods, name, signature, skipping_overpass);
1482 return hit >= 0 ? methods->at(hit): NULL; 1498 return hit >= 0 ? methods->at(hit): NULL;
1483 } 1499 }
1484 1500
1485 // Used directly for default_methods to find the index into the 1501 // Used directly for default_methods to find the index into the
1486 // default_vtable_indices, and indirectly by find_method 1502 // default_vtable_indices, and indirectly by find_method
1487 // find_method_index looks in the local methods array to return the index 1503 // find_method_index looks in the local methods array to return the index
1488 // of the matching name/signature 1504 // of the matching name/signature. If, overpass methods are being ignored,
1505 // the search continues to find a potential non-overpass match. This capability
1506 // is important during method resolution to prefer a static method, for example,
1507 // over an overpass method.
1489 int InstanceKlass::find_method_index( 1508 int InstanceKlass::find_method_index(
1490 Array<Method*>* methods, Symbol* name, Symbol* signature) { 1509 Array<Method*>* methods, Symbol* name, Symbol* signature, bool skipping_overpass) {
1491 int hit = binary_search(methods, name); 1510 int hit = binary_search(methods, name);
1492 if (hit != -1) { 1511 if (hit != -1) {
1493 Method* m = methods->at(hit); 1512 Method* m = methods->at(hit);
1494 // Do linear search to find matching signature. First, quick check 1513 // Do linear search to find matching signature. First, quick check
1495 // for common case 1514 // for common case, ignoring overpasses if requested.
1496 if (m->signature() == signature) return hit; 1515 if ((m->signature() == signature) && (!skipping_overpass || !m->is_overpass())) return hit;
1516
1497 // search downwards through overloaded methods 1517 // search downwards through overloaded methods
1498 int i; 1518 int i;
1499 for (i = hit - 1; i >= 0; --i) { 1519 for (i = hit - 1; i >= 0; --i) {
1500 Method* m = methods->at(i); 1520 Method* m = methods->at(i);
1501 assert(m->is_method(), "must be method"); 1521 assert(m->is_method(), "must be method");
1502 if (m->name() != name) break; 1522 if (m->name() != name) break;
1503 if (m->signature() == signature) return i; 1523 if ((m->signature() == signature) && (!skipping_overpass || !m->is_overpass())) return i;
1504 } 1524 }
1505 // search upwards 1525 // search upwards
1506 for (i = hit + 1; i < methods->length(); ++i) { 1526 for (i = hit + 1; i < methods->length(); ++i) {
1507 Method* m = methods->at(i); 1527 Method* m = methods->at(i);
1508 assert(m->is_method(), "must be method"); 1528 assert(m->is_method(), "must be method");
1509 if (m->name() != name) break; 1529 if (m->name() != name) break;
1510 if (m->signature() == signature) return i; 1530 if ((m->signature() == signature) && (!skipping_overpass || !m->is_overpass())) return i;
1511 } 1531 }
1512 // not found 1532 // not found
1513 #ifdef ASSERT 1533 #ifdef ASSERT
1514 int index = linear_search(methods, name, signature); 1534 int index = skipping_overpass ? -1 : linear_search(methods, name, signature);
1515 assert(index == -1, err_msg("binary search should have found entry %d", index)); 1535 assert(index == -1, err_msg("binary search should have found entry %d", index));
1516 #endif 1536 #endif
1517 } 1537 }
1518 return -1; 1538 return -1;
1519 } 1539 }
1535 return -1; 1555 return -1;
1536 } 1556 }
1537 1557
1538 // uncached_lookup_method searches both the local class methods array and all 1558 // uncached_lookup_method searches both the local class methods array and all
1539 // superclasses methods arrays, skipping any overpass methods in superclasses. 1559 // superclasses methods arrays, skipping any overpass methods in superclasses.
1540 Method* InstanceKlass::uncached_lookup_method(Symbol* name, Symbol* signature) const { 1560 Method* InstanceKlass::uncached_lookup_method(Symbol* name, Symbol* signature, MethodLookupMode mode) const {
1561 MethodLookupMode lookup_mode = mode;
1541 Klass* klass = const_cast<InstanceKlass*>(this); 1562 Klass* klass = const_cast<InstanceKlass*>(this);
1542 bool dont_ignore_overpasses = true; // For the class being searched, find its overpasses.
1543 while (klass != NULL) { 1563 while (klass != NULL) {
1544 Method* method = InstanceKlass::cast(klass)->find_method(name, signature); 1564 Method* method = InstanceKlass::cast(klass)->find_method_impl(name, signature, (lookup_mode == skip_overpass));
1545 if ((method != NULL) && (dont_ignore_overpasses || !method->is_overpass())) { 1565 if (method != NULL) {
1546 return method; 1566 return method;
1547 } 1567 }
1548 klass = InstanceKlass::cast(klass)->super(); 1568 klass = InstanceKlass::cast(klass)->super();
1549 dont_ignore_overpasses = false; // Ignore overpass methods in all superclasses. 1569 lookup_mode = skip_overpass; // Always ignore overpass methods in superclasses
1550 } 1570 }
1551 return NULL; 1571 return NULL;
1552 } 1572 }
1553 1573
1554 // lookup a method in the default methods list then in all transitive interfaces 1574 // lookup a method in the default methods list then in all transitive interfaces
1559 if (default_methods() != NULL) { 1579 if (default_methods() != NULL) {
1560 m = find_method(default_methods(), name, signature); 1580 m = find_method(default_methods(), name, signature);
1561 } 1581 }
1562 // Look up interfaces 1582 // Look up interfaces
1563 if (m == NULL) { 1583 if (m == NULL) {
1564 m = lookup_method_in_all_interfaces(name, signature, false); 1584 m = lookup_method_in_all_interfaces(name, signature, normal);
1565 } 1585 }
1566 return m; 1586 return m;
1567 } 1587 }
1568 1588
1569 // lookup a method in all the interfaces that this class implements 1589 // lookup a method in all the interfaces that this class implements
1570 // Do NOT return private or static methods, new in JDK8 which are not externally visible 1590 // Do NOT return private or static methods, new in JDK8 which are not externally visible
1571 // They should only be found in the initial InterfaceMethodRef 1591 // They should only be found in the initial InterfaceMethodRef
1572 Method* InstanceKlass::lookup_method_in_all_interfaces(Symbol* name, 1592 Method* InstanceKlass::lookup_method_in_all_interfaces(Symbol* name,
1573 Symbol* signature, 1593 Symbol* signature,
1574 bool skip_default_methods) const { 1594 MethodLookupMode mode) const {
1575 Array<Klass*>* all_ifs = transitive_interfaces(); 1595 Array<Klass*>* all_ifs = transitive_interfaces();
1576 int num_ifs = all_ifs->length(); 1596 int num_ifs = all_ifs->length();
1577 InstanceKlass *ik = NULL; 1597 InstanceKlass *ik = NULL;
1578 for (int i = 0; i < num_ifs; i++) { 1598 for (int i = 0; i < num_ifs; i++) {
1579 ik = InstanceKlass::cast(all_ifs->at(i)); 1599 ik = InstanceKlass::cast(all_ifs->at(i));
1580 Method* m = ik->lookup_method(name, signature); 1600 Method* m = ik->lookup_method(name, signature);
1581 if (m != NULL && m->is_public() && !m->is_static() && 1601 if (m != NULL && m->is_public() && !m->is_static() &&
1582 (!skip_default_methods || !m->is_default_method())) { 1602 ((mode != skip_defaults) || !m->is_default_method())) {
1583 return m; 1603 return m;
1584 } 1604 }
1585 } 1605 }
1586 return NULL; 1606 return NULL;
1587 } 1607 }
2269 2289
2270 void InstanceKlass::clean_method_data(BoolObjectClosure* is_alive) { 2290 void InstanceKlass::clean_method_data(BoolObjectClosure* is_alive) {
2271 for (int m = 0; m < methods()->length(); m++) { 2291 for (int m = 0; m < methods()->length(); m++) {
2272 MethodData* mdo = methods()->at(m)->method_data(); 2292 MethodData* mdo = methods()->at(m)->method_data();
2273 if (mdo != NULL) { 2293 if (mdo != NULL) {
2274 for (ProfileData* data = mdo->first_data(); 2294 mdo->clean_method_data(is_alive);
2275 mdo->is_valid(data);
2276 data = mdo->next_data(data)) {
2277 data->clean_weak_klass_links(is_alive);
2278 }
2279 ParametersTypeData* parameters = mdo->parameters_type_data();
2280 if (parameters != NULL) {
2281 parameters->clean_weak_klass_links(is_alive);
2282 }
2283 } 2295 }
2284 } 2296 }
2285 } 2297 }
2286 2298
2287 2299
2323 2335
2324 Array<Method*>* methods = ik->methods(); 2336 Array<Method*>* methods = ik->methods();
2325 int num_methods = methods->length(); 2337 int num_methods = methods->length();
2326 for (int index2 = 0; index2 < num_methods; ++index2) { 2338 for (int index2 = 0; index2 < num_methods; ++index2) {
2327 methodHandle m(THREAD, methods->at(index2)); 2339 methodHandle m(THREAD, methods->at(index2));
2328 m()->link_method(m, CHECK); 2340 m->restore_unshareable_info(CHECK);
2329 // restore method's vtable by calling a virtual function
2330 m->restore_vtable();
2331 } 2341 }
2332 if (JvmtiExport::has_redefined_a_class()) { 2342 if (JvmtiExport::has_redefined_a_class()) {
2333 // Reinitialize vtable because RedefineClasses may have changed some 2343 // Reinitialize vtable because RedefineClasses may have changed some
2334 // entries in this vtable for super classes so the CDS vtable might 2344 // entries in this vtable for super classes so the CDS vtable might
2335 // point to old or obsolete entries. RedefineClasses doesn't fix up 2345 // point to old or obsolete entries. RedefineClasses doesn't fix up
2800 nmethod* cur = osr_nmethods_head(); 2810 nmethod* cur = osr_nmethods_head();
2801 int max_level = CompLevel_none; // Find the max comp level excluding n 2811 int max_level = CompLevel_none; // Find the max comp level excluding n
2802 Method* m = n->method(); 2812 Method* m = n->method();
2803 // Search for match 2813 // Search for match
2804 while(cur != NULL && cur != n) { 2814 while(cur != NULL && cur != n) {
2805 if (TieredCompilation) { 2815 if (TieredCompilation && m == cur->method()) {
2806 // Find max level before n 2816 // Find max level before n
2807 max_level = MAX2(max_level, cur->comp_level()); 2817 max_level = MAX2(max_level, cur->comp_level());
2808 } 2818 }
2809 last = cur; 2819 last = cur;
2810 cur = cur->osr_link(); 2820 cur = cur->osr_link();
2822 n->set_osr_link(NULL); 2832 n->set_osr_link(NULL);
2823 if (TieredCompilation) { 2833 if (TieredCompilation) {
2824 cur = next; 2834 cur = next;
2825 while (cur != NULL) { 2835 while (cur != NULL) {
2826 // Find max level after n 2836 // Find max level after n
2827 max_level = MAX2(max_level, cur->comp_level()); 2837 if (m == cur->method()) {
2838 max_level = MAX2(max_level, cur->comp_level());
2839 }
2828 cur = cur->osr_link(); 2840 cur = cur->osr_link();
2829 } 2841 }
2830 m->set_highest_osr_comp_level(max_level); 2842 m->set_highest_osr_comp_level(max_level);
2831 } 2843 }
2832 // Remember to unlock again 2844 // Remember to unlock again
2926 Klass::print_on(st); 2938 Klass::print_on(st);
2927 2939
2928 st->print(BULLET"instance size: %d", size_helper()); st->cr(); 2940 st->print(BULLET"instance size: %d", size_helper()); st->cr();
2929 st->print(BULLET"klass size: %d", size()); st->cr(); 2941 st->print(BULLET"klass size: %d", size()); st->cr();
2930 st->print(BULLET"access: "); access_flags().print_on(st); st->cr(); 2942 st->print(BULLET"access: "); access_flags().print_on(st); st->cr();
2931 st->print(BULLET"state: "); st->print_cr(state_names[_init_state]); 2943 st->print(BULLET"state: "); st->print_cr("%s", state_names[_init_state]);
2932 st->print(BULLET"name: "); name()->print_value_on(st); st->cr(); 2944 st->print(BULLET"name: "); name()->print_value_on(st); st->cr();
2933 st->print(BULLET"super: "); super()->print_value_on_maybe_null(st); st->cr(); 2945 st->print(BULLET"super: "); super()->print_value_on_maybe_null(st); st->cr();
2934 st->print(BULLET"sub: "); 2946 st->print(BULLET"sub: ");
2935 Klass* sub = subklass(); 2947 Klass* sub = subklass();
2936 int n; 2948 int n;
3220 public: 3232 public:
3221 virtual void do_oop(oop* p) { VerifyFieldClosure::do_oop_work(p); } 3233 virtual void do_oop(oop* p) { VerifyFieldClosure::do_oop_work(p); }
3222 virtual void do_oop(narrowOop* p) { VerifyFieldClosure::do_oop_work(p); } 3234 virtual void do_oop(narrowOop* p) { VerifyFieldClosure::do_oop_work(p); }
3223 }; 3235 };
3224 3236
3225 void InstanceKlass::verify_on(outputStream* st, bool check_dictionary) { 3237 void InstanceKlass::verify_on(outputStream* st) {
3226 #ifndef PRODUCT 3238 #ifndef PRODUCT
3227 // Avoid redundant verifies, this really should be in product. 3239 // Avoid redundant verifies, this really should be in product.
3228 if (_verify_count == Universe::verify_count()) return; 3240 if (_verify_count == Universe::verify_count()) return;
3229 _verify_count = Universe::verify_count(); 3241 _verify_count = Universe::verify_count();
3230 #endif 3242 #endif
3231 3243
3232 // Verify Klass 3244 // Verify Klass
3233 Klass::verify_on(st, check_dictionary); 3245 Klass::verify_on(st);
3234 3246
3235 // Verify that klass is present in SystemDictionary if not already 3247 // Verify that klass is present in ClassLoaderData
3236 // verifying the SystemDictionary. 3248 guarantee(class_loader_data()->contains_klass(this),
3237 if (is_loaded() && !is_anonymous() && check_dictionary) { 3249 "this class isn't found in class loader data");
3238 Symbol* h_name = name();
3239 SystemDictionary::verify_obj_klass_present(h_name, class_loader_data());
3240 }
3241 3250
3242 // Verify vtables 3251 // Verify vtables
3243 if (is_linked()) { 3252 if (is_linked()) {
3244 ResourceMark rm; 3253 ResourceMark rm;
3245 // $$$ This used to be done only for m/s collections. Doing it 3254 // $$$ This used to be done only for m/s collections. Doing it