Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/native/java/lang/reflect/Proxy.c
38918 views
/*1* Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425#include <stdlib.h>2627#include "jni.h"28#include "jni_util.h"2930#include "java_lang_reflect_Proxy.h"3132/* defined in libverify.so/verify.dll (src file common/check_format.c) */33extern jboolean VerifyFixClassname(char *utf_name);3435/*36* Class: java_lang_reflect_Proxy37* Method: defineClass038* Signature: (Ljava/lang/ClassLoader;Ljava/lang/String;[BII)Ljava/lang/Class;39*40* The implementation of this native static method is a copy of that of41* the native instance method Java_java_lang_ClassLoader_defineClass0()42* with the implicit "this" parameter becoming the "loader" parameter.43*/44JNIEXPORT jclass JNICALL45Java_java_lang_reflect_Proxy_defineClass0(JNIEnv *env,46jclass ignore,47jobject loader,48jstring name,49jbyteArray data,50jint offset,51jint length)52{53jbyte *body;54char *utfName;55jclass result = 0;56char buf[128];5758if (data == NULL) {59JNU_ThrowNullPointerException(env, 0);60return 0;61}6263/* Work around 4153825. malloc crashes on Solaris when passed a64* negative size.65*/66if (length < 0) {67JNU_ThrowArrayIndexOutOfBoundsException(env, 0);68return 0;69}7071body = (jbyte *)malloc(length);7273if (body == 0) {74JNU_ThrowOutOfMemoryError(env, 0);75return 0;76}7778(*env)->GetByteArrayRegion(env, data, offset, length, body);7980if ((*env)->ExceptionOccurred(env))81goto free_body;8283if (name != NULL) {84jsize len = (*env)->GetStringUTFLength(env, name);85jsize unicode_len = (*env)->GetStringLength(env, name);86if (len >= (jsize)sizeof(buf)) {87utfName = malloc(len + 1);88if (utfName == NULL) {89JNU_ThrowOutOfMemoryError(env, NULL);90goto free_body;91}92} else {93utfName = buf;94}95(*env)->GetStringUTFRegion(env, name, 0, unicode_len, utfName);96VerifyFixClassname(utfName);97} else {98utfName = NULL;99}100101result = (*env)->DefineClass(env, utfName, loader, body, length);102103if (utfName && utfName != buf)104free(utfName);105106free_body:107free(body);108return result;109}110111112