annotate src/share/vm/oops/instanceRefKlass.cpp @ 9266:4535697211eb

8139203: Consistent naming for klass type predicates 8138923: Remove oop coupling with InstanceKlass subclasses Summary: Renamed oop_is_instance and friends, removed the functions in oop that dug down into InstanceKlass. Reviewed-by: jrose, lfoltan, stefank
author coleenp
date Wed, 28 Oct 2015 09:47:23 -0400
parents 115188e14c15
children 767bc8e5cb19
rev   line source
duke@0 1 /*
stefank@8046 2 * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
duke@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@0 4 *
duke@0 5 * This code is free software; you can redistribute it and/or modify it
duke@0 6 * under the terms of the GNU General Public License version 2 only, as
duke@0 7 * published by the Free Software Foundation.
duke@0 8 *
duke@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@0 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@0 13 * accompanied this code).
duke@0 14 *
duke@0 15 * You should have received a copy of the GNU General Public License version
duke@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@0 18 *
trims@1472 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1472 20 * or visit www.oracle.com if you need additional information or have any
trims@1472 21 * questions.
duke@0 22 *
duke@0 23 */
duke@0 24
stefank@1879 25 #include "precompiled.hpp"
stefank@1879 26 #include "classfile/javaClasses.hpp"
stefank@1879 27 #include "classfile/systemDictionary.hpp"
pliden@8413 28 #include "gc/shared/collectedHeap.inline.hpp"
pliden@8413 29 #include "gc/shared/genCollectedHeap.hpp"
pliden@8413 30 #include "gc/shared/specialized_oop_closures.hpp"
stefank@8135 31 #include "oops/instanceRefKlass.inline.hpp"
stefank@1879 32 #include "oops/oop.inline.hpp"
pliden@8413 33 #include "utilities/macros.hpp"
stefank@1879 34 #include "utilities/preserveException.hpp"
duke@0 35
coleenp@3612 36 void InstanceRefKlass::update_nonstatic_oop_maps(Klass* k) {
duke@0 37 // Clear the nonstatic oop-map entries corresponding to referent
duke@0 38 // and nextPending field. They are treated specially by the
duke@0 39 // garbage collector.
duke@0 40 // The discovered field is used only by the garbage collector
duke@0 41 // and is also treated specially.
coleenp@3602 42 InstanceKlass* ik = InstanceKlass::cast(k);
duke@0 43
duke@0 44 // Check that we have the right class
duke@0 45 debug_only(static bool first_time = true);
never@1142 46 assert(k == SystemDictionary::Reference_klass() && first_time,
duke@0 47 "Invalid update of maps");
duke@0 48 debug_only(first_time = false);
jcoomes@938 49 assert(ik->nonstatic_oop_map_count() == 1, "just checking");
duke@0 50
duke@0 51 OopMapBlock* map = ik->start_of_nonstatic_oop_maps();
duke@0 52
duke@0 53 // Check that the current map is (2,4) - currently points at field with
duke@0 54 // offset 2 (words) and has 4 map entries.
duke@0 55 debug_only(int offset = java_lang_ref_Reference::referent_offset);
jcoomes@939 56 debug_only(unsigned int count = ((java_lang_ref_Reference::discovered_offset -
coleenp@113 57 java_lang_ref_Reference::referent_offset)/heapOopSize) + 1);
duke@0 58
duke@0 59 if (UseSharedSpaces) {
duke@0 60 assert(map->offset() == java_lang_ref_Reference::queue_offset &&
jcoomes@938 61 map->count() == 1, "just checking");
duke@0 62 } else {
jcoomes@938 63 assert(map->offset() == offset && map->count() == count,
duke@0 64 "just checking");
duke@0 65
duke@0 66 // Update map to (3,1) - point to offset of 3 (words) with 1 map entry.
duke@0 67 map->set_offset(java_lang_ref_Reference::queue_offset);
jcoomes@938 68 map->set_count(1);
duke@0 69 }
duke@0 70 }
duke@0 71
duke@0 72
duke@0 73 // Verification
duke@0 74
coleenp@3612 75 void InstanceRefKlass::oop_verify_on(oop obj, outputStream* st) {
coleenp@3602 76 InstanceKlass::oop_verify_on(obj, st);
duke@0 77 // Verify referent field
duke@0 78 oop referent = java_lang_ref_Reference::referent(obj);
duke@0 79 if (referent != NULL) {
duke@0 80 guarantee(referent->is_oop(), "referent field heap failed");
duke@0 81 }
duke@0 82 // Verify next field
duke@0 83 oop next = java_lang_ref_Reference::next(obj);
duke@0 84 if (next != NULL) {
coleenp@9266 85 guarantee(next->is_oop(), "next field should be an oop");
coleenp@9266 86 guarantee(next->is_instance(), "next field should be an instance");
coleenp@9266 87 guarantee(InstanceKlass::cast(next->klass())->is_reference_instance_klass(), "next field verify failed");
duke@0 88 }
duke@0 89 }
duke@0 90
coleenp@3612 91 bool InstanceRefKlass::owns_pending_list_lock(JavaThread* thread) {
coleenp@1932 92 if (java_lang_ref_Reference::pending_list_lock() == NULL) return false;
coleenp@1928 93 Handle h_lock(thread, java_lang_ref_Reference::pending_list_lock());
coleenp@1928 94 return ObjectSynchronizer::current_thread_holds_lock(thread, h_lock);
coleenp@1928 95 }
coleenp@1928 96
coleenp@3612 97 void InstanceRefKlass::acquire_pending_list_lock(BasicLock *pending_list_basic_lock) {
duke@0 98 // we may enter this with pending exception set
duke@0 99 PRESERVE_EXCEPTION_MARK; // exceptions are never thrown, needed for TRAPS argument
johnc@3376 100
johnc@3376 101 // Create a HandleMark in case we retry a GC multiple times.
johnc@3376 102 // Each time we attempt the GC, we allocate the handle below
johnc@3376 103 // to hold the pending list lock. We want to free this handle.
johnc@3376 104 HandleMark hm;
johnc@3376 105
duke@0 106 Handle h_lock(THREAD, java_lang_ref_Reference::pending_list_lock());
duke@0 107 ObjectSynchronizer::fast_enter(h_lock, pending_list_basic_lock, false, THREAD);
duke@0 108 assert(ObjectSynchronizer::current_thread_holds_lock(
duke@0 109 JavaThread::current(), h_lock),
duke@0 110 "Locking should have succeeded");
duke@0 111 if (HAS_PENDING_EXCEPTION) CLEAR_PENDING_EXCEPTION;
duke@0 112 }
duke@0 113
coleenp@3612 114 void InstanceRefKlass::release_and_notify_pending_list_lock(
duke@0 115 BasicLock *pending_list_basic_lock) {
duke@0 116 // we may enter this with pending exception set
duke@0 117 PRESERVE_EXCEPTION_MARK; // exceptions are never thrown, needed for TRAPS argument
johnc@3376 118
johnc@3376 119 // Create a HandleMark in case we retry a GC multiple times.
johnc@3376 120 // Each time we attempt the GC, we allocate the handle below
johnc@3376 121 // to hold the pending list lock. We want to free this handle.
johnc@3376 122 HandleMark hm;
johnc@3376 123
duke@0 124 Handle h_lock(THREAD, java_lang_ref_Reference::pending_list_lock());
duke@0 125 assert(ObjectSynchronizer::current_thread_holds_lock(
duke@0 126 JavaThread::current(), h_lock),
duke@0 127 "Lock should be held");
duke@0 128 // Notify waiters on pending lists lock if there is any reference.
duke@0 129 if (java_lang_ref_Reference::pending_list() != NULL) {
duke@0 130 ObjectSynchronizer::notifyall(h_lock, THREAD);
duke@0 131 }
duke@0 132 ObjectSynchronizer::fast_exit(h_lock(), pending_list_basic_lock, THREAD);
duke@0 133 if (HAS_PENDING_EXCEPTION) CLEAR_PENDING_EXCEPTION;
duke@0 134 }