Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/j9vm/j8vmi.c
5985 views
1
/*******************************************************************************
2
* Copyright (c) 2002, 2019 IBM Corp. and others
3
*
4
* This program and the accompanying materials are made available under
5
* the terms of the Eclipse Public License 2.0 which accompanies this
6
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
7
* or the Apache License, Version 2.0 which accompanies this distribution and
8
* is available at https://www.apache.org/licenses/LICENSE-2.0.
9
*
10
* This Source Code may also be made available under the following
11
* Secondary Licenses when the conditions for such availability set
12
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
13
* General Public License, version 2 with the GNU Classpath
14
* Exception [1] and GNU General Public License, version 2 with the
15
* OpenJDK Assembly Exception [2].
16
*
17
* [1] https://www.gnu.org/software/classpath/license.html
18
* [2] http://openjdk.java.net/legal/assembly-exception.html
19
*
20
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception
21
*******************************************************************************/
22
23
/**
24
* @brief This file contains implementations of the public JVM interface (JVM_ functions)
25
* which simply forward to a concrete implementation located either in the JCL library
26
* or proxy forwarder.
27
*/
28
29
#include <stdlib.h>
30
#include <assert.h>
31
32
#include "j9.h"
33
#include "omrgcconsts.h"
34
#include "j9modifiers_api.h"
35
#include "j9vm_internal.h"
36
#include "j9vmconstantpool.h"
37
#include "rommeth.h"
38
#include "sunvmi_api.h"
39
#include "util_api.h"
40
#include "ut_j9scar.h"
41
#include "j9vmnls.h"
42
43
jbyteArray JNICALL
44
JVM_GetClassTypeAnnotations(JNIEnv *env, jclass jlClass) {
45
ENSURE_VMI();
46
return g_VMI->JVM_GetClassTypeAnnotations(env, jlClass);
47
}
48
49
jbyteArray JNICALL
50
JVM_GetFieldTypeAnnotations(JNIEnv *env, jobject jlrField) {
51
ENSURE_VMI();
52
return g_VMI->JVM_GetFieldTypeAnnotations(env, jlrField);
53
}
54
55
jobjectArray JNICALL
56
JVM_GetMethodParameters(JNIEnv *env, jobject jlrExecutable) {
57
ENSURE_VMI();
58
return g_VMI->JVM_GetMethodParameters(env, jlrExecutable);
59
}
60
61
jbyteArray JNICALL
62
JVM_GetMethodTypeAnnotations(JNIEnv *env, jobject jlrMethod) {
63
ENSURE_VMI();
64
return g_VMI->JVM_GetMethodTypeAnnotations(env, jlrMethod);
65
}
66
67
jboolean JNICALL
68
JVM_IsVMGeneratedMethodIx(JNIEnv *env, jclass cb, jint index) {
69
assert(!"JVM_IsVMGeneratedMethodIx unimplemented"); /* Jazz 63527: Stub in APIs for Java 8 */
70
return FALSE;
71
}
72
73
/**
74
* Returns platform specific temporary directory used by the system.
75
* Same as getTmpDir() defined in jcl/unix/syshelp.c and jcl/win32/syshelp.c.
76
*
77
* @param [in] env Pointer to JNI environment.
78
*
79
* @return String object representing the platform specific temporary directory.
80
*/
81
jstring JNICALL
82
JVM_GetTemporaryDirectory(JNIEnv *env)
83
{
84
PORT_ACCESS_FROM_ENV(env);
85
jstring result = NULL;
86
IDATA size = j9sysinfo_get_tmp(NULL, 0, TRUE);
87
if (0 <= size) {
88
char *buffer = (char *)j9mem_allocate_memory(size, OMRMEM_CATEGORY_VM);
89
if (NULL == buffer) {
90
return NULL;
91
}
92
if (0 == j9sysinfo_get_tmp(buffer, size, TRUE)) {
93
result = (*env)->NewStringUTF(env, buffer);
94
}
95
96
j9mem_free_memory(buffer);
97
}
98
99
return result;
100
}
101
102
103
/**
104
* Copies memory from one place to another, endian flipping the data.
105
*
106
* Implementation of native java.nio.Bits.copySwapMemory0(). The single java caller
107
* has ensured all of the parameters are valid.
108
*
109
* @param [in] env Pointer to JNI environment
110
* @param [in] srcObj Source primitive array (NULL means srcOffset represents native memory)
111
* @param [in] srcOffset Offset in source array / address in native memory
112
* @param [in] dstObj Destination primitive array (NULL means dstOffset represents native memory)
113
* @param [in] dstOffset Offset in destination array / address in native memory
114
* @param [in] size Number of bytes to copy
115
* @param [in] elemSize Size of elements to copy and flip
116
*
117
* elemSize = 2 means byte order 1,2 becomes 2,1
118
* elemSize = 4 means byte order 1,2,3,4 becomes 4,3,2,1
119
* elemSize = 8 means byte order 1,2,3,4,5,6,7,8 becomes 8,7,6,5,4,3,2,1
120
*/
121
void JNICALL
122
JVM_CopySwapMemory(JNIEnv *env, jobject srcObj, jlong srcOffset, jobject dstObj, jlong dstOffset, jlong size, jlong elemSize)
123
{
124
U_8 *srcBytes = NULL;
125
U_8 *dstBytes = NULL;
126
U_8 *dstAddr = NULL;
127
if (NULL != srcObj) {
128
srcBytes = (*env)->GetPrimitiveArrayCritical(env, srcObj, NULL);
129
/* The java caller has added Unsafe.arrayBaseOffset() to the offset. Remove it
130
* here as GetPrimitiveArrayCritical returns a pointer to the first element.
131
*/
132
srcOffset -= J9VMTHREAD_CONTIGUOUS_HEADER_SIZE((J9VMThread*)env);
133
}
134
if (NULL != dstObj) {
135
dstBytes = (*env)->GetPrimitiveArrayCritical(env, dstObj, NULL);
136
dstAddr = dstBytes;
137
/* The java caller has added Unsafe.arrayBaseOffset() to the offset. Remove it
138
* here as GetPrimitiveArrayCritical returns a pointer to the first element.
139
*/
140
dstOffset -= J9VMTHREAD_CONTIGUOUS_HEADER_SIZE((J9VMThread*)env);
141
}
142
dstAddr += (UDATA)dstOffset;
143
/* First copy the bytes unmodified to the new location (memmove handles the overlap case) */
144
memmove(dstAddr, srcBytes + (UDATA)srcOffset, (size_t)size);
145
/* Now flip each element in the destination */
146
switch(elemSize) {
147
case 2: {
148
jlong elemCount = size / 2;
149
while (0 != elemCount) {
150
U_8 temp = dstAddr[0];
151
dstAddr[0] = dstAddr[1];
152
dstAddr[1] = temp;
153
dstAddr += 2;
154
elemCount -= 1;
155
}
156
break;
157
}
158
case 4: {
159
jlong elemCount = size / 4;
160
while (0 != elemCount) {
161
U_8 temp = dstAddr[0];
162
dstAddr[0] = dstAddr[3];
163
dstAddr[3] = temp;
164
temp = dstAddr[1];
165
dstAddr[1] = dstAddr[2];
166
dstAddr[2] = temp;
167
dstAddr += 4;
168
elemCount -= 1;
169
}
170
break;
171
}
172
default /* 8 */: {
173
jlong elemCount = size / 8;
174
while (0 != elemCount) {
175
U_8 temp = dstAddr[0];
176
dstAddr[0] = dstAddr[7];
177
dstAddr[7] = temp;
178
temp = dstAddr[1];
179
dstAddr[1] = dstAddr[6];
180
dstAddr[6] = temp;
181
temp = dstAddr[2];
182
dstAddr[2] = dstAddr[5];
183
dstAddr[5] = temp;
184
temp = dstAddr[3];
185
dstAddr[3] = dstAddr[4];
186
dstAddr[4] = temp;
187
dstAddr += 8;
188
elemCount -= 1;
189
}
190
break;
191
}
192
}
193
if (NULL != srcObj) {
194
(*env)->ReleasePrimitiveArrayCritical(env, srcObj, srcBytes, JNI_ABORT);
195
}
196
if (NULL != dstObj) {
197
(*env)->ReleasePrimitiveArrayCritical(env, dstObj, dstBytes, 0);
198
}
199
}
200
201