Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/stress/jni/libjnistress006.cpp
41155 views
1
/*
2
* Copyright (c) 2007, 2018, 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
#include <jni.h>
25
#include <stdio.h>
26
#include <stdlib.h>
27
#include "jnihelper.h"
28
29
extern "C" {
30
31
JNIEXPORT jboolean JNICALL
32
Java_nsk_stress_jni_JNIter006_refs (JNIEnv *env, jobject jobj, jobject tobj, jint LIMIT) {
33
34
static jobject *globRefsArray = 0;
35
static int upper = 0;
36
37
jclass clazz;
38
jmethodID jmethod;
39
jboolean res=JNI_FALSE;
40
const char *classname = "nsk/stress/jni/JNIter006";
41
const char *getmethodname="get_i";
42
const char *setmethodname="set_i";
43
const char *getsig="()I";
44
const char *setsig="(I)V";
45
const char *setdone = "halt";
46
const char *setdonesig = "()V";
47
int i = 0;
48
49
if (upper >= LIMIT) return JNI_TRUE;
50
51
if (upper == 0) {
52
globRefsArray=(jobject*)(malloc(LIMIT*sizeof(jobject)));
53
}
54
55
globRefsArray[upper]=env->NewGlobalRef(tobj); CE
56
if (env->IsSameObject(tobj, globRefsArray[upper])) {
57
env->DeleteLocalRef(tobj); CE
58
clazz=env->GetObjectClass(globRefsArray[upper]); CE
59
}
60
else {
61
fprintf(stderr,"Objects are different\n");
62
env->MonitorExit(jobj); CE
63
return res;
64
}
65
jmethod=env->GetStaticMethodID(clazz, setmethodname, setsig); CE
66
env->CallStaticVoidMethod(clazz, jmethod, (jint)upper); CE
67
env->MonitorEnter(jobj); CE
68
++upper;
69
res=JNI_TRUE;
70
env->MonitorExit(jobj); CE
71
/* If upper == LIMIT than flush ref's array and set */
72
/* 'done' flag in JNIter006 class to JNI_TRUE */
73
if (upper == LIMIT) {
74
fprintf(stderr,"\n\tTotal memory allocated: %zd bytes\n",
75
LIMIT*sizeof(jobject));
76
clazz=env->FindClass(classname); CE
77
jmethod=env->GetMethodID(clazz, setdone, setdonesig); CE
78
env->CallVoidMethod(jobj, jmethod); CE
79
80
for (i=0;i<LIMIT;i++) {
81
env->DeleteGlobalRef(globRefsArray[i]); CE
82
}
83
free(globRefsArray);
84
}
85
return res;
86
}
87
88
}
89
90