From b9d4ec9627bc292ea23a24530a3a19f04ead5b5a Mon Sep 17 00:00:00 2001 From: Yudi Zheng Date: Mon, 16 Jun 2025 13:59:59 +0200 Subject: [PATCH 01/11] IDE-suggested refactoring --- .../classes/jdk/vm/ci/aarch64/AArch64.java | 28 +-- .../jdk/vm/ci/aarch64/AArch64Kind.java | 77 +++------ .../share/classes/jdk/vm/ci/amd64/AMD64.java | 28 +-- .../classes/jdk/vm/ci/amd64/AMD64Kind.java | 126 ++++---------- .../classes/jdk/vm/ci/code/Architecture.java | 3 +- .../classes/jdk/vm/ci/code/BytecodeFrame.java | 12 +- .../jdk/vm/ci/code/BytecodePosition.java | 6 +- .../jdk/vm/ci/code/CallingConvention.java | 3 +- .../classes/jdk/vm/ci/code/CodeUtil.java | 13 +- .../jdk/vm/ci/code/MemoryBarriers.java | 11 +- .../classes/jdk/vm/ci/code/Register.java | 16 +- .../jdk/vm/ci/code/RegisterAttributes.java | 2 +- .../jdk/vm/ci/code/RegisterSaveLayout.java | 9 +- .../classes/jdk/vm/ci/code/RegisterValue.java | 7 +- .../jdk/vm/ci/code/StackLockValue.java | 5 +- .../classes/jdk/vm/ci/code/StackSlot.java | 5 +- .../jdk/vm/ci/code/TargetDescription.java | 22 +-- .../classes/jdk/vm/ci/code/site/Call.java | 9 +- .../vm/ci/code/site/ConstantReference.java | 5 +- .../jdk/vm/ci/code/site/DataPatch.java | 9 +- .../vm/ci/code/site/DataSectionReference.java | 5 +- .../jdk/vm/ci/code/site/ExceptionHandler.java | 9 +- .../code/site/ImplicitExceptionDispatch.java | 9 +- .../jdk/vm/ci/code/site/Infopoint.java | 6 +- .../classes/jdk/vm/ci/code/site/Mark.java | 12 +- .../hotspot/HotSpotCallingConventionType.java | 5 +- .../ci/hotspot/HotSpotCodeCacheProvider.java | 7 +- .../vm/ci/hotspot/HotSpotCompiledNmethod.java | 10 +- .../vm/ci/hotspot/HotSpotConstantPool.java | 139 ++++++--------- .../HotSpotConstantReflectionProvider.java | 28 +-- .../hotspot/HotSpotJVMCIBackendFactory.java | 4 +- .../vm/ci/hotspot/HotSpotJVMCIRuntime.java | 115 +++++------- .../HotSpotMemoryAccessProviderImpl.java | 64 +++---- .../ci/hotspot/HotSpotMetaAccessProvider.java | 88 ++++------ .../hotspot/HotSpotMetaspaceConstantImpl.java | 5 +- .../jdk/vm/ci/hotspot/HotSpotMethodData.java | 8 +- .../ci/hotspot/HotSpotMethodDataAccessor.java | 30 +--- .../HotSpotMethodHandleAccessProvider.java | 5 +- .../ci/hotspot/HotSpotObjectConstantImpl.java | 5 +- .../ci/hotspot/HotSpotProfilingInfoImpl.java | 5 +- .../vm/ci/hotspot/HotSpotReferenceMap.java | 18 +- .../hotspot/HotSpotResolvedJavaFieldImpl.java | 8 +- .../ci/hotspot/HotSpotResolvedJavaMethod.java | 1 - .../jdk/vm/ci/hotspot/HotSpotSignature.java | 7 +- .../hotspot/HotSpotSpeculationEncoding.java | 2 +- .../vm/ci/hotspot/HotSpotSpeculationLog.java | 6 +- .../jdk/vm/ci/hotspot/HotSpotVMConfig.java | 9 +- .../vm/ci/hotspot/HotSpotVMConfigStore.java | 7 +- .../IndirectHotSpotObjectConstantImpl.java | 6 +- .../jdk/vm/ci/hotspot/VMIntrinsicMethod.java | 5 +- .../AArch64HotSpotJVMCIBackendFactory.java | 5 +- .../aarch64/AArch64HotSpotRegisterConfig.java | 44 ++--- .../amd64/AMD64HotSpotRegisterConfig.java | 56 ++---- .../RISCV64HotSpotJVMCIBackendFactory.java | 8 +- .../riscv64/RISCV64HotSpotRegisterConfig.java | 44 ++--- .../jdk/vm/ci/meta/AbstractProfiledItem.java | 6 +- .../jdk/vm/ci/meta/AnnotationData.java | 5 +- .../classes/jdk/vm/ci/meta/Assumptions.java | 27 +-- .../vm/ci/meta/EncodedSpeculationReason.java | 14 +- .../classes/jdk/vm/ci/meta/EnumData.java | 5 +- .../classes/jdk/vm/ci/meta/ErrorData.java | 5 +- .../jdk/vm/ci/meta/ExceptionHandler.java | 5 +- .../classes/jdk/vm/ci/meta/JavaConstant.java | 163 +++++++----------- .../classes/jdk/vm/ci/meta/JavaKind.java | 131 +++++--------- .../share/classes/jdk/vm/ci/meta/Local.java | 5 +- .../classes/jdk/vm/ci/meta/PlatformKind.java | 5 +- .../jdk/vm/ci/meta/PrimitiveConstant.java | 38 ++-- .../classes/jdk/vm/ci/meta/ProfilingInfo.java | 8 +- .../jdk/vm/ci/meta/SpeculationLog.java | 5 +- .../jdk/vm/ci/meta/UnresolvedJavaField.java | 5 +- .../jdk/vm/ci/meta/UnresolvedJavaMethod.java | 5 +- .../jdk/vm/ci/meta/UnresolvedJavaType.java | 5 +- .../share/classes/jdk/vm/ci/meta/Value.java | 5 +- .../classes/jdk/vm/ci/riscv64/RISCV64.java | 28 +-- .../jdk/vm/ci/riscv64/RISCV64Kind.java | 49 ++---- .../classes/jdk/vm/ci/services/Services.java | 26 ++- .../jdk/vm/ci/services/SystemProperties.java | 4 +- 77 files changed, 587 insertions(+), 1143 deletions(-) diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/aarch64/AArch64.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/aarch64/AArch64.java index 66aed480bbbac..62157cccc7744 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/aarch64/AArch64.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/aarch64/AArch64.java @@ -201,25 +201,15 @@ public EnumSet getFeatures() { @Override public PlatformKind getPlatformKind(JavaKind javaKind) { - switch (javaKind) { - case Boolean: - case Byte: - return AArch64Kind.BYTE; - case Short: - case Char: - return AArch64Kind.WORD; - case Int: - return AArch64Kind.DWORD; - case Long: - case Object: - return AArch64Kind.QWORD; - case Float: - return AArch64Kind.SINGLE; - case Double: - return AArch64Kind.DOUBLE; - default: - return null; - } + return switch (javaKind) { + case Boolean, Byte -> AArch64Kind.BYTE; + case Short, Char -> AArch64Kind.WORD; + case Int -> AArch64Kind.DWORD; + case Long, Object -> AArch64Kind.QWORD; + case Float -> AArch64Kind.SINGLE; + case Double -> AArch64Kind.DOUBLE; + default -> null; + }; } @Override diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/aarch64/AArch64Kind.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/aarch64/AArch64Kind.java index ac8f74421046a..af96fc6ce99cc 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/aarch64/AArch64Kind.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/aarch64/AArch64Kind.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2025, 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 @@ -87,67 +87,32 @@ public Key getKey() { } public boolean isInteger() { - switch (this) { - case BYTE: - case WORD: - case DWORD: - case QWORD: - return true; - default: - return false; - } + return switch (this) { + case BYTE, WORD, DWORD, QWORD -> true; + default -> false; + }; } public boolean isSIMD() { - switch (this) { - case SINGLE: - case DOUBLE: - case V32_BYTE: - case V32_WORD: - case V64_BYTE: - case V64_WORD: - case V64_DWORD: - case V128_BYTE: - case V128_WORD: - case V128_DWORD: - case V128_QWORD: - case V128_SINGLE: - case V128_DOUBLE: - return true; - default: - return false; - } + return switch (this) { + case SINGLE, DOUBLE, V32_BYTE, V32_WORD, V64_BYTE, V64_WORD, V64_DWORD, V128_BYTE, V128_WORD, V128_DWORD, + V128_QWORD, V128_SINGLE, V128_DOUBLE -> true; + default -> false; + }; } @Override public char getTypeChar() { - switch (this) { - case BYTE: - return 'b'; - case WORD: - return 'w'; - case DWORD: - return 'd'; - case QWORD: - return 'q'; - case SINGLE: - return 'S'; - case DOUBLE: - return 'D'; - case V32_BYTE: - case V32_WORD: - case V64_BYTE: - case V64_WORD: - case V64_DWORD: - case V128_BYTE: - case V128_WORD: - case V128_DWORD: - case V128_QWORD: - case V128_SINGLE: - case V128_DOUBLE: - return 'v'; - default: - return '-'; - } + return switch (this) { + case BYTE -> 'b'; + case WORD -> 'w'; + case DWORD -> 'd'; + case QWORD -> 'q'; + case SINGLE -> 'S'; + case DOUBLE -> 'D'; + case V32_BYTE, V32_WORD, V64_BYTE, V64_WORD, V64_DWORD, V128_BYTE, V128_WORD, V128_DWORD, V128_QWORD, + V128_SINGLE, V128_DOUBLE -> 'v'; + default -> '-'; + }; } } diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/amd64/AMD64.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/amd64/AMD64.java index dbb27c7d7eccb..4519a36dc9b43 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/amd64/AMD64.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/amd64/AMD64.java @@ -339,25 +339,15 @@ public List getAvailableValueRegisters() { @Override public PlatformKind getPlatformKind(JavaKind javaKind) { - switch (javaKind) { - case Boolean: - case Byte: - return AMD64Kind.BYTE; - case Short: - case Char: - return AMD64Kind.WORD; - case Int: - return AMD64Kind.DWORD; - case Long: - case Object: - return AMD64Kind.QWORD; - case Float: - return AMD64Kind.SINGLE; - case Double: - return AMD64Kind.DOUBLE; - default: - return null; - } + return switch (javaKind) { + case Boolean, Byte -> AMD64Kind.BYTE; + case Short, Char -> AMD64Kind.WORD; + case Int -> AMD64Kind.DWORD; + case Long, Object -> AMD64Kind.QWORD; + case Float -> AMD64Kind.SINGLE; + case Double -> AMD64Kind.DOUBLE; + default -> null; + }; } @Override diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/amd64/AMD64Kind.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/amd64/AMD64Kind.java index 49cba6bac99a4..dab4d5257f2af 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/amd64/AMD64Kind.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/amd64/AMD64Kind.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2025, 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 @@ -108,111 +108,43 @@ public Key getKey() { } public boolean isInteger() { - switch (this) { - case BYTE: - case WORD: - case DWORD: - case QWORD: - return true; - default: - return false; - } + return switch (this) { + case BYTE, WORD, DWORD, QWORD -> true; + default -> false; + }; } public boolean isXMM() { - switch (this) { - case SINGLE: - case DOUBLE: - case V32_BYTE: - case V32_WORD: - case V64_BYTE: - case V64_WORD: - case V64_DWORD: - case V128_BYTE: - case V128_WORD: - case V128_DWORD: - case V128_QWORD: - case V128_SINGLE: - case V128_DOUBLE: - case V256_BYTE: - case V256_WORD: - case V256_DWORD: - case V256_QWORD: - case V256_SINGLE: - case V256_DOUBLE: - case V512_BYTE: - case V512_WORD: - case V512_DWORD: - case V512_QWORD: - case V512_SINGLE: - case V512_DOUBLE: - return true; - default: - return false; - } + return switch (this) { + case SINGLE, DOUBLE, V32_BYTE, V32_WORD, V64_BYTE, V64_WORD, V64_DWORD, V128_BYTE, V128_WORD, V128_DWORD, + V128_QWORD, V128_SINGLE, V128_DOUBLE, V256_BYTE, V256_WORD, V256_DWORD, V256_QWORD, V256_SINGLE, + V256_DOUBLE, V512_BYTE, V512_WORD, V512_DWORD, V512_QWORD, V512_SINGLE, V512_DOUBLE -> true; + default -> false; + }; } public boolean isMask() { - switch (this) { - case MASK8: - case MASK16: - case MASK32: - case MASK64: - return true; - default: - return false; - } + return switch (this) { + case MASK8, MASK16, MASK32, MASK64 -> true; + default -> false; + }; } @Override public char getTypeChar() { - switch (this) { - case BYTE: - return 'b'; - case WORD: - return 'w'; - case DWORD: - return 'd'; - case QWORD: - return 'q'; - case SINGLE: - return 'S'; - case DOUBLE: - return 'D'; - case V32_BYTE: - case V32_WORD: - case V64_BYTE: - case V64_WORD: - case V64_DWORD: - return 'v'; - case V128_BYTE: - case V128_WORD: - case V128_DWORD: - case V128_QWORD: - case V128_SINGLE: - case V128_DOUBLE: - return 'x'; - case V256_BYTE: - case V256_WORD: - case V256_DWORD: - case V256_QWORD: - case V256_SINGLE: - case V256_DOUBLE: - return 'y'; - case V512_BYTE: - case V512_WORD: - case V512_DWORD: - case V512_QWORD: - case V512_SINGLE: - case V512_DOUBLE: - return 'z'; - case MASK8: - case MASK16: - case MASK32: - case MASK64: - return 'k'; - default: - return '-'; - } + return switch (this) { + case BYTE -> 'b'; + case WORD -> 'w'; + case DWORD -> 'd'; + case QWORD -> 'q'; + case SINGLE -> 'S'; + case DOUBLE -> 'D'; + case V32_BYTE, V32_WORD, V64_BYTE, V64_WORD, V64_DWORD -> 'v'; + case V128_BYTE, V128_WORD, V128_DWORD, V128_QWORD, V128_SINGLE, V128_DOUBLE -> 'x'; + case V256_BYTE, V256_WORD, V256_DWORD, V256_QWORD, V256_SINGLE, V256_DOUBLE -> 'y'; + case V512_BYTE, V512_WORD, V512_DWORD, V512_QWORD, V512_SINGLE, V512_DOUBLE -> 'z'; + case MASK8, MASK16, MASK32, MASK64 -> 'k'; + default -> '-'; + }; } } diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/Architecture.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/Architecture.java index 187c1d72c6100..ce27c433864d1 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/Architecture.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/Architecture.java @@ -222,8 +222,7 @@ public final boolean equals(Object obj) { if (obj == this) { return true; } - if (obj instanceof Architecture) { - Architecture that = (Architecture) obj; + if (obj instanceof Architecture that) { if (this.name.equals(that.name)) { assert this.byteOrder.equals(that.byteOrder); assert this.implicitMemoryBarriers == that.implicitMemoryBarriers; diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/BytecodeFrame.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/BytecodeFrame.java index c4d090a74c4b0..84913b97504c2 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/BytecodeFrame.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/BytecodeFrame.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2025, 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 @@ -286,7 +286,7 @@ public boolean validateFormat() { * * @param i the local variable to query * @return the kind of local variable {@code i} - * @throw {@link IndexOutOfBoundsException} if {@code i < 0 || i >= this.numLocals} + * @throws IndexOutOfBoundsException if {@code i < 0 || i >= this.numLocals} */ public JavaKind getLocalValueKind(int i) { Objects.checkIndex(i, numLocals); @@ -298,7 +298,7 @@ public JavaKind getLocalValueKind(int i) { * * @param i the local variable to query * @return the kind of stack slot {@code i} - * @throw {@link IndexOutOfBoundsException} if {@code i < 0 || i >= this.numStack} + * @throws IndexOutOfBoundsException if {@code i < 0 || i >= this.numStack} */ public JavaKind getStackValueKind(int i) { Objects.checkIndex(i, numStack); @@ -310,7 +310,7 @@ public JavaKind getStackValueKind(int i) { * * @param i the local variable index * @return the value that can be used to reconstruct the local's current value - * @throw {@link IndexOutOfBoundsException} if {@code i < 0 || i >= this.numLocals} + * @throws IndexOutOfBoundsException if {@code i < 0 || i >= this.numLocals} */ public JavaValue getLocalValue(int i) { Objects.checkIndex(i, numLocals); @@ -322,7 +322,7 @@ public JavaValue getLocalValue(int i) { * * @param i the stack index * @return the value that can be used to reconstruct the stack slot's current value - * @throw {@link IndexOutOfBoundsException} if {@code i < 0 || i >= this.numStack} + * @throws IndexOutOfBoundsException if {@code i < 0 || i >= this.numStack} */ public JavaValue getStackValue(int i) { Objects.checkIndex(i, numStack); @@ -334,7 +334,7 @@ public JavaValue getStackValue(int i) { * * @param i the lock index * @return the value that can be used to reconstruct the lock's current value - * @throw {@link IndexOutOfBoundsException} if {@code i < 0 || i >= this.numLocks} + * @throws IndexOutOfBoundsException if {@code i < 0 || i >= this.numLocks} */ public JavaValue getLockValue(int i) { Objects.checkIndex(i, numLocks); diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/BytecodePosition.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/BytecodePosition.java index 06a86c3935661..105b95631c5ce 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/BytecodePosition.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/BytecodePosition.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2025, 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 @@ -78,9 +78,7 @@ public boolean equals(Object obj) { } if (obj != null && getClass() == obj.getClass()) { BytecodePosition that = (BytecodePosition) obj; - if (this.bci == that.bci && Objects.equals(this.getMethod(), that.getMethod()) && Objects.equals(this.caller, that.caller)) { - return true; - } + return this.bci == that.bci && Objects.equals(this.getMethod(), that.getMethod()) && Objects.equals(this.caller, that.caller); } return false; } diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/CallingConvention.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/CallingConvention.java index df87a5408c07a..da4faa831beab 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/CallingConvention.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/CallingConvention.java @@ -123,8 +123,7 @@ public String toString() { } private boolean verify() { - for (int i = 0; i < argumentLocations.size(); i++) { - Value location = argumentLocations.get(i); + for (Value location : argumentLocations) { assert isStackSlot(location) || isAllocatableValue(location); } return true; diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/CodeUtil.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/CodeUtil.java index 59af250a69518..68a0cce9a871d 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/CodeUtil.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/CodeUtil.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2025, 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 @@ -248,14 +248,11 @@ public static String tabulate(Object[] cells, int cols, int lpad, int rpad) { } } StringBuilder sb = new StringBuilder(); - String nl = NEW_LINE; for (int row = 0; row < rows; row++) { for (int col = 0; col < cols; col++) { int index = col + (row * cols); if (index < cells.length) { - for (int i = 0; i < lpad; i++) { - sb.append(' '); - } + sb.append(" ".repeat(Math.max(0, lpad))); Object cell = cells[index]; String s = String.valueOf(cell); int w = s.length(); @@ -264,12 +261,10 @@ public static String tabulate(Object[] cells, int cols, int lpad, int rpad) { sb.append(' '); w++; } - for (int i = 0; i < rpad; i++) { - sb.append(' '); - } + sb.append(" ".repeat(Math.max(0, rpad))); } } - sb.append(nl); + sb.append(NEW_LINE); } return sb.toString(); } diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/MemoryBarriers.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/MemoryBarriers.java index 08bc0856d3ed6..44355bcbf0517 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/MemoryBarriers.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/MemoryBarriers.java @@ -111,11 +111,10 @@ public class MemoryBarriers { public static final int JMM_POST_VOLATILE_READ = LOAD_LOAD | LOAD_STORE; public static String barriersString(int barriers) { - StringBuilder sb = new StringBuilder(); - sb.append((barriers & LOAD_LOAD) != 0 ? "LOAD_LOAD " : ""); - sb.append((barriers & LOAD_STORE) != 0 ? "LOAD_STORE " : ""); - sb.append((barriers & STORE_LOAD) != 0 ? "STORE_LOAD " : ""); - sb.append((barriers & STORE_STORE) != 0 ? "STORE_STORE " : ""); - return sb.toString().trim(); + String sb = ((barriers & LOAD_LOAD) != 0 ? "LOAD_LOAD " : "") + + ((barriers & LOAD_STORE) != 0 ? "LOAD_STORE " : "") + + ((barriers & STORE_LOAD) != 0 ? "STORE_LOAD " : "") + + ((barriers & STORE_STORE) != 0 ? "STORE_STORE " : ""); + return sb.trim(); } } diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/Register.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/Register.java index f271053db1e2d..bf4d2265e132f 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/Register.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/Register.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2025, 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 @@ -95,8 +95,7 @@ public int hashCode() { @Override public boolean equals(Object obj) { - if (obj instanceof RegisterCategory) { - RegisterCategory that = (RegisterCategory) obj; + if (obj instanceof RegisterCategory that) { return this.name.equals(that.name); } return false; @@ -164,13 +163,7 @@ public String toString() { @Override public int compareTo(Register o) { - if (number < o.number) { - return -1; - } - if (number > o.number) { - return 1; - } - return 0; + return Integer.compare(number, o.number); } @Override @@ -180,8 +173,7 @@ public int hashCode() { @Override public boolean equals(Object obj) { - if (obj instanceof Register) { - Register other = (Register) obj; + if (obj instanceof Register other) { if (number == other.number) { assert name.equals(other.name); assert encoding == other.encoding; diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/RegisterAttributes.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/RegisterAttributes.java index 652687744841c..d9856b191bfed 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/RegisterAttributes.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/RegisterAttributes.java @@ -52,7 +52,7 @@ public RegisterAttributes(boolean isCallerSave, boolean isCalleeSave, boolean is * * @param registerConfig a register configuration * @param registers a set of registers - * @return an array whose length is the max register number in {@code registers} plus 1. An + * @return a list whose length is the max register number in {@code registers} plus 1. An * element at index i holds the attributes of the register whose number is i. */ public static List createMap(RegisterConfig registerConfig, List registers) { diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/RegisterSaveLayout.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/RegisterSaveLayout.java index 49c9608a21e29..f55c846cc2a2e 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/RegisterSaveLayout.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/RegisterSaveLayout.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2025, 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 @@ -123,11 +123,8 @@ public boolean equals(Object obj) { if (this == obj) { return true; } - if (obj instanceof RegisterSaveLayout) { - RegisterSaveLayout that = (RegisterSaveLayout) obj; - if (Arrays.equals(registers, that.registers) && Arrays.equals(slots, that.slots)) { - return true; - } + if (obj instanceof RegisterSaveLayout that) { + return Arrays.equals(registers, that.registers) && Arrays.equals(slots, that.slots); } return false; } diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/RegisterValue.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/RegisterValue.java index 7104fc0c26d3d..832612559bf44 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/RegisterValue.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/RegisterValue.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2025, 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 @@ -32,7 +32,7 @@ public final class RegisterValue extends AllocatableValue { private final Register reg; - protected RegisterValue(ValueKind kind, Register register) { + RegisterValue(ValueKind kind, Register register) { super(kind); this.reg = register; } @@ -56,8 +56,7 @@ public int hashCode() { @Override public boolean equals(Object obj) { - if (obj instanceof RegisterValue) { - RegisterValue other = (RegisterValue) obj; + if (obj instanceof RegisterValue other) { return super.equals(obj) && reg.equals(other.reg); } return false; diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/StackLockValue.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/StackLockValue.java index 43337e539eaff..891b2586eec8a 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/StackLockValue.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/StackLockValue.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2025, 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 @@ -73,8 +73,7 @@ public int hashCode() { @Override public boolean equals(Object obj) { - if (obj instanceof StackLockValue) { - StackLockValue other = (StackLockValue) obj; + if (obj instanceof StackLockValue other) { return super.equals(obj) && eliminated == other.eliminated && owner.equals(other.owner) && slot.equals(other.slot); } return false; diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/StackSlot.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/StackSlot.java index ca4a8b531f031..6babd54e46f4a 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/StackSlot.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/StackSlot.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2025, 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 @@ -126,8 +126,7 @@ public int hashCode() { @Override public boolean equals(Object obj) { - if (obj instanceof StackSlot) { - StackSlot other = (StackSlot) obj; + if (obj instanceof StackSlot other) { return super.equals(obj) && addFrameSize == other.addFrameSize && offset == other.offset; } return false; diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/TargetDescription.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/TargetDescription.java index e1e746c6fe3f7..4578d3a8beaed 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/TargetDescription.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/TargetDescription.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2025, 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 @@ -25,7 +25,6 @@ import static jdk.vm.ci.meta.MetaUtil.identityHashCodeString; import jdk.vm.ci.meta.JavaKind; -import jdk.vm.ci.services.Services; import jdk.internal.util.OperatingSystem; /** @@ -101,18 +100,15 @@ public final boolean equals(Object obj) { if (this == obj) { return true; } - if (obj instanceof TargetDescription) { - TargetDescription that = (TargetDescription) obj; + if (obj instanceof TargetDescription that) { // @formatter:off - if (this.implicitNullCheckLimit == that.implicitNullCheckLimit && - this.inlineObjects == that.inlineObjects && - this.isMP == that.isMP && - this.stackAlignment == that.stackAlignment && - this.wordJavaKind.equals(that.wordJavaKind) && - this.wordSize == that.wordSize && - this.arch.equals(that.arch)) { - return true; - } + return this.implicitNullCheckLimit == that.implicitNullCheckLimit + && this.inlineObjects == that.inlineObjects + && this.isMP == that.isMP + && this.stackAlignment == that.stackAlignment + && this.wordJavaKind.equals(that.wordJavaKind) + && this.wordSize == that.wordSize + && this.arch.equals(that.arch); // @formatter:on } return false; diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/site/Call.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/site/Call.java index c323b055a35fd..bf7365b4622e1 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/site/Call.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/site/Call.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2025, 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 @@ -61,11 +61,8 @@ public boolean equals(Object obj) { if (this == obj) { return true; } - if (obj instanceof Call && super.equals(obj)) { - Call that = (Call) obj; - if (this.size == that.size && this.direct == that.direct && Objects.equals(this.target, that.target)) { - return true; - } + if (obj instanceof Call that && super.equals(obj)) { + return this.size == that.size && this.direct == that.direct && Objects.equals(this.target, that.target); } return false; } diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/site/ConstantReference.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/site/ConstantReference.java index 232bc477de6bf..7101bfa026ae9 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/site/ConstantReference.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/site/ConstantReference.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2025, 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 @@ -57,8 +57,7 @@ public boolean equals(Object obj) { if (this == obj) { return true; } - if (obj instanceof ConstantReference) { - ConstantReference that = (ConstantReference) obj; + if (obj instanceof ConstantReference that) { return Objects.equals(this.constant, that.constant); } return false; diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/site/DataPatch.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/site/DataPatch.java index df67033d8e973..8c14f54f8203f 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/site/DataPatch.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/site/DataPatch.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2025, 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 @@ -62,11 +62,8 @@ public boolean equals(Object obj) { if (this == obj) { return true; } - if (obj instanceof DataPatch) { - DataPatch that = (DataPatch) obj; - if (this.pcOffset == that.pcOffset && Objects.equals(this.reference, that.reference) && Objects.equals(this.note, that.note)) { - return true; - } + if (obj instanceof DataPatch that) { + return this.pcOffset == that.pcOffset && Objects.equals(this.reference, that.reference) && Objects.equals(this.note, that.note); } return false; } diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/site/DataSectionReference.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/site/DataSectionReference.java index 364141e2c2a81..06ba8dc803538 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/site/DataSectionReference.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/site/DataSectionReference.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2025, 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 @@ -59,8 +59,7 @@ public boolean equals(Object obj) { if (this == obj) { return true; } - if (obj instanceof DataSectionReference) { - DataSectionReference that = (DataSectionReference) obj; + if (obj instanceof DataSectionReference that) { return this.offset == that.offset; } return false; diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/site/ExceptionHandler.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/site/ExceptionHandler.java index 3f9f73f386799..118caca8d2009 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/site/ExceptionHandler.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/site/ExceptionHandler.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2025, 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 @@ -45,11 +45,8 @@ public boolean equals(Object obj) { if (this == obj) { return true; } - if (obj instanceof ExceptionHandler) { - ExceptionHandler that = (ExceptionHandler) obj; - if (this.pcOffset == that.pcOffset && this.handlerPos == that.handlerPos) { - return true; - } + if (obj instanceof ExceptionHandler that) { + return this.pcOffset == that.pcOffset && this.handlerPos == that.handlerPos; } return false; } diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/site/ImplicitExceptionDispatch.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/site/ImplicitExceptionDispatch.java index 2d4bf6eec45c4..27d2927941e6d 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/site/ImplicitExceptionDispatch.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/site/ImplicitExceptionDispatch.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2025, 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 @@ -54,11 +54,8 @@ public boolean equals(Object obj) { if (this == obj) { return true; } - if (obj instanceof ImplicitExceptionDispatch && super.equals(obj)) { - ImplicitExceptionDispatch that = (ImplicitExceptionDispatch) obj; - if (this.dispatchOffset == that.dispatchOffset) { - return true; - } + if (obj instanceof ImplicitExceptionDispatch that && super.equals(obj)) { + return this.dispatchOffset == that.dispatchOffset; } return false; } diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/site/Infopoint.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/site/Infopoint.java index e590768cab7f9..08f5567b0f564 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/site/Infopoint.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/site/Infopoint.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2025, 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 @@ -74,9 +74,7 @@ public boolean equals(Object obj) { } if (obj != null && obj.getClass() == getClass()) { Infopoint that = (Infopoint) obj; - if (this.pcOffset == that.pcOffset && Objects.equals(this.debugInfo, that.debugInfo) && Objects.equals(this.reason, that.reason)) { - return true; - } + return this.pcOffset == that.pcOffset && Objects.equals(this.debugInfo, that.debugInfo) && Objects.equals(this.reason, that.reason); } return false; } diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/site/Mark.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/site/Mark.java index ed2dc336dbb82..ddc4d01791415 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/site/Mark.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/site/Mark.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2025, 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 @@ -38,9 +38,6 @@ public final class Mark extends Site { /** * Creates a mark that associates {@code id} with the machine code position {@code pcOffset}. - * - * @param pcOffset - * @param id */ public Mark(int pcOffset, Object id) { super(pcOffset); @@ -63,11 +60,8 @@ public boolean equals(Object obj) { if (this == obj) { return true; } - if (obj instanceof Mark) { - Mark that = (Mark) obj; - if (this.pcOffset == that.pcOffset && Objects.equals(this.id, that.id)) { - return true; - } + if (obj instanceof Mark that) { + return this.pcOffset == that.pcOffset && Objects.equals(this.id, that.id); } return false; } diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotCallingConventionType.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotCallingConventionType.java index 3a6f28ce2a9ef..02d34bb5694bc 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotCallingConventionType.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotCallingConventionType.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2025, 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 @@ -23,7 +23,6 @@ package jdk.vm.ci.hotspot; import jdk.vm.ci.code.CallingConvention; -import jdk.vm.ci.code.CallingConvention.Type; public enum HotSpotCallingConventionType implements CallingConvention.Type { /** @@ -47,8 +46,6 @@ public enum HotSpotCallingConventionType implements CallingConvention.Type { */ public final boolean out; - public static final Type[] VALUES = values(); - HotSpotCallingConventionType(boolean out) { this.out = out; } diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotCodeCacheProvider.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotCodeCacheProvider.java index 9545c9aa9ec2b..4843fe01dac35 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotCodeCacheProvider.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotCodeCacheProvider.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2025, 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 @@ -77,7 +77,7 @@ public String getTargetName(Call call) { HotSpotVMConfigStore store = runtime.getConfigStore(); for (Map.Entry e : store.getFields().entrySet()) { VMField field = e.getValue(); - if (field.isStatic() && field.value != null && field.value instanceof Long && ((Long) field.value) == address) { + if (field.isStatic() && field.value instanceof Long && ((Long) field.value) == address) { return e.getValue() + ":0x" + Long.toHexString(address); } } @@ -155,8 +155,7 @@ public InstalledCode installCode(ResolvedJavaMethod method, CompiledCode compile } public void invalidateInstalledCode(InstalledCode installedCode, int invalidationReason) { - if (installedCode instanceof HotSpotNmethod) { - HotSpotNmethod nmethod = (HotSpotNmethod) installedCode; + if (installedCode instanceof HotSpotNmethod nmethod) { nmethod.invalidate(true, invalidationReason); } else { throw new IllegalArgumentException("Cannot invalidate a " + Objects.requireNonNull(installedCode).getClass().getName()); diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotCompiledNmethod.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotCompiledNmethod.java index b1be3dee25cd8..4bd4dd6f77ff1 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotCompiledNmethod.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotCompiledNmethod.java @@ -33,20 +33,20 @@ */ public final class HotSpotCompiledNmethod extends HotSpotCompiledCode { - protected final HotSpotResolvedJavaMethod method; - protected final int entryBCI; + final HotSpotResolvedJavaMethod method; + final int entryBCI; /** * Compilation identifier. */ - protected final int id; + final int id; /** * Address of a native {@code JVMCICompileState} object or 0L if no such object exists. */ - protected final long compileState; + final long compileState; - protected final boolean hasUnsafeAccess; + final boolean hasUnsafeAccess; /** * May be set by VM if code installation fails. It will describe in more detail why installation diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotConstantPool.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotConstantPool.java index 20e3915527d11..96bdd7288805f 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotConstantPool.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotConstantPool.java @@ -22,16 +22,16 @@ */ package jdk.vm.ci.hotspot; +import static jdk.vm.ci.hotspot.CompilerToVM.compilerToVM; +import static jdk.vm.ci.hotspot.HotSpotJVMCIRuntime.runtime; +import static jdk.vm.ci.hotspot.HotSpotVMConfig.config; +import static jdk.vm.ci.hotspot.UnsafeAccess.UNSAFE; + import java.util.AbstractList; import java.util.List; import java.util.stream.Collectors; import java.util.stream.IntStream; - import jdk.vm.ci.common.JVMCIError; -import static jdk.vm.ci.hotspot.CompilerToVM.compilerToVM; -import static jdk.vm.ci.hotspot.HotSpotJVMCIRuntime.runtime; -import static jdk.vm.ci.hotspot.HotSpotVMConfig.config; -import static jdk.vm.ci.hotspot.UnsafeAccess.UNSAFE; import jdk.vm.ci.meta.ConstantPool; import jdk.vm.ci.meta.JavaConstant; import jdk.vm.ci.meta.JavaField; @@ -87,29 +87,20 @@ public static class Bytecodes { public static final int MULTIANEWARRAY = 197; // 0xC5 static boolean isInvoke(int opcode) { - switch (opcode) { - case INVOKEVIRTUAL: - case INVOKESPECIAL: - case INVOKESTATIC: - case INVOKEINTERFACE: - case INVOKEDYNAMIC: - return true; - default: - return false; - } + return switch (opcode) { + case INVOKEVIRTUAL, INVOKESPECIAL, INVOKESTATIC, INVOKEINTERFACE, INVOKEDYNAMIC -> true; + default -> false; + }; } /** * See: {@code Rewriter::maybe_rewrite_invokehandle}. */ static boolean isInvokeHandleAlias(int opcode) { - switch (opcode) { - case INVOKEVIRTUAL: - case INVOKESPECIAL: - return true; - default: - return false; - } + return switch (opcode) { + case INVOKEVIRTUAL, INVOKESPECIAL -> true; + default -> false; + }; } } @@ -511,15 +502,13 @@ public JavaConstant get(int index) { if (res == null) { int argCpi = compilerToVM().bootstrapArgumentIndexAt(cp, bssIndex, index); Object object = cp.lookupConstant(argCpi, false); - if (object instanceof PrimitiveConstant primitiveConstant) { - res = runtime().getReflection().boxPrimitive(primitiveConstant); - } else if (object instanceof JavaConstant javaConstant) { - res = javaConstant; - } else if (object instanceof JavaType type) { - res = runtime().getReflection().forObject(type); - } else { - res = JavaConstant.forInt(argCpi); - } + res = switch (object) { + case PrimitiveConstant primitiveConstant -> + runtime().getReflection().boxPrimitive(primitiveConstant); + case JavaConstant javaConstant -> javaConstant; + case JavaType type -> runtime().getReflection().forObject(type); + case null, default -> JavaConstant.forInt(argCpi); + }; cache[index] = res; } return res; @@ -621,17 +610,16 @@ public BootstrapMethodInvocation lookupBootstrapMethodInvocation(int index, int JavaConstant type = (JavaConstant) bsmi[2]; Object staticArguments = bsmi[3]; List staticArgumentsList; - if (staticArguments == null) { - staticArgumentsList = List.of(); - } else if (staticArguments instanceof JavaConstant) { - staticArgumentsList = List.of((JavaConstant) staticArguments); - } else if (staticArguments instanceof JavaConstant[]) { - staticArgumentsList = List.of((JavaConstant[]) staticArguments); - } else { - int[] bsciArgs = (int[]) staticArguments; - int argCount = bsciArgs[0]; - int bss_index = bsciArgs[1]; - staticArgumentsList = new CachedBSMArgs(this, bss_index, argCount); + switch (staticArguments) { + case null -> staticArgumentsList = List.of(); + case JavaConstant javaConstant -> staticArgumentsList = List.of(javaConstant); + case JavaConstant[] javaConstants -> staticArgumentsList = List.of(javaConstants); + default -> { + int[] bsciArgs = (int[]) staticArguments; + int argCount = bsciArgs[0]; + int bss_index = bsciArgs[1]; + staticArgumentsList = new CachedBSMArgs(this, bss_index, argCount); + } } boolean isIndy = tag.name.equals("InvokeDynamic"); return new BootstrapMethodInvocationImpl(isIndy, method, name, type, staticArgumentsList, isIndy ? index : cpi); @@ -668,20 +656,14 @@ public List lookupBootstrapMethodInvocations(boolean */ JavaConstant getStaticFieldConstantValue(int cpi) { final JvmConstant tag = getTagAt(cpi); - switch (tag.name) { - case "Integer": - return JavaConstant.forInt(getIntAt(cpi)); - case "Long": - return JavaConstant.forLong(getLongAt(cpi)); - case "Float": - return JavaConstant.forFloat(getFloatAt(cpi)); - case "Double": - return JavaConstant.forDouble(getDoubleAt(cpi)); - case "String": - return compilerToVM().getUncachedStringInPool(this, cpi); - default: - throw new IllegalArgumentException("Illegal entry for a ConstantValue attribute:" + tag); - } + return switch (tag.name) { + case "Integer" -> JavaConstant.forInt(getIntAt(cpi)); + case "Long" -> JavaConstant.forLong(getLongAt(cpi)); + case "Float" -> JavaConstant.forFloat(getFloatAt(cpi)); + case "Double" -> JavaConstant.forDouble(getDoubleAt(cpi)); + case "String" -> compilerToVM().getUncachedStringInPool(this, cpi); + default -> throw new IllegalArgumentException("Illegal entry for a ConstantValue attribute:" + tag); + }; } @Override @@ -692,37 +674,26 @@ public Object lookupConstant(int cpi) { @Override public Object lookupConstant(int cpi, boolean resolve) { final JvmConstant tag = getTagAt(cpi); - switch (tag.name) { - case "Integer": - return JavaConstant.forInt(getIntAt(cpi)); - case "Long": - return JavaConstant.forLong(getLongAt(cpi)); - case "Float": - return JavaConstant.forFloat(getFloatAt(cpi)); - case "Double": - return JavaConstant.forDouble(getDoubleAt(cpi)); - case "Class": - case "UnresolvedClass": - case "UnresolvedClassInError": + return switch (tag.name) { + case "Integer" -> JavaConstant.forInt(getIntAt(cpi)); + case "Long" -> JavaConstant.forLong(getLongAt(cpi)); + case "Float" -> JavaConstant.forFloat(getFloatAt(cpi)); + case "Double" -> JavaConstant.forDouble(getDoubleAt(cpi)); + case "Class", "UnresolvedClass", "UnresolvedClassInError" -> { final int opcode = -1; // opcode is not used - return lookupType(cpi, opcode); - case "String": + yield lookupType(cpi, opcode); // opcode is not used + } + case "String" -> /* * Normally, we would expect a String here, but unsafe anonymous classes can have * "pseudo strings" (arbitrary live objects) patched into a String entry. Such * entries do not have a symbol in the constant pool slot. */ - return compilerToVM().lookupConstantInPool(this, cpi, true); - case "MethodHandle": - case "MethodHandleInError": - case "MethodType": - case "MethodTypeInError": - case "Dynamic": - case "DynamicInError": - return compilerToVM().lookupConstantInPool(this, cpi, resolve); - default: - throw new JVMCIError("Unknown constant pool tag %s", tag); - } + compilerToVM().lookupConstantInPool(this, cpi, true); + case "MethodHandle", "MethodHandleInError", "MethodType", "MethodTypeInError", "Dynamic", + "DynamicInError" -> compilerToVM().lookupConstantInPool(this, cpi, resolve); + default -> throw new JVMCIError("Unknown constant pool tag %s", tag); + }; } @@ -751,8 +722,7 @@ public JavaConstant lookupAppendix(int rawIndex, int opcode) { * @param type either a ResolvedJavaType or a String naming a unresolved type. */ private static JavaType getJavaType(final Object type) { - if (type instanceof String) { - String name = (String) type; + if (type instanceof String name) { return UnresolvedJavaType.create("L" + name + ";"); } else { return (JavaType) type; @@ -852,8 +822,7 @@ public JavaField lookupField(int rawIndex, ResolvedJavaMethod method, int opcode final int offset = info[1]; final int fieldIndex = info[2]; final int fieldFlags = info[3]; - HotSpotResolvedJavaField result = resolvedHolder.createField(type, offset, flags, fieldFlags, fieldIndex); - return result; + return resolvedHolder.createField(type, offset, flags, fieldFlags, fieldIndex); } else { return new UnresolvedJavaField(fieldHolder, lookupUtf8(getNameRefIndexAt(nameAndTypeIndex)), type); } diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotConstantReflectionProvider.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotConstantReflectionProvider.java index 9e1cd28752733..f3787e723e7ed 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotConstantReflectionProvider.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotConstantReflectionProvider.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2025, 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 @@ -25,7 +25,6 @@ import static jdk.vm.ci.hotspot.HotSpotJVMCIRuntime.runtime; import java.util.Objects; - import jdk.vm.ci.common.JVMCIError; import jdk.vm.ci.meta.Constant; import jdk.vm.ci.meta.ConstantReflectionProvider; @@ -99,23 +98,14 @@ public JavaConstant readArrayElement(JavaConstant array, int index) { * @return true if the box is cached */ private static boolean isBoxCached(JavaConstant source) { - switch (source.getJavaKind()) { - case Boolean: - return true; - case Char: - return source.asInt() <= 127; - case Byte: - case Short: - case Int: - return source.asInt() >= -128 && source.asInt() <= 127; - case Long: - return source.asLong() >= -128 && source.asLong() <= 127; - case Float: - case Double: - return false; - default: - throw new IllegalArgumentException("unexpected kind " + source.getJavaKind()); - } + return switch (source.getJavaKind()) { + case Boolean -> true; + case Char -> source.asInt() <= 127; + case Byte, Short, Int -> source.asInt() >= -128 && source.asInt() <= 127; + case Long -> source.asLong() >= -128 && source.asLong() <= 127; + case Float, Double -> false; + default -> throw new IllegalArgumentException("unexpected kind " + source.getJavaKind()); + }; } @Override diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotJVMCIBackendFactory.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotJVMCIBackendFactory.java index 319b9b9bc44d7..330c038b13849 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotJVMCIBackendFactory.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotJVMCIBackendFactory.java @@ -22,15 +22,15 @@ */ package jdk.vm.ci.hotspot; +import static jdk.vm.ci.hotspot.UnsafeAccess.UNSAFE; + import java.util.ArrayList; import java.util.EnumSet; import java.util.List; import java.util.Map; import java.util.Map.Entry; - import jdk.vm.ci.common.JVMCIError; import jdk.vm.ci.runtime.JVMCIBackend; -import static jdk.vm.ci.hotspot.UnsafeAccess.UNSAFE; public interface HotSpotJVMCIBackendFactory { diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotJVMCIRuntime.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotJVMCIRuntime.java index ebe2778ca3c8e..6946666ea4aef 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotJVMCIRuntime.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotJVMCIRuntime.java @@ -25,8 +25,8 @@ import static jdk.vm.ci.common.InitTimer.timer; import static jdk.vm.ci.services.Services.IS_IN_NATIVE_IMAGE; -import java.io.IOException; import java.io.ByteArrayOutputStream; +import java.io.IOException; import java.io.OutputStream; import java.io.PrintStream; import java.io.Serializable; @@ -52,7 +52,6 @@ import java.util.function.Predicate; import java.util.regex.Matcher; import java.util.regex.Pattern; - import jdk.internal.misc.Unsafe; import jdk.vm.ci.code.Architecture; import jdk.vm.ci.code.CompilationRequest; @@ -170,7 +169,6 @@ HotSpotResolvedObjectType getMethodHandleClass() { * Gets the singleton {@link HotSpotJVMCIRuntime} object. */ @VMEntryPoint - @SuppressWarnings("try") public static HotSpotJVMCIRuntime runtime() { HotSpotJVMCIRuntime result = instance; if (result == null) { @@ -180,7 +178,7 @@ public static HotSpotJVMCIRuntime runtime() { synchronized (JVMCI.class) { result = instance; if (result == null) { - try (InitTimer t = timer("HotSpotJVMCIRuntime.")) { + try (InitTimer _ = timer("HotSpotJVMCIRuntime.")) { instance = result = new HotSpotJVMCIRuntime(); // Can only do eager initialization of the JVMCI compiler @@ -556,11 +554,10 @@ public KlassWeakReference(Long klassPointer, HotSpotResolvedObjectTypeImpl refer private final List vmEventListeners; - @SuppressWarnings("try") private HotSpotJVMCIRuntime() { compilerToVm = new CompilerToVM(); - try (InitTimer t = timer("HotSpotVMConfig")) { + try (InitTimer _ = timer("HotSpotVMConfig")) { configStore = new HotSpotVMConfigStore(compilerToVm); config = new HotSpotVMConfig(configStore); } @@ -578,7 +575,7 @@ private HotSpotJVMCIRuntime() { // Initialize the Option values. Option.parse(this); - try (InitTimer t = timer("create JVMCI backend:", backendFactory.getArchitecture())) { + try (InitTimer _ = timer("create JVMCI backend:", backendFactory.getArchitecture())) { hostBackend = registerBackend(backendFactory.createJVMCIBackend(this, null)); } @@ -1137,29 +1134,18 @@ public boolean setCountersSize(int newSize) { * @return the offset in bytes */ public int getArrayBaseOffset(JavaKind kind) { - switch (kind) { - case Boolean: - return compilerToVm.ARRAY_BOOLEAN_BASE_OFFSET; - case Byte: - return compilerToVm.ARRAY_BYTE_BASE_OFFSET; - case Char: - return compilerToVm.ARRAY_CHAR_BASE_OFFSET; - case Short: - return compilerToVm.ARRAY_SHORT_BASE_OFFSET; - case Int: - return compilerToVm.ARRAY_INT_BASE_OFFSET; - case Long: - return compilerToVm.ARRAY_LONG_BASE_OFFSET; - case Float: - return compilerToVm.ARRAY_FLOAT_BASE_OFFSET; - case Double: - return compilerToVm.ARRAY_DOUBLE_BASE_OFFSET; - case Object: - return compilerToVm.ARRAY_OBJECT_BASE_OFFSET; - default: - throw new JVMCIError("%s", kind); - } - + return switch (kind) { + case Boolean -> compilerToVm.ARRAY_BOOLEAN_BASE_OFFSET; + case Byte -> compilerToVm.ARRAY_BYTE_BASE_OFFSET; + case Char -> compilerToVm.ARRAY_CHAR_BASE_OFFSET; + case Short -> compilerToVm.ARRAY_SHORT_BASE_OFFSET; + case Int -> compilerToVm.ARRAY_INT_BASE_OFFSET; + case Long -> compilerToVm.ARRAY_LONG_BASE_OFFSET; + case Float -> compilerToVm.ARRAY_FLOAT_BASE_OFFSET; + case Double -> compilerToVm.ARRAY_DOUBLE_BASE_OFFSET; + case Object -> compilerToVm.ARRAY_OBJECT_BASE_OFFSET; + default -> throw new JVMCIError("%s", kind); + }; } /** @@ -1168,29 +1154,18 @@ public int getArrayBaseOffset(JavaKind kind) { * @return the scale in order to convert the index into a byte offset */ public int getArrayIndexScale(JavaKind kind) { - switch (kind) { - case Boolean: - return compilerToVm.ARRAY_BOOLEAN_INDEX_SCALE; - case Byte: - return compilerToVm.ARRAY_BYTE_INDEX_SCALE; - case Char: - return compilerToVm.ARRAY_CHAR_INDEX_SCALE; - case Short: - return compilerToVm.ARRAY_SHORT_INDEX_SCALE; - case Int: - return compilerToVm.ARRAY_INT_INDEX_SCALE; - case Long: - return compilerToVm.ARRAY_LONG_INDEX_SCALE; - case Float: - return compilerToVm.ARRAY_FLOAT_INDEX_SCALE; - case Double: - return compilerToVm.ARRAY_DOUBLE_INDEX_SCALE; - case Object: - return compilerToVm.ARRAY_OBJECT_INDEX_SCALE; - default: - throw new JVMCIError("%s", kind); - - } + return switch (kind) { + case Boolean -> compilerToVm.ARRAY_BOOLEAN_INDEX_SCALE; + case Byte -> compilerToVm.ARRAY_BYTE_INDEX_SCALE; + case Char -> compilerToVm.ARRAY_CHAR_INDEX_SCALE; + case Short -> compilerToVm.ARRAY_SHORT_INDEX_SCALE; + case Int -> compilerToVm.ARRAY_INT_INDEX_SCALE; + case Long -> compilerToVm.ARRAY_LONG_INDEX_SCALE; + case Float -> compilerToVm.ARRAY_FLOAT_INDEX_SCALE; + case Double -> compilerToVm.ARRAY_DOUBLE_INDEX_SCALE; + case Object -> compilerToVm.ARRAY_OBJECT_INDEX_SCALE; + default -> throw new JVMCIError("%s", kind); + }; } /** @@ -1323,22 +1298,26 @@ static void postTranslation(Object translatedObject) { String value = Option.ForceTranslateFailure.getString(); String toMatch; String type; - if (translatedObject instanceof HotSpotResolvedJavaMethodImpl) { - toMatch = ((HotSpotResolvedJavaMethodImpl) translatedObject).format("%H.%n"); - type = "method"; - } else if (translatedObject instanceof HotSpotResolvedObjectTypeImpl) { - toMatch = ((HotSpotResolvedObjectTypeImpl) translatedObject).toJavaName(); - type = "type"; - } else if (translatedObject instanceof HotSpotNmethod) { - HotSpotNmethod nmethod = (HotSpotNmethod) translatedObject; - if (nmethod.getMethod() != null) { - toMatch = nmethod.getMethod().format("%H.%n"); - } else { - toMatch = String.valueOf(nmethod.getName()); + switch (translatedObject) { + case HotSpotResolvedJavaMethodImpl hotSpotResolvedJavaMethod -> { + toMatch = hotSpotResolvedJavaMethod.format("%H.%n"); + type = "method"; + } + case HotSpotResolvedObjectTypeImpl hotSpotResolvedObjectType -> { + toMatch = hotSpotResolvedObjectType.toJavaName(); + type = "type"; + } + case HotSpotNmethod nmethod -> { + if (nmethod.getMethod() != null) { + toMatch = nmethod.getMethod().format("%H.%n"); + } else { + toMatch = String.valueOf(nmethod.getName()); + } + type = "nmethod"; + } + case null, default -> { + return; } - type = "nmethod"; - } else { - return; } String[] filters = value.split(","); for (String filter : filters) { diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotMemoryAccessProviderImpl.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotMemoryAccessProviderImpl.java index f22749edccca8..ccc6d00915af2 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotMemoryAccessProviderImpl.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotMemoryAccessProviderImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2025, 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 @@ -46,8 +46,7 @@ private static long asRawPointer(Constant base) { if (base instanceof HotSpotMetaspaceConstantImpl) { MetaspaceObject meta = HotSpotMetaspaceConstantImpl.getMetaspaceObject(base); return meta.getMetaspacePointer(); - } else if (base instanceof PrimitiveConstant) { - PrimitiveConstant prim = (PrimitiveConstant) base; + } else if (base instanceof PrimitiveConstant prim) { if (prim.getJavaKind().isNumericInteger()) { return prim.asLong(); } @@ -57,27 +56,17 @@ private static long asRawPointer(Constant base) { @Override public JavaConstant readPrimitiveConstant(JavaKind kind, Constant baseConstant, long initialDisplacement, int bits) { - if (baseConstant instanceof HotSpotObjectConstantImpl) { + if (baseConstant instanceof HotSpotObjectConstantImpl baseObject) { JavaKind readKind = kind; if (kind.getBitCount() != bits) { - switch (bits) { - case Byte.SIZE: - readKind = JavaKind.Byte; - break; - case Short.SIZE: - readKind = JavaKind.Short; - break; - case Integer.SIZE: - readKind = JavaKind.Int; - break; - case Long.SIZE: - readKind = JavaKind.Long; - break; - default: - throw new IllegalArgumentException(String.valueOf(bits)); - } + readKind = switch (bits) { + case Byte.SIZE -> JavaKind.Byte; + case Short.SIZE -> JavaKind.Short; + case Integer.SIZE -> JavaKind.Int; + case Long.SIZE -> JavaKind.Long; + default -> throw new IllegalArgumentException(String.valueOf(bits)); + }; } - HotSpotObjectConstantImpl baseObject = (HotSpotObjectConstantImpl) baseConstant; JavaConstant result = runtime().compilerToVm.readFieldValue(baseObject, null, initialDisplacement, readKind.getTypeChar()); if (result != null && kind != readKind) { return JavaConstant.forPrimitive(kind, result.asLong()); @@ -85,37 +74,25 @@ public JavaConstant readPrimitiveConstant(JavaKind kind, Constant baseConstant, return result; } else { long pointer = asRawPointer(baseConstant); - long value; - switch (bits) { - case Byte.SIZE: - value = UNSAFE.getByte(pointer + initialDisplacement); - break; - case Short.SIZE: - value = UNSAFE.getShort(pointer + initialDisplacement); - break; - case Integer.SIZE: - value = UNSAFE.getInt(pointer + initialDisplacement); - break; - case Long.SIZE: - value = UNSAFE.getLong(pointer + initialDisplacement); - break; - default: - throw new IllegalArgumentException(String.valueOf(bits)); - } + long value = switch (bits) { + case Byte.SIZE -> UNSAFE.getByte(pointer + initialDisplacement); + case Short.SIZE -> UNSAFE.getShort(pointer + initialDisplacement); + case Integer.SIZE -> UNSAFE.getInt(pointer + initialDisplacement); + case Long.SIZE -> UNSAFE.getLong(pointer + initialDisplacement); + default -> throw new IllegalArgumentException(String.valueOf(bits)); + }; return JavaConstant.forPrimitive(kind, value); } } @Override public JavaConstant readObjectConstant(Constant base, long displacement) { - if (base instanceof HotSpotObjectConstantImpl) { - HotSpotObjectConstantImpl hsBase = (HotSpotObjectConstantImpl) base; + if (base instanceof HotSpotObjectConstantImpl hsBase) { return runtime.getCompilerToVM().readFieldValue(hsBase, null, displacement, JavaKind.Object.getTypeChar()); } if (base instanceof HotSpotMetaspaceConstant) { MetaspaceObject metaspaceObject = HotSpotMetaspaceConstantImpl.getMetaspaceObject(base); - if (metaspaceObject instanceof HotSpotResolvedObjectTypeImpl) { - HotSpotResolvedObjectTypeImpl type = (HotSpotResolvedObjectTypeImpl) metaspaceObject; + if (metaspaceObject instanceof HotSpotResolvedObjectTypeImpl type) { if (displacement == runtime.getConfig().javaMirrorOffset) { // Klass::_java_mirror is valid for all Klass* values return type.getJavaMirror(); @@ -130,9 +107,8 @@ public JavaConstant readObjectConstant(Constant base, long displacement) { @Override public JavaConstant readNarrowOopConstant(Constant base, long displacement) { - if (base instanceof HotSpotObjectConstantImpl) { + if (base instanceof HotSpotObjectConstantImpl hsBase) { assert runtime.getConfig().useCompressedOops; - HotSpotObjectConstantImpl hsBase = (HotSpotObjectConstantImpl) base; JavaConstant res = runtime.getCompilerToVM().readFieldValue(hsBase, null, displacement, JavaKind.Object.getTypeChar()); if (res != null) { return JavaConstant.NULL_POINTER.equals(res) ? HotSpotCompressedNullConstant.COMPRESSED_NULL : ((HotSpotObjectConstant) res).compress(); diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotMetaAccessProvider.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotMetaAccessProvider.java index 0bc6fce0ce203..627808f71c746 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotMetaAccessProvider.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotMetaAccessProvider.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2025, 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 @@ -25,6 +25,7 @@ import java.lang.reflect.Executable; import java.lang.reflect.Field; import java.lang.reflect.Modifier; +import java.util.List; import java.util.Objects; import jdk.vm.ci.code.CodeUtil; @@ -87,7 +88,7 @@ public ResolvedJavaField lookupJavaField(Field reflectionField) { HotSpotResolvedJavaType holder = runtime.fromClass(fieldHolder); assert holder != null : fieldHolder; - ResolvedJavaField[] fields; + List fields; if (Modifier.isStatic(reflectionField.getModifiers())) { fields = holder.getStaticFields(); } else { @@ -125,16 +126,14 @@ public JavaConstant encodeDeoptActionAndReason(DeoptimizationAction action, Deop public DeoptimizationReason decodeDeoptReason(JavaConstant constant) { HotSpotVMConfig config = runtime.getConfig(); int reasonValue = ((~constant.asInt()) >> config.deoptimizationReasonShift) & intMaskRight(config.deoptimizationReasonBits); - DeoptimizationReason reason = convertDeoptReason(reasonValue); - return reason; + return convertDeoptReason(reasonValue); } @Override public DeoptimizationAction decodeDeoptAction(JavaConstant constant) { HotSpotVMConfig config = runtime.getConfig(); int actionValue = ((~constant.asInt()) >> config.deoptimizationActionShift) & intMaskRight(config.deoptimizationActionBits); - DeoptimizationAction action = convertDeoptAction(actionValue); - return action; + return convertDeoptAction(actionValue); } @Override @@ -164,20 +163,14 @@ public Speculation decodeSpeculation(JavaConstant constant, SpeculationLog specu public int convertDeoptAction(DeoptimizationAction action) { HotSpotVMConfig config = runtime.getConfig(); - switch (action) { - case None: - return config.deoptActionNone; - case RecompileIfTooManyDeopts: - return config.deoptActionMaybeRecompile; - case InvalidateReprofile: - return config.deoptActionReinterpret; - case InvalidateRecompile: - return config.deoptActionMakeNotEntrant; - case InvalidateStopCompiling: - return config.deoptActionMakeNotCompilable; - default: - throw new JVMCIError("%s", action); - } + return switch (action) { + case None -> config.deoptActionNone; + case RecompileIfTooManyDeopts -> config.deoptActionMaybeRecompile; + case InvalidateReprofile -> config.deoptActionReinterpret; + case InvalidateRecompile -> config.deoptActionMakeNotEntrant; + case InvalidateStopCompiling -> config.deoptActionMakeNotCompilable; + default -> throw new JVMCIError("%s", action); + }; } public DeoptimizationAction convertDeoptAction(int action) { @@ -202,42 +195,25 @@ public DeoptimizationAction convertDeoptAction(int action) { public int convertDeoptReason(DeoptimizationReason reason) { HotSpotVMConfig config = runtime.getConfig(); - switch (reason) { - case None: - return config.deoptReasonNone; - case NullCheckException: - return config.deoptReasonNullCheck; - case BoundsCheckException: - return config.deoptReasonRangeCheck; - case ClassCastException: - return config.deoptReasonClassCheck; - case ArrayStoreException: - return config.deoptReasonArrayCheck; - case UnreachedCode: - return config.deoptReasonUnreached0; - case TypeCheckedInliningViolated: - return config.deoptReasonTypeCheckInlining; - case OptimizedTypeCheckViolated: - return config.deoptReasonOptimizedTypeCheck; - case NotCompiledExceptionHandler: - return config.deoptReasonNotCompiledExceptionHandler; - case Unresolved: - return config.deoptReasonUnresolved; - case JavaSubroutineMismatch: - return config.deoptReasonJsrMismatch; - case ArithmeticException: - return config.deoptReasonDiv0Check; - case RuntimeConstraint: - return config.deoptReasonConstraint; - case LoopLimitCheck: - return config.deoptReasonLoopLimitCheck; - case Aliasing: - return config.deoptReasonAliasing; - case TransferToInterpreter: - return config.deoptReasonTransferToInterpreter; - default: - throw new JVMCIError("%s", reason); - } + return switch (reason) { + case None -> config.deoptReasonNone; + case NullCheckException -> config.deoptReasonNullCheck; + case BoundsCheckException -> config.deoptReasonRangeCheck; + case ClassCastException -> config.deoptReasonClassCheck; + case ArrayStoreException -> config.deoptReasonArrayCheck; + case UnreachedCode -> config.deoptReasonUnreached0; + case TypeCheckedInliningViolated -> config.deoptReasonTypeCheckInlining; + case OptimizedTypeCheckViolated -> config.deoptReasonOptimizedTypeCheck; + case NotCompiledExceptionHandler -> config.deoptReasonNotCompiledExceptionHandler; + case Unresolved -> config.deoptReasonUnresolved; + case JavaSubroutineMismatch -> config.deoptReasonJsrMismatch; + case ArithmeticException -> config.deoptReasonDiv0Check; + case RuntimeConstraint -> config.deoptReasonConstraint; + case LoopLimitCheck -> config.deoptReasonLoopLimitCheck; + case Aliasing -> config.deoptReasonAliasing; + case TransferToInterpreter -> config.deoptReasonTransferToInterpreter; + default -> throw new JVMCIError("%s", reason); + }; } public DeoptimizationReason convertDeoptReason(int reason) { diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotMetaspaceConstantImpl.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotMetaspaceConstantImpl.java index 55d5492c2f8da..ace9c4e314276 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotMetaspaceConstantImpl.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotMetaspaceConstantImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2025, 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 @@ -58,11 +58,10 @@ public boolean equals(Object o) { if (o == this) { return true; } - if (!(o instanceof HotSpotMetaspaceConstantImpl)) { + if (!(o instanceof HotSpotMetaspaceConstantImpl other)) { return false; } - HotSpotMetaspaceConstantImpl other = (HotSpotMetaspaceConstantImpl) o; return Objects.equals(this.metaspaceObject, other.metaspaceObject) && this.compressed == other.compressed; } diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotMethodData.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotMethodData.java index 2478b97a5b240..00ff5ad7dd28f 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotMethodData.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotMethodData.java @@ -29,7 +29,6 @@ import static jdk.vm.ci.hotspot.UnsafeAccess.UNSAFE; import java.util.Arrays; - import jdk.internal.misc.Unsafe; import jdk.vm.ci.meta.DeoptimizationReason; import jdk.vm.ci.meta.JavaMethodProfile; @@ -467,7 +466,6 @@ private RawItemProfile getRawTypeProfile(HotSpotMethodData dat outer: for (int i = 0; i < typeProfileWidth; i++) { HotSpotResolvedObjectTypeImpl receiverKlass = data.readKlass(position, getTypeOffset(i)); if (receiverKlass != null) { - HotSpotResolvedObjectTypeImpl klass = receiverKlass; long count = data.readUnsignedInt(position, getTypeCountOffset(i)); /* * Because of races in the profile collection machinery it's possible for a @@ -475,13 +473,13 @@ private RawItemProfile getRawTypeProfile(HotSpotMethodData dat * rational. */ for (int j = 0; j < entries; j++) { - if (types[j].equals(klass)) { + if (types[j].equals(receiverKlass)) { totalCount += count; counts[j] += count; continue outer; } } - types[entries] = klass; + types[entries] = receiverKlass; totalCount += count; counts[entries] = count; entries++; @@ -822,7 +820,7 @@ protected int getDynamicSize(HotSpotMethodData data, int position) { @Override public StringBuilder appendTo(StringBuilder sb, HotSpotMethodData data, int pos) { - sb.append("unknown profile data with tag: " + tag); + sb.append("unknown profile data with tag: ").append(tag); return sb; } } diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotMethodDataAccessor.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotMethodDataAccessor.java index bde0ea3c5d536..252ad10b080dd 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotMethodDataAccessor.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotMethodDataAccessor.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2025, 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 @@ -88,50 +88,26 @@ TriState getExceptionSeen(HotSpotMethodData data, int position) { return TriState.get((getFlags(data, position) & exceptionsMask) != 0); } - /** - * @param data - * @param position - */ JavaTypeProfile getTypeProfile(HotSpotMethodData data, int position) { return null; } - /** - * @param data - * @param position - */ JavaMethodProfile getMethodProfile(HotSpotMethodData data, int position) { return null; } - /** - * @param data - * @param position - */ double getBranchTakenProbability(HotSpotMethodData data, int position) { return -1; } - /** - * @param data - * @param position - */ double[] getSwitchProbabilities(HotSpotMethodData data, int position) { return null; } - /** - * @param data - * @param position - */ int getExecutionCount(HotSpotMethodData data, int position) { return -1; } - /** - * @param data - * @param position - */ TriState getNullSeen(HotSpotMethodData data, int position) { return TriState.UNKNOWN; } @@ -140,10 +116,6 @@ protected int getFlags(HotSpotMethodData data, int position) { return data.readUnsignedByte(position, config.dataLayoutFlagsOffset); } - /** - * @param data - * @param position - */ protected int getDynamicSize(HotSpotMethodData data, int position) { return 0; } diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotMethodHandleAccessProvider.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotMethodHandleAccessProvider.java index 6211bd5063ae9..f69e2d29f2ce0 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotMethodHandleAccessProvider.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotMethodHandleAccessProvider.java @@ -64,11 +64,10 @@ static final class Internals { * @param fieldName name of the field to be searched * @param fieldType resolved Java type of the field * @return resolved Java field - * @throws NoSuchFieldError + * @throws NoSuchFieldError if no field matches the field name and type */ private static ResolvedJavaField findFieldInClass(ResolvedJavaType declaringType, String fieldName, ResolvedJavaType fieldType) { - ResolvedJavaField[] fields = declaringType.getInstanceFields(false); - for (ResolvedJavaField field : fields) { + for (ResolvedJavaField field : declaringType.getInstanceFields(false)) { if (field.getName().equals(fieldName) && field.getType().equals(fieldType)) { return field; } diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotObjectConstantImpl.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotObjectConstantImpl.java index cf3ac0f994a00..0f70db0708afe 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotObjectConstantImpl.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotObjectConstantImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2025, 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 @@ -165,8 +165,7 @@ public double asDouble() { public boolean equals(Object o) { if (o == this) { return true; - } else if (o instanceof HotSpotObjectConstantImpl) { - HotSpotObjectConstantImpl other = (HotSpotObjectConstantImpl) o; + } else if (o instanceof HotSpotObjectConstantImpl other) { return runtime().reflection.equals(this, other); } return false; diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotProfilingInfoImpl.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotProfilingInfoImpl.java index 3dcdedef28227..94c6aef0bd1fd 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotProfilingInfoImpl.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotProfilingInfoImpl.java @@ -27,7 +27,6 @@ import jdk.vm.ci.meta.DeoptimizationReason; import jdk.vm.ci.meta.JavaMethodProfile; import jdk.vm.ci.meta.JavaTypeProfile; -import jdk.vm.ci.meta.ProfilingInfo; import jdk.vm.ci.meta.TriState; final class HotSpotProfilingInfoImpl implements HotSpotProfilingInfo { @@ -41,8 +40,8 @@ final class HotSpotProfilingInfoImpl implements HotSpotProfilingInfo { private int hintBCI; private HotSpotMethodDataAccessor dataAccessor; - private boolean includeNormal; - private boolean includeOSR; + private final boolean includeNormal; + private final boolean includeOSR; HotSpotProfilingInfoImpl(HotSpotMethodData methodData, HotSpotResolvedJavaMethod method, boolean includeNormal, boolean includeOSR) { this.methodData = methodData; diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotReferenceMap.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotReferenceMap.java index 37fe0c14a3159..1e30db28ddd07 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotReferenceMap.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotReferenceMap.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2025, 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 @@ -38,12 +38,11 @@ public final class HotSpotReferenceMap extends ReferenceMap { final int maxRegisterSize; /** - * - * @param objects This array is now owned by this object and must not be mutated by the caller. + * @param objects This array is now owned by this object and must not be mutated by the caller. * @param derivedBase This array is now owned by this object and must not be mutated by the - * caller. + * caller. * @param sizeInBytes This array is now owned by this object and must not be mutated by the - * caller. + * caller. */ @SuppressFBWarnings(value = "EI_EXPOSE_REP2", justification = "caller transfers ownership of `objects`, `derivedBase` and `sizeInBytes`") public HotSpotReferenceMap(Location[] objects, Location[] derivedBase, int[] sizeInBytes, int maxRegisterSize) { @@ -63,11 +62,10 @@ public boolean equals(Object obj) { if (this == obj) { return true; } - if (obj instanceof HotSpotReferenceMap) { - HotSpotReferenceMap that = (HotSpotReferenceMap) obj; - if (sizeInBytes == that.sizeInBytes && maxRegisterSize == that.maxRegisterSize && Arrays.equals(objects, that.objects) && Arrays.equals(derivedBase, that.derivedBase)) { - return true; - } + if (obj instanceof HotSpotReferenceMap that) { + return sizeInBytes == that.sizeInBytes && maxRegisterSize == that.maxRegisterSize + && Arrays.equals(objects, that.objects) + && Arrays.equals(derivedBase, that.derivedBase); } return false; } diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotResolvedJavaFieldImpl.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotResolvedJavaFieldImpl.java index 6eb4dfb9b0215..f2379e817c09c 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotResolvedJavaFieldImpl.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotResolvedJavaFieldImpl.java @@ -82,8 +82,7 @@ public boolean equals(Object obj) { if (this == obj) { return true; } - if (obj instanceof HotSpotResolvedJavaFieldImpl) { - HotSpotResolvedJavaFieldImpl that = (HotSpotResolvedJavaFieldImpl) obj; + if (obj instanceof HotSpotResolvedJavaFieldImpl that) { if (that.offset != this.offset || that.isStatic() != this.isStatic()) { return false; } else if (this.holder.equals(that.holder)) { @@ -138,9 +137,8 @@ public JavaType getType() { // Pull field into local variable to prevent a race causing // a ClassCastException below JavaType currentType = type; - if (currentType instanceof UnresolvedJavaType) { + if (currentType instanceof UnresolvedJavaType unresolvedType) { // Don't allow unresolved types to hang around forever - UnresolvedJavaType unresolvedType = (UnresolvedJavaType) currentType; JavaType resolved = HotSpotJVMCIRuntime.runtime().lookupType(unresolvedType.getName(), holder, false); if (resolved instanceof ResolvedJavaType) { type = resolved; @@ -236,7 +234,7 @@ public AnnotationData getAnnotationData(ResolvedJavaType annotationType) { if (!hasAnnotations()) { return null; } - return getAnnotationData0(annotationType).get(0); + return getAnnotationData0(annotationType).getFirst(); } @Override diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotResolvedJavaMethod.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotResolvedJavaMethod.java index 0f5c5002e0a2d..be60e8722a708 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotResolvedJavaMethod.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotResolvedJavaMethod.java @@ -82,7 +82,6 @@ public interface HotSpotResolvedJavaMethod extends ResolvedJavaMethod { boolean hasCompiledCode(); /** - * @param level * @return true if the currently installed code was generated at {@code level}. */ boolean hasCompiledCodeAtLevel(int level); diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotSignature.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotSignature.java index 45565295bc9a0..7081d033b82e1 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotSignature.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotSignature.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2025, 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 @@ -45,7 +45,7 @@ public class HotSpotSignature implements Signature { public HotSpotSignature(HotSpotJVMCIRuntime runtime, String signature) { this.runtime = runtime; - if (signature.length() == 0) { + if (signature.isEmpty()) { throw new IllegalArgumentException("Signature cannot be empty"); } this.originalString = signature; @@ -212,8 +212,7 @@ public String toString() { @Override public boolean equals(Object obj) { - if (obj instanceof HotSpotSignature) { - HotSpotSignature other = (HotSpotSignature) obj; + if (obj instanceof HotSpotSignature other) { if (other.originalString.equals(originalString)) { assert other.parameters.equals(parameters); assert other.returnType.equals(returnType); diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotSpeculationEncoding.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotSpeculationEncoding.java index b730e9bfee19c..62a3fb3084627 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotSpeculationEncoding.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotSpeculationEncoding.java @@ -188,7 +188,7 @@ private boolean addNull(Object o, int nullValue) { // Should never happen given that SHA-1 is mandated in a // compliant Java platform implementation. throw new JVMCIError(e); - } catch (CloneNotSupportedException e) { + } catch (CloneNotSupportedException _) { } SHA1 = sha1; SHA1_IS_CLONEABLE = sha1IsCloneable; diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotSpeculationLog.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotSpeculationLog.java index e3d812c2e83d6..d6e19e118e7ae 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotSpeculationLog.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotSpeculationLog.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2025, 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 @@ -332,8 +332,8 @@ public String toString() { String sep = ""; if (failedSpeculations != null) { - for (int i = 0; i < failedSpeculations.length; i++) { - buf.format("%s{len:%d, hash:0x%x}", sep, failedSpeculations[i].length, Arrays.hashCode(failedSpeculations[i])); + for (byte[] failedSpeculation : failedSpeculations) { + buf.format("%s{len:%d, hash:0x%x}", sep, failedSpeculation.length, Arrays.hashCode(failedSpeculation)); sep = ", "; } } diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotVMConfig.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotVMConfig.java index bc2e121fe903d..a077c5dfb7f16 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotVMConfig.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotVMConfig.java @@ -25,10 +25,9 @@ import static jdk.vm.ci.hotspot.HotSpotJVMCIRuntime.runtime; import static jdk.vm.ci.hotspot.UnsafeAccess.UNSAFE; -import jdk.vm.ci.common.JVMCIError; -import jdk.vm.ci.services.Services; import jdk.internal.misc.Unsafe; import jdk.internal.util.Architecture; +import jdk.vm.ci.common.JVMCIError; /** * Used to access native configuration details. @@ -57,10 +56,10 @@ static HotSpotVMConfig config() { */ static String getHostArchitectureName() { Architecture arch = Architecture.current(); - switch (arch) { - case X64: return "amd64"; - default: return arch.name().toLowerCase(); + if (arch == Architecture.X64) { + return "amd64"; } + return arch.name().toLowerCase(); } final boolean useDeferredInitBarriers = getFlag("ReduceInitialCardMarks", Boolean.class); diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotVMConfigStore.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotVMConfigStore.java index c6735cef5f64c..4e981c42ce084 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotVMConfigStore.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotVMConfigStore.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2025, 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 @@ -124,11 +124,10 @@ public VMIntrinsicMethod getIntrinsic(int intrinsicID) { * ] * */ - @SuppressWarnings("try") HotSpotVMConfigStore(CompilerToVM compilerToVm) { this.compilerToVm = compilerToVm; Object[] data; - try (InitTimer t = timer("CompilerToVm readConfiguration")) { + try (InitTimer _ = timer("CompilerToVm readConfiguration")) { data = compilerToVm.readConfiguration(); } if (data.length != 5) { @@ -148,7 +147,7 @@ public VMIntrinsicMethod getIntrinsic(int intrinsicID) { vmIntrinsics = Arrays.asList((VMIntrinsicMethod[]) data[4]); // @formatter:on - try (InitTimer t = timer("HotSpotVMConfigStore fill maps")) { + try (InitTimer _ = timer("HotSpotVMConfigStore fill maps")) { for (VMField vmField : vmFieldsInfo) { vmFields.put(vmField.name, vmField); } diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/IndirectHotSpotObjectConstantImpl.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/IndirectHotSpotObjectConstantImpl.java index 2b8f717840e27..0f96ecf8db103 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/IndirectHotSpotObjectConstantImpl.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/IndirectHotSpotObjectConstantImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2025, 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 @@ -23,7 +23,6 @@ package jdk.vm.ci.hotspot; import static jdk.vm.ci.hotspot.HotSpotJVMCIRuntime.runtime; -import static jdk.vm.ci.hotspot.UnsafeAccess.UNSAFE; import java.io.ByteArrayOutputStream; import java.io.PrintStream; @@ -112,8 +111,7 @@ long getHandle() { private void checkHandle() { if (objectHandle == 0L) { String message; - if (rawAudit instanceof Audit) { - Audit audit = (Audit) rawAudit; + if (rawAudit instanceof Audit audit) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(baos); ps.println("Foreign object reference " + audit.handle + " created in scope '" + audit.scope + "' is no longer valid. Origin: {"); diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/VMIntrinsicMethod.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/VMIntrinsicMethod.java index d43c9dcca72ee..64e6b9d9ee712 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/VMIntrinsicMethod.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/VMIntrinsicMethod.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2025, 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 @@ -84,8 +84,7 @@ public final class VMIntrinsicMethod { @Override public boolean equals(Object obj) { - if (obj instanceof VMIntrinsicMethod) { - VMIntrinsicMethod that = (VMIntrinsicMethod) obj; + if (obj instanceof VMIntrinsicMethod that) { if (that.id == this.id) { assert that.name.equals(this.name) && that.declaringClass.equals(this.declaringClass) && diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/aarch64/AArch64HotSpotJVMCIBackendFactory.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/aarch64/AArch64HotSpotJVMCIBackendFactory.java index 19c161d6bdeac..875a59caea0e3 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/aarch64/AArch64HotSpotJVMCIBackendFactory.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/aarch64/AArch64HotSpotJVMCIBackendFactory.java @@ -22,12 +22,11 @@ */ package jdk.vm.ci.hotspot.aarch64; -import static java.util.Collections.emptyMap; import static jdk.vm.ci.common.InitTimer.timer; +import java.util.Collections; import java.util.EnumSet; import java.util.Map; - import jdk.vm.ci.aarch64.AArch64; import jdk.vm.ci.aarch64.AArch64.CPUFeature; import jdk.vm.ci.code.Architecture; @@ -49,7 +48,7 @@ public class AArch64HotSpotJVMCIBackendFactory implements HotSpotJVMCIBackendFac private static EnumSet computeFeatures(AArch64HotSpotVMConfig config) { // Configure the feature set using the HotSpot flag settings. Map constants = config.getStore().getConstants(); - return HotSpotJVMCIBackendFactory.convertFeatures(CPUFeature.class, constants, config.vmVersionFeatures, emptyMap()); + return HotSpotJVMCIBackendFactory.convertFeatures(CPUFeature.class, constants, config.vmVersionFeatures, Collections.emptyMap()); } private static TargetDescription createTarget(AArch64HotSpotVMConfig config) { diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/aarch64/AArch64HotSpotRegisterConfig.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/aarch64/AArch64HotSpotRegisterConfig.java index 3ca3ea68edf0f..e7259ed2f25bd 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/aarch64/AArch64HotSpotRegisterConfig.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/aarch64/AArch64HotSpotRegisterConfig.java @@ -209,21 +209,12 @@ public CallingConvention getCallingConvention(Type type, JavaType returnType, Ja @Override public List getCallingConventionRegisters(Type type, JavaKind kind) { HotSpotCallingConventionType hotspotType = (HotSpotCallingConventionType) type; - switch (kind) { - case Boolean: - case Byte: - case Short: - case Char: - case Int: - case Long: - case Object: - return hotspotType == HotSpotCallingConventionType.NativeCall ? nativeGeneralParameterRegisters : javaGeneralParameterRegisters; - case Float: - case Double: - return simdParameterRegisters; - default: - throw JVMCIError.shouldNotReachHere(); - } + return switch (kind) { + case Boolean, Byte, Short, Char, Int, Long, Object -> + hotspotType == HotSpotCallingConventionType.NativeCall ? nativeGeneralParameterRegisters : javaGeneralParameterRegisters; + case Float, Double -> simdParameterRegisters; + default -> throw JVMCIError.shouldNotReachHere(); + }; } private int parseStackArg(ValueKind valueKind, AllocatableValue[] locations, int index, int currentStackOffset, HotSpotCallingConventionType type) { @@ -298,24 +289,11 @@ private CallingConvention callingConvention(List generalParameterRegis @Override public Register getReturnRegister(JavaKind kind) { - switch (kind) { - case Boolean: - case Byte: - case Char: - case Short: - case Int: - case Long: - case Object: - return r0; - case Float: - case Double: - return v0; - case Void: - case Illegal: - return null; - default: - throw new UnsupportedOperationException("no return register for type " + kind); - } + return switch (kind) { + case Boolean, Byte, Char, Short, Int, Long, Object -> r0; + case Float, Double -> v0; + case Void, Illegal -> null; + }; } @Override diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/amd64/AMD64HotSpotRegisterConfig.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/amd64/AMD64HotSpotRegisterConfig.java index 3849ac779c48f..e67bff33ff144 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/amd64/AMD64HotSpotRegisterConfig.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/amd64/AMD64HotSpotRegisterConfig.java @@ -92,9 +92,7 @@ public List filterAllocatableRegisters(PlatformKind kind, List ret = List.copyOf(list); - return ret; + return List.copyOf(list); } @Override @@ -201,21 +199,13 @@ public CallingConvention getCallingConvention(Type type, JavaType returnType, Ja @Override public List getCallingConventionRegisters(Type type, JavaKind kind) { HotSpotCallingConventionType hotspotType = (HotSpotCallingConventionType) type; - switch (kind) { - case Boolean: - case Byte: - case Short: - case Char: - case Int: - case Long: - case Object: - return hotspotType == HotSpotCallingConventionType.NativeCall ? nativeGeneralParameterRegisters : javaGeneralParameterRegisters; - case Float: - case Double: - return hotspotType == HotSpotCallingConventionType.NativeCall ? nativeXMMParameterRegisters : javaXMMParameterRegisters; - default: - throw JVMCIError.shouldNotReachHere(); - } + return switch (kind) { + case Boolean, Byte, Short, Char, Int, Long, Object -> + hotspotType == HotSpotCallingConventionType.NativeCall ? nativeGeneralParameterRegisters : javaGeneralParameterRegisters; + case Float, Double -> + hotspotType == HotSpotCallingConventionType.NativeCall ? nativeXMMParameterRegisters : javaXMMParameterRegisters; + default -> throw JVMCIError.shouldNotReachHere(); + }; } /** @@ -226,13 +216,6 @@ public List getCallingConventionRegisters(Type type, JavaKind kind) { * support the Windows calling convention which only ever passes 4 arguments in registers, no * matter their types. * - * @param generalParameterRegisters - * @param xmmParameterRegisters - * @param unified - * @param returnType - * @param parameterTypes - * @param type - * @param valueKindFactory * @return the resulting calling convention */ private CallingConvention callingConvention(List generalParameterRegisters, List xmmParameterRegisters, boolean unified, JavaType returnType, JavaType[] parameterTypes, @@ -287,24 +270,11 @@ private CallingConvention callingConvention(List generalParameterRegis @Override public Register getReturnRegister(JavaKind kind) { - switch (kind) { - case Boolean: - case Byte: - case Char: - case Short: - case Int: - case Long: - case Object: - return rax; - case Float: - case Double: - return xmm0; - case Void: - case Illegal: - return null; - default: - throw new UnsupportedOperationException("no return register for type " + kind); - } + return switch (kind) { + case Boolean, Byte, Char, Short, Int, Long, Object -> rax; + case Float, Double -> xmm0; + case Void, Illegal -> null; + }; } @Override diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/riscv64/RISCV64HotSpotJVMCIBackendFactory.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/riscv64/RISCV64HotSpotJVMCIBackendFactory.java index c0e3112450057..f8a5b59e3398c 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/riscv64/RISCV64HotSpotJVMCIBackendFactory.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/riscv64/RISCV64HotSpotJVMCIBackendFactory.java @@ -22,14 +22,10 @@ */ package jdk.vm.ci.hotspot.riscv64; -import static java.util.Collections.emptyMap; import static jdk.vm.ci.common.InitTimer.timer; import java.util.EnumSet; import java.util.Map; - -import jdk.vm.ci.riscv64.RISCV64; -import jdk.vm.ci.riscv64.RISCV64.CPUFeature; import jdk.vm.ci.code.Architecture; import jdk.vm.ci.code.RegisterConfig; import jdk.vm.ci.code.TargetDescription; @@ -42,6 +38,8 @@ import jdk.vm.ci.hotspot.HotSpotMetaAccessProvider; import jdk.vm.ci.hotspot.HotSpotStackIntrospection; import jdk.vm.ci.meta.ConstantReflectionProvider; +import jdk.vm.ci.riscv64.RISCV64; +import jdk.vm.ci.riscv64.RISCV64.CPUFeature; import jdk.vm.ci.runtime.JVMCIBackend; public class RISCV64HotSpotJVMCIBackendFactory implements HotSpotJVMCIBackendFactory { @@ -49,7 +47,7 @@ public class RISCV64HotSpotJVMCIBackendFactory implements HotSpotJVMCIBackendFac private static EnumSet computeFeatures(RISCV64HotSpotVMConfig config) { // Configure the feature set using the HotSpot flag settings. Map constants = config.getStore().getConstants(); - return HotSpotJVMCIBackendFactory.convertFeatures(CPUFeature.class, constants, config.vmVersionFeatures, emptyMap()); + return HotSpotJVMCIBackendFactory.convertFeatures(CPUFeature.class, constants, config.vmVersionFeatures, Collections.emptyMap()); } private static TargetDescription createTarget(RISCV64HotSpotVMConfig config) { diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/riscv64/RISCV64HotSpotRegisterConfig.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/riscv64/RISCV64HotSpotRegisterConfig.java index 80091d71fe9e8..24385f787a665 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/riscv64/RISCV64HotSpotRegisterConfig.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/riscv64/RISCV64HotSpotRegisterConfig.java @@ -200,21 +200,12 @@ public CallingConvention getCallingConvention(Type type, JavaType returnType, Ja @Override public List getCallingConventionRegisters(Type type, JavaKind kind) { HotSpotCallingConventionType hotspotType = (HotSpotCallingConventionType) type; - switch (kind) { - case Boolean: - case Byte: - case Short: - case Char: - case Int: - case Long: - case Object: - return hotspotType == HotSpotCallingConventionType.NativeCall ? nativeGeneralParameterRegisters : javaGeneralParameterRegisters; - case Float: - case Double: - return fpParameterRegisters; - default: - throw JVMCIError.shouldNotReachHere(); - } + return switch (kind) { + case Boolean, Byte, Short, Char, Int, Long, Object -> + hotspotType == HotSpotCallingConventionType.NativeCall ? nativeGeneralParameterRegisters : javaGeneralParameterRegisters; + case Float, Double -> fpParameterRegisters; + default -> throw JVMCIError.shouldNotReachHere(); + }; } private CallingConvention callingConvention(List generalParameterRegisters, JavaType returnType, JavaType[] parameterTypes, HotSpotCallingConventionType type, @@ -269,24 +260,11 @@ private CallingConvention callingConvention(List generalParameterRegis @Override public Register getReturnRegister(JavaKind kind) { - switch (kind) { - case Boolean: - case Byte: - case Char: - case Short: - case Int: - case Long: - case Object: - return x10; - case Float: - case Double: - return f10; - case Void: - case Illegal: - return null; - default: - throw new UnsupportedOperationException("no return register for type " + kind); - } + return switch (kind) { + case Boolean, Byte, Char, Short, Int, Long, Object -> x10; + case Float, Double -> f10; + case Void, Illegal -> null; + }; } @Override diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/AbstractProfiledItem.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/AbstractProfiledItem.java index 87b8c99f1f650..6c8e9caffd821 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/AbstractProfiledItem.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/AbstractProfiledItem.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2025, 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 @@ -65,9 +65,7 @@ public int compareTo(AbstractProfiledItem o) { public int hashCode() { final int prime = 31; int result = 1; - long temp; - temp = Double.doubleToLongBits(probability); - result = prime * result + (int) (temp ^ (temp >>> 32)); + result = prime * result + Double.hashCode(probability); result = prime * result + item.hashCode(); return result; } diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/AnnotationData.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/AnnotationData.java index 76edb8c83a77e..e85dc66156b0e 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/AnnotationData.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/AnnotationData.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2023, 2025, 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 @@ -146,8 +146,7 @@ public boolean equals(Object obj) { if (this == obj) { return true; } - if (obj instanceof AnnotationData) { - AnnotationData that = (AnnotationData) obj; + if (obj instanceof AnnotationData that) { return this.type.equals(that.type) && this.elements.equals(that.elements); } diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/Assumptions.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/Assumptions.java index ddbd7ba980575..1d15d25d666e3 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/Assumptions.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/Assumptions.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2025, 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 @@ -118,8 +118,7 @@ public int hashCode() { @Override public boolean equals(Object obj) { - if (obj instanceof NoFinalizableSubclass) { - NoFinalizableSubclass other = (NoFinalizableSubclass) obj; + if (obj instanceof NoFinalizableSubclass other) { return other.receiverType.equals(receiverType); } return false; @@ -167,8 +166,7 @@ public int hashCode() { @Override public boolean equals(Object obj) { - if (obj instanceof ConcreteSubtype) { - ConcreteSubtype other = (ConcreteSubtype) obj; + if (obj instanceof ConcreteSubtype other) { return other.context.equals(context) && other.subtype.equals(subtype); } return false; @@ -205,8 +203,7 @@ public int hashCode() { @Override public boolean equals(Object obj) { - if (obj instanceof LeafType) { - LeafType other = (LeafType) obj; + if (obj instanceof LeafType other) { return other.context.equals(context); } return false; @@ -257,8 +254,7 @@ public int hashCode() { @Override public boolean equals(Object obj) { - if (obj instanceof ConcreteMethod) { - ConcreteMethod other = (ConcreteMethod) obj; + if (obj instanceof ConcreteMethod other) { return other.method.equals(method) && other.context.equals(context) && other.impl.equals(impl); } return false; @@ -294,8 +290,7 @@ public int hashCode() { @Override public boolean equals(Object obj) { - if (obj instanceof CallSiteTargetValue) { - CallSiteTargetValue other = (CallSiteTargetValue) obj; + if (obj instanceof CallSiteTargetValue other) { return callSite.equals(other.callSite) && methodHandle.equals(other.methodHandle); } return false; @@ -328,12 +323,8 @@ public boolean equals(Object obj) { if (this == obj) { return true; } - if (obj instanceof Assumptions) { - Assumptions that = (Assumptions) obj; - if (!this.assumptions.equals(that.assumptions)) { - return false; - } - return true; + if (obj instanceof Assumptions that) { + return this.assumptions.equals(that.assumptions); } return false; } @@ -383,7 +374,7 @@ public void record(Assumption assumption) { * Gets a copy of the assumptions recorded in this object as an array. */ public Assumption[] toArray() { - return assumptions.toArray(new Assumption[assumptions.size()]); + return assumptions.toArray(new Assumption[0]); } /** diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/EncodedSpeculationReason.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/EncodedSpeculationReason.java index 4df14bc672bb7..7c1454caf35e0 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/EncodedSpeculationReason.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/EncodedSpeculationReason.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 2025, 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 @@ -20,8 +20,6 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ - - package jdk.vm.ci.meta; import java.util.Arrays; @@ -46,12 +44,8 @@ public EncodedSpeculationReason(int groupId, String groupName, Object[] context) @Override public boolean equals(Object obj) { - if (obj instanceof EncodedSpeculationReason) { - if (obj instanceof EncodedSpeculationReason) { - EncodedSpeculationReason that = (EncodedSpeculationReason) obj; - return this.groupId == that.groupId && Arrays.equals(this.context, that.context); - } - return false; + if (obj instanceof EncodedSpeculationReason that) { + return this.groupId == that.groupId && Arrays.equals(this.context, that.context); } return false; } @@ -74,7 +68,7 @@ public SpeculationLog.SpeculationReasonEncoding encode(Supplier c = o.getClass(); + Class c = o.getClass(); if (c == String.class) { encoding.addString((String) o); } else if (c == Byte.class) { diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/EnumData.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/EnumData.java index 4e8fc3a8ab774..896d8b257d37b 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/EnumData.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/EnumData.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2023, 2025, 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 @@ -64,8 +64,7 @@ public boolean equals(Object obj) { if (this == obj) { return true; } - if (obj instanceof EnumData) { - EnumData that = (EnumData) obj; + if (obj instanceof EnumData that) { return this.type.equals(that.type) && this.name.equals(that.name); } return false; diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/ErrorData.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/ErrorData.java index 72177ddcbbcb4..1a2dad3701bef 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/ErrorData.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/ErrorData.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2023, 2025, 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 @@ -49,8 +49,7 @@ public boolean equals(Object obj) { if (this == obj) { return true; } - if (obj instanceof ErrorData) { - ErrorData that = (ErrorData) obj; + if (obj instanceof ErrorData that) { return this.description.equals(that.description); } return false; diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/ExceptionHandler.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/ExceptionHandler.java index 4beae9daa0545..9402bd41658d7 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/ExceptionHandler.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/ExceptionHandler.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2025, 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 @@ -99,10 +99,9 @@ public JavaType getCatchType() { @Override public boolean equals(Object obj) { - if (!(obj instanceof ExceptionHandler)) { + if (!(obj instanceof ExceptionHandler that)) { return false; } - ExceptionHandler that = (ExceptionHandler) obj; if (this.startBCI != that.startBCI || this.endBCI != that.endBCI || this.handlerBCI != that.handlerBCI || this.catchTypeCPI != that.catchTypeCPI) { return false; } diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/JavaConstant.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/JavaConstant.java index 905296c8c13d6..1fe72df5c72a0 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/JavaConstant.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/JavaConstant.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2025, 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 @@ -204,18 +204,13 @@ static PrimitiveConstant forLong(long i) { * @return a boxed copy of {@code value} */ static PrimitiveConstant forInt(int i) { - switch (i) { - case -1: - return INT_MINUS_1; - case 0: - return INT_0; - case 1: - return INT_1; - case 2: - return INT_2; - default: - return new PrimitiveConstant(JavaKind.Int, i); - } + return switch (i) { + case -1 -> INT_MINUS_1; + case 0 -> INT_0; + case 1 -> INT_1; + case 2 -> INT_2; + default -> new PrimitiveConstant(JavaKind.Int, i); + }; } /** @@ -262,22 +257,15 @@ static PrimitiveConstant forShort(short i) { * Creates a {@link JavaConstant} from a primitive integer of a certain kind. */ static PrimitiveConstant forIntegerKind(JavaKind kind, long i) { - switch (kind) { - case Boolean: - return forBoolean(i != 0); - case Byte: - return forByte((byte) i); - case Short: - return forShort((short) i); - case Char: - return forChar((char) i); - case Int: - return forInt((int) i); - case Long: - return forLong(i); - default: - throw new IllegalArgumentException("not an integer kind: " + kind); - } + return switch (kind) { + case Boolean -> forBoolean(i != 0); + case Byte -> forByte((byte) i); + case Short -> forShort((short) i); + case Char -> forChar((char) i); + case Int -> forInt((int) i); + case Long -> forLong(i); + default -> throw new IllegalArgumentException("not an integer kind: " + kind); + }; } /** @@ -285,20 +273,14 @@ static PrimitiveConstant forIntegerKind(JavaKind kind, long i) { */ static PrimitiveConstant forPrimitiveInt(int bits, long i) { assert bits <= 64; - switch (bits) { - case 1: - return forBoolean(i != 0); - case 8: - return forByte((byte) i); - case 16: - return forShort((short) i); - case 32: - return forInt((int) i); - case 64: - return forLong(i); - default: - throw new IllegalArgumentException("unsupported integer width: " + bits); - } + return switch (bits) { + case 1 -> forBoolean(i != 0); + case 8 -> forByte((byte) i); + case 16 -> forShort((short) i); + case 32 -> forInt((int) i); + case 64 -> forLong(i); + default -> throw new IllegalArgumentException("unsupported integer width: " + bits); + }; } static PrimitiveConstant forPrimitive(char typeChar, long rawValue) { @@ -306,26 +288,17 @@ static PrimitiveConstant forPrimitive(char typeChar, long rawValue) { } static PrimitiveConstant forPrimitive(JavaKind kind, long rawValue) { - switch (kind) { - case Boolean: - return JavaConstant.forBoolean(rawValue != 0); - case Byte: - return JavaConstant.forByte((byte) rawValue); - case Char: - return JavaConstant.forChar((char) rawValue); - case Short: - return JavaConstant.forShort((short) rawValue); - case Int: - return JavaConstant.forInt((int) rawValue); - case Long: - return JavaConstant.forLong(rawValue); - case Float: - return JavaConstant.forFloat(Float.intBitsToFloat((int) rawValue)); - case Double: - return JavaConstant.forDouble(Double.longBitsToDouble(rawValue)); - default: - throw new IllegalArgumentException("Unsupported kind: " + kind); - } + return switch (kind) { + case Boolean -> JavaConstant.forBoolean(rawValue != 0); + case Byte -> JavaConstant.forByte((byte) rawValue); + case Char -> JavaConstant.forChar((char) rawValue); + case Short -> JavaConstant.forShort((short) rawValue); + case Int -> JavaConstant.forInt((int) rawValue); + case Long -> JavaConstant.forLong(rawValue); + case Float -> JavaConstant.forFloat(Float.intBitsToFloat((int) rawValue)); + case Double -> JavaConstant.forDouble(Double.longBitsToDouble(rawValue)); + default -> throw new IllegalArgumentException("Unsupported kind: " + kind); + }; } /** @@ -335,25 +308,17 @@ static PrimitiveConstant forPrimitive(JavaKind kind, long rawValue) { * @return the primitive constant holding the {@code value} */ static PrimitiveConstant forBoxedPrimitive(Object value) { - if (value instanceof Boolean) { - return forBoolean((Boolean) value); - } else if (value instanceof Byte) { - return forByte((Byte) value); - } else if (value instanceof Character) { - return forChar((Character) value); - } else if (value instanceof Short) { - return forShort((Short) value); - } else if (value instanceof Integer) { - return forInt((Integer) value); - } else if (value instanceof Long) { - return forLong((Long) value); - } else if (value instanceof Float) { - return forFloat((Float) value); - } else if (value instanceof Double) { - return forDouble((Double) value); - } else { - return null; - } + return switch (value) { + case Boolean b -> forBoolean(b); + case Byte b -> forByte(b); + case Character c -> forChar(c); + case Short i -> forShort(i); + case Integer i -> forInt(i); + case Long l -> forLong(l); + case Float v -> forFloat(v); + case Double v -> forDouble(v); + case null, default -> null; + }; } static PrimitiveConstant forIllegal() { @@ -364,27 +329,17 @@ static PrimitiveConstant forIllegal() { * Returns a constant with the default value for the given kind. */ static JavaConstant defaultForKind(JavaKind kind) { - switch (kind) { - case Boolean: - return FALSE; - case Byte: - return forByte((byte) 0); - case Char: - return forChar((char) 0); - case Short: - return forShort((short) 0); - case Int: - return INT_0; - case Double: - return DOUBLE_0; - case Float: - return FLOAT_0; - case Long: - return LONG_0; - case Object: - return NULL_POINTER; - default: - throw new IllegalArgumentException(kind.toString()); - } + return switch (kind) { + case Boolean -> FALSE; + case Byte -> forByte((byte) 0); + case Char -> forChar((char) 0); + case Short -> forShort((short) 0); + case Int -> INT_0; + case Double -> DOUBLE_0; + case Float -> FLOAT_0; + case Long -> LONG_0; + case Object -> NULL_POINTER; + default -> throw new IllegalArgumentException(kind.toString()); + }; } } diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/JavaKind.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/JavaKind.java index baa7e295d328c..1e446410f1d3b 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/JavaKind.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/JavaKind.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2025, 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 @@ -190,7 +190,7 @@ public boolean isObject() { * @return the kind */ public static JavaKind fromTypeString(String typeString) { - assert typeString.length() > 0; + assert !typeString.isEmpty(); final char first = typeString.charAt(0); if (first == '[' || first == 'L') { return JavaKind.Object; @@ -220,27 +220,18 @@ public static JavaKind fromWordSize(int wordSizeInBytes) { * @return the kind */ public static JavaKind fromPrimitiveOrVoidTypeChar(char ch) { - switch (ch) { - case 'Z': - return Boolean; - case 'C': - return Char; - case 'F': - return Float; - case 'D': - return Double; - case 'B': - return Byte; - case 'S': - return Short; - case 'I': - return Int; - case 'J': - return Long; - case 'V': - return Void; - } - throw new IllegalArgumentException("unknown primitive or void type character: " + ch); + return switch (ch) { + case 'Z' -> Boolean; + case 'C' -> Char; + case 'F' -> Float; + case 'D' -> Double; + case 'B' -> Byte; + case 'S' -> Short; + case 'I' -> Int; + case 'J' -> Long; + case 'V' -> Void; + default -> throw new IllegalArgumentException("unknown primitive or void type character: " + ch); + }; } /** @@ -328,8 +319,7 @@ public String format(Object value) { if (value == null) { return "null"; } else { - if (value instanceof String) { - String s = (String) value; + if (value instanceof String s) { if (s.length() > 50) { return "String:\"" + s.substring(0, 30) + "...\""; } else { @@ -386,26 +376,17 @@ private static String formatArray(Object array) { * @return the minimum value represented as a {@code long} */ public long getMinValue() { - switch (this) { - case Boolean: - return 0; - case Byte: - return java.lang.Byte.MIN_VALUE; - case Char: - return java.lang.Character.MIN_VALUE; - case Short: - return java.lang.Short.MIN_VALUE; - case Int: - return java.lang.Integer.MIN_VALUE; - case Long: - return java.lang.Long.MIN_VALUE; - case Float: - return java.lang.Float.floatToRawIntBits(java.lang.Float.MIN_VALUE); - case Double: - return java.lang.Double.doubleToRawLongBits(java.lang.Double.MIN_VALUE); - default: - throw new IllegalArgumentException("illegal call to minValue on " + this); - } + return switch (this) { + case Boolean -> 0; + case Byte -> java.lang.Byte.MIN_VALUE; + case Char -> Character.MIN_VALUE; + case Short -> java.lang.Short.MIN_VALUE; + case Int -> Integer.MIN_VALUE; + case Long -> java.lang.Long.MIN_VALUE; + case Float -> java.lang.Float.floatToRawIntBits(java.lang.Float.MIN_VALUE); + case Double -> java.lang.Double.doubleToRawLongBits(java.lang.Double.MIN_VALUE); + default -> throw new IllegalArgumentException("illegal call to minValue on " + this); + }; } /** @@ -414,26 +395,17 @@ public long getMinValue() { * @return the maximum value represented as a {@code long} */ public long getMaxValue() { - switch (this) { - case Boolean: - return 1; - case Byte: - return java.lang.Byte.MAX_VALUE; - case Char: - return java.lang.Character.MAX_VALUE; - case Short: - return java.lang.Short.MAX_VALUE; - case Int: - return java.lang.Integer.MAX_VALUE; - case Long: - return java.lang.Long.MAX_VALUE; - case Float: - return java.lang.Float.floatToRawIntBits(java.lang.Float.MAX_VALUE); - case Double: - return java.lang.Double.doubleToRawLongBits(java.lang.Double.MAX_VALUE); - default: - throw new IllegalArgumentException("illegal call to maxValue on " + this); - } + return switch (this) { + case Boolean -> 1; + case Byte -> java.lang.Byte.MAX_VALUE; + case Char -> Character.MAX_VALUE; + case Short -> java.lang.Short.MAX_VALUE; + case Int -> Integer.MAX_VALUE; + case Long -> java.lang.Long.MAX_VALUE; + case Float -> java.lang.Float.floatToRawIntBits(java.lang.Float.MAX_VALUE); + case Double -> java.lang.Double.doubleToRawLongBits(java.lang.Double.MAX_VALUE); + default -> throw new IllegalArgumentException("illegal call to maxValue on " + this); + }; } /** @@ -455,24 +427,15 @@ public int getByteCount() { * @return the number of bits */ public int getBitCount() { - switch (this) { - case Boolean: - return 1; - case Byte: - return 8; - case Char: - case Short: - return 16; - case Float: - return 32; - case Int: - return 32; - case Double: - return 64; - case Long: - return 64; - default: - throw new IllegalArgumentException("illegal call to getBitCount() on " + this); - } + return switch (this) { + case Boolean -> 1; + case Byte -> 8; + case Char, Short -> 16; + case Float -> 32; + case Int -> 32; + case Double -> 64; + case Long -> 64; + default -> throw new IllegalArgumentException("illegal call to getBitCount() on " + this); + }; } } diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/Local.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/Local.java index c68ce13d81177..d2cec3282498d 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/Local.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/Local.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2025, 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 @@ -72,10 +72,9 @@ public int getSlot() { @Override public boolean equals(Object obj) { - if (!(obj instanceof Local)) { + if (!(obj instanceof Local that)) { return false; } - Local that = (Local) obj; return this.name.equals(that.name) && this.startBci == that.startBci && this.endBci == that.endBci && this.slot == that.slot && this.type.equals(that.type); } diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/PlatformKind.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/PlatformKind.java index 0d01d209a98ce..7c2346400ea2b 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/PlatformKind.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/PlatformKind.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2025, 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 @@ -50,8 +50,7 @@ public boolean equals(Object obj) { if (obj == this) { return true; } - if (obj instanceof EnumKey) { - EnumKey that = (EnumKey) obj; + if (obj instanceof EnumKey that) { return this.e == that.e; } return false; diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/PrimitiveConstant.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/PrimitiveConstant.java index 6a3d576bb27f7..53df93d05b551 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/PrimitiveConstant.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/PrimitiveConstant.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2025, 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 @@ -101,26 +101,17 @@ public double asDouble() { @Override public Object asBoxedPrimitive() { - switch (getJavaKind()) { - case Byte: - return Byte.valueOf((byte) primitive); - case Boolean: - return Boolean.valueOf(asBoolean()); - case Short: - return Short.valueOf((short) primitive); - case Char: - return Character.valueOf((char) primitive); - case Int: - return Integer.valueOf(asInt()); - case Long: - return Long.valueOf(asLong()); - case Float: - return Float.valueOf(asFloat()); - case Double: - return Double.valueOf(asDouble()); - default: - throw new IllegalArgumentException("unexpected kind " + getJavaKind()); - } + return switch (getJavaKind()) { + case Byte -> Byte.valueOf((byte) primitive); + case Boolean -> Boolean.valueOf(asBoolean()); + case Short -> Short.valueOf((short) primitive); + case Char -> Character.valueOf((char) primitive); + case Int -> Integer.valueOf(asInt()); + case Long -> Long.valueOf(asLong()); + case Float -> Float.valueOf(asFloat()); + case Double -> Double.valueOf(asDouble()); + default -> throw new IllegalArgumentException("unexpected kind " + getJavaKind()); + }; } @Override @@ -160,7 +151,7 @@ public void serialize(ByteBuffer buffer) { @Override public int hashCode() { - return (int) (primitive ^ (primitive >>> 32)) * (getJavaKind().ordinal() + 31); + return Long.hashCode(primitive) * (getJavaKind().ordinal() + 31); } @Override @@ -168,10 +159,9 @@ public boolean equals(Object o) { if (o == this) { return true; } - if (!(o instanceof PrimitiveConstant)) { + if (!(o instanceof PrimitiveConstant other)) { return false; } - PrimitiveConstant other = (PrimitiveConstant) o; return this.kind.equals(other.kind) && this.primitive == other.primitive; } diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/ProfilingInfo.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/ProfilingInfo.java index 7eaa8e9667056..91035bb6cb0b7 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/ProfilingInfo.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/ProfilingInfo.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2025, 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 @@ -157,8 +157,8 @@ default String toString(ResolvedJavaMethod method, String sep) { double[] switchProbabilities = getSwitchProbabilities(i); if (switchProbabilities != null) { buf.append(String.format("switchProbabilities@%d:", i)); - for (int j = 0; j < switchProbabilities.length; j++) { - buf.append(String.format(" %.6f", switchProbabilities[j])); + for (double switchProbability : switchProbabilities) { + buf.append(String.format(" %.6f", switchProbability)); } buf.append(sep); } @@ -189,7 +189,7 @@ default String toString(ResolvedJavaMethod method, String sep) { buf.append(String.format(" %s: %d%s", reason.name(), count, sep)); } } - if (buf.length() == 0) { + if (buf.isEmpty()) { return ""; } String s = buf.toString(); diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/SpeculationLog.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/SpeculationLog.java index f860150b25235..828108682c4f9 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/SpeculationLog.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/SpeculationLog.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2025, 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 @@ -114,8 +114,7 @@ public String toString() { @Override public boolean equals(Object obj) { - if (obj instanceof Speculation) { - Speculation other = (Speculation) obj; + if (obj instanceof Speculation other) { return reason.equals(other.reason); } return false; diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/UnresolvedJavaField.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/UnresolvedJavaField.java index d3c874ca26b3a..55e52f2732a99 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/UnresolvedJavaField.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/UnresolvedJavaField.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2025, 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 @@ -79,10 +79,9 @@ public boolean equals(Object obj) { if (this == obj) { return true; } - if (obj == null || !(obj instanceof UnresolvedJavaField)) { + if (!(obj instanceof UnresolvedJavaField that)) { return false; } - UnresolvedJavaField that = (UnresolvedJavaField) obj; return this.holder.equals(that.holder) && this.name.equals(that.name) && this.type.equals(that.type); } diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/UnresolvedJavaMethod.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/UnresolvedJavaMethod.java index 1ec73cc8030da..a5ede69b397b0 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/UnresolvedJavaMethod.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/UnresolvedJavaMethod.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2025, 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 @@ -79,10 +79,9 @@ public boolean equals(Object obj) { if (this == obj) { return true; } - if (obj == null || !(obj instanceof UnresolvedJavaMethod)) { + if (!(obj instanceof UnresolvedJavaMethod that)) { return false; } - UnresolvedJavaMethod that = (UnresolvedJavaMethod) obj; return this.name.equals(that.name) && this.signature.equals(that.signature) && this.holder.equals(that.holder); } } diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/UnresolvedJavaType.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/UnresolvedJavaType.java index 1740744b4b1fd..a540b2a711b06 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/UnresolvedJavaType.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/UnresolvedJavaType.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2025, 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 @@ -93,10 +93,9 @@ public boolean equals(Object obj) { if (this == obj) { return true; } - if (obj == null || !(obj instanceof UnresolvedJavaType)) { + if (!(obj instanceof UnresolvedJavaType that)) { return false; } - UnresolvedJavaType that = (UnresolvedJavaType) obj; return this.getName().equals(that.getName()); } diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/Value.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/Value.java index 81090c2b92e7c..d722c5ec1ff32 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/Value.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/Value.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2025, 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 @@ -90,8 +90,7 @@ public int hashCode() { @Override public boolean equals(Object obj) { - if (obj instanceof Value) { - Value that = (Value) obj; + if (obj instanceof Value that) { return valueKind.equals(that.valueKind); } return false; diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/riscv64/RISCV64.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/riscv64/RISCV64.java index 79491e507fd04..b505721e832d3 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/riscv64/RISCV64.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/riscv64/RISCV64.java @@ -172,25 +172,15 @@ public EnumSet getFeatures() { @Override public PlatformKind getPlatformKind(JavaKind javaKind) { - switch (javaKind) { - case Boolean: - case Byte: - return RISCV64Kind.BYTE; - case Short: - case Char: - return RISCV64Kind.WORD; - case Int: - return RISCV64Kind.DWORD; - case Long: - case Object: - return RISCV64Kind.QWORD; - case Float: - return RISCV64Kind.SINGLE; - case Double: - return RISCV64Kind.DOUBLE; - default: - return null; - } + return switch (javaKind) { + case Boolean, Byte -> RISCV64Kind.BYTE; + case Short, Char -> RISCV64Kind.WORD; + case Int -> RISCV64Kind.DWORD; + case Long, Object -> RISCV64Kind.QWORD; + case Float -> RISCV64Kind.SINGLE; + case Double -> RISCV64Kind.DOUBLE; + default -> null; + }; } @Override diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/riscv64/RISCV64Kind.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/riscv64/RISCV64Kind.java index 6ff4ed5b41aa0..9bdcf7007d741 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/riscv64/RISCV64Kind.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/riscv64/RISCV64Kind.java @@ -74,45 +74,30 @@ public Key getKey() { } public boolean isInteger() { - switch (this) { - case BYTE: - case WORD: - case DWORD: - case QWORD: - return true; - default: - return false; - } + return switch (this) { + case BYTE, WORD, DWORD, QWORD -> true; + default -> false; + }; } public boolean isFP() { - switch (this) { - case SINGLE: - case DOUBLE: - return true; - default: - return false; - } + return switch (this) { + case SINGLE, DOUBLE -> true; + default -> false; + }; } @Override public char getTypeChar() { - switch (this) { - case BYTE: - return 'b'; - case WORD: - return 'w'; - case DWORD: - return 'd'; - case QWORD: - return 'q'; - case SINGLE: - return 'S'; - case DOUBLE: - return 'D'; - default: - return '-'; - } + return switch (this) { + case BYTE -> 'b'; + case WORD -> 'w'; + case DWORD -> 'd'; + case QWORD -> 'q'; + case SINGLE -> 'S'; + case DOUBLE -> 'D'; + default -> '-'; + }; } } diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/services/Services.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/services/Services.java index 22f8eec7d120f..5b37e7f4eb5ee 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/services/Services.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/services/Services.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2025, 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 @@ -23,7 +23,6 @@ package jdk.vm.ci.services; import java.util.HashMap; -import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Set; @@ -31,7 +30,6 @@ import java.util.function.Supplier; import jdk.internal.misc.TerminatingThreadLocal; -import jdk.internal.misc.VM; import jdk.internal.misc.Unsafe; import jdk.internal.util.Architecture; import jdk.internal.util.OperatingSystem; @@ -264,16 +262,16 @@ private static String realOS() { private static String realArch() { Architecture arch = Architecture.current(); - switch (arch) { - case X64: return "x86_64"; - case X86: return "x86"; - case AARCH64: return "aarch64"; - case RISCV64: return "riscv64"; - case ARM: return "arm"; - case S390: return "s390"; - case PPC64: return "ppc64"; - case OTHER: return "other"; - default: throw new InternalError("missing case for " + arch); - } + return switch (arch) { + case X64 -> "x86_64"; + case X86 -> "x86"; + case AARCH64 -> "aarch64"; + case RISCV64 -> "riscv64"; + case ARM -> "arm"; + case S390 -> "s390"; + case PPC64 -> "ppc64"; + case OTHER -> "other"; + default -> throw new InternalError("missing case for " + arch); + }; } } diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/services/SystemProperties.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/services/SystemProperties.java index 2b4f3141e6b29..abf1f8b593d8b 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/services/SystemProperties.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/services/SystemProperties.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2023, 2025, 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 @@ -107,7 +107,7 @@ public Set keySet() { @Override public Collection values() { if (values == null) { - values = entries.values().stream().map(v -> v.getString(unsafe)).collect(Collectors.toUnmodifiableList()); + values = entries.values().stream().map(v -> v.getString(unsafe)).toList(); } return values; } From a9e1a65c0f54ff016f2c14f57d4d11a495445013 Mon Sep 17 00:00:00 2001 From: Yudi Zheng Date: Mon, 16 Jun 2025 14:01:47 +0200 Subject: [PATCH 02/11] Remove JVMCIPermission --- .../hotspot/HotSpotJVMCICompilerConfig.java | 3 -- .../jdk/vm/ci/services/JVMCIPermission.java | 37 ----------------- .../vm/ci/services/JVMCIServiceLocator.java | 27 +------------ .../vm/ci/services/SuppressFBWarnings.java | 40 ------------------- 4 files changed, 1 insertion(+), 106 deletions(-) delete mode 100644 src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/services/JVMCIPermission.java delete mode 100644 src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/services/SuppressFBWarnings.java diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotJVMCICompilerConfig.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotJVMCICompilerConfig.java index 8767531451bbe..f6ea8dfb255c5 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotJVMCICompilerConfig.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotJVMCICompilerConfig.java @@ -32,7 +32,6 @@ import jdk.vm.ci.runtime.JVMCICompiler; import jdk.vm.ci.runtime.JVMCICompilerFactory; import jdk.vm.ci.runtime.JVMCIRuntime; -import jdk.vm.ci.services.JVMCIPermission; import jdk.vm.ci.services.JVMCIServiceLocator; import jdk.vm.ci.services.Services; @@ -99,8 +98,6 @@ public boolean isGCSupported(int gcIdentifier) { * Gets the selected system compiler factory. * * @return the selected system compiler factory - * @throws SecurityException if a security manager is present and it denies - * {@link JVMCIPermission} for any {@link JVMCIServiceLocator} loaded by this method */ static JVMCICompilerFactory getCompilerFactory(HotSpotJVMCIRuntime runtime) { if (compilerFactory == null) { diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/services/JVMCIPermission.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/services/JVMCIPermission.java deleted file mode 100644 index 2548dd78093a1..0000000000000 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/services/JVMCIPermission.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2016, 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 - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package jdk.vm.ci.services; - -import java.security.BasicPermission; - -/** - * This class represents the permission to access JVMCI services. - */ -public class JVMCIPermission extends BasicPermission { - - private static final long serialVersionUID = 6346818963934448226L; - - public JVMCIPermission() { - super("jvmci"); - } -} diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/services/JVMCIServiceLocator.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/services/JVMCIServiceLocator.java index d5ff0bba9b300..3ded6b512549c 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/services/JVMCIServiceLocator.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/services/JVMCIServiceLocator.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2025, 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 @@ -37,28 +37,11 @@ */ public abstract class JVMCIServiceLocator { - private static Void checkPermission() { - @SuppressWarnings("removal") - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - sm.checkPermission(new JVMCIPermission()); - } - return null; - } - - @SuppressWarnings("unused") - private JVMCIServiceLocator(Void ignore) { - } - /** * Creates a capability for accessing JVMCI. Once successfully instantiated, JVMCI opens all its * packages to the module defining the type of this object. - * - * @throws SecurityException if a security manager has been installed and it denies - * {@link JVMCIPermission} */ protected JVMCIServiceLocator() { - this(checkPermission()); Services.openJVMCITo(getClass().getModule()); } @@ -79,16 +62,8 @@ protected JVMCIServiceLocator() { /** * Gets the providers of the service defined by {@code service} by querying the available * {@link JVMCIServiceLocator} providers. - * - * @throws SecurityException if a security manager is present and it denies - * {@link JVMCIPermission} */ public static List getProviders(Class service) { - @SuppressWarnings("removal") - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - sm.checkPermission(new JVMCIPermission()); - } List providers = new ArrayList<>(); for (JVMCIServiceLocator access : locators) { S provider = access.getProvider(service); diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/services/SuppressFBWarnings.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/services/SuppressFBWarnings.java deleted file mode 100644 index 88b6c7bc653e7..0000000000000 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/services/SuppressFBWarnings.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2019, 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 - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package jdk.vm.ci.services; - -/** - * Used to suppress FindBugs warnings. - */ -@interface SuppressFBWarnings { - /** - * The set of FindBugs - * warnings that are to be - * suppressed in annotated element. The value can be a bug category, kind or pattern. - */ - String[] value(); - - /** - * Reason why the warning is suppressed. - */ - String justification(); -} From ba5fd3f0eb91d2f2f1dbfeca30822f32574f5ec9 Mon Sep 17 00:00:00 2001 From: Yudi Zheng Date: Mon, 16 Jun 2025 14:03:45 +0200 Subject: [PATCH 03/11] DirectHotSpotObjectConstantImpl.forObject is always called with compressed being false --- .../ci/hotspot/DirectHotSpotObjectConstantImpl.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/DirectHotSpotObjectConstantImpl.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/DirectHotSpotObjectConstantImpl.java index c241af0348aef..30cdcd715d4c7 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/DirectHotSpotObjectConstantImpl.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/DirectHotSpotObjectConstantImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2025, 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 @@ -26,19 +26,19 @@ final class DirectHotSpotObjectConstantImpl extends HotSpotObjectConstantImpl { - static JavaConstant forObject(Object object, boolean compressed) { + static JavaConstant forObject(Object object) { if (object == null) { - return compressed ? HotSpotCompressedNullConstant.COMPRESSED_NULL : JavaConstant.NULL_POINTER; + return JavaConstant.NULL_POINTER; } else { - return new DirectHotSpotObjectConstantImpl(object, compressed); + return new DirectHotSpotObjectConstantImpl(object, false); } } - static HotSpotObjectConstantImpl forNonNullObject(Object object, boolean compressed) { + static HotSpotObjectConstantImpl forNonNullObject(Object object) { if (object == null) { throw new NullPointerException(); } - return new DirectHotSpotObjectConstantImpl(object, compressed); + return new DirectHotSpotObjectConstantImpl(object, false); } private DirectHotSpotObjectConstantImpl(Object object, boolean compressed) { From 29d5ef9c54dd96f0ed11c5f1e836155785de081b Mon Sep 17 00:00:00 2001 From: Yudi Zheng Date: Mon, 16 Jun 2025 18:29:58 +0200 Subject: [PATCH 04/11] Replace raw arrays with List --- .../classes/jdk/vm/ci/code/DebugInfo.java | 28 +- .../classes/jdk/vm/ci/code/VirtualObject.java | 37 ++- .../vm/ci/hotspot/AnnotationDataDecoder.java | 5 +- .../jdk/vm/ci/hotspot/CompilerToVM.java | 242 +++++++++--------- .../vm/ci/hotspot/HotSpotCompiledCode.java | 12 +- .../ci/hotspot/HotSpotCompiledCodeStream.java | 214 +++++++--------- .../vm/ci/hotspot/HotSpotJDKReflection.java | 48 ++-- .../vm/ci/hotspot/HotSpotJVMCIReflection.java | 6 +- .../jdk/vm/ci/hotspot/HotSpotNmethod.java | 14 +- .../HotSpotResolvedJavaMethodImpl.java | 30 +-- .../ci/hotspot/HotSpotResolvedObjectType.java | 5 +- .../HotSpotResolvedObjectTypeImpl.java | 137 +++++----- .../hotspot/HotSpotResolvedPrimitiveType.java | 28 +- .../hotspot/SharedLibraryJVMCIReflection.java | 28 +- .../jdk/vm/ci/meta/AbstractJavaProfile.java | 34 +-- .../jdk/vm/ci/meta/JavaMethodProfile.java | 8 +- .../jdk/vm/ci/meta/JavaTypeProfile.java | 46 ++-- .../jdk/vm/ci/meta/LocalVariableTable.java | 21 +- .../jdk/vm/ci/meta/MetaAccessProvider.java | 7 +- .../classes/jdk/vm/ci/meta/MetaUtil.java | 23 +- .../jdk/vm/ci/meta/ResolvedJavaMethod.java | 28 +- .../jdk/vm/ci/meta/ResolvedJavaType.java | 33 +-- .../classes/jdk/vm/ci/meta/Signature.java | 12 +- 23 files changed, 493 insertions(+), 553 deletions(-) diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/DebugInfo.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/DebugInfo.java index da5a6a0131307..1d447993c3640 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/DebugInfo.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/DebugInfo.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2025, 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 @@ -22,6 +22,7 @@ */ package jdk.vm.ci.code; +import java.util.List; import java.util.Objects; /** @@ -40,21 +41,19 @@ public final class DebugInfo { private final BytecodePosition bytecodePosition; private ReferenceMap referenceMap; - private final VirtualObject[] virtualObjectMapping; + private final List virtualObjectMapping; private RegisterSaveLayout calleeSaveInfo; /** * Creates a new {@link DebugInfo} from the given values. * - * @param codePos the {@linkplain BytecodePosition code position} or {@linkplain BytecodeFrame - * frame} info - * @param virtualObjectMapping the mapping of {@link VirtualObject}s to their real values. This - * array is now owned by this object and must not be mutated by the caller. + * @param codePos the {@linkplain BytecodePosition code position} or {@linkplain BytecodeFrame + * frame} info + * @param virtualObjectMapping the mapping of {@link VirtualObject}s to their real values. */ - @SuppressFBWarnings(value = "EI_EXPOSE_REP2", justification = "caller transfers ownership of `virtualObjectMapping`") public DebugInfo(BytecodePosition codePos, VirtualObject[] virtualObjectMapping) { this.bytecodePosition = codePos; - this.virtualObjectMapping = virtualObjectMapping; + this.virtualObjectMapping = virtualObjectMapping == null ? List.of() : List.of(virtualObjectMapping); } public DebugInfo(BytecodePosition codePos) { @@ -91,8 +90,8 @@ public String toString() { /** * @return The code position (including all inlined methods) of this debug info. If this is a - * {@link BytecodeFrame} instance, then it is also the deoptimization information for - * each inlined frame. + * {@link BytecodeFrame} instance, then it is also the deoptimization information for + * each inlined frame. */ public BytecodePosition getBytecodePosition() { return bytecodePosition; @@ -102,7 +101,7 @@ public ReferenceMap getReferenceMap() { return referenceMap; } - public VirtualObject[] getVirtualObjectMapping() { + public List getVirtualObjectMapping() { return virtualObjectMapping; } @@ -132,11 +131,8 @@ public boolean equals(Object obj) { if (this == obj) { return true; } - if (obj instanceof DebugInfo) { - DebugInfo that = (DebugInfo) obj; - if (Objects.equals(this.bytecodePosition, that.bytecodePosition) && Objects.equals(this.calleeSaveInfo, that.calleeSaveInfo) && Objects.equals(this.referenceMap, that.referenceMap)) { - return true; - } + if (obj instanceof DebugInfo that) { + return Objects.equals(this.bytecodePosition, that.bytecodePosition) && Objects.equals(this.calleeSaveInfo, that.calleeSaveInfo) && Objects.equals(this.referenceMap, that.referenceMap); } return false; } diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/VirtualObject.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/VirtualObject.java index d26b135a40556..85d314b5df62b 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/VirtualObject.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/VirtualObject.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2025, 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,6 +24,7 @@ import java.util.Collections; import java.util.IdentityHashMap; +import java.util.List; import java.util.Set; import jdk.vm.ci.common.JVMCIError; @@ -43,7 +44,7 @@ public final class VirtualObject implements JavaValue { private JavaValue[] values; private JavaKind[] slotKinds; private final int id; - private boolean isAutoBox; + private final boolean isAutoBox; /** * Creates a new {@link VirtualObject} for the given type, with the given fields. If @@ -89,8 +90,7 @@ private VirtualObject(ResolvedJavaType type, int id, boolean isAutoBox) { } private static StringBuilder appendValue(StringBuilder buf, JavaValue value, Set visited) { - if (value instanceof VirtualObject) { - VirtualObject vo = (VirtualObject) value; + if (value instanceof VirtualObject vo) { buf.append("vobject:").append(vo.type.toJavaName(false)).append(':').append(vo.id); if (!visited.contains(vo)) { visited.add(vo); @@ -107,22 +107,22 @@ private static StringBuilder appendValue(StringBuilder buf, JavaValue value, Set appendValue(buf, vo.values[i], visited); } } else { - ResolvedJavaField[] fields = vo.type.getInstanceFields(true); + List fields = vo.type.getInstanceFields(true); int fieldIndex = 0; for (int i = 0; i < vo.values.length; i++, fieldIndex++) { if (i != 0) { buf.append(','); } - if (fieldIndex >= fields.length) { + if (fieldIndex >= fields.size()) { buf.append(""); } else { - ResolvedJavaField field = fields[fieldIndex]; + ResolvedJavaField field = fields.get(fieldIndex); buf.append(field.getName()); if (vo.slotKinds[i].getSlotCount() == 2 && field.getType().getJavaKind().getSlotCount() == 1) { - if (fieldIndex + 1 >= fields.length) { + if (fieldIndex + 1 >= fields.size()) { buf.append("/"); } else { - ResolvedJavaField field2 = fields[++fieldIndex]; + ResolvedJavaField field2 = fields.get(++fieldIndex); buf.append('/').append(field2.getName()); } } @@ -131,8 +131,8 @@ private static StringBuilder appendValue(StringBuilder buf, JavaValue value, Set appendValue(buf, vo.values[i], visited); } // Extra fields - for (; fieldIndex < fields.length; fieldIndex++) { - buf.append(fields[fieldIndex].getName()).append("="); + for (; fieldIndex < fields.size(); fieldIndex++) { + buf.append(fields.get(fieldIndex).getName()).append("="); } } } @@ -154,14 +154,14 @@ default JavaKind getStorageKind(ResolvedJavaField field) { public void verifyLayout(LayoutVerifier verifier) { if (!type.isArray()) { - ResolvedJavaField[] fields = type.getInstanceFields(true); + List fields = type.getInstanceFields(true); int fieldIndex = 0; for (int i = 0; i < values.length; i++, fieldIndex++) { JavaKind slotKind = slotKinds[i]; - if (fieldIndex >= fields.length) { + if (fieldIndex >= fields.size()) { throw new JVMCIError("Not enough fields for the values provided for %s", toString()); } else { - ResolvedJavaField field = fields[fieldIndex]; + ResolvedJavaField field = fields.get(fieldIndex); JavaKind fieldKind = verifier.getStorageKind(field); if (slotKind.getSlotCount() == 2 && fieldKind == JavaKind.Int) { int offset = verifier.getOffset(field); @@ -169,10 +169,10 @@ public void verifyLayout(LayoutVerifier verifier) { throw new JVMCIError("Double word value stored across two ints must be aligned %s", toString()); } - if (fieldIndex + 1 >= fields.length) { + if (fieldIndex + 1 >= fields.size()) { throw new JVMCIError("Missing second field for double word value stored in two ints %s", toString()); } - ResolvedJavaField field2 = fields[fieldIndex + 1]; + ResolvedJavaField field2 = fields.get(fieldIndex + 1); if (field2.getType().getJavaKind() != JavaKind.Int) { throw new JVMCIError("Second field for double word value stored in two ints must be int but got %s in %s", field2.getType().getJavaKind(), toString()); } @@ -187,7 +187,7 @@ public void verifyLayout(LayoutVerifier verifier) { } } // Extra fields - if (fieldIndex < fields.length) { + if (fieldIndex < fields.size()) { throw new JVMCIError("Not enough values provided for fields in %s", this); } } else if (type.getComponentType().getJavaKind() == JavaKind.Byte) { @@ -289,8 +289,7 @@ public boolean equals(Object o) { if (o == this) { return true; } - if (o instanceof VirtualObject) { - VirtualObject l = (VirtualObject) o; + if (o instanceof VirtualObject l) { if (!l.type.equals(type) || l.values.length != values.length) { return false; } diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/AnnotationDataDecoder.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/AnnotationDataDecoder.java index 9cc33a395fc52..8679280f05da0 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/AnnotationDataDecoder.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/AnnotationDataDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2023, 2025, 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 @@ -63,6 +63,9 @@ public ErrorData newErrorValue(String description) { return new ErrorData(description); } + /** + * Aggregate {@link ResolvedJavaType} inputs in an array as argument to varargs method. + */ static ResolvedJavaType[] asArray(ResolvedJavaType type1, ResolvedJavaType type2, ResolvedJavaType... types) { ResolvedJavaType[] filter = new ResolvedJavaType[2 + types.length]; filter[0] = type1; diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/CompilerToVM.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/CompilerToVM.java index b25f7a092560c..b4fd7d1245722 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/CompilerToVM.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/CompilerToVM.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2025, 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 @@ -20,22 +20,23 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ - package jdk.vm.ci.hotspot; +import static jdk.vm.ci.common.InitTimer.timer; +import static jdk.vm.ci.hotspot.HotSpotJVMCIRuntime.runtime; + import java.lang.reflect.Executable; import java.lang.reflect.Field; - +import java.util.List; +import jdk.internal.access.SharedSecrets; import jdk.internal.misc.Unsafe; import jdk.vm.ci.code.BytecodeFrame; import jdk.vm.ci.code.InstalledCode; import jdk.vm.ci.code.InvalidInstalledCodeException; import jdk.vm.ci.code.stack.InspectedFrameVisitor; import jdk.vm.ci.common.InitTimer; -import static jdk.vm.ci.common.InitTimer.timer; import jdk.vm.ci.common.JVMCIError; import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime.Option; -import static jdk.vm.ci.hotspot.HotSpotJVMCIRuntime.runtime; import jdk.vm.ci.meta.Constant; import jdk.vm.ci.meta.ConstantReflectionProvider; import jdk.vm.ci.meta.JavaConstant; @@ -48,7 +49,7 @@ * Calls from Java into HotSpot. The behavior of all the methods in this class that take a native * pointer as an argument (e.g., {@link #getSymbol(long)}) is undefined if the argument does not * denote a valid native object. - * + *

* Note also that some calls pass a raw VM value to avoid a JNI upcall. For example, * {@link #getBytecode(HotSpotResolvedJavaMethodImpl, long)} needs the raw {@code Method*} value * (stored in {@link HotSpotResolvedJavaMethodImpl#methodHandle}) in the C++ implementation. The @@ -84,9 +85,8 @@ final class CompilerToVM { final int ARRAY_DOUBLE_INDEX_SCALE; final int ARRAY_OBJECT_INDEX_SCALE; - @SuppressWarnings("try") CompilerToVM() { - try (InitTimer t = timer("CompilerToVM.registerNatives")) { + try (InitTimer _ = timer("CompilerToVM.registerNatives")) { registerNatives(); ARRAY_BOOLEAN_BASE_OFFSET = arrayBaseOffset(JavaKind.Boolean.getTypeChar()); ARRAY_BYTE_BASE_OFFSET = arrayBaseOffset(JavaKind.Byte.getTypeChar()); @@ -144,7 +144,7 @@ int getExceptionTableLength(HotSpotResolvedJavaMethodImpl method) { /** * Gets the address of the first entry in {@code method}'s exception handler table. - * + *

* Each entry is a native object described by these fields: * *

    @@ -156,7 +156,7 @@ int getExceptionTableLength(HotSpotResolvedJavaMethodImpl method) { *
* * @return 0 if {@code method} has no exception handlers (i.e. - * {@code getExceptionTableLength(method) == 0}) + * {@code getExceptionTableLength(method) == 0}) */ long getExceptionTableStart(HotSpotResolvedJavaMethodImpl method) { return getExceptionTableStart(method, method.getMethodPointer()); @@ -204,7 +204,7 @@ boolean shouldInlineMethod(HotSpotResolvedJavaMethodImpl method) { * Used to implement {@link ResolvedJavaType#findUniqueConcreteMethod(ResolvedJavaMethod)}. * * @param actualHolderType the best known type of receiver - * @param method the method on which to base the search + * @param method the method on which to base the search * @return the method result or 0 is there is no unique concrete method for {@code method} */ HotSpotResolvedJavaMethodImpl findUniqueConcreteMethod(HotSpotResolvedObjectTypeImpl actualHolderType, HotSpotResolvedJavaMethodImpl method) { @@ -217,7 +217,7 @@ HotSpotResolvedJavaMethodImpl findUniqueConcreteMethod(HotSpotResolvedObjectType * Gets the implementor for the interface class {@code type}. * * @return the implementor if there is a single implementor, {@code null} if there is no - * implementor, or {@code type} itself if there is more than one implementor + * implementor, or {@code type} itself if there is more than one implementor * @throws IllegalArgumentException if type is not an interface type */ HotSpotResolvedObjectTypeImpl getImplementor(HotSpotResolvedObjectTypeImpl type) { @@ -238,10 +238,10 @@ boolean methodIsIgnoredBySecurityStackWalk(HotSpotResolvedJavaMethodImpl method) /** * Converts a name to a type. * - * @param name a well formed Java type in {@linkplain JavaType#getName() internal} format + * @param name a well formed Java type in {@linkplain JavaType#getName() internal} format * @param accessingClass the class loader of this class is used for resolution. Must not be null. - * @param resolve force resolution to a {@link ResolvedJavaType}. If true, this method will - * either return a {@link ResolvedJavaType} or throw an exception + * @param resolve force resolution to a {@link ResolvedJavaType}. If true, this method will + * either return a {@link ResolvedJavaType} or throw an exception * @return the type for {@code name} or {@code null} if resolution failed and {@code resolve == false} * @throws NoClassDefFoundError if {@code resolve == true} and the resolution failed */ @@ -253,8 +253,8 @@ HotSpotResolvedJavaType lookupType(String name, HotSpotResolvedObjectTypeImpl ac * Converts a name to a type. * * @param classLoader the class loader to use for resolution. Must not be {@code null}, - * {@link ClassLoader#getPlatformClassLoader} or {@link ClassLoader#getSystemClassLoader} - * @param name a well formed Java type in {@linkplain JavaType#getName() internal} format + * {@link ClassLoader#getPlatformClassLoader} or {@link ClassLoader#getSystemClassLoader} + * @param name a well formed Java type in {@linkplain JavaType#getName() internal} format * @return the type for {@code name} * @throws NoClassDefFoundError if resolution failed */ @@ -274,16 +274,14 @@ HotSpotResolvedJavaType lookupType(ClassLoader classLoader, String name) throws /** * @param accessingClassLoader ignored if {@code accessingKlassPointer != 0L}. Otherwise, the supported values are: - * 0 - boot class loader - * 1 - {@linkplain ClassLoader#getPlatformClassLoader() platform class loader} - * 2 - {@linkplain ClassLoader#getSystemClassLoader() system class loader} + * 0 - boot class loader + * 1 - {@linkplain ClassLoader#getPlatformClassLoader() platform class loader} + * 2 - {@linkplain ClassLoader#getSystemClassLoader() system class loader} */ private native HotSpotResolvedJavaType lookupType(String name, HotSpotResolvedObjectTypeImpl accessingClass, long accessingKlassPointer, int accessingClassLoader, boolean resolve) throws NoClassDefFoundError; /** * Converts {@code javaClass} to a HotSpotResolvedJavaType. - * - * Must not be called if {@link Services#IS_IN_NATIVE_IMAGE} is {@code true}. */ native HotSpotResolvedJavaType lookupClass(Class javaClass); @@ -291,13 +289,12 @@ HotSpotResolvedJavaType lookupType(ClassLoader classLoader, String name) throws /** * Gets the {@code jobject} value wrapped by {@code peerObject}. - * Must not be called if {@link Services#IS_IN_NATIVE_IMAGE} is {@code false}. */ native long getJObjectValue(HotSpotObjectConstantImpl peerObject); /** * Resolves the entry at index {@code cpi} in {@code constantPool} to an interned String object. - * + *

* The behavior of this method is undefined if {@code cpi} does not denote an * {@code JVM_CONSTANT_String}. */ @@ -310,7 +307,7 @@ JavaConstant getUncachedStringInPool(HotSpotConstantPool constantPool, int cpi) /** * Gets the entry at index {@code cpi} in {@code constantPool}, looking in the * constant pool cache first. - * + *

* The behavior of this method is undefined if {@code cpi} does not denote one of the following * entry types: {@code JVM_CONSTANT_Dynamic}, {@code JVM_CONSTANT_String}, * {@code JVM_CONSTANT_MethodHandle}, {@code JVM_CONSTANT_MethodHandleInError}, @@ -327,8 +324,8 @@ JavaConstant lookupConstantInPool(HotSpotConstantPool constantPool, int cpi, boo /** * Gets the {@code JVM_CONSTANT_NameAndType} index referenced by the {@code rawIndex}. - * The meaning of {@code rawIndex} is dependent on the given {@opcode}. - * + * The meaning of {@code rawIndex} is dependent on the given {@code opcode}. + *

* The behavior of this method is undefined if the class holding the {@code constantPool} * has not yet been rewritten, or {@code rawIndex} is not a valid index for * this class for the given {@code opcode} @@ -342,13 +339,13 @@ int lookupNameAndTypeRefIndexInPool(HotSpotConstantPool constantPool, int rawInd /** * Gets the name of the {@code JVM_CONSTANT_NameAndType} entry in {@code constantPool} * referenced by the {@code which}. - * + *

* The behavior of this method is undefined if the class holding the {@code constantPool} * has not yet been rewritten, or {@code which} is not a valid index for * this class for the given {@code opcode} * - * @param which for INVOKE{VIRTUAL,SPECIAL,STATIC,INTERFACE}, must be {@code cpci}. For all other bytecodes, - * must be {@code rawIndex} + * @param which for INVOKE{VIRTUAL,SPECIAL,STATIC,INTERFACE}, must be {@code cpci}. For all other bytecodes, + * must be {@code rawIndex} */ String lookupNameInPool(HotSpotConstantPool constantPool, int which, int opcode) { return lookupNameInPool(constantPool, constantPool.getConstantPoolPointer(), which, opcode); @@ -359,13 +356,13 @@ String lookupNameInPool(HotSpotConstantPool constantPool, int which, int opcode) /** * Gets the signature of the {@code JVM_CONSTANT_NameAndType} entry in {@code constantPool} * referenced by the {@code which}. - * + *

* The behavior of this method is undefined if the class holding the {@code constantPool} * has not yet been rewritten, or {@code which} is not a valid index for * this class for the given {@code opcode} * - * @param which for INVOKE{VIRTUAL,SPECIAL,STATIC,INTERFACE}, must be {@code cpci}. For all other bytecodes, - * must be {@code rawIndex} + * @param which for INVOKE{VIRTUAL,SPECIAL,STATIC,INTERFACE}, must be {@code cpci}. For all other bytecodes, + * must be {@code rawIndex} */ String lookupSignatureInPool(HotSpotConstantPool constantPool, int which, int opcode) { return lookupSignatureInPool(constantPool, constantPool.getConstantPoolPointer(), which, opcode); @@ -376,14 +373,14 @@ String lookupSignatureInPool(HotSpotConstantPool constantPool, int which, int op /** * Gets the {@code JVM_CONSTANT_Class} index from the entry in {@code constantPool} * referenced by the {@code which}. The meaning of {@code which} is dependent - * on the given {@opcode}. - * + * on the given {@code opcode}. + *

* The behavior of this method is undefined if the class holding the {@code constantPool} * has not yet been rewritten, or {@code which} is not a valid index for * this class for the given {@code opcode} * - * @param which for INVOKE{VIRTUAL,SPECIAL,STATIC,INTERFACE}, must be {@code cpci}. For all other bytecodes, - * must be {@code rawIndex} + * @param which for INVOKE{VIRTUAL,SPECIAL,STATIC,INTERFACE}, must be {@code cpci}. For all other bytecodes, + * must be {@code rawIndex} */ int lookupKlassRefIndexInPool(HotSpotConstantPool constantPool, int which, int opcode) { return lookupKlassRefIndexInPool(constantPool, constantPool.getConstantPoolPointer(), which, opcode); @@ -394,7 +391,7 @@ int lookupKlassRefIndexInPool(HotSpotConstantPool constantPool, int which, int o /** * Looks up a class denoted by the {@code JVM_CONSTANT_Class} entry at index {@code cpi} in * {@code constantPool}. This method does not perform any resolution. - * + *

* The behavior of this method is undefined if {@code cpi} does not denote a * {@code JVM_CONSTANT_Class} entry. * @@ -409,16 +406,16 @@ Object lookupKlassInPool(HotSpotConstantPool constantPool, int cpi) { /** * Looks up a method denoted by the entry at index {@code cpi} in {@code constantPool}. This * method does not perform any resolution. - * + *

* The behavior of this method is undefined if {@code cpi} does not denote an entry representing * a method. * * @param opcode the opcode of the instruction for which the lookup is being performed or - * {@code -1}. If non-negative, then resolution checks specific to the bytecode it - * denotes are performed if the method is already resolved. Should any of these - * checks fail, 0 is returned. + * {@code -1}. If non-negative, then resolution checks specific to the bytecode it + * denotes are performed if the method is already resolved. Should any of these + * checks fail, 0 is returned. * @param caller if non-null, do access checks in the context of {@code caller} calling the - * looked up method + * looked up method * @return the resolved method entry, 0 otherwise */ HotSpotResolvedJavaMethodImpl lookupMethodInPool(HotSpotConstantPool constantPool, int cpi, byte opcode, HotSpotResolvedJavaMethodImpl caller) { @@ -427,11 +424,11 @@ HotSpotResolvedJavaMethodImpl lookupMethodInPool(HotSpotConstantPool constantPoo } private native HotSpotResolvedJavaMethodImpl lookupMethodInPool(HotSpotConstantPool constantPool, - long constantPoolPointer, - int cpi, - byte opcode, - HotSpotResolvedJavaMethodImpl caller, - long callerMethodPointer); + long constantPoolPointer, + int cpi, + byte opcode, + HotSpotResolvedJavaMethodImpl caller, + long callerMethodPointer); /** * Converts the indy index operand of an invokedynamic instruction @@ -450,8 +447,8 @@ int decodeIndyIndexToCPIndex(HotSpotConstantPool constantPool, int encoded_indy_ * Converts the {@code rawIndex} operand of a rewritten getfield/putfield/getstatic/putstatic instruction * to an index directly into {@code constantPool}. * - * @throws IllegalArgumentException if {@code rawIndex} is out of range. * @return {@code JVM_CONSTANT_FieldRef} constant pool entry index for the instruction + * @throws IllegalArgumentException if {@code rawIndex} is out of range. */ int decodeFieldIndexToCPIndex(HotSpotConstantPool constantPool, int rawIndex) { return decodeFieldIndexToCPIndex(constantPool, constantPool.getConstantPoolPointer(), rawIndex); @@ -463,11 +460,11 @@ int decodeFieldIndexToCPIndex(HotSpotConstantPool constantPool, int rawIndex) { * Converts the {@code rawIndex} operand of a rewritten invokestatic/invokespecial/invokeinterface/invokevirtual instruction * to an index directly into {@code constantPool}. * - * @throws IllegalArgumentException if {@code rawIndex} is out of range. * @return {@code JVM_CONSTANT_MethodRef} or {@code JVM_CONSTANT_InterfaceMethodRef} constant pool entry index for the instruction + * @throws IllegalArgumentException if {@code rawIndex} is out of range. */ int decodeMethodIndexToCPIndex(HotSpotConstantPool constantPool, int rawIndex) { - return decodeMethodIndexToCPIndex(constantPool, constantPool.getConstantPoolPointer(), rawIndex); + return decodeMethodIndexToCPIndex(constantPool, constantPool.getConstantPoolPointer(), rawIndex); } private native int decodeMethodIndexToCPIndex(HotSpotConstantPool constantPool, long constantPoolPointer, int rawIndex); @@ -486,7 +483,7 @@ int getNumIndyEntries(HotSpotConstantPool constantPool) { * Resolves the details for invoking the bootstrap method associated with the * {@code CONSTANT_Dynamic_info} or @{code CONSTANT_InvokeDynamic_info} entry at {@code cpi} in * {@code constant pool}. - * + *

* The return value encodes the details in an object array that is described by the pseudo Java * object {@code info} below: * @@ -512,17 +509,17 @@ Object[] resolveBootstrapMethod(HotSpotConstantPool constantPool, int cpi) { /** * Gets the constant pool index of a static argument of a {@code CONSTANT_Dynamic_info} or - * @{code CONSTANT_InvokeDynamic_info} entry. Used when the list of static arguments in the - * {@link BootstrapMethodInvocation} is a {@code List} of the form + * {@code CONSTANT_InvokeDynamic_info} entry. Used when the list of static arguments in the + * {@code BootstrapMethodInvocation} is a {@code List} of the form * {{@code arg_count}, {@code pool_index}}, meaning the arguments are not already resolved and that * the JDK has to lookup the arguments when they are needed. The {@code cpi} corresponds to * {@code pool_index} and the {@code index} has to be smaller than {@code arg_count}. - * + *

* The behavior of this method is undefined if {@code cpi} does not denote an entry representing * a {@code CONSTANT_Dynamic_info} or a @{code CONSTANT_InvokeDynamic_info}, or if the index * is out of bounds. * - * @param cpi the index of a {@code CONSTANT_Dynamic_info} or @{code CONSTANT_InvokeDynamic_info} entry + * @param cpi the index of a {@code CONSTANT_Dynamic_info} or @{code CONSTANT_InvokeDynamic_info} entry * @param index the index of the static argument in the list of static arguments * @return the constant pool index associated with the static argument */ @@ -563,7 +560,7 @@ int isResolvedInvokeHandleInPool(HotSpotConstantPool constantPool, int cpi, int /** * Gets the resolved type denoted by the entry at index {@code cpi} in {@code constantPool}. - * + *

* The behavior of this method is undefined if {@code cpi} does not denote an entry representing * a class. * @@ -588,7 +585,7 @@ HotSpotResolvedObjectTypeImpl resolveTypeInPool(HotSpotConstantPool constantPool * fflags // fieldDescriptor::field_flags() * ] * - * + *

* The behavior of this method is undefined if {@code rawIndex} is invalid. * * @param info an array in which the details of the field are returned @@ -601,7 +598,7 @@ HotSpotResolvedObjectTypeImpl resolveFieldInPool(HotSpotConstantPool constantPoo } private native HotSpotResolvedObjectTypeImpl resolveFieldInPool(HotSpotConstantPool constantPool, long constantPoolPointer, - int rawIndex, HotSpotResolvedJavaMethodImpl method, long methodPointer, byte opcode, int[] info); + int rawIndex, HotSpotResolvedJavaMethodImpl method, long methodPointer, byte opcode, int[] info); /** * Gets the appendix object (if any) associated with the entry identified by {@code which}. @@ -620,15 +617,14 @@ HotSpotObjectConstantImpl lookupAppendixInPool(HotSpotConstantPool constantPool, * Installs the result of a compilation into the code cache. * * @param compiledCode the result of a compilation - * @param code the details of the installed CodeBlob are written to this object - * + * @param code the details of the installed CodeBlob are written to this object * @return the outcome of the installation which will be one of - * {@link HotSpotVMConfig#codeInstallResultOk}, - * {@link HotSpotVMConfig#codeInstallResultCacheFull}, - * {@link HotSpotVMConfig#codeInstallResultCodeTooLarge} or - * {@link HotSpotVMConfig#codeInstallResultDependenciesFailed}. + * {@link HotSpotVMConfig#codeInstallResultOk}, + * {@link HotSpotVMConfig#codeInstallResultCacheFull}, + * {@link HotSpotVMConfig#codeInstallResultCodeTooLarge} or + * {@link HotSpotVMConfig#codeInstallResultDependenciesFailed}. * @throws JVMCIError if there is something wrong with the compiled code or the associated - * metadata. + * metadata. */ int installCode(HotSpotCompiledCode compiledCode, InstalledCode code, long failedSpeculationsAddress, byte[] speculations) { int codeInstallFlags = getInstallCodeFlags(); @@ -646,13 +642,13 @@ int installCode(HotSpotCompiledCode compiledCode, InstalledCode code, long faile } native int installCode0(long compiledCodeBuffer, - long serializationNS, - boolean withTypeInfo, - HotSpotCompiledCode compiledCode, - Object[] objectPool, - InstalledCode code, - long failedSpeculationsAddress, - byte[] speculations); + long serializationNS, + boolean withTypeInfo, + HotSpotCompiledCode compiledCode, + Object[] objectPool, + InstalledCode code, + long failedSpeculationsAddress, + byte[] speculations); native String getInvalidationReasonDescription(int invalidationReason); @@ -700,17 +696,17 @@ native int installCode0(long compiledCodeBuffer, * {@code exactReceiver}. * * @param exactReceiver the exact receiver type - * @param caller the caller or context type used to perform access checks + * @param caller the caller or context type used to perform access checks * @return the link-time resolved method (might be abstract) or {@code null} if it is either a - * signature polymorphic method or can not be linked. + * signature polymorphic method or can not be linked. */ HotSpotResolvedJavaMethodImpl resolveMethod(HotSpotResolvedObjectTypeImpl exactReceiver, HotSpotResolvedJavaMethodImpl method, HotSpotResolvedObjectTypeImpl caller) { return resolveMethod(exactReceiver, exactReceiver.getKlassPointer(), method, method.getMethodPointer(), caller, caller.getKlassPointer()); } private native HotSpotResolvedJavaMethodImpl resolveMethod(HotSpotResolvedObjectTypeImpl exactReceiver, long exactReceiverKlass, - HotSpotResolvedJavaMethodImpl method, long methodPointer, - HotSpotResolvedObjectTypeImpl caller, long callerKlass); + HotSpotResolvedJavaMethodImpl method, long methodPointer, + HotSpotResolvedObjectTypeImpl caller, long callerKlass); /** * Gets the static initializer of {@code type}. @@ -751,7 +747,7 @@ boolean hasFinalizableSubclass(HotSpotResolvedObjectTypeImpl type) { * Gets a textual disassembly of {@code codeBlob}. * * @return a non-zero length string containing a disassembly of {@code codeBlob} or null if - * {@code codeBlob} could not be disassembled for some reason + * {@code codeBlob} could not be disassembled for some reason */ // The HotSpot disassembler seems not to be thread safe so it's better to synchronize its usage synchronized native String disassembleCodeBlob(InstalledCode installedCode); @@ -798,7 +794,7 @@ int getLocalVariableTableLength(HotSpotResolvedJavaMethodImpl method) { /** * Gets the address of the first entry in the local variable table for {@code method}. - * + *

* Each entry is a native object described by these fields: * *

    @@ -912,7 +908,7 @@ boolean hasCompiledCodeForOSR(HotSpotResolvedJavaMethodImpl method, int entryBCI * Materializes all virtual objects within {@code stackFrame} and updates its locals. * * @param invalidate if {@code true}, the compiled method for the stack frame will be - * invalidated + * invalidated */ native void materializeVirtualObjects(HotSpotStackFrameReference stackFrame, boolean invalidate); @@ -922,8 +918,8 @@ boolean hasCompiledCodeForOSR(HotSpotResolvedJavaMethodImpl method, int entryBCI * v-table. * * @throws InternalError if {@code type} is an interface, {@code method} is not defined by an - * interface, {@code type} does not implement the interface defining {@code method} - * or class represented by {@code type} is not initialized + * interface, {@code type} does not implement the interface defining {@code method} + * or class represented by {@code type} is not initialized */ int getVtableIndexForInterfaceMethod(HotSpotResolvedObjectTypeImpl type, HotSpotResolvedJavaMethodImpl method) { return getVtableIndexForInterfaceMethod(type, type.getKlassPointer(), method, method.getMethodPointer()); @@ -940,9 +936,9 @@ int getVtableIndexForInterfaceMethod(HotSpotResolvedObjectTypeImpl type, HotSpot * Writes {@code length} bytes from {@code buffer} to HotSpot's log stream. * * @param buffer if {@code length <= 8}, then the bytes are encoded in this value in native - * endianness order otherwise this is the address of a native memory buffer holding - * the bytes - * @param flush specifies if the log stream should be flushed after writing + * endianness order otherwise this is the address of a native memory buffer holding + * the bytes + * @param flush specifies if the log stream should be flushed after writing */ native void writeDebugOutput(long buffer, int length, boolean flush); @@ -962,7 +958,7 @@ int getVtableIndexForInterfaceMethod(HotSpotResolvedObjectTypeImpl type, HotSpot * and added to {@code displacement}. Any other non-null object type causes an * {@link IllegalArgumentException} to be thrown. * - * @param base an object to read from or null + * @param base an object to read from or null * @param displacement * @return null or the resolved method for this location */ @@ -973,12 +969,12 @@ int getVtableIndexForInterfaceMethod(HotSpotResolvedObjectTypeImpl type, HotSpot * {@link HotSpotConstantPool} wrapping it. * * @param object a {@link HotSpotResolvedJavaMethodImpl} or - * {@link HotSpotResolvedObjectTypeImpl} object + * {@link HotSpotResolvedObjectTypeImpl} object * @return a {@link HotSpotConstantPool} wrapping the {@code ConstantPool*} associated with - * {@code object} - * @throws NullPointerException if {@code object == null} + * {@code object} + * @throws NullPointerException if {@code object == null} * @throws IllegalArgumentException if {@code object} is neither a - * {@link HotSpotResolvedJavaMethodImpl} nor a {@link HotSpotResolvedObjectTypeImpl} + * {@link HotSpotResolvedJavaMethodImpl} nor a {@link HotSpotResolvedObjectTypeImpl} */ HotSpotConstantPool getConstantPool(MetaspaceObject object) { return getConstantPool(object, object.getMetaspacePointer(), object instanceof HotSpotResolvedJavaType); @@ -998,9 +994,9 @@ HotSpotConstantPool getConstantPool(MetaspaceObject object) { * with type {@code Klass*} that are described in the {@link HotSpotVMConfigStore#getFields()}. * Additionally several injected fields in {@link Class} are also handled. * - * @param base an object to read from + * @param base an object to read from * @param displacement - * @param compressed true if the location contains a compressed Klass* + * @param compressed true if the location contains a compressed Klass* * @return null or the resolved method for this location * @throws NullPointerException if {@code base == null} */ @@ -1070,17 +1066,21 @@ HotSpotResolvedObjectTypeImpl getResolvedJavaType(long address) { * * @param name name of a VM option * @return {@code this} if the named VM option doesn't exist, a {@link String} or {@code null} - * if its type is {@code ccstr} or {@code ccstrlist}, a {@link Double} if its type is - * {@code double}, a {@link Boolean} if its type is {@code bool} otherwise a - * {@link Long} + * if its type is {@code ccstr} or {@code ccstrlist}, a {@link Double} if its type is + * {@code double}, a {@link Boolean} if its type is {@code bool} otherwise a + * {@link Long} */ native Object getFlagValue(String name); + static List listFromTrustedArray(Object[] array) { + return SharedSecrets.getJavaUtilCollectionAccess().listFromTrustedArray(array); + } + /** * @see ResolvedJavaType#getInterfaces() */ - HotSpotResolvedObjectTypeImpl[] getInterfaces(HotSpotResolvedObjectTypeImpl klass) { - return getInterfaces(klass, klass.getKlassPointer()); + List getInterfaces(HotSpotResolvedObjectTypeImpl klass) { + return listFromTrustedArray(getInterfaces(klass, klass.getKlassPointer())); } native HotSpotResolvedObjectTypeImpl[] getInterfaces(HotSpotResolvedObjectTypeImpl klass, long klassPointer); @@ -1098,7 +1098,7 @@ HotSpotResolvedJavaType getComponentType(HotSpotResolvedObjectTypeImpl klass) { * Get the array class for the primitive type represented by the {@link JavaKind#getTypeChar()} * value in {@code typeChar} or the non-primitive type represented by {@code nonPrimitiveKlass}. * This can't be done symbolically since hidden classes can't be looked up by name. - * + *

    * Exactly one of {@code primitiveTypeChar} or {@code nonPrimitiveKlass} must be non-zero. * * @param primitiveTypeChar a {@link JavaKind#getTypeChar()} value for a primitive type @@ -1153,8 +1153,8 @@ void ensureLinked(HotSpotResolvedObjectTypeImpl klass) { /** * Gets the {@link ResolvedJavaMethod}s for all the constructors of {@code klass}. */ - ResolvedJavaMethod[] getDeclaredConstructors(HotSpotResolvedObjectTypeImpl klass) { - return getDeclaredConstructors(klass, klass.getKlassPointer()); + List getDeclaredConstructors(HotSpotResolvedObjectTypeImpl klass) { + return listFromTrustedArray(getDeclaredConstructors(klass, klass.getKlassPointer())); } native ResolvedJavaMethod[] getDeclaredConstructors(HotSpotResolvedObjectTypeImpl klass, long klassPointer); @@ -1163,8 +1163,8 @@ ResolvedJavaMethod[] getDeclaredConstructors(HotSpotResolvedObjectTypeImpl klass * Gets the {@link ResolvedJavaMethod}s for all non-overpass and non-initializer * methods of {@code klass}. */ - ResolvedJavaMethod[] getDeclaredMethods(HotSpotResolvedObjectTypeImpl klass) { - return getDeclaredMethods(klass, klass.getKlassPointer()); + List getDeclaredMethods(HotSpotResolvedObjectTypeImpl klass) { + return listFromTrustedArray(getDeclaredMethods(klass, klass.getKlassPointer())); } native ResolvedJavaMethod[] getDeclaredMethods(HotSpotResolvedObjectTypeImpl klass, long klassPointer); @@ -1172,14 +1172,14 @@ ResolvedJavaMethod[] getDeclaredMethods(HotSpotResolvedObjectTypeImpl klass) { /** * Gets the {@link ResolvedJavaMethod}s for all methods of {@code klass}. */ - ResolvedJavaMethod[] getAllMethods(HotSpotResolvedObjectTypeImpl klass) { - return getAllMethods(klass, klass.getKlassPointer()); + List getAllMethods(HotSpotResolvedObjectTypeImpl klass) { + return listFromTrustedArray(getAllMethods(klass, klass.getKlassPointer())); } native ResolvedJavaMethod[] getAllMethods(HotSpotResolvedObjectTypeImpl klass, long klassPointer); - HotSpotResolvedObjectTypeImpl.FieldInfo[] getDeclaredFieldsInfo(HotSpotResolvedObjectTypeImpl klass) { - return getDeclaredFieldsInfo(klass, klass.getKlassPointer()); + List getDeclaredFieldsInfo(HotSpotResolvedObjectTypeImpl klass) { + return listFromTrustedArray(getDeclaredFieldsInfo(klass, klass.getKlassPointer())); } native HotSpotResolvedObjectTypeImpl.FieldInfo[] getDeclaredFieldsInfo(HotSpotResolvedObjectTypeImpl klass, long klassPointer); @@ -1189,7 +1189,7 @@ HotSpotResolvedObjectTypeImpl.FieldInfo[] getDeclaredFieldsInfo(HotSpotResolvedO * performed on the offset and kind of the read being performed. * * @param declaringKlass the type in which the static field is declared - * @param offset the offset of the field in the {@link Class} mirror of {@code declaringKlass} + * @param offset the offset of the field in the {@link Class} mirror of {@code declaringKlass} * @throws IllegalArgumentException if any of the sanity checks fail */ JavaConstant readStaticFieldValue(HotSpotResolvedObjectTypeImpl declaringKlass, long offset, char typeChar) { @@ -1203,9 +1203,9 @@ JavaConstant readStaticFieldValue(HotSpotResolvedObjectTypeImpl declaringKlass, * {@code object} is expected to be a subtype of {@code expectedType}. Extra sanity checking is * performed on the offset and kind of the read being performed. * - * @param object the object from which the field is to be read. If {@code object} is of type - * {@link Class} and {@code offset} is >= the offset of the static field storage in a - * {@link Class} instance, then this operation is a static field read. + * @param object the object from which the field is to be read. If {@code object} is of type + * {@link Class} and {@code offset} is >= the offset of the static field storage in a + * {@link Class} instance, then this operation is a static field read. * @param expectedType the expected type of {@code object} * @throws IllegalArgumentException if any of the sanity checks fail */ @@ -1309,7 +1309,7 @@ Executable asReflectionExecutable(HotSpotResolvedJavaMethodImpl method) { /** * Gets a {@link Field} denoted by {@code holder} and {@code index}. * - * @param holder the class in which the requested field is declared + * @param holder the class in which the requested field is declared * @param fieldIndex the {@code fieldDescriptor::index()} denoting the field */ Field asReflectionField(HotSpotResolvedObjectTypeImpl holder, int fieldIndex) { @@ -1342,7 +1342,7 @@ boolean isTrustedForIntrinsics(HotSpotResolvedObjectTypeImpl klass) { * * @param currentFailures the known failures at {@code failedSpeculationsAddress} * @return the list of failed speculations with each entry being a single speculation in the - * format emitted by {@link HotSpotSpeculationEncoding#toByteArray()} + * format emitted by {@link HotSpotSpeculationEncoding#toByteArray()} */ native byte[][] getFailedSpeculations(long failedSpeculationsAddress, byte[][] currentFailures); @@ -1441,7 +1441,7 @@ void notifyCompilerInliningEvent(int compileId, HotSpotResolvedJavaMethodImpl ca } native void notifyCompilerInliningEvent(int compileId, HotSpotResolvedJavaMethodImpl caller, long callerPointer, - HotSpotResolvedJavaMethodImpl callee, long calleePointer, boolean succeeded, String message, int bci); + HotSpotResolvedJavaMethodImpl callee, long calleePointer, boolean succeeded, String message, int bci); /** * Gets the serialized annotation info for {@code type} by calling @@ -1450,12 +1450,12 @@ native void notifyCompilerInliningEvent(int compileId, HotSpotResolvedJavaMethod byte[] getEncodedClassAnnotationData(HotSpotResolvedObjectTypeImpl type, ResolvedJavaType[] filter) { try (KlassPointers a = new KlassPointers(filter)) { return getEncodedClassAnnotationData(type, type.getKlassPointer(), - a.types, a.types.length, a.buffer()); + a.types, a.types.length, a.buffer()); } } native byte[] getEncodedClassAnnotationData(HotSpotResolvedObjectTypeImpl type, long klassPointer, - Object filter, int filterLength, long filterKlassPointers); + Object filter, int filterLength, long filterKlassPointers); /** * Gets the serialized annotation info for {@code method} by calling @@ -1464,12 +1464,12 @@ native byte[] getEncodedClassAnnotationData(HotSpotResolvedObjectTypeImpl type, byte[] getEncodedExecutableAnnotationData(HotSpotResolvedJavaMethodImpl method, ResolvedJavaType[] filter) { try (KlassPointers a = new KlassPointers(filter)) { return getEncodedExecutableAnnotationData(method, method.getMethodPointer(), - a.types, a.types.length, a.buffer()); + a.types, a.types.length, a.buffer()); } } native byte[] getEncodedExecutableAnnotationData(HotSpotResolvedJavaMethodImpl method, long methodPointer, - Object filter, int filterLength, long filterKlassPointers); + Object filter, int filterLength, long filterKlassPointers); /** * Gets the serialized annotation info for the field denoted by {@code holder} and @@ -1478,12 +1478,12 @@ native byte[] getEncodedExecutableAnnotationData(HotSpotResolvedJavaMethodImpl m byte[] getEncodedFieldAnnotationData(HotSpotResolvedObjectTypeImpl holder, int fieldIndex, ResolvedJavaType[] filter) { try (KlassPointers a = new KlassPointers(filter)) { return getEncodedFieldAnnotationData(holder, holder.getKlassPointer(), fieldIndex, - a.types, a.types.length, a.buffer()); + a.types, a.types.length, a.buffer()); } } native byte[] getEncodedFieldAnnotationData(HotSpotResolvedObjectTypeImpl holder, long klassPointer, int fieldIndex, - Object filterTypes, int filterLength, long filterKlassPointers); + Object filterTypes, int filterLength, long filterKlassPointers); /** * Helper for passing {@Klass*} values to native code. @@ -1501,7 +1501,7 @@ static final class KlassPointers implements AutoCloseable { * Gets the buffer in which to pass the {@Klass*} values to JNI. * * @return a {@Klass*} value if {@code types.length == 1} otherwise the address of a native - * buffer holding an array of {@Klass*} values + * buffer holding an array of {@Klass*} values */ long buffer() { int length = types.length; @@ -1541,7 +1541,7 @@ void getOopMapAt(HotSpotResolvedJavaMethodImpl method, int bci, long[] oopMap) { * If the current thread is a CompilerThread associated with a JVMCI compiler where * newState != CompilerThread::_can_call_java, then _can_call_java is set to newState. * - * @returns false if no change was made, otherwise true + * @return false if no change was made, otherwise true */ native boolean updateCompilerThreadCanCallJava(boolean newState); diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotCompiledCode.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotCompiledCode.java index 6004db48423d2..306b5577f70c6 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotCompiledCode.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotCompiledCode.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2025, 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 @@ -33,6 +33,8 @@ import jdk.vm.ci.meta.ResolvedJavaField; import jdk.vm.ci.meta.ResolvedJavaMethod; +import java.util.List; + /** * A {@link CompiledCode} with additional HotSpot-specific information required for installing the * code in HotSpot's code cache. @@ -117,7 +119,6 @@ public Comment(int pcOffset, String text) { } } - @SuppressFBWarnings(value = "EI_EXPOSE_REP2", justification = "caller transfers ownership of `sites`, `targetCode`, `comments`, `methods`, `dataSection`, `dataSectionPatches` and `assumptions`") public HotSpotCompiledCode(String name, byte[] targetCode, int targetCodeSize, @@ -132,14 +133,14 @@ public HotSpotCompiledCode(String name, int totalFrameSize, StackSlot deoptRescueSlot) { this.name = name; - this.targetCode = targetCode; + this.targetCode = targetCode.clone(); this.targetCodeSize = targetCodeSize; this.sites = sites; this.assumptions = assumptions; this.methods = methods; this.comments = comments; - this.dataSection = dataSection; + this.dataSection = dataSection.clone(); this.dataSectionAlignment = dataSectionAlignment; this.dataSectionPatches = dataSectionPatches; this.isImmutablePIC = isImmutablePIC; @@ -164,8 +165,7 @@ public String toString() { */ private boolean validateFrames() { for (Site site : sites) { - if (site instanceof Infopoint) { - Infopoint info = (Infopoint) site; + if (site instanceof Infopoint info) { if (info.debugInfo != null) { BytecodeFrame frame = info.debugInfo.frame(); assert frame == null || frame.validateFormat(); diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotCompiledCodeStream.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotCompiledCodeStream.java index 2cd5e839ee80e..62a02da9e201c 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotCompiledCodeStream.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotCompiledCodeStream.java @@ -74,6 +74,7 @@ import java.nio.charset.StandardCharsets; import java.util.HashMap; import java.util.IdentityHashMap; +import java.util.List; import java.util.Map; import jdk.internal.misc.Unsafe; @@ -390,9 +391,6 @@ private void beforeWrite(String name, int sizeInBytes) { /** * Emits the name and size in bytes of a data element if type info is enabled. - * - * @param name - * @param sizeInBytes */ private void emitType(String name, int sizeInBytes) { if (withTypeInfo) { @@ -503,8 +501,7 @@ private void writeUTF8(String name, String value) { currentChunkOffset += 4; // body - for (int i = 0; i < utf.length; i++) { - byte b = utf[i]; + for (byte b : utf) { unsafe.putByte(currentChunk + currentChunkOffset, b); currentChunkOffset++; } @@ -704,13 +701,7 @@ private static void hexdump(PrintStream out, long address, byte[] data) { if (col % 2 == 0) { out.print(' '); } - if (pos < data.length) { - byte b = data[pos]; - char ch = (char) ((char) b & 0xff); - out.printf("%02X", (int) ch); - } else { - out.print(" "); - } + out.printf("%02X", (int) (char) ((char) data[pos] & 0xff)); if ((col + 1) % 16 == 0) { out.print(" "); for (int j = pos - 15; j <= pos; ++j) { @@ -738,68 +729,64 @@ private void writeSites(HotSpotCompiledCode code) { Site[] sites = code.sites; for (Site site : sites) { writeInt("site:pcOffset", site.pcOffset); - if (site instanceof Call) { - Call call = (Call) site; - DebugInfo debugInfo = call.debugInfo; - InvokeTarget target = call.target; - if (target instanceof HotSpotForeignCallTarget) { - HotSpotForeignCallTarget foreignCall = (HotSpotForeignCallTarget) target; - writeTag(debugInfo == null ? SITE_FOREIGN_CALL_NO_DEBUG_INFO : SITE_FOREIGN_CALL); - writeLong("target", foreignCall.address); - if (debugInfo != null) { + switch (site) { + case Call call -> { + DebugInfo debugInfo = call.debugInfo; + InvokeTarget target = call.target; + if (target instanceof HotSpotForeignCallTarget foreignCall) { + writeTag(debugInfo == null ? SITE_FOREIGN_CALL_NO_DEBUG_INFO : SITE_FOREIGN_CALL); + writeLong("target", foreignCall.address); + if (debugInfo != null) { + writeDebugInfo(debugInfo, true); + } + } else { + if (debugInfo == null) { + throw error("debug info expected at call %s", call); + } + writeTag(SITE_CALL); + ResolvedJavaMethod method = (ResolvedJavaMethod) target; + writeMethod("target", method); + writeBoolean("direct", call.direct); writeDebugInfo(debugInfo, true); } - } else { + } + case Infopoint info -> { + InfopointReason reason = info.reason; + DebugInfo debugInfo = info.debugInfo; if (debugInfo == null) { - throw error("debug info expected at call %s", call); + throw error("debug info expected at infopoint %s", info); + } + Tag tag = switch (reason) { + case SAFEPOINT -> SITE_SAFEPOINT; + case IMPLICIT_EXCEPTION -> + info instanceof ImplicitExceptionDispatch ? SITE_IMPLICIT_EXCEPTION_DISPATCH : SITE_IMPLICIT_EXCEPTION; + case CALL -> + throw error("only %s objects expected to have CALL reason: %s", Call.class.getName(), info); + default -> SITE_INFOPOINT; + }; + writeTag(tag); + boolean fullInfo = reason == InfopointReason.SAFEPOINT || reason == InfopointReason.IMPLICIT_EXCEPTION; + writeDebugInfo(debugInfo, fullInfo); + if (tag == SITE_IMPLICIT_EXCEPTION_DISPATCH) { + int dispatchOffset = ((ImplicitExceptionDispatch) info).dispatchOffset; + writeInt("dispatchOffset", dispatchOffset); } - writeTag(SITE_CALL); - ResolvedJavaMethod method = (ResolvedJavaMethod) target; - writeMethod("target", method); - writeBoolean("direct", call.direct); - writeDebugInfo(debugInfo, true); + } - } else if (site instanceof Infopoint) { - Infopoint info = (Infopoint) site; - InfopointReason reason = info.reason; - DebugInfo debugInfo = info.debugInfo; - if (debugInfo == null) { - throw error("debug info expected at infopoint %s", info); + case DataPatch patch -> { + writeTag(SITE_DATA_PATCH); + writeDataPatch(patch, code); } - Tag tag; - switch (reason) { - case SAFEPOINT: - tag = SITE_SAFEPOINT; - break; - case IMPLICIT_EXCEPTION: - tag = info instanceof ImplicitExceptionDispatch ? SITE_IMPLICIT_EXCEPTION_DISPATCH : SITE_IMPLICIT_EXCEPTION; - break; - case CALL: - throw error("only %s objects expected to have CALL reason: %s", Call.class.getName(), info); - default: - tag = SITE_INFOPOINT; - break; + case Mark mark -> { + writeTag(SITE_MARK); + writeU1("mark:id", (int) mark.id); } - writeTag(tag); - boolean fullInfo = reason == InfopointReason.SAFEPOINT || reason == InfopointReason.IMPLICIT_EXCEPTION; - writeDebugInfo(debugInfo, fullInfo); - if (tag == SITE_IMPLICIT_EXCEPTION_DISPATCH) { - int dispatchOffset = ((ImplicitExceptionDispatch) info).dispatchOffset; - writeInt("dispatchOffset", dispatchOffset); + case ExceptionHandler handler -> { + writeTag(SITE_EXCEPTION_HANDLER); + writeInt("site:handlerPos", handler.handlerPos); + } + default -> { } - - } else if (site instanceof DataPatch) { - writeTag(SITE_DATA_PATCH); - DataPatch patch = (DataPatch) site; - writeDataPatch(patch, code); - } else if (site instanceof Mark) { - Mark mark = (Mark) site; - writeTag(SITE_MARK); - writeU1("mark:id", (int) mark.id); - } else if (site instanceof ExceptionHandler) { - ExceptionHandler handler = (ExceptionHandler) site; - writeTag(SITE_EXCEPTION_HANDLER); - writeInt("site:handlerPos", handler.handlerPos); } } } @@ -808,11 +795,10 @@ private void writeDataSectionPatches(DataPatch[] dataSectionPatches) { writeU2("dataSectionPatches:length", dataSectionPatches.length); for (DataPatch dp : dataSectionPatches) { Reference ref = dp.reference; - if (!(ref instanceof ConstantReference)) { + if (!(ref instanceof ConstantReference cref)) { throw error("invalid patch in data section: %s", dp); } writeInt("patch:pcOffset", dp.pcOffset); - ConstantReference cref = (ConstantReference) ref; VMConstant con = cref.getConstant(); if (con instanceof HotSpotMetaspaceConstantImpl) { writeMetaspaceConstantPatch((HotSpotMetaspaceConstantImpl) con); @@ -827,8 +813,7 @@ private void writeDataSectionPatches(DataPatch[] dataSectionPatches) { private void writeDataPatch(DataPatch patch, HotSpotCompiledCode code) { Reference ref = patch.reference; - if (ref instanceof ConstantReference) { - ConstantReference cref = (ConstantReference) ref; + if (ref instanceof ConstantReference cref) { VMConstant con = cref.getConstant(); if (con instanceof HotSpotObjectConstantImpl) { writeOopConstantPatch((HotSpotObjectConstantImpl) con); @@ -837,8 +822,7 @@ private void writeDataPatch(DataPatch patch, HotSpotCompiledCode code) { } else { throw error("unexpected constant patch: %s", con); } - } else if (ref instanceof DataSectionReference) { - DataSectionReference dsref = (DataSectionReference) ref; + } else if (ref instanceof DataSectionReference dsref) { int dataOffset = dsref.getOffset(); if (dataOffset < 0 || dataOffset >= code.dataSection.length) { throw error("data offset 0x%X points outside data section (size 0x%X)", dataOffset, code.dataSection.length); @@ -851,11 +835,10 @@ private void writeDataPatch(DataPatch patch, HotSpotCompiledCode code) { } private void writeOopConstantPatch(HotSpotObjectConstantImpl con) { - if (con instanceof DirectHotSpotObjectConstantImpl) { + if (con instanceof DirectHotSpotObjectConstantImpl obj) { if (Services.IS_IN_NATIVE_IMAGE) { throw error("Direct object constant reached the backend: %s", con); } - DirectHotSpotObjectConstantImpl obj = (DirectHotSpotObjectConstantImpl) con; if (!obj.isCompressed()) { writeObjectID(obj, PATCH_OBJECT_ID, PATCH_OBJECT_ID2); } else { @@ -909,10 +892,9 @@ private void writeStubCounts(HotSpotCompiledCode code) { int numStaticCallStubs = 0; int numTrampolineStubs = 0; for (Site site : code.sites) { - if (site instanceof Mark) { - Mark mark = (Mark) site; + if (site instanceof Mark mark) { if (!(mark.id instanceof Integer)) { - error("Mark id must be Integer, not %s", mark.id.getClass().getName()); + throw error("Mark id must be Integer, not %s", mark.id.getClass().getName()); } int id = (Integer) mark.id; if (id == MARK_INVOKEINTERFACE || id == MARK_INVOKEVIRTUAL) { @@ -930,29 +912,31 @@ private void writeStubCounts(HotSpotCompiledCode code) { private void writeAssumptions(Assumption[] assumptions) { writeU2("assumptions:length", assumptions.length); for (Assumption a : assumptions) { - if (a instanceof NoFinalizableSubclass) { - writeTag(NO_FINALIZABLE_SUBCLASS); - writeObjectType("receiverType", ((NoFinalizableSubclass) a).receiverType); - } else if (a instanceof ConcreteSubtype) { - writeTag(CONCRETE_SUBTYPE); - ConcreteSubtype cs = (ConcreteSubtype) a; - writeObjectType("context", cs.context); - writeObjectType("subtype", cs.subtype); - } else if (a instanceof LeafType) { - writeTag(LEAF_TYPE); - writeObjectType("context", ((LeafType) a).context); - } else if (a instanceof ConcreteMethod) { - writeTag(CONCRETE_METHOD); - ConcreteMethod cm = (ConcreteMethod) a; - writeObjectType("context", cm.context); - writeMethod("impl", cm.impl); - } else if (a instanceof CallSiteTargetValue) { - writeTag(CALLSITE_TARGET_VALUE); - CallSiteTargetValue cs = (CallSiteTargetValue) a; - writeJavaValue(cs.callSite, JavaKind.Object); - writeJavaValue(cs.methodHandle, JavaKind.Object); - } else { - throw error("unexpected assumption %s", a); + switch (a) { + case NoFinalizableSubclass noFinalizableSubclass -> { + writeTag(NO_FINALIZABLE_SUBCLASS); + writeObjectType("receiverType", noFinalizableSubclass.receiverType); + } + case ConcreteSubtype cs -> { + writeTag(CONCRETE_SUBTYPE); + writeObjectType("context", cs.context); + writeObjectType("subtype", cs.subtype); + } + case LeafType leafType -> { + writeTag(LEAF_TYPE); + writeObjectType("context", leafType.context); + } + case ConcreteMethod cm -> { + writeTag(CONCRETE_METHOD); + writeObjectType("context", cm.context); + writeMethod("impl", cm.impl); + } + case CallSiteTargetValue cs -> { + writeTag(CALLSITE_TARGET_VALUE); + writeJavaValue(cs.callSite, JavaKind.Object); + writeJavaValue(cs.methodHandle, JavaKind.Object); + } + case null, default -> throw error("unexpected assumption %s", a); } } } @@ -989,16 +973,18 @@ private void writeDebugInfo(DebugInfo debugInfo, boolean fullInfo) { } } - private void writeVirtualObjects(VirtualObject[] virtualObjects) { - int length = virtualObjects != null ? virtualObjects.length : 0; + private void writeVirtualObjects(List virtualObjects) { + if (virtualObjects == null) { + return; + } + int length = virtualObjects.size(); writeU2("virtualObjects:length", length); - for (int i = 0; i < length; i++) { - VirtualObject vo = virtualObjects[i]; + for (VirtualObject vo : virtualObjects) { writeObjectType("type", vo.getType()); writeBoolean("isAutoBox", vo.isAutoBox()); } for (int i = 0; i < length; i++) { - VirtualObject vo = virtualObjects[i]; + VirtualObject vo = virtualObjects.get(i); int id = vo.getId(); if (id != i) { throw error("duplicate virtual object id %d", id); @@ -1059,8 +1045,7 @@ private void writeJavaValue(JavaValue value, JavaKind kind) { throw error("object constant (%s) kind expected to be Object, got %s", value, kind); } writeTag(NULL_CONSTANT); - } else if (value instanceof RegisterValue) { - RegisterValue reg = (RegisterValue) value; + } else if (value instanceof RegisterValue reg) { Tag tag; if (kind == JavaKind.Object) { if (isVector(reg)) { @@ -1073,8 +1058,7 @@ private void writeJavaValue(JavaValue value, JavaKind kind) { } writeTag(tag); writeRegister(reg.getRegister()); - } else if (value instanceof StackSlot) { - StackSlot slot = (StackSlot) value; + } else if (value instanceof StackSlot slot) { Tag tag; int offset = slot.getRawOffset(); boolean s2 = isS2(offset); @@ -1096,8 +1080,7 @@ private void writeJavaValue(JavaValue value, JavaKind kind) { writeInt("offset4", slot.getRawOffset()); } writeBoolean("addRawFrameSize", slot.getRawAddFrameSize()); - } else if (value instanceof VirtualObject) { - VirtualObject vo = (VirtualObject) value; + } else if (value instanceof VirtualObject vo) { if (kind != JavaKind.Object) { throw error("virtual object kind must be Object, not %s", kind); } @@ -1109,12 +1092,10 @@ private void writeJavaValue(JavaValue value, JavaKind kind) { writeTag(VIRTUAL_OBJECT_ID2); writeU2("id:2", id); } - } else if (value instanceof RawConstant) { - RawConstant prim = (RawConstant) value; + } else if (value instanceof RawConstant prim) { writeTag(RAW_CONSTANT); writeLong("primitive", prim.getRawValue()); - } else if (value instanceof PrimitiveConstant) { - PrimitiveConstant prim = (PrimitiveConstant) value; + } else if (value instanceof PrimitiveConstant prim) { if (prim.getJavaKind() != kind) { throw error("primitive constant (%s) kind expected to be %s, got %s", prim, kind, prim.getJavaKind()); } @@ -1129,11 +1110,10 @@ private void writeJavaValue(JavaValue value, JavaKind kind) { writeTag(PRIMITIVE8); writeLong("primitive8", raw); } - } else if (value instanceof IndirectHotSpotObjectConstantImpl) { + } else if (value instanceof IndirectHotSpotObjectConstantImpl obj) { if (JavaKind.Object != kind) { throw error("object constant (%s) kind expected to be Object, got %s", value, kind); } - IndirectHotSpotObjectConstantImpl obj = (IndirectHotSpotObjectConstantImpl) value; writeTag(JOBJECT); writeLong("jobject", obj.getHandle()); } else if (value instanceof DirectHotSpotObjectConstantImpl) { diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotJDKReflection.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotJDKReflection.java index 6ee925cd3a7b0..e6ba9ff0452b8 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotJDKReflection.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotJDKReflection.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2025, 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 @@ -23,6 +23,7 @@ package jdk.vm.ci.hotspot; import static jdk.vm.ci.hotspot.CompilerToVM.compilerToVM; +import static jdk.vm.ci.hotspot.CompilerToVM.listFromTrustedArray; import static jdk.vm.ci.hotspot.HotSpotJVMCIRuntime.runtime; import java.lang.annotation.Annotation; @@ -32,7 +33,7 @@ import java.lang.reflect.Method; import java.lang.reflect.Type; import java.util.HashMap; - +import java.util.List; import jdk.vm.ci.common.JVMCIError; import jdk.vm.ci.meta.JavaConstant; import jdk.vm.ci.meta.JavaKind; @@ -109,7 +110,7 @@ boolean equals(HotSpotObjectConstantImpl a, HotSpotObjectConstantImpl b) { } @Override - ResolvedJavaMethod.Parameter[] getParameters(HotSpotResolvedJavaMethodImpl javaMethod) { + List getParameters(HotSpotResolvedJavaMethodImpl javaMethod) { java.lang.reflect.Parameter[] javaParameters = getMethod(javaMethod).getParameters(); ResolvedJavaMethod.Parameter[] res = new ResolvedJavaMethod.Parameter[javaParameters.length]; for (int i = 0; i < res.length; i++) { @@ -117,7 +118,7 @@ ResolvedJavaMethod.Parameter[] getParameters(HotSpotResolvedJavaMethodImpl javaM String paramName = src.isNamePresent() ? src.getName() : null; res[i] = new ResolvedJavaMethod.Parameter(paramName, src.getModifiers(), javaMethod, i); } - return res; + return listFromTrustedArray(res); } @Override @@ -126,8 +127,8 @@ Annotation[][] getParameterAnnotations(HotSpotResolvedJavaMethodImpl javaMethod) } @Override - Type[] getGenericParameterTypes(HotSpotResolvedJavaMethodImpl javaMethod) { - return getMethod(javaMethod).getGenericParameterTypes(); + List getGenericParameterTypes(HotSpotResolvedJavaMethodImpl javaMethod) { + return listFromTrustedArray(getMethod(javaMethod).getGenericParameterTypes()); } @Override @@ -179,8 +180,7 @@ String asString(HotSpotObjectConstantImpl object) { @Override ResolvedJavaType asJavaType(HotSpotObjectConstantImpl object) { Object value = resolveObject(object); - if (value instanceof Class) { - Class javaClass = (Class) value; + if (value instanceof Class javaClass) { return runtime().fromClass(javaClass); } if (value instanceof ResolvedJavaType) { @@ -232,25 +232,17 @@ JavaConstant readArrayElement(HotSpotObjectConstantImpl arrayObject, int index) Object element = ((Object[]) a)[index]; return forObject(element); } else { - if (a instanceof int[]) { - return JavaConstant.forInt(((int[]) a)[index]); - } else if (a instanceof char[]) { - return JavaConstant.forChar(((char[]) a)[index]); - } else if (a instanceof byte[]) { - return JavaConstant.forByte(((byte[]) a)[index]); - } else if (a instanceof long[]) { - return JavaConstant.forLong(((long[]) a)[index]); - } else if (a instanceof short[]) { - return JavaConstant.forShort(((short[]) a)[index]); - } else if (a instanceof float[]) { - return JavaConstant.forFloat(((float[]) a)[index]); - } else if (a instanceof double[]) { - return JavaConstant.forDouble(((double[]) a)[index]); - } else if (a instanceof boolean[]) { - return JavaConstant.forBoolean(((boolean[]) a)[index]); - } else { - throw new JVMCIError("Should not reach here"); - } + return switch (a) { + case int[] ints -> JavaConstant.forInt(ints[index]); + case char[] chars -> JavaConstant.forChar(chars[index]); + case byte[] bytes -> JavaConstant.forByte(bytes[index]); + case long[] longs -> JavaConstant.forLong(longs[index]); + case short[] shorts -> JavaConstant.forShort(shorts[index]); + case float[] floats -> JavaConstant.forFloat(floats[index]); + case double[] doubles -> JavaConstant.forDouble(doubles[index]); + case boolean[] booleans -> JavaConstant.forBoolean(booleans[index]); + default -> throw new JVMCIError("Should not reach here"); + }; } } @@ -268,7 +260,7 @@ JavaConstant forObject(Object value) { } private static HotSpotObjectConstantImpl forNonNullObject(Object value) { - return DirectHotSpotObjectConstantImpl.forNonNullObject(value, false); + return DirectHotSpotObjectConstantImpl.forNonNullObject(value); } @Override diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotJVMCIReflection.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotJVMCIReflection.java index 3211e0ab40917..da4e07ed0aa59 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotJVMCIReflection.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotJVMCIReflection.java @@ -24,7 +24,7 @@ import java.lang.annotation.Annotation; import java.lang.reflect.Type; - +import java.util.List; import jdk.vm.ci.meta.JavaConstant; import jdk.vm.ci.meta.ResolvedJavaMethod; import jdk.vm.ci.meta.ResolvedJavaType; @@ -52,11 +52,11 @@ abstract class HotSpotJVMCIReflection { abstract boolean equals(HotSpotObjectConstantImpl hotSpotResolvedJavaType, HotSpotObjectConstantImpl that); - abstract ResolvedJavaMethod.Parameter[] getParameters(HotSpotResolvedJavaMethodImpl javaMethod); + abstract List getParameters(HotSpotResolvedJavaMethodImpl javaMethod); abstract Annotation[][] getParameterAnnotations(HotSpotResolvedJavaMethodImpl javaMethod); - abstract Type[] getGenericParameterTypes(HotSpotResolvedJavaMethodImpl javaMethod); + abstract List getGenericParameterTypes(HotSpotResolvedJavaMethodImpl javaMethod); abstract Annotation[] getFieldAnnotations(HotSpotResolvedJavaFieldImpl javaMethod); diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotNmethod.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotNmethod.java index 5c7089da6cb69..5c816b656420b 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotNmethod.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotNmethod.java @@ -25,6 +25,7 @@ import static jdk.vm.ci.hotspot.CompilerToVM.compilerToVM; import static jdk.vm.ci.services.Services.IS_IN_NATIVE_IMAGE; +import java.util.List; import jdk.vm.ci.code.InstalledCode; import jdk.vm.ci.code.InvalidInstalledCodeException; import jdk.vm.ci.common.JVMCIError; @@ -168,14 +169,15 @@ public String toString() { } private boolean checkArgs(Object... args) { - JavaType[] sig = method.toParameterTypes(); - assert args.length == sig.length : method.format("%H.%n(%p): expected ") + sig.length + " args, got " + args.length; - for (int i = 0; i < sig.length; i++) { + List sig = method.toParameterTypes(); + assert args.length == sig.size() : method.format("%H.%n(%p): expected ") + sig.size() + " args, got " + args.length; + for (int i = 0; i < sig.size(); i++) { Object arg = args[i]; + JavaType type = sig.get(i); if (arg == null) { - assert sig[i].getJavaKind() == JavaKind.Object : method.format("%H.%n(%p): expected arg ") + i + " to be Object, not " + sig[i]; - } else if (sig[i].getJavaKind() != JavaKind.Object) { - assert sig[i].getJavaKind().toBoxedJavaClass() == arg.getClass() : method.format("%H.%n(%p): expected arg ") + i + " to be " + sig[i] + ", not " + arg.getClass(); + assert type.getJavaKind() == JavaKind.Object : method.format("%H.%n(%p): expected arg ") + i + " to be Object, not " + type; + } else if (type.getJavaKind() != JavaKind.Object) { + assert type.getJavaKind().toBoxedJavaClass() == arg.getClass() : method.format("%H.%n(%p): expected arg ") + i + " to be " + type + ", not " + arg.getClass(); } } return true; diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotResolvedJavaMethodImpl.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotResolvedJavaMethodImpl.java index 9440a719dd4b0..2e90e49f77e8b 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotResolvedJavaMethodImpl.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotResolvedJavaMethodImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2025, 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 @@ -23,6 +23,7 @@ package jdk.vm.ci.hotspot; import static jdk.vm.ci.hotspot.CompilerToVM.compilerToVM; +import static jdk.vm.ci.hotspot.CompilerToVM.listFromTrustedArray; import static jdk.vm.ci.hotspot.HotSpotJVMCIRuntime.runtime; import static jdk.vm.ci.hotspot.HotSpotModifiers.BRIDGE; import static jdk.vm.ci.hotspot.HotSpotModifiers.SYNTHETIC; @@ -38,7 +39,6 @@ import java.util.BitSet; import java.util.Collections; import java.util.List; -import java.util.Objects; import jdk.internal.vm.VMSupport; import jdk.vm.ci.common.JVMCIError; @@ -152,8 +152,7 @@ public boolean equals(Object obj) { if (this == obj) { return true; } - if (obj instanceof HotSpotResolvedJavaMethodImpl) { - HotSpotResolvedJavaMethodImpl that = (HotSpotResolvedJavaMethodImpl) obj; + if (obj instanceof HotSpotResolvedJavaMethodImpl that) { return that.getMethodPointer() == getMethodPointer(); } return false; @@ -252,10 +251,10 @@ public int getCodeSize() { } @Override - public ExceptionHandler[] getExceptionHandlers() { + public List getExceptionHandlers() { final boolean hasExceptionTable = (getConstMethodFlags() & config().constMethodHasExceptionTable) != 0; if (!hasExceptionTable) { - return new ExceptionHandler[0]; + return List.of(); } HotSpotVMConfig config = config(); @@ -277,8 +276,7 @@ public ExceptionHandler[] getExceptionHandlers() { catchType = constantPool.lookupType(catchTypeIndex, opcode); // Check for Throwable which catches everything. - if (catchType instanceof HotSpotResolvedObjectTypeImpl) { - HotSpotResolvedObjectTypeImpl resolvedType = (HotSpotResolvedObjectTypeImpl) catchType; + if (catchType instanceof HotSpotResolvedObjectTypeImpl resolvedType) { if (resolvedType.equals(runtime().getJavaLangThrowable())) { catchTypeIndex = 0; catchType = null; @@ -291,7 +289,7 @@ public ExceptionHandler[] getExceptionHandlers() { exceptionTableElement += config.exceptionTableElementSize; } - return handlers; + return listFromTrustedArray(handlers); } /** @@ -455,7 +453,6 @@ public boolean hasCompiledCode() { } /** - * @param level * @return true if the currently installed code was generated at {@code level}. */ @Override @@ -505,9 +502,9 @@ public ConstantPool getConstantPool() { } @Override - public Parameter[] getParameters() { + public List getParameters() { if (signature.getParameterCount(false) == 0) { - return new ResolvedJavaMethod.Parameter[0]; + return List.of(); } return runtime().reflection.getParameters(this); } @@ -587,9 +584,9 @@ public boolean isDeclared() { } @Override - public Type[] getGenericParameterTypes() { + public List getGenericParameterTypes() { if (isClassInitializer()) { - return new Type[0]; + return List.of(); } return runtime().reflection.getGenericParameterTypes(this); } @@ -692,8 +689,7 @@ public int vtableEntryOffset(ResolvedJavaType resolved) { @Override public boolean isInVirtualMethodTable(ResolvedJavaType resolved) { - if (resolved instanceof HotSpotResolvedObjectTypeImpl) { - HotSpotResolvedObjectTypeImpl hotspotResolved = (HotSpotResolvedObjectTypeImpl) resolved; + if (resolved instanceof HotSpotResolvedObjectTypeImpl hotspotResolved) { int vtableIndex = getVtableIndex(hotspotResolved); return vtableIndex >= 0 && vtableIndex < hotspotResolved.getVtableLength(); } @@ -777,7 +773,7 @@ public AnnotationData getAnnotationData(ResolvedJavaType type) { if (!hasAnnotations()) { return null; } - return getAnnotationData0(type).get(0); + return getAnnotationData0(type).getFirst(); } @Override diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotResolvedObjectType.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotResolvedObjectType.java index 0417a761fc47a..13755d92a9ac0 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotResolvedObjectType.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotResolvedObjectType.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2025, 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 @@ -48,8 +48,7 @@ public interface HotSpotResolvedObjectType extends ResolvedJavaType { @Override HotSpotResolvedObjectType getSuperclass(); - @Override - HotSpotResolvedObjectType[] getInterfaces(); + // TODO remove, cannot inherit and return List HotSpotResolvedObjectType getSupertype(); diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotResolvedObjectTypeImpl.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotResolvedObjectTypeImpl.java index 17eede6f49074..ed3d40428f472 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotResolvedObjectTypeImpl.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotResolvedObjectTypeImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2025, 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 @@ -22,8 +22,8 @@ */ package jdk.vm.ci.hotspot; -import static java.util.Objects.requireNonNull; import static jdk.vm.ci.hotspot.CompilerToVM.compilerToVM; +import static jdk.vm.ci.hotspot.CompilerToVM.listFromTrustedArray; import static jdk.vm.ci.hotspot.HotSpotConstantPool.isSignaturePolymorphicHolder; import static jdk.vm.ci.hotspot.HotSpotJVMCIRuntime.runtime; import static jdk.vm.ci.hotspot.HotSpotModifiers.jvmClassModifiers; @@ -34,11 +34,11 @@ import java.lang.reflect.Field; import java.lang.reflect.Modifier; import java.nio.ByteOrder; -import java.util.Arrays; +import java.util.ArrayList; import java.util.Collections; -import java.util.Comparator; import java.util.HashMap; import java.util.List; +import java.util.Objects; import jdk.internal.vm.VMSupport; import jdk.vm.ci.common.JVMCIError; @@ -65,7 +65,6 @@ */ final class HotSpotResolvedObjectTypeImpl extends HotSpotResolvedJavaType implements HotSpotResolvedObjectType, MetaspaceObject { - private static final HotSpotResolvedJavaField[] NO_FIELDS = new HotSpotResolvedJavaField[0]; private static final int METHOD_CACHE_ARRAY_CAPACITY = 8; /** @@ -75,8 +74,8 @@ final class HotSpotResolvedObjectTypeImpl extends HotSpotResolvedJavaType implem private HotSpotResolvedJavaMethodImpl[] methodCacheArray; private HashMap methodCacheHashMap; - private volatile HotSpotResolvedJavaField[] instanceFields; - private volatile HotSpotResolvedObjectTypeImpl[] interfaces; + private volatile List instanceFields; + private volatile List interfaces; private HotSpotConstantPool constantPool; private final JavaConstant mirror; private HotSpotResolvedObjectTypeImpl superClass; @@ -90,7 +89,7 @@ final class HotSpotResolvedObjectTypeImpl extends HotSpotResolvedJavaType implem /** * Lazily initialized cache for FieldInfo. */ - private FieldInfo[] fieldInfo; + private List fieldInfo; /** * Managed exclusively by {@link HotSpotJDKReflection#getField}. @@ -103,13 +102,12 @@ static HotSpotResolvedObjectTypeImpl getJavaLangObject() { /** * Gets the JVMCI mirror from a HotSpot type. - * + *

    * Called from the VM. * * @param klassPointer a native pointer to the Klass* * @return the {@link ResolvedJavaType} corresponding to {@code javaClass} */ - @SuppressWarnings("unused") @VMEntryPoint private static HotSpotResolvedObjectTypeImpl fromMetaspace(long klassPointer) { return runtime().fromMetaspace(klassPointer); @@ -124,7 +122,6 @@ private static HotSpotResolvedObjectTypeImpl fromMetaspace(long klassPointer) { * * @param klass the {@code Klass*} for the type */ - @SuppressWarnings("try") HotSpotResolvedObjectTypeImpl(long klass, String name) { super(name); assert klass != 0; @@ -133,7 +130,7 @@ private static HotSpotResolvedObjectTypeImpl fromMetaspace(long klassPointer) { // The mirror object must be in the global scope since // this object will be cached in HotSpotJVMCIRuntime.resolvedJavaTypes // and live across more than one compilation. - try (HotSpotObjectConstantScope global = HotSpotObjectConstantScope.enterGlobalScope()) { + try (HotSpotObjectConstantScope _ = HotSpotObjectConstantScope.enterGlobalScope()) { this.mirror = runtime().compilerToVm.getJavaMirror(this); assert getName().charAt(0) != '[' || isArray() : getName(); } @@ -308,13 +305,10 @@ public HotSpotResolvedObjectTypeImpl getSuperclass() { } @Override - public HotSpotResolvedObjectTypeImpl[] getInterfaces() { + public List getInterfaces() { if (interfaces == null) { if (isArray()) { - HotSpotResolvedObjectTypeImpl[] types = new HotSpotResolvedObjectTypeImpl[2]; - types[0] = runtime().getJavaLangCloneable(); - types[1] = runtime().getJavaLangSerializable(); - this.interfaces = types; + interfaces = List.of(runtime().getJavaLangCloneable(), runtime().getJavaLangSerializable()); } else { interfaces = runtime().compilerToVm.getInterfaces(this); } @@ -393,17 +387,17 @@ public boolean isEnum() { @Override public boolean isInitialized() { - return isArray() ? true : getInitState() == config().instanceKlassStateFullyInitialized; + return isArray() || getInitState() == config().instanceKlassStateFullyInitialized; } @Override public boolean isBeingInitialized() { - return isArray() ? false : getInitState() == config().instanceKlassStateBeingInitialized; + return !isArray() && getInitState() == config().instanceKlassStateBeingInitialized; } @Override public boolean isLinked() { - return isArray() ? true : getInitState() >= config().instanceKlassStateLinked; + return isArray() || getInitState() >= config().instanceKlassStateLinked; } @Override @@ -467,8 +461,7 @@ public boolean isInterface() { @Override public boolean isAssignableFrom(ResolvedJavaType other) { assert other != null; - if (other instanceof HotSpotResolvedObjectTypeImpl) { - HotSpotResolvedObjectTypeImpl otherType = (HotSpotResolvedObjectTypeImpl) other; + if (other instanceof HotSpotResolvedObjectTypeImpl otherType) { return runtime().reflection.isAssignableFrom(this, otherType); } return false; @@ -558,8 +551,7 @@ synchronized HotSpotResolvedJavaMethod createMethod(long metaspaceHandle) { methodCacheArray = new HotSpotResolvedJavaMethodImpl[METHOD_CACHE_ARRAY_CAPACITY]; } - int i = 0; - for (; i < methodCacheArray.length; ++i) { + for (int i = 0; i < methodCacheArray.length; ++i) { HotSpotResolvedJavaMethodImpl curMethod = methodCacheArray[i]; if (curMethod == null) { HotSpotResolvedJavaMethodImpl newMethod = new HotSpotResolvedJavaMethodImpl(this, metaspaceHandle); @@ -644,7 +636,7 @@ public AssumptionResult findUniqueConcreteMethod(ResolvedJav return null; } - private FieldInfo[] getFieldInfo() { + private List getFieldInfo() { if (fieldInfo == null) { fieldInfo = runtime().compilerToVm.getDeclaredFieldsInfo(this); } @@ -652,7 +644,7 @@ private FieldInfo[] getFieldInfo() { } FieldInfo getFieldInfo(int index) { - return getFieldInfo()[index]; + return getFieldInfo().get(index); } public void ensureInitialized() { @@ -664,10 +656,9 @@ public boolean equals(Object obj) { if (obj == this) { return true; } - if (!(obj instanceof HotSpotResolvedObjectTypeImpl)) { + if (!(obj instanceof HotSpotResolvedObjectTypeImpl that)) { return false; } - HotSpotResolvedObjectTypeImpl that = (HotSpotResolvedObjectTypeImpl) obj; return getKlassPointer() == that.getKlassPointer(); } @@ -697,11 +688,11 @@ static class FieldInfo { /** * Creates a field info with the provided indices. * - * @param nameIndex index of field's name in the constant pool - * @param signatureIndex index of field's signature in the constant pool - * @param offset field's offset - * @param classfileFlags field's access flags (from the class file) - * @param internalFlags field's internal flags (from the VM) + * @param nameIndex index of field's name in the constant pool + * @param signatureIndex index of field's signature in the constant pool + * @param offset field's offset + * @param classfileFlags field's access flags (from the class file) + * @param internalFlags field's internal flags (from the VM) * @param initializerIndex field's initial value index in the constant pool */ FieldInfo(int nameIndex, int signatureIndex, int offset, int classfileFlags, int internalFlags, int initializerIndex) { @@ -740,6 +731,7 @@ public int getOffset() { /** * Returns the name of this field as a {@link String}. If the field is an internal field the * name index is pointing into the vmSymbols table. + * * @param klass field's holder class */ public String getName(HotSpotResolvedObjectTypeImpl klass) { @@ -749,6 +741,7 @@ public String getName(HotSpotResolvedObjectTypeImpl klass) { /** * Returns the signature of this field as {@link String}. If the field is an internal field * the signature index is pointing into the vmSymbols table. + * * @param klass field's holder class */ public String getSignature(HotSpotResolvedObjectTypeImpl klass) { @@ -782,34 +775,27 @@ public boolean isStatic() { } @Override - public ResolvedJavaField[] getInstanceFields(boolean includeSuperclasses) { + public List getInstanceFields(boolean includeSuperclasses) { if (instanceFields == null) { if (isArray() || isInterface()) { - instanceFields = NO_FIELDS; + instanceFields = List.of(); } else { - HotSpotResolvedJavaField[] prepend = NO_FIELDS; + List prepend = List.of(); if (getSuperclass() != null) { - prepend = (HotSpotResolvedJavaField[]) getSuperclass().getInstanceFields(true); + prepend = getSuperclass().getInstanceFields(true); } instanceFields = getFields(false, prepend); } } if (!includeSuperclasses && getSuperclass() != null) { - int superClassFieldCount = getSuperclass().getInstanceFields(true).length; - if (superClassFieldCount == instanceFields.length) { + int superClassFieldCount = getSuperclass().getInstanceFields(true).size(); + if (superClassFieldCount == instanceFields.size()) { // This class does not have any instance fields of its own. - return NO_FIELDS; + return List.of(); } else if (superClassFieldCount != 0) { - // Fields of the current class can be interleaved with fields of its super-classes - // but the array of fields to be returned must be sorted by increasing offset - // This code populates the array, then applies the sorting function - HotSpotResolvedJavaField[] result = new HotSpotResolvedJavaField[instanceFields.length - superClassFieldCount]; - int i = 0; - for (HotSpotResolvedJavaField f : instanceFields) { - if (f.getDeclaringClass() == this) { - result[i++] = f; - } - } + // The super classes' instanceFields are prepended. + List result = instanceFields.subList(superClassFieldCount, instanceFields.size()); + assert result.stream().map(ResolvedJavaField::getDeclaringClass).allMatch(c -> c == this); return result; } else { // The super classes of this class do not have any instance fields. @@ -819,11 +805,11 @@ public ResolvedJavaField[] getInstanceFields(boolean includeSuperclasses) { } @Override - public ResolvedJavaField[] getStaticFields() { + public List getStaticFields() { if (isArray()) { - return new HotSpotResolvedJavaField[0]; + return List.of(); } else { - return getFields(true, NO_FIELDS); + return getFields(true, List.of()); } } @@ -831,15 +817,13 @@ public ResolvedJavaField[] getStaticFields() { * Gets the instance or static fields of this class. * * @param retrieveStaticFields specifies whether to return instance or static fields - * @param prepend an array to be prepended to the returned result + * @param prepend a list to be prepended to the returned result */ - private HotSpotResolvedJavaField[] getFields(boolean retrieveStaticFields, HotSpotResolvedJavaField[] prepend) { - HotSpotVMConfig config = config(); + private List getFields(boolean retrieveStaticFields, List prepend) { int resultCount = 0; - int index = 0; - for (index = 0; index < getFieldInfo().length; index++) { - if (getFieldInfo(index).isStatic() == retrieveStaticFields) { + for (FieldInfo field : getFieldInfo()) { + if (field.isStatic() == retrieveStaticFields) { resultCount++; } } @@ -848,27 +832,28 @@ private HotSpotResolvedJavaField[] getFields(boolean retrieveStaticFields, HotSp return prepend; } - int prependLength = prepend.length; + int prependLength = prepend.size(); resultCount += prependLength; HotSpotResolvedJavaField[] result = new HotSpotResolvedJavaField[resultCount]; if (prependLength != 0) { - System.arraycopy(prepend, 0, result, 0, prependLength); + for (int i = 0; i < prependLength; i++) { + result[i] = (HotSpotResolvedJavaField) prepend.get(i); + } } // Fields of the current class can be interleaved with fields of its super-classes // but the array of fields to be returned must be sorted by increasing offset // This code populates the array, then applies the sorting function int resultIndex = prependLength; - for (int i = 0; i < getFieldInfo().length; ++i) { - FieldInfo field = getFieldInfo(i); + for (FieldInfo field : getFieldInfo()) { if (field.isStatic() == retrieveStaticFields) { int offset = field.getOffset(); - HotSpotResolvedJavaField resolvedJavaField = createField(field.getType(this), offset, field.getClassfileFlags(), field.getInternalFlags(), i); + HotSpotResolvedJavaField resolvedJavaField = createField(field.getType(this), offset, field.getClassfileFlags(), field.getInternalFlags(), resultIndex - prependLength); result[resultIndex++] = resolvedJavaField; } } - return result; + return listFromTrustedArray(result); } @Override @@ -957,12 +942,12 @@ public boolean isDefinitelyResolvedWithRespectTo(ResolvedJavaType accessingClass private boolean hasSameClassLoader(HotSpotResolvedObjectTypeImpl otherMirror) { return UnsafeAccess.UNSAFE.getAddress(getKlassPointer() + config().classLoaderDataOffset) == UnsafeAccess.UNSAFE.getAddress( - otherMirror.getKlassPointer() + config().classLoaderDataOffset); + otherMirror.getKlassPointer() + config().classLoaderDataOffset); } @Override public ResolvedJavaType resolve(ResolvedJavaType accessingClass) { - if (isDefinitelyResolvedWithRespectTo(requireNonNull(accessingClass))) { + if (isDefinitelyResolvedWithRespectTo(Objects.requireNonNull(accessingClass))) { return this; } HotSpotResolvedObjectTypeImpl accessingType = (HotSpotResolvedObjectTypeImpl) accessingClass; @@ -996,16 +981,16 @@ public long prototypeMarkWord() { @Override public ResolvedJavaField findInstanceFieldWithOffset(long offset, JavaKind expectedEntryKind) { - ResolvedJavaField[] declaredFields = getInstanceFields(true); + List declaredFields = getInstanceFields(true); return findFieldWithOffset(offset, expectedEntryKind, declaredFields); } public ResolvedJavaField findStaticFieldWithOffset(long offset, JavaKind expectedEntryKind) { - ResolvedJavaField[] declaredFields = getStaticFields(); + List declaredFields = getStaticFields(); return findFieldWithOffset(offset, expectedEntryKind, declaredFields); } - private static ResolvedJavaField findFieldWithOffset(long offset, JavaKind expectedEntryKind, ResolvedJavaField[] declaredFields) { + private static ResolvedJavaField findFieldWithOffset(long offset, JavaKind expectedEntryKind, List declaredFields) { for (ResolvedJavaField field : declaredFields) { long resolvedFieldOffset = field.getOffset(); // @formatter:off @@ -1041,13 +1026,13 @@ public HotSpotResolvedObjectType getEnclosingType() { } @Override - public ResolvedJavaMethod[] getDeclaredConstructors() { + public List getDeclaredConstructors() { link(); return runtime().compilerToVm.getDeclaredConstructors(this); } @Override - public ResolvedJavaMethod[] getDeclaredConstructors(boolean forceLink) { + public List getDeclaredConstructors(boolean forceLink) { if (forceLink) { link(); } @@ -1055,12 +1040,12 @@ public ResolvedJavaMethod[] getDeclaredConstructors(boolean forceLink) { } @Override - public ResolvedJavaMethod[] getDeclaredMethods() { + public List getDeclaredMethods() { return getDeclaredMethods(true); } @Override - public ResolvedJavaMethod[] getDeclaredMethods(boolean forceLink) { + public List getDeclaredMethods(boolean forceLink) { if (forceLink) { link(); } @@ -1072,7 +1057,7 @@ public List getAllMethods(boolean forceLink) { if (forceLink) { link(); } - return List.of(runtime().compilerToVm.getAllMethods(this)); + return runtime().compilerToVm.getAllMethods(this); } @Override @@ -1122,7 +1107,7 @@ public AnnotationData getAnnotationData(ResolvedJavaType annotationType) { if (!mayHaveAnnotations(true)) { return null; } - return getAnnotationData0(annotationType).get(0); + return getAnnotationData0(annotationType).getFirst(); } @Override diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotResolvedPrimitiveType.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotResolvedPrimitiveType.java index b707906af0826..c66a885de2104 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotResolvedPrimitiveType.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotResolvedPrimitiveType.java @@ -27,7 +27,6 @@ import java.lang.annotation.Annotation; import java.lang.reflect.Modifier; -import java.util.Collections; import java.util.List; import jdk.vm.ci.common.JVMCIError; @@ -47,7 +46,7 @@ public final class HotSpotResolvedPrimitiveType extends HotSpotResolvedJavaType static HotSpotResolvedPrimitiveType[] primitives; - private JavaKind kind; + private final JavaKind kind; HotSpotObjectConstantImpl mirror; /** @@ -107,8 +106,8 @@ public ResolvedJavaType getSuperclass() { } @Override - public ResolvedJavaType[] getInterfaces() { - return new ResolvedJavaType[0]; + public List getInterfaces() { + return List.of(); } @Override @@ -213,13 +212,13 @@ public AssumptionResult findUniqueConcreteMethod(ResolvedJav } @Override - public ResolvedJavaField[] getInstanceFields(boolean includeSuperclasses) { - return new ResolvedJavaField[0]; + public List getInstanceFields(boolean includeSuperclasses) { + return List.of(); } @Override - public ResolvedJavaField[] getStaticFields() { - return new ResolvedJavaField[0]; + public List getStaticFields() { + return List.of(); } @Override @@ -287,13 +286,13 @@ public ResolvedJavaType getEnclosingType() { } @Override - public ResolvedJavaMethod[] getDeclaredConstructors() { - return new ResolvedJavaMethod[0]; + public List getDeclaredConstructors() { + return List.of(); } @Override - public ResolvedJavaMethod[] getDeclaredMethods() { - return new ResolvedJavaMethod[0]; + public List getDeclaredMethods() { + return List.of(); } @Override @@ -313,10 +312,9 @@ public boolean isCloneableWithAllocation() { @Override public boolean equals(Object obj) { - if (!(obj instanceof HotSpotResolvedPrimitiveType)) { + if (!(obj instanceof HotSpotResolvedPrimitiveType that)) { return false; } - HotSpotResolvedPrimitiveType that = (HotSpotResolvedPrimitiveType) obj; return that.kind == kind; } @@ -332,7 +330,7 @@ public AnnotationData getAnnotationData(ResolvedJavaType type) { @Override public List getAnnotationData(ResolvedJavaType type1, ResolvedJavaType type2, ResolvedJavaType... types) { - return Collections.emptyList(); + return List.of(); } } diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/SharedLibraryJVMCIReflection.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/SharedLibraryJVMCIReflection.java index d7e8fd37ab277..bb8a469434f07 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/SharedLibraryJVMCIReflection.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/SharedLibraryJVMCIReflection.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2025, 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 @@ -27,6 +27,7 @@ import java.lang.annotation.Annotation; import java.lang.reflect.Array; import java.lang.reflect.Type; +import java.util.List; import jdk.vm.ci.meta.JavaConstant; import jdk.vm.ci.meta.ResolvedJavaMethod; @@ -79,9 +80,7 @@ boolean equals(HotSpotObjectConstantImpl x, HotSpotObjectConstantImpl y) { if (x.compressed != y.compressed) { return false; } - if (x instanceof DirectHotSpotObjectConstantImpl && y instanceof DirectHotSpotObjectConstantImpl) { - DirectHotSpotObjectConstantImpl xd = (DirectHotSpotObjectConstantImpl) x; - DirectHotSpotObjectConstantImpl yd = (DirectHotSpotObjectConstantImpl) y; + if (x instanceof DirectHotSpotObjectConstantImpl xd && y instanceof DirectHotSpotObjectConstantImpl yd) { return (xd.object == yd.object); } if (x instanceof DirectHotSpotObjectConstantImpl || y instanceof DirectHotSpotObjectConstantImpl) { @@ -94,9 +93,8 @@ boolean equals(HotSpotObjectConstantImpl x, HotSpotObjectConstantImpl y) { } @Override - ResolvedJavaMethod.Parameter[] getParameters(HotSpotResolvedJavaMethodImpl javaMethod) { - // ResolvedJavaMethod.getParameters allows a return value of null - return null; + List getParameters(HotSpotResolvedJavaMethodImpl javaMethod) { + return List.of(); } // Substituted by Target_jdk_vm_ci_hotspot_SharedLibraryJVMCIReflection @@ -135,7 +133,7 @@ Annotation[][] getParameterAnnotations(HotSpotResolvedJavaMethodImpl javaMethod) } @Override - Type[] getGenericParameterTypes(HotSpotResolvedJavaMethodImpl javaMethod) { + List getGenericParameterTypes(HotSpotResolvedJavaMethodImpl javaMethod) { throw new HotSpotJVMCIUnsupportedOperationError("unimplemented"); } @@ -212,10 +210,8 @@ String asString(HotSpotObjectConstantImpl object) { @Override ResolvedJavaType asJavaType(HotSpotObjectConstantImpl object) { - if (object instanceof DirectHotSpotObjectConstantImpl) { - DirectHotSpotObjectConstantImpl direct = (DirectHotSpotObjectConstantImpl) object; - if (direct.object instanceof Class) { - Class javaClass = (Class) direct.object; + if (object instanceof DirectHotSpotObjectConstantImpl direct) { + if (direct.object instanceof Class javaClass) { return runtime().fromClass(javaClass); } if (direct.object instanceof ResolvedJavaType) { @@ -251,8 +247,7 @@ Object asObject(HotSpotObjectConstantImpl object, HotSpotResolvedJavaType type) @Override String formatString(HotSpotObjectConstantImpl object) { - if (object instanceof DirectHotSpotObjectConstantImpl) { - DirectHotSpotObjectConstantImpl direct = (DirectHotSpotObjectConstantImpl) object; + if (object instanceof DirectHotSpotObjectConstantImpl direct) { return "CompilerObject<" + direct.object.getClass().getName() + ">"; } IndirectHotSpotObjectConstantImpl indirect = (IndirectHotSpotObjectConstantImpl) object; @@ -264,8 +259,7 @@ String formatString(HotSpotObjectConstantImpl object) { @Override Integer getLength(HotSpotObjectConstantImpl object) { - if (object instanceof DirectHotSpotObjectConstantImpl) { - DirectHotSpotObjectConstantImpl direct = (DirectHotSpotObjectConstantImpl) object; + if (object instanceof DirectHotSpotObjectConstantImpl direct) { if (direct.object.getClass().isArray()) { return Array.getLength(direct.object); } @@ -296,7 +290,7 @@ JavaConstant readArrayElement(HotSpotObjectConstantImpl arrayObject, int index) @Override JavaConstant forObject(Object value) { - return DirectHotSpotObjectConstantImpl.forObject(value, false); + return DirectHotSpotObjectConstantImpl.forObject(value); } @Override diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/AbstractJavaProfile.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/AbstractJavaProfile.java index 4e703beddf6a0..b96debadf34db 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/AbstractJavaProfile.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/AbstractJavaProfile.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2025, 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 @@ -22,6 +22,8 @@ */ package jdk.vm.ci.meta; +import java.util.List; + /** * This object holds probability information for a set of items that were profiled at a specific * BCI. The precision of the supplied values may vary, but a runtime that provides this information @@ -35,15 +37,9 @@ public abstract class AbstractJavaProfile, U> { private final double notRecordedProbability; - private final T[] pitems; + private final List pitems; - /** - * - * @param notRecordedProbability - * @param pitems - */ - @SuppressFBWarnings(value = "EI_EXPOSE_REP2", justification = "caller transfers ownership of the `pitems` array parameter") - public AbstractJavaProfile(double notRecordedProbability, T[] pitems) { + public AbstractJavaProfile(double notRecordedProbability, List pitems) { this.pitems = pitems; assert !Double.isNaN(notRecordedProbability); this.notRecordedProbability = notRecordedProbability; @@ -64,8 +60,8 @@ private double totalProbablility() { * probabilities. */ private boolean isSorted() { - for (int i = 1; i < pitems.length; i++) { - if (pitems[i - 1].getProbability() < pitems[i].getProbability()) { + for (int i = 1; i < pitems.size(); i++) { + if (pitems.get(i - 1).getProbability() < pitems.get(i).getProbability()) { return false; } } @@ -82,7 +78,7 @@ public double getNotRecordedProbability() { return notRecordedProbability; } - protected T[] getItems() { + protected List getItems() { return pitems; } @@ -123,8 +119,7 @@ public boolean isIncluded(U item) { if (this.getNotRecordedProbability() > 0.0) { return true; } else { - for (int i = 0; i < getItems().length; i++) { - T pitem = getItems()[i]; + for (T pitem : getItems()) { U curType = pitem.getItem(); if (curType == item) { return true; @@ -139,18 +134,17 @@ public boolean equals(Object obj) { if (obj == this) { return true; } - if (!(obj instanceof AbstractJavaProfile)) { + if (!(obj instanceof AbstractJavaProfile that)) { return false; } - AbstractJavaProfile that = (AbstractJavaProfile) obj; if (that.notRecordedProbability != notRecordedProbability) { return false; } - if (that.pitems.length != pitems.length) { + if (that.pitems.size() != pitems.size()) { return false; } - for (int i = 0; i < pitems.length; ++i) { - if (!pitems[i].equals(that.pitems[i])) { + for (int i = 0; i < pitems.size(); ++i) { + if (!pitems.get(i).equals(that.pitems.get(i))) { return false; } } @@ -159,6 +153,6 @@ public boolean equals(Object obj) { @Override public int hashCode() { - return (int) Double.doubleToLongBits(notRecordedProbability) + pitems.length * 13; + return (int) Double.doubleToLongBits(notRecordedProbability) + pitems.size() * 13; } } diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/JavaMethodProfile.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/JavaMethodProfile.java index f63c6f5a6d3c2..583555c4c25c5 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/JavaMethodProfile.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/JavaMethodProfile.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2025, 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,6 +24,8 @@ import jdk.vm.ci.meta.JavaMethodProfile.ProfiledMethod; +import java.util.List; + /** * This profile object represents the method profile at a specific BCI. The precision of the * supplied values may vary, but a runtime that provides this information should be aware that it @@ -32,10 +34,10 @@ public final class JavaMethodProfile extends AbstractJavaProfile { public JavaMethodProfile(double notRecordedProbability, ProfiledMethod[] pitems) { - super(notRecordedProbability, pitems); + super(notRecordedProbability, List.of(pitems)); } - public ProfiledMethod[] getMethods() { + public List getMethods() { return super.getItems(); } diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/JavaTypeProfile.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/JavaTypeProfile.java index 8827017df6d9b..e397477838bd1 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/JavaTypeProfile.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/JavaTypeProfile.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2025, 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,7 +24,9 @@ import java.lang.reflect.Modifier; import java.util.ArrayList; +import java.util.List; +import jdk.internal.access.SharedSecrets; import jdk.vm.ci.meta.JavaTypeProfile.ProfiledType; /** @@ -34,11 +36,13 @@ */ public final class JavaTypeProfile extends AbstractJavaProfile { - private static final ProfiledType[] EMPTY_ARRAY = new ProfiledType[0]; - private final TriState nullSeen; public JavaTypeProfile(TriState nullSeen, double notRecordedProbability, ProfiledType[] pitems) { + this(nullSeen, notRecordedProbability, List.of(pitems)); + } + + private JavaTypeProfile(TriState nullSeen, double notRecordedProbability, List pitems) { super(notRecordedProbability, pitems); this.nullSeen = nullSeen; } @@ -55,7 +59,7 @@ public TriState getNullSeen() { * includes both positive and negative types where a positive type is a subtype of the checked * type and a negative type is not. */ - public ProfiledType[] getTypes() { + public List getTypes() { return getItems(); } @@ -71,8 +75,7 @@ public JavaTypeProfile restrict(JavaTypeProfile otherProfile) { } ArrayList result = new ArrayList<>(); - for (int i = 0; i < getItems().length; i++) { - ProfiledType ptype = getItems()[i]; + for (ProfiledType ptype : getItems()) { ResolvedJavaType type = ptype.getItem(); if (otherProfile.isIncluded(type)) { result.add(ptype); @@ -86,8 +89,7 @@ public JavaTypeProfile restrict(JavaTypeProfile otherProfile) { public JavaTypeProfile restrict(ResolvedJavaType declaredType, boolean nonNull) { ArrayList result = new ArrayList<>(); - for (int i = 0; i < getItems().length; i++) { - ProfiledType ptype = getItems()[i]; + for (ProfiledType ptype : getItems()) { ResolvedJavaType type = ptype.getItem(); if (declaredType.isAssignableFrom(type)) { result.add(ptype); @@ -97,25 +99,25 @@ public JavaTypeProfile restrict(ResolvedJavaType declaredType, boolean nonNull) TriState newNullSeen = (nonNull) ? TriState.FALSE : getNullSeen(); double newNotRecorded = this.getNotRecordedProbability(); // Assume for the types not recorded, the incompatibility rate is the same. - if (getItems().length != 0) { - newNotRecorded *= ((double) result.size() / (double) getItems().length); + if (!getItems().isEmpty()) { + newNotRecorded *= ((double) result.size() / (double) getItems().size()); } return createAdjustedProfile(result, newNullSeen, newNotRecorded); } private JavaTypeProfile createAdjustedProfile(ArrayList result, TriState newNullSeen, double newNotRecorded) { - if (result.size() != this.getItems().length || newNotRecorded != getNotRecordedProbability() || newNullSeen != getNullSeen()) { - if (result.size() == 0) { - return new JavaTypeProfile(newNullSeen, 1.0, EMPTY_ARRAY); + if (result.size() != this.getItems().size() || newNotRecorded != getNotRecordedProbability() || newNullSeen != getNullSeen()) { + if (result.isEmpty()) { + return new JavaTypeProfile(newNullSeen, 1.0, List.of()); } double factor; - if (result.size() == this.getItems().length) { + if (result.size() == this.getItems().size()) { /* List of types did not change, no need to recompute probabilities. */ factor = 1.0; } else { double probabilitySum = 0.0; - for (int i = 0; i < result.size(); i++) { - probabilitySum += result.get(i).getProbability(); + for (ProfiledType profiledType : result) { + probabilitySum += profiledType.getProbability(); } probabilitySum += newNotRecorded; @@ -128,7 +130,7 @@ private JavaTypeProfile createAdjustedProfile(ArrayList result, Tr newResult[i] = new ProfiledType(curType.getItem(), Math.min(1.0, curType.getProbability() * factor)); } double newNotRecordedTypeProbability = Math.min(1.0, newNotRecorded * factor); - return new JavaTypeProfile(newNullSeen, newNotRecordedTypeProbability, newResult); + return new JavaTypeProfile(newNullSeen, newNotRecordedTypeProbability, MetaUtil.listFromTrustedArray(newResult)); } return this; } @@ -166,11 +168,11 @@ public String toString() { @Override public String toString() { StringBuilder buf = new StringBuilder("JavaTypeProfile", getNotRecordedProbability())).toString(); @@ -184,12 +186,12 @@ public boolean allTypesRecorded() { } /** - * Returns the single monormorphic type representing this profile or {@code null} if no such + * Returns the single monomorphic type representing this profile or {@code null} if no such * type exists. */ public ResolvedJavaType asSingleType() { - if (allTypesRecorded() && this.getTypes().length == 1) { - return getTypes()[0].getType(); + if (allTypesRecorded() && this.getTypes().size() == 1) { + return getTypes().getFirst().getType(); } return null; } diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/LocalVariableTable.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/LocalVariableTable.java index 4ac00c930b4bf..2f2fd25b16119 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/LocalVariableTable.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/LocalVariableTable.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2025, 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 @@ -32,17 +32,16 @@ */ public class LocalVariableTable { - private final Local[] locals; + private final List locals; /** * Creates an object describing the {@link Local}s for a Java method. * * @param locals array of objects describing local variables. This array is now owned by this - * object and must not be mutated by the caller. + * object and must not be mutated by the caller. */ - @SuppressFBWarnings(value = "EI_EXPOSE_REP2", justification = "caller transfers ownership of `locals`") public LocalVariableTable(Local[] locals) { - this.locals = locals; + this.locals = List.of(locals); } /** @@ -50,7 +49,7 @@ public LocalVariableTable(Local[] locals) { * {@code slot} and is live at the bytecode index {@code bci}. * * @return a description of the requested local variable or null if no such variable matches - * {@code slot} and {@code bci} + * {@code slot} and {@code bci} */ public Local getLocal(int slot, int bci) { Local result = null; @@ -67,22 +66,22 @@ public Local getLocal(int slot, int bci) { } /** - * Gets a copy of the array of {@link Local}s that was passed to this object's constructor. + * Gets the local variables */ - public Local[] getLocals() { - return locals.clone(); + public List getLocals() { + return locals; } /** * Gets a description of all the local variables live at the bytecode index {@code bci}. */ - public Local[] getLocalsAt(int bci) { + public List getLocalsAt(int bci) { List result = new ArrayList<>(); for (Local l : locals) { if (l.getStartBCI() <= bci && bci <= l.getEndBCI()) { result.add(l); } } - return result.toArray(new Local[result.size()]); + return MetaUtil.listFromTrustedArray(result.toArray()); } } diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/MetaAccessProvider.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/MetaAccessProvider.java index 2686ab1737f28..cbf7286b61737 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/MetaAccessProvider.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/MetaAccessProvider.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2025, 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 @@ -26,6 +26,7 @@ import java.lang.reflect.Executable; import java.lang.reflect.Field; import java.lang.reflect.Method; +import java.util.List; import jdk.vm.ci.meta.SpeculationLog.Speculation; @@ -48,12 +49,12 @@ public interface MetaAccessProvider { * @param classes the Java class objects * @return the resolved Java type objects */ - default ResolvedJavaType[] lookupJavaTypes(Class[] classes) { + default List lookupJavaTypes(Class[] classes) { ResolvedJavaType[] result = new ResolvedJavaType[classes.length]; for (int i = 0; i < result.length; i++) { result[i] = lookupJavaType(classes[i]); } - return result; + return List.of(result); } /** diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/MetaUtil.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/MetaUtil.java index 8ee2818b613c8..5d8ff84497263 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/MetaUtil.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/MetaUtil.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2025, 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 @@ -22,6 +22,9 @@ */ package jdk.vm.ci.meta; +import java.util.List; +import jdk.internal.access.SharedSecrets; + /** * Miscellaneous collection of utility methods used by {@code jdk.vm.ci.meta} and its clients. */ @@ -44,7 +47,7 @@ public class MetaUtil { */ public static String getSimpleName(Class clazz, boolean withEnclosingClass) { final String simpleName = safeSimpleName(clazz); - if (simpleName.length() != 0) { + if (!simpleName.isEmpty()) { if (withEnclosingClass) { String prefix = ""; Class enclosingClass = clazz; @@ -179,10 +182,6 @@ public static String toLocation(ResolvedJavaMethod method, int bci) { *

          *     java.lang.String.valueOf(int) [bci: 12]
          * 
    - * - * @param sb - * @param method - * @param bci */ public static StringBuilder appendLocation(StringBuilder sb, ResolvedJavaMethod method, int bci) { if (method != null) { @@ -200,11 +199,10 @@ public static StringBuilder appendLocation(StringBuilder sb, ResolvedJavaMethod static void appendProfile(StringBuilder buf, AbstractJavaProfile profile, int bci, String type, String sep) { if (profile != null) { - AbstractProfiledItem[] pitems = profile.getItems(); + var pitems = profile.getItems(); if (pitems != null) { buf.append(String.format("%s@%d:", type, bci)); - for (int j = 0; j < pitems.length; j++) { - AbstractProfiledItem pitem = pitems[j]; + for (AbstractProfiledItem pitem : pitems) { buf.append(String.format(" %.6f (%s)%s", pitem.getProbability(), pitem.getItem(), sep)); } if (profile.getNotRecordedProbability() != 0) { @@ -283,4 +281,11 @@ public static String identityHashCodeString(Object obj) { } return obj.getClass().getName() + "@" + System.identityHashCode(obj); } + + /** + * Creates an immutable list from a trusted array. + */ + static List listFromTrustedArray(Object[] array) { + return SharedSecrets.getJavaUtilCollectionAccess().listFromTrustedArray(array); + } } diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/ResolvedJavaMethod.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/ResolvedJavaMethod.java index f401bc30f83ee..318961c224a5d 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/ResolvedJavaMethod.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/ResolvedJavaMethod.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2025, 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 @@ -28,7 +28,7 @@ import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.lang.reflect.Type; -import java.util.BitSet; +import java.util.List; /** * Represents a resolved Java method. Methods, like fields and types, are resolved through @@ -145,7 +145,7 @@ default boolean isFinal() { /** * Returns the list of exception handlers for this method. */ - ExceptionHandler[] getExceptionHandlers(); + List getExceptionHandlers(); /** * Returns a stack trace element for this method and a given bytecode index. @@ -255,7 +255,7 @@ public JavaKind getKind() { * Gets the formal type of the parameter. */ public Type getParameterizedType() { - return method.getGenericParameterTypes()[index]; + return method.getGenericParameterTypes().get(index); } /** @@ -284,7 +284,7 @@ public boolean isVarArgs() { @Override public T getAnnotation(Class annotationClass) { - return method.getParameterAnnotations(annotationClass)[index]; + return method.getParameterAnnotations(annotationClass).get(index); } @Override @@ -306,7 +306,7 @@ public String toString() { } final StringBuilder sb = new StringBuilder(Modifier.toString(getModifiers())); - if (sb.length() != 0) { + if (!sb.isEmpty()) { sb.append(' '); } return sb.append(typename).append(' ').append(getName()).toString(); @@ -314,8 +314,7 @@ public String toString() { @Override public boolean equals(Object obj) { - if (obj instanceof Parameter) { - Parameter other = (Parameter) obj; + if (obj instanceof Parameter other) { return (other.method.equals(method) && other.index == index); } return false; @@ -332,7 +331,7 @@ public int hashCode() { * method. Returns an array of length 0 if this method has no parameters. Returns {@code null} * if the parameter information is unavailable. */ - default Parameter[] getParameters() { + default List getParameters() { return null; } @@ -342,15 +341,16 @@ default Parameter[] getParameters() { * * @see Method#getParameterAnnotations() */ + // TODO libgraal does not support this, shall we deprecate/remove this? Annotation[][] getParameterAnnotations(); /** - * Returns an array of {@link Type} objects that represent the formal parameter types, in + * Returns a list of {@link Type} objects that represent the formal parameter types, in * declaration order, of this method. * * @see Method#getGenericParameterTypes() */ - Type[] getGenericParameterTypes(); + List getGenericParameterTypes(); /** * Returns {@code true} if this method is not excluded from inlining and has associated Java @@ -419,7 +419,7 @@ default T getParameterAnnotation(Class annotationClass return null; } - default JavaType[] toParameterTypes() { + default List toParameterTypes() { JavaType receiver = isStatic() || isConstructor() ? null : getDeclaringClass(); return getSignature().toParameterTypes(receiver); } @@ -432,7 +432,7 @@ default JavaType[] toParameterTypes() { * present */ @SuppressWarnings("unchecked") - default T[] getParameterAnnotations(Class annotationClass) { + default List getParameterAnnotations(Class annotationClass) { Annotation[][] parameterAnnotations = getParameterAnnotations(); T[] result = (T[]) Array.newInstance(annotationClass, parameterAnnotations.length); for (int i = 0; i < parameterAnnotations.length; i++) { @@ -442,7 +442,7 @@ default T[] getParameterAnnotations(Class annotationCl } } } - return result; + return MetaUtil.listFromTrustedArray(result); } /** diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/ResolvedJavaType.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/ResolvedJavaType.java index 929a4713330ad..11092d0f85420 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/ResolvedJavaType.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/ResolvedJavaType.java @@ -139,15 +139,6 @@ default boolean declaresDefaultMethods() { */ boolean isAssignableFrom(ResolvedJavaType other); - /** - * Returns {@code null} since support for VM anonymous class was removed by JDK-8243287. This - * method is preserved for JVMCI backwards compatibility. - */ - @Deprecated - default ResolvedJavaType getHostClass() { - return null; - } - /** * Returns true if this type is exactly the type {@link java.lang.Object}. */ @@ -176,7 +167,7 @@ default boolean isJavaLangObject() { * {@link Class#getInterfaces()} and as such, only returns the interfaces directly implemented * or extended by this type. */ - ResolvedJavaType[] getInterfaces(); + List getInterfaces(); /** * Gets the single implementor of this type. Calling this method on a non-interface type causes @@ -292,16 +283,16 @@ default ResolvedJavaMethod resolveConcreteMethod(ResolvedJavaMethod method, Reso * * @param includeSuperclasses if true, then non-static fields for the complete hierarchy of this * type are included in the result with superclass fields coming before subclass fields - * @return an array of non-static fields + * @return a list of non-static fields */ - ResolvedJavaField[] getInstanceFields(boolean includeSuperclasses); + List getInstanceFields(boolean includeSuperclasses); /** * Returns the static fields of this class, including {@linkplain ResolvedJavaField#isInternal() * internal} fields. A zero-length array is returned for array and primitive types. The order of * fields returned by this method is the same as {@link Class#getDeclaredFields}. */ - ResolvedJavaField[] getStaticFields(); + List getStaticFields(); /** * Returns the instance field of this class (or one of its super classes) at the given offset, @@ -333,36 +324,36 @@ default ResolvedJavaMethod resolveConcreteMethod(ResolvedJavaMethod method, Reso ResolvedJavaType getEnclosingType(); /** - * Returns an array reflecting all the constructors declared by this type. This method is + * Returns a list reflecting all the constructors declared by this type. This method is * similar to {@link Class#getDeclaredConstructors()} in terms of returned constructors. Calling * this method forces this type to be {@link #link linked}. */ - ResolvedJavaMethod[] getDeclaredConstructors(); + List getDeclaredConstructors(); /** - * Returns an array reflecting all the constructors declared by this type. This method is + * Returns a list reflecting all the constructors declared by this type. This method is * similar to {@link Class#getDeclaredConstructors()} in terms of returned constructors. * * @param forceLink if {@code true}, forces this type to be {@link #link linked} */ - default ResolvedJavaMethod[] getDeclaredConstructors(boolean forceLink) { + default List getDeclaredConstructors(boolean forceLink) { throw new UnsupportedOperationException(); } /** - * Returns an array reflecting all the methods declared by this type. This method is similar to + * Returns a list reflecting all the methods declared by this type. This method is similar to * {@link Class#getDeclaredMethods()} in terms of returned methods. Calling this method forces * this type to be {@link #link linked}. */ - ResolvedJavaMethod[] getDeclaredMethods(); + List getDeclaredMethods(); /** - * Returns an array reflecting all the methods declared by this type. This method is similar to + * Returns a list reflecting all the methods declared by this type. This method is similar to * {@link Class#getDeclaredMethods()} in terms of returned methods. * * @param forceLink if {@code true}, forces this type to be {@link #link linked} */ - default ResolvedJavaMethod[] getDeclaredMethods(boolean forceLink) { + default List getDeclaredMethods(boolean forceLink) { throw new UnsupportedOperationException(); } diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/Signature.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/Signature.java index 88d46996f5ec1..75df0ad0b2b59 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/Signature.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/Signature.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2025, 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 @@ -22,6 +22,8 @@ */ package jdk.vm.ci.meta; +import java.util.List; + /** * Represents a method signature provided by the runtime. * @@ -100,7 +102,7 @@ default String toMethodDescriptor() { return sb.toString(); } - default JavaType[] toParameterTypes(JavaType receiverType) { + default List toParameterTypes(JavaType receiverType) { int args = getParameterCount(false); JavaType[] result; int i = 0; @@ -114,10 +116,10 @@ default JavaType[] toParameterTypes(JavaType receiverType) { for (int j = 0; j < args; j++) { result[i + j] = getParameterType(j, null); } - return result; + return MetaUtil.listFromTrustedArray(result); } - default JavaKind[] toParameterKinds(boolean receiver) { + default List toParameterKinds(boolean receiver) { int args = getParameterCount(false); JavaKind[] result; int i = 0; @@ -131,6 +133,6 @@ default JavaKind[] toParameterKinds(boolean receiver) { for (int j = 0; j < args; j++) { result[i + j] = getParameterKind(j); } - return result; + return MetaUtil.listFromTrustedArray(result); } } From 649a49105833c4ff9418b38b7e4e0b438dd42c89 Mon Sep 17 00:00:00 2001 From: Yudi Zheng Date: Mon, 16 Jun 2025 20:59:47 +0200 Subject: [PATCH 05/11] Fix compilation issue --- src/java.base/share/classes/module-info.java | 3 ++- .../ci/hotspot/riscv64/RISCV64HotSpotJVMCIBackendFactory.java | 1 + .../share/classes/jdk/vm/ci/meta/JavaTypeProfile.java | 1 - 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/java.base/share/classes/module-info.java b/src/java.base/share/classes/module-info.java index 43d148a342886..a37150c56a63c 100644 --- a/src/java.base/share/classes/module-info.java +++ b/src/java.base/share/classes/module-info.java @@ -174,7 +174,8 @@ jdk.management, jdk.net, jdk.sctp, - jdk.crypto.cryptoki; + jdk.crypto.cryptoki, + jdk.internal.vm.ci; exports jdk.internal.classfile.components to jdk.jfr; exports jdk.internal.foreign to diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/riscv64/RISCV64HotSpotJVMCIBackendFactory.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/riscv64/RISCV64HotSpotJVMCIBackendFactory.java index f8a5b59e3398c..35b6bea6c6d32 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/riscv64/RISCV64HotSpotJVMCIBackendFactory.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/riscv64/RISCV64HotSpotJVMCIBackendFactory.java @@ -24,6 +24,7 @@ import static jdk.vm.ci.common.InitTimer.timer; +import java.util.Collections; import java.util.EnumSet; import java.util.Map; import jdk.vm.ci.code.Architecture; diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/JavaTypeProfile.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/JavaTypeProfile.java index e397477838bd1..8f966378ff2f1 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/JavaTypeProfile.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/JavaTypeProfile.java @@ -26,7 +26,6 @@ import java.util.ArrayList; import java.util.List; -import jdk.internal.access.SharedSecrets; import jdk.vm.ci.meta.JavaTypeProfile.ProfiledType; /** From 6bcd689f5e7f806149459d225fc5c018274eb628 Mon Sep 17 00:00:00 2001 From: Yudi Zheng Date: Mon, 16 Jun 2025 21:10:34 +0200 Subject: [PATCH 06/11] Remove HotSpotMethod --- .../jdk/vm/ci/hotspot/HotSpotMethod.java | 81 ------------------- .../HotSpotResolvedJavaMethodImpl.java | 51 +++++++++++- 2 files changed, 50 insertions(+), 82 deletions(-) delete mode 100644 src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotMethod.java diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotMethod.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotMethod.java deleted file mode 100644 index c2145b298b622..0000000000000 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotMethod.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (c) 2011, 2019, 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 - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package jdk.vm.ci.hotspot; - -import static java.util.FormattableFlags.ALTERNATE; -import static java.util.FormattableFlags.LEFT_JUSTIFY; -import static java.util.FormattableFlags.UPPERCASE; - -import java.util.Formattable; -import java.util.Formatter; - -import jdk.vm.ci.meta.JavaMethod; -import jdk.vm.ci.meta.ResolvedJavaMethod; - -abstract class HotSpotMethod implements JavaMethod, Formattable { - - public static String applyFormattingFlagsAndWidth(String s, int flags, int width) { - if (flags == 0 && width < 0) { - return s; - } - StringBuilder sb = new StringBuilder(s); - - // apply width and justification - int len = sb.length(); - if (len < width) { - for (int i = 0; i < width - len; i++) { - if ((flags & LEFT_JUSTIFY) == LEFT_JUSTIFY) { - sb.append(' '); - } else { - sb.insert(0, ' '); - } - } - } - - String res = sb.toString(); - if ((flags & UPPERCASE) == UPPERCASE) { - res = res.toUpperCase(); - } - return res; - } - - /** - * Controls whether {@link #toString()} includes the qualified or simple name of the class in - * which the method is declared. - */ - public static final boolean FULLY_QUALIFIED_METHOD_NAME = false; - - @Override - public final String toString() { - char h = FULLY_QUALIFIED_METHOD_NAME ? 'H' : 'h'; - String suffix = this instanceof ResolvedJavaMethod ? "" : ", unresolved"; - String fmt = String.format("HotSpotMethod<%%%c.%%n(%%p)%s>", h, suffix); - return format(fmt); - } - - @Override - public void formatTo(Formatter formatter, int flags, int width, int precision) { - String base = (flags & ALTERNATE) == ALTERNATE ? getName() : toString(); - formatter.format(applyFormattingFlagsAndWidth(base, flags & ~ALTERNATE, width)); - } -} diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotResolvedJavaMethodImpl.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotResolvedJavaMethodImpl.java index 2e90e49f77e8b..943f08967ad5d 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotResolvedJavaMethodImpl.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotResolvedJavaMethodImpl.java @@ -22,6 +22,9 @@ */ package jdk.vm.ci.hotspot; +import static java.util.FormattableFlags.ALTERNATE; +import static java.util.FormattableFlags.LEFT_JUSTIFY; +import static java.util.FormattableFlags.UPPERCASE; import static jdk.vm.ci.hotspot.CompilerToVM.compilerToVM; import static jdk.vm.ci.hotspot.CompilerToVM.listFromTrustedArray; import static jdk.vm.ci.hotspot.HotSpotJVMCIRuntime.runtime; @@ -38,6 +41,8 @@ import java.lang.reflect.Type; import java.util.BitSet; import java.util.Collections; +import java.util.Formattable; +import java.util.Formatter; import java.util.List; import jdk.internal.vm.VMSupport; @@ -62,7 +67,7 @@ /** * Implementation of {@link JavaMethod} for resolved HotSpot methods. */ -final class HotSpotResolvedJavaMethodImpl extends HotSpotMethod implements HotSpotResolvedJavaMethod, MetaspaceHandleObject { +final class HotSpotResolvedJavaMethodImpl implements JavaMethod, Formattable, HotSpotResolvedJavaMethod, MetaspaceHandleObject { /** * A {@code jmetadata} value that is a handle to {@code Method*} value. @@ -799,4 +804,48 @@ public BitSet getOopMapAt(int bci) { compilerToVM().getOopMapAt(this, bci, oopMap); return BitSet.valueOf(oopMap); } + + private static String applyFormattingFlagsAndWidth(String s, int flags, int width) { + if (flags == 0 && width < 0) { + return s; + } + StringBuilder sb = new StringBuilder(s); + + // apply width and justification + int len = sb.length(); + if (len < width) { + for (int i = 0; i < width - len; i++) { + if ((flags & LEFT_JUSTIFY) == LEFT_JUSTIFY) { + sb.append(' '); + } else { + sb.insert(0, ' '); + } + } + } + + String res = sb.toString(); + if ((flags & UPPERCASE) == UPPERCASE) { + res = res.toUpperCase(); + } + return res; + } + + /** + * Controls whether {@link #toString()} includes the qualified or simple name of the class in + * which the method is declared. + */ + private static final boolean FULLY_QUALIFIED_METHOD_NAME = false; + + @Override + public final String toString() { + char h = FULLY_QUALIFIED_METHOD_NAME ? 'H' : 'h'; + String fmt = String.format("HotSpotMethod<%%%c.%%n(%%p)>", h); + return format(fmt); + } + + @Override + public void formatTo(Formatter formatter, int flags, int width, int precision) { + String base = (flags & ALTERNATE) == ALTERNATE ? getName() : toString(); + formatter.format(applyFormattingFlagsAndWidth(base, flags & ~ALTERNATE, width)); + } } From c114c4c2222f188f84569fe062f54945cbcba77a Mon Sep 17 00:00:00 2001 From: Andrej Pecimuth Date: Sun, 15 Sep 2024 16:51:53 +0200 Subject: [PATCH 07/11] JVMCI refactorings to enable replay compilation in Graal. --- .../classes/jdk/vm/ci/code/BytecodeFrame.java | 10 ++ .../classes/jdk/vm/ci/code/VirtualObject.java | 18 +++- .../classes/jdk/vm/ci/code/site/Site.java | 4 +- .../vm/ci/hotspot/HotSpotCompiledCode.java | 95 ++++++++++++++++++- .../vm/ci/hotspot/HotSpotCompiledNmethod.java | 38 ++++++++ .../jdk/vm/ci/hotspot/HotSpotJavaType.java | 2 +- .../jdk/vm/ci/hotspot/HotSpotMethod.java | 81 ++++++++++++++++ .../vm/ci/hotspot/HotSpotObjectConstant.java | 28 +++++- .../ci/hotspot/HotSpotObjectConstantImpl.java | 10 +- .../ci/hotspot/HotSpotResolvedJavaType.java | 20 ++-- .../ci/hotspot/HotSpotResolvedObjectType.java | 7 ++ .../HotSpotResolvedObjectTypeImpl.java | 4 +- .../hotspot/HotSpotResolvedPrimitiveType.java | 13 ++- .../vm/ci/hotspot/HotSpotSpeculationLog.java | 24 ++++- .../vm/ci/hotspot/HotSpotVMConfigAccess.java | 2 +- .../classes/jdk/vm/ci/hotspot/VMField.java | 2 +- .../vm/ci/meta/EncodedSpeculationReason.java | 21 ++++ 17 files changed, 346 insertions(+), 33 deletions(-) create mode 100644 src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotMethod.java diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/BytecodeFrame.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/BytecodeFrame.java index 84913b97504c2..2bd2ddd752986 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/BytecodeFrame.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/BytecodeFrame.java @@ -387,4 +387,14 @@ public boolean equals(Object obj) { public String toString() { return CodeUtil.append(new StringBuilder(100), this).toString(); } + + /** + * Returns a copy of the array describing the Java kinds in {@link #values}. + * The returned array represents the kinds for the locals and the operand stack. + * + * @return a copy of the slot kinds array + */ + public JavaKind[] getSlotKinds() { + return (slotKinds == null) ? null : Arrays.copyOf(slotKinds, slotKinds.length); + } } diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/VirtualObject.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/VirtualObject.java index 85d314b5df62b..384cc5be3d4ae 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/VirtualObject.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/VirtualObject.java @@ -22,6 +22,7 @@ */ package jdk.vm.ci.code; +import java.util.Arrays; import java.util.Collections; import java.util.IdentityHashMap; import java.util.List; @@ -290,10 +291,12 @@ public boolean equals(Object o) { return true; } if (o instanceof VirtualObject l) { - if (!l.type.equals(type) || l.values.length != values.length) { + int lValuesLength = (l.values == null) ? 0 : l.values.length; + int valuesLength = (values == null) ? 0 : values.length; + if (!l.type.equals(type) || lValuesLength != valuesLength) { return false; } - for (int i = 0; i < values.length; i++) { + for (int i = 0; i < valuesLength; i++) { /* * Virtual objects can form cycles. Calling equals() could therefore lead to * infinite recursion. @@ -310,4 +313,15 @@ public boolean equals(Object o) { private static boolean same(Object o1, Object o2) { return o1 == o2; } + + /** + * Returns a copy of the array containing the Java kinds of the values stored in this + * virtual object. + * + * @return a copy of the array containing the Java kinds of the values or {@code null} if the + * values have not been initialized. + */ + public JavaKind[] getSlotKinds() { + return (slotKinds == null) ? null : Arrays.copyOf(slotKinds, slotKinds.length); + } } diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/site/Site.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/site/Site.java index dbf76c58be05b..7d1239fea0e95 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/site/Site.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/site/Site.java @@ -39,8 +39,8 @@ public Site(int pos) { } @Override - public final int hashCode() { - throw new UnsupportedOperationException("hashCode"); + public int hashCode() { + return 41 * pcOffset; } @Override diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotCompiledCode.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotCompiledCode.java index 306b5577f70c6..725c8511343bd 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotCompiledCode.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotCompiledCode.java @@ -33,7 +33,7 @@ import jdk.vm.ci.meta.ResolvedJavaField; import jdk.vm.ci.meta.ResolvedJavaMethod; -import java.util.List; +import java.util.Arrays; /** * A {@link CompiledCode} with additional HotSpot-specific information required for installing the @@ -188,4 +188,97 @@ public int getOffset(ResolvedJavaField field) { } }); } + + /** + * Returns a copy of the compiled machine code. + */ + public byte[] getTargetCode() { + return (targetCode == null) ? null : Arrays.copyOf(targetCode, targetCode.length); + } + + /** + * Gets the size of the compiled machine code in bytes. + */ + public int getTargetCodeSize() { + return targetCodeSize; + } + + /** + * Returns a copy of the array of {@link Site} objects associated with this compiled code. + */ + public Site[] getSites() { + return (sites == null) ? null : Arrays.copyOf(sites, sites.length); + } + + /** + * Returns a copy of the array of {@link Assumption} objects associated with this compiled code. + */ + public Assumption[] getAssumptions() { + return (assumptions == null) ? null : Arrays.copyOf(assumptions, assumptions.length); + } + + /** + * Returns a copy of the array of {@link ResolvedJavaMethod} objects representing the methods + * whose bytecodes were used as input to the compilation. If the compilation did not record + * method dependencies, this method returns {@code null}. Otherwise, the first element of the + * returned array is the root method of the compilation. + * + * @return a copy of the array of methods associated with this compiled code or {@code null} + * if no methods were recorded + */ + public ResolvedJavaMethod[] getMethods() { + return (methods == null) ? null : Arrays.copyOf(methods, methods.length); + } + + /** + * Returns a copy of the array of {@link Comment} objects associated with this compiled code. + */ + public Comment[] getComments() { + return Arrays.copyOf(comments, comments.length); + } + + /** + * Returns a copy of the data section containing serialized constants for the emitted machine code. + */ + public byte[] getDataSection() { + return (dataSection == null) ? null : Arrays.copyOf(dataSection, dataSection.length); + } + + /** + * Gets the minimum alignment of the data section. + */ + public int getDataSectionAlignment() { + return dataSectionAlignment; + } + + /** + * Returns a copy of the array of {@link DataPatch} objects representing the relocations in the + * {@linkplain #getDataSection() data section}. + * + * @return a copy of the array of data section patches or {@code null} if there are no patches + */ + public DataPatch[] getDataSectionPatches() { + return (dataSectionPatches == null) ? null : Arrays.copyOf(dataSectionPatches, dataSectionPatches.length); + } + + /** + * Checks if this compiled code is immutable and position independent. + */ + public boolean isImmutablePIC() { + return isImmutablePIC; + } + + /** + * Gets the total size of the stack frame of this compiled method. + */ + public int getTotalFrameSize() { + return totalFrameSize; + } + + /** + * Gets the deoptimization rescue slot associated with this compiled code. + */ + public StackSlot getDeoptRescueSlot() { + return deoptRescueSlot; + } } diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotCompiledNmethod.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotCompiledNmethod.java index 4bd4dd6f77ff1..22c5772631745 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotCompiledNmethod.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotCompiledNmethod.java @@ -118,4 +118,42 @@ public boolean hasScopedAccess() { return false; } + /** + * Returns the method to which this compiled nmethod belongs. + */ + public HotSpotResolvedJavaMethod getMethod() { + return method; + } + + /** + * Returns the bytecode index (BCI) in the {@link #getMethod() method} that is the beginning of this compiled + * nmethod. -1 denotes the beginning of the method. + */ + public int getEntryBCI() { + return entryBCI; + } + + /** + * Returns the identifier of the compilation request. + */ + public int getId() { + return id; + } + + /** + * Returns the address of a native {@code JVMCICompileState} object associated with this compiled nmethod. + * If no such object exists, it returns 0L. + * + * @return the address of the native {@code JVMCICompileState} object or 0L if it does not exist + */ + public long getCompileState() { + return compileState; + } + + /** + * Checks if this compiled nmethod has a memory access via the {@code Unsafe} class. + */ + public boolean hasUnsafeAccess() { + return hasUnsafeAccess; + } } diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotJavaType.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotJavaType.java index ef8253596d8af..792c7bc00a276 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotJavaType.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotJavaType.java @@ -36,7 +36,7 @@ public HotSpotJavaType(String name) { } @Override - public final String getName() { + public String getName() { return name; } } diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotMethod.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotMethod.java new file mode 100644 index 0000000000000..98006237a5c71 --- /dev/null +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotMethod.java @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2011, 2019, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package jdk.vm.ci.hotspot; + +import static java.util.FormattableFlags.ALTERNATE; +import static java.util.FormattableFlags.LEFT_JUSTIFY; +import static java.util.FormattableFlags.UPPERCASE; + +import java.util.Formattable; +import java.util.Formatter; + +import jdk.vm.ci.meta.JavaMethod; +import jdk.vm.ci.meta.ResolvedJavaMethod; + +public abstract class HotSpotMethod implements JavaMethod, Formattable { + + public static String applyFormattingFlagsAndWidth(String s, int flags, int width) { + if (flags == 0 && width < 0) { + return s; + } + StringBuilder sb = new StringBuilder(s); + + // apply width and justification + int len = sb.length(); + if (len < width) { + for (int i = 0; i < width - len; i++) { + if ((flags & LEFT_JUSTIFY) == LEFT_JUSTIFY) { + sb.append(' '); + } else { + sb.insert(0, ' '); + } + } + } + + String res = sb.toString(); + if ((flags & UPPERCASE) == UPPERCASE) { + res = res.toUpperCase(); + } + return res; + } + + /** + * Controls whether {@link #toString()} includes the qualified or simple name of the class in + * which the method is declared. + */ + public static final boolean FULLY_QUALIFIED_METHOD_NAME = false; + + @Override + public final String toString() { + char h = FULLY_QUALIFIED_METHOD_NAME ? 'H' : 'h'; + String suffix = this instanceof ResolvedJavaMethod ? "" : ", unresolved"; + String fmt = String.format("HotSpotMethod<%%%c.%%n(%%p)%s>", h, suffix); + return format(fmt); + } + + @Override + public void formatTo(Formatter formatter, int flags, int width, int precision) { + String base = (flags & ALTERNATE) == ALTERNATE ? getName() : toString(); + formatter.format(applyFormattingFlagsAndWidth(base, flags & ~ALTERNATE, width)); + } +} diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotObjectConstant.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotObjectConstant.java index 227fcb731a9f4..bed38f9198845 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotObjectConstant.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotObjectConstant.java @@ -22,14 +22,15 @@ */ package jdk.vm.ci.hotspot; -import java.lang.invoke.CallSite; -import java.util.Objects; - import jdk.vm.ci.meta.Assumptions; import jdk.vm.ci.meta.JavaConstant; import jdk.vm.ci.meta.ResolvedJavaType; import jdk.vm.ci.meta.VMConstant; +import java.lang.invoke.CallSite; +import java.lang.invoke.ConstantCallSite; +import java.util.Objects; + /** * Represents a constant non-{@code null} object reference, within the compiler and across the * compiler/runtime interface. @@ -61,7 +62,26 @@ public interface HotSpotObjectConstant extends JavaConstant, HotSpotConstant, VM * change * @return {@code null} if this constant does not represent a {@link CallSite} object */ - JavaConstant getCallSiteTarget(Assumptions assumptions); + default JavaConstant getCallSiteTarget(Assumptions assumptions) { + Assumptions.AssumptionResult result = getCallSiteTarget(); + if (!result.canRecordTo(assumptions)) { + return null; + } + result.recordTo(assumptions); + return result.getResult(); + } + + /** + * Gets the result of {@link CallSite#getTarget()} for the {@link CallSite} object represented + * by this constant. The target is bound to an assumption if this is not a fully initialized + * {@link ConstantCallSite}. + * + * @return a call-site target (possibly bound to an assumption) or {@code null} if this constant + * does not represent a {@link CallSite} object + */ + default Assumptions.AssumptionResult getCallSiteTarget() { + throw new UnsupportedOperationException("getCallSiteTarget"); + } /** * Determines if this constant represents an {@linkplain String#intern() interned} string. diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotObjectConstantImpl.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotObjectConstantImpl.java index 0f70db0708afe..6b2d31a2c8cca 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotObjectConstantImpl.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotObjectConstantImpl.java @@ -89,19 +89,15 @@ private HotSpotObjectConstantImpl readTarget() { } @Override - public JavaConstant getCallSiteTarget(Assumptions assumptions) { + public Assumptions.AssumptionResult getCallSiteTarget() { if (runtime().getCallSite().isInstance(this)) { // For ConstantCallSites, we need to read "isFrozen" before reading "target" // isFullyInitializedConstantCallSite() reads "isFrozen" if (isFullyInitializedConstantCallSite()) { - return readTarget(); - } - if (assumptions == null) { - return null; + return new Assumptions.AssumptionResult<>(readTarget()); } HotSpotObjectConstantImpl result = readTarget(); - assumptions.record(new Assumptions.CallSiteTargetValue(this, result)); - return result; + return new Assumptions.AssumptionResult<>(result, new Assumptions.CallSiteTargetValue(this, result)); } return null; } diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotResolvedJavaType.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotResolvedJavaType.java index fbb5a3fc9b5c4..4d4e73761378e 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotResolvedJavaType.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotResolvedJavaType.java @@ -27,9 +27,9 @@ public abstract class HotSpotResolvedJavaType extends HotSpotJavaType implements ResolvedJavaType { - HotSpotResolvedObjectTypeImpl arrayOfType; + HotSpotResolvedObjectType arrayOfType; - HotSpotResolvedJavaType(String name) { + protected HotSpotResolvedJavaType(String name) { super(name); } @@ -37,16 +37,22 @@ public abstract class HotSpotResolvedJavaType extends HotSpotJavaType implements public abstract boolean equals(Object obj); @Override - public final int hashCode() { + public int hashCode() { return getName().hashCode(); } - abstract JavaConstant getJavaMirror(); + /** + * Gets the runtime representation of the {@link Class} object of this type. + */ + public abstract JavaConstant getJavaMirror(); - abstract HotSpotResolvedObjectTypeImpl getArrayType(); + /** + * Gets the array type of this type without caching the result. + */ + protected abstract HotSpotResolvedObjectType getArrayType(); @Override - public final HotSpotResolvedObjectType getArrayClass() { + public HotSpotResolvedObjectType getArrayClass() { if (arrayOfType == null) { arrayOfType = getArrayType(); } @@ -60,5 +66,5 @@ public final HotSpotResolvedObjectType getArrayClass() { * * @return {@code true} if this type is being initialized */ - abstract boolean isBeingInitialized(); + protected abstract boolean isBeingInitialized(); } diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotResolvedObjectType.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotResolvedObjectType.java index 13755d92a9ac0..c3d440ca33648 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotResolvedObjectType.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotResolvedObjectType.java @@ -79,6 +79,13 @@ default JavaKind getJavaKind() { @Override AssumptionResult findUniqueConcreteMethod(ResolvedJavaMethod method); + /** + * Gets the runtime representation of the {@link Class} object of this type. + */ + default JavaConstant getJavaMirror() { + throw new UnsupportedOperationException("getJavaMirror"); + } + /** * Performs a fast-path check that this type is resolved in the context of a given accessing * class. A negative result does not mean this type is not resolved with respect to diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotResolvedObjectTypeImpl.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotResolvedObjectTypeImpl.java index ed3d40428f472..fc1e9f2409727 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotResolvedObjectTypeImpl.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotResolvedObjectTypeImpl.java @@ -663,12 +663,12 @@ public boolean equals(Object obj) { } @Override - JavaConstant getJavaMirror() { + public JavaConstant getJavaMirror() { return mirror; } @Override - HotSpotResolvedObjectTypeImpl getArrayType() { + protected HotSpotResolvedObjectTypeImpl getArrayType() { return runtime().compilerToVm.getArrayType((char) 0, this); } diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotResolvedPrimitiveType.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotResolvedPrimitiveType.java index c66a885de2104..4f73a8186a1c9 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotResolvedPrimitiveType.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotResolvedPrimitiveType.java @@ -60,7 +60,13 @@ private HotSpotResolvedPrimitiveType(JavaKind kind, HotSpotObjectConstantImpl mi this.kind = kind; } - static HotSpotResolvedPrimitiveType forKind(JavaKind kind) { + /** + * Returns a primitive type instance corresponding to the given {@link JavaKind}. + * + * @param kind the Java kind of the primitive type + * @return the primitive type instance for the given Java kind + */ + public static HotSpotResolvedPrimitiveType forKind(JavaKind kind) { HotSpotResolvedPrimitiveType primitive = primitives[kind.getBasicType()]; assert primitive != null : kind; return primitive; @@ -83,7 +89,7 @@ public int getModifiers() { } @Override - HotSpotResolvedObjectTypeImpl getArrayType() { + protected HotSpotResolvedObjectType getArrayType() { if (kind == JavaKind.Void) { return null; } @@ -319,7 +325,7 @@ public boolean equals(Object obj) { } @Override - JavaConstant getJavaMirror() { + public JavaConstant getJavaMirror() { return mirror; } @@ -332,5 +338,4 @@ public AnnotationData getAnnotationData(ResolvedJavaType type) { public List getAnnotationData(ResolvedJavaType type1, ResolvedJavaType type2, ResolvedJavaType... types) { return List.of(); } - } diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotSpeculationLog.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotSpeculationLog.java index d6e19e118e7ae..de198663db726 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotSpeculationLog.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotSpeculationLog.java @@ -28,6 +28,7 @@ import java.util.Arrays; import java.util.Formatter; import java.util.List; +import java.util.Objects; import jdk.vm.ci.code.BailoutException; import jdk.vm.ci.common.JVMCIError; @@ -130,7 +131,7 @@ public static final class HotSpotSpeculation extends Speculation { private final byte[] encoding; - HotSpotSpeculation(SpeculationReason reason, JavaConstant id, byte[] encoding) { + public HotSpotSpeculation(SpeculationReason reason, JavaConstant id, byte[] encoding) { super(reason); this.id = id; this.encoding = encoding; @@ -140,6 +141,13 @@ public JavaConstant getEncoding() { return id; } + /** + * Returns a copy of the speculation reason encoding. + */ + public byte[] getReasonEncoding() { + return (encoding == null) ? null : Arrays.copyOf(encoding, encoding.length); + } + @Override public String toString() { long indexAndLength = id.asLong(); @@ -147,6 +155,20 @@ public String toString() { int length = decodeLength(indexAndLength); return String.format("{0x%016x[index: %d, len: %d, hash: 0x%x]: %s}", indexAndLength, index, length, Arrays.hashCode(encoding), getReason()); } + + @Override + public boolean equals(Object object) { + if (object instanceof HotSpotSpeculation that) { + return getReason().equals(that.getReason()) && id.equals(that.id) && Arrays.equals(encoding, that.encoding); + } else { + return false; + } + } + + @Override + public int hashCode() { + return Objects.hash(getReason(), id, Arrays.hashCode(encoding)); + } } /** diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotVMConfigAccess.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotVMConfigAccess.java index 9954c700ca7b3..15bd58a5a5d25 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotVMConfigAccess.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotVMConfigAccess.java @@ -305,7 +305,7 @@ private T getFieldValue0(String name, Class type, T notPresent, String in * @return the field * @throws JVMCIError if the field is not present and {@code required == true} */ - private VMField getField(String name, String cppType, boolean required) { + public VMField getField(String name, String cppType, boolean required) { VMField entry = store.vmFields.get(name); if (entry == null) { if (!required) { diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/VMField.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/VMField.java index 3a294f5d9feef..21755445ca0ee 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/VMField.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/VMField.java @@ -66,7 +66,7 @@ public boolean isStatic() { * Creates a description of a non-static field. */ @VMEntryPoint - VMField(String name, String type, long offset, long address, Object value) { + public VMField(String name, String type, long offset, long address, Object value) { this.name = name; this.type = type; this.offset = offset; diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/EncodedSpeculationReason.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/EncodedSpeculationReason.java index 7c1454caf35e0..0b14170f86904 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/EncodedSpeculationReason.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/EncodedSpeculationReason.java @@ -107,4 +107,25 @@ public int hashCode() { public String toString() { return String.format("%s@%d%s", groupName, groupId, Arrays.toString(context)); } + + /** + * Returns the group ID of this speculation reason. + */ + public int getGroupId() { + return groupId; + } + + /** + * Returns the group name of this speculation reason. + */ + public String getGroupName() { + return groupName; + } + + /** + * Returns a copy of the array of context objects. + */ + public Object[] getContext() { + return (context == null) ? null : Arrays.copyOf(context, context.length); + } } From 1687ec8a82653e5c800422c1e5c8544e1670675f Mon Sep 17 00:00:00 2001 From: Yudi Zheng Date: Mon, 16 Jun 2025 23:47:00 +0200 Subject: [PATCH 08/11] Replace raw arrays with List -- address comment --- .../classes/jdk/vm/ci/code/BytecodeFrame.java | 40 +++---- .../classes/jdk/vm/ci/code/CodeUtil.java | 9 ++ .../classes/jdk/vm/ci/code/VirtualObject.java | 27 ++--- .../vm/ci/hotspot/HotSpotCompiledCode.java | 112 ++++++++++-------- .../ci/hotspot/HotSpotCompiledCodeStream.java | 29 +++-- .../vm/ci/hotspot/HotSpotCompiledNmethod.java | 81 ++++++++----- .../jdk/vm/ci/hotspot/HotSpotSignature.java | 15 --- .../jdk/vm/ci/meta/LocalVariableTable.java | 2 +- .../classes/jdk/vm/ci/meta/MetaUtil.java | 25 ++-- 9 files changed, 181 insertions(+), 159 deletions(-) diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/BytecodeFrame.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/BytecodeFrame.java index 2bd2ddd752986..ea1a9edbd8969 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/BytecodeFrame.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/BytecodeFrame.java @@ -23,6 +23,7 @@ package jdk.vm.ci.code; import java.util.Arrays; +import java.util.List; import java.util.Objects; import jdk.vm.ci.common.JVMCIError; @@ -31,6 +32,8 @@ import jdk.vm.ci.meta.ResolvedJavaMethod; import jdk.vm.ci.meta.Value; +import static jdk.vm.ci.code.CodeUtil.listFromTrustedArray; + /** * Represents the Java bytecode frame state(s) at a given position including {@link Value locations} * where to find the local variables, operand stack values and locked objects of the bytecode @@ -75,10 +78,10 @@ public final class BytecodeFrame extends BytecodePosition { public final JavaValue[] values; /** - * An array describing the Java kinds in {@link #values}. It records a kind for the locals and + * A list describing the Java kinds in {@link #values}. It records a kind for the locals and * the operand stack. */ - private final JavaKind[] slotKinds; + private final List slotKinds; /** * The number of locals in the values array. @@ -221,7 +224,7 @@ public BytecodeFrame(BytecodeFrame caller, this.rethrowException = rethrowException; this.duringCall = duringCall; this.values = values; - this.slotKinds = slotKinds; + this.slotKinds = listFromTrustedArray(slotKinds); this.numLocals = numLocals; this.numStack = numStack; this.numLocks = numLocks; @@ -239,19 +242,19 @@ public void verifyInvariants() { if (values.length != numLocals + numStack + numLocks) { throw new JVMCIError("unexpected values length %d in frame (%d locals, %d stack slots, %d locks)", values.length, numLocals, numStack, numLocks); } - if (slotKinds.length != numLocals + numStack) { + if (slotKinds.size() != numLocals + numStack) { throw new JVMCIError("unexpected slotKinds length %d in frame (%d locals, %d stack slots)", values.length, numLocals, numStack); } - for (int i = 0; i < slotKinds.length; i++) { + for (int i = 0; i < slotKinds.size(); i++) { Objects.requireNonNull(values[i]); - JavaKind kind = slotKinds[i]; + JavaKind kind = slotKinds.get(i); if (kind.needsTwoSlots()) { if (i + 1 >= values.length || values[i + 1] != Value.ILLEGAL) { throw new JVMCIError("2 slot value at index %d not followed by Value.ILLEGAL", i); } } } - for (int i = slotKinds.length; i < values.length; i++) { + for (int i = slotKinds.size(); i < values.length; i++) { JavaValue lock = values[i]; Objects.requireNonNull(lock); if (!(lock instanceof StackLockValue)) { @@ -271,10 +274,10 @@ public boolean validateFormat() { } for (int i = 0; i < numLocals + numStack; i++) { if (values[i] != null) { - JavaKind kind = slotKinds[i]; + JavaKind kind = slotKinds.get(i); if (kind.needsTwoSlots()) { - assert slotKinds.length > i + 1 : String.format("missing second word %s", this); - assert slotKinds[i + 1] == JavaKind.Illegal : this; + assert slotKinds.size() > i + 1 : String.format("missing second word %s", this); + assert slotKinds.get(i + 1) == JavaKind.Illegal : this; } } } @@ -290,7 +293,7 @@ public boolean validateFormat() { */ public JavaKind getLocalValueKind(int i) { Objects.checkIndex(i, numLocals); - return slotKinds[i]; + return slotKinds.get(i); } /** @@ -302,7 +305,7 @@ public JavaKind getLocalValueKind(int i) { */ public JavaKind getStackValueKind(int i) { Objects.checkIndex(i, numStack); - return slotKinds[i + numLocals]; + return slotKinds.get(i + numLocals); } /** @@ -358,7 +361,7 @@ public int hashCode() { numLocks, numStack, rethrowException, - Arrays.hashCode(slotKinds), + slotKinds, Arrays.hashCode(values)); } @@ -379,7 +382,7 @@ public boolean equals(Object obj) { numLocks == that.numLocks && numStack == that.numStack && rethrowException == that.rethrowException && - Arrays.equals(slotKinds, that.slotKinds) && + slotKinds.equals(that.slotKinds) && Arrays.equals(values, that.values); } @@ -389,12 +392,9 @@ public String toString() { } /** - * Returns a copy of the array describing the Java kinds in {@link #values}. - * The returned array represents the kinds for the locals and the operand stack. - * - * @return a copy of the slot kinds array + * Returns the list describing the Java kinds in {@link #values}. */ - public JavaKind[] getSlotKinds() { - return (slotKinds == null) ? null : Arrays.copyOf(slotKinds, slotKinds.length); + public List getSlotKinds() { + return slotKinds; } } diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/CodeUtil.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/CodeUtil.java index 68a0cce9a871d..ef9643e71cf49 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/CodeUtil.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/CodeUtil.java @@ -25,8 +25,10 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; +import java.util.List; import java.util.Map; +import jdk.internal.access.SharedSecrets; import jdk.vm.ci.meta.JavaType; import jdk.vm.ci.meta.MetaUtil; import jdk.vm.ci.meta.ResolvedJavaMethod; @@ -432,4 +434,11 @@ public static CallingConvention getCallingConvention(CodeCacheProvider codeCache RegisterConfig registerConfig = codeCache.getRegisterConfig(); return registerConfig.getCallingConvention(type, retType, argTypes, valueKindFactory); } + + /** + * Creates an immutable list from a trusted array that has no references retained by the caller. + */ + static List listFromTrustedArray(Object[] array) { + return SharedSecrets.getJavaUtilCollectionAccess().listFromTrustedArray(array); + } } diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/VirtualObject.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/VirtualObject.java index 384cc5be3d4ae..56576a4da1732 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/VirtualObject.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/VirtualObject.java @@ -22,7 +22,6 @@ */ package jdk.vm.ci.code; -import java.util.Arrays; import java.util.Collections; import java.util.IdentityHashMap; import java.util.List; @@ -34,6 +33,8 @@ import jdk.vm.ci.meta.ResolvedJavaField; import jdk.vm.ci.meta.ResolvedJavaType; +import static jdk.vm.ci.code.CodeUtil.listFromTrustedArray; + /** * An instance of this class represents an object whose allocation was removed by escape analysis. * The information stored in the {@link VirtualObject} is used during deoptimization to recreate the @@ -43,7 +44,7 @@ public final class VirtualObject implements JavaValue { private final ResolvedJavaType type; private JavaValue[] values; - private JavaKind[] slotKinds; + private List slotKinds; private final int id; private final boolean isAutoBox; @@ -119,7 +120,7 @@ private static StringBuilder appendValue(StringBuilder buf, JavaValue value, Set } else { ResolvedJavaField field = fields.get(fieldIndex); buf.append(field.getName()); - if (vo.slotKinds[i].getSlotCount() == 2 && field.getType().getJavaKind().getSlotCount() == 1) { + if (vo.slotKinds.get(i).getSlotCount() == 2 && field.getType().getJavaKind().getSlotCount() == 1) { if (fieldIndex + 1 >= fields.size()) { buf.append("/"); } else { @@ -158,7 +159,7 @@ public void verifyLayout(LayoutVerifier verifier) { List fields = type.getInstanceFields(true); int fieldIndex = 0; for (int i = 0; i < values.length; i++, fieldIndex++) { - JavaKind slotKind = slotKinds[i]; + JavaKind slotKind = slotKinds.get(i); if (fieldIndex >= fields.size()) { throw new JVMCIError("Not enough fields for the values provided for %s", toString()); } else { @@ -193,13 +194,13 @@ public void verifyLayout(LayoutVerifier verifier) { } } else if (type.getComponentType().getJavaKind() == JavaKind.Byte) { for (int i = 0; i < values.length;) { - JavaKind slotkind = slotKinds[i]; + JavaKind slotkind = slotKinds.get(i); if (slotkind != JavaKind.Byte) { if (!slotkind.isPrimitive()) { throw new JVMCIError("Storing a non-primitive in a byte array: %s %s", slotkind, toString()); } int byteCount = 1; - while (++i < values.length && slotKinds[i] == JavaKind.Illegal) { + while (++i < values.length && slotKinds.get(i) == JavaKind.Illegal) { byteCount++; } /* @@ -245,7 +246,7 @@ public JavaValue[] getValues() { * Returns the kind of the value at {@code index}. */ public JavaKind getSlotKind(int index) { - return slotKinds[index]; + return slotKinds.get(index); } /** @@ -277,7 +278,7 @@ public boolean isAutoBox() { public void setValues(JavaValue[] values, JavaKind[] slotKinds) { assert values.length == slotKinds.length; this.values = values; - this.slotKinds = slotKinds; + this.slotKinds = listFromTrustedArray(slotKinds); } @Override @@ -315,13 +316,9 @@ private static boolean same(Object o1, Object o2) { } /** - * Returns a copy of the array containing the Java kinds of the values stored in this - * virtual object. - * - * @return a copy of the array containing the Java kinds of the values or {@code null} if the - * values have not been initialized. + * Returns the list containing the Java kinds of the values stored in this virtual object. */ - public JavaKind[] getSlotKinds() { - return (slotKinds == null) ? null : Arrays.copyOf(slotKinds, slotKinds.length); + public List getSlotKinds() { + return slotKinds; } } diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotCompiledCode.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotCompiledCode.java index 725c8511343bd..fb91b28b21242 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotCompiledCode.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotCompiledCode.java @@ -22,6 +22,8 @@ */ package jdk.vm.ci.hotspot; +import static jdk.vm.ci.hotspot.CompilerToVM.listFromTrustedArray; + import jdk.vm.ci.code.BytecodeFrame; import jdk.vm.ci.code.CompiledCode; import jdk.vm.ci.code.StackSlot; @@ -34,6 +36,7 @@ import jdk.vm.ci.meta.ResolvedJavaMethod; import java.util.Arrays; +import java.util.List; /** * A {@link CompiledCode} with additional HotSpot-specific information required for installing the @@ -59,24 +62,24 @@ public class HotSpotCompiledCode implements CompiledCode { /** * A list of code annotations describing special sites in {@link #targetCode}. */ - protected final Site[] sites; + protected final List sites; /** * A list of {@link Assumption} this code relies on. */ - protected final Assumption[] assumptions; + protected final List assumptions; /** * The list of the methods whose bytecodes were used as input to the compilation. If - * {@code null}, then the compilation did not record method dependencies. Otherwise, the first + * empty, then the compilation did not record method dependencies. Otherwise, the first * element of this array is the root method of the compilation. */ - protected final ResolvedJavaMethod[] methods; + protected final List methods; /** * A list of comments that will be included in code dumps. */ - protected final Comment[] comments; + protected final List comments; /** * The data section containing serialized constants for the emitted machine code. @@ -91,7 +94,7 @@ public class HotSpotCompiledCode implements CompiledCode { /** * A list of relocations in the {@link #dataSection}. */ - protected final DataPatch[] dataSectionPatches; + protected final List dataSectionPatches; /** * A flag determining whether this code is immutable and position independent. @@ -119,34 +122,50 @@ public Comment(int pcOffset, String text) { } } + /** + * @param name the name of this compilation unit. + * @param targetCode the buffer containing the emitted machine code. This array is now owned by this object and should not be mutated by the caller. + * @param targetCodeSize the leading number of bytes in {@link #targetCode} containing the emitted machine code. + * @param sites an array of code annotations describing special sites in {@link #targetCode}. This array is now owned by this object and should not be mutated by the caller. + * @param assumptions an array of {@link Assumption} this code relies on. This array is now owned by this object and should not be mutated by the caller. + * @param methods an array of the methods whose bytecodes were used as input to the compilation. This array is now owned by this object and should not be mutated by the caller. + * @param comments an array of comments that will be included in code dumps. This array is now owned by this object and should not be mutated by the caller. + * @param dataSection the data section containing serialized constants for the emitted machine code. This array is now owned by this object and should not be mutated by the caller. + * @param dataSectionAlignment the minimum alignment of the data section. + * @param dataSectionPatches an array of relocations in the {@link #dataSection}. This array is now owned by this object and should not be mutated by the caller. + * @param isImmutablePIC the flag determining whether this code is immutable and position independent. + * @param totalFrameSize the total size of the stack frame of this compiled method. + * @param deoptRescueSlot the deopt rescue slot. Must be non-null if there is a safepoint in the method. + */ public HotSpotCompiledCode(String name, - byte[] targetCode, - int targetCodeSize, - Site[] sites, - Assumption[] assumptions, - ResolvedJavaMethod[] methods, - Comment[] comments, - byte[] dataSection, - int dataSectionAlignment, - DataPatch[] dataSectionPatches, - boolean isImmutablePIC, - int totalFrameSize, - StackSlot deoptRescueSlot) { + byte[] targetCode, + int targetCodeSize, + Site[] sites, + Assumption[] assumptions, + ResolvedJavaMethod[] methods, + Comment[] comments, + byte[] dataSection, + int dataSectionAlignment, + DataPatch[] dataSectionPatches, + boolean isImmutablePIC, + int totalFrameSize, + StackSlot deoptRescueSlot) { this.name = name; - this.targetCode = targetCode.clone(); + this.targetCode = targetCode; this.targetCodeSize = targetCodeSize; - this.sites = sites; - this.assumptions = assumptions; - this.methods = methods; + this.sites = sites == null ? List.of() : listFromTrustedArray(sites); + this.assumptions = assumptions == null ? List.of() : listFromTrustedArray(assumptions); + this.methods = methods == null ? List.of() : listFromTrustedArray(methods); - this.comments = comments; - this.dataSection = dataSection.clone(); + this.comments = comments == null ? List.of() : listFromTrustedArray(comments); + this.dataSection = dataSection; this.dataSectionAlignment = dataSectionAlignment; - this.dataSectionPatches = dataSectionPatches; + this.dataSectionPatches = dataSectionPatches == null ? List.of() : listFromTrustedArray(dataSectionPatches); this.isImmutablePIC = isImmutablePIC; this.totalFrameSize = totalFrameSize; this.deoptRescueSlot = deoptRescueSlot; + assert targetCode != null && dataSection != null; assert validateFrames(); } @@ -193,7 +212,7 @@ public int getOffset(ResolvedJavaField field) { * Returns a copy of the compiled machine code. */ public byte[] getTargetCode() { - return (targetCode == null) ? null : Arrays.copyOf(targetCode, targetCode.length); + return targetCode.clone(); } /** @@ -204,44 +223,38 @@ public int getTargetCodeSize() { } /** - * Returns a copy of the array of {@link Site} objects associated with this compiled code. + * Returns the list of code annotations describing special sites in {@link #targetCode}. */ - public Site[] getSites() { - return (sites == null) ? null : Arrays.copyOf(sites, sites.length); + public List getSites() { + return sites; } /** - * Returns a copy of the array of {@link Assumption} objects associated with this compiled code. + * Returns list of {@link Assumption} this code relies on. */ - public Assumption[] getAssumptions() { - return (assumptions == null) ? null : Arrays.copyOf(assumptions, assumptions.length); + public List getAssumptions() { + return assumptions; } /** - * Returns a copy of the array of {@link ResolvedJavaMethod} objects representing the methods - * whose bytecodes were used as input to the compilation. If the compilation did not record - * method dependencies, this method returns {@code null}. Otherwise, the first element of the - * returned array is the root method of the compilation. - * - * @return a copy of the array of methods associated with this compiled code or {@code null} - * if no methods were recorded + * Returns the list of the methods whose bytecodes were used as input to the compilation */ - public ResolvedJavaMethod[] getMethods() { - return (methods == null) ? null : Arrays.copyOf(methods, methods.length); + public List getMethods() { + return methods; } /** - * Returns a copy of the array of {@link Comment} objects associated with this compiled code. + * Returns the list of comments that will be included in code dumps. */ - public Comment[] getComments() { - return Arrays.copyOf(comments, comments.length); + public List getComments() { + return comments; } /** * Returns a copy of the data section containing serialized constants for the emitted machine code. */ public byte[] getDataSection() { - return (dataSection == null) ? null : Arrays.copyOf(dataSection, dataSection.length); + return dataSection.clone(); } /** @@ -252,13 +265,10 @@ public int getDataSectionAlignment() { } /** - * Returns a copy of the array of {@link DataPatch} objects representing the relocations in the - * {@linkplain #getDataSection() data section}. - * - * @return a copy of the array of data section patches or {@code null} if there are no patches + * Gets the list of relocations in the {@link #dataSection}. */ - public DataPatch[] getDataSectionPatches() { - return (dataSectionPatches == null) ? null : Arrays.copyOf(dataSectionPatches, dataSectionPatches.length); + public List getDataSectionPatches() { + return dataSectionPatches; } /** diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotCompiledCodeStream.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotCompiledCodeStream.java index 62a02da9e201c..c97b75def425a 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotCompiledCodeStream.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotCompiledCodeStream.java @@ -540,10 +540,10 @@ private String codeDesc() { this.runtime = HotSpotJVMCIRuntime.runtime(); this.withTypeInfo = withTypeInfo; - ResolvedJavaMethod[] methods = withMethods ? code.methods : null; - Assumption[] assumptions = code.assumptions; + List methods = withMethods ? code.methods : null; + List assumptions = code.assumptions; StackSlot deoptRescueSlot = code.deoptRescueSlot; - Comment[] comments = withComments ? code.comments : null; + List comments = withComments ? code.comments : null; String name = code.name; codeDesc = name; @@ -559,7 +559,7 @@ private String codeDesc() { // @formatter:off int flags = setIf(IS_NMETHOD, nmethod != null) | - setIf(HAS_METHODS, nmethod != null && methods != null && methods.length != 0 ) | + setIf(HAS_METHODS, nmethod != null && methods != null && !methods.isEmpty() ) | setIf(HAS_ASSUMPTIONS, assumptions) | setIf(HAS_DEOPT_RESCUE_SLOT, deoptRescueSlot != null) | setIf(HAS_COMMENTS, comments); @@ -580,13 +580,13 @@ private String codeDesc() { writeAssumptions(assumptions); } if (isSet(flags, HAS_METHODS)) { - writeU2("methods:length", methods.length); + writeU2("methods:length", methods.size()); for (ResolvedJavaMethod method : methods) { writeMethod("method", method); } } - writeInt("sites:length", code.sites.length); + writeInt("sites:length", code.sites.size()); writeInt("targetCodeSize", code.targetCodeSize); writeInt("totalFrameSize", code.totalFrameSize); if (isSet(flags, HAS_DEOPT_RESCUE_SLOT)) { @@ -602,7 +602,7 @@ private String codeDesc() { writeSites(code); if (isSet(flags, HAS_COMMENTS)) { - writeU2("comments:length", comments.length); + writeU2("comments:length", comments.size()); for (Comment c : comments) { writeInt("comment:pcOffset", c.pcOffset); writeUTF8("comment:text", c.text); @@ -726,8 +726,7 @@ public void close() { } private void writeSites(HotSpotCompiledCode code) { - Site[] sites = code.sites; - for (Site site : sites) { + for (Site site : code.sites) { writeInt("site:pcOffset", site.pcOffset); switch (site) { case Call call -> { @@ -791,8 +790,8 @@ private void writeSites(HotSpotCompiledCode code) { } } - private void writeDataSectionPatches(DataPatch[] dataSectionPatches) { - writeU2("dataSectionPatches:length", dataSectionPatches.length); + private void writeDataSectionPatches(List dataSectionPatches) { + writeU2("dataSectionPatches:length", dataSectionPatches.size()); for (DataPatch dp : dataSectionPatches) { Reference ref = dp.reference; if (!(ref instanceof ConstantReference cref)) { @@ -909,8 +908,8 @@ private void writeStubCounts(HotSpotCompiledCode code) { writeU2("numTrampolineStubs", numTrampolineStubs); } - private void writeAssumptions(Assumption[] assumptions) { - writeU2("assumptions:length", assumptions.length); + private void writeAssumptions(List assumptions) { + writeU2("assumptions:length", assumptions.size()); for (Assumption a : assumptions) { switch (a) { case NoFinalizableSubclass noFinalizableSubclass -> { @@ -1157,8 +1156,8 @@ private int writeObjectID(DirectHotSpotObjectConstantImpl value, Tag u1Tag, Tag /** * Returns {@code flag} if {@code condition == true} else {@code 0}. */ - private static int setIf(int flag, Object[] array) { - return array != null && array.length > 0 ? flag : 0; + private static int setIf(int flag, List array) { + return array != null && !array.isEmpty() ? flag : 0; } /** diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotCompiledNmethod.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotCompiledNmethod.java index 22c5772631745..a89c3a154e0b2 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotCompiledNmethod.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotCompiledNmethod.java @@ -52,39 +52,60 @@ public final class HotSpotCompiledNmethod extends HotSpotCompiledCode { * May be set by VM if code installation fails. It will describe in more detail why installation * failed (e.g., exactly which dependency failed). */ - @SuppressFBWarnings(value = "UWF_UNWRITTEN_FIELD", justification = "set by the VM") private String installationFailureMessage; + @SuppressFBWarnings(value = "UWF_UNWRITTEN_FIELD", justification = "set by the VM") + private String installationFailureMessage; + /** + * @param name the name of this compilation unit. + * @param targetCode the buffer containing the emitted machine code. This array is now owned by this object and should not be mutated by the caller. + * @param targetCodeSize the leading number of bytes in {@link #targetCode} containing the emitted machine code. + * @param sites an array of code annotations describing special sites in {@link #targetCode}. This array is now owned by this object and should not be mutated by the caller. + * @param assumptions an array of {@link Assumption} this code relies on. This array is now owned by this object and should not be mutated by the caller. + * @param methods an array of the methods whose bytecodes were used as input to the compilation. This array is now owned by this object and should not be mutated by the caller. + * @param comments an array of comments that will be included in code dumps. This array is now owned by this object and should not be mutated by the caller. + * @param dataSection the data section containing serialized constants for the emitted machine code. This array is now owned by this object and should not be mutated by the caller. + * @param dataSectionAlignment the minimum alignment of the data section. + * @param dataSectionPatches an array of relocations in the {@link #dataSection}. This array is now owned by this object and should not be mutated by the caller. + * @param isImmutablePIC the flag determining whether this code is immutable and position independent. + * @param totalFrameSize the total size of the stack frame of this compiled method. + * @param deoptRescueSlot the deopt rescue slot. Must be non-null if there is a safepoint in the method. + * @param method the method to which this compiled nmethod belongs. + * @param entryBCI the bytecode index (BCI) in the {@link #method} + * @param id the identifier of the compilation request. + * @param compileState the address of a native {@code JVMCICompileState} object associated with this compiled nmethod. + * @param hasUnsafeAccess a flag indicating if this compiled nmethod has a memory access via the {@code Unsafe} class. + */ public HotSpotCompiledNmethod(String name, - byte[] targetCode, - int targetCodeSize, - Site[] sites, - Assumption[] assumptions, - ResolvedJavaMethod[] methods, - Comment[] comments, - byte[] dataSection, - int dataSectionAlignment, - DataPatch[] dataSectionPatches, - boolean isImmutablePIC, - int totalFrameSize, - StackSlot deoptRescueSlot, - HotSpotResolvedJavaMethod method, - int entryBCI, - int id, - long compileState, - boolean hasUnsafeAccess) { + byte[] targetCode, + int targetCodeSize, + Site[] sites, + Assumption[] assumptions, + ResolvedJavaMethod[] methods, + Comment[] comments, + byte[] dataSection, + int dataSectionAlignment, + DataPatch[] dataSectionPatches, + boolean isImmutablePIC, + int totalFrameSize, + StackSlot deoptRescueSlot, + HotSpotResolvedJavaMethod method, + int entryBCI, + int id, + long compileState, + boolean hasUnsafeAccess) { super(name, - targetCode, - targetCodeSize, - sites, - assumptions, - methods, - comments, - dataSection, - dataSectionAlignment, - dataSectionPatches, - isImmutablePIC, - totalFrameSize, - deoptRescueSlot); + targetCode, + targetCodeSize, + sites, + assumptions, + methods, + comments, + dataSection, + dataSectionAlignment, + dataSectionPatches, + isImmutablePIC, + totalFrameSize, + deoptRescueSlot); this.method = method; this.entryBCI = entryBCI; this.id = id; diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotSignature.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotSignature.java index 7081d033b82e1..e75665344b69d 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotSignature.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotSignature.java @@ -69,21 +69,6 @@ public HotSpotSignature(HotSpotJVMCIRuntime runtime, String signature) { } } - public HotSpotSignature(HotSpotJVMCIRuntime runtime, ResolvedJavaType returnType, ResolvedJavaType... parameterTypes) { - this.runtime = runtime; - this.parameterTypes = parameterTypes.clone(); - this.returnTypeCache = returnType; - this.returnType = returnType.getName(); - StringBuilder sb = new StringBuilder("("); - for (JavaType type : parameterTypes) { - parameters.add(type.getName()); - sb.append(type.getName()); - } - sb.append(")").append(returnType.getName()); - this.originalString = sb.toString(); - assert new HotSpotSignature(runtime, originalString).equals(this); - } - private static int parseSignature(String signature, int start) { try { int cur = start; diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/LocalVariableTable.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/LocalVariableTable.java index 2f2fd25b16119..eacc463660db9 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/LocalVariableTable.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/LocalVariableTable.java @@ -41,7 +41,7 @@ public class LocalVariableTable { * object and must not be mutated by the caller. */ public LocalVariableTable(Local[] locals) { - this.locals = List.of(locals); + this.locals = MetaUtil.listFromTrustedArray(locals); } /** diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/MetaUtil.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/MetaUtil.java index 5d8ff84497263..efbb44b9de12b 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/MetaUtil.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/MetaUtil.java @@ -23,6 +23,7 @@ package jdk.vm.ci.meta; import java.util.List; + import jdk.internal.access.SharedSecrets; /** @@ -39,10 +40,10 @@ public class MetaUtil { * Extends the functionality of {@link Class#getSimpleName()} to include a non-empty string for * anonymous and local classes. * - * @param clazz the class for which the simple name is being requested + * @param clazz the class for which the simple name is being requested * @param withEnclosingClass specifies if the returned name should be qualified with the name(s) - * of the enclosing class/classes of {@code clazz} (if any). This option is ignored - * if {@code clazz} denotes an anonymous or local class. + * of the enclosing class/classes of {@code clazz} (if any). This option is ignored + * if {@code clazz} denotes an anonymous or local class. * @return the simple name */ public static String getSimpleName(Class clazz, boolean withEnclosingClass) { @@ -101,9 +102,9 @@ private static String safeSimpleName(Class clazz) { * {@link Character#isJavaIdentifierStart(char)} (e.g., * "jdk.vm.ci.runtime.test.TypeUniverse$$Lambda/869601985"). * - * @param name the name to perform the replacements on + * @param name the name to perform the replacements on * @param packageSeparator the {@link Character} used as the package separator, e.g. {@code /} in internal form - * @param hiddenSeparator the {@link Character} used as the hidden class separator, e.g. {@code .} in internal form + * @param hiddenSeparator the {@link Character} used as the hidden class separator, e.g. {@code .} in internal form */ private static String replacePackageAndHiddenSeparators(String name, Character packageSeparator, Character hiddenSeparator) { int index = name.indexOf(hiddenSeparator); // check if it's a hidden class @@ -122,12 +123,12 @@ private static String replacePackageAndHiddenSeparators(String name, Character p /** * Converts a type name in internal form to an external form. * - * @param name the internal name to convert - * @param qualified whether the returned name should be qualified with the package name + * @param name the internal name to convert + * @param qualified whether the returned name should be qualified with the package name * @param classForNameCompatible specifies if the returned name for array types should be in - * {@link Class#forName(String)} format (e.g., {@code "[Ljava.lang.Object;"}, - * {@code "[[I"}) or in Java source code format (e.g., {@code "java.lang.Object[]"}, - * {@code "int[][]"} ). + * {@link Class#forName(String)} format (e.g., {@code "[Ljava.lang.Object;"}, + * {@code "[[I"}) or in Java source code format (e.g., {@code "java.lang.Object[]"}, + * {@code "int[][]"} ). */ public static String internalNameToJava(String name, boolean qualified, boolean classForNameCompatible) { switch (name.charAt(0)) { @@ -175,7 +176,7 @@ public static String toLocation(ResolvedJavaMethod method, int bci) { *
          *     java.lang.String.valueOf(String.java:2930) [bci: 12]
          * 
    - * + *

    * Otherwise, the string returned is the value of applying {@link JavaMethod#format(String)} * with the format string {@code "%H.%n(%p)"}, suffixed by the bci location. For example: * @@ -283,7 +284,7 @@ public static String identityHashCodeString(Object obj) { } /** - * Creates an immutable list from a trusted array. + * Creates an immutable list from a trusted array that has no references retained by the caller. */ static List listFromTrustedArray(Object[] array) { return SharedSecrets.getJavaUtilCollectionAccess().listFromTrustedArray(array); From afdc79f289774a4e27488fd59cad513c7e447a26 Mon Sep 17 00:00:00 2001 From: Yudi Zheng Date: Thu, 19 Jun 2025 10:43:05 +0200 Subject: [PATCH 09/11] Replace raw arrays with List (cont) --- .../classes/jdk/vm/ci/code/CallingConvention.java | 2 +- .../share/classes/jdk/vm/ci/code/CodeUtil.java | 2 +- .../classes/jdk/vm/ci/code/RegisterConfig.java | 2 +- .../jdk/vm/ci/hotspot/HotSpotSignature.java | 15 +++++++++++++++ .../aarch64/AArch64HotSpotRegisterConfig.java | 10 +++++----- .../hotspot/amd64/AMD64HotSpotRegisterConfig.java | 10 +++++----- .../riscv64/RISCV64HotSpotRegisterConfig.java | 10 +++++----- .../classes/jdk/vm/ci/meta/JavaMethodProfile.java | 6 +++++- .../classes/jdk/vm/ci/meta/JavaTypeProfile.java | 7 ++++++- .../jdk/vm/ci/meta/MetaAccessProvider.java | 2 +- 10 files changed, 45 insertions(+), 21 deletions(-) diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/CallingConvention.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/CallingConvention.java index da4faa831beab..c9f2539c905e8 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/CallingConvention.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/CallingConvention.java @@ -65,7 +65,7 @@ public interface Type { public CallingConvention(int stackSize, AllocatableValue returnLocation, AllocatableValue... argumentLocations) { assert argumentLocations != null; assert returnLocation != null; - this.argumentLocations = List.of(argumentLocations); + this.argumentLocations = CodeUtil.listFromTrustedArray(argumentLocations); this.stackSize = stackSize; this.returnLocation = returnLocation; assert verify(); diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/CodeUtil.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/CodeUtil.java index ef9643e71cf49..d17a142b9db66 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/CodeUtil.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/CodeUtil.java @@ -432,7 +432,7 @@ public static CallingConvention getCallingConvention(CodeCacheProvider codeCache } RegisterConfig registerConfig = codeCache.getRegisterConfig(); - return registerConfig.getCallingConvention(type, retType, argTypes, valueKindFactory); + return registerConfig.getCallingConvention(type, retType, listFromTrustedArray(argTypes), valueKindFactory); } /** diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/RegisterConfig.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/RegisterConfig.java index 0cc1980b28ff5..947c75a05fff4 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/RegisterConfig.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/RegisterConfig.java @@ -61,7 +61,7 @@ default int getMaximumFrameSize() { * @param parameterTypes the types of the arguments of the call * @param valueKindFactory the factory to create custom {@link ValueKind ValueKinds} */ - CallingConvention getCallingConvention(Type type, JavaType returnType, JavaType[] parameterTypes, ValueKindFactory valueKindFactory); + CallingConvention getCallingConvention(Type type, JavaType returnType, List parameterTypes, ValueKindFactory valueKindFactory); /** * Gets the ordered set of registers that are can be used to pass parameters according to a diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotSignature.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotSignature.java index e75665344b69d..7081d033b82e1 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotSignature.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotSignature.java @@ -69,6 +69,21 @@ public HotSpotSignature(HotSpotJVMCIRuntime runtime, String signature) { } } + public HotSpotSignature(HotSpotJVMCIRuntime runtime, ResolvedJavaType returnType, ResolvedJavaType... parameterTypes) { + this.runtime = runtime; + this.parameterTypes = parameterTypes.clone(); + this.returnTypeCache = returnType; + this.returnType = returnType.getName(); + StringBuilder sb = new StringBuilder("("); + for (JavaType type : parameterTypes) { + parameters.add(type.getName()); + sb.append(type.getName()); + } + sb.append(")").append(returnType.getName()); + this.originalString = sb.toString(); + assert new HotSpotSignature(runtime, originalString).equals(this); + } + private static int parseSignature(String signature, int start) { try { int cur = start; diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/aarch64/AArch64HotSpotRegisterConfig.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/aarch64/AArch64HotSpotRegisterConfig.java index e7259ed2f25bd..3414788b38b4f 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/aarch64/AArch64HotSpotRegisterConfig.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/aarch64/AArch64HotSpotRegisterConfig.java @@ -196,7 +196,7 @@ public boolean areAllAllocatableRegistersCallerSaved() { } @Override - public CallingConvention getCallingConvention(Type type, JavaType returnType, JavaType[] parameterTypes, ValueKindFactory valueKindFactory) { + public CallingConvention getCallingConvention(Type type, JavaType returnType, List parameterTypes, ValueKindFactory valueKindFactory) { HotSpotCallingConventionType hotspotType = (HotSpotCallingConventionType) type; if (type == HotSpotCallingConventionType.NativeCall) { return callingConvention(nativeGeneralParameterRegisters, returnType, parameterTypes, hotspotType, valueKindFactory); @@ -238,16 +238,16 @@ private int parseDarwinNativeStackArg(ValueKind valueKind, AllocatableValue[] return currentStackOffset; } - private CallingConvention callingConvention(List generalParameterRegisters, JavaType returnType, JavaType[] parameterTypes, HotSpotCallingConventionType type, + private CallingConvention callingConvention(List generalParameterRegisters, JavaType returnType, List parameterTypes, HotSpotCallingConventionType type, ValueKindFactory valueKindFactory) { - AllocatableValue[] locations = new AllocatableValue[parameterTypes.length]; + AllocatableValue[] locations = new AllocatableValue[parameterTypes.size()]; int currentGeneral = 0; int currentSIMD = 0; int currentStackOffset = 0; - for (int i = 0; i < parameterTypes.length; i++) { - final JavaKind kind = parameterTypes[i].getJavaKind().getStackKind(); + for (int i = 0; i < parameterTypes.size(); i++) { + final JavaKind kind = parameterTypes.get(i).getJavaKind().getStackKind(); switch (kind) { case Byte: diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/amd64/AMD64HotSpotRegisterConfig.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/amd64/AMD64HotSpotRegisterConfig.java index e67bff33ff144..561b0d012e756 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/amd64/AMD64HotSpotRegisterConfig.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/amd64/AMD64HotSpotRegisterConfig.java @@ -186,7 +186,7 @@ public boolean areAllAllocatableRegistersCallerSaved() { } @Override - public CallingConvention getCallingConvention(Type type, JavaType returnType, JavaType[] parameterTypes, ValueKindFactory valueKindFactory) { + public CallingConvention getCallingConvention(Type type, JavaType returnType, List parameterTypes, ValueKindFactory valueKindFactory) { HotSpotCallingConventionType hotspotType = (HotSpotCallingConventionType) type; if (type == HotSpotCallingConventionType.NativeCall) { return callingConvention(nativeGeneralParameterRegisters, nativeXMMParameterRegisters, windowsOS, returnType, parameterTypes, hotspotType, valueKindFactory); @@ -218,18 +218,18 @@ public List getCallingConventionRegisters(Type type, JavaKind kind) { * * @return the resulting calling convention */ - private CallingConvention callingConvention(List generalParameterRegisters, List xmmParameterRegisters, boolean unified, JavaType returnType, JavaType[] parameterTypes, + private CallingConvention callingConvention(List generalParameterRegisters, List xmmParameterRegisters, boolean unified, JavaType returnType, List parameterTypes, HotSpotCallingConventionType type, ValueKindFactory valueKindFactory) { assert !unified || generalParameterRegisters.size() == xmmParameterRegisters.size() : "must be same size in unified mode"; - AllocatableValue[] locations = new AllocatableValue[parameterTypes.length]; + AllocatableValue[] locations = new AllocatableValue[parameterTypes.size()]; int currentGeneral = 0; int currentXMM = 0; int currentStackOffset = type == HotSpotCallingConventionType.NativeCall && needsNativeStackHomeSpace ? generalParameterRegisters.size() * target.wordSize : 0; - for (int i = 0; i < parameterTypes.length; i++) { - final JavaKind kind = parameterTypes[i].getJavaKind().getStackKind(); + for (int i = 0; i < parameterTypes.size(); i++) { + final JavaKind kind = parameterTypes.get(i).getJavaKind().getStackKind(); switch (kind) { case Byte: diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/riscv64/RISCV64HotSpotRegisterConfig.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/riscv64/RISCV64HotSpotRegisterConfig.java index 24385f787a665..727ebc444f66b 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/riscv64/RISCV64HotSpotRegisterConfig.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/riscv64/RISCV64HotSpotRegisterConfig.java @@ -189,7 +189,7 @@ public boolean areAllAllocatableRegistersCallerSaved() { } @Override - public CallingConvention getCallingConvention(Type type, JavaType returnType, JavaType[] parameterTypes, ValueKindFactory valueKindFactory) { + public CallingConvention getCallingConvention(Type type, JavaType returnType, List parameterTypes, ValueKindFactory valueKindFactory) { HotSpotCallingConventionType hotspotType = (HotSpotCallingConventionType) type; if (type == HotSpotCallingConventionType.NativeCall) { return callingConvention(nativeGeneralParameterRegisters, returnType, parameterTypes, hotspotType, valueKindFactory); @@ -208,16 +208,16 @@ public List getCallingConventionRegisters(Type type, JavaKind kind) { }; } - private CallingConvention callingConvention(List generalParameterRegisters, JavaType returnType, JavaType[] parameterTypes, HotSpotCallingConventionType type, + private CallingConvention callingConvention(List generalParameterRegisters, JavaType returnType, List parameterTypes, HotSpotCallingConventionType type, ValueKindFactory valueKindFactory) { - AllocatableValue[] locations = new AllocatableValue[parameterTypes.length]; + AllocatableValue[] locations = new AllocatableValue[parameterTypes.size()]; int currentGeneral = 0; int currentFP = 0; int currentStackOffset = 0; - for (int i = 0; i < parameterTypes.length; i++) { - final JavaKind kind = parameterTypes[i].getJavaKind().getStackKind(); + for (int i = 0; i < parameterTypes.size(); i++) { + final JavaKind kind = parameterTypes.get(i).getJavaKind().getStackKind(); switch (kind) { case Byte: diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/JavaMethodProfile.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/JavaMethodProfile.java index 583555c4c25c5..1ad58e666fffb 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/JavaMethodProfile.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/JavaMethodProfile.java @@ -33,8 +33,12 @@ */ public final class JavaMethodProfile extends AbstractJavaProfile { + /** + * @param notRecordedProbability estimated probability of all types that could not be recorded due to profiling limitation + * @param pitems an array of profile items. This array is now owned by this object and should not be mutated by the caller. + */ public JavaMethodProfile(double notRecordedProbability, ProfiledMethod[] pitems) { - super(notRecordedProbability, List.of(pitems)); + super(notRecordedProbability, MetaUtil.listFromTrustedArray(pitems)); } public List getMethods() { diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/JavaTypeProfile.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/JavaTypeProfile.java index 8f966378ff2f1..bcce492592d3f 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/JavaTypeProfile.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/JavaTypeProfile.java @@ -37,8 +37,13 @@ public final class JavaTypeProfile extends AbstractJavaProfile pitems) { diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/MetaAccessProvider.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/MetaAccessProvider.java index cbf7286b61737..68cf3dea584cc 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/MetaAccessProvider.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/MetaAccessProvider.java @@ -54,7 +54,7 @@ default List lookupJavaTypes(Class[] classes) { for (int i = 0; i < result.length; i++) { result[i] = lookupJavaType(classes[i]); } - return List.of(result); + return MetaUtil.listFromTrustedArray(result); } /** From c05efe1fc87b0518325c93d7c77b5b67a5d71454 Mon Sep 17 00:00:00 2001 From: Yudi Zheng Date: Thu, 19 Jun 2025 17:59:29 +0200 Subject: [PATCH 10/11] Replace raw arrays with List (cont 1) --- .../classes/jdk/vm/ci/code/VirtualObject.java | 4 ++-- .../vm/ci/hotspot/HotSpotMetaAccessProvider.java | 2 +- .../amd64/AMD64HotSpotRegisterConfig.java | 7 ++++--- .../riscv64/RISCV64HotSpotRegisterConfig.java | 11 ++++++----- .../jdk/vm/ci/meta/MetaAccessProvider.java | 2 +- .../classes/jdk/vm/ci/meta/ResolvedJavaType.java | 16 ++++++++-------- 6 files changed, 22 insertions(+), 20 deletions(-) diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/VirtualObject.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/VirtualObject.java index 56576a4da1732..476e14e63cf8c 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/VirtualObject.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/VirtualObject.java @@ -109,7 +109,7 @@ private static StringBuilder appendValue(StringBuilder buf, JavaValue value, Set appendValue(buf, vo.values[i], visited); } } else { - List fields = vo.type.getInstanceFields(true); + List fields = vo.type.getInstanceFields(true); int fieldIndex = 0; for (int i = 0; i < vo.values.length; i++, fieldIndex++) { if (i != 0) { @@ -156,7 +156,7 @@ default JavaKind getStorageKind(ResolvedJavaField field) { public void verifyLayout(LayoutVerifier verifier) { if (!type.isArray()) { - List fields = type.getInstanceFields(true); + List fields = type.getInstanceFields(true); int fieldIndex = 0; for (int i = 0; i < values.length; i++, fieldIndex++) { JavaKind slotKind = slotKinds.get(i); diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotMetaAccessProvider.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotMetaAccessProvider.java index 627808f71c746..deb36d567c2c1 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotMetaAccessProvider.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotMetaAccessProvider.java @@ -88,7 +88,7 @@ public ResolvedJavaField lookupJavaField(Field reflectionField) { HotSpotResolvedJavaType holder = runtime.fromClass(fieldHolder); assert holder != null : fieldHolder; - List fields; + List fields; if (Modifier.isStatic(reflectionField.getModifiers())) { fields = holder.getStaticFields(); } else { diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/amd64/AMD64HotSpotRegisterConfig.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/amd64/AMD64HotSpotRegisterConfig.java index 561b0d012e756..356e3f8164fb1 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/amd64/AMD64HotSpotRegisterConfig.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/amd64/AMD64HotSpotRegisterConfig.java @@ -218,9 +218,10 @@ public List getCallingConventionRegisters(Type type, JavaKind kind) { * * @return the resulting calling convention */ - private CallingConvention callingConvention(List generalParameterRegisters, List xmmParameterRegisters, boolean unified, JavaType returnType, List parameterTypes, - HotSpotCallingConventionType type, - ValueKindFactory valueKindFactory) { + private CallingConvention callingConvention(List generalParameterRegisters, List xmmParameterRegisters, boolean unified, JavaType returnType, + List parameterTypes, + HotSpotCallingConventionType type, + ValueKindFactory valueKindFactory) { assert !unified || generalParameterRegisters.size() == xmmParameterRegisters.size() : "must be same size in unified mode"; AllocatableValue[] locations = new AllocatableValue[parameterTypes.size()]; diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/riscv64/RISCV64HotSpotRegisterConfig.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/riscv64/RISCV64HotSpotRegisterConfig.java index 727ebc444f66b..f95fe45e11d48 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/riscv64/RISCV64HotSpotRegisterConfig.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/riscv64/RISCV64HotSpotRegisterConfig.java @@ -127,7 +127,7 @@ public List getAttributesMap() { public static final Register threadRegister = x23; public static final Register heapBaseRegister = x27; - private static final List reservedRegisters =List.of(zero, ra, sp, gp, tp, t0, t1, t2, fp); + private static final List reservedRegisters = List.of(zero, ra, sp, gp, tp, t0, t1, t2, fp); private static List initAllocatable(Architecture arch, boolean reserveForHeapBase) { List allRegisters = arch.getAvailableValueRegisters(); @@ -140,7 +140,7 @@ private static List initAllocatable(Architecture arch, boolean reserve continue; } assert !(reg.equals(zero) || reg.equals(ra) || reg.equals(sp) || reg.equals(gp) || reg.equals(tp) || - reg.equals(t0) || reg.equals(t1) || reg.equals(t2) || reg.equals(fp)); + reg.equals(t0) || reg.equals(t1) || reg.equals(t2) || reg.equals(fp)); if (reserveForHeapBase && reg.equals(heapBaseRegister)) { // skip heap base register continue; @@ -189,7 +189,7 @@ public boolean areAllAllocatableRegistersCallerSaved() { } @Override - public CallingConvention getCallingConvention(Type type, JavaType returnType, List parameterTypes, ValueKindFactory valueKindFactory) { + public CallingConvention getCallingConvention(Type type, JavaType returnType, List parameterTypes, ValueKindFactory valueKindFactory) { HotSpotCallingConventionType hotspotType = (HotSpotCallingConventionType) type; if (type == HotSpotCallingConventionType.NativeCall) { return callingConvention(nativeGeneralParameterRegisters, returnType, parameterTypes, hotspotType, valueKindFactory); @@ -208,8 +208,9 @@ public List getCallingConventionRegisters(Type type, JavaKind kind) { }; } - private CallingConvention callingConvention(List generalParameterRegisters, JavaType returnType, List parameterTypes, HotSpotCallingConventionType type, - ValueKindFactory valueKindFactory) { + private CallingConvention callingConvention(List generalParameterRegisters, JavaType returnType, + List parameterTypes, HotSpotCallingConventionType type, + ValueKindFactory valueKindFactory) { AllocatableValue[] locations = new AllocatableValue[parameterTypes.size()]; int currentGeneral = 0; diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/MetaAccessProvider.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/MetaAccessProvider.java index 68cf3dea584cc..f44f7b9c18ac7 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/MetaAccessProvider.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/MetaAccessProvider.java @@ -49,7 +49,7 @@ public interface MetaAccessProvider { * @param classes the Java class objects * @return the resolved Java type objects */ - default List lookupJavaTypes(Class[] classes) { + default List lookupJavaTypes(Class[] classes) { ResolvedJavaType[] result = new ResolvedJavaType[classes.length]; for (int i = 0; i < result.length; i++) { result[i] = lookupJavaType(classes[i]); diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/ResolvedJavaType.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/ResolvedJavaType.java index 11092d0f85420..78536828dc2a4 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/ResolvedJavaType.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/ResolvedJavaType.java @@ -167,7 +167,7 @@ default boolean isJavaLangObject() { * {@link Class#getInterfaces()} and as such, only returns the interfaces directly implemented * or extended by this type. */ - List getInterfaces(); + List getInterfaces(); /** * Gets the single implementor of this type. Calling this method on a non-interface type causes @@ -285,14 +285,14 @@ default ResolvedJavaMethod resolveConcreteMethod(ResolvedJavaMethod method, Reso * type are included in the result with superclass fields coming before subclass fields * @return a list of non-static fields */ - List getInstanceFields(boolean includeSuperclasses); + List getInstanceFields(boolean includeSuperclasses); /** * Returns the static fields of this class, including {@linkplain ResolvedJavaField#isInternal() * internal} fields. A zero-length array is returned for array and primitive types. The order of * fields returned by this method is the same as {@link Class#getDeclaredFields}. */ - List getStaticFields(); + List getStaticFields(); /** * Returns the instance field of this class (or one of its super classes) at the given offset, @@ -328,7 +328,7 @@ default ResolvedJavaMethod resolveConcreteMethod(ResolvedJavaMethod method, Reso * similar to {@link Class#getDeclaredConstructors()} in terms of returned constructors. Calling * this method forces this type to be {@link #link linked}. */ - List getDeclaredConstructors(); + List getDeclaredConstructors(); /** * Returns a list reflecting all the constructors declared by this type. This method is @@ -336,7 +336,7 @@ default ResolvedJavaMethod resolveConcreteMethod(ResolvedJavaMethod method, Reso * * @param forceLink if {@code true}, forces this type to be {@link #link linked} */ - default List getDeclaredConstructors(boolean forceLink) { + default List getDeclaredConstructors(boolean forceLink) { throw new UnsupportedOperationException(); } @@ -345,7 +345,7 @@ default List getDeclaredConstructors(boolean forceLink) { * {@link Class#getDeclaredMethods()} in terms of returned methods. Calling this method forces * this type to be {@link #link linked}. */ - List getDeclaredMethods(); + List getDeclaredMethods(); /** * Returns a list reflecting all the methods declared by this type. This method is similar to @@ -353,7 +353,7 @@ default List getDeclaredConstructors(boolean forceLink) { * * @param forceLink if {@code true}, forces this type to be {@link #link linked} */ - default List getDeclaredMethods(boolean forceLink) { + default List getDeclaredMethods(boolean forceLink) { throw new UnsupportedOperationException(); } @@ -366,7 +366,7 @@ default List getDeclaredMethods(boolean forceLink) { * * @param forceLink if {@code true}, forces this type to be {@link #link linked} */ - List getAllMethods(boolean forceLink); + List getAllMethods(boolean forceLink); /** * Returns the {@code } method for this class if there is one. From 554b97896bf6572810dc5091cc5afcbe50496d1f Mon Sep 17 00:00:00 2001 From: Yudi Zheng Date: Mon, 23 Jun 2025 17:58:40 +0200 Subject: [PATCH 11/11] Use records where applicable --- .../classes/jdk/vm/ci/code/Architecture.java | 4 +- .../jdk/vm/ci/code/CallingConvention.java | 64 ++---- .../classes/jdk/vm/ci/code/CodeUtil.java | 61 +++--- .../classes/jdk/vm/ci/code/DebugInfo.java | 4 +- .../classes/jdk/vm/ci/code/Location.java | 14 +- .../classes/jdk/vm/ci/code/ReferenceMap.java | 2 +- .../classes/jdk/vm/ci/code/Register.java | 116 ++--------- .../jdk/vm/ci/code/RegisterAttributes.java | 55 ++--- .../jdk/vm/ci/code/RegisterConfig.java | 2 +- .../jdk/vm/ci/code/RegisterSaveLayout.java | 44 +--- .../classes/jdk/vm/ci/code/RegisterValue.java | 2 +- .../jdk/vm/ci/code/TargetDescription.java | 106 ++-------- .../jdk/vm/ci/hotspot/CompilerToVM.java | 3 + .../ci/hotspot/HotSpotCodeCacheProvider.java | 26 +-- .../HotSpotCompilationRequestResult.java | 55 +---- .../vm/ci/hotspot/HotSpotCompiledCode.java | 10 +- .../ci/hotspot/HotSpotCompiledCodeStream.java | 58 ++---- .../vm/ci/hotspot/HotSpotConstantPool.java | 38 +--- .../vm/ci/hotspot/HotSpotJVMCIRuntime.java | 12 +- .../ci/hotspot/HotSpotMetaAccessProvider.java | 2 +- .../jdk/vm/ci/hotspot/HotSpotMethodData.java | 4 +- .../vm/ci/hotspot/HotSpotReferenceMap.java | 54 +---- .../HotSpotResolvedObjectTypeImpl.java | 72 ++----- .../jdk/vm/ci/hotspot/HotSpotSignature.java | 2 +- .../ci/hotspot/HotSpotStackIntrospection.java | 8 +- .../vm/ci/hotspot/HotSpotVMConfigAccess.java | 110 +++++----- .../vm/ci/hotspot/HotSpotVMConfigStore.java | 18 +- .../IndirectHotSpotObjectConstantImpl.java | 11 +- .../classes/jdk/vm/ci/hotspot/VMField.java | 57 ++--- .../classes/jdk/vm/ci/hotspot/VMFlag.java | 35 +--- .../jdk/vm/ci/hotspot/VMIntrinsicMethod.java | 102 ++------- .../AArch64HotSpotJVMCIBackendFactory.java | 3 +- .../aarch64/AArch64HotSpotRegisterConfig.java | 11 +- .../amd64/AMD64HotSpotRegisterConfig.java | 10 +- .../RISCV64HotSpotJVMCIBackendFactory.java | 3 +- .../riscv64/RISCV64HotSpotRegisterConfig.java | 8 +- .../jdk/vm/ci/meta/AnnotationData.java | 78 +++---- .../classes/jdk/vm/ci/meta/Assumptions.java | 194 ++---------------- .../jdk/vm/ci/meta/DefaultProfilingInfo.java | 13 +- .../classes/jdk/vm/ci/meta/EnumData.java | 54 +---- .../classes/jdk/vm/ci/meta/ErrorData.java | 36 +--- .../jdk/vm/ci/meta/ExceptionHandler.java | 95 +-------- .../share/classes/jdk/vm/ci/meta/Local.java | 72 +------ .../jdk/vm/ci/meta/LocalVariableTable.java | 8 +- .../classes/jdk/vm/ci/meta/MetaUtil.java | 3 + .../jdk/vm/ci/meta/ResolvedJavaMethod.java | 101 +++------ .../jdk/vm/ci/meta/UnresolvedJavaField.java | 35 +--- .../jdk/vm/ci/meta/UnresolvedJavaMethod.java | 41 +--- .../jdk/vm/ci/meta/UnresolvedJavaType.java | 37 +--- .../jdk/vm/ci/runtime/JVMCIBackend.java | 36 +--- .../classes/jdk/vm/ci/services/Services.java | 2 +- .../jdk/vm/ci/services/SystemProperties.java | 2 +- 52 files changed, 476 insertions(+), 1517 deletions(-) diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/Architecture.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/Architecture.java index ce27c433864d1..c4254d0bf455f 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/Architecture.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/Architecture.java @@ -85,9 +85,9 @@ protected Architecture(String name, PlatformKind wordKind, ByteOrder byteOrder, int returnAddressSize) { // registers is expected to mention all registers in order of their encoding. for (int i = 0; i < registers.size(); ++i) { - if (registers.get(i).number != i) { + if (registers.get(i).number() != i) { Register reg = registers.get(i); - throw new JVMCIError("%s: %d != %d", reg, reg.number, i); + throw new JVMCIError("%s: %d != %d", reg, reg.number(), i); } } this.name = name; diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/CallingConvention.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/CallingConvention.java index c9f2539c905e8..d781b8ad653ee 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/CallingConvention.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/CallingConvention.java @@ -32,8 +32,14 @@ /** * A calling convention describes the locations in which the arguments for a call are placed and the * location in which the return value is placed if the call is not void. + * + * @param stackSize amount of stack space (in bytes) required for the stack-based arguments of the call + * @param returnLocation the location for the return value or {@link Value#ILLEGAL} if a void call + * @param argumentLocations the ordered locations in which the arguments are placed */ -public class CallingConvention { +public record CallingConvention(int stackSize, + AllocatableValue returnLocation, + List argumentLocations) { /** * Marker interface denoting the type of a call for which a calling convention is requested. @@ -41,41 +47,26 @@ public class CallingConvention { public interface Type { } - /** - * The amount of stack space (in bytes) required for the stack-based arguments of the call. - */ - private final int stackSize; - - private final AllocatableValue returnLocation; - - /** - * The ordered locations in which the arguments are placed. - */ - private final List argumentLocations; - /** * Creates a description of the registers and stack locations used by a call. * - * @param stackSize amount of stack space (in bytes) required for the stack-based arguments of - * the call - * @param returnLocation the location for the return value or {@link Value#ILLEGAL} if a void - * call - * @param argumentLocations the ordered locations in which the arguments are placed + * @param stackSize amount of stack space (in bytes) required for the stack-based arguments of the call + * @param returnLocation the location for the return value or {@link Value#ILLEGAL} if a void call + * @param argumentLocations the ordered locations in which the arguments are placed. This array is now owned by this + * object and should not be mutated by the caller. */ public CallingConvention(int stackSize, AllocatableValue returnLocation, AllocatableValue... argumentLocations) { + this(stackSize, returnLocation, CodeUtil.listFromTrustedArray(argumentLocations)); assert argumentLocations != null; assert returnLocation != null; - this.argumentLocations = CodeUtil.listFromTrustedArray(argumentLocations); - this.stackSize = stackSize; - this.returnLocation = returnLocation; assert verify(); } - /** - * Gets the location for the return value or {@link Value#ILLEGAL} if a void call. - */ - public AllocatableValue getReturn() { - return returnLocation; + private boolean verify() { + for (Value location : argumentLocations) { + assert isStackSlot(location) || isAllocatableValue(location); + } + return true; } /** @@ -85,13 +76,6 @@ public AllocatableValue getArgument(int index) { return argumentLocations.get(index); } - /** - * Gets the amount of stack space (in bytes) required for the stack-based arguments of the call. - */ - public int getStackSize() { - return stackSize; - } - /** * Gets the number of locations required for the arguments. */ @@ -99,13 +83,6 @@ public int getArgumentCount() { return argumentLocations.size(); } - /** - * Gets the locations required for the arguments. - */ - public List getArguments() { - return argumentLocations; - } - @Override public String toString() { StringBuilder sb = new StringBuilder(); @@ -121,11 +98,4 @@ public String toString() { sb.append("]"); return sb.toString(); } - - private boolean verify() { - for (Value location : argumentLocations) { - assert isStackSlot(location) || isAllocatableValue(location); - } - return true; - } } diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/CodeUtil.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/CodeUtil.java index d17a142b9db66..92e052c3f0374 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/CodeUtil.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/CodeUtil.java @@ -99,7 +99,7 @@ public static int log2(long val) { /** * Narrow an integer value to a given bit width, and return the result as a signed long. * - * @param value the value + * @param value the value * @param resultBits the result bit width * @return {@code value} interpreted as {@code resultBits} bit number, encoded as signed long */ @@ -111,10 +111,10 @@ public static long narrow(long value, int resultBits) { /** * Sign extend an integer. * - * @param value the input value + * @param value the input value * @param inputBits the bit width of the input value * @return a signed long with the same value as the signed {@code inputBits}-bit number - * {@code value} + * {@code value} */ public static long signExtend(long value, int inputBits) { if (inputBits < 64) { @@ -131,10 +131,10 @@ public static long signExtend(long value, int inputBits) { /** * Zero extend an integer. * - * @param value the input value + * @param value the input value * @param inputBits the bit width of the input value * @return an unsigned long with the same value as the unsigned {@code inputBits}-bit number - * {@code value} + * {@code value} */ public static long zeroExtend(long value, int inputBits) { if (inputBits < 64) { @@ -147,9 +147,9 @@ public static long zeroExtend(long value, int inputBits) { /** * Convert an integer to long. * - * @param value the input value + * @param value the input value * @param inputBits the bit width of the input value - * @param unsigned whether the values should be interpreted as signed or unsigned + * @param unsigned whether the values should be interpreted as signed or unsigned * @return a long with the same value as the {@code inputBits}-bit number {@code value} */ public static long convert(long value, int inputBits, boolean unsigned) { @@ -232,9 +232,9 @@ public static String tabulateValues(BytecodeFrame frame) { * {@link String#valueOf(Object)}. * * @param cells the cells of the table in row-major order - * @param cols the number of columns per row - * @param lpad the number of space padding inserted before each formatted cell value - * @param rpad the number of space padding inserted after each formatted cell value + * @param cols the number of columns per row + * @param lpad the number of space padding inserted before each formatted cell value + * @param rpad the number of space padding inserted after each formatted cell value * @return a string with one line per row and each column left-aligned */ public static String tabulate(Object[] cells, int cols, int lpad, int rpad) { @@ -274,7 +274,7 @@ public static String tabulate(Object[] cells, int cols, int lpad, int rpad) { /** * Appends a formatted code position to a {@link StringBuilder}. * - * @param sb the {@link StringBuilder} to append to + * @param sb the {@link StringBuilder} to append to * @param pos the code position to format and append to {@code sb} * @return the value of {@code sb} */ @@ -290,7 +290,7 @@ public static StringBuilder append(StringBuilder sb, BytecodePosition pos) { /** * Appends a formatted frame to a {@link StringBuilder}. * - * @param sb the {@link StringBuilder} to append to + * @param sb the {@link StringBuilder} to append to * @param frame the frame to format and append to {@code sb} * @return the value of {@code sb} */ @@ -330,31 +330,13 @@ public interface RefMapFormatter { /** * Formats a location present in a reference map. + * + * @param slotSize the size of a stack slot. + * @param fp the register used as the frame pointer. + * @param refMapToFPOffset the offset (in bytes) from the slot pointed to by {@link #fp} to the slot corresponding + * to bit 0 in the frame reference map. */ - public static class DefaultRefMapFormatter implements RefMapFormatter { - - /** - * The size of a stack slot. - */ - public final int slotSize; - - /** - * The register used as the frame pointer. - */ - public final Register fp; - - /** - * The offset (in bytes) from the slot pointed to by {@link #fp} to the slot corresponding - * to bit 0 in the frame reference map. - */ - public final int refMapToFPOffset; - - public DefaultRefMapFormatter(int slotSize, Register fp, int refMapToFPOffset) { - this.slotSize = slotSize; - this.fp = fp; - this.refMapToFPOffset = refMapToFPOffset; - } - + public record DefaultRefMapFormatter(int slotSize, Register fp, int refMapToFPOffset) implements RefMapFormatter { @Override public String formatStackSlot(int frameRefMapIndex) { int refMapOffset = frameRefMapIndex * slotSize; @@ -362,7 +344,7 @@ public String formatStackSlot(int frameRefMapIndex) { if (fpOffset >= 0) { return fp + "+" + fpOffset; } - return fp.name + fpOffset; + return fp.name() + fpOffset; } } @@ -381,7 +363,7 @@ public String formatRegister(int regRefMapIndex) { /** * Appends a formatted debug info to a {@link StringBuilder}. * - * @param sb the {@link StringBuilder} to append to + * @param sb the {@link StringBuilder} to append to * @param info the debug info to format and append to {@code sb} * @return the value of {@code sb} */ @@ -439,6 +421,9 @@ public static CallingConvention getCallingConvention(CodeCacheProvider codeCache * Creates an immutable list from a trusted array that has no references retained by the caller. */ static List listFromTrustedArray(Object[] array) { + if (array == null) { + return List.of(); + } return SharedSecrets.getJavaUtilCollectionAccess().listFromTrustedArray(array); } } diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/DebugInfo.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/DebugInfo.java index 1d447993c3640..c3b2eb17c181a 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/DebugInfo.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/DebugInfo.java @@ -22,6 +22,8 @@ */ package jdk.vm.ci.code; +import static jdk.vm.ci.code.CodeUtil.listFromTrustedArray; + import java.util.List; import java.util.Objects; @@ -53,7 +55,7 @@ public final class DebugInfo { */ public DebugInfo(BytecodePosition codePos, VirtualObject[] virtualObjectMapping) { this.bytecodePosition = codePos; - this.virtualObjectMapping = virtualObjectMapping == null ? List.of() : List.of(virtualObjectMapping); + this.virtualObjectMapping = listFromTrustedArray(virtualObjectMapping); } public DebugInfo(BytecodePosition codePos) { diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/Location.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/Location.java index 4e0c58d720829..29508efac9425 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/Location.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/Location.java @@ -26,15 +26,7 @@ * Represents a location where a value can be stored. This can be either a {@link Register} or a * stack slot. */ -public final class Location { - - public final Register reg; - public final int offset; - - private Location(Register reg, int offset) { - this.reg = reg; - this.offset = offset; - } +public record Location(Register reg, int offset) { /** * Create a {@link Location} for a register. @@ -46,7 +38,7 @@ public static Location register(Register reg) { /** * Create a {@link Location} for a vector subregister. * - * @param reg the {@link Register vector register} + * @param reg the {@link Register vector register} * @param offset the offset in bytes into the vector register */ public static Location subregister(Register reg, int offset) { @@ -72,7 +64,7 @@ public boolean isStack() { public String toString() { String regName; if (isRegister()) { - regName = reg.name + ":"; + regName = reg.name() + ":"; } else { regName = "stack:"; } diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/ReferenceMap.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/ReferenceMap.java index 305c503105af3..06f9e62e6db33 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/ReferenceMap.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/ReferenceMap.java @@ -27,5 +27,5 @@ * state (e.g., registers or stack locations). This is typically associated with an execution point * in compiled code. */ -public abstract class ReferenceMap { +public interface ReferenceMap { } diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/Register.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/Register.java index bf4d2265e132f..b0710d334e76b 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/Register.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/Register.java @@ -26,100 +26,32 @@ /** * Represents a target machine register. + * + * @param number unique identifier for the register. A valid register has {@code number >= 0}. + * @param encoding the target machine encoding for the register, which may or may not be the + * same as {@link #number}. + * @param name the mnemonic name for the register + * @param registerCategory the register category */ -public final class Register implements Comparable { - - public static final RegisterCategory SPECIAL = new RegisterCategory("SPECIAL"); - - /** - * Invalid register. - */ - public static final Register None = new Register(-1, -1, "noreg", SPECIAL); - - /** - * The identifier for this register that is unique across all the registers in a - * {@link Architecture}. A valid register has {@code number >= 0}. - */ - public final int number; - - /** - * The mnemonic of this register. - */ - public final String name; - - /** - * The actual encoding in a target machine instruction for this register, which may or may not - * be the same as {@link #number}. - */ - public final int encoding; - - /** - * The assembler calls this method to get the register's encoding. - */ - public int encoding() { - return encoding; - } - - /** - * A platform specific register category that describes which values can be stored in a - * register. - */ - private final RegisterCategory registerCategory; - +public record Register(int number, + int encoding, + String name, + RegisterCategory registerCategory) implements Comparable { /** * A platform specific register type that describes which values can be stored in a register. */ - public static class RegisterCategory { - - private final String name; - private final boolean mayContainReference; - + public record RegisterCategory(String name, boolean mayContainReference) { public RegisterCategory(String name) { this(name, true); } - - public RegisterCategory(String name, boolean mayContainReference) { - this.name = name; - this.mayContainReference = mayContainReference; - } - - @Override - public String toString() { - return name; - } - - @Override - public int hashCode() { - return 23 + name.hashCode(); - } - - @Override - public boolean equals(Object obj) { - if (obj instanceof RegisterCategory that) { - return this.name.equals(that.name); - } - return false; - } } + public static final RegisterCategory SPECIAL = new RegisterCategory("SPECIAL"); + /** - * Creates a {@link Register} instance. - * - * @param number unique identifier for the register - * @param encoding the target machine encoding for the register - * @param name the mnemonic name for the register - * @param registerCategory the register category + * Invalid register. */ - public Register(int number, int encoding, String name, RegisterCategory registerCategory) { - this.number = number; - this.name = name; - this.registerCategory = registerCategory; - this.encoding = encoding; - } - - public RegisterCategory getRegisterCategory() { - return registerCategory; - } + public static final Register None = new Register(-1, -1, "noreg", SPECIAL); /** * Determine whether this register needs to be part of the reference map. @@ -165,22 +97,4 @@ public String toString() { public int compareTo(Register o) { return Integer.compare(number, o.number); } - - @Override - public int hashCode() { - return 17 + name.hashCode(); - } - - @Override - public boolean equals(Object obj) { - if (obj instanceof Register other) { - if (number == other.number) { - assert name.equals(other.name); - assert encoding == other.encoding; - assert registerCategory.equals(other.registerCategory); - return true; - } - } - return false; - } } diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/RegisterAttributes.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/RegisterAttributes.java index d9856b191bfed..a7e2d270dc3e6 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/RegisterAttributes.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/RegisterAttributes.java @@ -30,18 +30,17 @@ * A collection of register attributes. The specific attribute values for a register may be local to * a compilation context. For example, a {@link RegisterConfig} in use during a compilation will * determine which registers are callee saved. + * + * @param isCallerSave {@code true} if a register whose value preservation (if required) across a + * call is the responsibility of the caller otherwise {@code false} + * @param isCalleeSave {@code true} if a register whose value preservation (if required) across a + * call is the responsibility of the callee otherwise {@code false} + * @param isAllocatable {@code true} if a register is available for use by a register allocator + * otherwise {@code false} */ -public class RegisterAttributes { - - private final boolean callerSave; - private final boolean calleeSave; - private final boolean allocatable; - - public RegisterAttributes(boolean isCallerSave, boolean isCalleeSave, boolean isAllocatable) { - this.callerSave = isCallerSave; - this.calleeSave = isCalleeSave; - this.allocatable = isAllocatable; - } +public record RegisterAttributes(boolean isCallerSave, + boolean isCalleeSave, + boolean isAllocatable) { public static final RegisterAttributes NONE = new RegisterAttributes(false, false, false); @@ -51,9 +50,9 @@ public RegisterAttributes(boolean isCallerSave, boolean isCalleeSave, boolean is * registers. * * @param registerConfig a register configuration - * @param registers a set of registers + * @param registers a set of registers * @return a list whose length is the max register number in {@code registers} plus 1. An - * element at index i holds the attributes of the register whose number is i. + * element at index i holds the attributes of the register whose number is i. */ public static List createMap(RegisterConfig registerConfig, List registers) { RegisterAttributes[] map = new RegisterAttributes[registers.size()]; @@ -63,10 +62,10 @@ public static List createMap(RegisterConfig registerConfig, for (Register reg : registers) { if (reg != null) { RegisterAttributes attr = new RegisterAttributes(callerSaveRegisters.contains(reg), calleeSaveRegisters.contains(reg), allocatableRegisters.contains(reg)); - if (map.length <= reg.number) { - map = Arrays.copyOf(map, reg.number + 1); + if (map.length <= reg.number()) { + map = Arrays.copyOf(map, reg.number() + 1); } - map[reg.number] = attr; + map[reg.number()] = attr; } } for (int i = 0; i < map.length; i++) { @@ -76,28 +75,4 @@ public static List createMap(RegisterConfig registerConfig, } return List.of(map); } - - /** - * @return {@code true} if a register is available for use by a register allocator otherwise - * {@code false} - */ - public boolean isAllocatable() { - return allocatable; - } - - /** - * @return {@code true} if a register whose value preservation (if required) across a call is - * the responsibility of the callee otherwise {@code false} - */ - public boolean isCalleeSave() { - return calleeSave; - } - - /** - * @return {@code true} if a register whose value preservation (if required) across a call is - * the responsibility of the caller otherwise {@code false} - */ - public boolean isCallerSave() { - return callerSave; - } } diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/RegisterConfig.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/RegisterConfig.java index 947c75a05fff4..d49a0708bf8d6 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/RegisterConfig.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/RegisterConfig.java @@ -102,7 +102,7 @@ default int getMaximumFrameSize() { * necessary. */ default PlatformKind getCalleeSaveRegisterStorageKind(Architecture arch, Register calleeSaveRegister) { - return arch.getLargestStorableKind(calleeSaveRegister.getRegisterCategory()); + return arch.getLargestStorableKind(calleeSaveRegister.registerCategory()); } /** diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/RegisterSaveLayout.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/RegisterSaveLayout.java index f55c846cc2a2e..3e0bd708db9f6 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/RegisterSaveLayout.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/RegisterSaveLayout.java @@ -22,7 +22,6 @@ */ package jdk.vm.ci.code; -import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.Map; @@ -31,30 +30,15 @@ /** * A map from registers to frame slots. This can be used to describe where callee saved registers * are saved in a callee's frame. + * + * @param registers the keys in the map. This array is now owned by this object and should not be mutated by the caller. + * @param slots frame slot index for each register in {@code registers}. This array is now owned by this object and + * should not be mutated by the caller. */ -public final class RegisterSaveLayout { +public record RegisterSaveLayout(Register[] registers, int[] slots) { - /** - * Keys. - */ - private final Register[] registers; - - /** - * Slot indexes relative to stack pointer. - */ - private final int[] slots; - - /** - * Creates a map from registers to frame slots. - * - * @param registers the keys in the map - * @param slots frame slot index for each register in {@code registers} - */ - @SuppressFBWarnings(value = "EI_EXPOSE_REP2", justification = "caller transfers ownership of `registers` and `slots`") - public RegisterSaveLayout(Register[] registers, int[] slots) { + public RegisterSaveLayout { assert registers.length == slots.length; - this.registers = registers; - this.slots = slots; assert registersToSlots(false).size() == registers.length : "non-unique registers"; assert new HashSet<>(registersToSlots(false).values()).size() == slots.length : "non-unqiue slots"; } @@ -113,22 +97,6 @@ public Map slotsToRegisters(boolean sorted) { return result; } - @Override - public int hashCode() { - throw new UnsupportedOperationException(); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj instanceof RegisterSaveLayout that) { - return Arrays.equals(registers, that.registers) && Arrays.equals(slots, that.slots); - } - return false; - } - @Override public String toString() { return registersToSlots(true).toString(); diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/RegisterValue.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/RegisterValue.java index 832612559bf44..d17fbe1f96256 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/RegisterValue.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/RegisterValue.java @@ -39,7 +39,7 @@ public final class RegisterValue extends AllocatableValue { @Override public String toString() { - return getRegister().name + getKindSuffix(); + return getRegister().name() + getKindSuffix(); } /** diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/TargetDescription.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/TargetDescription.java index 4578d3a8beaed..afa2b628b8ce0 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/TargetDescription.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/TargetDescription.java @@ -25,97 +25,33 @@ import static jdk.vm.ci.meta.MetaUtil.identityHashCodeString; import jdk.vm.ci.meta.JavaKind; -import jdk.internal.util.OperatingSystem; /** * Represents the target machine for a compiler, including the CPU architecture, the size of * pointers and references, alignment of stacks, caches, etc. + * + * @param arch CPU architecture of the target machine. + * @param isMP specifies if this is a multi-processor system. + * @param wordSize the machine word size on this target. + * @param wordJavaKind the {@link JavaKind} to be used for representing raw pointers and CPU registers in Java code. + * @param stackAlignment the stack alignment requirement of the platform. For example, from Appendix D of + * Intel 64 and IA-32 Architectures + * Optimization Reference Manual: + * "It is important to ensure that the stack frame is aligned to a 16-byte boundary upon function + * entry to keep local __m128 data, parameters, and XMM register spill locations aligned throughout + * a function invocation." + * @param implicitNullCheckLimit maximum constant displacement at which a memory access can no longer be an implicit null check. + * @param inlineObjects specifies if this target supports encoding objects inline in the machine code. */ -public class TargetDescription { - - public final boolean linuxOs = OperatingSystem.isLinux(); - public final boolean macOs = OperatingSystem.isMacOS(); - - public final Architecture arch; - - /** - * Specifies if this is a multi-processor system. - */ - public final boolean isMP; - - /** - * Specifies if this target supports encoding objects inline in the machine code. - */ - public final boolean inlineObjects; - - /** - * The machine word size on this target. - */ - public final int wordSize; - - /** - * The {@link JavaKind} to be used for representing raw pointers and CPU registers in Java code. - */ - public final JavaKind wordJavaKind; - - /** - * The stack alignment requirement of the platform. For example, from Appendix D of - * Intel 64 and IA-32 Architectures - * Optimization Reference Manual: - * - *

    -     *     "It is important to ensure that the stack frame is aligned to a
    -     *      16-byte boundary upon function entry to keep local __m128 data,
    -     *      parameters, and XMM register spill locations aligned throughout
    -     *      a function invocation."
    -     * 
    - */ - public final int stackAlignment; - - /** - * Maximum constant displacement at which a memory access can no longer be an implicit null - * check. - */ - public final int implicitNullCheckLimit; - +public record TargetDescription(Architecture arch, + boolean isMP, + int wordSize, + JavaKind wordJavaKind, + int stackAlignment, + int implicitNullCheckLimit, + boolean inlineObjects) { public TargetDescription(Architecture arch, boolean isMP, int stackAlignment, int implicitNullCheckLimit, boolean inlineObjects) { - this.arch = arch; - this.isMP = isMP; - this.wordSize = arch.getWordSize(); - this.wordJavaKind = JavaKind.fromWordSize(wordSize); - this.stackAlignment = stackAlignment; - this.implicitNullCheckLimit = implicitNullCheckLimit; - this.inlineObjects = inlineObjects; - + this(arch, isMP, arch.getWordSize(), JavaKind.fromWordSize(arch.getWordSize()), stackAlignment, implicitNullCheckLimit, inlineObjects); assert arch.getPlatformKind(wordJavaKind).equals(arch.getWordKind()); } - - @Override - public final int hashCode() { - throw new UnsupportedOperationException(); - } - - @Override - public final boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj instanceof TargetDescription that) { - // @formatter:off - return this.implicitNullCheckLimit == that.implicitNullCheckLimit - && this.inlineObjects == that.inlineObjects - && this.isMP == that.isMP - && this.stackAlignment == that.stackAlignment - && this.wordJavaKind.equals(that.wordJavaKind) - && this.wordSize == that.wordSize - && this.arch.equals(that.arch); - // @formatter:on - } - return false; - } - - @Override - public String toString() { - return identityHashCodeString(this); - } } diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/CompilerToVM.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/CompilerToVM.java index b4fd7d1245722..9a0fcb8cf108d 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/CompilerToVM.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/CompilerToVM.java @@ -1073,6 +1073,9 @@ HotSpotResolvedObjectTypeImpl getResolvedJavaType(long address) { native Object getFlagValue(String name); static List listFromTrustedArray(Object[] array) { + if (array == null) { + return List.of(); + } return SharedSecrets.getJavaUtilCollectionAccess().listFromTrustedArray(array); } diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotCodeCacheProvider.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotCodeCacheProvider.java index 4843fe01dac35..cb7b5ff64af02 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotCodeCacheProvider.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotCodeCacheProvider.java @@ -40,19 +40,9 @@ /** * HotSpot implementation of {@link CodeCacheProvider}. */ -public class HotSpotCodeCacheProvider implements CodeCacheProvider { - - protected final HotSpotJVMCIRuntime runtime; - private final HotSpotVMConfig config; - protected final TargetDescription target; - protected final RegisterConfig regConfig; - - public HotSpotCodeCacheProvider(HotSpotJVMCIRuntime runtime, TargetDescription target, RegisterConfig regConfig) { - this.runtime = runtime; - this.config = runtime.getConfig(); - this.target = target; - this.regConfig = regConfig; - } +public record HotSpotCodeCacheProvider(HotSpotJVMCIRuntime runtime, + TargetDescription target, + RegisterConfig regConfig) implements CodeCacheProvider { @Override public String getMarkName(Mark mark) { @@ -77,7 +67,7 @@ public String getTargetName(Call call) { HotSpotVMConfigStore store = runtime.getConfigStore(); for (Map.Entry e : store.getFields().entrySet()) { VMField field = e.getValue(); - if (field.isStatic() && field.value instanceof Long && ((Long) field.value) == address) { + if (field.isStatic() && field.value() instanceof Long && ((Long) field.value()) == address) { return e.getValue() + ":0x" + Long.toHexString(address); } } @@ -92,7 +82,7 @@ public RegisterConfig getRegisterConfig() { @Override public int getMinimumOutgoingSize() { - return config.runtimeCallStackSize; + return runtime.getConfig().runtimeCallStackSize; } private InstalledCode logOrDump(InstalledCode installedCode, CompiledCode compiledCode) { @@ -137,8 +127,8 @@ public InstalledCode installCode(ResolvedJavaMethod method, CompiledCode compile } int result = runtime.getCompilerToVM().installCode(hsCompiledCode, resultInstalledCode, failedSpeculationsAddress, speculations); - if (result != config.codeInstallResultOk) { - String resultDesc = config.getCodeInstallResultDescription(result); + if (result != runtime.getConfig().codeInstallResultOk) { + String resultDesc = runtime.getConfig().getCodeInstallResultDescription(result); if (hsCompiledNmethod != null) { String msg = hsCompiledNmethod.getInstallationFailureMessage(); if (msg != null) { @@ -146,7 +136,7 @@ public InstalledCode installCode(ResolvedJavaMethod method, CompiledCode compile } else { msg = String.format("Code installation failed: %s", resultDesc); } - throw new BailoutException(result >= config.codeInstallResultFirstPermanentBailout, msg); + throw new BailoutException(result >= runtime.getConfig().codeInstallResultFirstPermanentBailout, msg); } else { throw new BailoutException("Error installing %s: %s", ((HotSpotCompiledCode) compiledCode).getName(), resultDesc); } diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotCompilationRequestResult.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotCompilationRequestResult.java index 644a4f7d6cea9..981d8b9f89b66 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotCompilationRequestResult.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotCompilationRequestResult.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2025, 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 @@ -27,36 +27,15 @@ /** * HotSpot specific information about the result of a {@link CompilationRequest}. + * + * @param failureMessage A user readable description of the failure. + * @param retry whether this is a transient failure where retrying would help. + * @param inlinedBytecodes number of bytecodes inlined into the compilation, exclusive of the bytecodes in the root + * method. */ -public final class HotSpotCompilationRequestResult implements CompilationRequestResult { - - /** - * A user readable description of the failure. - * - * This field is read by the VM. - */ - private final String failureMessage; - - /** - * Whether this is a transient failure where retrying would help. - * - * This field is read by the VM. - */ - private final boolean retry; - - /** - * Number of bytecodes inlined into the compilation, exclusive of the bytecodes in the root - * method. - * - * This field is read by the VM. - */ - private final int inlinedBytecodes; - - private HotSpotCompilationRequestResult(String failureMessage, boolean retry, int inlinedBytecodes) { - this.failureMessage = failureMessage; - this.retry = retry; - this.inlinedBytecodes = inlinedBytecodes; - } +public record HotSpotCompilationRequestResult(String failureMessage, + boolean retry, + int inlinedBytecodes) implements CompilationRequestResult { @Override public Object getFailure() { @@ -67,7 +46,7 @@ public Object getFailure() { * Creates a result representing a successful compilation. * * @param inlinedBytecodes number of bytecodes inlined into the compilation, exclusive of the - * bytecodes in the root method + * bytecodes in the root method */ public static HotSpotCompilationRequestResult success(int inlinedBytecodes) { return new HotSpotCompilationRequestResult(null, true, inlinedBytecodes); @@ -77,21 +56,9 @@ public static HotSpotCompilationRequestResult success(int inlinedBytecodes) { * Creates a result representing a failed compilation. * * @param failureMessage a description of the failure - * @param retry whether this is a transient failure where retrying may succeed + * @param retry whether this is a transient failure where retrying may succeed */ public static HotSpotCompilationRequestResult failure(String failureMessage, boolean retry) { return new HotSpotCompilationRequestResult(failureMessage, retry, 0); } - - public String getFailureMessage() { - return failureMessage; - } - - public boolean getRetry() { - return retry; - } - - public int getInlinedBytecodes() { - return inlinedBytecodes; - } } diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotCompiledCode.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotCompiledCode.java index fb91b28b21242..b655a54249989 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotCompiledCode.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotCompiledCode.java @@ -153,14 +153,14 @@ public HotSpotCompiledCode(String name, this.name = name; this.targetCode = targetCode; this.targetCodeSize = targetCodeSize; - this.sites = sites == null ? List.of() : listFromTrustedArray(sites); - this.assumptions = assumptions == null ? List.of() : listFromTrustedArray(assumptions); - this.methods = methods == null ? List.of() : listFromTrustedArray(methods); + this.sites = listFromTrustedArray(sites); + this.assumptions = listFromTrustedArray(assumptions); + this.methods = listFromTrustedArray(methods); - this.comments = comments == null ? List.of() : listFromTrustedArray(comments); + this.comments = listFromTrustedArray(comments); this.dataSection = dataSection; this.dataSectionAlignment = dataSectionAlignment; - this.dataSectionPatches = dataSectionPatches == null ? List.of() : listFromTrustedArray(dataSectionPatches); + this.dataSectionPatches = listFromTrustedArray(dataSectionPatches); this.isImmutablePIC = isImmutablePIC; this.totalFrameSize = totalFrameSize; this.deoptRescueSlot = deoptRescueSlot; diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotCompiledCodeStream.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotCompiledCodeStream.java index c97b75def425a..fc6c527800076 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotCompiledCodeStream.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotCompiledCodeStream.java @@ -257,23 +257,7 @@ enum Tag { * Alternative to using {@link IdentityHashMap} which would require dealing with the * {@link IdentityHashMap#NULL_KEY} constant. */ - static class IdentityBox { - Object obj; - - IdentityBox(Object obj) { - this.obj = obj; - } - - @Override - public boolean equals(Object other) { - IdentityBox that = (IdentityBox) other; - return that.obj == obj; - } - - @Override - public int hashCode() { - return System.identityHashCode(obj); - } + record IdentityBox(Object obj) { } private HashMap objects; @@ -628,7 +612,7 @@ private Object[] finalizeObjectPool() throws JVMCIError { Object[] pool = new Object[objects.size()]; for (Map.Entry e : objects.entrySet()) { int id = e.getValue(); - Object object = e.getKey().obj; + Object object = e.getKey().obj(); if (object == null) { throw error("unexpected null in object pool at %d - map is %s", id, objects); } @@ -914,26 +898,26 @@ private void writeAssumptions(List assumptions) { switch (a) { case NoFinalizableSubclass noFinalizableSubclass -> { writeTag(NO_FINALIZABLE_SUBCLASS); - writeObjectType("receiverType", noFinalizableSubclass.receiverType); + writeObjectType("receiverType", noFinalizableSubclass.receiverType()); } case ConcreteSubtype cs -> { writeTag(CONCRETE_SUBTYPE); - writeObjectType("context", cs.context); - writeObjectType("subtype", cs.subtype); + writeObjectType("context", cs.context()); + writeObjectType("subtype", cs.subtype()); } case LeafType leafType -> { writeTag(LEAF_TYPE); - writeObjectType("context", leafType.context); + writeObjectType("context", leafType.context()); } case ConcreteMethod cm -> { writeTag(CONCRETE_METHOD); - writeObjectType("context", cm.context); - writeMethod("impl", cm.impl); + writeObjectType("context", cm.context()); + writeMethod("impl", cm.impl()); } case CallSiteTargetValue cs -> { writeTag(CALLSITE_TARGET_VALUE); - writeJavaValue(cs.callSite, JavaKind.Object); - writeJavaValue(cs.methodHandle, JavaKind.Object); + writeJavaValue(cs.callSite(), JavaKind.Object); + writeJavaValue(cs.methodHandle(), JavaKind.Object); } case null, default -> throw error("unexpected assumption %s", a); } @@ -1029,7 +1013,7 @@ private void writeMethod(String name, ResolvedJavaMethod method) { } private boolean isNarrowOop(Value oopValue) { - return oopValue.getPlatformKind() != runtime.getHostJVMCIBackend().getTarget().arch.getWordKind(); + return oopValue.getPlatformKind() != runtime.getHostJVMCIBackend().target().arch().getWordKind(); } private boolean isVector(Value value) { @@ -1232,23 +1216,23 @@ private void writeFrame(BytecodePosition pos, boolean fullInfo, int depth) { private void writeReferenceMap(ReferenceMap map) { HotSpotReferenceMap hsMap = (HotSpotReferenceMap) map; - int length = hsMap.objects.length; - writeU2("maxRegisterSize", hsMap.maxRegisterSize); - int derivedBaseLength = hsMap.derivedBase.length; - int sizeInBytesLength = hsMap.sizeInBytes.length; + int length = hsMap.objects().length; + writeU2("maxRegisterSize", hsMap.maxRegisterSize()); + int derivedBaseLength = hsMap.derivedBase().length; + int sizeInBytesLength = hsMap.sizeInBytes().length; if (derivedBaseLength != length || sizeInBytesLength != length) { throw error("arrays in reference map have different sizes: %d %d %d", length, derivedBaseLength, sizeInBytesLength); } writeU2("referenceMap:length", length); for (int i = 0; i < length; i++) { - Location derived = hsMap.derivedBase[i]; + Location derived = hsMap.derivedBase()[i]; writeBoolean("hasDerived", derived != null); - int size = hsMap.sizeInBytes[i]; + int size = hsMap.sizeInBytes()[i]; if (size % 4 != 0) { throw error("invalid oop size in ReferenceMap: %d", size); } writeU2("sizeInBytes", size); - writeLocation(hsMap.objects[i]); + writeLocation(hsMap.objects()[i]); if (derived != null) { writeLocation(derived); } @@ -1256,15 +1240,15 @@ private void writeReferenceMap(ReferenceMap map) { } private void writeLocation(Location loc) { - writeRegister(loc.reg); - writeU2("offset", loc.offset); + writeRegister(loc.reg()); + writeU2("offset", loc.offset()); } private void writeRegister(Register reg) { if (reg == null) { writeU2("register", NO_REGISTER); } else { - writeU2("register", reg.number); + writeU2("register", reg.number()); } } } diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotConstantPool.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotConstantPool.java index 96bdd7288805f..59ffe95d35f7d 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotConstantPool.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotConstantPool.java @@ -104,15 +104,7 @@ static boolean isInvokeHandleAlias(int opcode) { } } - static final class JvmConstant { - private final int tag; - private final String name; - - JvmConstant(int tag, String name) { - this.tag = tag; - this.name = name; - } - + record JvmConstant(int tag, String name) { @Override public String toString() { return name; @@ -189,15 +181,7 @@ static JvmConstants instance() { } } - private static class LookupTypeCacheElement { - int lastCpi = Integer.MIN_VALUE; - JavaType javaType; - - LookupTypeCacheElement(int lastCpi, JavaType javaType) { - super(); - this.lastCpi = lastCpi; - this.javaType = javaType; - } + private record LookupTypeCacheElement(int lastCpi, JavaType javaType) { } /** @@ -284,7 +268,7 @@ private JvmConstant getTagAt(int index) { */ long getEntryAt(int index) { checkBounds(index); - int offset = index * runtime().getHostJVMCIBackend().getTarget().wordSize; + int offset = index * runtime().getHostJVMCIBackend().target().wordSize(); return UNSAFE.getAddress(getConstantPoolPointer() + config().constantPoolSize + offset); } @@ -296,7 +280,7 @@ long getEntryAt(int index) { */ private int getIntAt(int index) { checkTag(index, constants.jvmInteger); - int offset = index * runtime().getHostJVMCIBackend().getTarget().wordSize; + int offset = index * runtime().getHostJVMCIBackend().target().wordSize(); return UNSAFE.getInt(getConstantPoolPointer() + config().constantPoolSize + offset); } @@ -308,7 +292,7 @@ private int getIntAt(int index) { */ private long getLongAt(int index) { checkTag(index, constants.jvmLong); - int offset = index * runtime().getHostJVMCIBackend().getTarget().wordSize; + int offset = index * runtime().getHostJVMCIBackend().target().wordSize(); return UNSAFE.getLong(getConstantPoolPointer() + config().constantPoolSize + offset); } @@ -320,7 +304,7 @@ private long getLongAt(int index) { */ private float getFloatAt(int index) { checkTag(index, constants.jvmFloat); - int offset = index * runtime().getHostJVMCIBackend().getTarget().wordSize; + int offset = index * runtime().getHostJVMCIBackend().target().wordSize(); return UNSAFE.getFloat(getConstantPoolPointer() + config().constantPoolSize + offset); } @@ -332,7 +316,7 @@ private float getFloatAt(int index) { */ private double getDoubleAt(int index) { checkTag(index, constants.jvmDouble); - int offset = index * runtime().getHostJVMCIBackend().getTarget().wordSize; + int offset = index * runtime().getHostJVMCIBackend().target().wordSize(); return UNSAFE.getDouble(getConstantPoolPointer() + config().constantPoolSize + offset); } @@ -344,7 +328,7 @@ private double getDoubleAt(int index) { */ private int getNameAndTypeAt(int index) { checkTag(index, constants.jvmNameAndType); - int offset = index * runtime().getHostJVMCIBackend().getTarget().wordSize; + int offset = index * runtime().getHostJVMCIBackend().target().wordSize(); return UNSAFE.getInt(getConstantPoolPointer() + config().constantPoolSize + offset); } @@ -408,7 +392,7 @@ private int getKlassRefIndexAt(int which, int opcode) { */ private int getUncachedKlassRefIndexAt(int index) { checkTagIsFieldOrMethod(index); - int offset = index * runtime().getHostJVMCIBackend().getTarget().wordSize; + int offset = index * runtime().getHostJVMCIBackend().target().wordSize(); final int refIndex = UNSAFE.getInt(getConstantPoolPointer() + config().constantPoolSize + offset); // klass ref index is in the low 16-bits. return refIndex & 0xFFFF; @@ -739,11 +723,11 @@ public JavaMethod lookupMethod(int rawIndex, int opcode, ResolvedJavaMethod call String name = compilerToVM().lookupNameInPool(this, rawIndex, opcode); HotSpotSignature signature = new HotSpotSignature(runtime(), compilerToVM().lookupSignatureInPool(this, rawIndex, opcode)); if (opcode == Bytecodes.INVOKEDYNAMIC) { - return new UnresolvedJavaMethod(name, signature, runtime().getMethodHandleClass()); + return new UnresolvedJavaMethod(runtime().getMethodHandleClass(), name, signature); } else { final int klassIndex = getKlassRefIndexAt(rawIndex, opcode); final Object type = compilerToVM().lookupKlassInPool(this, klassIndex); - return new UnresolvedJavaMethod(name, signature, getJavaType(type)); + return new UnresolvedJavaMethod(getJavaType(type), name, signature); } } } diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotJVMCIRuntime.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotJVMCIRuntime.java index 6946666ea4aef..840384a844c10 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotJVMCIRuntime.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotJVMCIRuntime.java @@ -475,7 +475,7 @@ static void parse(HotSpotJVMCIRuntime runtime) { * Gets the kind of a word value on the {@linkplain #getHostJVMCIBackend() host} backend. */ public static JavaKind getHostWordKind() { - return runtime().getHostJVMCIBackend().getCodeCache().getTarget().wordJavaKind; + return runtime().getHostJVMCIBackend().target().wordJavaKind(); } protected final CompilerToVM compilerToVm; @@ -720,7 +720,7 @@ private void expungeStaleKlassEntries() { } private JVMCIBackend registerBackend(JVMCIBackend backend) { - Class arch = backend.getCodeCache().getTarget().arch.getClass(); + Class arch = backend.target().arch().getClass(); JVMCIBackend oldValue = backends.put(arch, backend); assert oldValue == null : "cannot overwrite existing backend for architecture " + arch.getSimpleName(); return backend; @@ -808,13 +808,7 @@ public Field getMirror(ResolvedJavaField field) { return null; } - static class ErrorCreatingCompiler implements JVMCICompiler { - private final RuntimeException t; - - ErrorCreatingCompiler(RuntimeException t) { - this.t = t; - } - + record ErrorCreatingCompiler(RuntimeException t) implements JVMCICompiler { @Override public CompilationRequestResult compileMethod(CompilationRequest request) { throw t; diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotMetaAccessProvider.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotMetaAccessProvider.java index deb36d567c2c1..a08fad6686df8 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotMetaAccessProvider.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotMetaAccessProvider.java @@ -278,7 +278,7 @@ public long getMemorySize(JavaConstant constant) { return 0; } else { if (lookupJavaType.isArray()) { - int length = runtime.getHostJVMCIBackend().getConstantReflection().readArrayLength(constant); + int length = runtime.getHostJVMCIBackend().constantReflection().readArrayLength(constant); ResolvedJavaType elementType = lookupJavaType.getComponentType(); JavaKind elementKind = elementType.getJavaKind(); final int headerSize = runtime.getArrayBaseOffset(elementKind); diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotMethodData.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotMethodData.java index 00ff5ad7dd28f..4131b1aad105c 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotMethodData.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotMethodData.java @@ -215,13 +215,13 @@ public boolean isWithin(int position) { } public int getDeoptimizationCount(DeoptimizationReason reason) { - HotSpotMetaAccessProvider metaAccess = (HotSpotMetaAccessProvider) runtime().getHostJVMCIBackend().getMetaAccess(); + HotSpotMetaAccessProvider metaAccess = (HotSpotMetaAccessProvider) runtime().getHostJVMCIBackend().metaAccess(); int reasonIndex = metaAccess.convertDeoptReason(reason); return UNSAFE.getByte(methodDataPointer + state.config.methodDataOopTrapHistoryOffset + reasonIndex) & 0xFF; } public int getOSRDeoptimizationCount(DeoptimizationReason reason) { - HotSpotMetaAccessProvider metaAccess = (HotSpotMetaAccessProvider) runtime().getHostJVMCIBackend().getMetaAccess(); + HotSpotMetaAccessProvider metaAccess = (HotSpotMetaAccessProvider) runtime().getHostJVMCIBackend().metaAccess(); int reasonIndex = metaAccess.convertDeoptReason(reason); return UNSAFE.getByte(methodDataPointer + state.config.methodDataOopTrapHistoryOffset + state.config.deoptReasonOSROffset + reasonIndex) & 0xFF; } diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotReferenceMap.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotReferenceMap.java index 1e30db28ddd07..56f3c4cec6889 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotReferenceMap.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotReferenceMap.java @@ -22,56 +22,18 @@ */ package jdk.vm.ci.hotspot; -import java.util.Arrays; - import jdk.vm.ci.code.Location; import jdk.vm.ci.code.ReferenceMap; /** * Describes where the object references are in machine state, compliant with what HotSpot expects. + * + * @param objects This array is now owned by this object and must not be mutated by the caller. + * @param derivedBase This array is now owned by this object and must not be mutated by the caller. + * @param sizeInBytes This array is now owned by this object and must not be mutated by the caller. */ -public final class HotSpotReferenceMap extends ReferenceMap { - - final Location[] objects; - final Location[] derivedBase; - final int[] sizeInBytes; - final int maxRegisterSize; - - /** - * @param objects This array is now owned by this object and must not be mutated by the caller. - * @param derivedBase This array is now owned by this object and must not be mutated by the - * caller. - * @param sizeInBytes This array is now owned by this object and must not be mutated by the - * caller. - */ - @SuppressFBWarnings(value = "EI_EXPOSE_REP2", justification = "caller transfers ownership of `objects`, `derivedBase` and `sizeInBytes`") - public HotSpotReferenceMap(Location[] objects, Location[] derivedBase, int[] sizeInBytes, int maxRegisterSize) { - this.objects = objects; - this.derivedBase = derivedBase; - this.sizeInBytes = sizeInBytes; - this.maxRegisterSize = maxRegisterSize; - } - - @Override - public int hashCode() { - throw new UnsupportedOperationException(); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj instanceof HotSpotReferenceMap that) { - return sizeInBytes == that.sizeInBytes && maxRegisterSize == that.maxRegisterSize - && Arrays.equals(objects, that.objects) - && Arrays.equals(derivedBase, that.derivedBase); - } - return false; - } - - @Override - public String toString() { - return Arrays.toString(objects); - } +public record HotSpotReferenceMap(Location[] objects, + Location[] derivedBase, + int[] sizeInBytes, + int maxRegisterSize) implements ReferenceMap { } diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotResolvedObjectTypeImpl.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotResolvedObjectTypeImpl.java index fc1e9f2409727..32de93b37fbdd 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotResolvedObjectTypeImpl.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotResolvedObjectTypeImpl.java @@ -675,58 +675,20 @@ protected HotSpotResolvedObjectTypeImpl getArrayType() { /** * This class represents the field information for one field contained in the fields array of an * {@code InstanceKlass}. The implementation is similar to the native {@code FieldInfo} class. + * + * @param nameIndex index of field's name in the constant pool + * @param signatureIndex index of field's signature in the constant pool + * @param offset field's offset + * @param classfileFlags field's access flags (from the class file) + * @param internalFlags field's internal flags (from the VM) + * @param initializerIndex field's initial value index in the constant pool */ - static class FieldInfo { - - private final int nameIndex; - private final int signatureIndex; - private final int offset; - private final int classfileFlags; - private final int internalFlags; - private final int initializerIndex; - - /** - * Creates a field info with the provided indices. - * - * @param nameIndex index of field's name in the constant pool - * @param signatureIndex index of field's signature in the constant pool - * @param offset field's offset - * @param classfileFlags field's access flags (from the class file) - * @param internalFlags field's internal flags (from the VM) - * @param initializerIndex field's initial value index in the constant pool - */ - FieldInfo(int nameIndex, int signatureIndex, int offset, int classfileFlags, int internalFlags, int initializerIndex) { - this.nameIndex = nameIndex; - this.signatureIndex = signatureIndex; - this.offset = offset; - this.classfileFlags = classfileFlags; - this.internalFlags = internalFlags; - this.initializerIndex = initializerIndex; - } - - private int getClassfileFlags() { - return classfileFlags; - } - - private int getInternalFlags() { - return internalFlags; - } - - private int getNameIndex() { - return nameIndex; - } - - private int getSignatureIndex() { - return signatureIndex; - } - - private int getConstantValueIndex() { - return initializerIndex; - } - - public int getOffset() { - return offset; - } + record FieldInfo(int nameIndex, + int signatureIndex, + int offset, + int classfileFlags, + int internalFlags, + int initializerIndex) { /** * Returns the name of this field as a {@link String}. If the field is an internal field the @@ -766,11 +728,11 @@ public JavaType getType(HotSpotResolvedObjectTypeImpl klass) { } private boolean isInternal() { - return (getInternalFlags() & (1 << config().jvmFieldFlagInternalShift)) != 0; + return (internalFlags() & (1 << config().jvmFieldFlagInternalShift)) != 0; } public boolean isStatic() { - return Modifier.isStatic(getClassfileFlags()); + return Modifier.isStatic(classfileFlags()); } } @@ -848,8 +810,8 @@ private List getFields(boolean retrieveStaticFields, List T iterateFrames(ResolvedJavaMethod[] initialMethods, ResolvedJavaMethod[] matchingMethods, int initialSkip, InspectedFrameVisitor visitor) { diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotVMConfigAccess.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotVMConfigAccess.java index 15bd58a5a5d25..59321c0c1f49a 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotVMConfigAccess.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotVMConfigAccess.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2025, 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 @@ -32,6 +32,12 @@ */ public class HotSpotVMConfigAccess { + private final HotSpotVMConfigStore store; + + public HotSpotVMConfigAccess(HotSpotVMConfigStore store) { + this.store = store; + } + /** * Gets the available configuration data. */ @@ -42,7 +48,7 @@ public HotSpotVMConfigStore getStore() { /** * Gets the address of a C++ symbol. * - * @param name name of C++ symbol + * @param name name of C++ symbol * @param notPresent if non-null and the symbol is not present then this value is returned * @return the address of the symbol * @throws JVMCIError if the symbol is not present and {@code notPresent == null} @@ -73,8 +79,8 @@ public long getAddress(String name) { /** * Gets the value of a C++ constant. * - * @param name name of the constant (e.g., {@code "frame::arg_reg_save_area_bytes"}) - * @param type the boxed type to which the constant value will be converted + * @param name name of the constant (e.g., {@code "frame::arg_reg_save_area_bytes"}) + * @param type the boxed type to which the constant value will be converted * @param notPresent if non-null and the constant is not present then this value is returned * @return the constant value converted to {@code type} * @throws JVMCIError if the constant is not present and {@code notPresent == null} @@ -105,10 +111,10 @@ public T getConstant(String name, Class type) { /** * Gets the offset of a non-static C++ field. * - * @param name fully qualified name of the field - * @param type the boxed type to which the offset value will be converted (must be - * {@link Integer} or {@link Long}) - * @param cppType if non-null, the expected C++ type of the field (e.g., {@code "HeapWord*"}) + * @param name fully qualified name of the field + * @param type the boxed type to which the offset value will be converted (must be + * {@link Integer} or {@link Long}) + * @param cppType if non-null, the expected C++ type of the field (e.g., {@code "HeapWord*"}) * @param notPresent if non-null and the field is not present then this value is returned * @return the offset in bytes of the requested field * @throws JVMCIError if the field is static or not present and {@code notPresent} is null @@ -120,12 +126,12 @@ public T getFieldOffset(String name, Class type, String cppType, T notPre /** * Gets the offset of a non-static C++ field. * - * @param name fully qualified name of the field - * @param type the boxed type to which the offset value will be converted (must be - * {@link Integer} or {@link Long}) + * @param name fully qualified name of the field + * @param type the boxed type to which the offset value will be converted (must be + * {@link Integer} or {@link Long}) * @param notPresent if non-null and the field is not present then this value is returned * @param outCppType if non-null, the C++ type of the field (e.g., {@code "HeapWord*"}) is - * returned in element 0 of this array + * returned in element 0 of this array * @return the offset in bytes of the requested field * @throws JVMCIError if the field is static or not present and {@code notPresent} is null */ @@ -136,9 +142,9 @@ public T getFieldOffset(String name, Class type, T notPresent, String[] o /** * Gets the offset of a non-static C++ field. * - * @param name fully qualified name of the field - * @param type the boxed type to which the offset value will be converted (must be - * {@link Integer} or {@link Long}) + * @param name fully qualified name of the field + * @param type the boxed type to which the offset value will be converted (must be + * {@link Integer} or {@link Long}) * @param cppType if non-null, the expected C++ type of the field (e.g., {@code "HeapWord*"}) * @return the offset in bytes of the requested field * @throws JVMCIError if the field is static or not present @@ -152,7 +158,7 @@ public T getFieldOffset(String name, Class type, String cppType) { * * @param name fully qualified name of the field * @param type the boxed type to which the offset value will be converted (must be - * {@link Integer} or {@link Long}) + * {@link Integer} or {@link Long}) * @return the offset in bytes of the requested field * @throws JVMCIError if the field is static or not present */ @@ -166,20 +172,20 @@ private T getFieldOffset0(String name, Class type, T notPresent, String i if (entry == null) { return notPresent; } - if (entry.address != 0) { + if (entry.address() != 0) { throw new JVMCIError("cannot get offset of static field " + name); } if (outCppType != null) { - outCppType[0] = entry.type; + outCppType[0] = entry.type(); } - return type.cast(convertValue(name, type, entry.offset, inCppType)); + return type.cast(convertValue(name, type, entry.offset(), inCppType)); } /** * Gets the address of a static C++ field. * - * @param name fully qualified name of the field - * @param cppType if non-null, the expected C++ type of the field (e.g., {@code "HeapWord*"}) + * @param name fully qualified name of the field + * @param cppType if non-null, the expected C++ type of the field (e.g., {@code "HeapWord*"}) * @param notPresent if non-null and the field is not present then this value is returned * @return the address of the requested field * @throws JVMCIError if the field is not static or not present and {@code notPresent} is null @@ -191,10 +197,10 @@ public long getFieldAddress(String name, String cppType, Long notPresent) { /** * Gets the address of a static C++ field. * - * @param name fully qualified name of the field + * @param name fully qualified name of the field * @param notPresent if non-null and the field is not present then this value is returned * @param outCppType if non-null, the C++ type of the field (e.g., {@code "HeapWord*"}) is - * returned in element 0 of this array + * returned in element 0 of this array * @return the address of the requested field * @throws JVMCIError if the field is not static or not present and {@code notPresent} is null */ @@ -205,7 +211,7 @@ public long getFieldAddress(String name, Long notPresent, String[] outCppType) { /** * Gets the address of a static C++ field. * - * @param name fully qualified name of the field + * @param name fully qualified name of the field * @param cppType if non-null, the expected C++ type of the field (e.g., {@code "HeapWord*"}) * @return the address of the requested field * @throws JVMCIError if the field is not static or not present @@ -219,21 +225,21 @@ private long getFieldAddress0(String name, Long notPresent, String inCppType, St if (entry == null) { return notPresent; } - if (entry.address == 0) { + if (entry.address() == 0) { throw new JVMCIError(name + " is not a static field"); } if (outCppType != null) { - outCppType[0] = entry.type; + outCppType[0] = entry.type(); } - return entry.address; + return entry.address(); } /** * Gets the value of a static C++ field. * - * @param name fully qualified name of the field - * @param type the boxed type to which the constant value will be converted - * @param cppType if non-null, the expected C++ type of the field (e.g., {@code "HeapWord*"}) + * @param name fully qualified name of the field + * @param type the boxed type to which the constant value will be converted + * @param cppType if non-null, the expected C++ type of the field (e.g., {@code "HeapWord*"}) * @param notPresent if non-null and the field is not present then this value is returned * @return the value of the requested field * @throws JVMCIError if the field is not static or not present and {@code notPresent} is null @@ -245,8 +251,8 @@ public T getFieldValue(String name, Class type, String cppType, T notPres /** * Gets the value of a static C++ field. * - * @param name fully qualified name of the field - * @param type the boxed type to which the constant value will be converted + * @param name fully qualified name of the field + * @param type the boxed type to which the constant value will be converted * @param cppType if non-null, the expected C++ type of the field (e.g., {@code "HeapWord*"}) * @return the value of the requested field * @throws JVMCIError if the field is not static or not present @@ -258,11 +264,11 @@ public T getFieldValue(String name, Class type, String cppType) { /** * Gets the value of a static C++ field. * - * @param name fully qualified name of the field - * @param type the boxed type to which the constant value will be converted + * @param name fully qualified name of the field + * @param type the boxed type to which the constant value will be converted * @param notPresent if non-null and the field is not present then this value is returned * @param outCppType if non-null, the C++ type of the field (e.g., {@code "HeapWord*"}) is - * returned in element 0 of this array + * returned in element 0 of this array * @return the value of the requested field * @throws JVMCIError if the field is not static or not present and {@code notPresent} is null */ @@ -287,20 +293,20 @@ private T getFieldValue0(String name, Class type, T notPresent, String in if (entry == null) { return notPresent; } - if (entry.value == null) { + if (entry.value() == null) { throw new JVMCIError(name + " is not a static field "); } if (outCppType != null) { - outCppType[0] = entry.type; + outCppType[0] = entry.type(); } - return type.cast(convertValue(name, type, entry.value, inCppType)); + return type.cast(convertValue(name, type, entry.value(), inCppType)); } /** * Gets a C++ field. * - * @param name fully qualified name of the field - * @param cppType if non-null, the expected C++ type of the field (e.g., {@code "HeapWord*"}) + * @param name fully qualified name of the field + * @param cppType if non-null, the expected C++ type of the field (e.g., {@code "HeapWord*"}) * @param required specifies if the field must be present * @return the field * @throws JVMCIError if the field is not present and {@code required == true} @@ -315,8 +321,8 @@ public VMField getField(String name, String cppType, boolean required) { } // Make sure the native type is still the type we expect. - if (cppType != null && !cppType.equals(entry.type)) { - throw new JVMCIError("expected type " + cppType + " but VM field " + name + " is of type " + entry.type); + if (cppType != null && !cppType.equals(entry.type())) { + throw new JVMCIError("expected type " + cppType + " but VM field " + name + " is of type " + entry.type()); } return entry; } @@ -327,7 +333,7 @@ public VMField getField(String name, String cppType, boolean required) { * @param name name of the flag (e.g., {@code "CompileTheWorldStartAt"}) * @param type the boxed type to which the flag's value will be converted * @return the flag's value converted to {@code type} or {@code notPresent} if the flag is not - * present + * present * @throws JVMCIError if the flag is not present */ public T getFlag(String name, Class type) { @@ -337,11 +343,11 @@ public T getFlag(String name, Class type) { /** * Gets a VM flag value. * - * @param name name of the flag (e.g., {@code "CompileTheWorldStartAt"}) - * @param type the boxed type to which the flag's value will be converted + * @param name name of the flag (e.g., {@code "CompileTheWorldStartAt"}) + * @param type the boxed type to which the flag's value will be converted * @param notPresent if non-null and the flag is not present then this value is returned * @return the flag's value converted to {@code type} or {@code notPresent} if the flag is not - * present + * present * @throws JVMCIError if the flag is not present and {@code notPresent == null} */ public T getFlag(String name, Class type, T notPresent) { @@ -360,15 +366,15 @@ public T getFlag(String name, Class type, T notPresent) { cppType = null; } } else { - value = entry.value; - cppType = entry.type; + value = entry.value(); + cppType = entry.type(); } return type.cast(convertValue(name, type, value, cppType)); } private JVMCIError missingEntry(String category, String name, Set keys) { throw new JVMCIError("expected VM %s not found in %s: %s%nAvailable values:%n %s", category, store, name, - keys.stream().sorted().collect(Collectors.joining(System.lineSeparator() + " "))); + keys.stream().sorted().collect(Collectors.joining(System.lineSeparator() + " "))); } private static Object convertValue(String name, Class toType, Object value, String cppType) throws JVMCIError { @@ -400,10 +406,4 @@ private static Object convertValue(String name, Class toType, Object valu throw new JVMCIError("cannot convert " + name + " of type " + value.getClass().getSimpleName() + (cppType == null ? "" : " [" + cppType + "]") + " to " + toType.getSimpleName()); } - - private final HotSpotVMConfigStore store; - - public HotSpotVMConfigAccess(HotSpotVMConfigStore store) { - this.store = store; - } } diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotVMConfigStore.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotVMConfigStore.java index 4e981c42ce084..cb8b682eeaa83 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotVMConfigStore.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotVMConfigStore.java @@ -90,13 +90,13 @@ public VMIntrinsicMethod getIntrinsic(int intrinsicID) { // valid intrinsicID starts from 1 VMIntrinsicMethod intrinsic = vmIntrinsics.get(intrinsicID - 1); // We speculate that vmIntrinsics are sorted by ID - if (intrinsic.id == intrinsicID) { + if (intrinsic.id() == intrinsicID) { return intrinsic; } } // Assumption failed, fall back to iteration for (VMIntrinsicMethod intrinsic : vmIntrinsics) { - if (intrinsic.id == intrinsicID) { + if (intrinsic.id() == intrinsicID) { return intrinsic; } } @@ -149,7 +149,7 @@ public VMIntrinsicMethod getIntrinsic(int intrinsicID) { try (InitTimer _ = timer("HotSpotVMConfigStore fill maps")) { for (VMField vmField : vmFieldsInfo) { - vmFields.put(vmField.name, vmField); + vmFields.put(vmField.name(), vmField); } for (int i = 0; i < vmConstantsInfo.length / 2; i++) { @@ -165,7 +165,7 @@ public VMIntrinsicMethod getIntrinsic(int intrinsicID) { } for (VMFlag vmFlag : vmFlagsInfo) { - vmFlags.put(vmFlag.name, vmFlag); + vmFlags.put(vmFlag.name(), vmFlag); } } } @@ -185,15 +185,15 @@ void printConfig(HotSpotJVMCIRuntime runtime) { TreeMap fields = new TreeMap<>(getFields()); for (VMField field : fields.values()) { if (!field.isStatic()) { - printConfigLine(runtime, "[vmconfig:instance field] %s %s {offset=%d[0x%x]}%n", field.type, field.name, field.offset, field.offset); + printConfigLine(runtime, "[vmconfig:instance field] %s %s {offset=%d[0x%x]}%n", field.type(), field.name(), field.offset(), field.offset()); } else { - String value = field.value == null ? "null" : field.value instanceof Boolean ? field.value.toString() : String.format("%d[0x%x]", field.value, field.value); - printConfigLine(runtime, "[vmconfig:static field] %s %s = %s {address=0x%x}%n", field.type, field.name, value, field.address); + String value = field.value() == null ? "null" : field.value() instanceof Boolean ? field.value().toString() : String.format("%d[0x%x]", field.value(), field.value()); + printConfigLine(runtime, "[vmconfig:static field] %s %s = %s {address=0x%x}%n", field.type(), field.name(), value, field.address()); } } TreeMap flags = new TreeMap<>(getFlags()); for (VMFlag flag : flags.values()) { - printConfigLine(runtime, "[vmconfig:flag] %s %s = %s%n", flag.type, flag.name, flag.value); + printConfigLine(runtime, "[vmconfig:flag] %s %s = %s%n", flag.type(), flag.name(), flag.value()); } TreeMap addresses = new TreeMap<>(getAddresses()); for (Map.Entry e : addresses.entrySet()) { @@ -205,7 +205,7 @@ void printConfig(HotSpotJVMCIRuntime runtime) { } for (VMIntrinsicMethod e : getIntrinsics()) { printConfigLine(runtime, "[vmconfig:intrinsic] %d = (available:%b c1Supported:%b c2Supported:%b) %s.%s %s%n", - e.id, e.isAvailable, e.c1Supported, e.c2Supported, e.declaringClass, e.name, e.descriptor); + e.id(), e.isAvailable(), e.c1Supported(), e.c2Supported(), e.declaringClass(), e.name(), e.descriptor()); } } diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/IndirectHotSpotObjectConstantImpl.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/IndirectHotSpotObjectConstantImpl.java index 0f96ecf8db103..8fca9263deed5 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/IndirectHotSpotObjectConstantImpl.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/IndirectHotSpotObjectConstantImpl.java @@ -50,16 +50,7 @@ final class IndirectHotSpotObjectConstantImpl extends HotSpotObjectConstantImpl final IndirectHotSpotObjectConstantImpl base; - private static class Audit { - final Object scope; - final long handle; - final Throwable origin; - - Audit(Object scope, long handle, Throwable origin) { - this.scope = scope; - this.handle = handle; - this.origin = origin; - } + private record Audit(Object scope, long handle, Throwable origin) { } /** diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/VMField.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/VMField.java index 21755445ca0ee..1411cb4978f63 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/VMField.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/VMField.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2025, 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,36 +24,21 @@ /** * Describes a C++ field exposed via {@link HotSpotVMConfigAccess}. + * + * @param name fully qualified name of the represented field (e.g., "Klass::_name"). + * @param type the represented field's type (e.g., "Symbol*"). This may be {@code null}. + * @param offset if the represented field is non-static, this is its offset within the containing structure. + * @param address if the represented field is static, this is its address. Otherwise, this is 0. + * @param value Value of the field represented as a boxed boolean if its C++ type is bool otherwise as a boxed long; + * only valid for non-oop static fields. This value is only captured once, during JVMCI initialization. + * If {@link #type} cannot be meaningfully (e.g., a struct) or safely (e.g., an oop) expressed as a + * boxed object, this is {@code null}. */ -public final class VMField { - - /** - * Fully qualified name of the represented field (e.g., "Klass::_name"). - */ - public final String name; - - /** - * The represented field's type (e.g., "Symbol*"). This may be {@code null}. - */ - public final String type; - - /** - * If the represented field is non-static, this is its offset within the containing structure. - */ - public final long offset; - - /** - * If the represented field is static, this is its address. Otherwise, this is 0. - */ - public final long address; - - /** - * Value of the field represented as a boxed boolean if its C++ type is bool otherwise as a - * boxed long; only valid for non-oop static fields. This value is only captured once, during - * JVMCI initialization. If {@link #type} cannot be meaningfully (e.g., a struct) or safely - * (e.g., an oop) expressed as a boxed object, this is {@code null}. - */ - public final Object value; +public record VMField(String name, + String type, + long offset, + long address, + Object value) { /** * Determines if the represented field is static. @@ -62,18 +47,6 @@ public boolean isStatic() { return address != 0; } - /** - * Creates a description of a non-static field. - */ - @VMEntryPoint - public VMField(String name, String type, long offset, long address, Object value) { - this.name = name; - this.type = type; - this.offset = offset; - this.address = address; - this.value = value; - } - @Override public String toString() { String val = value == null ? "null" : (type.contains("*") ? String.format("0x%x", value) : String.format("%s", value)); diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/VMFlag.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/VMFlag.java index 66030bbcfb08a..d0e227a6760d9 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/VMFlag.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/VMFlag.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2025, 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,33 +24,10 @@ /** * Describes a VM flag exposed via {@link HotSpotVMConfigAccess}. + * + * @param name the name of the flag. + * @param type the C++ type of the flag. + * @param value the flag's value. */ -public final class VMFlag { - - /** - * The name of the flag. - */ - public final String name; - - /** - * The C++ type of the flag. - */ - public final String type; - - /** - * The flag's value. - */ - public final Object value; - - @VMEntryPoint - VMFlag(String name, String type, Object value) { - this.name = name; - this.type = type; - this.value = value; - } - - @Override - public String toString() { - return String.format("Flag[type=%s, name=%s, value=%s]", type, name, value); - } +public record VMFlag(String name, String type, Object value) { } diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/VMIntrinsicMethod.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/VMIntrinsicMethod.java index 64e6b9d9ee712..ce09b82e4fa17 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/VMIntrinsicMethod.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/VMIntrinsicMethod.java @@ -26,86 +26,26 @@ /** * Describes a method for which the VM has an intrinsic implementation. + * + * @param declaringClass the name of the class declaring the intrinsified method. The name is in class file format + * (see JVMS {@jvms 4.2.1}). For example, {@code "java/lang/Thread"} instead of + * {@code "java.lang.Thread"}. + * @param name the name of the intrinsified method. This is not guaranteed to be a legal method name (e.g., + * there is a HotSpot intrinsic with the name {@code ""}). + * @param descriptor the {@link Signature#toMethodDescriptor() descriptor} of the intrinsified method. This is not + * guaranteed to be a legal method descriptor (e.g., intrinsics for signature polymorphic + * methods have a descriptor of {@code "*"}). + * @param id the unique VM identifier for the intrinsic. + * @param isAvailable this value reflects the `ControlIntrinsic`, `DisableIntrinsic` and `UseXXXIntrinsic` VM flags + * as well as other factors such as the current CPU. + * @param c1Supported true if this intrinsic is supported by C1. + * @param c2Supported true if this intrinsic is supported by C2. */ -public final class VMIntrinsicMethod { - - /** - * The name of the class declaring the intrinsified method. The name is in class file format - * (see JVMS {@jvms 4.2.1}). For example, {@code "java/lang/Thread"} instead of - * {@code "java.lang.Thread"}. - */ - public final String declaringClass; - - /** - * The name of the intrinsified method. This is not guaranteed to be a legal method name (e.g., - * there is a HotSpot intrinsic with the name {@code ""}). - */ - public final String name; - - /** - * The {@link Signature#toMethodDescriptor() descriptor} of the intrinsified method. This is not - * guaranteed to be a legal method descriptor (e.g., intrinsics for signature polymorphic - * methods have a descriptor of {@code "*"}). - */ - public final String descriptor; - - /** - * The unique VM identifier for the intrinsic. - */ - public final int id; - - /** - * This value reflects the `ControlIntrinsic`, `DisableIntrinsic` and `UseXXXIntrinsic` VM flags - * as well as other factors such as the current CPU. - */ - public final boolean isAvailable; - - /** - * True if this intrinsic is supported by C1. - */ - public final boolean c1Supported; - - /** - * True if this intrinsic is supported by C2. - */ - public final boolean c2Supported; - - @VMEntryPoint - VMIntrinsicMethod(String declaringClass, String name, String descriptor, int id, - boolean isAvailable, boolean c1Supported, boolean c2Supported) { - this.declaringClass = declaringClass; - this.name = name; - this.descriptor = descriptor; - this.id = id; - this.isAvailable = isAvailable; - this.c1Supported = c1Supported; - this.c2Supported = c2Supported; - } - - @Override - public boolean equals(Object obj) { - if (obj instanceof VMIntrinsicMethod that) { - if (that.id == this.id) { - assert that.name.equals(this.name) && - that.declaringClass.equals(this.declaringClass) && - that.descriptor.equals(this.descriptor) && - that.isAvailable == this.isAvailable && - that.c1Supported == this.c1Supported && - that.c2Supported == this.c2Supported; - return true; - } - } - return false; - } - - @Override - public int hashCode() { - return id; - } - - @Override - public String toString() { - return String.format("IntrinsicMethod[declaringClass=%s, name=%s, descriptor=%s, id=%d, isAvailable=%b, c1Supported=%b, c2Supported=%b]", - declaringClass, name, descriptor, id, isAvailable, c1Supported, c2Supported); - } +public record VMIntrinsicMethod(String declaringClass, + String name, + String descriptor, + int id, + boolean isAvailable, + boolean c1Supported, + boolean c2Supported) { } diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/aarch64/AArch64HotSpotJVMCIBackendFactory.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/aarch64/AArch64HotSpotJVMCIBackendFactory.java index 875a59caea0e3..f17eb5a50dd99 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/aarch64/AArch64HotSpotJVMCIBackendFactory.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/aarch64/AArch64HotSpotJVMCIBackendFactory.java @@ -27,6 +27,7 @@ import java.util.Collections; import java.util.EnumSet; import java.util.Map; +import jdk.internal.util.OperatingSystem; import jdk.vm.ci.aarch64.AArch64; import jdk.vm.ci.aarch64.AArch64.CPUFeature; import jdk.vm.ci.code.Architecture; @@ -67,7 +68,7 @@ private static RegisterConfig createRegisterConfig(AArch64HotSpotVMConfig config // ARMv8 defines r18 as being available to the platform ABI. Windows // and Darwin use it for such. Linux doesn't assign it and thus r18 can // be used as an additional register. - boolean canUsePlatformRegister = target.linuxOs; + boolean canUsePlatformRegister = OperatingSystem.isLinux(); return new AArch64HotSpotRegisterConfig(target, config.useCompressedOops, canUsePlatformRegister); } diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/aarch64/AArch64HotSpotRegisterConfig.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/aarch64/AArch64HotSpotRegisterConfig.java index 3414788b38b4f..2af81f19ad9f1 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/aarch64/AArch64HotSpotRegisterConfig.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/aarch64/AArch64HotSpotRegisterConfig.java @@ -55,6 +55,7 @@ import java.util.List; import java.util.Set; +import jdk.internal.util.OperatingSystem; import jdk.vm.ci.aarch64.AArch64; import jdk.vm.ci.code.Architecture; import jdk.vm.ci.code.CallingConvention; @@ -98,7 +99,7 @@ public List getAllocatableRegisters() { public List filterAllocatableRegisters(PlatformKind kind, List registers) { ArrayList list = new ArrayList<>(); for (Register reg : registers) { - if (target.arch.canStoreValue(reg.getRegisterCategory(), kind)) { + if (target.arch().canStoreValue(reg.registerCategory(), kind)) { list.add(reg); } } @@ -161,7 +162,7 @@ private static List initAllocatable(Architecture arch, boolean reserve } public AArch64HotSpotRegisterConfig(TargetDescription target, boolean useCompressedOops, boolean canUsePlatformRegister) { - this(target, initAllocatable(target.arch, useCompressedOops, canUsePlatformRegister)); + this(target, initAllocatable(target.arch(), useCompressedOops, canUsePlatformRegister)); assert callerSaved.size() >= allocatable.size(); } @@ -220,7 +221,7 @@ public List getCallingConventionRegisters(Type type, JavaKind kind) { private int parseStackArg(ValueKind valueKind, AllocatableValue[] locations, int index, int currentStackOffset, HotSpotCallingConventionType type) { int kindSize = valueKind.getPlatformKind().getSizeInBytes(); locations[index] = StackSlot.get(valueKind, currentStackOffset, !type.out); - currentStackOffset += Math.max(kindSize, target.wordSize); + currentStackOffset += Math.max(kindSize, target.wordSize()); return currentStackOffset; } @@ -239,7 +240,7 @@ private int parseDarwinNativeStackArg(ValueKind valueKind, AllocatableValue[] } private CallingConvention callingConvention(List generalParameterRegisters, JavaType returnType, List parameterTypes, HotSpotCallingConventionType type, - ValueKindFactory valueKindFactory) { + ValueKindFactory valueKindFactory) { AllocatableValue[] locations = new AllocatableValue[parameterTypes.size()]; int currentGeneral = 0; @@ -274,7 +275,7 @@ private CallingConvention callingConvention(List generalParameterRegis } if (locations[i] == null) { - if (target.macOs && type == HotSpotCallingConventionType.NativeCall) { + if (OperatingSystem.isMacOS() && type == HotSpotCallingConventionType.NativeCall) { currentStackOffset = parseDarwinNativeStackArg(valueKindFactory.getValueKind(kind), locations, i, currentStackOffset, type); } else { currentStackOffset = parseStackArg(valueKindFactory.getValueKind(kind), locations, i, currentStackOffset, type); diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/amd64/AMD64HotSpotRegisterConfig.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/amd64/AMD64HotSpotRegisterConfig.java index 356e3f8164fb1..4cfae6feb717e 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/amd64/AMD64HotSpotRegisterConfig.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/amd64/AMD64HotSpotRegisterConfig.java @@ -88,7 +88,7 @@ public List getAllocatableRegisters() { public List filterAllocatableRegisters(PlatformKind kind, List registers) { ArrayList list = new ArrayList<>(); for (Register reg : registers) { - if (target.arch.canStoreValue(reg.getRegisterCategory(), kind)) { + if (target.arch().canStoreValue(reg.registerCategory(), kind)) { list.add(reg); } } @@ -137,7 +137,7 @@ private static List initAllocatable(Architecture arch, boolean reserve } public AMD64HotSpotRegisterConfig(TargetDescription target, boolean useCompressedOops, boolean windowsOs) { - this(target, initAllocatable(target.arch, useCompressedOops), windowsOs); + this(target, initAllocatable(target.arch(), useCompressedOops), windowsOs); assert callerSaved.size() >= allocatable.size(); } @@ -167,7 +167,7 @@ public AMD64HotSpotRegisterConfig(TargetDescription target, List alloc callerSaved = List.copyOf(callerSaveSet); allAllocatableAreCallerSaved = true; - attributesMap = RegisterAttributes.createMap(this, target.arch.getRegisters()); + attributesMap = RegisterAttributes.createMap(this, target.arch().getRegisters()); } @Override @@ -227,7 +227,7 @@ private CallingConvention callingConvention(List generalParameterRegis int currentGeneral = 0; int currentXMM = 0; - int currentStackOffset = type == HotSpotCallingConventionType.NativeCall && needsNativeStackHomeSpace ? generalParameterRegisters.size() * target.wordSize : 0; + int currentStackOffset = type == HotSpotCallingConventionType.NativeCall && needsNativeStackHomeSpace ? generalParameterRegisters.size() * target.wordSize() : 0; for (int i = 0; i < parameterTypes.size(); i++) { final JavaKind kind = parameterTypes.get(i).getJavaKind().getStackKind(); @@ -259,7 +259,7 @@ private CallingConvention callingConvention(List generalParameterRegis if (locations[i] == null) { ValueKind valueKind = valueKindFactory.getValueKind(kind); locations[i] = StackSlot.get(valueKind, currentStackOffset, !type.out); - currentStackOffset += Math.max(valueKind.getPlatformKind().getSizeInBytes(), target.wordSize); + currentStackOffset += Math.max(valueKind.getPlatformKind().getSizeInBytes(), target.wordSize()); } } assert !unified || currentXMM == 0 : "shouldn't be used in unified mode"; diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/riscv64/RISCV64HotSpotJVMCIBackendFactory.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/riscv64/RISCV64HotSpotJVMCIBackendFactory.java index 35b6bea6c6d32..2b98102a7dab6 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/riscv64/RISCV64HotSpotJVMCIBackendFactory.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/riscv64/RISCV64HotSpotJVMCIBackendFactory.java @@ -27,6 +27,7 @@ import java.util.Collections; import java.util.EnumSet; import java.util.Map; +import jdk.internal.util.OperatingSystem; import jdk.vm.ci.code.Architecture; import jdk.vm.ci.code.RegisterConfig; import jdk.vm.ci.code.TargetDescription; @@ -64,7 +65,7 @@ protected HotSpotConstantReflectionProvider createConstantReflection(HotSpotJVMC } private static RegisterConfig createRegisterConfig(RISCV64HotSpotVMConfig config, TargetDescription target) { - return new RISCV64HotSpotRegisterConfig(target, config.useCompressedOops, target.linuxOs); + return new RISCV64HotSpotRegisterConfig(target, config.useCompressedOops); } protected HotSpotCodeCacheProvider createCodeCache(HotSpotJVMCIRuntime runtime, TargetDescription target, RegisterConfig regConfig) { diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/riscv64/RISCV64HotSpotRegisterConfig.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/riscv64/RISCV64HotSpotRegisterConfig.java index f95fe45e11d48..c7ccafe43fa4d 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/riscv64/RISCV64HotSpotRegisterConfig.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/riscv64/RISCV64HotSpotRegisterConfig.java @@ -98,7 +98,7 @@ public List getAllocatableRegisters() { public List filterAllocatableRegisters(PlatformKind kind, List registers) { ArrayList list = new ArrayList<>(); for (Register reg : registers) { - if (target.arch.canStoreValue(reg.getRegisterCategory(), kind)) { + if (target.arch().canStoreValue(reg.registerCategory(), kind)) { list.add(reg); } } @@ -153,8 +153,8 @@ private static List initAllocatable(Architecture arch, boolean reserve return List.of(registers); } - public RISCV64HotSpotRegisterConfig(TargetDescription target, boolean useCompressedOops, boolean linuxOs) { - this(target, initAllocatable(target.arch, useCompressedOops)); + public RISCV64HotSpotRegisterConfig(TargetDescription target, boolean useCompressedOops) { + this(target, initAllocatable(target.arch(), useCompressedOops)); assert callerSaved.size() >= allocatable.size(); } @@ -250,7 +250,7 @@ private CallingConvention callingConvention(List generalParameterRegis if (locations[i] == null) { ValueKind valueKind = valueKindFactory.getValueKind(kind); locations[i] = StackSlot.get(valueKind, currentStackOffset, !type.out); - currentStackOffset += Math.max(valueKind.getPlatformKind().getSizeInBytes(), target.wordSize); + currentStackOffset += Math.max(valueKind.getPlatformKind().getSizeInBytes(), target.wordSize()); } } diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/AnnotationData.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/AnnotationData.java index e85dc66156b0e..9c109d0f59f7a 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/AnnotationData.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/AnnotationData.java @@ -31,56 +31,59 @@ /** * Represents an annotation where element values are represented with the types described * {@linkplain #get here}. - * + *

    * In contrast to the standard annotation API based on {@link Annotation}, use of * {@link AnnotationData} allows annotations to be queried without the JVMCI runtime having to * support dynamic loading of arbitrary {@link Annotation} classes. Such support is impossible in a * closed world, ahead-of-time compiled environment such as libgraal. + * + * @param type the annotation interface of this annotation, represented as a {@link JavaType} + * @param elements the names and values of this annotation's element values. Each value's type + * must be one of the {@code AnnotationData} types described {@linkplain #get here} + * or it must be a {@link ErrorData} object whose {@code toString()} value describes + * the error raised while parsing the element. There is no distinction between a + * value explicitly present in the annotation and an element's default value. */ -public final class AnnotationData { - - private final JavaType type; - private final Map elements; +public record AnnotationData(JavaType type, Map elements) { private static final Set> ELEMENT_TYPES = Set.of( - Boolean.class, - Byte.class, - Character.class, - Short.class, - Integer.class, - Float.class, - Long.class, - Double.class, - String.class, - EnumData.class, - AnnotationData.class); + Boolean.class, + Byte.class, + Character.class, + Short.class, + Integer.class, + Float.class, + Long.class, + Double.class, + String.class, + EnumData.class, + AnnotationData.class); /** * Creates an annotation. * - * @param type the annotation interface of this annotation, represented as a {@link JavaType} + * @param type the annotation interface of this annotation, represented as a {@link JavaType} * @param elements the names and values of this annotation's element values. Each value's type - * must be one of the {@code AnnotationData} types described {@linkplain #get here} - * or it must be a {@link ErrorData} object whose {@code toString()} value describes - * the error raised while parsing the element. There is no distinction between a - * value explicitly present in the annotation and an element's default value. + * must be one of the {@code AnnotationData} types described {@linkplain #get here} + * or it must be a {@link ErrorData} object whose {@code toString()} value describes + * the error raised while parsing the element. There is no distinction between a + * value explicitly present in the annotation and an element's default value. * @throws IllegalArgumentException if the value of an entry in {@code elements} is not of an - * accepted type - * @throws NullPointerException if any of the above parameters is null or any entry in - * {@code elements} is null + * accepted type + * @throws NullPointerException if any of the above parameters is null or any entry in + * {@code elements} is null */ public AnnotationData(JavaType type, Map.Entry[] elements) { - this.type = Objects.requireNonNull(type); + this(Objects.requireNonNull(type), Map.ofEntries(elements)); for (Map.Entry e : elements) { Object value = e.getValue(); if (!(value instanceof ErrorData) && - !(value instanceof JavaType) && - !(value instanceof List) && - !ELEMENT_TYPES.contains(value.getClass())) { + !(value instanceof JavaType) && + !(value instanceof List) && + !ELEMENT_TYPES.contains(value.getClass())) { throw new IllegalArgumentException("illegal type for element " + e.getKey() + ": " + value.getClass().getName()); } } - this.elements = Map.ofEntries(elements); } /** @@ -140,21 +143,4 @@ public V get(String name, Class elementType) { public String toString() { return "@" + type.getName() + "(" + elements + ")"; } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj instanceof AnnotationData that) { - return this.type.equals(that.type) && this.elements.equals(that.elements); - - } - return false; - } - - @Override - public int hashCode() { - return type.hashCode() ^ elements.hashCode(); - } } diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/Assumptions.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/Assumptions.java index 1d15d25d666e3..631b61a0fb50f 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/Assumptions.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/Assumptions.java @@ -37,7 +37,7 @@ public final class Assumptions implements Iterable { * be invalidated by subsequent execution (e.g., that a class has no subclasses implementing * {@link NoFinalizableSubclass Object.finalize()}). */ - public abstract static class Assumption { + public interface Assumption { } /** @@ -103,203 +103,51 @@ public String toString() { /** * An assumption that a given class has no subclasses implementing {@code Object#finalize()}). */ - public static final class NoFinalizableSubclass extends Assumption { - - public final ResolvedJavaType receiverType; - - public NoFinalizableSubclass(ResolvedJavaType receiverType) { - this.receiverType = receiverType; - } - - @Override - public int hashCode() { - return 31 + receiverType.hashCode(); - } - - @Override - public boolean equals(Object obj) { - if (obj instanceof NoFinalizableSubclass other) { - return other.receiverType.equals(receiverType); - } - return false; - } - - @Override - public String toString() { - return "NoFinalizableSubclass[receiverType=" + receiverType.toJavaName() + "]"; - } - + public record NoFinalizableSubclass(ResolvedJavaType receiverType) implements Assumption { } /** * An assumption that a given abstract or interface type has one direct concrete subtype. There * is no requirement that the subtype is a leaf type. + * + * @param context type the assumption is made about. + * @param subtype assumed concrete sub-type of the context type. */ - public static final class ConcreteSubtype extends Assumption { - - /** - * Type the assumption is made about. - */ - public final ResolvedJavaType context; - - /** - * Assumed concrete sub-type of the context type. - */ - public final ResolvedJavaType subtype; - - public ConcreteSubtype(ResolvedJavaType context, ResolvedJavaType subtype) { - this.context = context; - this.subtype = subtype; + public record ConcreteSubtype(ResolvedJavaType context, ResolvedJavaType subtype) implements Assumption { + public ConcreteSubtype { assert context.isAbstract(); assert subtype.isConcrete() || context.isInterface() : subtype.toString() + " : " + context.toString(); assert !subtype.isArray() || subtype.getElementalType().isFinalFlagSet() : subtype.toString() + " : " + context.toString(); } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + context.hashCode(); - result = prime * result + subtype.hashCode(); - return result; - } - - @Override - public boolean equals(Object obj) { - if (obj instanceof ConcreteSubtype other) { - return other.context.equals(context) && other.subtype.equals(subtype); - } - return false; - } - - @Override - public String toString() { - return "ConcreteSubtype[context=" + context.toJavaName() + ", subtype=" + subtype.toJavaName() + "]"; - } } /** * An assumption that a given type has no subtypes. + * + * @param context type the assumption is made about. */ - public static final class LeafType extends Assumption { - - /** - * Type the assumption is made about. - */ - public final ResolvedJavaType context; - - public LeafType(ResolvedJavaType context) { + public record LeafType(ResolvedJavaType context) implements Assumption { + public LeafType { assert !context.isLeaf() : "assumption isn't required for leaf types"; - this.context = context; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + context.hashCode(); - return result; - } - - @Override - public boolean equals(Object obj) { - if (obj instanceof LeafType other) { - return other.context.equals(context); - } - return false; - } - - @Override - public String toString() { - return "LeafSubtype[context=" + context.toJavaName() + "]"; } } /** * An assumption that a given virtual method has a given unique implementation. + * + * @param method a virtual (or interface) method whose unique implementation for the receiver type in {@link #context} is {@link #impl}. + * @param context receiver type + * @param impl the unique implementation of {@link #method} for {@link #context}. */ - public static final class ConcreteMethod extends Assumption { - - /** - * A virtual (or interface) method whose unique implementation for the receiver type in - * {@link #context} is {@link #impl}. - */ - public final ResolvedJavaMethod method; - - /** - * A receiver type. - */ - public final ResolvedJavaType context; - - /** - * The unique implementation of {@link #method} for {@link #context}. - */ - public final ResolvedJavaMethod impl; - - public ConcreteMethod(ResolvedJavaMethod method, ResolvedJavaType context, ResolvedJavaMethod impl) { - this.method = method; - this.context = context; - this.impl = impl; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + method.hashCode(); - result = prime * result + context.hashCode(); - result = prime * result + impl.hashCode(); - return result; - } - - @Override - public boolean equals(Object obj) { - if (obj instanceof ConcreteMethod other) { - return other.method.equals(method) && other.context.equals(context) && other.impl.equals(impl); - } - return false; - } - - @Override - public String toString() { - return "ConcreteMethod[method=" + method.format("%H.%n(%p)%r") + ", context=" + context.toJavaName() + ", impl=" + impl.format("%H.%n(%p)%r") + "]"; - } + public record ConcreteMethod(ResolvedJavaMethod method, + ResolvedJavaType context, + ResolvedJavaMethod impl) implements Assumption { } /** * An assumption that a given call site's method handle did not change. */ - public static final class CallSiteTargetValue extends Assumption { - - public final JavaConstant callSite; - public final JavaConstant methodHandle; - - public CallSiteTargetValue(JavaConstant callSite, JavaConstant methodHandle) { - this.callSite = callSite; - this.methodHandle = methodHandle; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + callSite.hashCode(); - result = prime * result + methodHandle.hashCode(); - return result; - } - - @Override - public boolean equals(Object obj) { - if (obj instanceof CallSiteTargetValue other) { - return callSite.equals(other.callSite) && methodHandle.equals(other.methodHandle); - } - return false; - } - - @Override - public String toString() { - return "CallSiteTargetValue[callSite=" + callSite + ", methodHandle=" + methodHandle + "]"; - } + public record CallSiteTargetValue(JavaConstant callSite, JavaConstant methodHandle) implements Assumption { } private final Set assumptions = new HashSet<>(); @@ -358,9 +206,9 @@ public void recordConcreteSubtype(ResolvedJavaType context, ResolvedJavaType sub * Records that {@code impl} is the only possible concrete target for a virtual call to * {@code method} with a receiver of type {@code context}. * - * @param method a method that is the target of a virtual call + * @param method a method that is the target of a virtual call * @param context the receiver type of a call to {@code method} - * @param impl the concrete method that is the only possible target for the virtual call + * @param impl the concrete method that is the only possible target for the virtual call */ public void recordConcreteMethod(ResolvedJavaMethod method, ResolvedJavaType context, ResolvedJavaMethod impl) { record(new ConcreteMethod(method, context, impl)); diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/DefaultProfilingInfo.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/DefaultProfilingInfo.java index 4fa945a896945..32ebeeefe11d9 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/DefaultProfilingInfo.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/DefaultProfilingInfo.java @@ -26,7 +26,7 @@ * An implementation of {@link ProfilingInfo} that can used in the absence of real profile * information. */ -public final class DefaultProfilingInfo implements ProfilingInfo { +public record DefaultProfilingInfo(TriState exceptionSeen) implements ProfilingInfo { private static final ProfilingInfo[] NO_PROFILING_INFO = { new DefaultProfilingInfo(TriState.TRUE), @@ -34,12 +34,6 @@ public final class DefaultProfilingInfo implements ProfilingInfo { new DefaultProfilingInfo(TriState.UNKNOWN) }; - private final TriState exceptionSeen; - - DefaultProfilingInfo(TriState exceptionSeen) { - this.exceptionSeen = exceptionSeen; - } - @Override public int getCodeSize() { return 0; @@ -94,11 +88,6 @@ public boolean isMature() { return false; } - @Override - public String toString() { - return "DefaultProfilingInfo<" + this.toString(null, "; ") + ">"; - } - @Override public void setMature() { // Do nothing diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/EnumData.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/EnumData.java index 896d8b257d37b..aa284317199bd 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/EnumData.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/EnumData.java @@ -24,54 +24,10 @@ /** * Represents an enum constant within {@link AnnotationData}. + * + * @param type the {@linkplain Enum enum type} + * @param name the {@linkplain Enum#name() name} of the enum */ -public final class EnumData { - private final JavaType type; - private final String name; - - /** - * Creates an enum constant. - * - * @param type the {@linkplain Enum enum type} - * @param name the {@linkplain Enum#name() name} of the enum - */ - public EnumData(JavaType type, String name) { - this.type = type; - this.name = name; - } - - /** - * Gets the {@linkplain Enum enum type}. - */ - public JavaType getEnumType() { - return type; - } - - /** - * Gets the {@linkplain Enum#name() name} of the enum. - */ - public String getName() { - return name; - } - - @Override - public String toString() { - return name; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj instanceof EnumData that) { - return this.type.equals(that.type) && this.name.equals(that.name); - } - return false; - } - - @Override - public int hashCode() { - return this.type.hashCode() ^ this.name.hashCode(); - } +public record EnumData(JavaType type, + String name) { } diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/ErrorData.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/ErrorData.java index 1a2dad3701bef..5a0b11edc2b58 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/ErrorData.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/ErrorData.java @@ -24,39 +24,9 @@ /** * Represents an error constant within {@link AnnotationData}. - * * Similar to {@code sun.reflect.annotation.ExceptionProxy}. + * + * @param description description of the error */ -public final class ErrorData { - private final String description; - - /** - * Creates an error constant. - * - * @param description description of the error - */ - public ErrorData(String description) { - this.description = description; - } - - @Override - public String toString() { - return description; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj instanceof ErrorData that) { - return this.description.equals(that.description); - } - return false; - } - - @Override - public int hashCode() { - return description.hashCode(); - } +public record ErrorData(String description) { } diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/ExceptionHandler.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/ExceptionHandler.java index 9402bd41658d7..2bdc51c088ee2 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/ExceptionHandler.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/ExceptionHandler.java @@ -22,65 +22,20 @@ */ package jdk.vm.ci.meta; -import java.util.Objects; - /** * Represents an exception handler within the bytecodes. + * + * @param startBCI the start index of the protected range + * @param endBCI the end index of the protected range + * @param handlerBCI the index of the handler + * @param catchTypeCPI the index of the throwable class in the constant pool + * @param catchType the type caught by this exception handler */ -public final class ExceptionHandler { - - private final int startBCI; - private final int endBCI; - private final int handlerBCI; - private final int catchTypeCPI; - private final JavaType catchType; - - /** - * Creates a new exception handler with the specified ranges. - * - * @param startBCI the start index of the protected range - * @param endBCI the end index of the protected range - * @param catchBCI the index of the handler - * @param catchTypeCPI the index of the throwable class in the constant pool - * @param catchType the type caught by this exception handler - */ - public ExceptionHandler(int startBCI, int endBCI, int catchBCI, int catchTypeCPI, JavaType catchType) { - this.startBCI = startBCI; - this.endBCI = endBCI; - this.handlerBCI = catchBCI; - this.catchTypeCPI = catchTypeCPI; - this.catchType = catchType; - } - - /** - * Returns the start bytecode index of the protected range of this handler. - */ - public int getStartBCI() { - return startBCI; - } - - /** - * Returns the end bytecode index of the protected range of this handler. - */ - public int getEndBCI() { - return endBCI; - } - - /** - * Returns the bytecode index of the handler block of this handler. - */ - public int getHandlerBCI() { - return handlerBCI; - } - - /** - * Returns the index into the constant pool representing the type of exception caught by this - * handler. - */ - public int catchTypeCPI() { - return catchTypeCPI; - } - +public record ExceptionHandler(int startBCI, + int endBCI, + int handlerBCI, + int catchTypeCPI, + JavaType catchType) { /** * Checks whether this handler catches all exceptions. * @@ -89,32 +44,4 @@ public int catchTypeCPI() { public boolean isCatchAll() { return catchTypeCPI == 0; } - - /** - * Returns the type of exception caught by this exception handler. - */ - public JavaType getCatchType() { - return catchType; - } - - @Override - public boolean equals(Object obj) { - if (!(obj instanceof ExceptionHandler that)) { - return false; - } - if (this.startBCI != that.startBCI || this.endBCI != that.endBCI || this.handlerBCI != that.handlerBCI || this.catchTypeCPI != that.catchTypeCPI) { - return false; - } - return Objects.equals(this.catchType, that.catchType); - } - - @Override - public String toString() { - return "ExceptionHandler"; - } - - @Override - public int hashCode() { - return catchTypeCPI ^ endBCI ^ handlerBCI; - } } diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/Local.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/Local.java index d2cec3282498d..53121d97335de 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/Local.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/Local.java @@ -24,67 +24,15 @@ /** * Describes the type and bytecode index range in which a local variable is live. + * + * @param startBci the first BCI at which this local has a value (inclusive). + * @param endBci the last BCI at which this local has a value (inclusive). + * If the value returned is less than {@link #startBci}, + * this object denotes a local variable that is never live. */ -public class Local { - - private final String name; - private final int startBci; - private final int endBci; - private final int slot; - private final JavaType type; - - public Local(String name, JavaType type, int startBci, int endBci, int slot) { - this.name = name; - this.startBci = startBci; - this.endBci = endBci; - this.slot = slot; - this.type = type; - } - - /** - * Returns the first BCI at which this local has a value (inclusive). - */ - public int getStartBCI() { - return startBci; - } - - - /** - * Returns the last BCI at which this local has a value (inclusive). - * If the value returned is less than {@link #getStartBCI}, this object denotes a local - * variable that is never live. - */ - public int getEndBCI() { - return endBci; - } - - public String getName() { - return name; - } - - public JavaType getType() { - return type; - } - - public int getSlot() { - return slot; - } - - @Override - public boolean equals(Object obj) { - if (!(obj instanceof Local that)) { - return false; - } - return this.name.equals(that.name) && this.startBci == that.startBci && this.endBci == that.endBci && this.slot == that.slot && this.type.equals(that.type); - } - - @Override - public int hashCode() { - return super.hashCode(); - } - - @Override - public String toString() { - return "LocalImpl"; - } +public record Local(String name, + JavaType type, + int startBci, + int endBci, + int slot) { } diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/LocalVariableTable.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/LocalVariableTable.java index eacc463660db9..0347921997bf0 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/LocalVariableTable.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/LocalVariableTable.java @@ -30,7 +30,7 @@ * * @jvms 4.7.13 */ -public class LocalVariableTable { +public final class LocalVariableTable { private final List locals; @@ -54,7 +54,7 @@ public LocalVariableTable(Local[] locals) { public Local getLocal(int slot, int bci) { Local result = null; for (Local local : locals) { - if (local.getSlot() == slot && local.getStartBCI() <= bci && local.getEndBCI() >= bci) { + if (local.slot() == slot && local.startBci() <= bci && local.endBci() >= bci) { if (result == null) { result = local; } else { @@ -78,10 +78,10 @@ public List getLocals() { public List getLocalsAt(int bci) { List result = new ArrayList<>(); for (Local l : locals) { - if (l.getStartBCI() <= bci && bci <= l.getEndBCI()) { + if (l.startBci() <= bci && bci <= l.endBci()) { result.add(l); } } - return MetaUtil.listFromTrustedArray(result.toArray()); + return List.copyOf(result); } } diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/MetaUtil.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/MetaUtil.java index efbb44b9de12b..0cc3b5fc5394f 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/MetaUtil.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/MetaUtil.java @@ -287,6 +287,9 @@ public static String identityHashCodeString(Object obj) { * Creates an immutable list from a trusted array that has no references retained by the caller. */ static List listFromTrustedArray(Object[] array) { + if (array == null) { + return List.of(); + } return SharedSecrets.getJavaUtilCollectionAccess().listFromTrustedArray(array); } } diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/ResolvedJavaMethod.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/ResolvedJavaMethod.java index 318961c224a5d..a09186b0bcc75 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/ResolvedJavaMethod.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/ResolvedJavaMethod.java @@ -40,12 +40,12 @@ public interface ResolvedJavaMethod extends JavaMethod, InvokeTarget, ModifiersP * Returns the method's bytecode. The returned bytecode does not contain breakpoints or non-Java * bytecodes. This will return {@code null} if {@link #getCodeSize()} returns {@code <= 0} or if * {@link #hasBytecodes()} returns {@code false}. - * + *

    * The contained constant pool indexes may not be the ones found in the original class file but * they can be used with the JVMCI API (e.g. methods in {@link ConstantPool}). * * @return {@code null} if {@code getLinkedCodeSize() <= 0} otherwise the bytecode of the method - * whose length is guaranteed to be {@code > 0} + * whose length is guaranteed to be {@code > 0} */ byte[] getCode(); @@ -54,9 +54,9 @@ public interface ResolvedJavaMethod extends JavaMethod, InvokeTarget, ModifiersP * {@link #getCode()} will not return {@code null}. * * @return 0 if the method has no bytecode, {@code -1} if the method does have bytecode but its - * {@linkplain #getDeclaringClass() declaring class} is not - * {@linkplain ResolvedJavaType#isLinked() linked} otherwise the size of the bytecode in - * bytes (guaranteed to be {@code > 0}) + * {@linkplain #getDeclaringClass() declaring class} is not + * {@linkplain ResolvedJavaType#isLinked() linked} otherwise the size of the bytecode in + * bytes (guaranteed to be {@code > 0}) */ int getCodeSize(); @@ -105,12 +105,12 @@ default boolean isFinal() { /** * Returns {@code true} if this method is a default method; returns {@code false} otherwise. - * + *

    * A default method is a public non-abstract instance method, that is, a non-static method with * a body, declared in an interface type. * * @return true if and only if this method is a default method as defined by the Java Language - * Specification. + * Specification. */ boolean isDefault(); @@ -163,13 +163,13 @@ default ProfilingInfo getProfilingInfo() { * Returns an object that provides access to the profiling information recorded for this method. * * @param includeNormal if true, - * {@linkplain ProfilingInfo#getDeoptimizationCount(DeoptimizationReason) - * deoptimization counts} will include deoptimization that happened during execution - * of standard non-osr methods. - * @param includeOSR if true, - * {@linkplain ProfilingInfo#getDeoptimizationCount(DeoptimizationReason) - * deoptimization counts} will include deoptimization that happened during execution - * of on-stack-replacement methods. + * {@linkplain ProfilingInfo#getDeoptimizationCount(DeoptimizationReason) + * deoptimization counts} will include deoptimization that happened during execution + * of standard non-osr methods. + * @param includeOSR if true, + * {@linkplain ProfilingInfo#getDeoptimizationCount(DeoptimizationReason) + * deoptimization counts} will include deoptimization that happened during execution + * of on-stack-replacement methods. */ ProfilingInfo getProfilingInfo(boolean includeNormal, boolean includeOSR); @@ -185,32 +185,18 @@ default ProfilingInfo getProfilingInfo() { /** * A {@code Parameter} provides information about method parameters. + * + * @param name the name of the parameter or {@code null} if there is no + * {@literal MethodParameters} class file attribute providing a non-empty name + * for the parameter + * @param modifiers the modifier flags for the parameter + * @param method the method which defines this parameter + * @param index the index of the parameter */ - class Parameter implements AnnotatedElement { - private final String name; - private final ResolvedJavaMethod method; - private final int modifiers; - private final int index; + record Parameter(String name, int modifiers, ResolvedJavaMethod method, int index) implements AnnotatedElement { - /** - * Constructor for {@code Parameter}. - * - * @param name the name of the parameter or {@code null} if there is no - * {@literal MethodParameters} class file attribute providing a non-empty name - * for the parameter - * @param modifiers the modifier flags for the parameter - * @param method the method which defines this parameter - * @param index the index of the parameter - */ - public Parameter(String name, - int modifiers, - ResolvedJavaMethod method, - int index) { + public Parameter { assert name == null || !name.isEmpty(); - this.name = name; - this.modifiers = modifiers; - this.method = method; - this.index = index; } /** @@ -220,7 +206,7 @@ public Parameter(String name, * descriptor of the method which declares the parameter. * * @return the name of the parameter, either provided by the class file or synthesized if - * the class file does not provide a name + * the class file does not provide a name */ public String getName() { if (name == null) { @@ -230,20 +216,6 @@ public String getName() { } } - /** - * Gets the method declaring the parameter. - */ - public ResolvedJavaMethod getDeclaringMethod() { - return method; - } - - /** - * Get the modifier flags for the parameter. - */ - public int getModifiers() { - return modifiers; - } - /** * Gets the kind of the parameter. */ @@ -305,25 +277,12 @@ public String toString() { typename = typename.replaceFirst("\\[\\]$", "..."); } - final StringBuilder sb = new StringBuilder(Modifier.toString(getModifiers())); + final StringBuilder sb = new StringBuilder(Modifier.toString(modifiers())); if (!sb.isEmpty()) { sb.append(' '); } return sb.append(typename).append(' ').append(getName()).toString(); } - - @Override - public boolean equals(Object obj) { - if (obj instanceof Parameter other) { - return (other.method.equals(method) && other.index == index); - } - return false; - } - - @Override - public int hashCode() { - return method.hashCode() ^ index; - } } /** @@ -401,11 +360,11 @@ default List getParameters() { * Gets the annotation of a particular type for a formal parameter of this method. * * @param annotationClass the Class object corresponding to the annotation type - * @param parameterIndex the index of a formal parameter of {@code method} + * @param parameterIndex the index of a formal parameter of {@code method} * @return the annotation of type {@code annotationClass} for the formal parameter present, else - * null + * null * @throws IndexOutOfBoundsException if {@code parameterIndex} does not denote a formal - * parameter + * parameter */ default T getParameterAnnotation(Class annotationClass, int parameterIndex) { if (parameterIndex >= 0) { @@ -429,7 +388,7 @@ default List toParameterTypes() { * * @param annotationClass the Class object corresponding to the annotation type * @return the annotation of type {@code annotationClass} (if any) for each formal parameter - * present + * present */ @SuppressWarnings("unchecked") default List getParameterAnnotations(Class annotationClass) { @@ -446,8 +405,8 @@ default List getParameterAnnotations(Class annotati } /** - * @see #getCodeSize() * @return {@code getCodeSize() > 0} + * @see #getCodeSize() */ default boolean hasBytecodes() { return getCodeSize() > 0; diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/UnresolvedJavaField.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/UnresolvedJavaField.java index 55e52f2732a99..1d1501a25adee 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/UnresolvedJavaField.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/UnresolvedJavaField.java @@ -24,36 +24,18 @@ /** * A implementation of {@link JavaField} for an unresolved field. + * + * @param cause the reason field resolution failed. Can be null. */ -public final class UnresolvedJavaField implements JavaField { - - private final String name; - private final JavaType holder; - private final JavaType type; - - /** - * The reason field resolution failed. Can be null. - */ - private final Throwable cause; - - public UnresolvedJavaField(JavaType holder, String name, JavaType type, Throwable cause) { - this.name = name; - this.type = type; - this.holder = holder; - this.cause = cause; - } +public record UnresolvedJavaField(JavaType holder, + String name, + JavaType type, + Throwable cause) implements JavaField { public UnresolvedJavaField(JavaType holder, String name, JavaType type) { this(holder, name, type, null); } - /** - * Gets the exception, if any, representing the reason field resolution resulted in this object. - */ - public Throwable getCause() { - return cause; - } - @Override public String getName() { return name; @@ -69,11 +51,6 @@ public JavaType getDeclaringClass() { return holder; } - @Override - public int hashCode() { - return super.hashCode(); - } - @Override public boolean equals(Object obj) { if (this == obj) { diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/UnresolvedJavaMethod.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/UnresolvedJavaMethod.java index a5ede69b397b0..28d26e55cb835 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/UnresolvedJavaMethod.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/UnresolvedJavaMethod.java @@ -24,34 +24,16 @@ /** * Implementation of {@link JavaMethod} for unresolved HotSpot methods. + * + * @param cause the reason method resolution failed. Can be null. */ -public final class UnresolvedJavaMethod implements JavaMethod { - - private final String name; - private final Signature signature; - protected JavaType holder; - - /** - * The reason method resolution failed. Can be null. - */ - private final Throwable cause; - - public UnresolvedJavaMethod(String name, Signature signature, JavaType holder, Throwable cause) { - this.name = name; - this.holder = holder; - this.signature = signature; - this.cause = cause; - } +public record UnresolvedJavaMethod(JavaType holder, + String name, + Signature signature, + Throwable cause) implements JavaMethod { - public UnresolvedJavaMethod(String name, Signature signature, JavaType holder) { - this(name, signature, holder, null); - } - - /** - * Gets the exception, if any, representing the reason method resolution resulted in this object. - */ - public Throwable getCause() { - return cause; + public UnresolvedJavaMethod(JavaType holder, String name, Signature signature) { + this(holder, name, signature, null); } @Override @@ -69,13 +51,10 @@ public JavaType getDeclaringClass() { return holder; } - @Override - public int hashCode() { - return super.hashCode(); - } - @Override public boolean equals(Object obj) { + // TODO delete? note that it does not take cause into account + // same applies to UnresolvedJavaField/Type if (this == obj) { return true; } diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/UnresolvedJavaType.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/UnresolvedJavaType.java index a540b2a711b06..57cbcf8df489a 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/UnresolvedJavaType.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/UnresolvedJavaType.java @@ -24,45 +24,22 @@ /** * Implementation of {@link JavaType} for unresolved HotSpot classes. + * + * @param cause the reason type resolution failed. Can be null. */ -public final class UnresolvedJavaType implements JavaType { - private final String name; - - /** - * The reason type resolution failed. Can be null. - */ - private final Throwable cause; - - @Override - public String getName() { - return name; - } +public record UnresolvedJavaType(String name, Throwable cause) implements JavaType { - private UnresolvedJavaType(String name, Throwable cause) { - this.name = name; - this.cause = cause; + public UnresolvedJavaType { assert name.length() == 1 && JavaKind.fromPrimitiveOrVoidTypeChar(name.charAt(0)) != null || name.charAt(0) == '[' || name.charAt(name.length() - 1) == ';' : name; } - /** - * Creates an unresolved type for a valid {@link JavaType#getName() type name}. - */ public static UnresolvedJavaType create(String name) { return new UnresolvedJavaType(name, null); } - /** - * Creates an unresolved type for a valid {@link JavaType#getName() type name}. - */ - public static UnresolvedJavaType create(String name, Throwable cause) { - return new UnresolvedJavaType(name, cause); - } - - /** - * Gets the exception, if any, representing the reason type resolution resulted in this object. - */ - public Throwable getCause() { - return cause; + @Override + public String getName() { + return name; } @Override diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/runtime/JVMCIBackend.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/runtime/JVMCIBackend.java index 28b296e095b13..a37f66398387a 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/runtime/JVMCIBackend.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/runtime/JVMCIBackend.java @@ -33,37 +33,11 @@ * installing code for a single compute unit within a JVM. In a JVM with support for heterogeneous * computing, more than one backend may be exposed. */ -public class JVMCIBackend { - - private final MetaAccessProvider metaAccess; - private final CodeCacheProvider codeCache; - private final ConstantReflectionProvider constantReflection; - private final StackIntrospection stackIntrospection; - - public JVMCIBackend(MetaAccessProvider metaAccess, CodeCacheProvider codeCache, ConstantReflectionProvider constantReflection, StackIntrospection stackIntrospection) { - this.metaAccess = metaAccess; - this.codeCache = codeCache; - this.constantReflection = constantReflection; - this.stackIntrospection = stackIntrospection; - } - - public MetaAccessProvider getMetaAccess() { - return metaAccess; - } - - public CodeCacheProvider getCodeCache() { - return codeCache; - } - - public ConstantReflectionProvider getConstantReflection() { - return constantReflection; - } - - public TargetDescription getTarget() { +public record JVMCIBackend(MetaAccessProvider metaAccess, + CodeCacheProvider codeCache, + ConstantReflectionProvider constantReflection, + StackIntrospection stackIntrospection) { + public TargetDescription target() { return codeCache.getTarget(); } - - public StackIntrospection getStackIntrospection() { - return stackIntrospection; - } } diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/services/Services.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/services/Services.java index 5b37e7f4eb5ee..0f078f0c45e51 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/services/Services.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/services/Services.java @@ -210,7 +210,7 @@ private static Map initProperties() { String key = toJavaString(unsafe, unsafe.getLong(prop + keyOffset)); long valueAddress = unsafe.getLong(prop + valueOffset); if (valueAddress != 0) { - props.put(key, new SystemProperties.Value(unsafe, valueAddress)); + props.put(key, new SystemProperties.Value(valueAddress)); i++; } } diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/services/SystemProperties.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/services/SystemProperties.java index abf1f8b593d8b..0fca1f62e59a3 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/services/SystemProperties.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/services/SystemProperties.java @@ -157,7 +157,7 @@ static class Value { /** * Creates a value whose string representation will be lazily constructed from {@code cstring}. */ - Value(Unsafe unsafe, long cstring) { + Value(long cstring) { this.cstring = cstring; }