|
1 /* |
|
2 * Copyright (c) 2017, 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 /* @test |
|
25 * @bug 8193222 |
|
26 * @summary Check EnsureLocalCapacity doesn't shrink unexpectedly |
|
27 * @library /test/lib |
|
28 * @run main/othervm/native TestCheckedEnsureLocalCapacity launch |
|
29 */ |
|
30 import jdk.test.lib.process.ProcessTools; |
|
31 import jdk.test.lib.process.OutputAnalyzer; |
|
32 |
|
33 public class TestCheckedEnsureLocalCapacity { |
|
34 |
|
35 static { |
|
36 System.loadLibrary("TestCheckedEnsureLocalCapacity"); |
|
37 } |
|
38 |
|
39 // Calls EnsureLocalCapacity(capacity) and then creates "copies" number |
|
40 // of LocalRefs to "o". |
|
41 // If capacity > copies no warning should ensue (with the bug fixed). |
|
42 // If copies > capacity + warning-threshold then we still get a warning. |
|
43 private static native void ensureCapacity(Object o, int capacity, int copies); |
|
44 |
|
45 private static int[][] testArgs = { |
|
46 { 60, 45 }, // good: capacity > copies |
|
47 { 1, 45 } // bad: copies >> capacity |
|
48 }; |
|
49 |
|
50 private static final String EXCEED_WARNING = |
|
51 "^WARNING: JNI local refs: \\d++, exceeds capacity:"; |
|
52 |
|
53 private static final String WARNING = "^WARNING: "; |
|
54 |
|
55 public static void main(String[] args) throws Throwable { |
|
56 if (args.length == 2) { |
|
57 ensureCapacity(new Object(), |
|
58 Integer.parseInt(args[0]), |
|
59 Integer.parseInt(args[1])); |
|
60 return; |
|
61 } |
|
62 |
|
63 // No warning |
|
64 ProcessTools.executeTestJvm("-Xcheck:jni", |
|
65 "TestCheckedEnsureLocalCapacity", |
|
66 Integer.toString(testArgs[0][0]), |
|
67 Integer.toString(testArgs[0][1])). |
|
68 shouldHaveExitValue(0). |
|
69 // check no capacity warning |
|
70 stdoutShouldNotMatch(EXCEED_WARNING). |
|
71 // check no other warning |
|
72 stdoutShouldNotMatch(WARNING). |
|
73 reportDiagnosticSummary(); |
|
74 |
|
75 // Warning |
|
76 ProcessTools.executeTestJvm("-Xcheck:jni", |
|
77 "TestCheckedEnsureLocalCapacity", |
|
78 Integer.toString(testArgs[1][0]), |
|
79 Integer.toString(testArgs[1][1])). |
|
80 shouldHaveExitValue(0). |
|
81 // check for capacity warning |
|
82 stdoutShouldMatch(EXCEED_WARNING). |
|
83 reportDiagnosticSummary(); |
|
84 } |
|
85 } |