8200478: For boxing conversion javac uses Long.valueOf which does not guarantee caching according to its javadoc

Reviewed-by: bpb
This commit is contained in:
Joe Darcy 2018-04-25 22:12:06 -07:00
parent 1515d70930
commit 15ef60b350
2 changed files with 5 additions and 7 deletions

View file

@ -1164,10 +1164,8 @@ public final class Long extends Number implements Comparable<Long> {
* significantly better space and time performance by caching * significantly better space and time performance by caching
* frequently requested values. * frequently requested values.
* *
* Note that unlike the {@linkplain Integer#valueOf(int) * This method will always cache values in the range -128 to 127,
* corresponding method} in the {@code Integer} class, this method * inclusive, and may cache other values outside of this range.
* is <em>not</em> required to cache values within a particular
* range.
* *
* @param l a long value. * @param l a long value.
* @return a {@code Long} instance representing {@code l}. * @return a {@code Long} instance representing {@code l}.

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -23,7 +23,7 @@
/* /*
* @test * @test
* @bug 4990346 * @bug 4990346 8200478
* @summary Verify autoboxed values are cached as required. * @summary Verify autoboxed values are cached as required.
* @author Joseph D. Darcy * @author Joseph D. Darcy
*/ */
@ -155,7 +155,7 @@ public class BoxingCaching {
Long L = (long)(i-128); Long L = (long)(i-128);
if (L != results[i]) { if (L != results[i]) {
cached = false; cached = false;
System.err.println("Integer value " + L + System.err.println("Long value " + L +
" is not cached appropriately."); " is not cached appropriately.");
} }
} }