8187443: Forest Consolidation: Move files to unified layout

Reviewed-by: darcy, ihse
This commit is contained in:
Erik Joelsson 2017-09-12 19:03:39 +02:00
parent 270fe13182
commit 3789983e89
56923 changed files with 3 additions and 15727 deletions

View file

@ -0,0 +1,96 @@
/*
* Copyright (c) 1997, 1998, 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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.
*/
/*-
* Implementation of class java.security.AccessController
*
*/
#include <string.h>
#include "jni.h"
#include "jvm.h"
#include "java_security_AccessController.h"
/*
* Class: java_security_AccessController
* Method: doPrivileged
* Signature: (Ljava/security/PrivilegedAction;)Ljava/lang/Object;
*/
JNIEXPORT jobject JNICALL Java_java_security_AccessController_doPrivileged__Ljava_security_PrivilegedAction_2
(JNIEnv *env, jclass cls, jobject action)
{
return JVM_DoPrivileged(env, cls, action, NULL, JNI_FALSE);
}
/*
* Class: java_security_AccessController
* Method: doPrivileged
* Signature: (Ljava/security/PrivilegedAction;Ljava/security/AccessControlContext;)Ljava/lang/Object;
*/
JNIEXPORT jobject JNICALL Java_java_security_AccessController_doPrivileged__Ljava_security_PrivilegedAction_2Ljava_security_AccessControlContext_2
(JNIEnv *env, jclass cls, jobject action, jobject context)
{
return JVM_DoPrivileged(env, cls, action, context, JNI_FALSE);
}
/*
* Class: java_security_AccessController
* Method: doPrivileged
* Signature: (Ljava/security/PrivilegedExceptionAction;)Ljava/lang/Object;
*/
JNIEXPORT jobject JNICALL Java_java_security_AccessController_doPrivileged__Ljava_security_PrivilegedExceptionAction_2
(JNIEnv *env, jclass cls, jobject action)
{
return JVM_DoPrivileged(env, cls, action, NULL, JNI_TRUE);
}
/*
* Class: java_security_AccessController
* Method: doPrivileged
* Signature: (Ljava/security/PrivilegedExceptionAction;Ljava/security/AccessControlContext;)Ljava/lang/Object;
*/
JNIEXPORT jobject JNICALL Java_java_security_AccessController_doPrivileged__Ljava_security_PrivilegedExceptionAction_2Ljava_security_AccessControlContext_2
(JNIEnv *env, jclass cls, jobject action, jobject context)
{
return JVM_DoPrivileged(env, cls, action, context, JNI_TRUE);
}
JNIEXPORT jobject JNICALL
Java_java_security_AccessController_getStackAccessControlContext(
JNIEnv *env,
jobject this)
{
return JVM_GetStackAccessControlContext(env, this);
}
JNIEXPORT jobject JNICALL
Java_java_security_AccessController_getInheritedAccessControlContext(
JNIEnv *env,
jobject this)
{
return JVM_GetInheritedAccessControlContext(env, this);
}

View file

@ -0,0 +1,208 @@
/*
* Copyright (c) 1996, 1998, 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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.
*/
#include "jni.h"
#include "jvm.h"
#include "java_lang_reflect_Array.h"
/*
* Native code for java.lang.reflect.Array.
*
* TODO: Performance
*/
/*
*
*/
JNIEXPORT jint JNICALL
Java_java_lang_reflect_Array_getLength(JNIEnv *env, jclass ignore, jobject arr)
{
return JVM_GetArrayLength(env, arr);
}
/*
*
*/
JNIEXPORT jobject JNICALL
Java_java_lang_reflect_Array_get(JNIEnv *env, jclass ignore, jobject arr,
jint index)
{
return JVM_GetArrayElement(env, arr, index);
}
JNIEXPORT jboolean JNICALL
Java_java_lang_reflect_Array_getBoolean(JNIEnv *env, jclass ignore, jobject arr,
jint index)
{
return JVM_GetPrimitiveArrayElement(env, arr, index, JVM_T_BOOLEAN).z;
}
JNIEXPORT jbyte JNICALL
Java_java_lang_reflect_Array_getByte(JNIEnv *env, jclass ignore, jobject arr,
jint index)
{
return JVM_GetPrimitiveArrayElement(env, arr, index, JVM_T_BYTE).b;
}
JNIEXPORT jchar JNICALL
Java_java_lang_reflect_Array_getChar(JNIEnv *env, jclass ignore, jobject arr,
jint index)
{
return JVM_GetPrimitiveArrayElement(env, arr, index, JVM_T_CHAR).c;
}
JNIEXPORT jshort JNICALL
Java_java_lang_reflect_Array_getShort(JNIEnv *env, jclass ignore, jobject arr,
jint index)
{
return JVM_GetPrimitiveArrayElement(env, arr, index, JVM_T_SHORT).s;
}
JNIEXPORT jint JNICALL
Java_java_lang_reflect_Array_getInt(JNIEnv *env, jclass ignore, jobject arr,
jint index)
{
return JVM_GetPrimitiveArrayElement(env, arr, index, JVM_T_INT).i;
}
JNIEXPORT jlong JNICALL
Java_java_lang_reflect_Array_getLong(JNIEnv *env, jclass ignore, jobject arr,
jint index)
{
return JVM_GetPrimitiveArrayElement(env, arr, index, JVM_T_LONG).j;
}
JNIEXPORT jfloat JNICALL
Java_java_lang_reflect_Array_getFloat(JNIEnv *env, jclass ignore, jobject arr,
jint index)
{
return JVM_GetPrimitiveArrayElement(env, arr, index, JVM_T_FLOAT).f;
}
JNIEXPORT jdouble JNICALL
Java_java_lang_reflect_Array_getDouble(JNIEnv *env, jclass ignore, jobject arr,
jint index)
{
return JVM_GetPrimitiveArrayElement(env, arr, index, JVM_T_DOUBLE).d;
}
/*
*
*/
JNIEXPORT void JNICALL
Java_java_lang_reflect_Array_set(JNIEnv *env, jclass ignore, jobject arr,
jint index, jobject val)
{
JVM_SetArrayElement(env, arr, index, val);
}
JNIEXPORT void JNICALL
Java_java_lang_reflect_Array_setBoolean(JNIEnv *env, jclass ignore,
jobject arr, jint index, jboolean z)
{
jvalue v;
v.z = z;
JVM_SetPrimitiveArrayElement(env, arr, index, v, JVM_T_BOOLEAN);
}
JNIEXPORT void JNICALL
Java_java_lang_reflect_Array_setByte(JNIEnv *env, jclass ignore,
jobject arr, jint index, jbyte b)
{
jvalue v;
v.b = b;
JVM_SetPrimitiveArrayElement(env, arr, index, v, JVM_T_BYTE);
}
JNIEXPORT void JNICALL
Java_java_lang_reflect_Array_setChar(JNIEnv *env, jclass ignore,
jobject arr, jint index, jchar c)
{
jvalue v;
v.c = c;
JVM_SetPrimitiveArrayElement(env, arr, index, v, JVM_T_CHAR);
}
JNIEXPORT void JNICALL
Java_java_lang_reflect_Array_setShort(JNIEnv *env, jclass ignore,
jobject arr, jint index, jshort s)
{
jvalue v;
v.s = s;
JVM_SetPrimitiveArrayElement(env, arr, index, v, JVM_T_SHORT);
}
JNIEXPORT void JNICALL
Java_java_lang_reflect_Array_setInt(JNIEnv *env, jclass ignore,
jobject arr, jint index, jint i)
{
jvalue v;
v.i = i;
JVM_SetPrimitiveArrayElement(env, arr, index, v, JVM_T_INT);
}
JNIEXPORT void JNICALL
Java_java_lang_reflect_Array_setLong(JNIEnv *env, jclass ignore,
jobject arr, jint index, jlong j)
{
jvalue v;
v.j = j;
JVM_SetPrimitiveArrayElement(env, arr, index, v, JVM_T_LONG);
}
JNIEXPORT void JNICALL
Java_java_lang_reflect_Array_setFloat(JNIEnv *env, jclass ignore,
jobject arr, jint index, jfloat f)
{
jvalue v;
v.f = f;
JVM_SetPrimitiveArrayElement(env, arr, index, v, JVM_T_FLOAT);
}
JNIEXPORT void JNICALL
Java_java_lang_reflect_Array_setDouble(JNIEnv *env, jclass ignore,
jobject arr, jint index, jdouble d)
{
jvalue v;
v.d = d;
JVM_SetPrimitiveArrayElement(env, arr, index, v, JVM_T_DOUBLE);
}
/*
*
*/
JNIEXPORT jobject JNICALL
Java_java_lang_reflect_Array_newArray(JNIEnv *env, jclass ignore,
jclass eltClass, jint length)
{
return JVM_NewArray(env, eltClass, length);
}
JNIEXPORT jobject JNICALL
Java_java_lang_reflect_Array_multiNewArray(JNIEnv *env, jclass ignore,
jclass eltClass, jintArray dim)
{
return JVM_NewMultiArray(env, eltClass, dim);
}

View file

@ -0,0 +1,34 @@
/*
* Copyright (c) 2004, 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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.
*/
#include <jni.h>
#include <jvm.h>
#include "java_util_concurrent_atomic_AtomicLong.h"
JNIEXPORT jboolean JNICALL
Java_java_util_concurrent_atomic_AtomicLong_VMSupportsCS8(JNIEnv *env, jclass cls)
{
return JVM_SupportsCX8();
}

View file

@ -0,0 +1,48 @@
/*
* Copyright (c) 1998, 2015, 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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.
*/
#include <stdlib.h>
#include "jvm.h"
#include "jni_util.h"
#include "jdk_internal_loader_BootLoader.h"
JNIEXPORT jstring JNICALL
Java_jdk_internal_loader_BootLoader_getSystemPackageLocation(JNIEnv *env, jclass cls, jstring str)
{
return JVM_GetSystemPackage(env, str);
}
JNIEXPORT jobject JNICALL
Java_jdk_internal_loader_BootLoader_getSystemPackageNames(JNIEnv *env, jclass cls)
{
return JVM_GetSystemPackages(env);
}
JNIEXPORT void JNICALL
Java_jdk_internal_loader_BootLoader_setBootLoaderUnnamedModule0(JNIEnv *env, jclass cls, jobject module)
{
JVM_SetBootLoaderUnnamedModule(env, module);
}

View file

@ -0,0 +1,185 @@
/*
* Copyright (c) 1994, 2014, 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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.
*/
/*-
* Implementation of class Class
*
* former threadruntime.c, Sun Sep 22 12:09:39 1991
*/
#include <string.h>
#include <stdlib.h>
#include "jni.h"
#include "jni_util.h"
#include "jvm.h"
#include "java_lang_Class.h"
/* defined in libverify.so/verify.dll (src file common/check_format.c) */
extern jboolean VerifyClassname(char *utf_name, jboolean arrayAllowed);
extern jboolean VerifyFixClassname(char *utf_name);
#define OBJ "Ljava/lang/Object;"
#define CLS "Ljava/lang/Class;"
#define CPL "Ljdk/internal/reflect/ConstantPool;"
#define STR "Ljava/lang/String;"
#define FLD "Ljava/lang/reflect/Field;"
#define MHD "Ljava/lang/reflect/Method;"
#define CTR "Ljava/lang/reflect/Constructor;"
#define PD "Ljava/security/ProtectionDomain;"
#define BA "[B"
static JNINativeMethod methods[] = {
{"getName0", "()" STR, (void *)&JVM_GetClassName},
{"getSuperclass", "()" CLS, NULL},
{"getInterfaces0", "()[" CLS, (void *)&JVM_GetClassInterfaces},
{"isInterface", "()Z", (void *)&JVM_IsInterface},
{"getSigners", "()[" OBJ, (void *)&JVM_GetClassSigners},
{"setSigners", "([" OBJ ")V", (void *)&JVM_SetClassSigners},
{"isArray", "()Z", (void *)&JVM_IsArrayClass},
{"isPrimitive", "()Z", (void *)&JVM_IsPrimitiveClass},
{"getModifiers", "()I", (void *)&JVM_GetClassModifiers},
{"getDeclaredFields0","(Z)[" FLD, (void *)&JVM_GetClassDeclaredFields},
{"getDeclaredMethods0","(Z)[" MHD, (void *)&JVM_GetClassDeclaredMethods},
{"getDeclaredConstructors0","(Z)[" CTR, (void *)&JVM_GetClassDeclaredConstructors},
{"getProtectionDomain0", "()" PD, (void *)&JVM_GetProtectionDomain},
{"getDeclaredClasses0", "()[" CLS, (void *)&JVM_GetDeclaredClasses},
{"getDeclaringClass0", "()" CLS, (void *)&JVM_GetDeclaringClass},
{"getSimpleBinaryName0", "()" STR, (void *)&JVM_GetSimpleBinaryName},
{"getGenericSignature0", "()" STR, (void *)&JVM_GetClassSignature},
{"getRawAnnotations", "()" BA, (void *)&JVM_GetClassAnnotations},
{"getConstantPool", "()" CPL, (void *)&JVM_GetClassConstantPool},
{"desiredAssertionStatus0","("CLS")Z",(void *)&JVM_DesiredAssertionStatus},
{"getEnclosingMethod0", "()[" OBJ, (void *)&JVM_GetEnclosingMethodInfo},
{"getRawTypeAnnotations", "()" BA, (void *)&JVM_GetClassTypeAnnotations},
};
#undef OBJ
#undef CLS
#undef STR
#undef FLD
#undef MHD
#undef CTR
#undef PD
JNIEXPORT void JNICALL
Java_java_lang_Class_registerNatives(JNIEnv *env, jclass cls)
{
methods[1].fnPtr = (void *)(*env)->GetSuperclass;
(*env)->RegisterNatives(env, cls, methods,
sizeof(methods)/sizeof(JNINativeMethod));
}
JNIEXPORT jclass JNICALL
Java_java_lang_Class_forName0(JNIEnv *env, jclass this, jstring classname,
jboolean initialize, jobject loader, jclass caller)
{
char *clname;
jclass cls = 0;
char buf[128];
jsize len;
jsize unicode_len;
if (classname == NULL) {
JNU_ThrowNullPointerException(env, 0);
return 0;
}
len = (*env)->GetStringUTFLength(env, classname);
unicode_len = (*env)->GetStringLength(env, classname);
if (len >= (jsize)sizeof(buf)) {
clname = malloc(len + 1);
if (clname == NULL) {
JNU_ThrowOutOfMemoryError(env, NULL);
return NULL;
}
} else {
clname = buf;
}
(*env)->GetStringUTFRegion(env, classname, 0, unicode_len, clname);
if (VerifyFixClassname(clname) == JNI_TRUE) {
/* slashes present in clname, use name b4 translation for exception */
(*env)->GetStringUTFRegion(env, classname, 0, unicode_len, clname);
JNU_ThrowClassNotFoundException(env, clname);
goto done;
}
if (!VerifyClassname(clname, JNI_TRUE)) { /* expects slashed name */
JNU_ThrowClassNotFoundException(env, clname);
goto done;
}
cls = JVM_FindClassFromCaller(env, clname, initialize, loader, caller);
done:
if (clname != buf) {
free(clname);
}
return cls;
}
JNIEXPORT jboolean JNICALL
Java_java_lang_Class_isInstance(JNIEnv *env, jobject cls, jobject obj)
{
if (obj == NULL) {
return JNI_FALSE;
}
return (*env)->IsInstanceOf(env, obj, (jclass)cls);
}
JNIEXPORT jboolean JNICALL
Java_java_lang_Class_isAssignableFrom(JNIEnv *env, jobject cls, jobject cls2)
{
if (cls2 == NULL) {
JNU_ThrowNullPointerException(env, 0);
return JNI_FALSE;
}
return (*env)->IsAssignableFrom(env, cls2, cls);
}
JNIEXPORT jclass JNICALL
Java_java_lang_Class_getPrimitiveClass(JNIEnv *env,
jclass cls,
jstring name)
{
const char *utfName;
jclass result;
if (name == NULL) {
JNU_ThrowNullPointerException(env, 0);
return NULL;
}
utfName = (*env)->GetStringUTFChars(env, name, 0);
if (utfName == 0)
return NULL;
result = JVM_FindPrimitiveClass(env, utfName);
(*env)->ReleaseStringUTFChars(env, name, utfName);
return result;
}

View file

@ -0,0 +1,524 @@
/*
* Copyright (c) 1996, 2015, 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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.
*/
#include <stdlib.h>
#include <assert.h>
#include "jni.h"
#include "jni_util.h"
#include "jlong.h"
#include "jvm.h"
#include "java_lang_ClassLoader.h"
#include "java_lang_ClassLoader_NativeLibrary.h"
#include <string.h>
/* defined in libverify.so/verify.dll (src file common/check_format.c) */
extern jboolean VerifyClassname(char *utf_name, jboolean arrayAllowed);
extern jboolean VerifyFixClassname(char *utf_name);
static JNINativeMethod methods[] = {
{"retrieveDirectives", "()Ljava/lang/AssertionStatusDirectives;", (void *)&JVM_AssertionStatusDirectives}
};
JNIEXPORT void JNICALL
Java_java_lang_ClassLoader_registerNatives(JNIEnv *env, jclass cls)
{
(*env)->RegisterNatives(env, cls, methods,
sizeof(methods)/sizeof(JNINativeMethod));
}
/* Convert java string to UTF char*. Use local buffer if possible,
otherwise malloc new memory. Returns null IFF malloc failed. */
static char*
getUTF(JNIEnv *env, jstring str, char* localBuf, int bufSize)
{
char* utfStr = NULL;
int len = (*env)->GetStringUTFLength(env, str);
int unicode_len = (*env)->GetStringLength(env, str);
if (len >= bufSize) {
utfStr = malloc(len + 1);
if (utfStr == NULL) {
JNU_ThrowOutOfMemoryError(env, NULL);
return NULL;
}
} else {
utfStr = localBuf;
}
(*env)->GetStringUTFRegion(env, str, 0, unicode_len, utfStr);
return utfStr;
}
JNIEXPORT jclass JNICALL
Java_java_lang_ClassLoader_defineClass1(JNIEnv *env,
jclass cls,
jobject loader,
jstring name,
jbyteArray data,
jint offset,
jint length,
jobject pd,
jstring source)
{
jbyte *body;
char *utfName;
jclass result = 0;
char buf[128];
char* utfSource;
char sourceBuf[1024];
if (data == NULL) {
JNU_ThrowNullPointerException(env, 0);
return 0;
}
/* Work around 4153825. malloc crashes on Solaris when passed a
* negative size.
*/
if (length < 0) {
JNU_ThrowArrayIndexOutOfBoundsException(env, 0);
return 0;
}
body = (jbyte *)malloc(length);
if (body == 0) {
JNU_ThrowOutOfMemoryError(env, 0);
return 0;
}
(*env)->GetByteArrayRegion(env, data, offset, length, body);
if ((*env)->ExceptionOccurred(env))
goto free_body;
if (name != NULL) {
utfName = getUTF(env, name, buf, sizeof(buf));
if (utfName == NULL) {
goto free_body;
}
VerifyFixClassname(utfName);
} else {
utfName = NULL;
}
if (source != NULL) {
utfSource = getUTF(env, source, sourceBuf, sizeof(sourceBuf));
if (utfSource == NULL) {
goto free_utfName;
}
} else {
utfSource = NULL;
}
result = JVM_DefineClassWithSource(env, utfName, loader, body, length, pd, utfSource);
if (utfSource && utfSource != sourceBuf)
free(utfSource);
free_utfName:
if (utfName && utfName != buf)
free(utfName);
free_body:
free(body);
return result;
}
JNIEXPORT jclass JNICALL
Java_java_lang_ClassLoader_defineClass2(JNIEnv *env,
jclass cls,
jobject loader,
jstring name,
jobject data,
jint offset,
jint length,
jobject pd,
jstring source)
{
jbyte *body;
char *utfName;
jclass result = 0;
char buf[128];
char* utfSource;
char sourceBuf[1024];
assert(data != NULL); // caller fails if data is null.
assert(length >= 0); // caller passes ByteBuffer.remaining() for length, so never neg.
// caller passes ByteBuffer.position() for offset, and capacity() >= position() + remaining()
assert((*env)->GetDirectBufferCapacity(env, data) >= (offset + length));
body = (*env)->GetDirectBufferAddress(env, data);
if (body == 0) {
JNU_ThrowNullPointerException(env, 0);
return 0;
}
body += offset;
if (name != NULL) {
utfName = getUTF(env, name, buf, sizeof(buf));
if (utfName == NULL) {
JNU_ThrowOutOfMemoryError(env, NULL);
return result;
}
VerifyFixClassname(utfName);
} else {
utfName = NULL;
}
if (source != NULL) {
utfSource = getUTF(env, source, sourceBuf, sizeof(sourceBuf));
if (utfSource == NULL) {
JNU_ThrowOutOfMemoryError(env, NULL);
goto free_utfName;
}
} else {
utfSource = NULL;
}
result = JVM_DefineClassWithSource(env, utfName, loader, body, length, pd, utfSource);
if (utfSource && utfSource != sourceBuf)
free(utfSource);
free_utfName:
if (utfName && utfName != buf)
free(utfName);
return result;
}
/*
* Returns NULL if class not found.
*/
JNIEXPORT jclass JNICALL
Java_java_lang_ClassLoader_findBootstrapClass(JNIEnv *env, jobject loader,
jstring classname)
{
char *clname;
jclass cls = 0;
char buf[128];
if (classname == NULL) {
return 0;
}
clname = getUTF(env, classname, buf, sizeof(buf));
if (clname == NULL) {
JNU_ThrowOutOfMemoryError(env, NULL);
return NULL;
}
VerifyFixClassname(clname);
if (!VerifyClassname(clname, JNI_TRUE)) { /* expects slashed name */
goto done;
}
cls = JVM_FindClassFromBootLoader(env, clname);
done:
if (clname != buf) {
free(clname);
}
return cls;
}
JNIEXPORT jclass JNICALL
Java_java_lang_ClassLoader_findLoadedClass0(JNIEnv *env, jobject loader,
jstring name)
{
if (name == NULL) {
return 0;
} else {
return JVM_FindLoadedClass(env, loader, name);
}
}
static jfieldID handleID;
static jfieldID jniVersionID;
static jfieldID loadedID;
static void *procHandle;
static jboolean initIDs(JNIEnv *env)
{
if (handleID == 0) {
jclass this =
(*env)->FindClass(env, "java/lang/ClassLoader$NativeLibrary");
if (this == 0)
return JNI_FALSE;
handleID = (*env)->GetFieldID(env, this, "handle", "J");
if (handleID == 0)
return JNI_FALSE;
jniVersionID = (*env)->GetFieldID(env, this, "jniVersion", "I");
if (jniVersionID == 0)
return JNI_FALSE;
loadedID = (*env)->GetFieldID(env, this, "loaded", "Z");
if (loadedID == 0)
return JNI_FALSE;
procHandle = getProcessHandle();
}
return JNI_TRUE;
}
typedef jint (JNICALL *JNI_OnLoad_t)(JavaVM *, void *);
typedef void (JNICALL *JNI_OnUnload_t)(JavaVM *, void *);
/*
* Support for finding JNI_On(Un)Load_<lib_name> if it exists.
* If cname == NULL then just find normal JNI_On(Un)Load entry point
*/
static void *findJniFunction(JNIEnv *env, void *handle,
const char *cname, jboolean isLoad) {
const char *onLoadSymbols[] = JNI_ONLOAD_SYMBOLS;
const char *onUnloadSymbols[] = JNI_ONUNLOAD_SYMBOLS;
const char **syms;
int symsLen;
void *entryName = NULL;
char *jniFunctionName;
int i;
size_t len;
// Check for JNI_On(Un)Load<_libname> function
if (isLoad) {
syms = onLoadSymbols;
symsLen = sizeof(onLoadSymbols) / sizeof(char *);
} else {
syms = onUnloadSymbols;
symsLen = sizeof(onUnloadSymbols) / sizeof(char *);
}
for (i = 0; i < symsLen; i++) {
// cname + sym + '_' + '\0'
if ((len = (cname != NULL ? strlen(cname) : 0) + strlen(syms[i]) + 2) >
FILENAME_MAX) {
goto done;
}
jniFunctionName = malloc(len);
if (jniFunctionName == NULL) {
JNU_ThrowOutOfMemoryError(env, NULL);
goto done;
}
buildJniFunctionName(syms[i], cname, jniFunctionName);
entryName = JVM_FindLibraryEntry(handle, jniFunctionName);
free(jniFunctionName);
if(entryName) {
break;
}
}
done:
return entryName;
}
/*
* Class: java_lang_ClassLoader_NativeLibrary
* Method: load
* Signature: (Ljava/lang/String;Z)V
*/
JNIEXPORT void JNICALL
Java_java_lang_ClassLoader_00024NativeLibrary_load
(JNIEnv *env, jobject this, jstring name, jboolean isBuiltin)
{
const char *cname;
jint jniVersion;
jthrowable cause;
void * handle;
if (!initIDs(env))
return;
cname = JNU_GetStringPlatformChars(env, name, 0);
if (cname == 0)
return;
handle = isBuiltin ? procHandle : JVM_LoadLibrary(cname);
if (handle) {
JNI_OnLoad_t JNI_OnLoad;
JNI_OnLoad = (JNI_OnLoad_t)findJniFunction(env, handle,
isBuiltin ? cname : NULL,
JNI_TRUE);
if (JNI_OnLoad) {
JavaVM *jvm;
(*env)->GetJavaVM(env, &jvm);
jniVersion = (*JNI_OnLoad)(jvm, NULL);
} else {
jniVersion = 0x00010001;
}
cause = (*env)->ExceptionOccurred(env);
if (cause) {
(*env)->ExceptionClear(env);
(*env)->Throw(env, cause);
if (!isBuiltin) {
JVM_UnloadLibrary(handle);
}
goto done;
}
if (!JVM_IsSupportedJNIVersion(jniVersion) ||
(isBuiltin && jniVersion < JNI_VERSION_1_8)) {
char msg[256];
jio_snprintf(msg, sizeof(msg),
"unsupported JNI version 0x%08X required by %s",
jniVersion, cname);
JNU_ThrowByName(env, "java/lang/UnsatisfiedLinkError", msg);
if (!isBuiltin) {
JVM_UnloadLibrary(handle);
}
goto done;
}
(*env)->SetIntField(env, this, jniVersionID, jniVersion);
} else {
cause = (*env)->ExceptionOccurred(env);
if (cause) {
(*env)->ExceptionClear(env);
(*env)->SetLongField(env, this, handleID, (jlong)0);
(*env)->Throw(env, cause);
}
goto done;
}
(*env)->SetLongField(env, this, handleID, ptr_to_jlong(handle));
(*env)->SetBooleanField(env, this, loadedID, JNI_TRUE);
done:
JNU_ReleaseStringPlatformChars(env, name, cname);
}
/*
* Class: java_lang_ClassLoader_NativeLibrary
* Method: unload
* Signature: (Z)V
*/
JNIEXPORT void JNICALL
Java_java_lang_ClassLoader_00024NativeLibrary_unload
(JNIEnv *env, jobject this, jstring name, jboolean isBuiltin)
{
const char *onUnloadSymbols[] = JNI_ONUNLOAD_SYMBOLS;
void *handle;
JNI_OnUnload_t JNI_OnUnload;
const char *cname;
if (!initIDs(env))
return;
cname = JNU_GetStringPlatformChars(env, name, 0);
if (cname == NULL) {
return;
}
handle = jlong_to_ptr((*env)->GetLongField(env, this, handleID));
JNI_OnUnload = (JNI_OnUnload_t )findJniFunction(env, handle,
isBuiltin ? cname : NULL,
JNI_FALSE);
if (JNI_OnUnload) {
JavaVM *jvm;
(*env)->GetJavaVM(env, &jvm);
(*JNI_OnUnload)(jvm, NULL);
}
if (!isBuiltin) {
JVM_UnloadLibrary(handle);
}
JNU_ReleaseStringPlatformChars(env, name, cname);
}
/*
* Class: java_lang_ClassLoader_NativeLibrary
* Method: find
* Signature: (Ljava/lang/String;)J
*/
JNIEXPORT jlong JNICALL
Java_java_lang_ClassLoader_00024NativeLibrary_find
(JNIEnv *env, jobject this, jstring name)
{
jlong handle;
const char *cname;
jlong res;
if (!initIDs(env))
return jlong_zero;
handle = (*env)->GetLongField(env, this, handleID);
cname = (*env)->GetStringUTFChars(env, name, 0);
if (cname == 0)
return jlong_zero;
res = ptr_to_jlong(JVM_FindLibraryEntry(jlong_to_ptr(handle), cname));
(*env)->ReleaseStringUTFChars(env, name, cname);
return res;
}
/*
* Class: java_lang_ClassLoader
* Method: findBuiltinLib
* Signature: (Ljava/lang/String;)Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL
Java_java_lang_ClassLoader_findBuiltinLib
(JNIEnv *env, jclass cls, jstring name)
{
const char *cname;
char *libName;
size_t prefixLen = strlen(JNI_LIB_PREFIX);
size_t suffixLen = strlen(JNI_LIB_SUFFIX);
size_t len;
jstring lib;
void *ret;
const char *onLoadSymbols[] = JNI_ONLOAD_SYMBOLS;
if (name == NULL) {
JNU_ThrowInternalError(env, "NULL filename for native library");
return NULL;
}
procHandle = getProcessHandle();
cname = JNU_GetStringPlatformChars(env, name, 0);
if (cname == NULL) {
return NULL;
}
// Copy name Skipping PREFIX
len = strlen(cname);
if (len <= (prefixLen+suffixLen)) {
JNU_ReleaseStringPlatformChars(env, name, cname);
return NULL;
}
libName = malloc(len + 1); //+1 for null if prefix+suffix == 0
if (libName == NULL) {
JNU_ReleaseStringPlatformChars(env, name, cname);
JNU_ThrowOutOfMemoryError(env, NULL);
return NULL;
}
if (len > prefixLen) {
strcpy(libName, cname+prefixLen);
}
JNU_ReleaseStringPlatformChars(env, name, cname);
// Strip SUFFIX
libName[strlen(libName)-suffixLen] = '\0';
// Check for JNI_OnLoad_libname function
ret = findJniFunction(env, procHandle, libName, JNI_TRUE);
if (ret != NULL) {
lib = JNU_NewStringPlatform(env, libName);
free(libName);
return lib;
}
free(libName);
return NULL;
}

View file

@ -0,0 +1,136 @@
/*
* Copyright (c) 2003, 2015, 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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.
*/
#include "jvm.h"
#include "jdk_internal_reflect_ConstantPool.h"
JNIEXPORT jint JNICALL Java_jdk_internal_reflect_ConstantPool_getSize0
(JNIEnv *env, jobject unused, jobject jcpool)
{
return JVM_ConstantPoolGetSize(env, unused, jcpool);
}
JNIEXPORT jclass JNICALL Java_jdk_internal_reflect_ConstantPool_getClassAt0
(JNIEnv *env, jobject unused, jobject jcpool, jint index)
{
return JVM_ConstantPoolGetClassAt(env, unused, jcpool, index);
}
JNIEXPORT jclass JNICALL Java_jdk_internal_reflect_ConstantPool_getClassAtIfLoaded0
(JNIEnv *env, jobject unused, jobject jcpool, jint index)
{
return JVM_ConstantPoolGetClassAtIfLoaded(env, unused, jcpool, index);
}
JNIEXPORT jint JNICALL Java_jdk_internal_reflect_ConstantPool_getClassRefIndexAt0
(JNIEnv *env, jobject unused, jobject jcpool, jint index)
{
return JVM_ConstantPoolGetClassRefIndexAt(env, unused, jcpool, index);
}
JNIEXPORT jobject JNICALL Java_jdk_internal_reflect_ConstantPool_getMethodAt0
(JNIEnv *env, jobject unused, jobject jcpool, jint index)
{
return JVM_ConstantPoolGetMethodAt(env, unused, jcpool, index);
}
JNIEXPORT jobject JNICALL Java_jdk_internal_reflect_ConstantPool_getMethodAtIfLoaded0
(JNIEnv *env, jobject unused, jobject jcpool, jint index)
{
return JVM_ConstantPoolGetMethodAtIfLoaded(env, unused, jcpool, index);
}
JNIEXPORT jobject JNICALL Java_jdk_internal_reflect_ConstantPool_getFieldAt0
(JNIEnv *env, jobject unused, jobject jcpool, jint index)
{
return JVM_ConstantPoolGetFieldAt(env, unused, jcpool, index);
}
JNIEXPORT jobject JNICALL Java_jdk_internal_reflect_ConstantPool_getFieldAtIfLoaded0
(JNIEnv *env, jobject unused, jobject jcpool, jint index)
{
return JVM_ConstantPoolGetFieldAtIfLoaded(env, unused, jcpool, index);
}
JNIEXPORT jobjectArray JNICALL Java_jdk_internal_reflect_ConstantPool_getMemberRefInfoAt0
(JNIEnv *env, jobject unused, jobject jcpool, jint index)
{
return JVM_ConstantPoolGetMemberRefInfoAt(env, unused, jcpool, index);
}
JNIEXPORT jint JNICALL Java_jdk_internal_reflect_ConstantPool_getNameAndTypeRefIndexAt0
(JNIEnv *env, jobject unused, jobject jcpool, jint index)
{
return JVM_ConstantPoolGetNameAndTypeRefIndexAt(env, unused, jcpool, index);
}
JNIEXPORT jobjectArray JNICALL Java_jdk_internal_reflect_ConstantPool_getNameAndTypeRefInfoAt0
(JNIEnv *env, jobject unused, jobject jcpool, jint index)
{
return JVM_ConstantPoolGetNameAndTypeRefInfoAt(env, unused, jcpool, index);
}
JNIEXPORT jint JNICALL Java_jdk_internal_reflect_ConstantPool_getIntAt0
(JNIEnv *env, jobject unused, jobject jcpool, jint index)
{
return JVM_ConstantPoolGetIntAt(env, unused, jcpool, index);
}
JNIEXPORT jlong JNICALL Java_jdk_internal_reflect_ConstantPool_getLongAt0
(JNIEnv *env, jobject unused, jobject jcpool, jint index)
{
return JVM_ConstantPoolGetLongAt(env, unused, jcpool, index);
}
JNIEXPORT jfloat JNICALL Java_jdk_internal_reflect_ConstantPool_getFloatAt0
(JNIEnv *env, jobject unused, jobject jcpool, jint index)
{
return JVM_ConstantPoolGetFloatAt(env, unused, jcpool, index);
}
JNIEXPORT jdouble JNICALL Java_jdk_internal_reflect_ConstantPool_getDoubleAt0
(JNIEnv *env, jobject unused, jobject jcpool, jint index)
{
return JVM_ConstantPoolGetDoubleAt(env, unused, jcpool, index);
}
JNIEXPORT jstring JNICALL Java_jdk_internal_reflect_ConstantPool_getStringAt0
(JNIEnv *env, jobject unused, jobject jcpool, jint index)
{
return JVM_ConstantPoolGetStringAt(env, unused, jcpool, index);
}
JNIEXPORT jstring JNICALL Java_jdk_internal_reflect_ConstantPool_getUTF8At0
(JNIEnv *env, jobject unused, jobject jcpool, jint index)
{
return JVM_ConstantPoolGetUTF8At(env, unused, jcpool, index);
}
JNIEXPORT jbyte JNICALL Java_jdk_internal_reflect_ConstantPool_getTagAt0
(JNIEnv *env, jobject unused, jobject jcpool, jint index)
{
return JVM_ConstantPoolGetTagAt(env, unused, jcpool, index);
}

View file

@ -0,0 +1,61 @@
/*
* Copyright (c) 1997, 2005, 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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.
*/
#include "jni.h"
#include "jni_util.h"
#include "jlong.h"
#include "jvm.h"
#include "java_lang_Double.h"
/*
* Find the double float corresponding to a given bit pattern
*/
JNIEXPORT jdouble JNICALL
Java_java_lang_Double_longBitsToDouble(JNIEnv *env, jclass unused, jlong v)
{
union {
jlong l;
double d;
} u;
jlong_to_jdouble_bits(&v);
u.l = v;
return (jdouble)u.d;
}
/*
* Find the bit pattern corresponding to a given double float, NOT collapsing NaNs
*/
JNIEXPORT jlong JNICALL
Java_java_lang_Double_doubleToRawLongBits(JNIEnv *env, jclass unused, jdouble v)
{
union {
jlong l;
double d;
} u;
jdouble_to_jlong_bits(&v);
u.d = (double)v;
return u.l;
}

View file

@ -0,0 +1,40 @@
/*
* Copyright (c) 2013, 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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.
*/
#include "jni.h"
#include "jvm.h"
#include "java_lang_reflect_Executable.h"
JNIEXPORT jobject JNICALL
Java_java_lang_reflect_Executable_getParameters0(JNIEnv *env,
jobject method) {
return JVM_GetMethodParameters(env, method);
}
JNIEXPORT jbyteArray JNICALL
Java_java_lang_reflect_Executable_getTypeAnnotationBytes0(JNIEnv *env,
jobject method) {
return JVM_GetMethodTypeAnnotations(env, method);
}

View file

@ -0,0 +1,34 @@
/*
* Copyright (c) 2013, 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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.
*/
#include "jni.h"
#include "jvm.h"
#include "java_lang_reflect_Field.h"
JNIEXPORT jbyteArray JNICALL
Java_java_lang_reflect_Field_getTypeAnnotationBytes0(JNIEnv *env,
jobject field) {
return JVM_GetFieldTypeAnnotations(env, field);
}

View file

@ -0,0 +1,110 @@
/*
* Copyright (c) 1997, 2015, 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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.
*/
#include <fcntl.h>
#include <limits.h>
#include "jni.h"
#include "jni_util.h"
#include "jlong.h"
#include "io_util.h"
#include "jvm.h"
#include "java_io_FileInputStream.h"
#include "io_util_md.h"
/*******************************************************************/
/* BEGIN JNI ********* BEGIN JNI *********** BEGIN JNI ************/
/*******************************************************************/
jfieldID fis_fd; /* id for jobject 'fd' in java.io.FileInputStream */
/**************************************************************
* static methods to store field ID's in initializers
*/
JNIEXPORT void JNICALL
Java_java_io_FileInputStream_initIDs(JNIEnv *env, jclass fdClass) {
fis_fd = (*env)->GetFieldID(env, fdClass, "fd", "Ljava/io/FileDescriptor;");
}
/**************************************************************
* Input stream
*/
JNIEXPORT void JNICALL
Java_java_io_FileInputStream_open0(JNIEnv *env, jobject this, jstring path) {
fileOpen(env, this, path, fis_fd, O_RDONLY);
}
JNIEXPORT jint JNICALL
Java_java_io_FileInputStream_read0(JNIEnv *env, jobject this) {
return readSingle(env, this, fis_fd);
}
JNIEXPORT jint JNICALL
Java_java_io_FileInputStream_readBytes(JNIEnv *env, jobject this,
jbyteArray bytes, jint off, jint len) {
return readBytes(env, this, bytes, off, len, fis_fd);
}
JNIEXPORT jlong JNICALL
Java_java_io_FileInputStream_skip0(JNIEnv *env, jobject this, jlong toSkip) {
jlong cur = jlong_zero;
jlong end = jlong_zero;
FD fd = GET_FD(this, fis_fd);
if (fd == -1) {
JNU_ThrowIOException (env, "Stream Closed");
return 0;
}
if ((cur = IO_Lseek(fd, (jlong)0, (jint)SEEK_CUR)) == -1) {
JNU_ThrowIOExceptionWithLastError(env, "Seek error");
} else if ((end = IO_Lseek(fd, toSkip, (jint)SEEK_CUR)) == -1) {
JNU_ThrowIOExceptionWithLastError(env, "Seek error");
}
return (end - cur);
}
JNIEXPORT jint JNICALL
Java_java_io_FileInputStream_available0(JNIEnv *env, jobject this) {
jlong ret;
FD fd = GET_FD(this, fis_fd);
if (fd == -1) {
JNU_ThrowIOException (env, "Stream Closed");
return 0;
}
if (IO_Available(fd, &ret)) {
if (ret > INT_MAX) {
ret = (jlong) INT_MAX;
} else if (ret < 0) {
ret = 0;
}
return jlong_to_jint(ret);
}
JNU_ThrowIOExceptionWithLastError(env, NULL);
return 0;
}

View file

@ -0,0 +1,57 @@
/*
* Copyright (c) 1997, 2005, 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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.
*/
#include "jni.h"
#include "jvm.h"
#include "java_lang_Float.h"
/*
* Find the float corresponding to a given bit pattern
*/
JNIEXPORT jfloat JNICALL
Java_java_lang_Float_intBitsToFloat(JNIEnv *env, jclass unused, jint v)
{
union {
int i;
float f;
} u;
u.i = (long)v;
return (jfloat)u.f;
}
/*
* Find the bit pattern corresponding to a given float, NOT collapsing NaNs
*/
JNIEXPORT jint JNICALL
Java_java_lang_Float_floatToRawIntBits(JNIEnv *env, jclass unused, jfloat v)
{
union {
int i;
float f;
} u;
u.f = (float)v;
return (jint)u.i;
}

View file

@ -0,0 +1,178 @@
/*
* Copyright (c) 2015, 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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.
*/
#include <stdlib.h>
#include <string.h>
#include "jni.h"
#include "jni_util.h"
#include "jvm.h"
#include "java_lang_Module.h"
/*
* Gets the UTF-8 chars for the string and translates '.' to '/'. Does no
* further validation, assumption being that both calling code in
* java.lang.Module and VM will do deeper validation.
*/
static char*
GetInternalPackageName(JNIEnv *env, jstring pkg, char* buf, jsize buf_size)
{
jsize len;
jsize unicode_len;
char* p;
char* utf_str;
len = (*env)->GetStringUTFLength(env, pkg);
unicode_len = (*env)->GetStringLength(env, pkg);
if (len >= buf_size) {
utf_str = malloc(len + 1);
if (utf_str == NULL) {
JNU_ThrowOutOfMemoryError(env, NULL);
return NULL;
}
} else {
utf_str = buf;
}
(*env)->GetStringUTFRegion(env, pkg, 0, unicode_len, utf_str);
p = utf_str;
while (*p != '\0') {
if (*p == '.') {
*p = '/';
}
p++;
}
return utf_str;
}
JNIEXPORT void JNICALL
Java_java_lang_Module_defineModule0(JNIEnv *env, jclass cls, jobject module,
jboolean is_open, jstring version,
jstring location, jobjectArray packages)
{
char** pkgs = NULL;
jsize num_packages = (*env)->GetArrayLength(env, packages);
if (num_packages != 0 && (pkgs = calloc(num_packages, sizeof(char*))) == NULL) {
JNU_ThrowOutOfMemoryError(env, NULL);
return;
} else if ((*env)->EnsureLocalCapacity(env, (jint)num_packages) == 0) {
jboolean failed = JNI_FALSE;
int idx;
for (idx = 0; idx < num_packages; idx++) {
jstring pkg = (*env)->GetObjectArrayElement(env, packages, idx);
char* name = GetInternalPackageName(env, pkg, NULL, 0);
if (name != NULL) {
pkgs[idx] = name;
} else {
failed = JNI_TRUE;
break;
}
}
if (!failed) {
JVM_DefineModule(env, module, is_open, version, location,
(const char* const*)pkgs, num_packages);
}
}
if (num_packages > 0) {
int idx;
for (idx = 0; idx < num_packages; idx++) {
if (pkgs[idx] != NULL) {
free(pkgs[idx]);
}
}
free(pkgs);
}
}
JNIEXPORT void JNICALL
Java_java_lang_Module_addReads0(JNIEnv *env, jclass cls, jobject from, jobject to)
{
JVM_AddReadsModule(env, from, to);
}
JNIEXPORT void JNICALL
Java_java_lang_Module_addExports0(JNIEnv *env, jclass cls, jobject from,
jstring pkg, jobject to)
{
char buf[128];
char* pkg_name;
if (pkg == NULL) {
JNU_ThrowNullPointerException(env, "package is null");
return;
}
pkg_name = GetInternalPackageName(env, pkg, buf, (jsize)sizeof(buf));
if (pkg_name != NULL) {
JVM_AddModuleExports(env, from, pkg_name, to);
if (pkg_name != buf) {
free(pkg_name);
}
}
}
JNIEXPORT void JNICALL
Java_java_lang_Module_addExportsToAll0(JNIEnv *env, jclass cls, jobject from,
jstring pkg)
{
char buf[128];
char* pkg_name;
if (pkg == NULL) {
JNU_ThrowNullPointerException(env, "package is null");
return;
}
pkg_name = GetInternalPackageName(env, pkg, buf, (jsize)sizeof(buf));
if (pkg_name != NULL) {
JVM_AddModuleExportsToAll(env, from, pkg_name);
if (pkg_name != buf) {
free(pkg_name);
}
}
}
JNIEXPORT void JNICALL
Java_java_lang_Module_addExportsToAllUnnamed0(JNIEnv *env, jclass cls,
jobject from, jstring pkg)
{
char buf[128];
char* pkg_name;
if (pkg == NULL) {
JNU_ThrowNullPointerException(env, "package is null");
return;
}
pkg_name = GetInternalPackageName(env, pkg, buf, (jsize)sizeof(buf));
if (pkg_name != NULL) {
JVM_AddModuleExportsToAllUnnamed(env, from, pkg_name);
if (pkg_name != buf) {
free(pkg_name);
}
}
}

View file

@ -0,0 +1,40 @@
/*
* Copyright (c) 2001, 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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.
*/
#include "jvm.h"
#include "jdk_internal_reflect_NativeConstructorAccessorImpl.h"
#include "jdk_internal_reflect_NativeMethodAccessorImpl.h"
JNIEXPORT jobject JNICALL Java_jdk_internal_reflect_NativeMethodAccessorImpl_invoke0
(JNIEnv *env, jclass unused, jobject m, jobject obj, jobjectArray args)
{
return JVM_InvokeMethod(env, m, obj, args);
}
JNIEXPORT jobject JNICALL Java_jdk_internal_reflect_NativeConstructorAccessorImpl_newInstance0
(JNIEnv *env, jclass unused, jobject c, jobjectArray args)
{
return JVM_NewInstanceFromConstructor(env, c, args);
}

View file

@ -0,0 +1,66 @@
/*
* Copyright (c) 1994, 2003, 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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.
*/
/*-
* Implementation of class Object
*
* former threadruntime.c, Sun Sep 22 12:09:39 1991
*/
#include <stdio.h>
#include <signal.h>
#include <limits.h>
#include "jni.h"
#include "jni_util.h"
#include "jvm.h"
#include "java_lang_Object.h"
static JNINativeMethod methods[] = {
{"hashCode", "()I", (void *)&JVM_IHashCode},
{"wait", "(J)V", (void *)&JVM_MonitorWait},
{"notify", "()V", (void *)&JVM_MonitorNotify},
{"notifyAll", "()V", (void *)&JVM_MonitorNotifyAll},
{"clone", "()Ljava/lang/Object;", (void *)&JVM_Clone},
};
JNIEXPORT void JNICALL
Java_java_lang_Object_registerNatives(JNIEnv *env, jclass cls)
{
(*env)->RegisterNatives(env, cls,
methods, sizeof(methods)/sizeof(methods[0]));
}
JNIEXPORT jclass JNICALL
Java_java_lang_Object_getClass(JNIEnv *env, jobject this)
{
if (this == NULL) {
JNU_ThrowNullPointerException(env, NULL);
return 0;
} else {
return (*env)->GetObjectClass(env, this);
}
}

View file

@ -0,0 +1,175 @@
/*
* Copyright (c) 1996, 2011, 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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.
*/
#include "jni.h"
#include "jvm.h"
#include "jni_util.h"
#include "jlong.h"
#include "java_lang_Float.h"
#include "java_lang_Double.h"
#include "java_io_ObjectInputStream.h"
/*
* Class: java_io_ObjectInputStream
* Method: bytesToFloats
* Signature: ([BI[FII)V
*
* Reconstitutes nfloats float values from their byte representations. Byte
* values are read from array src starting at offset srcpos; the resulting
* float values are written to array dst starting at dstpos.
*/
JNIEXPORT void JNICALL
Java_java_io_ObjectInputStream_bytesToFloats(JNIEnv *env,
jclass this,
jbyteArray src,
jint srcpos,
jfloatArray dst,
jint dstpos,
jint nfloats)
{
union {
int i;
float f;
} u;
jfloat *floats;
jbyte *bytes;
jsize dstend;
jint ival;
if (nfloats == 0)
return;
/* fetch source array */
if (src == NULL) {
JNU_ThrowNullPointerException(env, NULL);
return;
}
bytes = (*env)->GetPrimitiveArrayCritical(env, src, NULL);
if (bytes == NULL) /* exception thrown */
return;
/* fetch dest array */
if (dst == NULL) {
(*env)->ReleasePrimitiveArrayCritical(env, src, bytes, JNI_ABORT);
JNU_ThrowNullPointerException(env, NULL);
return;
}
floats = (*env)->GetPrimitiveArrayCritical(env, dst, NULL);
if (floats == NULL) { /* exception thrown */
(*env)->ReleasePrimitiveArrayCritical(env, src, bytes, JNI_ABORT);
return;
}
/* do conversion */
dstend = dstpos + nfloats;
for ( ; dstpos < dstend; dstpos++) {
ival = ((bytes[srcpos + 0] & 0xFF) << 24) +
((bytes[srcpos + 1] & 0xFF) << 16) +
((bytes[srcpos + 2] & 0xFF) << 8) +
((bytes[srcpos + 3] & 0xFF) << 0);
u.i = (long) ival;
floats[dstpos] = (jfloat) u.f;
srcpos += 4;
}
(*env)->ReleasePrimitiveArrayCritical(env, src, bytes, JNI_ABORT);
(*env)->ReleasePrimitiveArrayCritical(env, dst, floats, 0);
}
/*
* Class: java_io_ObjectInputStream
* Method: bytesToDoubles
* Signature: ([BI[DII)V
*
* Reconstitutes ndoubles double values from their byte representations.
* Byte values are read from array src starting at offset srcpos; the
* resulting double values are written to array dst starting at dstpos.
*/
JNIEXPORT void JNICALL
Java_java_io_ObjectInputStream_bytesToDoubles(JNIEnv *env,
jclass this,
jbyteArray src,
jint srcpos,
jdoubleArray dst,
jint dstpos,
jint ndoubles)
{
union {
jlong l;
double d;
} u;
jdouble *doubles;
jbyte *bytes;
jsize dstend;
jlong lval;
if (ndoubles == 0)
return;
/* fetch source array */
if (src == NULL) {
JNU_ThrowNullPointerException(env, NULL);
return;
}
bytes = (*env)->GetPrimitiveArrayCritical(env, src, NULL);
if (bytes == NULL) /* exception thrown */
return;
/* fetch dest array */
if (dst == NULL) {
(*env)->ReleasePrimitiveArrayCritical(env, src, bytes, JNI_ABORT);
JNU_ThrowNullPointerException(env, NULL);
return;
}
doubles = (*env)->GetPrimitiveArrayCritical(env, dst, NULL);
if (doubles == NULL) { /* exception thrown */
(*env)->ReleasePrimitiveArrayCritical(env, src, bytes, JNI_ABORT);
return;
}
/* do conversion */
dstend = dstpos + ndoubles;
for ( ; dstpos < dstend; dstpos++) {
lval = (((jlong) bytes[srcpos + 0] & 0xFF) << 56) +
(((jlong) bytes[srcpos + 1] & 0xFF) << 48) +
(((jlong) bytes[srcpos + 2] & 0xFF) << 40) +
(((jlong) bytes[srcpos + 3] & 0xFF) << 32) +
(((jlong) bytes[srcpos + 4] & 0xFF) << 24) +
(((jlong) bytes[srcpos + 5] & 0xFF) << 16) +
(((jlong) bytes[srcpos + 6] & 0xFF) << 8) +
(((jlong) bytes[srcpos + 7] & 0xFF) << 0);
jlong_to_jdouble_bits(&lval);
u.l = lval;
doubles[dstpos] = (jdouble) u.d;
srcpos += 8;
}
(*env)->ReleasePrimitiveArrayCritical(env, src, bytes, JNI_ABORT);
(*env)->ReleasePrimitiveArrayCritical(env, dst, doubles, 0);
}

View file

@ -0,0 +1,181 @@
/*
* Copyright (c) 1999, 2013, 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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.
*/
#include "jni_util.h"
#include "jdk_util.h"
#include "java_lang_Float.h"
#include "java_lang_Double.h"
#include "java_io_ObjectOutputStream.h"
/*
* Class: java_io_ObjectOutputStream
* Method: floatsToBytes
* Signature: ([FI[BII)V
*
* Convert nfloats float values to their byte representations. Float values
* are read from array src starting at offset srcpos and written to array
* dst starting at offset dstpos.
*/
JNIEXPORT void JNICALL
Java_java_io_ObjectOutputStream_floatsToBytes(JNIEnv *env,
jclass this,
jfloatArray src,
jint srcpos,
jbyteArray dst,
jint dstpos,
jint nfloats)
{
union {
int i;
float f;
} u;
jfloat *floats;
jbyte *bytes;
jsize srcend;
jint ival;
float fval;
if (nfloats == 0)
return;
/* fetch source array */
if (src == NULL) {
JNU_ThrowNullPointerException(env, NULL);
return;
}
floats = (*env)->GetPrimitiveArrayCritical(env, src, NULL);
if (floats == NULL) /* exception thrown */
return;
/* fetch dest array */
if (dst == NULL) {
(*env)->ReleasePrimitiveArrayCritical(env, src, floats, JNI_ABORT);
JNU_ThrowNullPointerException(env, NULL);
return;
}
bytes = (*env)->GetPrimitiveArrayCritical(env, dst, NULL);
if (bytes == NULL) { /* exception thrown */
(*env)->ReleasePrimitiveArrayCritical(env, src, floats, JNI_ABORT);
return;
}
/* do conversion */
srcend = srcpos + nfloats;
for ( ; srcpos < srcend; srcpos++) {
fval = (float) floats[srcpos];
if (ISNANF(fval)) { /* collapse NaNs */
ival = 0x7fc00000;
} else {
u.f = fval;
ival = (jint) u.i;
}
bytes[dstpos++] = (ival >> 24) & 0xFF;
bytes[dstpos++] = (ival >> 16) & 0xFF;
bytes[dstpos++] = (ival >> 8) & 0xFF;
bytes[dstpos++] = (ival >> 0) & 0xFF;
}
(*env)->ReleasePrimitiveArrayCritical(env, src, floats, JNI_ABORT);
(*env)->ReleasePrimitiveArrayCritical(env, dst, bytes, 0);
}
/*
* Class: java_io_ObjectOutputStream
* Method: doublesToBytes
* Signature: ([DI[BII)V
*
* Convert ndoubles double values to their byte representations. Double
* values are read from array src starting at offset srcpos and written to
* array dst starting at offset dstpos.
*/
JNIEXPORT void JNICALL
Java_java_io_ObjectOutputStream_doublesToBytes(JNIEnv *env,
jclass this,
jdoubleArray src,
jint srcpos,
jbyteArray dst,
jint dstpos,
jint ndoubles)
{
union {
jlong l;
double d;
} u;
jdouble *doubles;
jbyte *bytes;
jsize srcend;
jdouble dval;
jlong lval;
if (ndoubles == 0)
return;
/* fetch source array */
if (src == NULL) {
JNU_ThrowNullPointerException(env, NULL);
return;
}
doubles = (*env)->GetPrimitiveArrayCritical(env, src, NULL);
if (doubles == NULL) /* exception thrown */
return;
/* fetch dest array */
if (dst == NULL) {
(*env)->ReleasePrimitiveArrayCritical(env, src, doubles, JNI_ABORT);
JNU_ThrowNullPointerException(env, NULL);
return;
}
bytes = (*env)->GetPrimitiveArrayCritical(env, dst, NULL);
if (bytes == NULL) { /* exception thrown */
(*env)->ReleasePrimitiveArrayCritical(env, src, doubles, JNI_ABORT);
return;
}
/* do conversion */
srcend = srcpos + ndoubles;
for ( ; srcpos < srcend; srcpos++) {
dval = doubles[srcpos];
if (ISNAND((double) dval)) { /* collapse NaNs */
lval = jint_to_jlong(0x7ff80000);
lval = jlong_shl(lval, 32);
} else {
jdouble_to_jlong_bits(&dval);
u.d = (double) dval;
lval = u.l;
}
bytes[dstpos++] = (lval >> 56) & 0xFF;
bytes[dstpos++] = (lval >> 48) & 0xFF;
bytes[dstpos++] = (lval >> 40) & 0xFF;
bytes[dstpos++] = (lval >> 32) & 0xFF;
bytes[dstpos++] = (lval >> 24) & 0xFF;
bytes[dstpos++] = (lval >> 16) & 0xFF;
bytes[dstpos++] = (lval >> 8) & 0xFF;
bytes[dstpos++] = (lval >> 0) & 0xFF;
}
(*env)->ReleasePrimitiveArrayCritical(env, src, doubles, JNI_ABORT);
(*env)->ReleasePrimitiveArrayCritical(env, dst, bytes, 0);
}

View file

@ -0,0 +1,98 @@
/*
* Copyright (c) 2001, 2003, 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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.
*/
#include "jni.h"
#include "jvm.h"
#include "java_io_ObjectStreamClass.h"
static jclass noSuchMethodErrCl;
/*
* Class: java_io_ObjectStreamClass
* Method: initNative
* Signature: ()V
*
* Native code initialization hook.
*/
JNIEXPORT void JNICALL
Java_java_io_ObjectStreamClass_initNative(JNIEnv *env, jclass this)
{
jclass cl = (*env)->FindClass(env, "java/lang/NoSuchMethodError");
if (cl == NULL) { /* exception thrown */
return;
}
noSuchMethodErrCl = (*env)->NewGlobalRef(env, cl);
}
/*
* Class: java_io_ObjectStreamClass
* Method: hasStaticInitializer
* Signature: (Ljava/lang/Class;)Z
*
* Returns true if the given class defines a <clinit>()V method; returns false
* otherwise.
*/
JNIEXPORT jboolean JNICALL
Java_java_io_ObjectStreamClass_hasStaticInitializer(JNIEnv *env, jclass this,
jclass clazz)
{
jclass superCl = NULL;
jmethodID superClinitId = NULL;
jmethodID clinitId =
(*env)->GetStaticMethodID(env, clazz, "<clinit>", "()V");
if (clinitId == NULL) { /* error thrown */
jthrowable th = (*env)->ExceptionOccurred(env);
(*env)->ExceptionClear(env); /* normal return */
if (!(*env)->IsInstanceOf(env, th, noSuchMethodErrCl)) {
(*env)->Throw(env, th);
}
return JNI_FALSE;
}
/*
* Check superclass for static initializer as well--if the same method ID
* is returned, then the static initializer is from a superclass.
* Empirically, this step appears to be unnecessary in 1.4; however, the
* JNI spec makes no guarantee that GetStaticMethodID will not return the
* ID for a superclass initializer.
*/
if ((superCl = (*env)->GetSuperclass(env, clazz)) == NULL) {
return JNI_TRUE;
}
superClinitId =
(*env)->GetStaticMethodID(env, superCl, "<clinit>", "()V");
if (superClinitId == NULL) { /* error thrown */
jthrowable th = (*env)->ExceptionOccurred(env);
(*env)->ExceptionClear(env); /* normal return */
if (!(*env)->IsInstanceOf(env, th, noSuchMethodErrCl)) {
(*env)->Throw(env, th);
}
return JNI_TRUE;
}
return (clinitId != superClinitId);
}

View file

@ -0,0 +1,166 @@
/*
* Copyright (c) 1997, 2015, 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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.
*/
#include "jni.h"
#include "jni_util.h"
#include "jlong.h"
#include "jvm.h"
#include "io_util.h"
#include "io_util_md.h"
#include "java_io_RandomAccessFile.h"
#include <fcntl.h>
/*
* static method to store field ID's in initializers
*/
jfieldID raf_fd; /* id for jobject 'fd' in java.io.RandomAccessFile */
JNIEXPORT void JNICALL
Java_java_io_RandomAccessFile_initIDs(JNIEnv *env, jclass fdClass) {
raf_fd = (*env)->GetFieldID(env, fdClass, "fd", "Ljava/io/FileDescriptor;");
}
JNIEXPORT void JNICALL
Java_java_io_RandomAccessFile_open0(JNIEnv *env,
jobject this, jstring path, jint mode)
{
int flags = 0;
if (mode & java_io_RandomAccessFile_O_RDONLY)
flags = O_RDONLY;
else if (mode & java_io_RandomAccessFile_O_RDWR) {
flags = O_RDWR | O_CREAT;
if (mode & java_io_RandomAccessFile_O_SYNC)
flags |= O_SYNC;
else if (mode & java_io_RandomAccessFile_O_DSYNC)
flags |= O_DSYNC;
}
#ifdef WIN32
if (mode & java_io_RandomAccessFile_O_TEMPORARY)
flags |= O_TEMPORARY;
#endif
fileOpen(env, this, path, raf_fd, flags);
}
JNIEXPORT jint JNICALL
Java_java_io_RandomAccessFile_read0(JNIEnv *env, jobject this) {
return readSingle(env, this, raf_fd);
}
JNIEXPORT jint JNICALL
Java_java_io_RandomAccessFile_readBytes(JNIEnv *env,
jobject this, jbyteArray bytes, jint off, jint len) {
return readBytes(env, this, bytes, off, len, raf_fd);
}
JNIEXPORT void JNICALL
Java_java_io_RandomAccessFile_write0(JNIEnv *env, jobject this, jint byte) {
writeSingle(env, this, byte, JNI_FALSE, raf_fd);
}
JNIEXPORT void JNICALL
Java_java_io_RandomAccessFile_writeBytes(JNIEnv *env,
jobject this, jbyteArray bytes, jint off, jint len) {
writeBytes(env, this, bytes, off, len, JNI_FALSE, raf_fd);
}
JNIEXPORT jlong JNICALL
Java_java_io_RandomAccessFile_getFilePointer(JNIEnv *env, jobject this) {
FD fd;
jlong ret;
fd = GET_FD(this, raf_fd);
if (fd == -1) {
JNU_ThrowIOException(env, "Stream Closed");
return -1;
}
if ((ret = IO_Lseek(fd, 0L, SEEK_CUR)) == -1) {
JNU_ThrowIOExceptionWithLastError(env, "Seek failed");
}
return ret;
}
JNIEXPORT jlong JNICALL
Java_java_io_RandomAccessFile_length(JNIEnv *env, jobject this) {
FD fd;
jlong length = jlong_zero;
fd = GET_FD(this, raf_fd);
if (fd == -1) {
JNU_ThrowIOException(env, "Stream Closed");
return -1;
}
if ((length = IO_GetLength(fd)) == -1) {
JNU_ThrowIOExceptionWithLastError(env, "GetLength failed");
}
return length;
}
JNIEXPORT void JNICALL
Java_java_io_RandomAccessFile_seek0(JNIEnv *env,
jobject this, jlong pos) {
FD fd;
fd = GET_FD(this, raf_fd);
if (fd == -1) {
JNU_ThrowIOException(env, "Stream Closed");
return;
}
if (pos < jlong_zero) {
JNU_ThrowIOException(env, "Negative seek offset");
} else if (IO_Lseek(fd, pos, SEEK_SET) == -1) {
JNU_ThrowIOExceptionWithLastError(env, "Seek failed");
}
}
JNIEXPORT void JNICALL
Java_java_io_RandomAccessFile_setLength(JNIEnv *env, jobject this,
jlong newLength)
{
FD fd;
jlong cur;
fd = GET_FD(this, raf_fd);
if (fd == -1) {
JNU_ThrowIOException(env, "Stream Closed");
return;
}
if ((cur = IO_Lseek(fd, 0L, SEEK_CUR)) == -1) goto fail;
if (IO_SetLength(fd, newLength) == -1) goto fail;
if (cur > newLength) {
if (IO_Lseek(fd, 0L, SEEK_END) == -1) goto fail;
} else {
if (IO_Lseek(fd, cur, SEEK_SET) == -1) goto fail;
}
return;
fail:
JNU_ThrowIOExceptionWithLastError(env, "setLength failed");
}

View file

@ -0,0 +1,45 @@
/*
* Copyright (c) 2016, 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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.
*/
#include "jvm.h"
#include "java_lang_ref_Reference.h"
JNIEXPORT jobject JNICALL
Java_java_lang_ref_Reference_getAndClearReferencePendingList(JNIEnv *env, jclass ignore)
{
return JVM_GetAndClearReferencePendingList(env);
}
JNIEXPORT jboolean JNICALL
Java_java_lang_ref_Reference_hasReferencePendingList(JNIEnv *env, jclass ignore)
{
return JVM_HasReferencePendingList(env);
}
JNIEXPORT void JNICALL
Java_java_lang_ref_Reference_waitForReferencePendingList(JNIEnv *env, jclass ignore)
{
JVM_WaitForReferencePendingList(env);
}

View file

@ -0,0 +1,46 @@
/*
* Copyright (c) 2001, 2013, 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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.
*/
#include "jni.h"
#include "jvm.h"
#include "jdk_internal_reflect_Reflection.h"
JNIEXPORT jclass JNICALL
Java_jdk_internal_reflect_Reflection_getCallerClass__(JNIEnv *env, jclass unused)
{
return JVM_GetCallerClass(env, JVM_CALLER_DEPTH);
}
JNIEXPORT jclass JNICALL
Java_jdk_internal_reflect_Reflection_getCallerClass__I(JNIEnv *env, jclass unused, jint depth)
{
return JVM_GetCallerClass(env, depth);
}
JNIEXPORT jint JNICALL
Java_jdk_internal_reflect_Reflection_getClassAccessFlags(JNIEnv *env, jclass unused, jclass cls)
{
return JVM_GetClassAccessFlags(env, cls);
}

View file

@ -0,0 +1,85 @@
/*
* Copyright (c) 1994, 2014, 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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.
*/
/*
* Link foreign methods. This first half of this file contains the
* machine independent dynamic linking routines.
* See "BUILD_PLATFORM"/java/lang/linker_md.c to see
* the implementation of this shared dynamic linking
* interface.
*
* NOTE - source in this file is POSIX.1 compliant, host
* specific code lives in the platform specific
* code tree.
*/
#include "jni.h"
#include "jni_util.h"
#include "jvm.h"
#include "java_lang_Runtime.h"
JNIEXPORT jlong JNICALL
Java_java_lang_Runtime_freeMemory(JNIEnv *env, jobject this)
{
return JVM_FreeMemory();
}
JNIEXPORT jlong JNICALL
Java_java_lang_Runtime_totalMemory(JNIEnv *env, jobject this)
{
return JVM_TotalMemory();
}
JNIEXPORT jlong JNICALL
Java_java_lang_Runtime_maxMemory(JNIEnv *env, jobject this)
{
return JVM_MaxMemory();
}
JNIEXPORT void JNICALL
Java_java_lang_Runtime_gc(JNIEnv *env, jobject this)
{
JVM_GC();
}
JNIEXPORT void JNICALL
Java_java_lang_Runtime_runFinalization0(JNIEnv *env, jobject this)
{
jclass cl;
jmethodID mid;
if ((cl = (*env)->FindClass(env, "java/lang/ref/Finalizer"))
&& (mid = (*env)->GetStaticMethodID(env, cl,
"runFinalization", "()V"))) {
(*env)->CallStaticVoidMethod(env, cl, mid);
}
}
JNIEXPORT jint JNICALL
Java_java_lang_Runtime_availableProcessors(JNIEnv *env, jobject this)
{
return JVM_ActiveProcessorCount();
}

View file

@ -0,0 +1,128 @@
/*
* Copyright (c) 1995, 2013, 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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.
*/
#include "jni.h"
#include "jni_util.h"
#include "jvm.h"
#include "java_lang_SecurityManager.h"
#include "java_lang_ClassLoader.h"
/*
* Make sure a security manager instance is initialized.
* TRUE means OK, FALSE means not.
*/
static jboolean
check(JNIEnv *env, jobject this)
{
static jfieldID initField = 0;
jboolean initialized = JNI_FALSE;
if (initField == 0) {
jclass clazz = (*env)->FindClass(env, "java/lang/SecurityManager");
if (clazz == 0) {
(*env)->ExceptionClear(env);
return JNI_FALSE;
}
initField = (*env)->GetFieldID(env, clazz, "initialized", "Z");
if (initField == 0) {
(*env)->ExceptionClear(env);
return JNI_FALSE;
}
}
initialized = (*env)->GetBooleanField(env, this, initField);
if (initialized == JNI_TRUE) {
return JNI_TRUE;
} else {
jclass securityException =
(*env)->FindClass(env, "java/lang/SecurityException");
if (securityException != 0) {
(*env)->ThrowNew(env, securityException,
"security manager not initialized.");
}
return JNI_FALSE;
}
}
JNIEXPORT jobjectArray JNICALL
Java_java_lang_SecurityManager_getClassContext(JNIEnv *env, jobject this)
{
if (!check(env, this)) {
return NULL; /* exception */
}
return JVM_GetClassContext(env);
}
JNIEXPORT jclass JNICALL
Java_java_lang_SecurityManager_currentLoadedClass0(JNIEnv *env, jobject this)
{
/* Make sure the security manager instance is initialized */
if (!check(env, this)) {
return NULL; /* exception */
}
return JVM_CurrentLoadedClass(env);
}
JNIEXPORT jobject JNICALL
Java_java_lang_SecurityManager_currentClassLoader0(JNIEnv *env, jobject this)
{
/* Make sure the security manager instance is initialized */
if (!check(env, this)) {
return NULL; /* exception */
}
return JVM_CurrentClassLoader(env);
}
JNIEXPORT jint JNICALL
Java_java_lang_SecurityManager_classDepth(JNIEnv *env, jobject this,
jstring name)
{
/* Make sure the security manager instance is initialized */
if (!check(env, this)) {
return -1; /* exception */
}
if (name == NULL) {
JNU_ThrowNullPointerException(env, 0);
return -1;
}
return JVM_ClassDepth(env, name);
}
JNIEXPORT jint JNICALL
Java_java_lang_SecurityManager_classLoaderDepth0(JNIEnv *env, jobject this)
{
/* Make sure the security manager instance is initialized */
if (!check(env, this)) {
return -1; /* exception */
}
return JVM_ClassLoaderDepth(env);
}

View file

@ -0,0 +1,51 @@
/*
* Copyright (c) 1999, 2003, 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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.
*/
#include "jni.h"
#include "jni_util.h"
#include "jvm.h"
#include "java_lang_Shutdown.h"
JNIEXPORT void JNICALL
Java_java_lang_Shutdown_halt0(JNIEnv *env, jclass ignored, jint code)
{
JVM_Halt(code);
}
JNIEXPORT void JNICALL
Java_java_lang_Shutdown_runAllFinalizers(JNIEnv *env, jclass ignored)
{
jclass cl;
jmethodID mid;
if ((cl = (*env)->FindClass(env, "java/lang/ref/Finalizer"))
&& (mid = (*env)->GetStaticMethodID(env, cl,
"runAllFinalizers", "()V"))) {
(*env)->CallStaticVoidMethod(env, cl, mid);
}
}

View file

@ -0,0 +1,64 @@
/*
* Copyright (c) 1998, 2016, 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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.
*/
#include <signal.h>
#include <stdlib.h>
#include <jni.h>
#include <jvm.h>
#include <jni_util.h>
#include <jlong.h>
#include "jdk_internal_misc_Signal.h"
JNIEXPORT jint JNICALL
Java_jdk_internal_misc_Signal_findSignal0(JNIEnv *env, jclass cls, jstring name)
{
jint res;
const char *cname;
if (name == NULL) {
JNU_ThrowNullPointerException(env, "name");
return 0;
}
cname = (*env)->GetStringUTFChars(env, name, 0);
if (cname == NULL) {
/* out of memory thrown */
return 0;
}
res = JVM_FindSignal(cname);
(*env)->ReleaseStringUTFChars(env, name, cname);
return res;
}
JNIEXPORT jlong JNICALL
Java_jdk_internal_misc_Signal_handle0(JNIEnv *env, jclass cls, jint sig, jlong handler)
{
return ptr_to_jlong(JVM_RegisterSignal(sig, jlong_to_ptr(handler)));
}
JNIEXPORT void JNICALL
Java_jdk_internal_misc_Signal_raise0(JNIEnv *env, jclass cls, jint sig)
{
JVM_RaiseSignal(sig);
}

View file

@ -0,0 +1,77 @@
/*
* Copyright (c) 2015, 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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.
*/
/*
* Implementation of class StackStreamfactory and AbstractStackWalker
*/
#include <stdio.h>
#include <signal.h>
#include "jni.h"
#include "jvm.h"
#include "java_lang_StackStreamFactory.h"
#include "java_lang_StackStreamFactory_AbstractStackWalker.h"
/*
* Class: java_lang_StackStreamFactory
* Method: checkStackWalkModes
* Signature: ()
*/
JNIEXPORT jboolean JNICALL Java_java_lang_StackStreamFactory_checkStackWalkModes
(JNIEnv *env, jclass dummy)
{
return JVM_STACKWALK_FILL_CLASS_REFS_ONLY == java_lang_StackStreamFactory_FILL_CLASS_REFS_ONLY &&
JVM_STACKWALK_SHOW_HIDDEN_FRAMES == java_lang_StackStreamFactory_SHOW_HIDDEN_FRAMES &&
JVM_STACKWALK_FILL_LIVE_STACK_FRAMES == java_lang_StackStreamFactory_FILL_LIVE_STACK_FRAMES;
}
/*
* Class: java_lang_StackStreamFactory_AbstractStackWalker
* Method: callStackWalk
* Signature: (JIII[Ljava/lang/Object;)Ljava/lang/Object;
*/
JNIEXPORT jobject JNICALL Java_java_lang_StackStreamFactory_00024AbstractStackWalker_callStackWalk
(JNIEnv *env, jobject stackstream, jlong mode, jint skipFrames, jint batchSize, jint startIndex,
jobjectArray frames)
{
return JVM_CallStackWalk(env, stackstream, mode, skipFrames, batchSize,
startIndex, frames);
}
/*
* Class: java_lang_StackStreamFactory_AbstractStackWalker
* Method: fetchStackFrames
* Signature: (JJII[Ljava/lang/Object;)I
*/
JNIEXPORT jint JNICALL Java_java_lang_StackStreamFactory_00024AbstractStackWalker_fetchStackFrames
(JNIEnv *env, jobject stackstream, jlong mode, jlong anchor,
jint batchSize, jint startIndex,
jobjectArray frames)
{
return JVM_MoreStackWalk(env, stackstream, mode, anchor, batchSize,
startIndex, frames);
}

View file

@ -0,0 +1,43 @@
/*
* Copyright (c) 2016, 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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.
*/
#include <stdio.h>
#include <signal.h>
#include "jni.h"
#include "jvm.h"
#include "java_lang_StackTraceElement.h"
JNIEXPORT void JNICALL Java_java_lang_StackTraceElement_initStackTraceElement
(JNIEnv *env, jobject dummy, jobject element, jobject stackframeinfo) {
JVM_InitStackTraceElement(env, element, stackframeinfo);
}
JNIEXPORT void JNICALL Java_java_lang_StackTraceElement_initStackTraceElements
(JNIEnv *env, jobject dummy, jobjectArray elements, jobject throwable)
{
JVM_InitStackTraceElementArray(env, elements, throwable);
}

View file

@ -0,0 +1,127 @@
/*
* Copyright (c) 1994, 2016, 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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.
*/
#include "jni.h"
#include "fdlibm.h"
#include "java_lang_StrictMath.h"
JNIEXPORT jdouble JNICALL
Java_java_lang_StrictMath_cos(JNIEnv *env, jclass unused, jdouble d)
{
return (jdouble) jcos((double)d);
}
JNIEXPORT jdouble JNICALL
Java_java_lang_StrictMath_sin(JNIEnv *env, jclass unused, jdouble d)
{
return (jdouble) jsin((double)d);
}
JNIEXPORT jdouble JNICALL
Java_java_lang_StrictMath_tan(JNIEnv *env, jclass unused, jdouble d)
{
return (jdouble) jtan((double)d);
}
JNIEXPORT jdouble JNICALL
Java_java_lang_StrictMath_asin(JNIEnv *env, jclass unused, jdouble d)
{
return (jdouble) jasin((double)d);
}
JNIEXPORT jdouble JNICALL
Java_java_lang_StrictMath_acos(JNIEnv *env, jclass unused, jdouble d)
{
return (jdouble) jacos((double)d);
}
JNIEXPORT jdouble JNICALL
Java_java_lang_StrictMath_atan(JNIEnv *env, jclass unused, jdouble d)
{
return (jdouble) jatan((double)d);
}
JNIEXPORT jdouble JNICALL
Java_java_lang_StrictMath_log(JNIEnv *env, jclass unused, jdouble d)
{
return (jdouble) jlog((double)d);
}
JNIEXPORT jdouble JNICALL
Java_java_lang_StrictMath_log10(JNIEnv *env, jclass unused, jdouble d)
{
return (jdouble) jlog10((double)d);
}
JNIEXPORT jdouble JNICALL
Java_java_lang_StrictMath_sqrt(JNIEnv *env, jclass unused, jdouble d)
{
return (jdouble) jsqrt((double)d);
}
JNIEXPORT jdouble JNICALL
Java_java_lang_StrictMath_atan2(JNIEnv *env, jclass unused, jdouble d1, jdouble d2)
{
return (jdouble) jatan2((double)d1, (double)d2);
}
JNIEXPORT jdouble JNICALL
Java_java_lang_StrictMath_IEEEremainder(JNIEnv *env, jclass unused,
jdouble dividend,
jdouble divisor)
{
return (jdouble) jremainder(dividend, divisor);
}
JNIEXPORT jdouble JNICALL
Java_java_lang_StrictMath_cosh(JNIEnv *env, jclass unused, jdouble d)
{
return (jdouble) jcosh((double)d);
}
JNIEXPORT jdouble JNICALL
Java_java_lang_StrictMath_sinh(JNIEnv *env, jclass unused, jdouble d)
{
return (jdouble) jsinh((double)d);
}
JNIEXPORT jdouble JNICALL
Java_java_lang_StrictMath_tanh(JNIEnv *env, jclass unused, jdouble d)
{
return (jdouble) jtanh((double)d);
}
JNIEXPORT jdouble JNICALL
Java_java_lang_StrictMath_log1p(JNIEnv *env, jclass unused, jdouble d)
{
return (jdouble) jlog1p((double)d);
}
JNIEXPORT jdouble JNICALL
Java_java_lang_StrictMath_expm1(JNIEnv *env, jclass unused, jdouble d)
{
return (jdouble) jexpm1((double)d);
}

View file

@ -0,0 +1,44 @@
/*
* Copyright (c) 1997, 1998, 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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.
*/
#include "jvm.h"
#include "java_lang_String.h"
JNIEXPORT jobject JNICALL
Java_java_lang_String_intern(JNIEnv *env, jobject this)
{
return JVM_InternString(env, this);
}
JNIEXPORT jboolean JNICALL
Java_java_lang_StringUTF16_isBigEndian(JNIEnv *env, jclass cls)
{
unsigned int endianTest = 0xff000000;
if (((char*)(&endianTest))[0] != 0) {
return JNI_TRUE;
} else {
return JNI_FALSE;
}
}

View file

@ -0,0 +1,75 @@
/*
* Copyright (c) 1998, 2014, 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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.
*/
#include <stdlib.h>
#include <jni.h>
#include <jni_util.h>
#include <stdio.h>
#include <jvm.h>
#include "java_lang_StringCoding.h"
static void
printToFile(JNIEnv *env, jstring s, FILE *file)
{
char *sConverted;
int length = 0;
int i;
const jchar *sAsArray;
if (s == NULL) {
JNU_ThrowNullPointerException(env, NULL);
return;
}
sAsArray = (*env)->GetStringChars(env, s, NULL);
if (!sAsArray)
return;
length = (*env)->GetStringLength(env, s);
if (length == 0) {
(*env)->ReleaseStringChars(env, s, sAsArray);
return;
}
sConverted = (char *) malloc(length + 1);
if (!sConverted) {
(*env)->ReleaseStringChars(env, s, sAsArray);
JNU_ThrowOutOfMemoryError(env, NULL);
return;
}
for(i = 0; i < length; i++) {
sConverted[i] = (0x7f & sAsArray[i]);
}
sConverted[length] = '\0';
jio_fprintf(file, "%s", sConverted);
(*env)->ReleaseStringChars(env, s, sAsArray);
free(sConverted);
}
JNIEXPORT void JNICALL
Java_java_lang_StringCoding_err(JNIEnv *env, jclass cls, jstring s)
{
printToFile(env, s, stderr);
}

View file

@ -0,0 +1,509 @@
/*
* Copyright (c) 1994, 2016, 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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.
*/
#include <string.h>
#include "jni.h"
#include "jni_util.h"
#include "jvm.h"
#include "java_props.h"
#include "java_lang_System.h"
#define OBJ "Ljava/lang/Object;"
/* Only register the performance-critical methods */
static JNINativeMethod methods[] = {
{"currentTimeMillis", "()J", (void *)&JVM_CurrentTimeMillis},
{"nanoTime", "()J", (void *)&JVM_NanoTime},
{"arraycopy", "(" OBJ "I" OBJ "II)V", (void *)&JVM_ArrayCopy},
};
#undef OBJ
JNIEXPORT void JNICALL
Java_java_lang_System_registerNatives(JNIEnv *env, jclass cls)
{
(*env)->RegisterNatives(env, cls,
methods, sizeof(methods)/sizeof(methods[0]));
}
JNIEXPORT jint JNICALL
Java_java_lang_System_identityHashCode(JNIEnv *env, jobject this, jobject x)
{
return JVM_IHashCode(env, x);
}
#define PUTPROP(props, key, val) \
if (1) { \
jstring jkey, jval; \
jobject r; \
jkey = (*env)->NewStringUTF(env, key); \
if (jkey == NULL) return NULL; \
jval = (*env)->NewStringUTF(env, val); \
if (jval == NULL) return NULL; \
r = (*env)->CallObjectMethod(env, props, putID, jkey, jval); \
if ((*env)->ExceptionOccurred(env)) return NULL; \
(*env)->DeleteLocalRef(env, jkey); \
(*env)->DeleteLocalRef(env, jval); \
(*env)->DeleteLocalRef(env, r); \
} else ((void) 0)
/* "key" is a char type string with only ASCII character in it.
"val" is a nchar (typedefed in java_props.h) type string */
#define PUTPROP_ForPlatformNString(props, key, val) \
if (1) { \
jstring jkey, jval; \
jobject r; \
jkey = (*env)->NewStringUTF(env, key); \
if (jkey == NULL) return NULL; \
jval = GetStringPlatform(env, val); \
if (jval == NULL) return NULL; \
r = (*env)->CallObjectMethod(env, props, putID, jkey, jval); \
if ((*env)->ExceptionOccurred(env)) return NULL; \
(*env)->DeleteLocalRef(env, jkey); \
(*env)->DeleteLocalRef(env, jval); \
(*env)->DeleteLocalRef(env, r); \
} else ((void) 0)
#define REMOVEPROP(props, key) \
if (1) { \
jstring jkey; \
jobject r; \
jkey = JNU_NewStringPlatform(env, key); \
if (jkey == NULL) return NULL; \
r = (*env)->CallObjectMethod(env, props, removeID, jkey); \
if ((*env)->ExceptionOccurred(env)) return NULL; \
(*env)->DeleteLocalRef(env, jkey); \
(*env)->DeleteLocalRef(env, r); \
} else ((void) 0)
#define GETPROP(props, key, jret) \
if (1) { \
jstring jkey = JNU_NewStringPlatform(env, key); \
if (jkey == NULL) return NULL; \
jret = (*env)->CallObjectMethod(env, props, getPropID, jkey); \
if ((*env)->ExceptionOccurred(env)) return NULL; \
(*env)->DeleteLocalRef(env, jkey); \
} else ((void) 0)
#ifndef VENDOR /* Third party may overwrite this. */
#define VENDOR "Oracle Corporation"
#define VENDOR_URL "http://java.oracle.com/"
#define VENDOR_URL_BUG "http://bugreport.java.com/bugreport/"
#endif
#define JAVA_MAX_SUPPORTED_VERSION 53
#define JAVA_MAX_SUPPORTED_MINOR_VERSION 0
#ifdef JAVA_SPECIFICATION_VENDOR /* Third party may NOT overwrite this. */
#error "ERROR: No override of JAVA_SPECIFICATION_VENDOR is allowed"
#else
#define JAVA_SPECIFICATION_VENDOR "Oracle Corporation"
#endif
static int fmtdefault; // boolean value
jobject fillI18nProps(JNIEnv *env, jobject props, char *baseKey,
char *platformDispVal, char *platformFmtVal,
jmethodID putID, jmethodID getPropID) {
jstring jVMBaseVal = NULL;
GETPROP(props, baseKey, jVMBaseVal);
if (jVMBaseVal) {
// user specified the base property. there's nothing to do here.
(*env)->DeleteLocalRef(env, jVMBaseVal);
} else {
char buf[64];
jstring jVMVal = NULL;
const char *baseVal = "";
/* user.xxx base property */
if (fmtdefault) {
if (platformFmtVal) {
PUTPROP(props, baseKey, platformFmtVal);
baseVal = platformFmtVal;
}
} else {
if (platformDispVal) {
PUTPROP(props, baseKey, platformDispVal);
baseVal = platformDispVal;
}
}
/* user.xxx.display property */
jio_snprintf(buf, sizeof(buf), "%s.display", baseKey);
GETPROP(props, buf, jVMVal);
if (jVMVal == NULL) {
if (platformDispVal && (strcmp(baseVal, platformDispVal) != 0)) {
PUTPROP(props, buf, platformDispVal);
}
} else {
(*env)->DeleteLocalRef(env, jVMVal);
}
/* user.xxx.format property */
jio_snprintf(buf, sizeof(buf), "%s.format", baseKey);
GETPROP(props, buf, jVMVal);
if (jVMVal == NULL) {
if (platformFmtVal && (strcmp(baseVal, platformFmtVal) != 0)) {
PUTPROP(props, buf, platformFmtVal);
}
} else {
(*env)->DeleteLocalRef(env, jVMVal);
}
}
return NULL;
}
JNIEXPORT jobject JNICALL
Java_java_lang_System_initProperties(JNIEnv *env, jclass cla, jobject props)
{
char buf[128];
java_props_t *sprops;
jmethodID putID, removeID, getPropID;
jobject ret = NULL;
jstring jVMVal = NULL;
sprops = GetJavaProperties(env);
CHECK_NULL_RETURN(sprops, NULL);
putID = (*env)->GetMethodID(env,
(*env)->GetObjectClass(env, props),
"put",
"(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
CHECK_NULL_RETURN(putID, NULL);
removeID = (*env)->GetMethodID(env,
(*env)->GetObjectClass(env, props),
"remove",
"(Ljava/lang/Object;)Ljava/lang/Object;");
CHECK_NULL_RETURN(removeID, NULL);
getPropID = (*env)->GetMethodID(env,
(*env)->GetObjectClass(env, props),
"getProperty",
"(Ljava/lang/String;)Ljava/lang/String;");
CHECK_NULL_RETURN(getPropID, NULL);
PUTPROP(props, "java.specification.version",
VERSION_SPECIFICATION);
PUTPROP(props, "java.specification.name",
"Java Platform API Specification");
PUTPROP(props, "java.specification.vendor",
JAVA_SPECIFICATION_VENDOR);
PUTPROP(props, "java.version", VERSION_SHORT);
PUTPROP(props, "java.vendor", VENDOR);
PUTPROP(props, "java.vendor.url", VENDOR_URL);
PUTPROP(props, "java.vendor.url.bug", VENDOR_URL_BUG);
jio_snprintf(buf, sizeof(buf), "%d.%d", JAVA_MAX_SUPPORTED_VERSION,
JAVA_MAX_SUPPORTED_MINOR_VERSION);
PUTPROP(props, "java.class.version", buf);
if (sprops->awt_toolkit) {
PUTPROP(props, "awt.toolkit", sprops->awt_toolkit);
}
#ifdef MACOSX
if (sprops->awt_headless) {
PUTPROP(props, "java.awt.headless", sprops->awt_headless);
}
#endif
/* os properties */
PUTPROP(props, "os.name", sprops->os_name);
PUTPROP(props, "os.version", sprops->os_version);
PUTPROP(props, "os.arch", sprops->os_arch);
#ifdef JDK_ARCH_ABI_PROP_NAME
PUTPROP(props, "sun.arch.abi", sprops->sun_arch_abi);
#endif
/* file system properties */
PUTPROP(props, "file.separator", sprops->file_separator);
PUTPROP(props, "path.separator", sprops->path_separator);
PUTPROP(props, "line.separator", sprops->line_separator);
/*
* user.language
* user.script, user.country, user.variant (if user's environment specifies them)
* file.encoding
* file.encoding.pkg
*/
PUTPROP(props, "user.language", sprops->language);
if (sprops->script) {
PUTPROP(props, "user.script", sprops->script);
}
if (sprops->country) {
PUTPROP(props, "user.country", sprops->country);
}
if (sprops->variant) {
PUTPROP(props, "user.variant", sprops->variant);
}
PUTPROP(props, "file.encoding", sprops->encoding);
PUTPROP(props, "sun.jnu.encoding", sprops->sun_jnu_encoding);
if (sprops->sun_stdout_encoding != NULL) {
PUTPROP(props, "sun.stdout.encoding", sprops->sun_stdout_encoding);
}
if (sprops->sun_stderr_encoding != NULL) {
PUTPROP(props, "sun.stderr.encoding", sprops->sun_stderr_encoding);
}
PUTPROP(props, "file.encoding.pkg", "sun.io");
/* unicode_encoding specifies the default endianness */
PUTPROP(props, "sun.io.unicode.encoding", sprops->unicode_encoding);
PUTPROP(props, "sun.cpu.isalist",
(sprops->cpu_isalist ? sprops->cpu_isalist : ""));
PUTPROP(props, "sun.cpu.endian", sprops->cpu_endian);
#ifdef MACOSX
/* Proxy setting properties */
if (sprops->httpProxyEnabled) {
PUTPROP(props, "http.proxyHost", sprops->httpHost);
PUTPROP(props, "http.proxyPort", sprops->httpPort);
}
if (sprops->httpsProxyEnabled) {
PUTPROP(props, "https.proxyHost", sprops->httpsHost);
PUTPROP(props, "https.proxyPort", sprops->httpsPort);
}
if (sprops->ftpProxyEnabled) {
PUTPROP(props, "ftp.proxyHost", sprops->ftpHost);
PUTPROP(props, "ftp.proxyPort", sprops->ftpPort);
}
if (sprops->socksProxyEnabled) {
PUTPROP(props, "socksProxyHost", sprops->socksHost);
PUTPROP(props, "socksProxyPort", sprops->socksPort);
}
if (sprops->gopherProxyEnabled) {
// The gopher client is different in that it expects an 'is this set?' flag that the others don't.
PUTPROP(props, "gopherProxySet", "true");
PUTPROP(props, "gopherProxyHost", sprops->gopherHost);
PUTPROP(props, "gopherProxyPort", sprops->gopherPort);
} else {
PUTPROP(props, "gopherProxySet", "false");
}
// Mac OS X only has a single proxy exception list which applies
// to all protocols
if (sprops->exceptionList) {
PUTPROP(props, "http.nonProxyHosts", sprops->exceptionList);
PUTPROP(props, "ftp.nonProxyHosts", sprops->exceptionList);
PUTPROP(props, "socksNonProxyHosts", sprops->exceptionList);
}
#endif
/* !!! DO NOT call PUTPROP_ForPlatformNString before this line !!!
* !!! I18n properties have not been set up yet !!!
*/
/* Printing properties */
/* Note: java.awt.printerjob is an implementation private property which
* just happens to have a java.* name because it is referenced in
* a java.awt class. It is the mechanism by which the implementation
* finds the appropriate class in the JRE for the platform.
* It is explicitly not designed to be overridden by clients as
* a way of replacing the implementation class, and in any case
* the mechanism by which the class is loaded is constrained to only
* find and load classes that are part of the JRE.
* This property may be removed if that mechanism is redesigned
*/
PUTPROP(props, "java.awt.printerjob", sprops->printerJob);
/* data model */
if (sizeof(sprops) == 4) {
sprops->data_model = "32";
} else if (sizeof(sprops) == 8) {
sprops->data_model = "64";
} else {
sprops->data_model = "unknown";
}
PUTPROP(props, "sun.arch.data.model", \
sprops->data_model);
/* patch level */
PUTPROP(props, "sun.os.patch.level", \
sprops->patch_level);
/* Java2D properties */
/* Note: java.awt.graphicsenv is an implementation private property which
* just happens to have a java.* name because it is referenced in
* a java.awt class. It is the mechanism by which the implementation
* finds the appropriate class in the JRE for the platform.
* It is explicitly not designed to be overridden by clients as
* a way of replacing the implementation class, and in any case
* the mechanism by which the class is loaded is constrained to only
* find and load classes that are part of the JRE.
* This property may be removed if that mechanism is redesigned
*/
PUTPROP(props, "java.awt.graphicsenv", sprops->graphics_env);
if (sprops->font_dir != NULL) {
PUTPROP_ForPlatformNString(props,
"sun.java2d.fontpath", sprops->font_dir);
}
PUTPROP_ForPlatformNString(props, "java.io.tmpdir", sprops->tmp_dir);
PUTPROP_ForPlatformNString(props, "user.name", sprops->user_name);
PUTPROP_ForPlatformNString(props, "user.home", sprops->user_home);
PUTPROP(props, "user.timezone", sprops->timezone);
PUTPROP_ForPlatformNString(props, "user.dir", sprops->user_dir);
/* This is a sun. property as it is currently only set for Gnome and
* Windows desktops.
*/
if (sprops->desktop != NULL) {
PUTPROP(props, "sun.desktop", sprops->desktop);
}
/*
* unset "user.language", "user.script", "user.country", and "user.variant"
* in order to tell whether the command line option "-DXXXX=YYYY" is
* specified or not. They will be reset in fillI18nProps() below.
*/
REMOVEPROP(props, "user.language");
REMOVEPROP(props, "user.script");
REMOVEPROP(props, "user.country");
REMOVEPROP(props, "user.variant");
REMOVEPROP(props, "file.encoding");
ret = JVM_InitProperties(env, props);
/* Check the compatibility flag */
GETPROP(props, "sun.locale.formatasdefault", jVMVal);
if (jVMVal) {
const char * val = (*env)->GetStringUTFChars(env, jVMVal, 0);
CHECK_NULL_RETURN(val, NULL);
fmtdefault = !strcmp(val, "true");
(*env)->ReleaseStringUTFChars(env, jVMVal, val);
(*env)->DeleteLocalRef(env, jVMVal);
}
/* reconstruct i18n related properties */
fillI18nProps(env, props, "user.language", sprops->display_language,
sprops->format_language, putID, getPropID);
fillI18nProps(env, props, "user.script",
sprops->display_script, sprops->format_script, putID, getPropID);
fillI18nProps(env, props, "user.country",
sprops->display_country, sprops->format_country, putID, getPropID);
fillI18nProps(env, props, "user.variant",
sprops->display_variant, sprops->format_variant, putID, getPropID);
GETPROP(props, "file.encoding", jVMVal);
if (jVMVal == NULL) {
#ifdef MACOSX
/*
* Since sun_jnu_encoding is now hard-coded to UTF-8 on Mac, we don't
* want to use it to overwrite file.encoding
*/
PUTPROP(props, "file.encoding", sprops->encoding);
#else
if (fmtdefault) {
PUTPROP(props, "file.encoding", sprops->encoding);
} else {
PUTPROP(props, "file.encoding", sprops->sun_jnu_encoding);
}
#endif
} else {
(*env)->DeleteLocalRef(env, jVMVal);
}
return ret;
}
/*
* The following three functions implement setter methods for
* java.lang.System.{in, out, err}. They are natively implemented
* because they violate the semantics of the language (i.e. set final
* variable).
*/
JNIEXPORT void JNICALL
Java_java_lang_System_setIn0(JNIEnv *env, jclass cla, jobject stream)
{
jfieldID fid =
(*env)->GetStaticFieldID(env,cla,"in","Ljava/io/InputStream;");
if (fid == 0)
return;
(*env)->SetStaticObjectField(env,cla,fid,stream);
}
JNIEXPORT void JNICALL
Java_java_lang_System_setOut0(JNIEnv *env, jclass cla, jobject stream)
{
jfieldID fid =
(*env)->GetStaticFieldID(env,cla,"out","Ljava/io/PrintStream;");
if (fid == 0)
return;
(*env)->SetStaticObjectField(env,cla,fid,stream);
}
JNIEXPORT void JNICALL
Java_java_lang_System_setErr0(JNIEnv *env, jclass cla, jobject stream)
{
jfieldID fid =
(*env)->GetStaticFieldID(env,cla,"err","Ljava/io/PrintStream;");
if (fid == 0)
return;
(*env)->SetStaticObjectField(env,cla,fid,stream);
}
static void cpchars(jchar *dst, char *src, int n)
{
int i;
for (i = 0; i < n; i++) {
dst[i] = src[i];
}
}
JNIEXPORT jstring JNICALL
Java_java_lang_System_mapLibraryName(JNIEnv *env, jclass ign, jstring libname)
{
int len;
int prefix_len = (int) strlen(JNI_LIB_PREFIX);
int suffix_len = (int) strlen(JNI_LIB_SUFFIX);
jchar chars[256];
if (libname == NULL) {
JNU_ThrowNullPointerException(env, 0);
return NULL;
}
len = (*env)->GetStringLength(env, libname);
if (len > 240) {
JNU_ThrowIllegalArgumentException(env, "name too long");
return NULL;
}
cpchars(chars, JNI_LIB_PREFIX, prefix_len);
(*env)->GetStringRegion(env, libname, 0, len, chars + prefix_len);
len += prefix_len;
cpchars(chars + len, JNI_LIB_SUFFIX, suffix_len);
len += suffix_len;
return (*env)->NewString(env, chars, len);
}

View file

@ -0,0 +1,71 @@
/*
* Copyright (c) 1994, 2012, 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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.
*/
/*-
* Stuff for dealing with threads.
* originally in threadruntime.c, Sun Sep 22 12:09:39 1991
*/
#include "jni.h"
#include "jvm.h"
#include "java_lang_Thread.h"
#define THD "Ljava/lang/Thread;"
#define OBJ "Ljava/lang/Object;"
#define STE "Ljava/lang/StackTraceElement;"
#define STR "Ljava/lang/String;"
#define ARRAY_LENGTH(a) (sizeof(a)/sizeof(a[0]))
static JNINativeMethod methods[] = {
{"start0", "()V", (void *)&JVM_StartThread},
{"stop0", "(" OBJ ")V", (void *)&JVM_StopThread},
{"isAlive", "()Z", (void *)&JVM_IsThreadAlive},
{"suspend0", "()V", (void *)&JVM_SuspendThread},
{"resume0", "()V", (void *)&JVM_ResumeThread},
{"setPriority0", "(I)V", (void *)&JVM_SetThreadPriority},
{"yield", "()V", (void *)&JVM_Yield},
{"sleep", "(J)V", (void *)&JVM_Sleep},
{"currentThread", "()" THD, (void *)&JVM_CurrentThread},
{"countStackFrames", "()I", (void *)&JVM_CountStackFrames},
{"interrupt0", "()V", (void *)&JVM_Interrupt},
{"isInterrupted", "(Z)Z", (void *)&JVM_IsInterrupted},
{"holdsLock", "(" OBJ ")Z", (void *)&JVM_HoldsLock},
{"getThreads", "()[" THD, (void *)&JVM_GetAllThreads},
{"dumpThreads", "([" THD ")[[" STE, (void *)&JVM_DumpThreads},
{"setNativeName", "(" STR ")V", (void *)&JVM_SetNativeThreadName},
};
#undef THD
#undef OBJ
#undef STE
#undef STR
JNIEXPORT void JNICALL
Java_java_lang_Thread_registerNatives(JNIEnv *env, jclass cls)
{
(*env)->RegisterNatives(env, cls, methods, ARRAY_LENGTH(methods));
}

View file

@ -0,0 +1,51 @@
/*
* Copyright (c) 1994, 2016, 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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.
*/
/*
* Implementation of class Throwable
*
* former classruntime.c, Wed Jun 26 18:43:20 1991
*/
#include <stdio.h>
#include <signal.h>
#include "jni.h"
#include "jvm.h"
#include "java_lang_Throwable.h"
/*
* Fill in the current stack trace in this exception. This is
* usually called automatically when the exception is created but it
* may also be called explicitly by the user. This routine returns
* `this' so you can write 'throw e.fillInStackTrace();'
*/
JNIEXPORT jobject JNICALL
Java_java_lang_Throwable_fillInStackTrace(JNIEnv *env, jobject throwable, jint dummy)
{
JVM_FillInStackTrace(env, throwable);
return throwable;
}

View file

@ -0,0 +1,79 @@
/*
* Copyright (c) 1999, 2014, 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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.
*/
#include <stdlib.h>
#include <string.h>
#include "jni.h"
#include "jni_util.h"
#include "jvm.h"
#include "TimeZone_md.h"
#include "java_util_TimeZone.h"
/*
* Gets the platform defined TimeZone ID
*/
JNIEXPORT jstring JNICALL
Java_java_util_TimeZone_getSystemTimeZoneID(JNIEnv *env, jclass ign,
jstring java_home)
{
const char *java_home_dir;
char *javaTZ;
jstring jstrJavaTZ = NULL;
CHECK_NULL_RETURN(java_home, NULL);
java_home_dir = JNU_GetStringPlatformChars(env, java_home, 0);
CHECK_NULL_RETURN(java_home_dir, NULL);
/*
* Invoke platform dependent mapping function
*/
javaTZ = findJavaTZ_md(java_home_dir);
if (javaTZ != NULL) {
jstrJavaTZ = JNU_NewStringPlatform(env, javaTZ);
free((void *)javaTZ);
}
JNU_ReleaseStringPlatformChars(env, java_home, java_home_dir);
return jstrJavaTZ;
}
/*
* Gets a GMT offset-based time zone ID (e.g., "GMT-08:00")
*/
JNIEXPORT jstring JNICALL
Java_java_util_TimeZone_getSystemGMTOffsetID(JNIEnv *env, jclass ign)
{
char *id = getGMTOffsetID();
jstring jstrID = NULL;
if (id != NULL) {
jstrID = JNU_NewStringPlatform(env, id);
free((void *)id);
}
return jstrID;
}

View file

@ -0,0 +1,62 @@
/*
* Copyright (c) 2004, 2015, 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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.
*/
#include "jni.h"
#include "jni_util.h"
#include "jvm.h"
#include "jdk_util.h"
#include "jdk_internal_misc_VM.h"
/* Only register the performance-critical methods */
static JNINativeMethod methods[] = {
{"getNanoTimeAdjustment", "(J)J", (void *)&JVM_GetNanoTimeAdjustment}
};
JNIEXPORT jobject JNICALL
Java_jdk_internal_misc_VM_latestUserDefinedLoader0(JNIEnv *env, jclass cls) {
return JVM_LatestUserDefinedLoader(env);
}
JNIEXPORT void JNICALL
Java_jdk_internal_misc_VM_initialize(JNIEnv *env, jclass cls) {
if (!JDK_InitJvmHandle()) {
JNU_ThrowInternalError(env, "Handle for JVM not found for symbol lookup");
return;
}
// Registers implementations of native methods described in methods[]
// above.
// In particular, registers JVM_GetNanoTimeAdjustment as the implementation
// of the native VM.getNanoTimeAdjustment - avoiding the cost of
// introducing a Java_jdk_internal_misc_VM_getNanoTimeAdjustment wrapper
(*env)->RegisterNatives(env, cls,
methods, sizeof(methods)/sizeof(methods[0]));
}
JNIEXPORT jobjectArray JNICALL
Java_jdk_internal_misc_VM_getRuntimeArguments(JNIEnv *env, jclass cls) {
return JVM_GetVmArguments(env);
}

View file

@ -0,0 +1,43 @@
/*
* Copyright (c) 2005, 2010, 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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.
*/
#include "jni.h"
#include "jni_util.h"
#include "jlong.h"
#include "jvm.h"
#include "jdk_internal_vm_VMSupport.h"
JNIEXPORT jobject JNICALL
Java_jdk_internal_vm_VMSupport_initAgentProperties(JNIEnv *env, jclass cls, jobject props)
{
return JVM_InitAgentProperties(env, props);
}
JNIEXPORT jstring JNICALL
Java_jdk_internal_vm_VMSupport_getVMTemporaryDirectory(JNIEnv *env, jclass cls)
{
return JVM_GetTemporaryDirectory(env);
}

View file

@ -0,0 +1,45 @@
/*
* Copyright (c) 1998, 2015, 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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.
*/
#include "jni.h"
#include "jni_util.h"
#include "jvm.h"
JNIEXPORT jint JNICALL
DEF_JNI_OnLoad(JavaVM *vm, void *reserved)
{
jint vm_version = JVM_GetInterfaceVersion();
if (vm_version != JVM_INTERFACE_VERSION) {
JNIEnv *env;
char buf[128];
sprintf(buf, "JVM interface version mismatch: expecting %d, got %d.",
JVM_INTERFACE_VERSION, (int)vm_version);
(*vm)->GetEnv(vm, (void **)&env, JNI_VERSION_1_2);
if (env) {
(*env)->FatalError(env, buf);
}
}
return JNI_VERSION_1_2;
}

View file

@ -0,0 +1,30 @@
/*
* Copyright (c) 2000, 2001, 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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.
*/
/*
* This file is used to define intptr_t,etc when needed at compile time.
*/
#include "gdefs_md.h"

View file

@ -0,0 +1,228 @@
/*
* Copyright (c) 1994, 2013, 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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.
*/
#include <stdlib.h>
#include <string.h>
#include <stddef.h>
#include "jni.h"
#include "jni_util.h"
#include "jvm.h"
#include "io_util.h"
#include "io_util_md.h"
/* IO helper functions */
jint
readSingle(JNIEnv *env, jobject this, jfieldID fid) {
jint nread;
char ret;
FD fd = GET_FD(this, fid);
if (fd == -1) {
JNU_ThrowIOException(env, "Stream Closed");
return -1;
}
nread = IO_Read(fd, &ret, 1);
if (nread == 0) { /* EOF */
return -1;
} else if (nread == -1) { /* error */
JNU_ThrowIOExceptionWithLastError(env, "Read error");
}
return ret & 0xFF;
}
/* The maximum size of a stack-allocated buffer.
*/
#define BUF_SIZE 8192
/*
* Returns true if the array slice defined by the given offset and length
* is out of bounds.
*/
static int
outOfBounds(JNIEnv *env, jint off, jint len, jbyteArray array) {
return ((off < 0) ||
(len < 0) ||
// We are very careful to avoid signed integer overflow,
// the result of which is undefined in C.
((*env)->GetArrayLength(env, array) - off < len));
}
jint
readBytes(JNIEnv *env, jobject this, jbyteArray bytes,
jint off, jint len, jfieldID fid)
{
jint nread;
char stackBuf[BUF_SIZE];
char *buf = NULL;
FD fd;
if (IS_NULL(bytes)) {
JNU_ThrowNullPointerException(env, NULL);
return -1;
}
if (outOfBounds(env, off, len, bytes)) {
JNU_ThrowByName(env, "java/lang/IndexOutOfBoundsException", NULL);
return -1;
}
if (len == 0) {
return 0;
} else if (len > BUF_SIZE) {
buf = malloc(len);
if (buf == NULL) {
JNU_ThrowOutOfMemoryError(env, NULL);
return 0;
}
} else {
buf = stackBuf;
}
fd = GET_FD(this, fid);
if (fd == -1) {
JNU_ThrowIOException(env, "Stream Closed");
nread = -1;
} else {
nread = IO_Read(fd, buf, len);
if (nread > 0) {
(*env)->SetByteArrayRegion(env, bytes, off, nread, (jbyte *)buf);
} else if (nread == -1) {
JNU_ThrowIOExceptionWithLastError(env, "Read error");
} else { /* EOF */
nread = -1;
}
}
if (buf != stackBuf) {
free(buf);
}
return nread;
}
void
writeSingle(JNIEnv *env, jobject this, jint byte, jboolean append, jfieldID fid) {
// Discard the 24 high-order bits of byte. See OutputStream#write(int)
char c = (char) byte;
jint n;
FD fd = GET_FD(this, fid);
if (fd == -1) {
JNU_ThrowIOException(env, "Stream Closed");
return;
}
if (append == JNI_TRUE) {
n = IO_Append(fd, &c, 1);
} else {
n = IO_Write(fd, &c, 1);
}
if (n == -1) {
JNU_ThrowIOExceptionWithLastError(env, "Write error");
}
}
void
writeBytes(JNIEnv *env, jobject this, jbyteArray bytes,
jint off, jint len, jboolean append, jfieldID fid)
{
jint n;
char stackBuf[BUF_SIZE];
char *buf = NULL;
FD fd;
if (IS_NULL(bytes)) {
JNU_ThrowNullPointerException(env, NULL);
return;
}
if (outOfBounds(env, off, len, bytes)) {
JNU_ThrowByName(env, "java/lang/IndexOutOfBoundsException", NULL);
return;
}
if (len == 0) {
return;
} else if (len > BUF_SIZE) {
buf = malloc(len);
if (buf == NULL) {
JNU_ThrowOutOfMemoryError(env, NULL);
return;
}
} else {
buf = stackBuf;
}
(*env)->GetByteArrayRegion(env, bytes, off, len, (jbyte *)buf);
if (!(*env)->ExceptionOccurred(env)) {
off = 0;
while (len > 0) {
fd = GET_FD(this, fid);
if (fd == -1) {
JNU_ThrowIOException(env, "Stream Closed");
break;
}
if (append == JNI_TRUE) {
n = IO_Append(fd, buf+off, len);
} else {
n = IO_Write(fd, buf+off, len);
}
if (n == -1) {
JNU_ThrowIOExceptionWithLastError(env, "Write error");
break;
}
off += n;
len -= n;
}
}
if (buf != stackBuf) {
free(buf);
}
}
void
throwFileNotFoundException(JNIEnv *env, jstring path)
{
char buf[256];
size_t n;
jobject x;
jstring why = NULL;
n = getLastErrorString(buf, sizeof(buf));
if (n > 0) {
#ifdef WIN32
why = (*env)->NewStringUTF(env, buf);
#else
why = JNU_NewStringPlatform(env, buf);
#endif
CHECK_NULL(why);
}
x = JNU_NewObjectByName(env,
"java/io/FileNotFoundException",
"(Ljava/lang/String;Ljava/lang/String;)V",
path, why);
if (x != NULL) {
(*env)->Throw(env, x);
}
}

View file

@ -0,0 +1,129 @@
/*
* Copyright (c) 1997, 2014, 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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.
*/
#include "jni.h"
#include "jni_util.h"
extern jfieldID IO_fd_fdID;
extern jfieldID IO_handle_fdID;
extern jfieldID IO_append_fdID;
#ifdef _ALLBSD_SOURCE
#include <fcntl.h>
#ifndef O_SYNC
#define O_SYNC O_FSYNC
#endif
#ifndef O_DSYNC
#define O_DSYNC O_FSYNC
#endif
#elif !defined(O_DSYNC) || !defined(O_SYNC)
#define O_SYNC (0x0800)
#define O_DSYNC (0x2000)
#endif
/*
* IO helper functions
*/
jint readSingle(JNIEnv *env, jobject this, jfieldID fid);
jint readBytes(JNIEnv *env, jobject this, jbyteArray bytes, jint off,
jint len, jfieldID fid);
void writeSingle(JNIEnv *env, jobject this, jint byte, jboolean append, jfieldID fid);
void writeBytes(JNIEnv *env, jobject this, jbyteArray bytes, jint off,
jint len, jboolean append, jfieldID fid);
void fileOpen(JNIEnv *env, jobject this, jstring path, jfieldID fid, int flags);
void throwFileNotFoundException(JNIEnv *env, jstring path);
/*
* Macros for managing platform strings. The typical usage pattern is:
*
* WITH_PLATFORM_STRING(env, string, var) {
* doSomethingWith(var);
* } END_PLATFORM_STRING(env, var);
*
* where env is the prevailing JNIEnv,
* string is a JNI reference to a java.lang.String object, and
* var is the char * variable that will point to the string,
* after being converted into the platform encoding.
*
* The related macro WITH_FIELD_PLATFORM_STRING first extracts the string from
* a given field of a given object:
*
* WITH_FIELD_PLATFORM_STRING(env, object, id, var) {
* doSomethingWith(var);
* } END_PLATFORM_STRING(env, var);
*
* where env is the prevailing JNIEnv,
* object is a jobject,
* id is the field ID of the String field to be extracted, and
* var is the char * variable that will point to the string.
*
* Uses of these macros may be nested as long as each WITH_.._STRING macro
* declares a unique variable.
*/
#define WITH_PLATFORM_STRING(env, strexp, var) \
if (1) { \
const char *var; \
jstring _##var##str = (strexp); \
if (_##var##str == NULL) { \
JNU_ThrowNullPointerException((env), NULL); \
goto _##var##end; \
} \
var = JNU_GetStringPlatformChars((env), _##var##str, NULL); \
if (var == NULL) goto _##var##end;
#define WITH_FIELD_PLATFORM_STRING(env, object, id, var) \
WITH_PLATFORM_STRING(env, \
((object == NULL) \
? NULL \
: (*(env))->GetObjectField((env), (object), (id))), \
var)
#define END_PLATFORM_STRING(env, var) \
JNU_ReleaseStringPlatformChars(env, _##var##str, var); \
_##var##end: ; \
} else ((void)NULL)
/* Macros for transforming Java Strings into native Unicode strings.
* Works analogously to WITH_PLATFORM_STRING.
*/
#define WITH_UNICODE_STRING(env, strexp, var) \
if (1) { \
const jchar *var; \
jstring _##var##str = (strexp); \
if (_##var##str == NULL) { \
JNU_ThrowNullPointerException((env), NULL); \
goto _##var##end; \
} \
var = (*(env))->GetStringChars((env), _##var##str, NULL); \
if (var == NULL) goto _##var##end;
#define END_UNICODE_STRING(env, var) \
(*(env))->ReleaseStringChars(env, _##var##str, var); \
_##var##end: ; \
} else ((void)NULL)

View file

@ -0,0 +1,128 @@
/*
* Copyright (c) 1998, 2013, 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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.
*/
#ifndef _JAVA_PROPS_H
#define _JAVA_PROPS_H
#include <jni_util.h>
/* The preferred native type for storing text on the current OS */
#ifdef WIN32
#include <tchar.h>
typedef WCHAR nchar;
#else
typedef char nchar;
#endif
typedef struct {
char *os_name;
char *os_version;
char *os_arch;
#ifdef JDK_ARCH_ABI_PROP_NAME
char *sun_arch_abi;
#endif
nchar *tmp_dir;
nchar *font_dir;
nchar *user_dir;
char *file_separator;
char *path_separator;
char *line_separator;
nchar *user_name;
nchar *user_home;
char *language;
char *format_language;
char *display_language;
char *script;
char *format_script;
char *display_script;
char *country;
char *format_country;
char *display_country;
char *variant;
char *format_variant;
char *display_variant;
char *encoding;
char *sun_jnu_encoding;
char *sun_stdout_encoding;
char *sun_stderr_encoding;
char *timezone;
char *printerJob;
char *graphics_env;
char *awt_toolkit;
char *unicode_encoding; /* The default endianness of unicode
i.e. UnicodeBig or UnicodeLittle */
const char *cpu_isalist; /* list of supported instruction sets */
char *cpu_endian; /* endianness of platform */
char *data_model; /* 32 or 64 bit data model */
char *patch_level; /* patches/service packs installed */
char *desktop; /* Desktop name. */
#ifdef MACOSX
// These are for proxy-related information.
// Note that if these platform-specific extensions get out of hand we should make a new
// structure for them and #include it here.
int httpProxyEnabled;
char *httpHost;
char *httpPort;
int httpsProxyEnabled;
char *httpsHost;
char *httpsPort;
int ftpProxyEnabled;
char *ftpHost;
char *ftpPort;
int socksProxyEnabled;
char *socksHost;
char *socksPort;
int gopherProxyEnabled;
char *gopherHost;
char *gopherPort;
char *exceptionList;
char *awt_headless; /* java.awt.headless setting, if NULL (default) will not be set */
#endif
} java_props_t;
java_props_t *GetJavaProperties(JNIEnv *env);
jstring GetStringPlatform(JNIEnv *env, nchar* str);
#endif /* _JAVA_PROPS_H */

View file

@ -0,0 +1,54 @@
/*
* Copyright (c) 2005, 2015, 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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.
*/
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <assert.h>
#include "jvm.h"
#include "jdk_util.h"
JNIEXPORT void
JDK_GetVersionInfo0(jdk_version_info* info, size_t info_size) {
/* These VERSION_* macros are given by the build system */
const unsigned int version_major = VERSION_MAJOR;
const unsigned int version_minor = VERSION_MINOR;
const unsigned int version_security = VERSION_SECURITY;
const unsigned int version_patch = VERSION_PATCH;
const unsigned int version_build = VERSION_BUILD;
memset(info, 0, info_size);
info->jdk_version = ((version_major & 0xFF) << 24) |
((version_minor & 0xFF) << 16) |
((version_security & 0xFF) << 8) |
(version_build & 0xFF);
info->patch_version = version_patch;
info->thread_park_blocker = 1;
// Advertise presence of PostVMInitHook:
// future optimization: detect if this is enabled.
info->post_vm_init_hook_enabled = 1;
info->pending_list_uses_discovered_field = 1;
}

View file

@ -0,0 +1,66 @@
/*
* Copyright (c) 2004, 2011, 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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.
*/
#ifndef JDK_UTIL_H
#define JDK_UTIL_H
#include "jni.h"
#include "jvm.h"
#include "jdk_util_md.h"
#ifdef __cplusplus
extern "C" {
#endif
/*-------------------------------------------------------
* Exported interfaces for both JDK and JVM to use
*-------------------------------------------------------
*/
/*
*
*/
JNIEXPORT void
JDK_GetVersionInfo0(jdk_version_info* info, size_t info_size);
/*-------------------------------------------------------
* Internal interface for JDK to use
*-------------------------------------------------------
*/
/* Init JVM handle for symbol lookup;
* Return 0 if JVM handle not found.
*/
int JDK_InitJvmHandle();
/* Find the named JVM entry; returns NULL if not found. */
void* JDK_FindJvmEntry(const char* name);
#ifdef __cplusplus
} /* extern "C" */
#endif /* __cplusplus */
#endif /* JDK_UTIL_H */

View file

@ -0,0 +1,69 @@
/*
* Copyright (c) 1998, 2015, 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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.
*/
#include <stdlib.h>
#include "jni.h"
#ifndef STATIC_BUILD
/* This is a temporary solution until we figure out how to let native
* libraries use jio_* without linking with the VM.
*/
extern int
jio_vsnprintf(char *str, size_t count, const char *fmt, va_list args);
JNIEXPORT int
jio_snprintf(char *str, size_t count, const char *fmt, ...)
{
int len;
va_list args;
va_start(args, fmt);
len = jio_vsnprintf(str, count, fmt, args);
va_end(args);
return len;
}
extern int
jio_vfprintf(FILE *, const char *fmt, va_list args);
JNIEXPORT int
jio_fprintf(FILE *fp, const char *fmt, ...)
{
int len;
va_list args;
va_start(args, fmt);
len = jio_vfprintf(fp, fmt, args);
va_end(args);
return len;
}
#endif

View file

@ -0,0 +1,31 @@
/*
* Copyright (c) 1997, 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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.
*/
#ifndef _JLONG_H_
#define _JLONG_H_
#include "jlong_md.h"
#endif

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,515 @@
/*
* Copyright (c) 1997, 2016, 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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.
*/
#ifndef JNI_UTIL_H
#define JNI_UTIL_H
#include "jni.h"
#include "jlong.h"
#ifdef __cplusplus
extern "C" {
#endif
/*
* This file contains utility functions that can be implemented in pure JNI.
*
* Caution: Callers of functions declared in this file should be
* particularly aware of the fact that these functions are convenience
* functions, and as such are often compound operations, each one of
* which may throw an exception. Therefore, the functions this file
* will often return silently if an exception has occurred, and callers
* must check for exception themselves.
*/
/* Throw a Java exception by name. Similar to SignalError. */
JNIEXPORT void JNICALL
JNU_ThrowByName(JNIEnv *env, const char *name, const char *msg);
/* Throw common exceptions */
JNIEXPORT void JNICALL
JNU_ThrowNullPointerException(JNIEnv *env, const char *msg);
JNIEXPORT void JNICALL
JNU_ThrowArrayIndexOutOfBoundsException(JNIEnv *env, const char *msg);
JNIEXPORT void JNICALL
JNU_ThrowOutOfMemoryError(JNIEnv *env, const char *msg);
JNIEXPORT void JNICALL
JNU_ThrowIllegalArgumentException(JNIEnv *env, const char *msg);
JNIEXPORT void JNICALL
JNU_ThrowIllegalAccessError(JNIEnv *env, const char *msg);
JNIEXPORT void JNICALL
JNU_ThrowIllegalAccessException(JNIEnv *env, const char *msg);
JNIEXPORT void JNICALL
JNU_ThrowInternalError(JNIEnv *env, const char *msg);
JNIEXPORT void JNICALL
JNU_ThrowIOException(JNIEnv *env, const char *msg);
JNIEXPORT void JNICALL
JNU_ThrowNoSuchFieldException(JNIEnv *env, const char *msg);
JNIEXPORT void JNICALL
JNU_ThrowNoSuchMethodException(JNIEnv *env, const char *msg);
JNIEXPORT void JNICALL
JNU_ThrowClassNotFoundException(JNIEnv *env, const char *msg);
JNIEXPORT void JNICALL
JNU_ThrowNumberFormatException(JNIEnv *env, const char *msg);
JNIEXPORT void JNICALL
JNU_ThrowNoSuchFieldError(JNIEnv *env, const char *msg);
JNIEXPORT void JNICALL
JNU_ThrowNoSuchMethodError(JNIEnv *env, const char *msg);
JNIEXPORT void JNICALL
JNU_ThrowStringIndexOutOfBoundsException(JNIEnv *env, const char *msg);
JNIEXPORT void JNICALL
JNU_ThrowInstantiationException(JNIEnv *env, const char *msg);
/* Throw an exception by name, using the string returned by
* getLastErrorString for the detail string. If the last-error
* string is NULL, use the given default detail string.
*/
JNIEXPORT void JNICALL
JNU_ThrowByNameWithLastError(JNIEnv *env, const char *name,
const char *defaultDetail);
/* Throw an exception by name, using a given message and the string
* returned by getLastErrorString to construct the detail string.
*/
JNIEXPORT void JNICALL
JNU_ThrowByNameWithMessageAndLastError
(JNIEnv *env, const char *name, const char *message);
/* Throw an IOException, using the last-error string for the detail
* string. If the last-error string is NULL, use the given default
* detail string.
*/
JNIEXPORT void JNICALL
JNU_ThrowIOExceptionWithLastError(JNIEnv *env, const char *defaultDetail);
/* Convert between Java strings and i18n C strings */
JNIEXPORT jstring
NewStringPlatform(JNIEnv *env, const char *str);
JNIEXPORT const char *
GetStringPlatformChars(JNIEnv *env, jstring jstr, jboolean *isCopy);
JNIEXPORT jstring JNICALL
JNU_NewStringPlatform(JNIEnv *env, const char *str);
JNIEXPORT const char * JNICALL
JNU_GetStringPlatformChars(JNIEnv *env, jstring jstr, jboolean *isCopy);
JNIEXPORT void JNICALL
JNU_ReleaseStringPlatformChars(JNIEnv *env, jstring jstr, const char *str);
/* Class constants */
JNIEXPORT jclass JNICALL
JNU_ClassString(JNIEnv *env);
JNIEXPORT jclass JNICALL
JNU_ClassClass(JNIEnv *env);
JNIEXPORT jclass JNICALL
JNU_ClassObject(JNIEnv *env);
JNIEXPORT jclass JNICALL
JNU_ClassThrowable(JNIEnv *env);
/* Copy count number of arguments from src to dst. Array bounds
* and ArrayStoreException are checked.
*/
JNIEXPORT jint JNICALL
JNU_CopyObjectArray(JNIEnv *env, jobjectArray dst, jobjectArray src,
jint count);
/* Invoke a object-returning static method, based on class name,
* method name, and signature string.
*
* The caller should check for exceptions by setting hasException
* argument. If the caller is not interested in whether an exception
* has occurred, pass in NULL.
*/
JNIEXPORT jvalue JNICALL
JNU_CallStaticMethodByName(JNIEnv *env,
jboolean *hasException,
const char *class_name,
const char *name,
const char *signature,
...);
/* Invoke an instance method by name.
*/
JNIEXPORT jvalue JNICALL
JNU_CallMethodByName(JNIEnv *env,
jboolean *hasException,
jobject obj,
const char *name,
const char *signature,
...);
JNIEXPORT jvalue JNICALL
JNU_CallMethodByNameV(JNIEnv *env,
jboolean *hasException,
jobject obj,
const char *name,
const char *signature,
va_list args);
/* Construct a new object of class, specifying the class by name,
* and specififying which constructor to run and what arguments to
* pass to it.
*
* The method will return an initialized instance if successful.
* It will return NULL if an error has occurred (for example if
* it ran out of memory) and the appropriate Java exception will
* have been thrown.
*/
JNIEXPORT jobject JNICALL
JNU_NewObjectByName(JNIEnv *env, const char *class_name,
const char *constructor_sig, ...);
/* returns:
* 0: object is not an instance of the class named by classname.
* 1: object is an instance of the class named by classname.
* -1: the class named by classname cannot be found. An exception
* has been thrown.
*/
JNIEXPORT jint JNICALL
JNU_IsInstanceOfByName(JNIEnv *env, jobject object, char *classname);
/* Get or set class and instance fields.
* Note that set functions take a variable number of arguments,
* but only one argument of the appropriate type can be passed.
* For example, to set an integer field i to 100:
*
* JNU_SetFieldByName(env, &exc, obj, "i", "I", 100);
*
* To set a float field f to 12.3:
*
* JNU_SetFieldByName(env, &exc, obj, "f", "F", 12.3);
*
* The caller should check for exceptions by setting hasException
* argument. If the caller is not interested in whether an exception
* has occurred, pass in NULL.
*/
JNIEXPORT jvalue JNICALL
JNU_GetFieldByName(JNIEnv *env,
jboolean *hasException,
jobject obj,
const char *name,
const char *sig);
JNIEXPORT void JNICALL
JNU_SetFieldByName(JNIEnv *env,
jboolean *hasException,
jobject obj,
const char *name,
const char *sig,
...);
JNIEXPORT jvalue JNICALL
JNU_GetStaticFieldByName(JNIEnv *env,
jboolean *hasException,
const char *classname,
const char *name,
const char *sig);
JNIEXPORT void JNICALL
JNU_SetStaticFieldByName(JNIEnv *env,
jboolean *hasException,
const char *classname,
const char *name,
const char *sig,
...);
/*
* Calls the .equals method.
*/
JNIEXPORT jboolean JNICALL
JNU_Equals(JNIEnv *env, jobject object1, jobject object2);
/************************************************************************
* Thread calls
*
* Convenience thread-related calls on the java.lang.Object class.
*/
JNIEXPORT void JNICALL
JNU_MonitorWait(JNIEnv *env, jobject object, jlong timeout);
JNIEXPORT void JNICALL
JNU_Notify(JNIEnv *env, jobject object);
JNIEXPORT void JNICALL
JNU_NotifyAll(JNIEnv *env, jobject object);
/************************************************************************
* Miscellaneous utilities used by the class libraries
*/
#define IS_NULL(obj) ((obj) == NULL)
#define JNU_IsNull(env,obj) ((obj) == NULL)
/************************************************************************
* Miscellaneous utilities used by the class libraries to return from
* a function if a value is NULL or an exception is pending.
*/
#define CHECK_NULL(x) \
do { \
if ((x) == NULL) { \
return; \
} \
} while (0) \
#define CHECK_NULL_RETURN(x, y) \
do { \
if ((x) == NULL) { \
return (y); \
} \
} while (0) \
#ifdef __cplusplus
#define JNU_CHECK_EXCEPTION(env) \
do { \
if ((env)->ExceptionCheck()) { \
return; \
} \
} while (0) \
#define JNU_CHECK_EXCEPTION_RETURN(env, y) \
do { \
if ((env)->ExceptionCheck()) { \
return (y); \
} \
} while (0)
#else
#define JNU_CHECK_EXCEPTION(env) \
do { \
if ((*env)->ExceptionCheck(env)) { \
return; \
} \
} while (0) \
#define JNU_CHECK_EXCEPTION_RETURN(env, y) \
do { \
if ((*env)->ExceptionCheck(env)) { \
return (y); \
} \
} while (0)
#endif /* __cplusplus */
/************************************************************************
* Debugging utilities
*/
JNIEXPORT void JNICALL
JNU_PrintString(JNIEnv *env, char *hdr, jstring string);
JNIEXPORT void JNICALL
JNU_PrintClass(JNIEnv *env, char *hdr, jobject object);
JNIEXPORT jstring JNICALL
JNU_ToString(JNIEnv *env, jobject object);
/*
* Package shorthand for use by native libraries
*/
#define JNU_JAVAPKG "java/lang/"
#define JNU_JAVAIOPKG "java/io/"
#define JNU_JAVANETPKG "java/net/"
/*
* Check if the current thread is attached to the VM, and returns
* the JNIEnv of the specified version if the thread is attached.
*
* If the current thread is not attached, this function returns 0.
*
* If the current thread is attached, this function returns the
* JNI environment, or returns (void *)JNI_ERR if the specified
* version is not supported.
*/
JNIEXPORT void * JNICALL
JNU_GetEnv(JavaVM *vm, jint version);
/*
* Warning free access to pointers stored in Java long fields.
*/
#define JNU_GetLongFieldAsPtr(env,obj,id) \
(jlong_to_ptr((*(env))->GetLongField((env),(obj),(id))))
#define JNU_SetLongFieldFromPtr(env,obj,id,val) \
(*(env))->SetLongField((env),(obj),(id),ptr_to_jlong(val))
/*
* Internal use only.
*/
enum {
NO_ENCODING_YET = 0, /* "sun.jnu.encoding" not yet set */
NO_FAST_ENCODING, /* Platform encoding is not fast */
FAST_8859_1, /* ISO-8859-1 */
FAST_CP1252, /* MS-DOS Cp1252 */
FAST_646_US, /* US-ASCII : ISO646-US */
FAST_UTF_8
};
int getFastEncoding();
void initializeEncoding();
void* getProcessHandle();
void buildJniFunctionName(const char *sym, const char *cname,
char *jniEntryName);
extern size_t getLastErrorString(char *buf, size_t len);
extern int getErrorString(int err, char *buf, size_t len);
#ifdef STATIC_BUILD
/* Macros for handling declaration of static/dynamic
* JNI library Load/Unload functions
*
* Use DEF_JNI_On{Un}Load when you want a static and non-static entry points.
* Use DEF_STATIC_JNI_On{Un}Load when you only want a static one.
*
* LIBRARY_NAME must be set to the name of the library
*/
/* These three macros are needed to get proper concatenation of
* the LIBRARY_NAME
*
* NOTE: LIBRARY_NAME must be set for static builds.
*/
#define ADD_LIB_NAME3(name, lib) name ## lib
#define ADD_LIB_NAME2(name, lib) ADD_LIB_NAME3(name, lib)
#define ADD_LIB_NAME(entry) ADD_LIB_NAME2(entry, LIBRARY_NAME)
#define DEF_JNI_OnLoad \
ADD_LIB_NAME(JNI_OnLoad_)(JavaVM *vm, void *reserved) \
{ \
jint JNICALL ADD_LIB_NAME(JNI_OnLoad_dynamic_)(JavaVM *vm, void *reserved); \
ADD_LIB_NAME(JNI_OnLoad_dynamic_)(vm, reserved); \
return JNI_VERSION_1_8; \
} \
jint JNICALL ADD_LIB_NAME(JNI_OnLoad_dynamic_)
#define DEF_STATIC_JNI_OnLoad \
JNIEXPORT jint JNICALL ADD_LIB_NAME(JNI_OnLoad_)(JavaVM *vm, void *reserved) { \
return JNI_VERSION_1_8; \
}
#define DEF_JNI_OnUnload \
ADD_LIB_NAME(JNI_OnUnload_)(JavaVM *vm, void *reserved) \
{ \
void JNICALL ADD_LIB_NAME(JNI_OnUnload_dynamic_)(JavaVM *vm, void *reserved); \
ADD_LIB_NAME(JNI_OnUnload_dynamic_)(vm, reserved); \
} \
void JNICALL ADD_LIB_NAME(JNI_OnUnload_dynamic_)
#define DEF_STATIC_JNI_OnUnload \
ADD_LIB_NAME(JNI_OnUnload_)
#else
#define DEF_JNI_OnLoad JNI_OnLoad
#define DEF_STATIC_JNI_OnLoad
#define DEF_JNI_OnUnload JNI_OnUnload
#define DEF_STATIC_JNI_OnUnload
#endif
#ifdef STATIC_BUILD
/* Macros for handling declaration of static/dynamic
* Agent library Load/Attach/Unload functions
*
* Use DEF_Agent_OnLoad, DEF_Agent_OnAttach or DEF_Agent_OnUnload
* when you want both static and non-static entry points.
* Use DEF_STATIC_Agent_OnLoad, DEF_STATIC_Agent_OnAttach or
* DEF_STATIC_Agent_OnUnload when you only want a static one.
*
* LIBRARY_NAME must be set to the name of the library for static builds.
*/
#define DEF_Agent_OnLoad \
ADD_LIB_NAME(Agent_OnLoad_)(JavaVM *vm, char *options, void *reserved) \
{ \
jint JNICALL ADD_LIB_NAME(Agent_OnLoad_dynamic_)(JavaVM *vm, char *options, void *reserved); \
return ADD_LIB_NAME(Agent_OnLoad_dynamic_)(vm, options, reserved); \
} \
jint JNICALL ADD_LIB_NAME(Agent_OnLoad_dynamic_)
#define DEF_STATIC_Agent_OnLoad \
JNIEXPORT jint JNICALL ADD_LIB_NAME(Agent_OnLoad_)(JavaVM *vm, char *options, void *reserved) { \
return JNI_FALSE; \
}
#define DEF_Agent_OnAttach \
ADD_LIB_NAME(Agent_OnAttach_)(JavaVM *vm, char *options, void *reserved) \
{ \
jint JNICALL ADD_LIB_NAME(Agent_OnAttach_dynamic_)(JavaVM *vm, char *options, void *reserved); \
return ADD_LIB_NAME(Agent_OnAttach_dynamic_)(vm, options, reserved); \
} \
jint JNICALL ADD_LIB_NAME(Agent_OnAttach_dynamic_)
#define DEF_STATIC_Agent_OnAttach \
JNIEXPORT jint JNICALL ADD_LIB_NAME(Agent_OnLoad_)(JavaVM *vm, char *options, void *reserved) { \
return JNI_FALSE; \
}
#define DEF_Agent_OnUnload \
ADD_LIB_NAME(Agent_OnUnload_)(JavaVM *vm) \
{ \
void JNICALL ADD_LIB_NAME(Agent_OnUnload_dynamic_)(JavaVM *vm); \
ADD_LIB_NAME(Agent_OnUnload_dynamic_)(vm); \
} \
void JNICALL ADD_LIB_NAME(Agent_OnUnload_dynamic_)
#define DEF_STATIC_Agent_OnUnload \
ADD_LIB_NAME(Agent_OnUnload_)
#else
#define DEF_Agent_OnLoad Agent_OnLoad
#define DEF_Agent_OnAttach Agent_OnAttach
#define DEF_Agent_OnUnload Agent_OnUnload
#define DEF_STATIC_Agent_OnLoad
#define DEF_STATIC_Agent_OnAttach
#define DEF_STATIC_Agent_OnUnload
#endif
#ifdef __cplusplus
} /* extern "C" */
#endif /* __cplusplus */
#endif /* JNI_UTIL_H */

View file

@ -0,0 +1,118 @@
/*
* Copyright (c) 2013, 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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.
*/
#ifndef SIZECALC_H
#define SIZECALC_H
/*
* A machinery for safe calculation of sizes used when allocating memory.
*
* All size checks are performed against the SIZE_MAX (the maximum value for
* size_t). All numerical arguments as well as the result of calculation must
* be non-negative integers less than or equal to SIZE_MAX, otherwise the
* calculated size is considered unsafe.
*
* If the SIZECALC_ALLOC_THROWING_BAD_ALLOC macro is defined, then _ALLOC_
* helper macros throw the std::bad_alloc instead of returning NULL.
*/
#include <stdint.h> /* SIZE_MAX for C99+ */
/* http://stackoverflow.com/questions/3472311/what-is-a-portable-method-to-find-the-maximum-value-of-size-t */
#ifndef SIZE_MAX
#define SIZE_MAX ((size_t)-1)
#endif
#define IS_SAFE_SIZE_T(x) ((x) >= 0 && (unsigned long long)(x) <= SIZE_MAX)
#define IS_SAFE_SIZE_MUL(m, n) \
(IS_SAFE_SIZE_T(m) && IS_SAFE_SIZE_T(n) && ((m) == 0 || (n) == 0 || (size_t)(n) <= (SIZE_MAX / (size_t)(m))))
#define IS_SAFE_SIZE_ADD(a, b) \
(IS_SAFE_SIZE_T(a) && IS_SAFE_SIZE_T(b) && (size_t)(b) <= (SIZE_MAX - (size_t)(a)))
/* Helper macros */
#ifdef SIZECALC_ALLOC_THROWING_BAD_ALLOC
#define FAILURE_RESULT throw std::bad_alloc()
#else
#define FAILURE_RESULT NULL
#endif
/*
* A helper macro to safely allocate an array of size m*n.
* Example usage:
* int* p = (int*)SAFE_SIZE_ARRAY_ALLOC(malloc, sizeof(int), n);
* if (!p) throw OutOfMemory;
* // Use the allocated array...
*/
#define SAFE_SIZE_ARRAY_ALLOC(func, m, n) \
(IS_SAFE_SIZE_MUL((m), (n)) ? ((func)((m) * (n))) : FAILURE_RESULT)
#define SAFE_SIZE_ARRAY_REALLOC(func, p, m, n) \
(IS_SAFE_SIZE_MUL((m), (n)) ? ((func)((p), (m) * (n))) : FAILURE_RESULT)
/*
* A helper macro to safely allocate an array of type 'type' with 'n' items
* using the C++ new[] operator.
* Example usage:
* MyClass* p = SAFE_SIZE_NEW_ARRAY(MyClass, n);
* // Use the pointer.
* This macro throws the std::bad_alloc C++ exception to indicate
* a failure.
* NOTE: if 'n' is calculated, the calling code is responsible for using the
* IS_SAFE_... macros to check if the calculations are safe.
*/
#define SAFE_SIZE_NEW_ARRAY(type, n) \
(IS_SAFE_SIZE_MUL(sizeof(type), (n)) ? (new type[(n)]) : throw std::bad_alloc())
#define SAFE_SIZE_NEW_ARRAY2(type, n, m) \
(IS_SAFE_SIZE_MUL((m), (n)) && IS_SAFE_SIZE_MUL(sizeof(type), (n) * (m)) ? \
(new type[(n) * (m)]) : throw std::bad_alloc())
/*
* Checks if a data structure of size (a + m*n) can be safely allocated
* w/o producing an integer overflow when calculating its size.
*/
#define IS_SAFE_STRUCT_SIZE(a, m, n) \
( \
IS_SAFE_SIZE_MUL((m), (n)) && IS_SAFE_SIZE_ADD((m) * (n), (a)) \
)
/*
* A helper macro for implementing safe memory allocation for a data structure
* of size (a + m * n).
* Example usage:
* void * p = SAFE_SIZE_ALLOC(malloc, header, num, itemSize);
* if (!p) throw OutOfMemory;
* // Use the allocated memory...
*/
#define SAFE_SIZE_STRUCT_ALLOC(func, a, m, n) \
(IS_SAFE_STRUCT_SIZE((a), (m), (n)) ? ((func)((a) + (m) * (n))) : FAILURE_RESULT)
#endif /* SIZECALC_H */

View file

@ -0,0 +1,59 @@
/*
* Copyright (c) 1999, 2003, 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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.
*/
/*
* The real verifier now lives in libverifier.so/verifier.dll.
*
* This dummy exists so that HotSpot will run with the new
* libjava.so/java.dll which is where is it accustomed to finding the
* verifier.
*/
#include "jni.h"
struct struct_class_size_info;
typedef struct struct_class_size_info class_size_info;
JNIIMPORT jboolean
VerifyClass(JNIEnv *env, jclass cb, char *buffer, jint len);
JNIIMPORT jboolean
VerifyClassForMajorVersion(JNIEnv *env, jclass cb, char *buffer, jint len,
jint major_version);
JNIEXPORT jboolean
VerifyClassCodes(JNIEnv *env, jclass cb, char *buffer, jint len)
{
return VerifyClass(env, cb, buffer, len);
}
JNIEXPORT jboolean
VerifyClassCodesForMajorVersion(JNIEnv *env, jclass cb, char *buffer,
jint len, jint major_version)
{
return VerifyClassForMajorVersion(env, cb, buffer, len, major_version);
}