8167408: Invalid critical JNI function lookup
Made correction to arg_size calculation in NativeLookup::lookup_critical_entry Reviewed-by: dholmes, dlong, mdoerr, vlivanov
This commit is contained in:
parent
168565de20
commit
ef98509665
@ -63,6 +63,7 @@ BUILD_HOTSPOT_JTREG_NATIVE_SRC += \
|
||||
$(TOPDIR)/test/hotspot/jtreg/runtime/RedefineTests \
|
||||
$(TOPDIR)/test/hotspot/jtreg/compiler/floatingpoint/ \
|
||||
$(TOPDIR)/test/hotspot/jtreg/compiler/calls \
|
||||
$(TOPDIR)/test/hotspot/jtreg/compiler/runtime/criticalnatives/lookup \
|
||||
$(TOPDIR)/test/hotspot/jtreg/serviceability/jvmti/GetOwnedMonitorInfo \
|
||||
$(TOPDIR)/test/hotspot/jtreg/serviceability/jvmti/GetNamedModule \
|
||||
$(TOPDIR)/test/hotspot/jtreg/serviceability/jvmti/IsModifiableModule \
|
||||
|
@ -293,10 +293,12 @@ address NativeLookup::lookup_critical_entry(const methodHandle& method) {
|
||||
char* critical_name = critical_jni_name(method);
|
||||
|
||||
// Compute argument size
|
||||
int args_size = 1 // JNIEnv
|
||||
+ (method->is_static() ? 1 : 0) // class for static methods
|
||||
+ method->size_of_parameters(); // actual parameters
|
||||
|
||||
int args_size = method->size_of_parameters();
|
||||
for (SignatureStream ss(signature); !ss.at_return_type(); ss.next()) {
|
||||
if (ss.is_array()) {
|
||||
args_size += T_INT_size; // array length parameter
|
||||
}
|
||||
}
|
||||
|
||||
// 1) Try JNI short style
|
||||
entry = lookup_critical_style(method, critical_name, "", args_size, true);
|
||||
|
@ -0,0 +1,59 @@
|
||||
/*
|
||||
* 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 8167408
|
||||
* @run main/othervm/native -Xcomp compiler.runtime.criticalnatives.lookup.LookUp
|
||||
*/
|
||||
package compiler.runtime.criticalnatives.lookup;
|
||||
public class LookUp {
|
||||
static {
|
||||
System.loadLibrary("CNLookUp");
|
||||
}
|
||||
static native void m1(byte a1, long a2, char a3, int a4, float a5, double a6, byte[] result);
|
||||
static native void m2(int a1, int[] a2, long a3, long[] a4, float a5,float[] a6, double a7, double[] a8, byte result[]);
|
||||
public static void main(String args[]) throws Exception {
|
||||
test();
|
||||
}
|
||||
private static void test() throws Exception {
|
||||
int[] l1 = { 1111, 2222, 3333 };
|
||||
long[] l2 = { 4444L, 5555L, 6666L };
|
||||
float[] l3 = { 7777.0F, 8888.0F, 9999.0F };
|
||||
double[] l4 = { 4545.0D, 5656.0D, 6767.0D };
|
||||
byte[] result = { -1 };
|
||||
m1((byte)0xA, 4444444455555555L, 'A', 12345678, 343434.0F, 6666666677777777.0D, result);
|
||||
check(result[0]);
|
||||
result[0] = -1;
|
||||
m2(12345678, l1, 4444444455555555L, l2, 343434.0F, l3, 6666666677777777.0D, l4, result);
|
||||
check(result[0]);
|
||||
}
|
||||
private static void check(byte result) throws Exception {
|
||||
if (result != 2) {
|
||||
if (result == 1) {
|
||||
throw new Exception("critical native arguments mismatch");
|
||||
}
|
||||
throw new Exception("critical native lookup failed");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
#include "jni.h"
|
||||
JNIEXPORT void JNICALL JavaCritical_compiler_runtime_criticalnatives_lookup_LookUp_m1
|
||||
(jbyte a1, jlong a2, jchar a3, jint a4, jfloat a5, jdouble a6, jint result_length, jbyte* result) {
|
||||
jint l1 = (jint) a5;
|
||||
jlong l2 = (jlong) a6;
|
||||
|
||||
if (a1 != 0xA || a2 != 4444444455555555LL || a3 != 0x41 || a4 != 12345678 || l1 != 343434 || l2 != 6666666677777777LL ||
|
||||
result_length != 1 || result[0] != -1) {
|
||||
result[0] = 1;
|
||||
} else {
|
||||
result[0] = 2;
|
||||
}
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL JavaCritical_compiler_runtime_criticalnatives_lookup_LookUp_m2
|
||||
(jint a1, jint a2_length, jint* a2, jlong a3, jint a4_length, jlong* a4, jfloat a5, jint a6_length, jfloat* a6, jdouble a7,
|
||||
jint a8_length, jdouble* a8, jint result_length, jbyte* result) {
|
||||
jint l1 = (jint) a5;
|
||||
jlong l2 = (jlong) a7;
|
||||
|
||||
if (a1 != 12345678 || a2_length != 3 || a2[0] != 1111 || a3 != 4444444455555555LL || a4_length != 3 || a4[0] != 4444 ||
|
||||
l1 != 343434 || a6_length != 3 || 7777 != (jint)a6[0] || l2 != 6666666677777777LL || a8_length != 3 || 4545 != (jlong)a8[0] ||
|
||||
result_length != 1 || result[0] != -1) {
|
||||
result[0] = 1;
|
||||
} else {
|
||||
result[0] = 2;
|
||||
}
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_compiler_runtime_criticalnatives_lookup_LookUp_m1
|
||||
(JNIEnv * env, jclass jclazz, jbyte a3, jlong a4, jchar a5, jint a6, jfloat a7, jdouble a8, jbyteArray result) {}
|
||||
|
||||
JNIEXPORT void JNICALL Java_compiler_runtime_criticalnatives_lookup_LookUp_m2
|
||||
(JNIEnv * env, jclass jclazz, jint a3, jintArray a4, jlong a5, jlongArray a6, jfloat a7, jfloatArray a8, jdouble a9, jdoubleArray a10, jbyteArray result) {}
|
||||
|
Loading…
x
Reference in New Issue
Block a user