8283287: ClassLoader.c cleanups

Reviewed-by: stuefe, alanb, rriggs
This commit is contained in:
Tyler Steele 2022-03-19 07:06:47 +00:00 committed by Thomas Stuefe
parent 0c3094c818
commit 3e58a438e9

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1996, 2021, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1996, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -23,16 +23,16 @@
* questions. * questions.
*/ */
#include <stdlib.h>
#include <assert.h> #include <assert.h>
#include <stdlib.h>
#include <string.h>
#include "jni.h"
#include "jni_util.h"
#include "jlong.h"
#include "jvm.h"
#include "check_classname.h" #include "check_classname.h"
#include "java_lang_ClassLoader.h" #include "java_lang_ClassLoader.h"
#include <string.h> #include "jlong.h"
#include "jni.h"
#include "jni_util.h"
#include "jvm.h"
static JNINativeMethod methods[] = { static JNINativeMethod methods[] = {
{"retrieveDirectives", "()Ljava/lang/AssertionStatusDirectives;", (void *)&JVM_AssertionStatusDirectives} {"retrieveDirectives", "()Ljava/lang/AssertionStatusDirectives;", (void *)&JVM_AssertionStatusDirectives}
@ -88,7 +88,7 @@ Java_java_lang_ClassLoader_defineClass1(JNIEnv *env,
if (data == NULL) { if (data == NULL) {
JNU_ThrowNullPointerException(env, 0); JNU_ThrowNullPointerException(env, 0);
return 0; return NULL;
} }
/* Work around 4153825. malloc crashes on Solaris when passed a /* Work around 4153825. malloc crashes on Solaris when passed a
@ -96,25 +96,27 @@ Java_java_lang_ClassLoader_defineClass1(JNIEnv *env,
*/ */
if (length < 0) { if (length < 0) {
JNU_ThrowArrayIndexOutOfBoundsException(env, 0); JNU_ThrowArrayIndexOutOfBoundsException(env, 0);
return 0; return NULL;
} }
// On AIX malloc(0) returns NULL which looks like an out-of-memory condition; so adjust it to malloc(1) // On AIX malloc(0) returns NULL which looks like an out-of-memory
// condition; so adjust it to malloc(1)
#ifdef _AIX #ifdef _AIX
body = (jbyte *)malloc(length == 0 ? 1 : length); body = (jbyte *)malloc(length == 0 ? 1 : length);
#else #else
body = (jbyte *)malloc(length); body = (jbyte *)malloc(length);
#endif #endif
if (body == 0) { if (body == NULL) {
JNU_ThrowOutOfMemoryError(env, 0); JNU_ThrowOutOfMemoryError(env, 0);
return 0; return NULL;
} }
(*env)->GetByteArrayRegion(env, data, offset, length, body); (*env)->GetByteArrayRegion(env, data, offset, length, body);
if ((*env)->ExceptionOccurred(env)) if ((*env)->ExceptionOccurred(env)) {
goto free_body; goto free_body;
}
if (name != NULL) { if (name != NULL) {
utfName = getUTF(env, name, buf, sizeof(buf)); utfName = getUTF(env, name, buf, sizeof(buf));
@ -173,9 +175,9 @@ Java_java_lang_ClassLoader_defineClass2(JNIEnv *env,
body = (*env)->GetDirectBufferAddress(env, data); body = (*env)->GetDirectBufferAddress(env, data);
if (body == 0) { if (body == NULL) {
JNU_ThrowNullPointerException(env, 0); JNU_ThrowNullPointerException(env, 0);
return 0; return NULL;
} }
body += offset; body += offset;
@ -233,7 +235,7 @@ Java_java_lang_ClassLoader_defineClass0(JNIEnv *env,
if (data == NULL) { if (data == NULL) {
JNU_ThrowNullPointerException(env, 0); JNU_ThrowNullPointerException(env, 0);
return 0; return NULL;
} }
/* Work around 4153825. malloc crashes on Solaris when passed a /* Work around 4153825. malloc crashes on Solaris when passed a
@ -241,19 +243,20 @@ Java_java_lang_ClassLoader_defineClass0(JNIEnv *env,
*/ */
if (length < 0) { if (length < 0) {
JNU_ThrowArrayIndexOutOfBoundsException(env, 0); JNU_ThrowArrayIndexOutOfBoundsException(env, 0);
return 0; return NULL;
} }
// On AIX malloc(0) returns NULL which looks like an out-of-memory condition; so adjust it to malloc(1) // On AIX malloc(0) returns NULL which looks like an out-of-memory
// condition; so adjust it to malloc(1)
#ifdef _AIX #ifdef _AIX
body = (jbyte *)malloc(length == 0 ? 1 : length); body = (jbyte *)malloc(length == 0 ? 1 : length);
#else #else
body = (jbyte *)malloc(length); body = (jbyte *)malloc(length);
#endif #endif
if (body == 0) { if (body == NULL) {
JNU_ThrowOutOfMemoryError(env, 0); JNU_ThrowOutOfMemoryError(env, 0);
return 0; return NULL;
} }
(*env)->GetByteArrayRegion(env, data, offset, length, body); (*env)->GetByteArrayRegion(env, data, offset, length, body);
@ -293,7 +296,7 @@ Java_java_lang_ClassLoader_findBootstrapClass(JNIEnv *env, jclass dummy,
char buf[128]; char buf[128];
if (classname == NULL) { if (classname == NULL) {
return 0; return NULL;
} }
clname = getUTF(env, classname, buf, sizeof(buf)); clname = getUTF(env, classname, buf, sizeof(buf));
@ -322,7 +325,7 @@ Java_java_lang_ClassLoader_findLoadedClass0(JNIEnv *env, jobject loader,
jstring name) jstring name)
{ {
if (name == NULL) { if (name == NULL) {
return 0; return NULL;
} else { } else {
return JVM_FindLoadedClass(env, loader, name); return JVM_FindLoadedClass(env, loader, name);
} }