forked from ibmruntimes/openj9-openjdk-jdk10
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
8193222: EnsureLocalCapacity() should maintain capacity requests thro…
…ugh multiple calls Reviewed-by: coleenp, dcubed
- Loading branch information
dholmes
committed
Dec 13, 2017
1 parent
c600704
commit c206239
Showing
3 changed files
with
135 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
test/hotspot/jtreg/runtime/jni/checked/TestCheckedEnsureLocalCapacity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* Copyright (c) 2017, 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. | ||
*/ | ||
|
||
/* @test | ||
* @bug 8193222 | ||
* @summary Check EnsureLocalCapacity doesn't shrink unexpectedly | ||
* @library /test/lib | ||
* @run main/othervm/native TestCheckedEnsureLocalCapacity launch | ||
*/ | ||
import jdk.test.lib.process.ProcessTools; | ||
import jdk.test.lib.process.OutputAnalyzer; | ||
|
||
public class TestCheckedEnsureLocalCapacity { | ||
|
||
static { | ||
System.loadLibrary("TestCheckedEnsureLocalCapacity"); | ||
} | ||
|
||
// Calls EnsureLocalCapacity(capacity) and then creates "copies" number | ||
// of LocalRefs to "o". | ||
// If capacity > copies no warning should ensue (with the bug fixed). | ||
// If copies > capacity + warning-threshold then we still get a warning. | ||
private static native void ensureCapacity(Object o, int capacity, int copies); | ||
|
||
private static int[][] testArgs = { | ||
{ 60, 45 }, // good: capacity > copies | ||
{ 1, 45 } // bad: copies >> capacity | ||
}; | ||
|
||
private static final String EXCEED_WARNING = | ||
"^WARNING: JNI local refs: \\d++, exceeds capacity:"; | ||
|
||
private static final String WARNING = "^WARNING: "; | ||
|
||
public static void main(String[] args) throws Throwable { | ||
if (args.length == 2) { | ||
ensureCapacity(new Object(), | ||
Integer.parseInt(args[0]), | ||
Integer.parseInt(args[1])); | ||
return; | ||
} | ||
|
||
// No warning | ||
ProcessTools.executeTestJvm("-Xcheck:jni", | ||
"TestCheckedEnsureLocalCapacity", | ||
Integer.toString(testArgs[0][0]), | ||
Integer.toString(testArgs[0][1])). | ||
shouldHaveExitValue(0). | ||
// check no capacity warning | ||
stdoutShouldNotMatch(EXCEED_WARNING). | ||
// check no other warning | ||
stdoutShouldNotMatch(WARNING). | ||
reportDiagnosticSummary(); | ||
|
||
// Warning | ||
ProcessTools.executeTestJvm("-Xcheck:jni", | ||
"TestCheckedEnsureLocalCapacity", | ||
Integer.toString(testArgs[1][0]), | ||
Integer.toString(testArgs[1][1])). | ||
shouldHaveExitValue(0). | ||
// check for capacity warning | ||
stdoutShouldMatch(EXCEED_WARNING). | ||
reportDiagnosticSummary(); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
test/hotspot/jtreg/runtime/jni/checked/libTestCheckedEnsureLocalCapacity.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright (c) 2017, 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. | ||
*/ | ||
|
||
#include <jni.h> | ||
#include <stdio.h> | ||
|
||
void reduceLocalCapacity(JNIEnv* env) { | ||
puts("reduceLocalCapacity: setting to 1"); | ||
(*env)->EnsureLocalCapacity(env,1); | ||
} | ||
|
||
JNIEXPORT void JNICALL | ||
Java_TestCheckedEnsureLocalCapacity_ensureCapacity(JNIEnv *env, | ||
jobject unused, | ||
jobject target, | ||
jint capacity, | ||
jint copies) { | ||
int i; | ||
printf("ensureCapacity: setting to %d\n", capacity); | ||
(*env)->EnsureLocalCapacity(env, capacity); // set high | ||
reduceLocalCapacity(env); // sets low | ||
|
||
printf("ensureCapacity: creating %d LocalRefs\n", copies); | ||
for (i = 0; i < copies; i++) { | ||
target = (*env)->NewLocalRef(env, target); | ||
} | ||
|
||
puts("ensureCapacity: done"); | ||
} |