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
25 $Id: java_lang_VMClass.c 6131 2006-12-06 22:15:57Z twisti $
37 #include "mm/memory.h"
39 #include "vm/global.h" /* required by native headers */
41 #include "native/jni.h"
42 #include "native/llni.h"
44 /* keep this order of the native includes */
46 #include "native/include/java_lang_Object.h"
48 #if defined(ENABLE_JAVASE)
49 # include "native/include/java_lang_String.h" /* required by j.l.C */
51 # if defined(WITH_CLASSPATH_SUN)
52 # include "native/include/java_nio_ByteBuffer.h" /* required by j.l.CL */
55 # include "native/include/java_lang_ClassLoader.h" /* required by j.l.C */
56 # include "native/include/java_lang_Class.h"
57 # include "native/include/java_security_ProtectionDomain.h"
60 #include "vm/exceptions.h"
61 #include "vm/stringlocal.h"
63 #include "vmcore/class.h"
64 #include "vmcore/classcache.h"
65 #include "vmcore/options.h"
67 #if defined(ENABLE_STATISTICS)
68 # include "vmcore/statistics.h"
73 * Class: java/lang/ClassLoader
75 * Signature: (Ljava/lang/ClassLoader;Ljava/lang/String;[BIILjava/security/ProtectionDomain;)Ljava/lang/Class;
77 java_lang_Class *_Jv_java_lang_ClassLoader_defineClass(java_lang_ClassLoader *cl, java_lang_String *name, java_bytearray *data, s4 offset, s4 len, java_security_ProtectionDomain *pd)
84 #if defined(ENABLE_JVMTI)
85 jint new_class_data_len = 0;
86 unsigned char* new_class_data = NULL;
89 /* check if data was passed */
92 exceptions_throw_nullpointerexception();
96 /* check the indexes passed */
98 if ((offset < 0) || (len < 0) || ((offset + len) > data->header.size)) {
99 exceptions_throw_arrayindexoutofboundsexception();
103 /* add classloader to classloader hashtable */
106 loader = loader_hashtable_classloader_add((java_objectheader *) cl);
109 /* convert '.' to '/' in java string */
111 utfname = javastring_toutf((java_handle_t *) name, true);
117 #if defined(ENABLE_JVMTI)
118 /* XXX again this will not work because of the indirection cell for classloaders */
120 /* fire Class File Load Hook JVMTI event */
123 jvmti_ClassFileLoadHook(utfname, len, (unsigned char *) data->data,
124 loader, (java_handle_t *) pd,
125 &new_class_data_len, &new_class_data);
128 /* define the class */
130 #if defined(ENABLE_JVMTI)
131 /* check if the JVMTI wants to modify the class */
133 if (new_class_data == NULL)
134 c = class_define(utfname, loader, new_class_data_len, new_class_data);
137 c = class_define(utfname, loader, len, (const uint8_t *) &data->data[offset]);
142 /* for convenience */
144 o = (java_lang_Class *) c;
146 #if defined(WITH_CLASSPATH_GNU)
147 /* set ProtectionDomain */
149 LLNI_field_set_ref(o, pd, pd);
157 * These are local overrides for various environment variables in Emacs.
158 * Please do not remove this and leave it at the end of the file, where
159 * Emacs will automagically detect them.
160 * ---------------------------------------------------------------------
163 * indent-tabs-mode: t
167 * vim:noexpandtab:sw=4:ts=4: