Path: blob/master/test/hotspot/jtreg/vmTestbase/vm/mlvm/share/jpda/StratumUtils.java
41161 views
/*1* Copyright (c) 2011, 2018, 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*/2223package vm.mlvm.share.jpda;2425import nsk.share.ArgumentParser;26import vm.mlvm.share.Env;2728import com.sun.jdi.AbsentInformationException;29import com.sun.jdi.Location;30import com.sun.jdi.ObjectReference;31import com.sun.jdi.ReferenceType;32import com.sun.jdi.StackFrame;3334public class StratumUtils {3536public static boolean checkStratum(Location location, StratumInfo si) throws AbsentInformationException {37// Check stratum information38try {39Env.traceVerbose(String.format("Stratum [%s]: required=[%s:%d]", si.stratum, si.stratumSourceName, si.stratumSourceLine));40Env.traceVerbose(String.format("Default stratum: location=[%s:%d]", location.sourceName(), location.lineNumber()));4142String stratumSourceName = location.sourceName(si.stratum);43int stratumSourceLine = location.lineNumber(si.stratum);44String stratumInfo = String.format("actual=[%s:%d]", stratumSourceName, stratumSourceLine);4546if (stratumSourceName.equals(si.stratumSourceName) && stratumSourceLine == si.stratumSourceLine) {47Env.traceVerbose("Stratum matches: " + stratumInfo);48return true;49} else {50Env.complain("Stratum mismatch: " + stratumInfo);51return false;52}53} catch (AbsentInformationException e) {54Env.complain(e, "Strata information is absent. Available strata: " + getStrataStr(location.declaringType()));5556return false;57}58}5960public static StratumInfo parseStratumInfo(String stratumInfo) throws Exception {61int sourceNamePos = stratumInfo.indexOf('=');62int sourceLinePos = stratumInfo.indexOf(':');6364if (sourceNamePos == -1 || sourceLinePos == -1 || sourceNamePos >= sourceLinePos) {65throw new ArgumentParser.BadOption("Wrong syntax of stratum information: [" + stratumInfo + "]");66}6768return new StratumInfo(69stratumInfo.substring(0, sourceNamePos),70stratumInfo.substring(sourceNamePos + 1, sourceLinePos),71Integer.parseInt(stratumInfo.substring(sourceLinePos + 1)));72}7374public static String getStrataStr(StackFrame sf) {75ObjectReference thisObject = sf.thisObject();76if (thisObject == null)77return "(no strata)";78return StratumUtils.getStrataStr(thisObject.referenceType());79}8081public static String getStrataStr(ReferenceType ref) {82return ref.availableStrata() + " (" + ref + ")";83}84}858687