instanceRefKlass.cpp revision 9099:115188e14c15
1181847Sjkim/* 2181847Sjkim * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved. 3181847Sjkim * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4181847Sjkim * 5181847Sjkim * This code is free software; you can redistribute it and/or modify it 6181847Sjkim * under the terms of the GNU General Public License version 2 only, as 7181847Sjkim * published by the Free Software Foundation. 8181847Sjkim * 9181847Sjkim * This code is distributed in the hope that it will be useful, but WITHOUT 10181847Sjkim * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11181847Sjkim * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12181847Sjkim * version 2 for more details (a copy is included in the LICENSE file that 13181847Sjkim * accompanied this code). 14181847Sjkim * 15181847Sjkim * You should have received a copy of the GNU General Public License version 16181847Sjkim * 2 along with this work; if not, write to the Free Software Foundation, 17181847Sjkim * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18181847Sjkim * 19181847Sjkim * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20181847Sjkim * or visit www.oracle.com if you need additional information or have any 21181847Sjkim * questions. 22181847Sjkim * 23181847Sjkim */ 24181847Sjkim 25181847Sjkim#include "precompiled.hpp" 26181847Sjkim#include "classfile/javaClasses.hpp" 27181847Sjkim#include "classfile/systemDictionary.hpp" 28181847Sjkim#include "gc/shared/collectedHeap.inline.hpp" 29182393Sjkim#include "gc/shared/genCollectedHeap.hpp" 30181847Sjkim#include "gc/shared/specialized_oop_closures.hpp" 31#include "oops/instanceRefKlass.inline.hpp" 32#include "oops/oop.inline.hpp" 33#include "utilities/macros.hpp" 34#include "utilities/preserveException.hpp" 35 36void InstanceRefKlass::update_nonstatic_oop_maps(Klass* k) { 37 // Clear the nonstatic oop-map entries corresponding to referent 38 // and nextPending field. They are treated specially by the 39 // garbage collector. 40 // The discovered field is used only by the garbage collector 41 // and is also treated specially. 42 InstanceKlass* ik = InstanceKlass::cast(k); 43 44 // Check that we have the right class 45 debug_only(static bool first_time = true); 46 assert(k == SystemDictionary::Reference_klass() && first_time, 47 "Invalid update of maps"); 48 debug_only(first_time = false); 49 assert(ik->nonstatic_oop_map_count() == 1, "just checking"); 50 51 OopMapBlock* map = ik->start_of_nonstatic_oop_maps(); 52 53 // Check that the current map is (2,4) - currently points at field with 54 // offset 2 (words) and has 4 map entries. 55 debug_only(int offset = java_lang_ref_Reference::referent_offset); 56 debug_only(unsigned int count = ((java_lang_ref_Reference::discovered_offset - 57 java_lang_ref_Reference::referent_offset)/heapOopSize) + 1); 58 59 if (UseSharedSpaces) { 60 assert(map->offset() == java_lang_ref_Reference::queue_offset && 61 map->count() == 1, "just checking"); 62 } else { 63 assert(map->offset() == offset && map->count() == count, 64 "just checking"); 65 66 // Update map to (3,1) - point to offset of 3 (words) with 1 map entry. 67 map->set_offset(java_lang_ref_Reference::queue_offset); 68 map->set_count(1); 69 } 70} 71 72 73// Verification 74 75void InstanceRefKlass::oop_verify_on(oop obj, outputStream* st) { 76 InstanceKlass::oop_verify_on(obj, st); 77 // Verify referent field 78 oop referent = java_lang_ref_Reference::referent(obj); 79 if (referent != NULL) { 80 guarantee(referent->is_oop(), "referent field heap failed"); 81 } 82 // Verify next field 83 oop next = java_lang_ref_Reference::next(obj); 84 if (next != NULL) { 85 guarantee(next->is_oop(), "next field verify failed"); 86 guarantee(next->is_instanceRef(), "next field verify failed"); 87 } 88} 89 90bool InstanceRefKlass::owns_pending_list_lock(JavaThread* thread) { 91 if (java_lang_ref_Reference::pending_list_lock() == NULL) return false; 92 Handle h_lock(thread, java_lang_ref_Reference::pending_list_lock()); 93 return ObjectSynchronizer::current_thread_holds_lock(thread, h_lock); 94} 95 96void InstanceRefKlass::acquire_pending_list_lock(BasicLock *pending_list_basic_lock) { 97 // we may enter this with pending exception set 98 PRESERVE_EXCEPTION_MARK; // exceptions are never thrown, needed for TRAPS argument 99 100 // Create a HandleMark in case we retry a GC multiple times. 101 // Each time we attempt the GC, we allocate the handle below 102 // to hold the pending list lock. We want to free this handle. 103 HandleMark hm; 104 105 Handle h_lock(THREAD, java_lang_ref_Reference::pending_list_lock()); 106 ObjectSynchronizer::fast_enter(h_lock, pending_list_basic_lock, false, THREAD); 107 assert(ObjectSynchronizer::current_thread_holds_lock( 108 JavaThread::current(), h_lock), 109 "Locking should have succeeded"); 110 if (HAS_PENDING_EXCEPTION) CLEAR_PENDING_EXCEPTION; 111} 112 113void InstanceRefKlass::release_and_notify_pending_list_lock( 114 BasicLock *pending_list_basic_lock) { 115 // we may enter this with pending exception set 116 PRESERVE_EXCEPTION_MARK; // exceptions are never thrown, needed for TRAPS argument 117 118 // Create a HandleMark in case we retry a GC multiple times. 119 // Each time we attempt the GC, we allocate the handle below 120 // to hold the pending list lock. We want to free this handle. 121 HandleMark hm; 122 123 Handle h_lock(THREAD, java_lang_ref_Reference::pending_list_lock()); 124 assert(ObjectSynchronizer::current_thread_holds_lock( 125 JavaThread::current(), h_lock), 126 "Lock should be held"); 127 // Notify waiters on pending lists lock if there is any reference. 128 if (java_lang_ref_Reference::pending_list() != NULL) { 129 ObjectSynchronizer::notifyall(h_lock, THREAD); 130 } 131 ObjectSynchronizer::fast_exit(h_lock(), pending_list_basic_lock, THREAD); 132 if (HAS_PENDING_EXCEPTION) CLEAR_PENDING_EXCEPTION; 133} 134