Path: blob/master/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/runtime/ObjectSynchronizer.java
41161 views
/*1* Copyright (c) 2001, 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*/2324package sun.jvm.hotspot.runtime;2526import java.util.*;2728import sun.jvm.hotspot.oops.*;29import sun.jvm.hotspot.utilities.*;30import sun.jvm.hotspot.debugger.*;31import sun.jvm.hotspot.types.*;32import sun.jvm.hotspot.utilities.Observable;33import sun.jvm.hotspot.utilities.Observer;3435public class ObjectSynchronizer {36static {37VM.registerVMInitializedObserver(new Observer() {38public void update(Observable o, Object data) {39initialize(VM.getVM().getTypeDataBase());40}41});42}4344private static synchronized void initialize(TypeDataBase db) throws WrongTypeException {45Type type = db.lookupType("ObjectSynchronizer");46inUseList = type.getAddressField("_in_use_list").getValue();47}4849public long identityHashValueFor(Oop obj) {50Mark mark = obj.getMark();51if (mark.isUnlocked()) {52// FIXME: can not generate marks in debugging system53return mark.hash();54} else if (mark.hasMonitor()) {55ObjectMonitor monitor = mark.monitor();56Mark temp = monitor.header();57return temp.hash();58} else {59if (Assert.ASSERTS_ENABLED) {60Assert.that(VM.getVM().isDebugging(), "Can not access displaced header otherwise");61}62if (mark.hasDisplacedMarkHelper()) {63Mark temp = mark.displacedMarkHelper();64return temp.hash();65}66// FIXME: can not do anything else here in debugging system67return 0;68}69}7071public static Iterator objectMonitorIterator() {72if (inUseList != null) {73return new ObjectMonitorIterator();74} else {75return null;76}77}7879private static class ObjectMonitorIterator implements Iterator {8081// JVMTI raw monitors are not included in _in_use_list and82// are not returned by this Iterator.8384ObjectMonitorIterator() {85mon = new ObjectMonitor(inUseList);86}8788public boolean hasNext() {89return (mon.nextOM() != null);90}9192public Object next() {93// advance to next entry94Address monAddr = mon.nextOM();95if (monAddr == null) {96throw new NoSuchElementException();97}98mon = new ObjectMonitor(monAddr);99return mon;100}101102public void remove() {103throw new UnsupportedOperationException();104}105106private ObjectMonitor mon;107}108109private static Address inUseList;110111}112113114