Path: blob/master/src/hotspot/share/oops/instanceRefKlass.cpp
40951 views
/*1* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#include "precompiled.hpp"25#include "classfile/javaClasses.hpp"26#include "classfile/vmClasses.hpp"27#include "oops/instanceRefKlass.inline.hpp"28#include "oops/oop.inline.hpp"2930void InstanceRefKlass::update_nonstatic_oop_maps(Klass* k) {31// Clear the nonstatic oop-map entries corresponding to referent32// and discovered fields. They are treated specially by the33// garbage collector.34InstanceKlass* ik = InstanceKlass::cast(k);3536// Check that we have the right class37debug_only(static bool first_time = true);38assert(k == vmClasses::Reference_klass() && first_time,39"Invalid update of maps");40debug_only(first_time = false);41assert(ik->nonstatic_oop_map_count() == 1, "just checking");4243OopMapBlock* map = ik->start_of_nonstatic_oop_maps();4445#ifdef ASSERT46// Verify fields are in the expected places.47int referent_offset = java_lang_ref_Reference::referent_offset();48int queue_offset = java_lang_ref_Reference::queue_offset();49int next_offset = java_lang_ref_Reference::next_offset();50int discovered_offset = java_lang_ref_Reference::discovered_offset();51assert(referent_offset < queue_offset, "just checking");52assert(queue_offset < next_offset, "just checking");53assert(next_offset < discovered_offset, "just checking");54const unsigned int count =551 + ((discovered_offset - referent_offset) / heapOopSize);56assert(count == 4, "just checking");57#endif // ASSERT5859// Updated map starts at "queue", covers "queue" and "next".60const int new_offset = java_lang_ref_Reference::queue_offset();61const unsigned int new_count = 2; // queue and next6263// Verify existing map is as expected, and update if needed.64if (UseSharedSpaces) {65assert(map->offset() == new_offset, "just checking");66assert(map->count() == new_count, "just checking");67} else {68assert(map->offset() == referent_offset, "just checking");69assert(map->count() == count, "just checking");70map->set_offset(new_offset);71map->set_count(new_count);72}73}747576// Verification7778void InstanceRefKlass::oop_verify_on(oop obj, outputStream* st) {79InstanceKlass::oop_verify_on(obj, st);80// Verify referent field81oop referent = java_lang_ref_Reference::unknown_referent_no_keepalive(obj);82if (referent != NULL) {83guarantee(oopDesc::is_oop(referent), "referent field heap failed");84}85// Additional verification for next field, which must be a Reference or null86oop next = java_lang_ref_Reference::next(obj);87if (next != NULL) {88guarantee(oopDesc::is_oop(next), "next field should be an oop");89guarantee(next->is_instance(), "next field should be an instance");90guarantee(InstanceKlass::cast(next->klass())->is_reference_instance_klass(), "next field verify failed");91}92}939495