--- old/src/hotspot/share/runtime/vmStructs.cpp 2017-11-28 16:44:40.975794293 +0900 +++ new/src/hotspot/share/runtime/vmStructs.cpp 2017-11-28 16:44:40.843791857 +0900 @@ -2636,6 +2636,46 @@ declare_constant(Deoptimization::_reason_shift) \ declare_constant(Deoptimization::_debug_id_shift) \ \ + /******************************************/ \ + /* BasicType enum (globalDefinitions.hpp) */ \ + /******************************************/ \ + \ + declare_constant(T_BOOLEAN) \ + declare_constant(T_CHAR) \ + declare_constant(T_FLOAT) \ + declare_constant(T_DOUBLE) \ + declare_constant(T_BYTE) \ + declare_constant(T_SHORT) \ + declare_constant(T_INT) \ + declare_constant(T_LONG) \ + declare_constant(T_OBJECT) \ + declare_constant(T_ARRAY) \ + declare_constant(T_VOID) \ + declare_constant(T_ADDRESS) \ + declare_constant(T_NARROWOOP) \ + declare_constant(T_METADATA) \ + declare_constant(T_NARROWKLASS) \ + declare_constant(T_CONFLICT) \ + declare_constant(T_ILLEGAL) \ + \ + /**********************************************/ \ + /* BasicTypeSize enum (globalDefinitions.hpp) */ \ + /**********************************************/ \ + \ + declare_constant(T_BOOLEAN_size) \ + declare_constant(T_CHAR_size) \ + declare_constant(T_FLOAT_size) \ + declare_constant(T_DOUBLE_size) \ + declare_constant(T_BYTE_size) \ + declare_constant(T_SHORT_size) \ + declare_constant(T_INT_size) \ + declare_constant(T_LONG_size) \ + declare_constant(T_OBJECT_size) \ + declare_constant(T_ARRAY_size) \ + declare_constant(T_NARROWOOP_size) \ + declare_constant(T_NARROWKLASS_size) \ + declare_constant(T_VOID_size) \ + \ /*********************/ \ /* Matcher (C2 only) */ \ /*********************/ \ --- old/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/runtime/BasicType.java 2017-11-28 16:44:41.303800347 +0900 +++ new/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/runtime/BasicType.java 2017-11-28 16:44:41.172797929 +0900 @@ -24,45 +24,92 @@ package sun.jvm.hotspot.runtime; +import java.util.Observer; +import sun.jvm.hotspot.types.TypeDataBase; + + /** Encapsulates the BasicType enum in globalDefinitions.hpp in the VM. */ public class BasicType { - public static final int tBoolean = 4; - public static final int tChar = 5; - public static final int tFloat = 6; - public static final int tDouble = 7; - public static final int tByte = 8; - public static final int tShort = 9; - public static final int tInt = 10; - public static final int tLong = 11; - public static final int tObject = 12; - public static final int tArray = 13; - public static final int tVoid = 14; - public static final int tAddress = 15; - public static final int tNarrowOop = 16; - public static final int tMetadata = 17; - public static final int tNarrowKlass = 18; - public static final int tConflict = 19; - public static final int tIllegal = 99; - - public static final BasicType T_BOOLEAN = new BasicType(tBoolean); - public static final BasicType T_CHAR = new BasicType(tChar); - public static final BasicType T_FLOAT = new BasicType(tFloat); - public static final BasicType T_DOUBLE = new BasicType(tDouble); - public static final BasicType T_BYTE = new BasicType(tByte); - public static final BasicType T_SHORT = new BasicType(tShort); - public static final BasicType T_INT = new BasicType(tInt); - public static final BasicType T_LONG = new BasicType(tLong); - public static final BasicType T_OBJECT = new BasicType(tObject); - public static final BasicType T_ARRAY = new BasicType(tArray); - public static final BasicType T_VOID = new BasicType(tVoid); - public static final BasicType T_ADDRESS = new BasicType(tAddress); - public static final BasicType T_NARROWOOP = new BasicType(tNarrowOop); - public static final BasicType T_METADATA = new BasicType(tMetadata); - public static final BasicType T_NARROWKLASS = new BasicType(tNarrowKlass); - public static final BasicType T_CONFLICT = new BasicType(tConflict); - public static final BasicType T_ILLEGAL = new BasicType(tIllegal); + private static int tBoolean; + private static int tChar; + private static int tFloat; + private static int tDouble; + private static int tByte; + private static int tShort; + private static int tInt; + private static int tLong; + private static int tObject; + private static int tArray; + private static int tVoid; + private static int tAddress; + private static int tNarrowOop; + private static int tMetadata; + private static int tNarrowKlass; + private static int tConflict; + private static int tIllegal; + + public static BasicType T_BOOLEAN; + public static BasicType T_CHAR; + public static BasicType T_FLOAT; + public static BasicType T_DOUBLE; + public static BasicType T_BYTE; + public static BasicType T_SHORT; + public static BasicType T_INT; + public static BasicType T_LONG; + public static BasicType T_OBJECT; + public static BasicType T_ARRAY; + public static BasicType T_VOID; + public static BasicType T_ADDRESS; + public static BasicType T_NARROWOOP; + public static BasicType T_METADATA; + public static BasicType T_NARROWKLASS; + public static BasicType T_CONFLICT; + public static BasicType T_ILLEGAL; + + static { + VM.registerVMInitializedObserver( + (o, d) -> initialize(VM.getVM().getTypeDataBase())); + } + + private static synchronized void initialize(TypeDataBase db) { + tBoolean = db.lookupIntConstant("T_BOOLEAN").intValue(); + tChar = db.lookupIntConstant("T_CHAR").intValue(); + tFloat = db.lookupIntConstant("T_FLOAT").intValue(); + tDouble = db.lookupIntConstant("T_DOUBLE").intValue(); + tByte = db.lookupIntConstant("T_BYTE").intValue(); + tShort = db.lookupIntConstant("T_SHORT").intValue(); + tInt = db.lookupIntConstant("T_INT").intValue(); + tLong = db.lookupIntConstant("T_LONG").intValue(); + tObject = db.lookupIntConstant("T_OBJECT").intValue(); + tArray = db.lookupIntConstant("T_ARRAY").intValue(); + tVoid = db.lookupIntConstant("T_VOID").intValue(); + tAddress = db.lookupIntConstant("T_ADDRESS").intValue(); + tNarrowOop = db.lookupIntConstant("T_NARROWOOP").intValue(); + tMetadata = db.lookupIntConstant("T_METADATA").intValue(); + tNarrowKlass = db.lookupIntConstant("T_NARROWKLASS").intValue(); + tConflict = db.lookupIntConstant("T_CONFLICT").intValue(); + tIllegal = db.lookupIntConstant("T_ILLEGAL").intValue(); + + T_BOOLEAN = new BasicType(tBoolean); + T_CHAR = new BasicType(tChar); + T_FLOAT = new BasicType(tFloat); + T_DOUBLE = new BasicType(tDouble); + T_BYTE = new BasicType(tByte); + T_SHORT = new BasicType(tShort); + T_INT = new BasicType(tInt); + T_LONG = new BasicType(tLong); + T_OBJECT = new BasicType(tObject); + T_ARRAY = new BasicType(tArray); + T_VOID = new BasicType(tVoid); + T_ADDRESS = new BasicType(tAddress); + T_NARROWOOP = new BasicType(tNarrowOop); + T_METADATA = new BasicType(tMetadata); + T_NARROWKLASS = new BasicType(tNarrowKlass); + T_CONFLICT = new BasicType(tConflict); + T_ILLEGAL = new BasicType(tIllegal); + } public static int getTBoolean() { return tBoolean; @@ -134,23 +181,38 @@ } public static BasicType intToBasicType(int i) { - switch(i) { - case tBoolean: return T_BOOLEAN; - case tChar: return T_CHAR; - case tFloat: return T_FLOAT; - case tDouble: return T_DOUBLE; - case tByte: return T_BYTE; - case tShort: return T_SHORT; - case tInt: return T_INT; - case tLong: return T_LONG; - case tObject: return T_OBJECT; - case tArray: return T_ARRAY; - case tVoid: return T_VOID; - case tAddress: return T_ADDRESS; - case tNarrowOop: return T_NARROWOOP; - case tMetadata: return T_METADATA; - case tNarrowKlass: return T_NARROWKLASS; - default: return T_ILLEGAL; + if (i == tBoolean) { + return T_BOOLEAN; + } else if (i == tChar) { + return T_CHAR; + } else if (i == tFloat) { + return T_FLOAT; + } else if (i == tDouble) { + return T_DOUBLE; + } else if (i == tByte) { + return T_BYTE; + } else if (i == tShort) { + return T_SHORT; + } else if (i == tInt) { + return T_INT; + } else if (i == tLong) { + return T_LONG; + } else if (i == tObject) { + return T_OBJECT; + } else if (i == tArray) { + return T_ARRAY; + } else if (i == tVoid) { + return T_VOID; + } else if (i == tAddress) { + return T_ADDRESS; + } else if (i == tNarrowOop) { + return T_NARROWOOP; + } else if (i == tMetadata) { + return T_METADATA; + } else if (i == tNarrowKlass) { + return T_NARROWKLASS; + } else { + return T_ILLEGAL; } } @@ -180,24 +242,40 @@ } public String getName() { - switch (type) { - case tBoolean: return "boolean"; - case tChar: return "char"; - case tFloat: return "float"; - case tDouble: return "double"; - case tByte: return "byte"; - case tShort: return "short"; - case tInt: return "int"; - case tLong: return "long"; - case tObject: return "object"; - case tArray: return "array"; - case tVoid: return "void"; - case tAddress: return "address"; - case tNarrowOop: return "narrow oop"; - case tMetadata: return "metadata"; - case tNarrowKlass: return "narrow klass"; - case tConflict: return "conflict"; - default: return "ILLEGAL TYPE"; + if (type == tBoolean) { + return "boolean"; + } else if (type == tChar) { + return "char"; + } else if (type == tFloat) { + return "float"; + } else if (type == tDouble) { + return "double"; + } else if (type == tByte) { + return "byte"; + } else if (type == tShort) { + return "short"; + } else if (type == tInt) { + return "int"; + } else if (type == tLong) { + return "long"; + } else if (type == tObject) { + return "object"; + } else if (type == tArray) { + return "array"; + } else if (type == tVoid) { + return "void"; + } else if (type == tAddress) { + return "address"; + } else if (type == tNarrowOop) { + return "narrow oop"; + } else if (type == tMetadata) { + return "metadata"; + } else if (type == tNarrowKlass) { + return "narrow klass"; + } else if (type == tConflict) { + return "conflict"; + } else { + return "ILLEGAL TYPE"; } } --- old/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/runtime/BasicTypeSize.java 2017-11-28 16:44:41.600805829 +0900 +++ new/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/runtime/BasicTypeSize.java 2017-11-28 16:44:41.466803356 +0900 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -24,22 +24,48 @@ package sun.jvm.hotspot.runtime; +import java.util.Observer; +import sun.jvm.hotspot.types.TypeDataBase; + + /** Encapsulates the BasicTypeSize enum in globalDefinitions.hpp in the VM. */ public class BasicTypeSize { - private static boolean initialized = false; - private static int tBooleanSize = 1; - private static int tCharSize = 1; - private static int tFloatSize = 1; - private static int tDoubleSize = 2; - private static int tByteSize = 1; - private static int tShortSize = 1; - private static int tIntSize = 1; - private static int tLongSize = 2; - private static int tObjectSize = 1; - private static int tArraySize = 1; - private static int tVoidSize = 0; + private static int tBooleanSize; + private static int tCharSize; + private static int tFloatSize; + private static int tDoubleSize; + private static int tByteSize; + private static int tShortSize; + private static int tIntSize; + private static int tLongSize; + private static int tObjectSize; + private static int tArraySize; + private static int tNarrowOopSize; + private static int tNarrowKlassSize; + private static int tVoidSize; + + static { + VM.registerVMInitializedObserver( + (o, d) -> initialize(VM.getVM().getTypeDataBase())); + } + + private static synchronized void initialize(TypeDataBase db) { + tBooleanSize = db.lookupIntConstant("T_BOOLEAN_size").intValue(); + tCharSize = db.lookupIntConstant("T_INT_size").intValue(); + tFloatSize = db.lookupIntConstant("T_FLOAT_size").intValue(); + tDoubleSize = db.lookupIntConstant("T_DOUBLE_size").intValue(); + tByteSize = db.lookupIntConstant("T_BYTE_size").intValue(); + tShortSize = db.lookupIntConstant("T_SHORT_size").intValue(); + tIntSize = db.lookupIntConstant("T_INT_size").intValue(); + tLongSize = db.lookupIntConstant("T_LONG_size").intValue(); + tObjectSize = db.lookupIntConstant("T_OBJECT_size").intValue(); + tArraySize = db.lookupIntConstant("T_ARRAY_size").intValue(); + tNarrowOopSize = db.lookupIntConstant("T_NARROWOOP_size").intValue(); + tNarrowKlassSize = db.lookupIntConstant("T_NARROWKLASS_size").intValue(); + tVoidSize = db.lookupIntConstant("T_VOID_size").intValue(); + } public static int getTBooleanSize() { return tBooleanSize; @@ -81,6 +107,14 @@ return tArraySize; } + public static int getTNarrowOopSize() { + return tNarrowOopSize; + } + + public static int getTNarrowKlassSize() { + return tNarrowKlassSize; + } + public static int getTVoidSize() { return tVoidSize; } --- old/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/runtime/PerfDataEntry.java 2017-11-28 16:44:41.893811237 +0900 +++ new/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/runtime/PerfDataEntry.java 2017-11-28 16:44:41.760808782 +0900 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2004, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -131,7 +131,7 @@ public boolean booleanValue() { if (Assert.ASSERTS_ENABLED) { Assert.that(vectorLength() == 0 && - dataType() == BasicType.tBoolean, "not a boolean"); + dataType() == BasicType.getTBoolean(), "not a boolean"); } return addr.getJBooleanAt(dataOffset()); } @@ -139,7 +139,7 @@ public char charValue() { if (Assert.ASSERTS_ENABLED) { Assert.that(vectorLength() == 0 && - dataType() == BasicType.tChar, "not a char"); + dataType() == BasicType.getTChar(), "not a char"); } return addr.getJCharAt(dataOffset()); } @@ -147,7 +147,7 @@ public byte byteValue() { if (Assert.ASSERTS_ENABLED) { Assert.that(vectorLength() == 0 && - dataType() == BasicType.tByte, "not a byte"); + dataType() == BasicType.getTByte(), "not a byte"); } return addr.getJByteAt(dataOffset()); @@ -156,7 +156,7 @@ public short shortValue() { if (Assert.ASSERTS_ENABLED) { Assert.that(vectorLength() == 0 && - dataType() == BasicType.tShort, "not a short"); + dataType() == BasicType.getTShort(), "not a short"); } return addr.getJShortAt(dataOffset()); } @@ -164,7 +164,7 @@ public int intValue() { if (Assert.ASSERTS_ENABLED) { Assert.that(vectorLength() == 0 && - dataType() == BasicType.tInt, "not an int"); + dataType() == BasicType.getTInt(), "not an int"); } return addr.getJIntAt(dataOffset()); } @@ -172,7 +172,7 @@ public long longValue() { if (Assert.ASSERTS_ENABLED) { Assert.that(vectorLength() == 0 && - dataType() == BasicType.tLong, "not a long"); + dataType() == BasicType.getTLong(), "not a long"); } return addr.getJLongAt(dataOffset()); } @@ -180,7 +180,7 @@ public float floatValue() { if (Assert.ASSERTS_ENABLED) { Assert.that(vectorLength() == 0 && - dataType() == BasicType.tFloat, "not a float"); + dataType() == BasicType.getTFloat(), "not a float"); } return addr.getJFloatAt(dataOffset()); } @@ -188,7 +188,7 @@ public double doubleValue() { if (Assert.ASSERTS_ENABLED) { Assert.that(vectorLength() == 0 && - dataType() == BasicType.tDouble, "not a double"); + dataType() == BasicType.getTDouble(), "not a double"); } return addr.getJDoubleAt(dataOffset()); } @@ -197,7 +197,7 @@ int len = vectorLength(); if (Assert.ASSERTS_ENABLED) { Assert.that(len > 0 && - dataType() == BasicType.tBoolean, "not a boolean vector"); + dataType() == BasicType.getTBoolean(), "not a boolean vector"); } boolean[] res = new boolean[len]; final int off = dataOffset(); @@ -212,7 +212,7 @@ int len = vectorLength(); if (Assert.ASSERTS_ENABLED) { Assert.that(len > 0 && - dataType() == BasicType.tChar, "not a char vector"); + dataType() == BasicType.getTChar(), "not a char vector"); } char[] res = new char[len]; final int off = dataOffset(); @@ -227,7 +227,7 @@ int len = vectorLength(); if (Assert.ASSERTS_ENABLED) { Assert.that(len > 0 && - dataType() == BasicType.tByte, "not a byte vector"); + dataType() == BasicType.getTByte(), "not a byte vector"); } byte[] res = new byte[len]; final int off = dataOffset(); @@ -242,7 +242,7 @@ int len = vectorLength(); if (Assert.ASSERTS_ENABLED) { Assert.that(len > 0 && - dataType() == BasicType.tShort, "not a short vector"); + dataType() == BasicType.getTShort(), "not a short vector"); } short[] res = new short[len]; final int off = dataOffset(); @@ -257,7 +257,7 @@ int len = vectorLength(); if (Assert.ASSERTS_ENABLED) { Assert.that(len > 0 && - dataType() == BasicType.tInt, "not an int vector"); + dataType() == BasicType.getTInt(), "not an int vector"); } int[] res = new int[len]; final int off = dataOffset(); @@ -272,7 +272,7 @@ int len = vectorLength(); if (Assert.ASSERTS_ENABLED) { Assert.that(len > 0 && - dataType() == BasicType.tLong, "not a long vector"); + dataType() == BasicType.getTLong(), "not a long vector"); } long[] res = new long[len]; final int off = dataOffset(); @@ -287,7 +287,7 @@ int len = vectorLength(); if (Assert.ASSERTS_ENABLED) { Assert.that(len > 0 && - dataType() == BasicType.tFloat, "not a float vector"); + dataType() == BasicType.getTFloat(), "not a float vector"); } float[] res = new float[len]; final int off = dataOffset(); @@ -302,7 +302,7 @@ int len = vectorLength(); if (Assert.ASSERTS_ENABLED) { Assert.that(len > 0 && - dataType() == BasicType.tDouble, "not a double vector"); + dataType() == BasicType.getTDouble(), "not a double vector"); } double[] res = new double[len]; final int off = dataOffset(); @@ -319,38 +319,27 @@ int len = vectorLength(); String str = null; if (len == 0) { // scalar - switch (dataType) { - case BasicType.tBoolean: + if (dataType == BasicType.getTBoolean()) { str = Boolean.toString(booleanValue()); - break; - case BasicType.tChar: + } else if (dataType == BasicType.getTChar()) { str = "'" + Character.toString(charValue()) + "'"; - break; - case BasicType.tByte: + } else if (dataType == BasicType.getTByte()) { str = Byte.toString(byteValue()); - break; - case BasicType.tShort: + } else if (dataType == BasicType.getTShort()) { str = Short.toString(shortValue()); - break; - case BasicType.tInt: + } else if (dataType == BasicType.getTInt()) { str = Integer.toString(intValue()); - break; - case BasicType.tLong: + } else if (dataType == BasicType.getTLong()) { str = Long.toString(longValue()); - break; - case BasicType.tFloat: + } else if (dataType == BasicType.getTFloat()) { str = Float.toString(floatValue()); - break; - case BasicType.tDouble: + } else if (dataType == BasicType.getTDouble()) { str = Double.toString(doubleValue()); - break; - default: + } else { str = ""; - break; } } else { // vector - switch (dataType) { - case BasicType.tBoolean: { + if (dataType == BasicType.getTBoolean()) { boolean[] res = booleanArrayValue(); StringBuffer buf = new StringBuffer(); buf.append('['); @@ -360,26 +349,17 @@ } buf.append(']'); str = buf.toString(); - break; - } - - case BasicType.tChar: { + } else if (dataType == BasicType.getTChar()) { // char[] is returned as a String str = new String(charArrayValue()); - break; - } - - case BasicType.tByte: { + } else if (dataType == BasicType.getTByte()) { // byte[] is returned as a String try { str = new String(byteArrayValue(), "US-ASCII"); } catch (java.io.UnsupportedEncodingException e) { str = "can't decode string : " + e.getMessage(); } - break; - } - - case BasicType.tShort: { + } else if (dataType == BasicType.getTShort()) { short[] res = shortArrayValue(); StringBuffer buf = new StringBuffer(); buf.append('['); @@ -389,10 +369,7 @@ } buf.append(']'); str = buf.toString(); - break; - } - - case BasicType.tInt: { + } else if (dataType == BasicType.getTInt()) { int[] res = intArrayValue(); StringBuffer buf = new StringBuffer(); buf.append('['); @@ -402,10 +379,7 @@ } buf.append(']'); str = buf.toString(); - break; - } - - case BasicType.tLong: { + } else if (dataType == BasicType.getTLong()) { long[] res = longArrayValue(); StringBuffer buf = new StringBuffer(); buf.append('['); @@ -415,10 +389,7 @@ } buf.append(']'); str = buf.toString(); - break; - } - - case BasicType.tFloat: { + } else if (dataType == BasicType.getTFloat()) { float[] res = floatArrayValue(); StringBuffer buf = new StringBuffer(); buf.append('['); @@ -428,10 +399,7 @@ } buf.append(']'); str = buf.toString(); - break; - } - - case BasicType.tDouble: { + } else if (dataType == BasicType.getTDouble()) { double[] res = doubleArrayValue(); StringBuffer buf = new StringBuffer(); buf.append('['); @@ -441,12 +409,8 @@ } buf.append(']'); str = buf.toString(); - break; - } - - default: + } else { str = ""; - break; } }