1 /* native/vm/VMClassLoader.c - java/lang/VMClassLoader
3 Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,
4 R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
5 C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
6 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., 59 Temple Place - Suite 330, Boston, MA
25 Contact: cacao@complang.tuwien.ac.at
27 Authors: Roman Obermaiser
29 Changes: Joseph Wenninger
31 $Id: VMClassLoader.c 1735 2004-12-07 14:33:27Z twisti $
36 #include "native/jni.h"
37 #include "native/native.h"
38 #include "native/include/java_lang_Class.h"
39 #include "native/include/java_lang_String.h"
40 #include "native/include/java_lang_ClassLoader.h"
41 #include "toolbox/logging.h"
42 #include "vm/exceptions.h"
43 #include "vm/builtin.h"
44 #include "vm/loader.h"
45 #include "vm/tables.h"
49 * Class: java/lang/ClassLoader
51 * Signature: (Ljava/lang/String;[BII)Ljava/lang/Class;
53 JNIEXPORT java_lang_Class* JNICALL Java_java_lang_VMClassLoader_defineClass(JNIEnv *env, jclass clazz, java_lang_ClassLoader *this, java_lang_String *name, java_bytearray *buf, s4 off, s4 len)
57 log_text("Java_java_lang_VMClassLoader_defineClass called");
59 if (off < 0 || len < 0 || off + len > buf->header.size) {
61 new_exception(string_java_lang_IndexOutOfBoundsException);
65 /* call JNI-function to load the class */
66 c = (*env)->DefineClass(env,
67 javastring_tochar((java_objectheader *) name),
69 (const jbyte *) &buf->data[off],
72 /* exception? return! */
76 use_class_as_object(c);
78 return (java_lang_Class *) c;
83 * Class: java/lang/ClassLoader
84 * Method: getPrimitiveClass
85 * Signature: (Ljava/lang/String;)Ljava/lang/Class;
87 JNIEXPORT java_lang_Class* JNICALL Java_java_lang_VMClassLoader_getPrimitiveClass(JNIEnv *env, jclass clazz, java_lang_String *name)
90 utf *u = javastring_toutf(name, false);
92 /* illegal primitive classname specified */
94 *exceptionptr = new_exception(string_java_lang_ClassNotFoundException);
98 /* get primitive class */
107 use_class_as_object(c);
109 return (java_lang_Class *) c;
114 * Class: java/lang/ClassLoader
115 * Method: resolveClass
116 * Signature: (Ljava/lang/Class;)V
118 JNIEXPORT void JNICALL Java_java_lang_VMClassLoader_resolveClass(JNIEnv *env, jclass clazz, java_lang_Class *c)
122 ci = (classinfo *) c;
125 *exceptionptr = new_exception(string_java_lang_NullPointerException);
138 * Class: java/lang/VMClassLoader
140 * Signature: (Ljava/lang/String;Z)Ljava/lang/Class;
142 JNIEXPORT java_lang_Class* JNICALL Java_java_lang_VMClassLoader_loadClass(JNIEnv *env, jclass clazz, java_lang_String *name, jboolean resolve)
148 *exceptionptr = new_exception(string_java_lang_NullPointerException);
152 /* create utf string in which '.' is replaced by '/' */
153 u = javastring_toutf(name, true);
159 if (!class_load(c)) {
162 xclass = (*exceptionptr)->vftbl->class;
164 /* if the exception is a NoClassDefFoundError, we replace it with a
165 ClassNotFoundException, otherwise return the exception */
167 if (xclass == class_get(utf_new_char(string_java_lang_NoClassDefFoundError))) {
168 /* clear exceptionptr, because builtin_new checks for
169 ExceptionInInitializerError */
170 *exceptionptr = NULL;
173 new_exception_javastring(string_java_lang_ClassNotFoundException, name);
179 /* resolve class -- if requested */
180 /* XXX TWISTI: we do not support REAL (at runtime) lazy linking */
185 use_class_as_object(c);
187 return (java_lang_Class *) c;
192 * These are local overrides for various environment variables in Emacs.
193 * Please do not remove this and leave it at the end of the file, where
194 * Emacs will automagically detect them.
195 * ---------------------------------------------------------------------
198 * indent-tabs-mode: t