Path: blob/master/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/oops/CompressedOops.java
41161 views
/*1* Copyright (c) 2000, 2020, 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.oops;2526import sun.jvm.hotspot.utilities.Observable;27import sun.jvm.hotspot.utilities.Observer;2829import sun.jvm.hotspot.debugger.Address;30import sun.jvm.hotspot.runtime.VM;31import sun.jvm.hotspot.types.AddressField;32import sun.jvm.hotspot.types.CIntegerField;33import sun.jvm.hotspot.types.Type;34import sun.jvm.hotspot.types.TypeDataBase;3536public class CompressedOops {37private static AddressField baseField;38private static CIntegerField shiftField;3940public enum Mode {41UnscaledNarrowOop,42ZeroBasedNarrowOop,43HeapBasedNarrowOop44}4546static {47VM.registerVMInitializedObserver(new Observer() {48public void update(Observable o, Object data) {49initialize(VM.getVM().getTypeDataBase());50}51});52}5354private static boolean typeExists(TypeDataBase db, String type) {55try {56db.lookupType(type);57} catch (RuntimeException e) {58return false;59}60return true;61}6263private static synchronized void initialize(TypeDataBase db) {64Type type = db.lookupType("CompressedOops");6566baseField = type.getAddressField("_narrow_oop._base");67shiftField = type.getCIntegerField("_narrow_oop._shift");68}6970public CompressedOops() {71}72public static String modeToString(Mode mode) {73switch (mode) {74case UnscaledNarrowOop:75return "32-bits Oops";76case ZeroBasedNarrowOop:77return "zero based Compressed Oops";78case HeapBasedNarrowOop:79return "Compressed Oops with base";80}81return "";82}8384public static long getBase() {85if (baseField.getValue() == null) {86return 0;87} else {88return baseField.getValue().minus(null);89}90}9192public static int getShift() {93return (int)shiftField.getValue();94}95}969798