Path: blob/master/test/hotspot/jtreg/serviceability/sa/ClhsdbLongConstant.java
41152 views
/*1* Copyright (c) 2017, 2019, 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*/2223/**24* @test25* @bug 819019826* @summary Test clhsdb longConstant command27* @requires vm.hasSA28* @library /test/lib29* @run main/othervm ClhsdbLongConstant30*/3132import java.util.HashMap;33import java.util.List;34import java.util.Map;3536import jdk.test.lib.apps.LingeredApp;37import jdk.test.lib.Platform;38import jtreg.SkippedException;3940public class ClhsdbLongConstant {4142public static void main(String[] args) throws Exception {43System.out.println("Starting ClhsdbLongConstant test");4445LingeredApp theApp = null;46try {47ClhsdbLauncher test = new ClhsdbLauncher();48theApp = LingeredApp.startApp();49System.out.println("Started LingeredApp with pid " + theApp.getPid());5051List<String> cmds = List.of(52"longConstant",53"longConstant markWord::locked_value",54"longConstant markWord::lock_bits",55"longConstant jtreg::test 6",56"longConstant jtreg::test");5758Map<String, List<String>> expStrMap = new HashMap<>();59expStrMap.put("longConstant", List.of(60"longConstant markWord::locked_value",61"longConstant markWord::lock_bits",62"InvocationCounter::count_increment",63"markWord::epoch_mask_in_place"));64expStrMap.put("longConstant markWord::locked_value", List.of(65"longConstant markWord::locked_value"));66expStrMap.put("longConstant markWord::lock_bits", List.of(67"longConstant markWord::lock_bits"));68expStrMap.put("longConstant jtreg::test", List.of(69"longConstant jtreg::test 6"));7071Map<String, List<String>> unExpStrMap = new HashMap<>();72unExpStrMap.put("longConstant jtreg::test", List.of(73"Error: java.lang.RuntimeException: No long constant named"));7475String longConstantOutput = test.run(theApp.getPid(), cmds, expStrMap, unExpStrMap);7677checkForTruncation(longConstantOutput);78} catch (SkippedException e) {79throw e;80} catch (Exception ex) {81throw new RuntimeException("Test ERROR " + ex, ex);82} finally {83LingeredApp.stopApp(theApp);84}85System.out.println("Test PASSED");86}8788private static void checkForTruncation(String longConstantOutput) throws Exception {8990// Expected values obtained from the hash_mask_in_place definition in markWord.hpp9192// Expected output snippet is of the form (on x64-64):93// ...94// longConstant VM_Version::CPU_SHA 1717986918495// longConstant markWord::biased_lock_bits 196// longConstant markWord::age_shift 397// longConstant markWord::hash_mask_in_place 54975581363298// ...99100checkLongValue("markWord::hash_mask_in_place",101longConstantOutput,102Platform.is64bit() ? 549755813632L: 4294967168L);103104String arch = System.getProperty("os.arch");105if (arch.equals("amd64") || arch.equals("i386") || arch.equals("x86")) {106// Expected value obtained from the CPU_SHA definition in vm_version_x86.hpp107checkLongValue("VM_Version::CPU_SHA",108longConstantOutput,10917179869184L);110}111}112113private static void checkLongValue(String constName, String longConstantOutput,114long checkValue) throws Exception {115116String[] snippets = longConstantOutput.split(constName);117String[] words = snippets[1].split("\\R");118long readValue = Long.parseLong(words[0].trim());119if (readValue != checkValue) {120throw new Exception ("Reading " + constName + ". Expected " + checkValue +121". Obtained " + readValue + " instead.");122}123}124}125126127