Path: blob/master/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/oops/Array.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 java.util.*;27import sun.jvm.hotspot.debugger.*;28import sun.jvm.hotspot.memory.*;29import sun.jvm.hotspot.runtime.*;30import sun.jvm.hotspot.types.*;31import sun.jvm.hotspot.utilities.Observable;32import sun.jvm.hotspot.utilities.Observer;3334// Array is an abstract superclass for TypeArray and ObjArray3536public class Array extends Oop {37static {38VM.registerVMInitializedObserver(new Observer() {39public void update(Observable o, Object data) {40initialize(VM.getVM().getTypeDataBase());41}42});43}4445Array(OopHandle handle, ObjectHeap heap) {46super(handle, heap);47}4849private static void initialize(TypeDataBase db) throws WrongTypeException {50Type type = db.lookupType("arrayOopDesc");51typeSize = (int)type.getSize();52}5354// Size of the arrayOopDesc55private static long headerSize=0;56private static long lengthOffsetInBytes=0;57private static long typeSize;5859private static long headerSizeInBytes() {60if (headerSize != 0) {61return headerSize;62}63if (VM.getVM().isCompressedKlassPointersEnabled()) {64headerSize = typeSize;65} else {66headerSize = VM.getVM().alignUp(typeSize + VM.getVM().getIntSize(),67VM.getVM().getHeapWordSize());68}69return headerSize;70}7172private static long headerSize(BasicType type) {73if (Universe.elementTypeShouldBeAligned(type)) {74return alignObjectSize(headerSizeInBytes())/VM.getVM().getHeapWordSize();75} else {76return headerSizeInBytes()/VM.getVM().getHeapWordSize();77}78}7980private long lengthOffsetInBytes() {81if (lengthOffsetInBytes != 0) {82return lengthOffsetInBytes;83}84if (VM.getVM().isCompressedKlassPointersEnabled()) {85lengthOffsetInBytes = typeSize - VM.getVM().getIntSize();86} else {87lengthOffsetInBytes = typeSize;88}89return lengthOffsetInBytes;90}9192// Accessors for declared fields93public long getLength() {94boolean isUnsigned = true;95return this.getHandle().getCIntegerAt(lengthOffsetInBytes(), VM.getVM().getIntSize(), isUnsigned);96}9798public long getObjectSize() {99ArrayKlass klass = (ArrayKlass) getKlass();100// We have to fetch the length of the array, shift (multiply) it101// appropriately, up to wordSize, add the header, and align to102// object size.103long s = getLength() << klass.getLog2ElementSize();104s += klass.getArrayHeaderInBytes();105s = Oop.alignObjectSize(s);106return s;107}108109public static long baseOffsetInBytes(BasicType type) {110return headerSize(type) * VM.getVM().getHeapWordSize();111}112113public boolean isArray() { return true; }114115public void iterateFields(OopVisitor visitor, boolean doVMFields) {116super.iterateFields(visitor, doVMFields);117}118}119120121