Path: blob/master/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/oops/DataLayout.java
41161 views
/*1* Copyright (c) 2011, 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.oops;2526import java.io.*;27import java.util.*;28import sun.jvm.hotspot.debugger.*;29import sun.jvm.hotspot.runtime.*;30import sun.jvm.hotspot.types.*;31import sun.jvm.hotspot.utilities.*;3233public class DataLayout {34public static final int noTag = 0;35public static final int bitDataTag = 1;36public static final int counterDataTag = 2;37public static final int jumpDataTag= 3;38public static final int receiverTypeDataTag = 4;39public static final int virtualCallDataTag = 5;40public static final int retDataTag = 6;41public static final int branchDataTag = 7;42public static final int multiBranchDataTag = 8;43public static final int argInfoDataTag = 9;44public static final int callTypeDataTag = 10;45public static final int virtualCallTypeDataTag = 11;46public static final int parametersTypeDataTag = 12;47public static final int speculativeTrapDataTag = 13;4849// The trap state breaks down as [recompile:1 | reason:31].50// This further breakdown is defined in deoptimization.cpp.51// See Deoptimization.trapStateReason for an assert that52// trapBits is big enough to hold reasons < reasonRecordedLimit.53//54// The trapState is collected only if ProfileTraps is true.55public static final int trapBits = 1+31; // 31: enough to distinguish [0..reasonRecordedLimit].56public static final int trapMask = Bits.rightNBits(trapBits);57public static final int firstFlag = 0;5859private Address data;6061private int offset;6263public DataLayout(MethodData d, int o) {64data = d.getAddress();65offset = o;66}6768public DataLayout(Address d, int o) {69data = d;70offset = o;71}7273public int dp() { return offset; }7475private int getU11(int at) {76return data.getJByteAt(offset + at) & 0xff;77}7879private int getU22(int at) {80return data.getJShortAt(offset + at) & 0xffff;81}8283long cellAt(int index) {84return data.getCIntegerAt(offset + cellOffset(index), MethodData.cellSize, false);85}8687public Address addressAt(int index) {88return data.getAddressAt(offset + cellOffset(index));89}9091// Every data layout begins with a header. This header92// contains a tag, which is used to indicate the size/layout93// of the data, 8 bits of flags, which can be used in any way,94// 32 bits of trap history (none/one reason/many reasons),95// and a bci, which is used to tie this piece of data to a96// specific bci in the bytecodes.97// union {98// u8 _bits;99// struct {100// u1 _tag;101// u1 _flags;102// u2 _bci;103// u4 _traps;104// } _struct;105// } _header;106107// Some types of data layouts need a length field.108static boolean needsArrayLen(int tag) {109return (tag == multiBranchDataTag);110}111112public static final int counterIncrement = 1;113114// Size computation115static int headerSizeInBytes() {116return MethodData.cellSize * headerSizeInCells();117}118static int headerSizeInCells() {119return VM.getVM().isLP64() ? 1 : 2;120}121122static public int computeSizeInBytes(int cellCount) {123return headerSizeInBytes() + cellCount * MethodData.cellSize;124}125126// Initialization127// void initialize(int tag, int bci, int cellCount);128129// Accessors130public int tag() {131return getU11(0);132}133134// Return a few bits of trap state. Range is [0..trapMask].135// The state tells if traps with zero, one, or many reasons have occurred.136// It also tells whether zero or many recompilations have occurred.137// The associated trap histogram in the MDO itself tells whether138// traps are common or not. If a BCI shows that a trap X has139// occurred, and the MDO shows N occurrences of X, we make the140// simplifying assumption that all N occurrences can be blamed141// on that BCI.142int trapState() {143return data.getJIntAt(offset+4);144}145146int flags() {147return getU11(1);148}149150int bci() {151return getU22(2);152}153154boolean flagAt(int flagNumber) {155// assert(flagNumber < flagLimit, "oob");156return (flags() & (0x1 << flagNumber)) != 0;157}158159// Low-level support for code generation.160static int headerOffset() {161return 0;162}163static int tagOffset() {164return 0;165}166static int flagsOffset() {167return 1;168}169static int bciOffset() {170return 2;171}172public static int cellOffset(int index) {173return (headerSizeInCells() + index) * MethodData.cellSize;174}175// // Return a value which, when or-ed as a byte into _flags, sets the flag.176// static int flagNumberToByteConstant(int flagNumber) {177// assert(0 <= flagNumber && flagNumber < flagLimit, "oob");178// DataLayout temp; temp.setHeader(0);179// temp.setFlagAt(flagNumber);180// return temp._header._struct._flags;181// }182// // Return a value which, when or-ed as a word into _header, sets the flag.183// static intptrT flagMaskToHeaderMask(int byteConstant) {184// DataLayout temp; temp.setHeader(0);185// temp._header._struct._flags = byteConstant;186// return temp._header._bits;187// }188}189190191