Skip to content

Commit 7b5bd25

Browse files
rjernstChrisHegarty
authored andcommitted
8286397: Address possibly lossy conversions in jdk.hotspot.agent
Reviewed-by: cjplummer, chegar
1 parent 28c5e48 commit 7b5bd25

File tree

3 files changed

+50
-50
lines changed

3 files changed

+50
-50
lines changed

src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/oops/ObjectHeap.java

+28-28
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,15 @@ public class ObjectHeap {
5353

5454
public ObjectHeap(TypeDataBase db) throws WrongTypeException {
5555
// Get commonly used sizes of basic types
56-
oopSize = VM.getVM().getOopSize();
57-
byteSize = db.getJByteType().getSize();
58-
charSize = db.getJCharType().getSize();
59-
booleanSize = db.getJBooleanType().getSize();
60-
intSize = db.getJIntType().getSize();
61-
shortSize = db.getJShortType().getSize();
62-
longSize = db.getJLongType().getSize();
63-
floatSize = db.getJFloatType().getSize();
64-
doubleSize = db.getJDoubleType().getSize();
56+
oopSize = (int) VM.getVM().getOopSize();
57+
byteSize = (int) db.getJByteType().getSize();
58+
charSize = (int) db.getJCharType().getSize();
59+
booleanSize = (int) db.getJBooleanType().getSize();
60+
intSize = (int) db.getJIntType().getSize();
61+
shortSize = (int) db.getJShortType().getSize();
62+
longSize = (int) db.getJLongType().getSize();
63+
floatSize = (int) db.getJFloatType().getSize();
64+
doubleSize = (int) db.getJDoubleType().getSize();
6565
}
6666

6767
/** Comparison operation for oops, either or both of which may be null */
@@ -71,25 +71,25 @@ public boolean equal(Oop o1, Oop o2) {
7171
}
7272

7373
// Cached sizes of basic types
74-
private long oopSize;
75-
private long byteSize;
76-
private long charSize;
77-
private long booleanSize;
78-
private long intSize;
79-
private long shortSize;
80-
private long longSize;
81-
private long floatSize;
82-
private long doubleSize;
83-
84-
public long getOopSize() { return oopSize; }
85-
public long getByteSize() { return byteSize; }
86-
public long getCharSize() { return charSize; }
87-
public long getBooleanSize() { return booleanSize; }
88-
public long getIntSize() { return intSize; }
89-
public long getShortSize() { return shortSize; }
90-
public long getLongSize() { return longSize; }
91-
public long getFloatSize() { return floatSize; }
92-
public long getDoubleSize() { return doubleSize; }
74+
private final int oopSize;
75+
private final int byteSize;
76+
private final int charSize;
77+
private final int booleanSize;
78+
private final int intSize;
79+
private final int shortSize;
80+
private final int longSize;
81+
private final int floatSize;
82+
private final int doubleSize;
83+
84+
public int getOopSize() { return oopSize; }
85+
public int getByteSize() { return byteSize; }
86+
public int getCharSize() { return charSize; }
87+
public int getBooleanSize() { return booleanSize; }
88+
public int getIntSize() { return intSize; }
89+
public int getShortSize() { return shortSize; }
90+
public int getLongSize() { return longSize; }
91+
public int getFloatSize() { return floatSize; }
92+
public int getDoubleSize() { return doubleSize; }
9393

9494
/** an interface to filter objects while walking heap */
9595
public static interface ObjectFilter {

src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/ui/classbrowser/HTMLGenerator.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -949,7 +949,7 @@ public void print(String s) {
949949
}
950950

951951
public void endInstruction(long endPc) {
952-
instrSize += endPc - pc;
952+
instrSize += (int) (endPc - pc);
953953
if (genHTML) buf.br();
954954

955955
if (nmethod != null) {

src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/utilities/HeapHprofBinWriter.java

+21-21
Original file line numberDiff line numberDiff line change
@@ -524,12 +524,12 @@ private int calculateInstanceDumpRecordSize(Instance instance) {
524524
Assert.that(cd != null, "can not get class data for " + klass.getName().asString() + klass.getAddress());
525525
}
526526
List<Field> fields = cd.fields;
527-
return (int) BYTE_SIZE + (int)OBJ_ID_SIZE * 2 + (int)INT_SIZE * 2 + getSizeForFields(fields);
527+
return BYTE_SIZE + OBJ_ID_SIZE * 2 + INT_SIZE * 2 + getSizeForFields(fields);
528528
}
529529

530530
private int calculateClassDumpRecordSize(Klass k) {
531531
// tag + javaMirror + DUMMY_STACK_TRACE_ID + super
532-
int size = (int)BYTE_SIZE + (int)INT_SIZE + (int)OBJ_ID_SIZE * 2;
532+
int size = BYTE_SIZE + INT_SIZE + OBJ_ID_SIZE * 2;
533533
if (k instanceof InstanceKlass ik) {
534534
List<Field> fields = getInstanceFields(ik);
535535
List<Field> declaredFields = ik.getImmediateFields();
@@ -592,7 +592,7 @@ private int calculateObjectArrayDumpRecordSize(ObjArray array) {
592592
private int calculatePrimitiveArrayDumpRecordSize(TypeArray array) throws IOException {
593593
int headerSize = getArrayHeaderSize(false);
594594
TypeArrayKlass tak = (TypeArrayKlass) array.getKlass();
595-
final int type = (int) tak.getElementType();
595+
final int type = tak.getElementType();
596596
final String typeName = tak.getElementTypeName();
597597
final long typeSize = getSizeForType(type);
598598
final int length = calculateArrayMaxLength(array.getLength(),
@@ -654,7 +654,7 @@ private void fillInHeapRecordLength() throws IOException {
654654
}
655655

656656
// get the size in bytes for the requested type
657-
private long getSizeForType(int type) throws IOException {
657+
private int getSizeForType(int type) throws IOException {
658658
switch (type) {
659659
case TypeArrayKlass.T_BOOLEAN:
660660
return BOOLEAN_SIZE;
@@ -680,8 +680,8 @@ private long getSizeForType(int type) throws IOException {
680680

681681
private int getArrayHeaderSize(boolean isObjectAarray) {
682682
return isObjectAarray?
683-
((int) BYTE_SIZE + 2 * (int) INT_SIZE + 2 * (int) OBJ_ID_SIZE):
684-
(2 * (int) BYTE_SIZE + 2 * (int) INT_SIZE + (int) OBJ_ID_SIZE);
683+
(BYTE_SIZE + 2 * INT_SIZE + 2 * OBJ_ID_SIZE):
684+
(2 * BYTE_SIZE + 2 * INT_SIZE + OBJ_ID_SIZE);
685685
}
686686

687687
// Check if we need to truncate an array.
@@ -817,7 +817,7 @@ private void writeClassDumpRecord(Klass k) throws IOException {
817817

818818
private void dumpStackTraces() throws IOException {
819819
// write a HPROF_TRACE record without any frames to be referenced as object alloc sites
820-
writeHeader(HPROF_TRACE, 3 * (int)INT_SIZE );
820+
writeHeader(HPROF_TRACE, 3 * INT_SIZE );
821821
out.writeInt(DUMMY_STACK_TRACE_ID);
822822
out.writeInt(0); // thread number
823823
out.writeInt(0); // frame count
@@ -848,7 +848,7 @@ private void dumpStackTraces() throws IOException {
848848
}
849849

850850
// write HPROF_TRACE record for one thread
851-
writeHeader(HPROF_TRACE, 3 * (int)INT_SIZE + depth * (int)VM.getVM().getOopSize());
851+
writeHeader(HPROF_TRACE, 3 * INT_SIZE + depth * OBJ_ID_SIZE);
852852
int stackSerialNum = numThreads + DUMMY_STACK_TRACE_ID;
853853
out.writeInt(stackSerialNum); // stack trace serial number
854854
out.writeInt(numThreads); // thread serial number
@@ -872,7 +872,7 @@ private void dumpStackFrame(int frameSN, int classSN, Method m, int bci) throws
872872
writeSymbol(m.getSignature()); // method's signature
873873
writeSymbol(m.getMethodHolder().getSourceFileName()); // source file name
874874
// Then write FRAME descriptor
875-
writeHeader(HPROF_FRAME, 4 * (int)VM.getVM().getOopSize() + 2 * (int)INT_SIZE);
875+
writeHeader(HPROF_FRAME, 4 * OBJ_ID_SIZE + 2 * INT_SIZE);
876876
writeObjectID(frameSN); // frame serial number
877877
writeSymbolID(m.getName()); // method's name
878878
writeSymbolID(m.getSignature()); // method's signature
@@ -882,7 +882,7 @@ private void dumpStackFrame(int frameSN, int classSN, Method m, int bci) throws
882882
}
883883

884884
protected void writeJavaThread(JavaThread jt, int index) throws IOException {
885-
int size = (int)BYTE_SIZE + (int)OBJ_ID_SIZE + (int)INT_SIZE * 2;
885+
int size = BYTE_SIZE + OBJ_ID_SIZE + INT_SIZE * 2;
886886
writeHeapRecordPrologue(size);
887887
out.writeByte((byte) HPROF_GC_ROOT_THREAD_OBJ);
888888
writeObjectID(jt.getThreadObj());
@@ -904,7 +904,7 @@ public void visitAddress(Address handleAddr) {
904904
Oop oop = objectHeap.newOop(oopHandle);
905905
// exclude JNI handles hotspot internal objects
906906
if (oop != null && isJavaVisible(oop)) {
907-
int size = (int)BYTE_SIZE + (int)OBJ_ID_SIZE + (int)INT_SIZE * 2;
907+
int size = BYTE_SIZE + OBJ_ID_SIZE + INT_SIZE * 2;
908908
writeHeapRecordPrologue(size);
909909
out.writeByte((byte) HPROF_GC_ROOT_JNI_LOCAL);
910910
writeObjectID(oop);
@@ -932,7 +932,7 @@ protected void writeGlobalJNIHandle(Address handleAddr) throws IOException {
932932
Oop oop = objectHeap.newOop(oopHandle);
933933
// exclude JNI handles of hotspot internal objects
934934
if (oop != null && isJavaVisible(oop)) {
935-
int size = (int)BYTE_SIZE + (int)OBJ_ID_SIZE * 2;
935+
int size = BYTE_SIZE + OBJ_ID_SIZE * 2;
936936
writeHeapRecordPrologue(size);
937937
out.writeByte((byte) HPROF_GC_ROOT_JNI_GLOBAL);
938938
writeObjectID(oop);
@@ -961,7 +961,7 @@ protected void writeObjectArray(ObjArray array) throws IOException {
961961
protected void writePrimitiveArray(TypeArray array) throws IOException {
962962
int headerSize = getArrayHeaderSize(false);
963963
TypeArrayKlass tak = (TypeArrayKlass) array.getKlass();
964-
final int type = (int) tak.getElementType();
964+
final int type = tak.getElementType();
965965
final String typeName = tak.getElementTypeName();
966966
final long typeSize = getSizeForType(type);
967967
final int length = calculateArrayMaxLength(array.getLength(),
@@ -1390,14 +1390,14 @@ private static byte[] genByteArrayFromInt(int value) {
13901390
private long DOUBLE_BASE_OFFSET;
13911391
private long OBJECT_BASE_OFFSET;
13921392

1393-
private long BOOLEAN_SIZE;
1394-
private long BYTE_SIZE;
1395-
private long CHAR_SIZE;
1396-
private long SHORT_SIZE;
1397-
private long INT_SIZE;
1398-
private long LONG_SIZE;
1399-
private long FLOAT_SIZE;
1400-
private long DOUBLE_SIZE;
1393+
private int BOOLEAN_SIZE;
1394+
private int BYTE_SIZE;
1395+
private int CHAR_SIZE;
1396+
private int SHORT_SIZE;
1397+
private int INT_SIZE;
1398+
private int LONG_SIZE;
1399+
private int FLOAT_SIZE;
1400+
private int DOUBLE_SIZE;
14011401

14021402
private static class ClassData {
14031403
int instSize;

0 commit comments

Comments
 (0)