Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/stress/jni/libjnistress002.cpp
41155 views
/*1* Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223#include <jni.h>24#include <stdio.h>25#include "jnihelper.h"2627extern "C" {2829jobject NewObjectWrapper(JNIEnv *env, jclass clazz, jmethodID methodID, ...) {30va_list ap;31jobject tmp;3233va_start(ap,methodID);34tmp=env->NewObjectV(clazz, methodID, ap);35va_end(ap);36return(tmp);37}3839JNIEXPORT jobjectArray JNICALL40Java_nsk_stress_jni_JNIter002_jniobjects (JNIEnv *env, jobject jobj, jstring jstr, jint intgr,41jlong lng, jcharArray jChArr, jfloat flt, jdouble dbl) {4243static int classCount = 0;44jobjectArray obj;45jobject element;46jclass clazz, clazzUp;47jmethodID methodID;48const char *classname="nsk/stress/jni/objectsJNI";49const char *name="<init>";50const char *sig="(Ljava/lang/String;IJ[CFD)V";51const char *upperClassName="nsk/stress/jni/jnistress002";52const char *fieldName="jniStringAllocSize";53const char *fieldSig="I";54const char *setpass="halt";55const char *setpassSig="()V";56jvalue paramArr [6];5758env->MonitorEnter(jobj); CE59++classCount;60env->MonitorExit(jobj); CE61paramArr[0].l=jstr;62paramArr[1].i=intgr;63paramArr[2].j=lng;64paramArr[3].l=jChArr;65paramArr[4].f=flt;66paramArr[5].d=dbl;6768clazz=env->FindClass(classname); CE69obj=env->NewObjectArray((jsize)3,clazz,70env->AllocObject(clazz)); CE71if (obj == NULL) {72fprintf(stderr,"Can not construct the object Array for %s\n", classname);73return(NULL);74}7576methodID=env->GetMethodID(clazz,name,sig); CE77if (methodID == NULL) {78fprintf(stderr,"Can not get the ID of <init> for %s\n", classname);79return(NULL);80}8182element=env->NewObject(clazz,methodID,83jstr, intgr, lng, jChArr, flt, dbl); CE84env->SetObjectArrayElement(obj,0,element); CE85element=env->NewObjectA(clazz,methodID,paramArr); CE86env->SetObjectArrayElement(obj,1,element); CE87element= NewObjectWrapper(env, clazz, methodID,88jstr, intgr, lng, jChArr, flt, dbl); CE89env->SetObjectArrayElement(obj,2,element); CE9091clazzUp=env->FindClass(upperClassName); CE92if (classCount == env->GetStaticIntField(clazzUp,93env->GetStaticFieldID(clazzUp,fieldName,fieldSig))) {94classname="nsk/stress/jni/JNIter002";95clazz=env->FindClass(classname); CE96methodID=env->GetStaticMethodID(clazz, setpass, setpassSig); CE97env->CallStaticVoidMethod(clazz, methodID); CE98}99100CE101102return obj;103}104105}106107108