1 /*
2 * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 //
26 // Help test archived box cache consistency.
27 //
28 // args[0]: the expected maximum value expected to be archived
29 //
30 public class CheckIntegerCacheApp {
31 public static void main(String[] args) throws Exception {
32 if (args.length != 1) {
33 throw new RuntimeException(
34 "FAILED. Incorrect argument length: " + args.length);
35 }
36
37 // Base JLS compliance check
38 for (int i = -128; i <= 127; i++) {
39 if (Integer.valueOf(i) != Integer.valueOf(i)) {
40 throw new RuntimeException(
41 "FAILED. All values in range [-128, 127] should be interned in cache: " + i);
42 }
43 if (Byte.valueOf((byte)i) != Byte.valueOf((byte)i)) {
44 throw new RuntimeException(
45 "FAILED. All Byte values in range [-128, 127] should be interned in cache: " + (byte)i);
46 }
47 if (Short.valueOf((short)i) != Short.valueOf((short)i)) {
48 throw new RuntimeException(
49 "FAILED. All Short values in range [-128, 127] should be interned in cache: " + (byte)i);
50 }
51 if (Long.valueOf(i) != Long.valueOf(i)) {
52 throw new RuntimeException(
53 "FAILED. All Long values in range [-128, 127] should be interned in cache: " + i);
54 }
55
56 // Character cache only values 0 through 127
57 if (i >= 0) {
58 if (Character.valueOf((char)i) != Character.valueOf((char)i)) {
59 throw new RuntimeException(
60 "FAILED. All Character values in range [0, 127] should be interned in cache: " + i);
61 }
62 }
63 }
64
65 // Check that archived integer cache agrees with runtime integer cache.
66 for (int i = -128; i <= 127; i++) {
67 if (ArchivedIntegerHolder.archivedObjects[i + 128] != Integer.valueOf(i)) {
68 throw new RuntimeException(
69 "FAILED. Archived and runtime caches disagree for " + i);
70 }
71 }
72
73 int high = Integer.parseInt(args[0]);
74 if (Integer.valueOf(high) != Integer.valueOf(high)) {
75 throw new RuntimeException(
76 "FAILED. Value expected to be retrieved from cache: " + high);
77 }
78
79 if (Integer.valueOf(high + 1) == Integer.valueOf(high + 1)) {
80 throw new RuntimeException(
81 "FAILED. Value not expected to be retrieved from cache: " + high);
82 }
83 }
84 }