Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/stress/jni/gclocker/libgcl001.cpp
41161 views
1
/*
2
* Copyright (c) 2007, 2020, 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 <stdlib.h>
26
#include "jnihelper.h"
27
28
/*
29
basic routine: provide critical sections and calculations
30
enter array CS
31
enter first string CS
32
leave first string CS
33
enter second string CS
34
leave array CS
35
leave second string CS
36
*/
37
#define BODY(type) \
38
int hash = 0; \
39
jsize i, arraySize, stringSize; \
40
jchar *nativeStr = NULL; \
41
type *nativeArray = NULL; \
42
\
43
arraySize = env->GetArrayLength(array); CE \
44
stringSize = env->GetStringLength(str); CE \
45
\
46
nativeArray = (type *)env->GetPrimitiveArrayCritical(array, NULL); CE \
47
qsort(nativeArray, arraySize, sizeof(type), *type##comp); \
48
\
49
nativeStr = (jchar *)env->GetStringCritical(str, NULL); CE \
50
\
51
for (i = 0; i < stringSize; ++i) \
52
hash += (int)nativeStr[i]; \
53
env->ReleaseStringCritical(str, nativeStr); CE \
54
\
55
nativeStr = (jchar *)env->GetStringCritical(str, NULL); CE \
56
\
57
env->ReleasePrimitiveArrayCritical(array, nativeArray, 0); CE \
58
\
59
for (i = 0; i < stringSize; ++i) \
60
hash += (int)nativeStr[i]; \
61
env->ReleaseStringCritical(str, nativeStr); CE \
62
\
63
return hash;
64
65
// compare most java primitive value types
66
#define COMP(type) \
67
int type##comp(const void *s1, const void *s2) \
68
{ \
69
type st1 = *((type *)s1); \
70
type st2 = *((type *)s2); \
71
if (st1 < st2) \
72
return -1; \
73
else if (st1 > st2) \
74
return 1; \
75
else \
76
return 0; \
77
}
78
79
COMP(jint)
80
COMP(jboolean)
81
COMP(jchar)
82
COMP(jshort)
83
COMP(jbyte)
84
COMP(jdouble)
85
COMP(jfloat)
86
COMP(jlong)
87
88
extern "C" {
89
90
/*
91
* Class: JNIWorker
92
* Method: NativeCall
93
* Signature: ([ZLjava/lang/String;)I
94
*/
95
JNIEXPORT jint JNICALL Java_nsk_stress_jni_gclocker_JNIWorker_NativeCall___3ZLjava_lang_String_2
96
(JNIEnv * env, jobject obj, jbooleanArray array, jstring str)
97
{
98
BODY(jboolean)
99
}
100
101
/*
102
* Class: JNIWorker
103
* Method: NativeCall
104
* Signature: ([BLjava/lang/String;)I
105
*/
106
JNIEXPORT jint JNICALL Java_nsk_stress_jni_gclocker_JNIWorker_NativeCall___3BLjava_lang_String_2
107
(JNIEnv * env, jobject obj, jbyteArray array, jstring str)
108
{
109
BODY(jbyte)
110
}
111
112
/*
113
* Class: JNIWorker
114
* Method: NativeCall
115
* Signature: ([CLjava/lang/String;)I
116
*/
117
JNIEXPORT jint JNICALL Java_nsk_stress_jni_gclocker_JNIWorker_NativeCall___3CLjava_lang_String_2
118
(JNIEnv *env, jobject obj, jcharArray array, jstring str)
119
{
120
BODY(jchar)
121
}
122
123
/*
124
* Class: JNIWorker
125
* Method: NativeCall
126
* Signature: ([SLjava/lang/String;)I
127
*/
128
JNIEXPORT jint JNICALL Java_nsk_stress_jni_gclocker_JNIWorker_NativeCall___3SLjava_lang_String_2
129
(JNIEnv *env, jobject obj, jshortArray array, jstring str)
130
{
131
BODY(jshort)
132
}
133
134
/*
135
* Class: JNIWorker
136
* Method: NativeCall
137
* Signature: ([ILjava/lang/String;)I
138
*/
139
JNIEXPORT jint JNICALL Java_nsk_stress_jni_gclocker_JNIWorker_NativeCall___3ILjava_lang_String_2
140
(JNIEnv *env, jobject obj, jintArray array, jstring str)
141
{
142
BODY(jint)
143
}
144
145
/*
146
* Class: JNIWorker
147
* Method: NativeCall
148
* Signature: ([JLjava/lang/String;)I
149
*/
150
151
JNIEXPORT jint JNICALL Java_nsk_stress_jni_gclocker_JNIWorker_NativeCall___3JLjava_lang_String_2
152
(JNIEnv *env, jobject obj, jlongArray array, jstring str)
153
{
154
BODY(jlong)
155
}
156
157
/*
158
* Class: JNIWorker
159
* Method: NativeCall
160
* Signature: ([FLjava/lang/String;)I
161
*/
162
JNIEXPORT jint JNICALL Java_nsk_stress_jni_gclocker_JNIWorker_NativeCall___3FLjava_lang_String_2
163
(JNIEnv *env, jobject obj, jfloatArray array, jstring str)
164
{
165
BODY(jfloat)
166
}
167
168
/*
169
* Class: JNIWorker
170
* Method: NativeCall
171
* Signature: ([DLjava/lang/String;)I
172
*/
173
JNIEXPORT jint JNICALL Java_nsk_stress_jni_gclocker_JNIWorker_NativeCall___3DLjava_lang_String_2
174
(JNIEnv *env, jobject obj, jdoubleArray array, jstring str)
175
{
176
BODY(jdouble)
177
}
178
179
}
180
181