2258N/A/*
2258N/A * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
2258N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2258N/A *
2258N/A * This code is free software; you can redistribute it and/or modify it
2258N/A * under the terms of the GNU General Public License version 2 only, as
2258N/A * published by the Free Software Foundation.
2258N/A *
2258N/A * This code is distributed in the hope that it will be useful, but WITHOUT
2258N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2258N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
2258N/A * version 2 for more details (a copy is included in the LICENSE file that
2258N/A * accompanied this code).
2258N/A *
2258N/A * You should have received a copy of the GNU General Public License version
2258N/A * 2 along with this work; if not, write to the Free Software Foundation,
2258N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2258N/A *
2258N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2258N/A * or visit www.oracle.com if you need additional information or have any
2258N/A * questions.
2258N/A *
2258N/A */
2258N/A
2258N/Apackage sun.jvm.hotspot.oops;
2258N/A
2258N/Aimport java.util.*;
2258N/A
2258N/Aimport sun.jvm.hotspot.debugger.*;
2258N/Aimport sun.jvm.hotspot.memory.*;
2258N/Aimport sun.jvm.hotspot.runtime.*;
2258N/Aimport sun.jvm.hotspot.types.Type;
2258N/Aimport sun.jvm.hotspot.types.TypeDataBase;
2258N/Aimport sun.jvm.hotspot.utilities.*;
2258N/Aimport sun.jvm.hotspot.jdi.JVMTIThreadState;
2258N/A
2258N/A/** A utility class encapsulating useful oop operations */
2258N/A
2258N/A// initialize fields for java.lang.Class
2258N/Apublic class java_lang_Class {
2258N/A
2258N/A // java.lang.Class fields
2258N/A static OopField klassField;
2258N/A static IntField oopSizeField;
2258N/A
2258N/A static {
2258N/A VM.registerVMInitializedObserver(new Observer() {
2258N/A public void update(Observable o, Object data) {
2258N/A initialize(VM.getVM().getTypeDataBase());
2258N/A }
2258N/A });
2258N/A }
2258N/A
2258N/A private static synchronized void initialize(TypeDataBase db) {
2258N/A // klass and oop_size are HotSpot magic fields and hence we can't
2258N/A // find them from InstanceKlass for java.lang.Class.
2258N/A Type jlc = db.lookupType("java_lang_Class");
2771N/A int klassOffset = (int) jlc.getCIntegerField("_klass_offset").getValue();
2258N/A if (VM.getVM().isCompressedOopsEnabled()) {
2258N/A klassField = new NarrowOopField(new NamedFieldIdentifier("klass"), klassOffset, true);
2258N/A } else {
2258N/A klassField = new OopField(new NamedFieldIdentifier("klass"), klassOffset, true);
2258N/A }
2771N/A int oopSizeOffset = (int) jlc.getCIntegerField("_oop_size_offset").getValue();
2258N/A oopSizeField = new IntField(new NamedFieldIdentifier("oop_size"), oopSizeOffset, true);
2258N/A }
2258N/A
2258N/A /** get klassOop field at offset hc_klass_offset from a java.lang.Class object */
2258N/A public static Klass asKlass(Oop aClass) {
2258N/A return (Klass) java_lang_Class.klassField.getValue(aClass);
2258N/A }
2258N/A
2258N/A /** get oop_size field at offset oop_size_offset from a java.lang.Class object */
2258N/A public static long getOopSize(Oop aClass) {
2258N/A return java_lang_Class.oopSizeField.getValue(aClass);
2258N/A }
2258N/A}