Path: blob/master/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/interpreter/OopMapCacheEntry.java
41161 views
/*1* Copyright (c) 2001, 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.interpreter;2526import sun.jvm.hotspot.oops.*;27import sun.jvm.hotspot.utilities.*;2829public class OopMapCacheEntry {30// Iteration31public boolean isValue(int offset) { return !entryAt(offset); }32public boolean isOop (int offset) { return entryAt(offset); }33public void iterateOop(OffsetClosure oopClosure) {34int n = numberOfEntries();35for (int i = 0; i < n; i++) {36if (entryAt(i)) {37oopClosure.offsetDo(i);38}39}40}4142// Initialization43public void fill(Method method, int bci) {44this.method = method;45this.bci = bci;46if (method.isNative()) {47// Native method activations have oops only among the parameters and one48// extra oop following the parameters (the mirror for static native methods).49fillForNative();50} else {51OopMapForCacheEntry gen = new OopMapForCacheEntry(method, bci, this);52gen.computeMap();53}54}5556public void setMask(CellTypeStateList vars,57CellTypeStateList stack,58int stackTop) {59// compute bit mask size60int maxLocals = (int) method.getMaxLocals();61int nEntries = maxLocals + stackTop;62maskSize = nEntries;63allocateBitMask();6465CellTypeStateList curList = vars;66int listIdx = 0;6768for (int entryIdx = 0; entryIdx < nEntries; entryIdx++, listIdx++) {69// switch to stack when done with locals70if (entryIdx == maxLocals) {71curList = stack;72listIdx = 0;73}7475CellTypeState cell = curList.get(listIdx);76// set oop bit77if ( cell.isReference()) {78mask.atPut(entryIdx, true);79}80}8182// verify bit mask83if (Assert.ASSERTS_ENABLED) {84Assert.that(verifyMask(vars, stack, maxLocals, stackTop), "mask could not be verified");85}86}8788//----------------------------------------------------------------------89// Internals only below this point90//91private Method method; // the method for which the mask is valid92private int bci; // the bci for which the mask is valid93private int maskSize; // the required mask size in bits94private BitMap mask; // may be null if mask is empty9596Method method() { return method; }97int bci() { return bci; }98int numberOfEntries() { return maskSize; }99boolean entryAt(int offset) {100return mask.at(offset);101}102103void setEmptyMask() { mask = null; }104void allocateBitMask() {105if (maskSize > 0) {106mask = new BitMap(maskSize);107}108}109110// fills the bit mask for native calls111void fillForNative() {112if (Assert.ASSERTS_ENABLED) {113Assert.that(method.isNative(), "method must be native method");114}115maskSize = (int) method.getSizeOfParameters();116allocateBitMask();117// fill mask for parameters118MaskFillerForNative mf = new MaskFillerForNative(method, mask, maskSize);119mf.generate();120}121122static class VerifyClosure implements OffsetClosure {123private OopMapCacheEntry entry;124private boolean failed;125126VerifyClosure(OopMapCacheEntry entry) { this.entry = entry; }127public void offsetDo(int offset) { if (!entry.isOop(offset)) failed = true; }128boolean failed() { return failed; }129}130131boolean verifyMask(CellTypeStateList vars, CellTypeStateList stack, int maxLocals, int stackTop) {132// Check mask includes map133VerifyClosure blk = new VerifyClosure(this);134iterateOop(blk);135if (blk.failed()) return false;136137// Check if map is generated correctly138for(int i = 0; i < maxLocals; i++) {139boolean v1 = isOop(i);140boolean v2 = vars.get(i).isReference();141if (Assert.ASSERTS_ENABLED) {142Assert.that(v1 == v2, "locals oop mask generation error");143}144}145146for(int j = 0; j < stackTop; j++) {147boolean v1 = isOop(maxLocals + j);148boolean v2 = stack.get(j).isReference();149if (Assert.ASSERTS_ENABLED) {150Assert.that(v1 == v2, "stack oop mask generation error");151}152}153return true;154}155}156157158