-
Bug
-
Resolution: Fixed
-
P3
-
15
The Integer array allocation in the following test can be scalar replaced because the array is not escaping:
public class Test {
public static Integer test() {
Integer[] src = new Integer[10];
src[0] = new Integer(42);
Integer[] dst = (Integer[])src.clone();
return dst[0];
}
public static void main(String[] args) {
for (int i = 0; i < 100_000; ++i) {
test();
}
}
}
BeforeJDK-8238759:
Scalar 351 CheckCastPP === 348 346 [[ 353 353 ]] #narrowoop: java/lang/Integer:exact *[int:10]:NotNull:exact *,iid=334 !jvms: Test::test @ bci:19
++++ Eliminated: 334 AllocateArray
Scalar 57 CheckCastPP === 54 52 [[ 161 161 63 63 ]] #narrowoop: java/lang/Integer:exact *[int:10]:NotNull:exact *,iid=40 !jvms: Test::test @ bci:2
++++ Eliminated: 40 AllocateArray
AfterJDK-8238759:
NotScalar (Object is passed as argument) 351 CheckCastPP === 348 346 [[ 358 370 370 ]] #narrowoop: java/lang/Integer:exact *[int:10]:NotNull:exact *,iid=334 !jvms: Test::test @ bci:19
>>>> 358 ArrayCopy === 348 1 333 8 1 ( 57 61 351 61 357 _ _ _ _ ) [[ 359 361 ]] void ( java/lang/Object *, int, java/lang/Object *, int, int, int, int, BotPTR *+bot, BotPTR *+bot ) (oop array clone, tightly coupled allocation) !jvms: Test::test @ bci:19
NotScalar (Object is passed as argument) 57 CheckCastPP === 54 52 [[ 334 161 63 63 161 358 ]] #narrowoop: java/lang/Integer:exact *[int:10]:NotNull:exact *,iid=40 !jvms: Test::test @ bci:2
>>>> 358 ArrayCopy === 348 1 333 8 1 ( 57 61 351 61 357 _ _ _ _ ) [[ 359 361 ]] void ( java/lang/Object *, int, java/lang/Object *, int, int, int, int, BotPTR *+bot, BotPTR *+bot ) (oop array clone, tightly coupled allocation) !jvms: Test::test @ bci:19
NotScalar (Object is passed as argument) 351 CheckCastPP === 348 346 [[ 358 370 370 ]] #narrowoop: java/lang/Integer:exact *[int:10]:NotNull:exact *,iid=334 !jvms: Test::test @ bci:19
>>>> 358 ArrayCopy === 348 1 333 8 1 ( 57 61 351 61 357 _ _ _ _ ) [[ 359 361 ]] void ( java/lang/Object *, int, java/lang/Object *, int, int, int, int, BotPTR *+bot, BotPTR *+bot ) (oop array clone, tightly coupled allocation) !jvms: Test::test @ bci:19
NotScalar (Object is passed as argument) 57 CheckCastPP === 54 52 [[ 334 161 63 63 161 358 ]] #narrowoop: java/lang/Integer:exact *[int:10]:NotNull:exact *,iid=40 !jvms: Test::test @ bci:2
>>>> 358 ArrayCopy === 348 1 333 8 1 ( 57 61 351 61 357 _ _ _ _ ) [[ 359 361 ]] void ( java/lang/Object *, int, java/lang/Object *, int, int, int, int, BotPTR *+bot, BotPTR *+bot ) (oop array clone, tightly coupled allocation) !jvms: Test::test @ bci:19
public class Test {
public static Integer test() {
Integer[] src = new Integer[10];
src[0] = new Integer(42);
Integer[] dst = (Integer[])src.clone();
return dst[0];
}
public static void main(String[] args) {
for (int i = 0; i < 100_000; ++i) {
test();
}
}
}
Before
Scalar 351 CheckCastPP === 348 346 [[ 353 353 ]] #narrowoop: java/lang/Integer:exact *[int:10]:NotNull:exact *,iid=334 !jvms: Test::test @ bci:19
++++ Eliminated: 334 AllocateArray
Scalar 57 CheckCastPP === 54 52 [[ 161 161 63 63 ]] #narrowoop: java/lang/Integer:exact *[int:10]:NotNull:exact *,iid=40 !jvms: Test::test @ bci:2
++++ Eliminated: 40 AllocateArray
After
NotScalar (Object is passed as argument) 351 CheckCastPP === 348 346 [[ 358 370 370 ]] #narrowoop: java/lang/Integer:exact *[int:10]:NotNull:exact *,iid=334 !jvms: Test::test @ bci:19
>>>> 358 ArrayCopy === 348 1 333 8 1 ( 57 61 351 61 357 _ _ _ _ ) [[ 359 361 ]] void ( java/lang/Object *, int, java/lang/Object *, int, int, int, int, BotPTR *+bot, BotPTR *+bot ) (oop array clone, tightly coupled allocation) !jvms: Test::test @ bci:19
NotScalar (Object is passed as argument) 57 CheckCastPP === 54 52 [[ 334 161 63 63 161 358 ]] #narrowoop: java/lang/Integer:exact *[int:10]:NotNull:exact *,iid=40 !jvms: Test::test @ bci:2
>>>> 358 ArrayCopy === 348 1 333 8 1 ( 57 61 351 61 357 _ _ _ _ ) [[ 359 361 ]] void ( java/lang/Object *, int, java/lang/Object *, int, int, int, int, BotPTR *+bot, BotPTR *+bot ) (oop array clone, tightly coupled allocation) !jvms: Test::test @ bci:19
NotScalar (Object is passed as argument) 351 CheckCastPP === 348 346 [[ 358 370 370 ]] #narrowoop: java/lang/Integer:exact *[int:10]:NotNull:exact *,iid=334 !jvms: Test::test @ bci:19
>>>> 358 ArrayCopy === 348 1 333 8 1 ( 57 61 351 61 357 _ _ _ _ ) [[ 359 361 ]] void ( java/lang/Object *, int, java/lang/Object *, int, int, int, int, BotPTR *+bot, BotPTR *+bot ) (oop array clone, tightly coupled allocation) !jvms: Test::test @ bci:19
NotScalar (Object is passed as argument) 57 CheckCastPP === 54 52 [[ 334 161 63 63 161 358 ]] #narrowoop: java/lang/Integer:exact *[int:10]:NotNull:exact *,iid=40 !jvms: Test::test @ bci:2
>>>> 358 ArrayCopy === 348 1 333 8 1 ( 57 61 351 61 357 _ _ _ _ ) [[ 359 361 ]] void ( java/lang/Object *, int, java/lang/Object *, int, int, int, int, BotPTR *+bot, BotPTR *+bot ) (oop array clone, tightly coupled allocation) !jvms: Test::test @ bci:19
- relates to
-
JDK-8238759 Clones should always keep the base pointer
-
- Resolved
-