1 /* src/native/vm/java_lang_ClassLoader.c - java/lang/ClassLoader
3 Copyright (C) 2007 R. Grafl, A. Krall, C. Kruegel,
4 C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5 E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6 J. Wenninger, Institut f. Computersprachen - TU Wien
8 This file is part of CACAO.
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License as
12 published by the Free Software Foundation; either version 2, or (at
13 your option) any later version.
15 This program is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
35 #include "mm/memory.h"
37 #include "vm/global.h" /* required by native headers */
39 #include "native/jni.h"
40 #include "native/llni.h"
42 /* keep this order of the native includes */
44 #include "native/include/java_lang_Object.h"
46 #if defined(ENABLE_JAVASE)
47 # include "native/include/java_lang_String.h" /* required by j.l.C */
49 # if defined(WITH_CLASSPATH_SUN)
50 # include "native/include/java_nio_ByteBuffer.h" /* required by j.l.CL */
53 # include "native/include/java_lang_ClassLoader.h" /* required by j.l.C */
54 # include "native/include/java_lang_Class.h"
55 # include "native/include/java_security_ProtectionDomain.h"
58 #include "vm/exceptions.h"
59 #include "vm/stringlocal.h"
61 #include "vmcore/class.h"
62 #include "vmcore/classcache.h"
63 #include "vmcore/options.h"
65 #if defined(ENABLE_STATISTICS)
66 # include "vmcore/statistics.h"
71 * Class: java/lang/ClassLoader
73 * Signature: (Ljava/lang/ClassLoader;Ljava/lang/String;[BIILjava/security/ProtectionDomain;)Ljava/lang/Class;
75 java_lang_Class *_Jv_java_lang_ClassLoader_defineClass(java_lang_ClassLoader *cl, java_lang_String *name, java_handle_bytearray_t *data, s4 offset, s4 len, java_security_ProtectionDomain *pd)
82 #if defined(ENABLE_JVMTI)
83 jint new_class_data_len = 0;
84 unsigned char* new_class_data = NULL;
87 /* check if data was passed */
90 exceptions_throw_nullpointerexception();
94 /* check the indexes passed */
96 if ((offset < 0) || (len < 0) || ((offset + len) > LLNI_array_size(data))) {
97 exceptions_throw_arrayindexoutofboundsexception();
101 /* add classloader to classloader hashtable */
104 loader = loader_hashtable_classloader_add((java_handle_t *) cl);
107 /* convert '.' to '/' in java string */
109 utfname = javastring_toutf((java_handle_t *) name, true);
115 #if defined(ENABLE_JVMTI)
116 /* XXX again this will not work because of the indirection cell for classloaders */
118 /* fire Class File Load Hook JVMTI event */
121 jvmti_ClassFileLoadHook(utfname, len, (unsigned char *) data->data,
122 loader, (java_handle_t *) pd,
123 &new_class_data_len, &new_class_data);
126 /* define the class */
128 #if defined(ENABLE_JVMTI)
129 /* check if the JVMTI wants to modify the class */
131 if (new_class_data == NULL)
132 c = class_define(utfname, loader, new_class_data_len, new_class_data);
135 c = class_define(utfname, loader, len, (const uint8_t *) &LLNI_array_direct(data, offset));
140 /* for convenience */
142 o = LLNI_classinfo_wrap(c);
144 #if defined(WITH_CLASSPATH_GNU)
145 /* set ProtectionDomain */
147 LLNI_field_set_ref(o, pd, pd);
155 * These are local overrides for various environment variables in Emacs.
156 * Please do not remove this and leave it at the end of the file, where
157 * Emacs will automagically detect them.
158 * ---------------------------------------------------------------------
161 * indent-tabs-mode: t
165 * vim:noexpandtab:sw=4:ts=4: