prefix to filenames.
* src/native/vm/VMClassLoader.c: Removed.
* src/native/vm/VMThrowable.c: Likewise.
* src/native/vm/VMAccessController.c: Likewise.
* src/native/vm/VMString.c: Likewise.
* src/native/vm/VMObject.c: Likewise.
* src/native/vm/VMStackWalker.c: Likewise.
* src/native/vm/Field.c: Likewise.
* src/native/vm/VMSystem.c: Likewise.
* src/native/vm/VMSystemProperties.c: Likewise.
* src/native/vm/VMClass.c: Likewise.
* src/native/vm/VMThread.c: Likewise.
* src/native/vm/Method.c: Likewise.
* src/native/vm/VMProxy.c: Likewise.
* src/native/vm/Constructor.c: Likewise.
* src/native/vm/VMRuntime.c: Likewise.
* src/native/vm/gnu_classpath_VMStackWalker.c: Added.
* src/native/vm/java_lang_VMSystem.c: Likewise.
* src/native/vm/java_lang_reflect_Method.c: Likewise.
* src/native/vm/java_lang_VMObject.c: Likewise.
* src/native/vm/java_lang_VMString.c: Likewise.
* src/native/vm/gnu_classpath_VMSystemProperties.c: Likewise.
* src/native/vm/java_lang_VMRuntime.c: Likewise.
* src/native/vm/java_lang_reflect_Field.c: Likewise.
* src/native/vm/java_lang_VMThrowable.c: Likewise.
* src/native/vm/java_lang_VMClassLoader.c: Likewise.
* src/native/vm/java_lang_VMClass.c: Likewise.
* src/native/vm/java_lang_VMThread.c: Likewise.
* src/native/vm/java_security_VMAccessController.c: Likewise.
* src/native/vm/java_lang_reflect_VMProxy.c: Likewise.
* src/native/vm/java_lang_reflect_Constructor.c: Likewise.
--HG--
rename : src/native/vm/VMStackWalker.c => src/native/vm/gnu_classpath_VMStackWalker.c
rename : src/native/vm/VMSystemProperties.c => src/native/vm/gnu_classpath_VMSystemProperties.c
rename : src/native/vm/VMClass.c => src/native/vm/java_lang_VMClass.c
rename : src/native/vm/VMClassLoader.c => src/native/vm/java_lang_VMClassLoader.c
rename : src/native/vm/VMObject.c => src/native/vm/java_lang_VMObject.c
rename : src/native/vm/VMRuntime.c => src/native/vm/java_lang_VMRuntime.c
rename : src/native/vm/VMString.c => src/native/vm/java_lang_VMString.c
rename : src/native/vm/VMSystem.c => src/native/vm/java_lang_VMSystem.c
rename : src/native/vm/VMThread.c => src/native/vm/java_lang_VMThread.c
rename : src/native/vm/VMThrowable.c => src/native/vm/java_lang_VMThrowable.c
rename : src/native/vm/Constructor.c => src/native/vm/java_lang_reflect_Constructor.c
rename : src/native/vm/Field.c => src/native/vm/java_lang_reflect_Field.c
rename : src/native/vm/Method.c => src/native/vm/java_lang_reflect_Method.c
rename : src/native/vm/VMProxy.c => src/native/vm/java_lang_reflect_VMProxy.c
rename : src/native/vm/VMAccessController.c => src/native/vm/java_security_VMAccessController.c
+++ /dev/null
-/* src/native/vm/Constructor.c - java/lang/reflect/Constructor
-
- Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
- C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
- E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
- J. Wenninger, Institut f. Computersprachen - TU Wien
-
- This file is part of CACAO.
-
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License as
- published by the Free Software Foundation; either version 2, or (at
- your option) any later version.
-
- This program is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- 02110-1301, USA.
-
- Contact: cacao@cacaojvm.org
-
- Authors: Roman Obermaiser
-
- Changes: Joseph Wenninger
- Christian Thalinger
-
- $Id: Constructor.c 4691 2006-03-28 09:41:33Z twisti $
-
-*/
-
-
-#include "config.h"
-
-#include <assert.h>
-#include <stdlib.h>
-
-#include "vm/types.h"
-
-#include "native/jni.h"
-#include "native/native.h"
-#include "native/include/java_lang_Class.h"
-#include "native/include/java_lang_Object.h"
-#include "native/include/java_lang_reflect_Constructor.h"
-#include "toolbox/logging.h"
-#include "vm/class.h"
-#include "vm/exceptions.h"
-#include "vm/method.h"
-#include "vm/stringlocal.h"
-
-
-/*
- * Class: java/lang/reflect/Constructor
- * Method: newInstance
- * Signature: ([Ljava/lang/Object;)Ljava/lang/Object;
- */
-JNIEXPORT java_lang_Object* JNICALL Java_java_lang_reflect_Constructor_constructNative(JNIEnv *env, java_lang_reflect_Constructor *this, java_objectarray *args, java_lang_Class *declaringClass, s4 slot)
-{
- classinfo *c;
- methodinfo *m;
- java_objectheader *o;
-
- c = (classinfo *) declaringClass;
-
-#if 0
- /* find initializer */
-
- if (!args) {
- if (this->parameterTypes->header.size != 0) {
- *exceptionptr =
- new_exception_message(string_java_lang_IllegalArgumentException,
- "wrong number of arguments");
- return NULL;
- }
-
- } else {
- if (this->parameterTypes->header.size != args->header.size) {
- *exceptionptr =
- new_exception_message(string_java_lang_IllegalArgumentException,
- "wrong number of arguments");
- return NULL;
- }
- }
-#endif
-
- if (this->slot >= c->methodscount) {
- log_text("illegal index in methods table");
- return NULL;
- }
-
- /* create object */
-
- o = builtin_new(c);
-
- if (!o)
- return NULL;
-
- m = &(c->methods[this->slot]);
-
- if (m->name != utf_init) {
- /* XXX throw an exception here, although this should never happen */
-
- assert(0);
- }
-
- /* call initializer */
-
- (void) _Jv_jni_invokeNative(m, o, args);
-
- return (java_lang_Object *) o;
-}
-
-
-/*
- * Class: java/lang/reflect/Constructor
- * Method: getModifiersInternal
- * Signature: ()I
- */
-JNIEXPORT s4 JNICALL Java_java_lang_reflect_Constructor_getModifiersInternal(JNIEnv *env, java_lang_reflect_Constructor *this)
-{
- classinfo *c;
- methodinfo *m;
-
- c = (classinfo *) (this->clazz);
- m = &(c->methods[this->slot]);
-
- return m->flags;
-}
-
-
-/*
- * Class: java/lang/reflect/Constructor
- * Method: getParameterTypes
- * Signature: ()[Ljava/lang/Class;
- */
-JNIEXPORT java_objectarray* JNICALL Java_java_lang_reflect_Constructor_getParameterTypes(JNIEnv *env, java_lang_reflect_Constructor *this)
-{
- classinfo *c;
- methodinfo *m;
-
- c = (classinfo *) this->clazz;
-
- if ((this->slot < 0) || (this->slot >= c->methodscount)) {
- log_text("error illegal slot for constructor in class");
- assert(0);
- }
-
- m = &(c->methods[this->slot]);
-
- return native_get_parametertypes(m);
-}
-
-
-/*
- * Class: java/lang/reflect/Constructor
- * Method: getExceptionTypes
- * Signature: ()[Ljava/lang/Class;
- */
-JNIEXPORT java_objectarray* JNICALL Java_java_lang_reflect_Constructor_getExceptionTypes(JNIEnv *env, java_lang_reflect_Constructor *this)
-{
- classinfo *c;
- methodinfo *m;
-
- c = (classinfo *) this->clazz;
-
- if ((this->slot < 0) || (this->slot >= c->methodscount)) {
- log_text("error illegal slot for constructor in class");
- assert(0);
- }
-
- m = &(c->methods[this->slot]);
-
- return native_get_exceptiontypes(m);
-}
-
-
-/*
- * These are local overrides for various environment variables in Emacs.
- * Please do not remove this and leave it at the end of the file, where
- * Emacs will automagically detect them.
- * ---------------------------------------------------------------------
- * Local variables:
- * mode: c
- * indent-tabs-mode: t
- * c-basic-offset: 4
- * tab-width: 4
- * End:
- */
+++ /dev/null
-/* src/native/vm/Field.c - java/lang/reflect/Field
-
- Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
- C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
- E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
- J. Wenninger, Institut f. Computersprachen - TU Wien
-
- This file is part of CACAO.
-
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License as
- published by the Free Software Foundation; either version 2, or (at
- your option) any later version.
-
- This program is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- 02110-1301, USA.
-
- Contact: cacao@cacaojvm.org
-
- Authors: Roman Obermaiser
-
- Changes: Joseph Wenninger
- Christian Thalinger
-
- $Id: Field.c 4807 2006-04-21 13:08:00Z edwin $
-
-*/
-
-
-#include "config.h"
-
-#include <assert.h>
-
-#include "vm/types.h"
-
-#include "native/jni.h"
-#include "native/native.h"
-#include "native/include/java_lang_Boolean.h"
-#include "native/include/java_lang_Byte.h"
-#include "native/include/java_lang_Character.h"
-#include "native/include/java_lang_Short.h"
-#include "native/include/java_lang_Integer.h"
-#include "native/include/java_lang_Long.h"
-#include "native/include/java_lang_Float.h"
-#include "native/include/java_lang_Double.h"
-#include "native/include/java_lang_Object.h"
-#include "native/include/java_lang_Class.h"
-#include "native/include/java_lang_reflect_Field.h"
-#include "vm/access.h"
-#include "vm/builtin.h"
-#include "vm/exceptions.h"
-#include "vm/global.h"
-#include "vm/initialize.h"
-#include "vm/loader.h"
-#include "vm/resolve.h"
-#include "vm/stringlocal.h"
-#include "vm/utf8.h"
-#include "vm/jit/stacktrace.h"
-
-
-#define CHECKFIELDACCESS(this,fi,c,doret)
-
-
-/* cacao_get_field_address *****************************************************
-
- Return the address of a field of an object.
-
- IN:
- this.........the field (a java.lang.reflect.Field object)
- o............the object of which to get the field
-
- RETURN VALUE:
- a pointer to the field, or
- NULL if an exception has been thrown
-
-*******************************************************************************/
-
-static void *cacao_get_field_address(java_lang_reflect_Field *this,
- java_lang_Object *o)
-{
- classinfo *c;
- fieldinfo *f;
- java_objectarray *oa;
- classinfo *callerclass;
-
- c = (classinfo *) this->declaringClass;
- f = &c->fields[this->slot];
-
- /* check field access */
-
- if (!(f->flags & ACC_PUBLIC)) {
- /* check if we should bypass security checks (AccessibleObject) */
-
- if (this->flag == false) {
- /* get the calling class */
-
- oa = stacktrace_getClassContext();
- if (!oa)
- return NULL;
-
- /* this function is always called like this:
-
- java.lang.reflect.Field.xxx (Native Method)
- [0] <caller>
- */
-
- callerclass = (classinfo *) oa->data[0];
-
- if (!access_is_accessible_member(callerclass, c, f->flags)) {
- *exceptionptr =
- new_exception(string_java_lang_IllegalAccessException);
- return NULL;
- }
- }
- }
-
- /* get the address of the field */
-
- if (f->flags & ACC_STATIC) {
- /* initialize class if required */
-
- if (!(c->state & CLASS_INITIALIZED))
- if (!initialize_class(c))
- return NULL;
-
- /* return value address */
-
- return &(f->value);
-
- } else {
- /* obj is required for not-static fields */
-
- if (o == NULL) {
- exceptions_throw_nullpointerexception();
- return NULL;
- }
-
- if (builtin_instanceof((java_objectheader *) o, c))
- return (void *) ((ptrint) o + f->offset);
- }
-
- /* exception path */
-
- exceptions_throw_illegalargumentexception();
-
- return NULL;
-}
-
-
-/*
- * Class: java/lang/reflect/Field
- * Method: get
- * Signature: (Ljava/lang/Object;)Ljava/lang/Object;
- */
-JNIEXPORT java_lang_Object* JNICALL Java_java_lang_reflect_Field_get(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o)
-{
- classinfo *c;
- fieldinfo *f;
- void *addr;
-
- c = (classinfo *) this->declaringClass;
- f = &c->fields[this->slot];
-
- /* get address of the source field value */
-
- if ((addr = cacao_get_field_address(this, o)) == NULL)
- return NULL;
-
- switch (f->parseddesc->decltype) {
- case PRIMITIVETYPE_BOOLEAN: {
- java_lang_Boolean *bo;
-
- /* create wrapping class */
-
- if (!(bo = (java_lang_Boolean *) builtin_new(class_java_lang_Boolean)))
- return NULL;
-
- /* set the object value */
-
- bo->value = *((s4 *) addr);
-
- /* return the wrapped object */
-
- return (java_lang_Object *) bo;
- }
-
- case PRIMITIVETYPE_BYTE: {
- java_lang_Byte *bo;
-
- if (!(bo = (java_lang_Byte *) builtin_new(class_java_lang_Byte)))
- return NULL;
-
- bo->value = *((s4 *) addr);
-
- return (java_lang_Object *) bo;
- }
-
- case PRIMITIVETYPE_CHAR: {
- java_lang_Character *co;
-
- if (!(co = (java_lang_Character *) builtin_new(class_java_lang_Character)))
- return NULL;
-
- co->value = *((s4 *) addr);
-
- return (java_lang_Object *) co;
- }
-
- case PRIMITIVETYPE_SHORT: {
- java_lang_Short *so;
-
- if (!(so = (java_lang_Short *) builtin_new(class_java_lang_Short)))
- return NULL;
-
- so->value = (s4) *((s4 *) addr);
-
- return (java_lang_Object *) so;
- }
-
- case PRIMITIVETYPE_INT: {
- java_lang_Integer *io;
-
- if (!(io = (java_lang_Integer *) builtin_new(class_java_lang_Integer)))
- return NULL;
-
- io->value = *((s4 *) addr);
-
- return (java_lang_Object *) io;
- }
-
- case PRIMITIVETYPE_LONG: {
- java_lang_Long *lo;
-
- if (!(lo = (java_lang_Long *) builtin_new(class_java_lang_Long)))
- return NULL;
-
- lo->value = *((s8 *) addr);
-
- return (java_lang_Object *) lo;
- }
-
- case PRIMITIVETYPE_FLOAT: {
- java_lang_Float *fo;
-
- if (!(fo = (java_lang_Float *) builtin_new(class_java_lang_Float)))
- return NULL;
-
- fo->value = *((float *) addr);
-
- return (java_lang_Object *) fo;
- }
-
- case PRIMITIVETYPE_DOUBLE: {
- java_lang_Double *_do;
-
- if (!(_do = (java_lang_Double *) builtin_new(class_java_lang_Double)))
- return NULL;
-
- _do->value = *((double *) addr);
-
- return (java_lang_Object *) _do;
- }
-
- case TYPE_ADR:
- return (java_lang_Object *) *((java_objectheader **) addr);
- }
-
- /* this must not happen */
-
- assert(0);
-
- /* keep compiler happy */
-
- return NULL;
-}
-
-
-/*
- * Class: java/lang/reflect/Field
- * Method: getBoolean
- * Signature: (Ljava/lang/Object;)Z
- */
-JNIEXPORT s4 JNICALL Java_java_lang_reflect_Field_getBoolean(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o)
-{
- classinfo *c;
- fieldinfo *f;
- void *addr;
-
- /* get the class and the field */
-
- c = (classinfo *) this->declaringClass;
- f = &c->fields[this->slot];
-
- /* get the address of the field with an internal helper */
-
- if ((addr = cacao_get_field_address(this, o)) == NULL)
- return 0;
-
- /* check the field type and return the value */
-
- switch (f->parseddesc->decltype) {
- case PRIMITIVETYPE_BOOLEAN:
- return (s4) *((s4 *) addr);
- default:
- exceptions_throw_illegalargumentexception();
- return 0;
- }
-}
-
-
-/*
- * Class: java/lang/reflect/Field
- * Method: getByte
- * Signature: (Ljava/lang/Object;)B
- */
-JNIEXPORT s4 JNICALL Java_java_lang_reflect_Field_getByte(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o)
-{
- classinfo *c;
- fieldinfo *f;
- void *addr;
-
- /* get the class and the field */
-
- c = (classinfo *) this->declaringClass;
- f = &c->fields[this->slot];
-
- /* get the address of the field with an internal helper */
-
- if ((addr = cacao_get_field_address(this, o)) == NULL)
- return 0;
-
- /* check the field type and return the value */
-
- switch (f->parseddesc->decltype) {
- case PRIMITIVETYPE_BYTE:
- return (s4) *((s4 *) addr);
- default:
- exceptions_throw_illegalargumentexception();
- return 0;
- }
-}
-
-
-/*
- * Class: java/lang/reflect/Field
- * Method: getChar
- * Signature: (Ljava/lang/Object;)C
- */
-JNIEXPORT s4 JNICALL Java_java_lang_reflect_Field_getChar(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o)
-{
- classinfo *c;
- fieldinfo *f;
- void *addr;
-
- /* get the class and the field */
-
- c = (classinfo *) this->declaringClass;
- f = &c->fields[this->slot];
-
- /* get the address of the field with an internal helper */
-
- if ((addr = cacao_get_field_address(this, o)) == NULL)
- return 0;
-
- /* check the field type and return the value */
-
- switch (f->parseddesc->decltype) {
- case PRIMITIVETYPE_CHAR:
- return (s4) *((s4 *) addr);
- default:
- exceptions_throw_illegalargumentexception();
- return 0;
- }
-}
-
-
-/*
- * Class: java/lang/reflect/Field
- * Method: getShort
- * Signature: (Ljava/lang/Object;)S
- */
-JNIEXPORT s4 JNICALL Java_java_lang_reflect_Field_getShort(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o)
-{
- classinfo *c;
- fieldinfo *f;
- void *addr;
-
- /* get the class and the field */
-
- c = (classinfo *) this->declaringClass;
- f = &c->fields[this->slot];
-
- /* get the address of the field with an internal helper */
-
- if ((addr = cacao_get_field_address(this, o)) == NULL)
- return 0;
-
- /* check the field type and return the value */
-
- switch (f->parseddesc->decltype) {
- case PRIMITIVETYPE_BYTE:
- case PRIMITIVETYPE_SHORT:
- return (s4) *((s4 *) addr);
- default:
- exceptions_throw_illegalargumentexception();
- return 0;
- }
-}
-
-
-/*
- * Class: java/lang/reflect/Field
- * Method: getInt
- * Signature: (Ljava/lang/Object;)I
- */
-JNIEXPORT s4 JNICALL Java_java_lang_reflect_Field_getInt(JNIEnv *env , java_lang_reflect_Field *this, java_lang_Object *o)
-{
- classinfo *c;
- fieldinfo *f;
- void *addr;
-
- /* get the class and the field */
-
- c = (classinfo *) this->declaringClass;
- f = &c->fields[this->slot];
-
- /* get the address of the field with an internal helper */
-
- if ((addr = cacao_get_field_address(this, o)) == NULL)
- return 0;
-
- /* check the field type and return the value */
-
- switch (f->parseddesc->decltype) {
- case PRIMITIVETYPE_BYTE:
- case PRIMITIVETYPE_CHAR:
- case PRIMITIVETYPE_SHORT:
- case PRIMITIVETYPE_INT:
- return (s4) *((s4 *) addr);
- default:
- exceptions_throw_illegalargumentexception();
- return 0;
- }
-}
-
-
-/*
- * Class: java/lang/reflect/Field
- * Method: getLong
- * Signature: (Ljava/lang/Object;)J
- */
-JNIEXPORT s8 JNICALL Java_java_lang_reflect_Field_getLong(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o)
-{
- classinfo *c;
- fieldinfo *f;
- void *addr;
-
- /* get the class and the field */
-
- c = (classinfo *) this->declaringClass;
- f = &c->fields[this->slot];
-
- /* get the address of the field with an internal helper */
-
- if ((addr = cacao_get_field_address(this, o)) == NULL)
- return 0;
-
- /* check the field type and return the value */
-
- switch (f->parseddesc->decltype) {
- case PRIMITIVETYPE_BYTE:
- case PRIMITIVETYPE_CHAR:
- case PRIMITIVETYPE_SHORT:
- case PRIMITIVETYPE_INT:
- return (s8) *((s4 *) addr);
- case PRIMITIVETYPE_LONG:
- return (s8) *((s8 *) addr);
- default:
- exceptions_throw_illegalargumentexception();
- return 0;
- }
-}
-
-
-/*
- * Class: java/lang/reflect/Field
- * Method: getFloat
- * Signature: (Ljava/lang/Object;)F
- */
-JNIEXPORT float JNICALL Java_java_lang_reflect_Field_getFloat(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o)
-{
- classinfo *c;
- fieldinfo *f;
- void *addr;
-
- /* get the class and the field */
-
- c = (classinfo *) this->declaringClass;
- f = &c->fields[this->slot];
-
- /* get the address of the field with an internal helper */
-
- if ((addr = cacao_get_field_address(this, o)) == NULL)
- return 0;
-
- /* check the field type and return the value */
-
- switch (f->parseddesc->decltype) {
- case PRIMITIVETYPE_BYTE:
- case PRIMITIVETYPE_CHAR:
- case PRIMITIVETYPE_SHORT:
- case PRIMITIVETYPE_INT:
- return (float) *((s4 *) addr);
- case PRIMITIVETYPE_LONG:
- return (float) *((s8 *) addr);
- case PRIMITIVETYPE_FLOAT:
- return (float) *((float *) addr);
- default:
- exceptions_throw_illegalargumentexception();
- return 0;
- }
-}
-
-
-/*
- * Class: java/lang/reflect/Field
- * Method: getDouble
- * Signature: (Ljava/lang/Object;)D
- */
-JNIEXPORT double JNICALL Java_java_lang_reflect_Field_getDouble(JNIEnv *env , java_lang_reflect_Field *this, java_lang_Object *o)
-{
- classinfo *c;
- fieldinfo *f;
- void *addr;
-
- /* get the class and the field */
-
- c = (classinfo *) this->declaringClass;
- f = &c->fields[this->slot];
-
- /* get the address of the field with an internal helper */
-
- if ((addr = cacao_get_field_address(this, o)) == NULL)
- return 0;
-
- /* check the field type and return the value */
-
- switch (f->parseddesc->decltype) {
- case PRIMITIVETYPE_BYTE:
- case PRIMITIVETYPE_CHAR:
- case PRIMITIVETYPE_SHORT:
- case PRIMITIVETYPE_INT:
- return (double) *((s4 *) addr);
- case PRIMITIVETYPE_LONG:
- return (double) *((s8 *) addr);
- case PRIMITIVETYPE_FLOAT:
- return (double) *((float *) addr);
- case PRIMITIVETYPE_DOUBLE:
- return (double) *((double *) addr);
- default:
- exceptions_throw_illegalargumentexception();
- return 0;
- }
-}
-
-
-/*
- * Class: java/lang/reflect/Field
- * Method: set
- * Signature: (Ljava/lang/Object;Ljava/lang/Object;)V
- */
-JNIEXPORT void JNICALL Java_java_lang_reflect_Field_set(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, java_lang_Object *value)
-{
- classinfo *sc;
- classinfo *dc;
- fieldinfo *sf;
- fieldinfo *df;
- void *faddr;
-
- /* get the class and the field */
-
- dc = (classinfo *) this->declaringClass;
- df = &dc->fields[this->slot];
-
- /* get the address of the destination field */
-
- if ((faddr = cacao_get_field_address(this, o)) == NULL)
- return;
-
- /* get the source classinfo from the object */
-
- if (value == NULL)
- sc = NULL;
- else
- sc = value->header.vftbl->class;
-
- /* The fieldid is used to set the new value, for primitive
- types the value has to be retrieved from the wrapping
- object */
-
- switch (df->parseddesc->decltype) {
- case PRIMITIVETYPE_BOOLEAN: {
- s4 val;
-
- /* determine the field to read the value */
-
- if ((sc == NULL) || !(sf = class_findfield(sc, utf_value, utf_Z)))
- break;
-
- switch (sf->parseddesc->decltype) {
- case PRIMITIVETYPE_BOOLEAN:
- val = ((java_lang_Boolean *) value)->value;
- break;
- default:
- exceptions_throw_illegalargumentexception();
- return;
- }
-
- *((s4 *) faddr) = val;
- return;
- }
-
- case PRIMITIVETYPE_BYTE: {
- s4 val;
-
- if ((sc == NULL) || !(sf = class_findfield(sc, utf_value, utf_B)))
- break;
-
- switch (sf->parseddesc->decltype) {
- case PRIMITIVETYPE_BYTE:
- val = ((java_lang_Byte *) value)->value;
- break;
- default:
- exceptions_throw_illegalargumentexception();
- return;
- }
-
- *((s4 *) faddr) = val;
- return;
- }
-
- case PRIMITIVETYPE_CHAR: {
- s4 val;
-
- if ((sc == NULL) || !(sf = class_findfield(sc, utf_value, utf_C)))
- break;
-
- switch (sf->parseddesc->decltype) {
- case PRIMITIVETYPE_CHAR:
- val = ((java_lang_Character *) value)->value;
- break;
- default:
- exceptions_throw_illegalargumentexception();
- return;
- }
-
- *((s4 *) faddr) = val;
- return;
- }
-
- case PRIMITIVETYPE_SHORT: {
- s4 val;
-
- /* get field only by name, it can be one of B, S */
-
- if ((sc == NULL) || !(sf = class_findfield_by_name(sc, utf_value)))
- break;
-
- switch (sf->parseddesc->decltype) {
- case PRIMITIVETYPE_BYTE:
- val = ((java_lang_Byte *) value)->value;
- break;
- case PRIMITIVETYPE_SHORT:
- val = ((java_lang_Short *) value)->value;
- break;
- default:
- exceptions_throw_illegalargumentexception();
- return;
- }
-
- *((s4 *) faddr) = val;
- return;
- }
-
- case PRIMITIVETYPE_INT: {
- s4 val;
-
- /* get field only by name, it can be one of B, S, C, I */
-
- if ((sc == NULL) || !(sf = class_findfield_by_name(sc, utf_value)))
- break;
-
- switch (sf->parseddesc->decltype) {
- case PRIMITIVETYPE_BYTE:
- val = ((java_lang_Byte *) value)->value;
- break;
- case PRIMITIVETYPE_CHAR:
- val = ((java_lang_Character *) value)->value;
- break;
- case PRIMITIVETYPE_SHORT:
- val = ((java_lang_Short *) value)->value;
- break;
- case PRIMITIVETYPE_INT:
- val = ((java_lang_Integer *) value)->value;
- break;
- default:
- exceptions_throw_illegalargumentexception();
- return;
- }
-
- *((s4 *) faddr) = val;
- return;
- }
-
- case PRIMITIVETYPE_LONG: {
- s8 val;
-
- /* get field only by name, it can be one of B, S, C, I, J */
-
- if ((sc == NULL) || !(sf = class_findfield_by_name(sc, utf_value)))
- break;
-
- switch (sf->parseddesc->decltype) {
- case PRIMITIVETYPE_BYTE:
- val = ((java_lang_Byte *) value)->value;
- break;
- case PRIMITIVETYPE_CHAR:
- val = ((java_lang_Character *) value)->value;
- break;
- case PRIMITIVETYPE_SHORT:
- val = ((java_lang_Short *) value)->value;
- break;
- case PRIMITIVETYPE_INT:
- val = ((java_lang_Integer *) value)->value;
- break;
- case PRIMITIVETYPE_LONG:
- val = ((java_lang_Long *) value)->value;
- break;
- default:
- exceptions_throw_illegalargumentexception();
- return;
- }
-
- *((s8 *) faddr) = val;
- return;
- }
-
- case PRIMITIVETYPE_FLOAT: {
- float val;
-
- /* get field only by name, it can be one of B, S, C, I, J, F */
-
- if ((sc == NULL) || !(sf = class_findfield_by_name(sc, utf_value)))
- break;
-
- switch (sf->parseddesc->decltype) {
- case PRIMITIVETYPE_BYTE:
- val = ((java_lang_Byte *) value)->value;
- break;
- case PRIMITIVETYPE_CHAR:
- val = ((java_lang_Character *) value)->value;
- break;
- case PRIMITIVETYPE_SHORT:
- val = ((java_lang_Short *) value)->value;
- break;
- case PRIMITIVETYPE_INT:
- val = ((java_lang_Integer *) value)->value;
- break;
- case PRIMITIVETYPE_LONG:
- val = ((java_lang_Long *) value)->value;
- break;
- case PRIMITIVETYPE_FLOAT:
- val = ((java_lang_Float *) value)->value;
- break;
- default:
- exceptions_throw_illegalargumentexception();
- return;
- }
-
- *((float *) faddr) = val;
- return;
- }
-
- case PRIMITIVETYPE_DOUBLE: {
- double val;
-
- /* get field only by name, it can be one of B, S, C, I, J, F, D */
-
- if ((sc == NULL) || !(sf = class_findfield_by_name(sc, utf_value)))
- break;
-
- switch (sf->parseddesc->decltype) {
- case PRIMITIVETYPE_BYTE:
- val = ((java_lang_Byte *) value)->value;
- break;
- case PRIMITIVETYPE_CHAR:
- val = ((java_lang_Character *) value)->value;
- break;
- case PRIMITIVETYPE_SHORT:
- val = ((java_lang_Short *) value)->value;
- break;
- case PRIMITIVETYPE_INT:
- val = ((java_lang_Integer *) value)->value;
- break;
- case PRIMITIVETYPE_LONG:
- val = ((java_lang_Long *) value)->value;
- break;
- case PRIMITIVETYPE_FLOAT:
- val = ((java_lang_Float *) value)->value;
- break;
- case PRIMITIVETYPE_DOUBLE:
- val = ((java_lang_Double *) value)->value;
- break;
- default:
- exceptions_throw_illegalargumentexception();
- return;
- }
-
- *((double *) faddr) = val;
- return;
- }
-
- case TYPE_ADR:
- /* check if value is an instance of the destination class */
-
- /* XXX TODO */
- /* if (!builtin_instanceof((java_objectheader *) value, df->class)) */
- /* break; */
-
- *((java_lang_Object **) faddr) = value;
- return;
- }
-
- /* raise exception */
-
- exceptions_throw_illegalargumentexception();
-}
-
-
-/*
- * Class: java/lang/reflect/Field
- * Method: setBoolean
- * Signature: (Ljava/lang/Object;Z)V
- */
-JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setBoolean(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, s4 value)
-{
- classinfo *c;
- fieldinfo *f;
- void *addr;
-
- /* get the class and the field */
-
- c = (classinfo *) this->declaringClass;
- f = &c->fields[this->slot];
-
- /* get the address of the field with an internal helper */
-
- if ((addr = cacao_get_field_address(this, o)) == NULL)
- return;
-
- /* check the field type and set the value */
-
- switch (f->parseddesc->decltype) {
- case PRIMITIVETYPE_BOOLEAN:
- *((s4 *) addr) = value;
- break;
- default:
- exceptions_throw_illegalargumentexception();
- }
-
- return;
-}
-
-
-/*
- * Class: java/lang/reflect/Field
- * Method: setByte
- * Signature: (Ljava/lang/Object;B)V
- */
-JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setByte(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, s4 value)
-{
- classinfo *c;
- fieldinfo *f;
- void *addr;
-
- /* get the class and the field */
-
- c = (classinfo *) this->declaringClass;
- f = &c->fields[this->slot];
-
- /* get the address of the field with an internal helper */
-
- if ((addr = cacao_get_field_address(this, o)) == NULL)
- return;
-
- /* check the field type and set the value */
-
- switch (f->parseddesc->decltype) {
- case PRIMITIVETYPE_BYTE:
- case PRIMITIVETYPE_SHORT:
- case PRIMITIVETYPE_INT:
- *((s4 *) addr) = value;
- break;
- case PRIMITIVETYPE_LONG:
- *((s8 *) addr) = value;
- break;
- case PRIMITIVETYPE_FLOAT:
- *((float *) addr) = value;
- break;
- case PRIMITIVETYPE_DOUBLE:
- *((double *) addr) = value;
- break;
- default:
- exceptions_throw_illegalargumentexception();
- }
-
- return;
-}
-
-
-/*
- * Class: java/lang/reflect/Field
- * Method: setChar
- * Signature: (Ljava/lang/Object;C)V
- */
-JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setChar(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, s4 value)
-{
- classinfo *c;
- fieldinfo *f;
- void *addr;
-
- /* get the class and the field */
-
- c = (classinfo *) this->declaringClass;
- f = &c->fields[this->slot];
-
- /* get the address of the field with an internal helper */
-
- if ((addr = cacao_get_field_address(this, o)) == NULL)
- return;
-
- /* check the field type and set the value */
-
- switch (f->parseddesc->decltype) {
- case PRIMITIVETYPE_CHAR:
- case PRIMITIVETYPE_INT:
- *((s4 *) addr) = value;
- break;
- case PRIMITIVETYPE_LONG:
- *((s8 *) addr) = value;
- break;
- case PRIMITIVETYPE_FLOAT:
- *((float *) addr) = value;
- break;
- case PRIMITIVETYPE_DOUBLE:
- *((double *) addr) = value;
- break;
- default:
- exceptions_throw_illegalargumentexception();
- }
-
- return;
-}
-
-
-/*
- * Class: java/lang/reflect/Field
- * Method: setShort
- * Signature: (Ljava/lang/Object;S)V
- */
-JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setShort(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, s4 value)
-{
- classinfo *c;
- fieldinfo *f;
- void *addr;
-
- /* get the class and the field */
-
- c = (classinfo *) this->declaringClass;
- f = &c->fields[this->slot];
-
- /* get the address of the field with an internal helper */
-
- if ((addr = cacao_get_field_address(this, o)) == NULL)
- return;
-
- /* check the field type and set the value */
-
- switch (f->parseddesc->decltype) {
- case PRIMITIVETYPE_SHORT:
- case PRIMITIVETYPE_INT:
- *((s4 *) addr) = value;
- break;
- case PRIMITIVETYPE_LONG:
- *((s8 *) addr) = value;
- break;
- case PRIMITIVETYPE_FLOAT:
- *((float *) addr) = value;
- break;
- case PRIMITIVETYPE_DOUBLE:
- *((double *) addr) = value;
- break;
- default:
- exceptions_throw_illegalargumentexception();
- }
-
- return;
-}
-
-
-/*
- * Class: java/lang/reflect/Field
- * Method: setInt
- * Signature: (Ljava/lang/Object;I)V
- */
-JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setInt(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, s4 value)
-{
- classinfo *c;
- fieldinfo *f;
- void *addr;
-
- /* get the class and the field */
-
- c = (classinfo *) this->declaringClass;
- f = &c->fields[this->slot];
-
- /* get the address of the field with an internal helper */
-
- if ((addr = cacao_get_field_address(this, o)) == NULL)
- return;
-
- /* check the field type and set the value */
-
- switch (f->parseddesc->decltype) {
- case PRIMITIVETYPE_INT:
- *((s4 *) addr) = value;
- break;
- case PRIMITIVETYPE_LONG:
- *((s8 *) addr) = value;
- break;
- case PRIMITIVETYPE_FLOAT:
- *((float *) addr) = value;
- break;
- case PRIMITIVETYPE_DOUBLE:
- *((double *) addr) = value;
- break;
- default:
- exceptions_throw_illegalargumentexception();
- }
-
- return;
-}
-
-
-/*
- * Class: java/lang/reflect/Field
- * Method: setLong
- * Signature: (Ljava/lang/Object;J)V
- */
-JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setLong(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, s8 value)
-{
- classinfo *c;
- fieldinfo *f;
- void *addr;
-
- /* get the class and the field */
-
- c = (classinfo *) this->declaringClass;
- f = &c->fields[this->slot];
-
- /* get the address of the field with an internal helper */
-
- if ((addr = cacao_get_field_address(this, o)) == NULL)
- return;
-
- /* check the field type and set the value */
-
- switch (f->parseddesc->decltype) {
- case PRIMITIVETYPE_LONG:
- *((s8 *) addr) = value;
- break;
- case PRIMITIVETYPE_FLOAT:
- *((float *) addr) = value;
- break;
- case PRIMITIVETYPE_DOUBLE:
- *((double *) addr) = value;
- break;
- default:
- exceptions_throw_illegalargumentexception();
- }
-
- return;
-}
-
-
-/*
- * Class: java/lang/reflect/Field
- * Method: setFloat
- * Signature: (Ljava/lang/Object;F)V
- */
-JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setFloat(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, float value)
-{
- classinfo *c;
- fieldinfo *f;
- void *addr;
-
- /* get the class and the field */
-
- c = (classinfo *) this->declaringClass;
- f = &c->fields[this->slot];
-
- /* get the address of the field with an internal helper */
-
- if ((addr = cacao_get_field_address(this, o)) == NULL)
- return;
-
- /* check the field type and set the value */
-
- switch (f->parseddesc->decltype) {
- case PRIMITIVETYPE_FLOAT:
- *((float *) addr) = value;
- break;
- case PRIMITIVETYPE_DOUBLE:
- *((double *) addr) = value;
- break;
- default:
- exceptions_throw_illegalargumentexception();
- }
-
- return;
-}
-
-
-/*
- * Class: java/lang/reflect/Field
- * Method: setDouble
- * Signature: (Ljava/lang/Object;D)V
- */
-JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setDouble(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, double value)
-{
- classinfo *c;
- fieldinfo *f;
- void *addr;
-
- /* get the class and the field */
-
- c = (classinfo *) this->declaringClass;
- f = &c->fields[this->slot];
-
- /* get the address of the field with an internal helper */
-
- if ((addr = cacao_get_field_address(this, o)) == NULL)
- return;
-
- /* check the field type and set the value */
-
- switch (f->parseddesc->decltype) {
- case PRIMITIVETYPE_DOUBLE:
- *((double *) addr) = value;
- break;
- default:
- exceptions_throw_illegalargumentexception();
- }
-
- return;
-}
-
-
-/*
- * Class: java/lang/reflect/Field
- * Method: getType
- * Signature: ()Ljava/lang/Class;
- */
-JNIEXPORT java_lang_Class* JNICALL Java_java_lang_reflect_Field_getType(JNIEnv *env, java_lang_reflect_Field *this)
-{
- classinfo *c;
- typedesc *desc;
- classinfo *ret;
-
- c = (classinfo *) this->declaringClass;
- desc = c->fields[this->slot].parseddesc;
-
- if (!desc)
- return NULL;
-
- if (!resolve_class_from_typedesc(desc, true, false, &ret))
- return NULL;
-
- return (java_lang_Class *) ret;
-}
-
-
-/*
- * Class: java/lang/reflect/Field
- * Method: getModifiersInternal
- * Signature: ()I
- */
-JNIEXPORT s4 JNICALL Java_java_lang_reflect_Field_getModifiersInternal(JNIEnv *env, java_lang_reflect_Field *this)
-{
- classinfo *c;
- fieldinfo *f;
-
- c = (classinfo *) this->declaringClass;
- f = &(c->fields[this->slot]);
-
- return f->flags;
-}
-
-
-/*
- * These are local overrides for various environment variables in Emacs.
- * Please do not remove this and leave it at the end of the file, where
- * Emacs will automagically detect them.
- * ---------------------------------------------------------------------
- * Local variables:
- * mode: c
- * indent-tabs-mode: t
- * c-basic-offset: 4
- * tab-width: 4
- * End:
- */
##
## Changes:
##
-## $Id: Makefile.am 5066 2006-07-02 18:31:02Z twisti $
+## $Id: Makefile.am 5153 2006-07-18 08:19:24Z twisti $
## Process this file with automake to produce Makefile.in
noinst_LTLIBRARIES = libnativevm.la
libnativevm_la_SOURCES = \
- Constructor.c \
- Field.c \
- Method.c \
- VMAccessController.c \
- VMClass.c \
- VMClassLoader.c \
- VMObject.c \
- VMProxy.c \
- VMRuntime.c \
+ gnu_classpath_VMStackWalker.c \
+ gnu_classpath_VMSystemProperties.c \
gnu_java_lang_management_VMRuntimeMXBeanImpl.c \
- VMStackWalker.c \
- VMString.c \
- VMSystem.c \
- VMSystemProperties.c \
- VMThread.c \
- VMThrowable.c
+ java_lang_VMClass.c \
+ java_lang_VMClassLoader.c \
+ java_lang_VMObject.c \
+ java_lang_VMRuntime.c \
+ java_lang_VMString.c \
+ java_lang_VMSystem.c \
+ java_lang_VMThread.c \
+ java_lang_VMThrowable.c \
+ java_lang_reflect_Constructor.c \
+ java_lang_reflect_Field.c \
+ java_lang_reflect_Method.c \
+ java_lang_reflect_VMProxy.c \
+ java_security_VMAccessController.c
if ENABLE_JVMTI
libnativevm_la_SOURCES += \
+++ /dev/null
-/* src/native/vm/Method.c - java/lang/reflect/Method
-
- Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
- C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
- E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
- J. Wenninger, Institut f. Computersprachen - TU Wien
-
- This file is part of CACAO.
-
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License as
- published by the Free Software Foundation; either version 2, or (at
- your option) any later version.
-
- This program is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- 02110-1301, USA.
-
- Contact: cacao@cacaojvm.org
-
- Authors: Roman Obermaiser
-
- Changes: Joseph Wenninger
- Christian Thalinger
-
- $Id: Method.c 4807 2006-04-21 13:08:00Z edwin $
-
-*/
-
-
-#include "config.h"
-
-#include <assert.h>
-
-#include "vm/types.h"
-
-#include "native/jni.h"
-#include "native/native.h"
-#include "native/include/java_lang_Object.h"
-#include "native/include/java_lang_Class.h"
-#include "native/include/java_lang_reflect_Method.h"
-#include "vm/access.h"
-#include "vm/global.h"
-#include "vm/builtin.h"
-#include "vm/exceptions.h"
-#include "vm/initialize.h"
-#include "vm/stringlocal.h"
-
-
-/*
- * Class: java/lang/reflect/Method
- * Method: getModifiersInternal
- * Signature: ()I
- */
-JNIEXPORT s4 JNICALL Java_java_lang_reflect_Method_getModifiersInternal(JNIEnv *env, java_lang_reflect_Method *this)
-{
- classinfo *c;
- methodinfo *m;
-
- c = (classinfo *) this->declaringClass;
- m = &(c->methods[this->slot]);
-
- return m->flags;
-}
-
-
-/*
- * Class: java/lang/reflect/Method
- * Method: getReturnType
- * Signature: ()Ljava/lang/Class;
- */
-JNIEXPORT java_lang_Class* JNICALL Java_java_lang_reflect_Method_getReturnType(JNIEnv *env, java_lang_reflect_Method *this)
-{
- classinfo *c;
- methodinfo *m;
-
- c = (classinfo *) this->declaringClass;
- m = &(c->methods[this->slot]);
-
- return (java_lang_Class *) native_get_returntype(m);
-}
-
-
-/*
- * Class: java/lang/reflect/Method
- * Method: getParameterTypes
- * Signature: ()[Ljava/lang/Class;
- */
-JNIEXPORT java_objectarray* JNICALL Java_java_lang_reflect_Method_getParameterTypes(JNIEnv *env, java_lang_reflect_Method *this)
-{
- classinfo *c;
- methodinfo *m;
-
- c = (classinfo *) this->declaringClass;
- m = &(c->methods[this->slot]);
-
- return native_get_parametertypes(m);
-}
-
-
-/*
- * Class: java/lang/reflect/Method
- * Method: getExceptionTypes
- * Signature: ()[Ljava/lang/Class;
- */
-JNIEXPORT java_objectarray* JNICALL Java_java_lang_reflect_Method_getExceptionTypes(JNIEnv *env, java_lang_reflect_Method *this)
-{
- classinfo *c;
- methodinfo *m;
-
- c = (classinfo *) this->declaringClass;
- m = &(c->methods[this->slot]);
-
- return native_get_exceptiontypes(m);
-}
-
-
-/*
- * Class: java/lang/reflect/Method
- * Method: invokeNative
- * Signature: (Ljava/lang/Object;[Ljava/lang/Object;Ljava/lang/Class;I)Ljava/lang/Object;
- */
-JNIEXPORT java_lang_Object* JNICALL Java_java_lang_reflect_Method_invokeNative(JNIEnv *env, java_lang_reflect_Method *this, java_lang_Object *o, java_objectarray *args, java_lang_Class *declaringClass, s4 slot)
-{
- classinfo *c;
- methodinfo *m;
- java_objectarray *oa;
- classinfo *callerclass;
-
- c = (classinfo *) declaringClass;
- m = &(c->methods[slot]);
-
- /* check method access */
-
- if (!(m->flags & ACC_PUBLIC) || !(c->flags & ACC_PUBLIC)) {
- /* check if we should bypass security checks (AccessibleObject) */
-
- if (this->flag == false) {
- /* get the calling class */
-
- oa = stacktrace_getClassContext();
- if (!oa)
- return NULL;
-
- /* this function is always called like this:
-
- java.lang.reflect.Method.invokeNative (Native Method)
- [0] java.lang.reflect.Method.invoke (Method.java:329)
- [1] <caller>
- */
-
- callerclass = (classinfo *) oa->data[1];
-
- if (!access_is_accessible_class(callerclass,c)
- || !access_is_accessible_member(callerclass, c, m->flags))
- {
- *exceptionptr =
- new_exception(string_java_lang_IllegalAccessException);
- return NULL;
- }
- }
- }
-
- /* check if method class is initialized */
-
- if (!(c->state & CLASS_INITIALIZED))
- if (!initialize_class(c))
- return NULL;
-
- /* call the Java method via a helper function */
-
- return (java_lang_Object *) _Jv_jni_invokeNative(m, (jobject) o, args);
-}
-
-
-/*
- * These are local overrides for various environment variables in Emacs.
- * Please do not remove this and leave it at the end of the file, where
- * Emacs will automagically detect them.
- * ---------------------------------------------------------------------
- * Local variables:
- * mode: c
- * indent-tabs-mode: t
- * c-basic-offset: 4
- * tab-width: 4
- * End:
- */
+++ /dev/null
-/* src/native/vm/VMAccessController.c - java/security/VMAccessController
-
- Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
- C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
- E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
- J. Wenninger, Institut f. Computersprachen - TU Wien
-
- This file is part of CACAO.
-
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License as
- published by the Free Software Foundation; either version 2, or (at
- your option) any later version.
-
- This program is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- 02110-1301, USA.
-
- Contact: cacao@cacaojvm.org
-
- Authors: Joseph Wenninger
-
- Changes: Christian Thalinger
-
- $Id: VMAccessController.c 4406 2006-02-03 13:19:36Z twisti $
-
-*/
-
-
-#include "config.h"
-#include "vm/types.h"
-
-#include "native/jni.h"
-#include "vm/builtin.h"
-#include "vm/class.h"
-#include "vm/options.h"
-#include "vm/jit/stacktrace.h"
-
-
-/*
- * Class: java/security/VMAccessController
- * Method: getStack
- * Signature: ()[[Ljava/lang/Object;
- */
-JNIEXPORT java_objectarray* JNICALL Java_java_security_VMAccessController_getStack(JNIEnv *env, jclass clazz) {
-#if defined(__ALPHA__) || defined(__ARM__) || defined(__I386__) || defined(__MIPS__) || defined(__POWERPC__) || defined (__X86_64__)
- /* these JITs support stacktraces */
-
- return stacktrace_getStack();
-
-#else
-# if defined(ENABLE_INTRP)
- /* the interpreter supports stacktraces, even if the JIT does not */
-
- if (opt_intrp) {
- return stacktrace_getStack();
-
- } else
-# endif
- {
- java_objectarray *result;
- java_objectarray *classes;
- java_objectarray *methodnames;
-
- if (!(result = builtin_anewarray(2, arrayclass_java_lang_Object)))
- return NULL;
-
- if (!(classes = builtin_anewarray(0, class_java_lang_Class)))
- return NULL;
-
- if (!(methodnames = builtin_anewarray(0, class_java_lang_String)))
- return NULL;
-
- result->data[0] = (java_objectheader *) classes;
- result->data[1] = (java_objectheader *) methodnames;
-
- return result;
- }
-#endif
-}
-
-
-/*
- * These are local overrides for various environment variables in Emacs.
- * Please do not remove this and leave it at the end of the file, where
- * Emacs will automagically detect them.
- * ---------------------------------------------------------------------
- * Local variables:
- * mode: c
- * indent-tabs-mode: t
- * c-basic-offset: 4
- * tab-width: 4
- * End:
- */
+++ /dev/null
-/* src/native/vm/VMClass.c - java/lang/VMClass
-
- Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
- C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
- E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
- J. Wenninger, Institut f. Computersprachen - TU Wien
-
- This file is part of CACAO.
-
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License as
- published by the Free Software Foundation; either version 2, or (at
- your option) any later version.
-
- This program is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- 02110-1301, USA.
-
- Contact: cacao@cacaojvm.org
-
- Authors: Roman Obermaiser
-
- Changes: Joseph Wenninger
- Christian Thalinger
- Edwin Steiner
-
- $Id: VMClass.c 4829 2006-04-24 17:16:45Z edwin $
-
-*/
-
-
-#include "config.h"
-
-#include <assert.h>
-#include <string.h>
-
-#include "vm/types.h"
-
-#include "mm/memory.h"
-#include "native/jni.h"
-#include "native/native.h"
-#include "native/include/java_lang_Class.h"
-#include "native/include/java_lang_ClassLoader.h"
-#include "native/include/java_lang_Object.h"
-#include "native/include/java_lang_VMClass.h"
-#include "native/include/java_lang_reflect_Constructor.h"
-#include "native/include/java_lang_reflect_Field.h"
-#include "native/include/java_lang_reflect_Method.h"
-#include "native/include/java_security_ProtectionDomain.h"
-#include "toolbox/logging.h"
-#include "vm/builtin.h"
-#include "vm/exceptions.h"
-#include "vm/global.h"
-#include "vm/initialize.h"
-#include "vm/loader.h"
-#include "vm/resolve.h"
-#include "vm/stringlocal.h"
-
-
-/*
- * Class: java/lang/Class
- * Method: isInstance
- * Signature: (Ljava/lang/Object;)Z
- */
-JNIEXPORT s4 JNICALL Java_java_lang_VMClass_isInstance(JNIEnv *env, jclass clazz, java_lang_Class *klass, java_lang_Object *o)
-{
- classinfo *c;
- java_objectheader *ob;
-
- c = (classinfo *) klass;
- ob = (java_objectheader *) o;
-
- if (!(c->state & CLASS_LINKED))
- if (!link_class(c))
- return 0;
-
- return builtin_instanceof(ob, c);
-}
-
-
-/*
- * Class: java/lang/Class
- * Method: isAssignableFrom
- * Signature: (Ljava/lang/Class;)Z
- */
-JNIEXPORT s4 JNICALL Java_java_lang_VMClass_isAssignableFrom(JNIEnv *env, jclass clazz, java_lang_Class *klass, java_lang_Class *c)
-{
- classinfo *kc;
- classinfo *cc;
-
- kc = (classinfo *) klass;
- cc = (classinfo *) c;
-
- if (cc == NULL) {
- exceptions_throw_nullpointerexception();
- return 0;
- }
-
- if (!(kc->state & CLASS_LINKED))
- if (!link_class(kc))
- return 0;
-
- if (!(cc->state & CLASS_LINKED))
- if (!link_class(cc))
- return 0;
-
- /* XXX this may be wrong for array classes */
-
- return builtin_isanysubclass(cc, kc);
-}
-
-
-/*
- * Class: java/lang/Class
- * Method: isInterface
- * Signature: ()Z
- */
-JNIEXPORT s4 JNICALL Java_java_lang_VMClass_isInterface(JNIEnv *env, jclass clazz, java_lang_Class *klass)
-{
- classinfo *c;
-
- c = (classinfo *) klass;
-
- if (c->flags & ACC_INTERFACE)
- return true;
-
- return false;
-}
-
-
-/*
- * Class: java/lang/Class
- * Method: isPrimitive
- * Signature: ()Z
- */
-JNIEXPORT s4 JNICALL Java_java_lang_VMClass_isPrimitive(JNIEnv *env, jclass clazz, java_lang_Class *klass)
-{
- classinfo *c;
- s4 i;
-
- c = (classinfo *) klass;
-
- /* search table of primitive classes */
-
- for (i = 0; i < PRIMITIVETYPE_COUNT; i++)
- if (primitivetype_table[i].class_primitive == c)
- return true;
-
- return false;
-}
-
-
-/*
- * Class: java/lang/VMClass
- * Method: getName
- * Signature: ()Ljava/lang/String;
- */
-JNIEXPORT java_lang_String* JNICALL Java_java_lang_VMClass_getName(JNIEnv *env, jclass clazz, java_lang_Class *klass)
-{
- classinfo *c;
- java_lang_String *s;
- u4 i;
-
- c = (classinfo *) klass;
- s = (java_lang_String *) javastring_new(c->name);
-
- if (!s)
- return NULL;
-
- /* return string where '/' is replaced by '.' */
-
- for (i = 0; i < s->value->header.size; i++) {
- if (s->value->data[i] == '/')
- s->value->data[i] = '.';
- }
-
- return s;
-}
-
-
-/*
- * Class: java/lang/Class
- * Method: getSuperclass
- * Signature: ()Ljava/lang/Class;
- */
-JNIEXPORT java_lang_Class* JNICALL Java_java_lang_VMClass_getSuperclass(JNIEnv *env, jclass clazz, java_lang_Class *klass)
-{
- classinfo *c;
- classinfo *sc;
-
- c = (classinfo *) klass;
-
- /* for java.lang.Object, primitive and Void classes we return NULL */
- if (!c->super.any)
- return NULL;
-
- /* for interfaces we also return NULL */
- if (c->flags & ACC_INTERFACE)
- return NULL;
-
- /* we may have to resolve the super class reference */
- if (!resolve_classref_or_classinfo(NULL, c->super, resolveEager,
- true, /* check access */
- false, /* don't link */
- &sc))
- {
- return NULL;
- }
-
- /* store the resolution */
- c->super.cls = sc;
-
- return (java_lang_Class *) sc;
-}
-
-
-/*
- * Class: java/lang/VMClass
- * Method: getInterfaces
- * Signature: ()[Ljava/lang/Class;
- */
-JNIEXPORT java_objectarray* JNICALL Java_java_lang_VMClass_getInterfaces(JNIEnv *env, jclass clazz, java_lang_Class *klass)
-{
- classinfo *c;
- classinfo *ic;
- java_objectarray *oa;
- u4 i;
-
- c = (classinfo *) klass;
-
- if (!(c->state & CLASS_LINKED))
- if (!link_class(c))
- return NULL;
-
- oa = builtin_anewarray(c->interfacescount, class_java_lang_Class);
-
- if (!oa)
- return NULL;
-
- for (i = 0; i < c->interfacescount; i++) {
- ic = c->interfaces[i].cls;
-
- oa->data[i] = (java_objectheader *) ic;
- }
-
- return oa;
-}
-
-
-/*
- * Class: java/lang/VMClass
- * Method: getComponentType
- * Signature: ()Ljava/lang/Class;
- */
-JNIEXPORT java_lang_Class* JNICALL Java_java_lang_VMClass_getComponentType(JNIEnv *env, jclass clazz, java_lang_Class *klass)
-{
- classinfo *c;
- classinfo *comp;
- arraydescriptor *desc;
-
- c = (classinfo *) klass;
-
- /* XXX maybe we could find a way to do this without linking. */
- /* This way should be safe and easy, however. */
-
- if (!(c->state & CLASS_LINKED))
- if (!link_class(c))
- return NULL;
-
- desc = c->vftbl->arraydesc;
-
- if (desc == NULL)
- return NULL;
-
- if (desc->arraytype == ARRAYTYPE_OBJECT)
- comp = desc->componentvftbl->class;
- else
- comp = primitivetype_table[desc->arraytype].class_primitive;
-
- return (java_lang_Class *) comp;
-}
-
-
-/*
- * Class: java/lang/VMClass
- * Method: getModifiers
- * Signature: (Z)I
- */
-JNIEXPORT s4 JNICALL Java_java_lang_VMClass_getModifiers(JNIEnv *env, jclass clazz, java_lang_Class *klass, s4 ignoreInnerClassesAttrib)
-{
- classinfo *c;
- classref_or_classinfo inner;
- classref_or_classinfo outer;
- utf *innername;
- s4 i;
-
- c = (classinfo *) klass;
-
- if (!ignoreInnerClassesAttrib && (c->innerclasscount != 0)) {
- /* search for passed class as inner class */
-
- for (i = 0; i < c->innerclasscount; i++) {
- inner = c->innerclass[i].inner_class;
- outer = c->innerclass[i].outer_class;
-
- /* Check if inner is a classref or a real class and get
- the name of the structure */
-
- innername = IS_CLASSREF(inner) ? inner.ref->name : inner.cls->name;
-
- /* innerclass is this class */
-
- if (innername == c->name) {
- /* has the class actually an outer class? */
-
- if (outer.any)
- /* return flags got from the outer class file */
- return c->innerclass[i].flags & ACC_CLASS_REFLECT_MASK;
- else
- return c->flags & ACC_CLASS_REFLECT_MASK;
- }
- }
- }
-
- /* passed class is no inner class or it was not requested */
-
- return c->flags & ACC_CLASS_REFLECT_MASK;
-}
-
-
-/*
- * Class: java/lang/VMClass
- * Method: getDeclaringClass
- * Signature: ()Ljava/lang/Class;
- */
-JNIEXPORT java_lang_Class* JNICALL Java_java_lang_VMClass_getDeclaringClass(JNIEnv *env, jclass clazz, java_lang_Class *klass)
-{
- classinfo *c;
- classref_or_classinfo inner;
- utf *innername;
- classinfo *outer;
- s4 i;
-
- c = (classinfo *) klass;
-
- if (!Java_java_lang_VMClass_isPrimitive(env, clazz, klass) &&
- (c->name->text[0] != '[')) {
-
- if (c->innerclasscount == 0) /* no innerclasses exist */
- return NULL;
-
- for (i = 0; i < c->innerclasscount; i++) {
- inner = c->innerclass[i].inner_class;
-
- /* check if inner_class is a classref or a real class and
- get the class name from the structure */
-
- innername = IS_CLASSREF(inner) ? inner.ref->name : inner.cls->name;
-
- /* innerclass is this class */
-
- if (innername == c->name) {
- /* maybe the outer class is not loaded yet */
-
- if (!resolve_classref_or_classinfo(NULL,
- c->innerclass[i].outer_class,
- resolveEager, false, false,
- &outer))
- return NULL;
-
- if (!(outer->state & CLASS_LINKED))
- if (!link_class(outer))
- return NULL;
-
- return (java_lang_Class *) outer;
- }
- }
- }
-
- /* return NULL for arrayclasses and primitive classes */
-
- return NULL;
-}
-
-
-/*
- * Class: java/lang/VMClass
- * Method: getDeclaredClasses
- * Signature: (Z)[Ljava/lang/Class;
- */
-JNIEXPORT java_objectarray* JNICALL Java_java_lang_VMClass_getDeclaredClasses(JNIEnv *env, jclass clazz, java_lang_Class *klass, s4 publicOnly)
-{
- classinfo *c;
- classref_or_classinfo outer;
- utf *outername;
- s4 declaredclasscount; /* number of declared classes */
- s4 pos; /* current declared class */
- java_objectarray *oa; /* array of declared classes */
- s4 i;
-
- c = (classinfo *) klass;
- declaredclasscount = 0;
-
- if (!Java_java_lang_VMClass_isPrimitive(env, clazz, klass) &&
- (c->name->text[0] != '[')) {
- /* determine number of declared classes */
-
- for (i = 0; i < c->innerclasscount; i++) {
- outer = c->innerclass[i].outer_class;
-
- /* check if outer_class is a classref or a real class and
- get the class name from the structure */
-
- outername = IS_CLASSREF(outer) ? outer.ref->name : outer.cls->name;
-
- /* outer class is this class */
-
- if ((outername == c->name) &&
- ((publicOnly == 0) || (c->innerclass[i].flags & ACC_PUBLIC)))
- declaredclasscount++;
- }
- }
-
- /* allocate Class[] and check for OOM */
-
- oa = builtin_anewarray(declaredclasscount, class_java_lang_Class);
-
- if (!oa)
- return NULL;
-
- for (i = 0, pos = 0; i < c->innerclasscount; i++) {
- outer = c->innerclass[i].outer_class;
-
- /* check if outer_class is a classref or a real class and
- get the class name from the structure */
-
- outername = IS_CLASSREF(outer) ? outer.ref->name : outer.cls->name;
-
- /* outer class is this class */
-
- if ((outername == c->name) &&
- ((publicOnly == 0) || (c->innerclass[i].flags & ACC_PUBLIC))) {
- classinfo *inner;
-
- if (!resolve_classref_or_classinfo(NULL,
- c->innerclass[i].inner_class,
- resolveEager, false, false,
- &inner))
- return NULL;
-
- if (!(inner->state & CLASS_LINKED))
- if (!link_class(inner))
- return NULL;
-
- oa->data[pos++] = (java_objectheader *) inner;
- }
- }
-
- return oa;
-}
-
-
-/*
- * Class: java/lang/VMClass
- * Method: getDeclaredFields
- * Signature: (Z)[Ljava/lang/reflect/Field;
- */
-JNIEXPORT java_objectarray* JNICALL Java_java_lang_VMClass_getDeclaredFields(JNIEnv *env, jclass clazz, java_lang_Class *klass, s4 publicOnly)
-{
- classinfo *c;
- java_objectarray *oa; /* result: array of field-objects */
- fieldinfo *f;
- java_objectheader *o;
- java_lang_reflect_Field *rf;
- s4 public_fields; /* number of elements in field-array */
- s4 pos;
- s4 i;
-
- c = (classinfo *) klass;
-
- /* determine number of fields */
-
- for (i = 0, public_fields = 0; i < c->fieldscount; i++)
- if ((c->fields[i].flags & ACC_PUBLIC) || (publicOnly == 0))
- public_fields++;
-
- /* create array of fields */
-
- oa = builtin_anewarray(public_fields, class_java_lang_reflect_Field);
-
- if (!oa)
- return NULL;
-
- /* get the fields and store in the array */
-
- for (i = 0, pos = 0; i < c->fieldscount; i++) {
- f = &(c->fields[i]);
-
- if ((f->flags & ACC_PUBLIC) || (publicOnly == 0)) {
- /* create Field object */
-
- if (!(o = native_new_and_init(class_java_lang_reflect_Field)))
- return NULL;
-
- /* initialize instance fields */
-
- rf = (java_lang_reflect_Field *) o;
-
- rf->declaringClass = (java_lang_Class *) c;
- rf->name = javastring_new(f->name);
- rf->slot = i;
-
- /* store object into array */
-
- oa->data[pos++] = o;
- }
- }
-
- return oa;
-}
-
-
-/*
- * Class: java/lang/VMClass
- * Method: getDeclaredMethods
- * Signature: (Z)[Ljava/lang/reflect/Method;
- */
-JNIEXPORT java_objectarray* JNICALL Java_java_lang_VMClass_getDeclaredMethods(JNIEnv *env, jclass clazz, java_lang_Class *klass, s4 publicOnly)
-{
- classinfo *c;
- java_objectheader *o;
- java_lang_reflect_Method *rm;
- java_objectarray *oa; /* result: array of Method-objects */
- methodinfo *m; /* the current method to be represented */
- s4 public_methods; /* number of public methods of the class */
- s4 pos;
- s4 i;
-
- c = (classinfo *) klass;
- public_methods = 0;
-
- /* JOWENN: array classes do not declare methods according to mauve
- test. It should be considered, if we should return to my old
- clone method overriding instead of declaring it as a member
- function. */
-
- if (Java_java_lang_VMClass_isArray(env, clazz, klass))
- return builtin_anewarray(0, class_java_lang_reflect_Method);
-
- /* determine number of methods */
-
- for (i = 0; i < c->methodscount; i++) {
- m = &c->methods[i];
-
- if (((m->flags & ACC_PUBLIC) || (publicOnly == false)) &&
- ((m->name != utf_init) && (m->name != utf_clinit)) &&
- !(m->flags & ACC_MIRANDA))
- public_methods++;
- }
-
- oa = builtin_anewarray(public_methods, class_java_lang_reflect_Method);
-
- if (!oa)
- return NULL;
-
- for (i = 0, pos = 0; i < c->methodscount; i++) {
- m = &c->methods[i];
-
- if (((m->flags & ACC_PUBLIC) || (publicOnly == false)) &&
- ((m->name != utf_init) && (m->name != utf_clinit)) &&
- !(m->flags & ACC_MIRANDA)) {
-
- if (!(o = native_new_and_init(class_java_lang_reflect_Method)))
- return NULL;
-
- /* initialize instance fields */
-
- rm = (java_lang_reflect_Method *) o;
-
- rm->declaringClass = (java_lang_Class *) m->class;
- rm->name = javastring_new(m->name);
- rm->slot = i;
-
- /* store object into array */
-
- oa->data[pos++] = o;
- }
- }
-
- return oa;
-}
-
-
-/*
- * Class: java/lang/VMClass
- * Method: getDeclaredConstructors
- * Signature: (Z)[Ljava/lang/reflect/Constructor;
- */
-JNIEXPORT java_objectarray* JNICALL Java_java_lang_VMClass_getDeclaredConstructors(JNIEnv *env, jclass clazz, java_lang_Class *klass, s4 publicOnly)
-{
- classinfo *c;
- methodinfo *m; /* the current method to be represented */
- java_objectarray *oa; /* result: array of Method-objects */
- java_objectheader *o;
- java_lang_reflect_Constructor *rc;
- s4 public_methods; /* number of public methods of the class */
- s4 pos;
- s4 i;
-
- c = (classinfo *) klass;
-
- /* determine number of constructors */
-
- for (i = 0, public_methods = 0; i < c->methodscount; i++) {
- m = &c->methods[i];
-
- if (((m->flags & ACC_PUBLIC) || (publicOnly == 0)) &&
- (m->name == utf_init))
- public_methods++;
- }
-
- oa = builtin_anewarray(public_methods, class_java_lang_reflect_Constructor);
-
- if (!oa)
- return NULL;
-
- for (i = 0, pos = 0; i < c->methodscount; i++) {
- m = &c->methods[i];
-
- if (((m->flags & ACC_PUBLIC) || (publicOnly == 0)) &&
- (m->name == utf_init)) {
-
- if (!(o = native_new_and_init(class_java_lang_reflect_Constructor)))
- return NULL;
-
- /* initialize instance fields */
-
- rc = (java_lang_reflect_Constructor *) o;
-
- rc->clazz = (java_lang_Class *) c;
- rc->slot = i;
-
- /* store object into array */
-
- oa->data[pos++] = o;
- }
- }
-
- return oa;
-}
-
-
-/*
- * Class: java/lang/VMClass
- * Method: getClassLoader
- * Signature: ()Ljava/lang/ClassLoader;
- */
-JNIEXPORT java_lang_ClassLoader* JNICALL Java_java_lang_VMClass_getClassLoader(JNIEnv *env, jclass clazz, java_lang_Class *klass)
-{
- classinfo *c;
-
- c = (classinfo *) klass;
-
- return (java_lang_ClassLoader *) c->classloader;
-}
-
-
-/*
- * Class: java/lang/VMClass
- * Method: forName
- * Signature: (Ljava/lang/String;ZLjava/lang/ClassLoader;)Ljava/lang/Class;
- */
-JNIEXPORT java_lang_Class* JNICALL Java_java_lang_VMClass_forName(JNIEnv *env, jclass clazz, java_lang_String *name, s4 initialize, java_lang_ClassLoader *loader)
-{
- classinfo *c;
- utf *u;
- u2 *pos;
- s4 i;
-
- /* illegal argument */
-
- if (!name)
- return NULL;
-
- /* name must not contain '/' (mauve test) */
-
- for (i = 0, pos = name->value->data + name->offset; i < name->count; i++, pos++) {
- if (*pos == '/') {
- *exceptionptr =
- new_exception_javastring(string_java_lang_ClassNotFoundException, name);
- return NULL;
- }
- }
-
- /* create utf string in which '.' is replaced by '/' */
-
- u = javastring_toutf(name, true);
-
- /* try to load, ... */
-
- if (!(c = load_class_from_classloader(u, (java_objectheader *) loader))) {
- classinfo *xclass;
-
- xclass = (*exceptionptr)->vftbl->class;
-
- /* if the exception is a NoClassDefFoundError, we replace it with a
- ClassNotFoundException, otherwise return the exception */
-
- if (xclass == class_java_lang_NoClassDefFoundError) {
- /* clear exceptionptr, because builtin_new checks for
- ExceptionInInitializerError */
- *exceptionptr = NULL;
-
- *exceptionptr =
- new_exception_javastring(string_java_lang_ClassNotFoundException, name);
- }
-
- return NULL;
- }
-
- /* link, ... */
-
- if (!link_class(c))
- return NULL;
-
- /* ...and initialize it, if required */
-
- if (initialize)
- if (!initialize_class(c))
- return NULL;
-
- return (java_lang_Class *) c;
-}
-
-
-/*
- * Class: java/lang/Class
- * Method: isArray
- * Signature: ()Z
- */
-JNIEXPORT s4 JNICALL Java_java_lang_VMClass_isArray(JNIEnv *env, jclass clazz, java_lang_Class *klass)
-{
- classinfo *c = (classinfo *) klass;
-
- if (!(c->state & CLASS_LINKED))
- if (!link_class(c))
- return 0;
-
- return (c->vftbl->arraydesc != NULL);
-}
-
-
-/*
- * Class: java/lang/VMClass
- * Method: throwException
- * Signature: (Ljava/lang/Throwable;)V
- */
-JNIEXPORT void JNICALL Java_java_lang_VMClass_throwException(JNIEnv *env, jclass clazz, java_lang_Throwable *t)
-{
- *exceptionptr = (java_objectheader *) t;
-}
-
-
-/*
- * These are local overrides for various environment variables in Emacs.
- * Please do not remove this and leave it at the end of the file, where
- * Emacs will automagically detect them.
- * ---------------------------------------------------------------------
- * Local variables:
- * mode: c
- * indent-tabs-mode: t
- * c-basic-offset: 4
- * tab-width: 4
- * End:
- * vim:noexpandtab:sw=4:ts=4:
- */
+++ /dev/null
-/* src/native/vm/VMClassLoader.c - java/lang/VMClassLoader
-
- Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
- C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
- E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
- J. Wenninger, Institut f. Computersprachen - TU Wien
-
- This file is part of CACAO.
-
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License as
- published by the Free Software Foundation; either version 2, or (at
- your option) any later version.
-
- This program is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- 02110-1301, USA.
-
- Contact: cacao@cacaojvm.org
-
- Authors: Roman Obermaiser
-
- Changes: Joseph Wenninger
- Christian Thalinger
- Edwin Steiner
-
- $Id: VMClassLoader.c 5091 2006-07-10 10:01:47Z twisti $
-
-*/
-
-
-#include "config.h"
-
-#include <sys/stat.h>
-
-#include "vm/types.h"
-
-#include "mm/memory.h"
-#include "native/jni.h"
-#include "native/native.h"
-#include "native/include/java_lang_Class.h"
-#include "native/include/java_lang_String.h"
-#include "native/include/java_lang_ClassLoader.h"
-#include "native/include/java_security_ProtectionDomain.h"
-#include "native/include/java_util_Vector.h"
-#include "toolbox/logging.h"
-#include "vm/builtin.h"
-#include "vm/class.h"
-#include "vm/classcache.h"
-#include "vm/exceptions.h"
-#include "vm/initialize.h"
-#include "vm/linker.h"
-#include "vm/loader.h"
-#include "vm/options.h"
-#include "vm/statistics.h"
-#include "vm/stringlocal.h"
-#include "vm/suck.h"
-#include "vm/vm.h"
-#include "vm/zip.h"
-#include "vm/jit/asmpart.h"
-
-#if defined(ENABLE_JVMTI)
-#include "native/jvmti/cacaodbg.h"
-#endif
-
-
-/*
- * Class: java/lang/VMClassLoader
- * Method: defineClass
- * Signature: (Ljava/lang/ClassLoader;Ljava/lang/String;[BIILjava/security/ProtectionDomain;)Ljava/lang/Class;
- */
-JNIEXPORT java_lang_Class* JNICALL Java_java_lang_VMClassLoader_defineClass(JNIEnv *env, jclass clazz, java_lang_ClassLoader *cl, java_lang_String *name, java_bytearray *data, s4 offset, s4 len, java_security_ProtectionDomain *pd)
-{
- classinfo *c;
- classinfo *r;
- classbuffer *cb;
- utf *utfname;
-#if defined(ENABLE_JVMTI)
- jint new_class_data_len = 0;
- unsigned char* new_class_data = NULL;
-#endif
-
- /* check if data was passed */
-
- if (data == NULL) {
- exceptions_throw_nullpointerexception();
- return NULL;
- }
-
- /* check the indexes passed */
-
- if ((offset < 0) || (len < 0) || ((offset + len) > data->header.size)) {
- exceptions_throw_arrayindexoutofboundsexception();
- return NULL;
- }
-
- if (name) {
- /* convert '.' to '/' in java string */
-
- utfname = javastring_toutf(name, true);
-
- /* check if this class has already been defined */
-
- c = classcache_lookup_defined_or_initiated((java_objectheader *) cl, utfname);
- if (c) {
- *exceptionptr =
- exceptions_new_linkageerror("duplicate class definition: ",c);
- return NULL;
- }
- }
- else {
- utfname = NULL;
- }
-
-
-#if defined(ENABLE_JVMTI)
- /* fire Class File Load Hook JVMTI event */
- if (jvmti) jvmti_ClassFileLoadHook(utfname, len, (unsigned char*)data->data,
- (java_objectheader *)cl, (java_objectheader *)pd,
- &new_class_data_len, &new_class_data);
-#endif
-
-
- /* create a new classinfo struct */
-
- c = class_create_classinfo(utfname);
-
-#if defined(ENABLE_STATISTICS)
- /* measure time */
-
- if (opt_getloadingtime)
- loadingtime_start();
-#endif
-
- /* build a classbuffer with the given data */
-
- cb = NEW(classbuffer);
- cb->class = c;
-#if defined(ENABLE_JVMTI)
- /* check if the JVMTI wants to modify the class */
- if (new_class_data == NULL) {
-#endif
- cb->size = len;
- cb->data = (u1 *) &data->data[offset];
-#if defined(ENABLE_JVMTI)
- } else {
- cb->size = new_class_data_len;
- cb->data = (u1 *) new_class_data;
- }
-#endif
- cb->pos = cb->data;
-
- /* preset the defining classloader */
-
- c->classloader = (java_objectheader *) cl;
-
- /* load the class from this buffer */
-
- r = load_class_from_classbuffer(cb);
-
- /* free memory */
-
- FREE(cb, classbuffer);
-
-#if defined(ENABLE_STATISTICS)
- /* measure time */
-
- if (opt_getloadingtime)
- loadingtime_stop();
-#endif
-
- if (!r) {
- /* If return value is NULL, we had a problem and the class is not */
- /* loaded. */
- /* now free the allocated memory, otherwise we could run into a DOS */
-
- class_free(c);
-
- return NULL;
- }
-
- /* set ProtectionDomain */
-
- c->object.pd = pd;
-
- /* Store the newly defined class in the class cache. This call also */
- /* checks whether a class of the same name has already been defined by */
- /* the same defining loader, and if so, replaces the newly created class */
- /* by the one defined earlier. */
- /* Important: The classinfo given to classcache_store must be */
- /* fully prepared because another thread may return this */
- /* pointer after the lookup at to top of this function */
- /* directly after the class cache lock has been released. */
-
- c = classcache_store((java_objectheader *)cl,c,true);
-
- return (java_lang_Class *) c;
-}
-
-
-/*
- * Class: java/lang/VMClassLoader
- * Method: getPrimitiveClass
- * Signature: (C)Ljava/lang/Class;
- */
-JNIEXPORT java_lang_Class* JNICALL Java_java_lang_VMClassLoader_getPrimitiveClass(JNIEnv *env, jclass clazz, s4 type)
-{
- classinfo *c;
-
- /* get primitive class */
-
- switch (type) {
- case 'I':
- c = primitivetype_table[PRIMITIVETYPE_INT].class_primitive;
- break;
- case 'J':
- c = primitivetype_table[PRIMITIVETYPE_LONG].class_primitive;
- break;
- case 'F':
- c = primitivetype_table[PRIMITIVETYPE_FLOAT].class_primitive;
- break;
- case 'D':
- c = primitivetype_table[PRIMITIVETYPE_DOUBLE].class_primitive;
- break;
- case 'B':
- c = primitivetype_table[PRIMITIVETYPE_BYTE].class_primitive;
- break;
- case 'C':
- c = primitivetype_table[PRIMITIVETYPE_CHAR].class_primitive;
- break;
- case 'S':
- c = primitivetype_table[PRIMITIVETYPE_SHORT].class_primitive;
- break;
- case 'Z':
- c = primitivetype_table[PRIMITIVETYPE_BOOLEAN].class_primitive;
- break;
- case 'V':
- c = primitivetype_table[PRIMITIVETYPE_VOID].class_primitive;
- break;
- default:
- *exceptionptr = new_exception(string_java_lang_ClassNotFoundException);
- c = NULL;
- }
-
- return (java_lang_Class *) c;
-}
-
-
-/*
- * Class: java/lang/VMClassLoader
- * Method: resolveClass
- * Signature: (Ljava/lang/Class;)V
- */
-JNIEXPORT void JNICALL Java_java_lang_VMClassLoader_resolveClass(JNIEnv *env, jclass clazz, java_lang_Class *c)
-{
- classinfo *ci;
-
- ci = (classinfo *) c;
-
- if (!ci) {
- exceptions_throw_nullpointerexception();
- return;
- }
-
- /* link the class */
-
- if (!(ci->state & CLASS_LINKED))
- (void) link_class(ci);
-
- return;
-}
-
-
-/*
- * Class: java/lang/VMClassLoader
- * Method: loadClass
- * Signature: (Ljava/lang/String;Z)Ljava/lang/Class;
- */
-JNIEXPORT java_lang_Class* JNICALL Java_java_lang_VMClassLoader_loadClass(JNIEnv *env, jclass clazz, java_lang_String *name, jboolean resolve)
-{
- classinfo *c;
- utf *u;
-
- if (name == NULL) {
- exceptions_throw_nullpointerexception();
- return NULL;
- }
-
- /* create utf string in which '.' is replaced by '/' */
-
- u = javastring_toutf(name, true);
-
- /* load class */
-
- if (!(c = load_class_bootstrap(u)))
- goto exception;
-
- /* resolve class -- if requested */
-
-/* if (resolve) */
- if (!link_class(c))
- goto exception;
-
- return (java_lang_Class *) c;
-
- exception:
- c = (*exceptionptr)->vftbl->class;
-
- /* if the exception is a NoClassDefFoundError, we replace it with a
- ClassNotFoundException, otherwise return the exception */
-
- if (c == class_java_lang_NoClassDefFoundError) {
- /* clear exceptionptr, because builtin_new checks for
- ExceptionInInitializerError */
- *exceptionptr = NULL;
-
- *exceptionptr =
- new_exception_javastring(string_java_lang_ClassNotFoundException, name);
- }
-
- return NULL;
-}
-
-
-/*
- * Class: java/lang/VMClassLoader
- * Method: nativeGetResources
- * Signature: (Ljava/lang/String;)Ljava/util/Vector;
- */
-JNIEXPORT java_util_Vector* JNICALL Java_java_lang_VMClassLoader_nativeGetResources(JNIEnv *env, jclass clazz, java_lang_String *name)
-{
- jobject o; /* vector being created */
- methodinfo *m; /* "add" method of vector */
- java_lang_String *path; /* path to be added */
- list_classpath_entry *lce; /* classpath entry */
- utf *utfname; /* utf to look for */
- char *buffer; /* char buffer */
- char *namestart; /* start of name to use */
- char *tmppath; /* temporary buffer */
- s4 namelen; /* length of name to use */
- s4 searchlen; /* length of name to search */
- s4 bufsize; /* size of buffer allocated */
- s4 pathlen; /* name of path to assemble */
- struct stat buf; /* buffer for stat */
- jboolean ret; /* return value of "add" */
-
- /* get the resource name as utf string */
-
- utfname = javastring_toutf(name, false);
- if (!utfname)
- return NULL;
-
- /* copy it to a char buffer */
-
- namelen = utf_bytes(utfname);
- searchlen = namelen;
- bufsize = namelen + strlen("0");
- buffer = MNEW(char, bufsize);
-
- utf_copy(buffer, utfname);
- namestart = buffer;
-
- /* skip leading '/' */
-
- if (namestart[0] == '/') {
- namestart++;
- namelen--;
- searchlen--;
- }
-
- /* remove trailing `.class' */
-
- if (namelen >= 6 && strcmp(namestart + (namelen - 6), ".class") == 0) {
- searchlen -= 6;
- }
-
- /* create a new needle to look for, if necessary */
-
- if (searchlen != bufsize-1) {
- utfname = utf_new(namestart, searchlen);
- if (utfname == NULL)
- goto return_NULL;
- }
-
- /* new Vector() */
-
- o = native_new_and_init(class_java_util_Vector);
-
- if (!o)
- goto return_NULL;
-
- /* get Vector.add() method */
-
- m = class_resolveclassmethod(class_java_util_Vector,
- utf_add,
- utf_new_char("(Ljava/lang/Object;)Z"),
- NULL,
- true);
-
- if (!m)
- goto return_NULL;
-
- /* iterate over all classpath entries */
-
- for (lce = list_first(list_classpath_entries); lce != NULL;
- lce = list_next(list_classpath_entries, lce)) {
- /* clear path pointer */
- path = NULL;
-
-#if defined(ENABLE_ZLIB)
- if (lce->type == CLASSPATH_ARCHIVE) {
-
- if (zip_find(lce, utfname)) {
- pathlen = strlen("jar:file://") + lce->pathlen + strlen("!/") +
- namelen + strlen("0");
-
- tmppath = MNEW(char, pathlen);
-
- sprintf(tmppath, "jar:file://%s!/%s", lce->path, namestart);
- path = javastring_new_from_utf_string(tmppath),
-
- MFREE(tmppath, char, pathlen);
- }
-
- } else {
-#endif /* defined(ENABLE_ZLIB) */
- pathlen = strlen("file://") + lce->pathlen + namelen + strlen("0");
-
- tmppath = MNEW(char, pathlen);
-
- sprintf(tmppath, "file://%s%s", lce->path, namestart);
-
- /* Does this file exist? */
-
- if (stat(tmppath + strlen("file://") - 1, &buf) == 0)
- if (!S_ISDIR(buf.st_mode))
- path = javastring_new_from_utf_string(tmppath);
-
- MFREE(tmppath, char, pathlen);
-#if defined(ENABLE_ZLIB)
- }
-#endif
-
- /* if a resource was found, add it to the vector */
-
- if (path) {
- ret = vm_call_method_int(m, o, path);
-
- if (*exceptionptr)
- goto return_NULL;
-
- if (ret == 0)
- goto return_NULL;
- }
- }
-
- MFREE(buffer, char, bufsize);
-
- return (java_util_Vector *) o;
-
-return_NULL:
- MFREE(buffer, char, bufsize);
-
- return NULL;
-}
-
-
-/*
- * Class: java/lang/VMClassLoader
- * Method: defaultAssertionStatus
- * Signature: ()Z
- */
-JNIEXPORT s4 JNICALL Java_java_lang_VMClassLoader_defaultAssertionStatus(JNIEnv *env, jclass clazz)
-{
- return _Jv_jvm->Java_java_lang_VMClassLoader_defaultAssertionStatus;
-}
-
-
-/*
- * Class: java/lang/VMClassLoader
- * Method: findLoadedClass
- * Signature: (Ljava/lang/ClassLoader;Ljava/lang/String;)Ljava/lang/Class;
- */
-JNIEXPORT java_lang_Class* JNICALL Java_java_lang_VMClassLoader_findLoadedClass(JNIEnv *env, jclass clazz, java_lang_ClassLoader *cl, java_lang_String *name)
-{
- classinfo *c;
- utf *u;
-
- /* replace `.' by `/', this is required by the classcache */
-
- u = javastring_toutf(name, true);
-
- /* lookup for defining classloader */
-
- c = classcache_lookup_defined((classloader *) cl, u);
-
- /* if not found, lookup for initiating classloader */
-
- if (c == NULL)
- c = classcache_lookup((classloader *) cl, u);
-
- return (java_lang_Class *) c;
-}
-
-
-/*
- * These are local overrides for various environment variables in Emacs.
- * Please do not remove this and leave it at the end of the file, where
- * Emacs will automagically detect them.
- * ---------------------------------------------------------------------
- * Local variables:
- * mode: c
- * indent-tabs-mode: t
- * c-basic-offset: 4
- * tab-width: 4
- * End:
- * vim:noexpandtab:sw=4:ts=4:
- */
+++ /dev/null
-/* src/native/vm/VMObject.c - java/lang/VMObject
-
- Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
- C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
- E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
- J. Wenninger, Institut f. Computersprachen - TU Wien
-
- This file is part of CACAO.
-
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License as
- published by the Free Software Foundation; either version 2, or (at
- your option) any later version.
-
- This program is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- 02110-1301, USA.
-
- Contact: cacao@cacaojvm.org
-
- Authors: Roman Obermaiser
-
- Changes: Joseph Wenninger
- Christian Thalinger
-
- $Id: VMObject.c 5031 2006-06-14 18:36:22Z motse $
-
-*/
-
-
-#include "config.h"
-
-#include <stdlib.h>
-#include <string.h>
-
-#include "vm/types.h"
-
-#include "mm/boehm.h"
-#include "mm/memory.h"
-#include "toolbox/logging.h"
-#include "native/jni.h"
-#include "native/native.h"
-#include "native/include/java_lang_Class.h"
-#include "native/include/java_lang_Cloneable.h"
-#include "native/include/java_lang_Object.h"
-
-#if defined(ENABLE_THREADS)
-# include "threads/native/threads.h"
-#endif
-
-#include "vm/builtin.h"
-#include "vm/exceptions.h"
-#include "vm/loader.h"
-#include "vm/options.h"
-#include "vm/stringlocal.h"
-
-#if defined(ENABLE_JVMTI)
-#include "native/jvmti/cacaodbg.h"
-#endif
-
-
-/*
- * Class: java/lang/VMObject
- * Method: getClass
- * Signature: (Ljava/lang/Object;)Ljava/lang/Class;
- */
-JNIEXPORT java_lang_Class* JNICALL Java_java_lang_VMObject_getClass(JNIEnv *env, jclass clazz, java_lang_Object *obj)
-{
- classinfo *c;
-
- if (!obj)
- return NULL;
-
- c = ((java_objectheader *) obj)->vftbl->class;
-
- return (java_lang_Class *) c;
-}
-
-
-/*
- * Class: java/lang/VMObject
- * Method: clone
- * Signature: (Ljava/lang/Cloneable;)Ljava/lang/Object;
- */
-JNIEXPORT java_lang_Object* JNICALL Java_java_lang_VMObject_clone(JNIEnv *env, jclass clazz, java_lang_Cloneable *this)
-{
- classinfo *c;
- java_lang_Object *new;
- arraydescriptor *desc;
-
- /* we are cloning an array */
-
- if ((desc = this->header.vftbl->arraydesc) != NULL) {
-
- u4 size = desc->dataoffset + desc->componentsize * ((java_arrayheader *) this)->size;
-
- new = (java_lang_Object *)
- heap_allocate(size, (desc->arraytype == ARRAYTYPE_OBJECT), NULL);
-
- if (new == NULL)
- return NULL;
-
- MCOPY(new, this, u1, size);
-
-#if defined(ENABLE_THREADS)
- lock_init_object_lock((java_objectheader *) new);
-#endif
-
- return new;
- }
-
- /* we are cloning a non-array */
-
- if (!builtin_instanceof((java_objectheader *) this, class_java_lang_Cloneable)) {
- *exceptionptr =
- new_exception(string_java_lang_CloneNotSupportedException);
- return NULL;
- }
-
- c = this->header.vftbl->class;
- new = (java_lang_Object *) builtin_new(c);
-
- if (new == NULL)
- return NULL;
-
- MCOPY(new, this, u1, c->instancesize);
-
-#if defined(ENABLE_THREADS)
- lock_init_object_lock((java_objectheader *) new);
-#endif
-
- return new;
-}
-
-
-/*
- * Class: java/lang/VMObject
- * Method: notify
- * Signature: ()V
- */
-JNIEXPORT void JNICALL Java_java_lang_VMObject_notify(JNIEnv *env, jclass clazz, java_lang_Object *this)
-{
-#if defined(ENABLE_THREADS)
- lock_notify_object(&this->header);
-#endif
-}
-
-
-/*
- * Class: java/lang/VMObject
- * Method: notifyAll
- * Signature: ()V
- */
-JNIEXPORT void JNICALL Java_java_lang_VMObject_notifyAll(JNIEnv *env, jclass clazz, java_lang_Object *this)
-{
-#if defined(ENABLE_THREADS)
- lock_notify_all_object(&this->header);
-#endif
-}
-
-
-/*
- * Class: java/lang/VMObject
- * Method: wait
- * Signature: (Ljava/lang/Object;JI)V
- */
-JNIEXPORT void JNICALL Java_java_lang_VMObject_wait(JNIEnv *env, jclass clazz, java_lang_Object *o, s8 ms, s4 ns)
-{
-#if defined(ENABLE_JVMTI)
- /* Monitor Wait */
- if (jvmti) jvmti_MonitorWaiting(true, o, ms);
-#endif
-
-#if defined(ENABLE_THREADS)
- lock_wait_for_object(&o->header, ms, ns);
-#endif
-
-#if defined(ENABLE_JVMTI)
- /* Monitor Waited */
- /* XXX: How do you know if wait timed out ?*/
- if (jvmti) jvmti_MonitorWaiting(false, o, 0);
-#endif
-}
-
-
-/*
- * These are local overrides for various environment variables in Emacs.
- * Please do not remove this and leave it at the end of the file, where
- * Emacs will automagically detect them.
- * ---------------------------------------------------------------------
- * Local variables:
- * mode: c
- * indent-tabs-mode: t
- * c-basic-offset: 4
- * tab-width: 4
- * End:
- */
+++ /dev/null
-/* src/native/vm/VMProxy.c - java/lang/reflect/VMProxy
-
- Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
- C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
- E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
- J. Wenninger, Institut f. Computersprachen - TU Wien
-
- This file is part of CACAO.
-
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License as
- published by the Free Software Foundation; either version 2, or (at
- your option) any later version.
-
- This program is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- 02110-1301, USA.
-
- Contact: cacao@cacaojvm.org
-
- Authors: Roman Obermaiser
-
- Changes: Joseph Wenninger
- Christian Thalinger
-
- $Id: VMProxy.c 4357 2006-01-22 23:33:38Z twisti $
-
-*/
-
-
-#include <stdlib.h>
-
-#include "native/jni.h"
-#include "native/include/java_lang_Class.h"
-#include "native/include/java_lang_ClassLoader.h"
-#include "toolbox/logging.h"
-
-
-/*
- * Class: java/lang/reflect/VMProxy
- * Method: getProxyClass
- * Signature: (Ljava/lang/ClassLoader;[Ljava/lang/Class;)Ljava/lang/Class;
- */
-JNIEXPORT java_lang_Class* JNICALL Java_java_lang_reflect_VMProxy_getProxyClass(JNIEnv *env, jclass clazz, java_lang_ClassLoader *par1, java_objectarray *par2)
-{
- log_text("Java_java_lang_reflect_Proxy_getProxyClass: IMPLEMENT ME!");
-
- return NULL;
-}
-
-
-/*
- * Class: java/lang/reflect/VMProxy
- * Method: getProxyData
- * Signature: (Ljava/lang/ClassLoader;[Ljava/lang/Class;)Ljava/lang/reflect/Proxy$ProxyData;
- */
-JNIEXPORT struct java_lang_reflect_Proxy_ProxyData* JNICALL Java_java_lang_reflect_VMProxy_getProxyData(JNIEnv *env, jclass clazz, java_lang_ClassLoader *par1, java_objectarray *par2)
-{
- log_text("Java_java_lang_reflect_Proxy_getProxyData: IMPLEMENT ME!");
-
- return NULL;
-}
-
-
-/*
- * Class: java/lang/reflect/VMProxy
- * Method: generateProxyClass
- * Signature: (Ljava/lang/ClassLoader;Ljava/lang/reflect/Proxy$ProxyData;)Ljava/lang/Class;
- */
-JNIEXPORT java_lang_Class* JNICALL Java_java_lang_reflect_VMProxy_generateProxyClass(JNIEnv *env, jclass clazz, java_lang_ClassLoader *par1, struct java_lang_reflect_Proxy_ProxyData *par2)
-{
- log_text("Java_java_lang_reflect_Proxy_generateProxyClass: IMPLEMENT ME!");
-
- return NULL;
-}
-
-
-/*
- * These are local overrides for various environment variables in Emacs.
- * Please do not remove this and leave it at the end of the file, where
- * Emacs will automagically detect them.
- * ---------------------------------------------------------------------
- * Local variables:
- * mode: c
- * indent-tabs-mode: t
- * c-basic-offset: 4
- * tab-width: 4
- * End:
- */
+++ /dev/null
-/* src/native/vm/VMRuntime.c - java/lang/VMRuntime
-
- Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
- C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
- E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
- J. Wenninger, Institut f. Computersprachen - TU Wien
-
- This file is part of CACAO.
-
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License as
- published by the Free Software Foundation; either version 2, or (at
- your option) any later version.
-
- This program is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- 02110-1301, USA.
-
- Contact: cacao@cacaojvm.org
-
- Authors: Roman Obermaiser
-
- Changes: Joseph Wenninger
- Christian Thalinger
- Edwin Steiner
-
- $Id: VMRuntime.c 5143 2006-07-17 10:00:33Z twisti $
-
-*/
-
-
-#include "config.h"
-
-#include <assert.h>
-#include <string.h>
-#include <stdlib.h>
-#include <sys/utsname.h>
-
-#if !defined(WITH_STATIC_CLASSPATH)
-# include <ltdl.h>
-#endif
-
-#if defined(__DARWIN__)
-# define OS_INLINE /* required for <libkern/ppc/OSByteOrder.h> */
-# include <mach/mach.h>
-#endif
-
-#include "vm/types.h"
-
-#include "mm/boehm.h"
-#include "mm/memory.h"
-#include "native/jni.h"
-#include "native/native.h"
-#include "native/include/java_io_File.h"
-#include "native/include/java_lang_String.h"
-#include "native/include/java_lang_Process.h"
-#include "toolbox/logging.h"
-#include "vm/builtin.h"
-#include "vm/exceptions.h"
-#include "vm/loader.h"
-#include "vm/options.h"
-#include "vm/stringlocal.h"
-#include "vm/vm.h"
-
-
-/* this should work on BSD */
-/*
-#if defined(__DARWIN__)
-#include <sys/sysctl.h>
-#endif
-*/
-
-
-/* should we run all finalizers on exit? */
-static bool finalizeOnExit = false;
-
-
-/*
- * Class: java/lang/VMRuntime
- * Method: exitInternal
- * Signature: (I)V
- */
-JNIEXPORT void JNICALL Java_java_lang_VMRuntime_exit(JNIEnv *env, jclass clazz, s4 par1)
-{
- if (finalizeOnExit)
- gc_finalize_all();
-
- vm_shutdown(par1);
-}
-
-
-/*
- * Class: java/lang/VMRuntime
- * Method: freeMemory
- * Signature: ()J
- */
-JNIEXPORT s8 JNICALL Java_java_lang_VMRuntime_freeMemory(JNIEnv *env, jclass clazz)
-{
- return gc_get_free_bytes();
-}
-
-
-/*
- * Class: java/lang/VMRuntime
- * Method: totalMemory
- * Signature: ()J
- */
-JNIEXPORT s8 JNICALL Java_java_lang_VMRuntime_totalMemory(JNIEnv *env, jclass clazz)
-{
- return gc_get_heap_size();
-}
-
-
-/*
- * Class: java/lang/VMRuntime
- * Method: maxMemory
- * Signature: ()J
- */
-JNIEXPORT s8 JNICALL Java_java_lang_VMRuntime_maxMemory(JNIEnv *env, jclass clazz)
-{
- return gc_get_max_heap_size();
-}
-
-
-/*
- * Class: java/lang/VMRuntime
- * Method: gc
- * Signature: ()V
- */
-JNIEXPORT void JNICALL Java_java_lang_VMRuntime_gc(JNIEnv *env, jclass clazz)
-{
- gc_call();
-}
-
-
-/*
- * Class: java/lang/VMRuntime
- * Method: runFinalization
- * Signature: ()V
- */
-JNIEXPORT void JNICALL Java_java_lang_VMRuntime_runFinalization(JNIEnv *env, jclass clazz)
-{
- gc_invoke_finalizers();
-}
-
-
-/*
- * Class: java/lang/VMRuntime
- * Method: runFinalizersOnExit
- * Signature: (Z)V
- */
-JNIEXPORT void JNICALL Java_java_lang_VMRuntime_runFinalizersOnExit(JNIEnv *env, jclass clazz, s4 value)
-{
- /* XXX threading */
-
- finalizeOnExit = value;
-}
-
-
-/*
- * Class: java/lang/VMRuntime
- * Method: runFinalizationsForExit
- * Signature: ()V
- */
-JNIEXPORT void JNICALL Java_java_lang_VMRuntime_runFinalizationForExit(JNIEnv *env, jclass clazz)
-{
-/* if (finalizeOnExit) { */
-/* gc_call(); */
- /* gc_finalize_all(); */
-/* } */
-/* log_text("Java_java_lang_VMRuntime_runFinalizationForExit called"); */
- /*gc_finalize_all();*/
- /*gc_invoke_finalizers();*/
- /*gc_call();*/
-}
-
-
-/*
- * Class: java/lang/VMRuntime
- * Method: traceInstructions
- * Signature: (Z)V
- */
-JNIEXPORT void JNICALL Java_java_lang_VMRuntime_traceInstructions(JNIEnv *env, jclass clazz, s4 par1)
-{
- /* not supported */
-}
-
-
-/*
- * Class: java/lang/VMRuntime
- * Method: traceMethodCalls
- * Signature: (Z)V
- */
-JNIEXPORT void JNICALL Java_java_lang_VMRuntime_traceMethodCalls(JNIEnv *env, jclass clazz, s4 par1)
-{
- /* not supported */
-}
-
-
-/*
- * Class: java/lang/VMRuntime
- * Method: availableProcessors
- * Signature: ()I
- */
-JNIEXPORT s4 JNICALL Java_java_lang_VMRuntime_availableProcessors(JNIEnv *env, jclass clazz)
-{
-#if defined(_SC_NPROC_ONLN)
- return (s4) sysconf(_SC_NPROC_ONLN);
-
-#elif defined(_SC_NPROCESSORS_ONLN)
- return (s4) sysconf(_SC_NPROCESSORS_ONLN);
-
-#elif defined(__DARWIN__)
- /* this should work in BSD */
- /*
- int ncpu, mib[2], rc;
- size_t len;
-
- mib[0] = CTL_HW;
- mib[1] = HW_NCPU;
- len = sizeof(ncpu);
- rc = sysctl(mib, 2, &ncpu, &len, NULL, 0);
-
- return (s4) ncpu;
- */
-
- host_basic_info_data_t hinfo;
- mach_msg_type_number_t hinfo_count = HOST_BASIC_INFO_COUNT;
- kern_return_t rc;
-
- rc = host_info(mach_host_self(), HOST_BASIC_INFO,
- (host_info_t) &hinfo, &hinfo_count);
-
- if (rc != KERN_SUCCESS) {
- return -1;
- }
-
- return (s4) hinfo.avail_cpus;
-
-#else
- return 1;
-#endif
-}
-
-
-/*
- * Class: java/lang/VMRuntime
- * Method: nativeLoad
- * Signature: (Ljava/lang/String;Ljava/lang/ClassLoader;)I
- */
-JNIEXPORT s4 JNICALL Java_java_lang_VMRuntime_nativeLoad(JNIEnv *env, jclass clazz, java_lang_String *filename, java_lang_ClassLoader *loader)
-{
-#if !defined(WITH_STATIC_CLASSPATH)
- utf *name;
- lt_dlhandle handle;
- lt_ptr onload;
- s4 version;
-#endif
-
- if (filename == NULL) {
- exceptions_throw_nullpointerexception();
- return 0;
- }
-
-#if defined(WITH_STATIC_CLASSPATH)
- return 1;
-#else /* defined(WITH_STATIC_CLASSPATH) */
- name = javastring_toutf(filename, 0);
-
- /* is the library already loaded? */
-
- if (native_hashtable_library_find(name, (java_objectheader *) loader))
- return 1;
-
- /* try to open the library */
-
- if (!(handle = lt_dlopen(name->text))) {
- if (opt_verbose) {
- log_start();
- log_print("Java_java_lang_VMRuntime_nativeLoad: ");
- log_print(lt_dlerror());
- log_finish();
- }
-
- return 0;
- }
-
- /* resolve JNI_OnLoad function */
-
- if ((onload = lt_dlsym(handle, "JNI_OnLoad"))) {
- JNIEXPORT s4 (JNICALL *JNI_OnLoad) (JavaVM *, void *);
- JavaVM *vm;
-
- JNI_OnLoad = (JNIEXPORT s4 (JNICALL *)(JavaVM *, void *)) (ptrint) onload;
-
- (*env)->GetJavaVM(env, &vm);
-
- version = JNI_OnLoad(vm, NULL);
-
- /* if the version is not 1.2 and not 1.4 the library cannot be loaded */
-
- if ((version != JNI_VERSION_1_2) && (version != JNI_VERSION_1_4)) {
- lt_dlclose(handle);
-
- return 0;
- }
- }
-
- /* insert the library name into the library hash */
-
- native_hashtable_library_add(name, (java_objectheader *) loader, handle);
-
- return 1;
-#endif /* defined(WITH_STATIC_CLASSPATH) */
-}
-
-
-/*
- * Class: java/lang/VMRuntime
- * Method: mapLibraryName
- * Signature: (Ljava/lang/String;)Ljava/lang/String;
- */
-JNIEXPORT java_lang_String* JNICALL Java_java_lang_VMRuntime_mapLibraryName(JNIEnv *env, jclass clazz, java_lang_String *libname)
-{
- utf *u;
- char *buffer;
- s4 buffer_len;
- s4 dumpsize;
- java_lang_String *s;
-
- if (!libname) {
- exceptions_throw_nullpointerexception();
- return NULL;
- }
-
- u = javastring_toutf(libname, 0);
-
- /* calculate length of library name */
-
- buffer_len = strlen("lib");
-
- buffer_len += utf_bytes(u);
-
-#if defined(__DARWIN__)
- buffer_len += strlen(".dylib");
-#else
- buffer_len += strlen(".so");
-#endif
-
- buffer_len += strlen("0");
-
- dumpsize = dump_size();
- buffer = DMNEW(char, buffer_len);
-
- /* generate library name */
-
- strcpy(buffer, "lib");
- utf_cat(buffer, u);
-
-#if defined(__DARWIN__)
- strcat(buffer, ".dylib");
-#else
- strcat(buffer, ".so");
-#endif
-
- s = javastring_new_from_utf_string(buffer);
-
- /* release memory */
-
- dump_release(dumpsize);
-
- return s;
-}
-
-
-/*
- * These are local overrides for various environment variables in Emacs.
- * Please do not remove this and leave it at the end of the file, where
- * Emacs will automagically detect them.
- * ---------------------------------------------------------------------
- * Local variables:
- * mode: c
- * indent-tabs-mode: t
- * c-basic-offset: 4
- * tab-width: 4
- * End:
- * vim:noexpandtab:sw=4:ts=4:
- */
+++ /dev/null
-/* src/native/vm/VMStackWalker.c - gnu/classpath/VMStackWalker
-
- Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
- C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
- E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
- J. Wenninger, Institut f. Computersprachen - TU Wien
-
- This file is part of CACAO.
-
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License as
- published by the Free Software Foundation; either version 2, or (at
- your option) any later version.
-
- This program is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- 02110-1301, USA.
-
- Contact: cacao@cacaojvm.org
-
- Authors: Christian Thalinger
-
- Changes: Edwin Steiner
-
- $Id: VMStackWalker.c 4807 2006-04-21 13:08:00Z edwin $
-
-*/
-
-
-#include "config.h"
-
-#include "native/jni.h"
-#include "native/native.h"
-#include "native/include/java_lang_Class.h"
-#include "native/include/java_lang_ClassLoader.h"
-#include "vm/builtin.h"
-#include "vm/class.h"
-#include "vm/global.h"
-#include "vm/options.h"
-
-
-/*
- * Class: gnu/classpath/VMStackWalker
- * Method: getClassContext
- * Signature: ()[Ljava/lang/Class;
- */
-JNIEXPORT java_objectarray* JNICALL Java_gnu_classpath_VMStackWalker_getClassContext(JNIEnv *env, jclass clazz)
-{
-/* if (cacao_initializing) */
-/* return NULL; */
-
-#if defined(__ALPHA__) || defined(__ARM__) || defined(__I386__) || defined(__MIPS__) || defined(__POWERPC__) || defined(__X86_64__)
- /* these JITs support stacktraces, and so does the interpreter */
-
- return stacktrace_getClassContext();
-
-#else
-# if defined(ENABLE_INTRP)
- /* the interpreter supports stacktraces, even if the JIT does not */
-
- if (opt_intrp) {
- return stacktrace_getClassContext();
-
- }
- else
-# endif
- {
- return builtin_anewarray(0, class_java_lang_Class);
- }
-#endif
-}
-
-
-/*
- * Class: gnu/classpath/VMStackWalker
- * Method: getCallingClass
- * Signature: ()Ljava/lang/Class;
- */
-JNIEXPORT java_lang_Class* JNICALL Java_gnu_classpath_VMStackWalker_getCallingClass(JNIEnv *env, jclass clazz)
-{
-#if defined(__ALPHA__) || defined(__ARM__) || defined(__I386__) || defined(__MIPS__) || defined(__POWERPC__) || defined(__X86_64__)
- /* these JITs support stacktraces, and so does the interpreter */
-
- java_objectarray *oa;
-
- oa = stacktrace_getClassContext();
- if (!oa)
- return NULL;
-
- if (oa->header.size < 2)
- return NULL;
-
- return (java_lang_Class *) oa->data[1];
-
-#else
-# if defined(ENABLE_INTRP)
- /* the interpreter supports stacktraces, even if the JIT does not */
-
- if (opt_intrp) {
- java_objectarray *oa;
-
- oa = stacktrace_getClassContext();
- if (!oa)
- return NULL;
-
- if (oa->header.size < 2)
- return NULL;
-
- return (java_lang_Class *) oa->data[1];
-
- }
- else
-# endif
- {
- return NULL;
- }
-#endif
-}
-
-
-/*
- * Class: gnu/classpath/VMStackWalker
- * Method: getCallingClassLoader
- * Signature: ()Ljava/lang/ClassLoader;
- */
-JNIEXPORT java_lang_ClassLoader* JNICALL Java_gnu_classpath_VMStackWalker_getCallingClassLoader(JNIEnv *env, jclass clazz)
-{
- java_objectarray *oa;
- classinfo *c;
- java_objectheader *cl;
-
-#if defined(__ALPHA__) || defined(__ARM__) || defined(__I386__) || defined(__MIPS__) || defined(__POWERPC__) || defined(__X86_64__)
- /* these JITs support stacktraces, and so does the interpreter */
-
- oa = stacktrace_getClassContext();
- if (!oa)
- return NULL;
-
- if (oa->header.size < 2)
- return NULL;
-
- c = (classinfo *) oa->data[1];
-
- cl = c->classloader;
-#else
-# if defined(ENABLE_INTRP)
- /* the interpreter supports stacktraces, even if the JIT does not */
-
- if (opt_intrp) {
- oa = stacktrace_getClassContext();
- if (!oa)
- return NULL;
-
- if (oa->header.size < 2)
- return NULL;
-
- c = (classinfo *) oa->data[1];
-
- cl = c->classloader;
-
- }
- else
-# endif
- {
- cl = NULL;
- }
-#endif
-
- return (java_lang_ClassLoader *) cl;
-}
-
-
-/*
- * These are local overrides for various environment variables in Emacs.
- * Please do not remove this and leave it at the end of the file, where
- * Emacs will automagically detect them.
- * ---------------------------------------------------------------------
- * Local variables:
- * mode: c
- * indent-tabs-mode: t
- * c-basic-offset: 4
- * tab-width: 4
- * End:
- * vim:noexpandtab:sw=4:ts=4:
- */
+++ /dev/null
-/* native/vm/VMString.c - java/lang/VMString
-
- Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
- C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
- E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
- J. Wenninger, Institut f. Computersprachen - TU Wien
-
- This file is part of CACAO.
-
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License as
- published by the Free Software Foundation; either version 2, or (at
- your option) any later version.
-
- This program is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- 02110-1301, USA.
-
- Contact: cacao@cacaojvm.org
-
- Authors: Roman Obermaiser
-
- Changes: Christian Thalinger
-
- $Id: VMString.c 4357 2006-01-22 23:33:38Z twisti $
-
-*/
-
-
-#include <stdlib.h>
-
-#include "native/jni.h"
-#include "native/native.h"
-#include "native/include/java_lang_String.h"
-#include "vm/stringlocal.h"
-
-
-/*
- * Class: java/lang/VMString
- * Method: intern
- * Signature: (Ljava/lang/String;)Ljava/lang/String;
- */
-JNIEXPORT java_lang_String* JNICALL Java_java_lang_VMString_intern(JNIEnv *env, jclass clazz, java_lang_String *str)
-{
- java_objectheader *o;
-
- if (!str)
- return NULL;
-
- /* search table so identical strings will get identical pointers */
-
- o = literalstring_u2(str->value, str->count, str->offset, true);
-
- return (java_lang_String *) o;
-}
-
-
-/*
- * These are local overrides for various environment variables in Emacs.
- * Please do not remove this and leave it at the end of the file, where
- * Emacs will automagically detect them.
- * ---------------------------------------------------------------------
- * Local variables:
- * mode: c
- * indent-tabs-mode: t
- * c-basic-offset: 4
- * tab-width: 4
- * End:
- */
+++ /dev/null
-/* src/native/vm/VMSystem.c - java/lang/VMSystem
-
- Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
- C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
- E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
- J. Wenninger, Institut f. Computersprachen - TU Wien
-
- This file is part of CACAO.
-
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License as
- published by the Free Software Foundation; either version 2, or (at
- your option) any later version.
-
- This program is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- 02110-1301, USA.
-
- Contact: cacao@cacaojvm.org
-
- Authors: Roman Obermaiser
-
- Changes: Joseph Wenninger
- Christian Thalinger
-
- $Id: VMSystem.c 4485 2006-02-12 00:30:13Z twisti $
-
-*/
-
-
-#include <string.h>
-
-#include "config.h"
-#include "vm/types.h"
-
-#include "native/jni.h"
-#include "native/native.h"
-#include "native/include/java_lang_Object.h"
-#include "toolbox/logging.h"
-#include "vm/builtin.h"
-#include "vm/exceptions.h"
-#include "vm/stringlocal.h"
-
-
-/*
- * Class: java/lang/VMSystem
- * Method: arraycopy
- * Signature: (Ljava/lang/Object;ILjava/lang/Object;II)V
- */
-JNIEXPORT void JNICALL Java_java_lang_VMSystem_arraycopy(JNIEnv *env, jclass clazz, java_lang_Object *source, s4 sp, java_lang_Object *dest, s4 dp, s4 len)
-{
- java_arrayheader *s;
- java_arrayheader *d;
- arraydescriptor *sdesc;
- arraydescriptor *ddesc;
- s4 i;
-
- s = (java_arrayheader *) source;
- d = (java_arrayheader *) dest;
-
- if (!s || !d) {
- exceptions_throw_nullpointerexception();
- return;
- }
-
- sdesc = s->objheader.vftbl->arraydesc;
- ddesc = d->objheader.vftbl->arraydesc;
-
- if (!sdesc || !ddesc || (sdesc->arraytype != ddesc->arraytype)) {
- *exceptionptr = new_arraystoreexception();
- return;
- }
-
- /* we try to throw exception with the same message as SUN does */
-
- if ((len < 0) || (sp < 0) || (dp < 0) ||
- (sp + len < 0) || (sp + len > s->size) ||
- (dp + len < 0) || (dp + len > d->size)) {
- exceptions_throw_arrayindexoutofboundsexception();
- return;
- }
-
- if (sdesc->componentvftbl == ddesc->componentvftbl) {
- /* We copy primitive values or references of exactly the same type */
-
- s4 dataoffset = sdesc->dataoffset;
- s4 componentsize = sdesc->componentsize;
-
- memmove(((u1 *) d) + dataoffset + componentsize * dp,
- ((u1 *) s) + dataoffset + componentsize * sp,
- (size_t) len * componentsize);
-
- } else {
- /* We copy references of different type */
-
- java_objectarray *oas = (java_objectarray *) s;
- java_objectarray *oad = (java_objectarray *) d;
-
- if (dp <= sp) {
- for (i = 0; i < len; i++) {
- java_objectheader *o = oas->data[sp + i];
- if (!builtin_canstore(oad, o)) {
- *exceptionptr = new_arraystoreexception();
- return;
- }
- oad->data[dp + i] = o;
- }
-
- } else {
- /* XXX this does not completely obey the specification!
- If an exception is thrown only the elements above the
- current index have been copied. The specification
- requires that only the elements *below* the current
- index have been copied before the throw. */
-
- for (i = len - 1; i >= 0; i--) {
- java_objectheader *o = oas->data[sp + i];
-
- if (!builtin_canstore(oad, o)) {
- *exceptionptr = new_arraystoreexception();
- return;
- }
-
- oad->data[dp + i] = o;
- }
- }
- }
-}
-
-
-/*
- * Class: java/lang/VMSystem
- * Method: identityHashCode
- * Signature: (Ljava/lang/Object;)I
- */
-JNIEXPORT s4 JNICALL Java_java_lang_VMSystem_identityHashCode(JNIEnv *env, jclass clazz, java_lang_Object *o)
-{
- return (s4) ((ptrint) o);
-}
-
-
-/*
- * These are local overrides for various environment variables in Emacs.
- * Please do not remove this and leave it at the end of the file, where
- * Emacs will automagically detect them.
- * ---------------------------------------------------------------------
- * Local variables:
- * mode: c
- * indent-tabs-mode: t
- * c-basic-offset: 4
- * tab-width: 4
- * End:
- */
+++ /dev/null
-/* src/native/vm/VMSystemProperties.c - gnu/classpath/VMSystemProperties
-
- Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
- C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
- E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
- J. Wenninger, Institut f. Computersprachen - TU Wien
-
- This file is part of CACAO.
-
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License as
- published by the Free Software Foundation; either version 2, or (at
- your option) any later version.
-
- This program is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- 02110-1301, USA.
-
- Contact: cacao@cacaojvm.org
-
- Authors: Christian Thalinger
-
- Changes:
-
- $Id: VMSystemProperties.c 5150 2006-07-18 08:05:02Z twisti $
-
-*/
-
-
-#include "config.h"
-
-#include <stdlib.h>
-#include <string.h>
-#include <sys/utsname.h>
-#include <time.h>
-
-#include "vm/types.h"
-
-#include "mm/memory.h"
-#include "native/jni.h"
-#include "native/native.h"
-#include "native/include/java_util_Properties.h"
-#include "toolbox/logging.h"
-#include "toolbox/util.h"
-#include "vm/exceptions.h"
-#include "vm/builtin.h"
-#include "vm/loader.h"
-#include "vm/options.h"
-#include "vm/properties.h"
-#include "vm/suck.h"
-
-
-/*
- * Class: gnu/classpath/VMSystemProperties
- * Method: preInit
- * Signature: (Ljava/util/Properties;)V
- */
-JNIEXPORT void JNICALL Java_gnu_classpath_VMSystemProperties_preInit(JNIEnv *env, jclass clazz, java_util_Properties *p)
-{
- char *cwd;
- char *env_java_home;
- char *env_user;
- char *env_home;
- char *env_lang;
- char *java_home;
- char *extdirs;
- char *lang;
- char *country;
- struct utsname utsnamebuf;
- s4 len;
-
-#if !defined(WITH_STATIC_CLASSPATH)
- char *ld_library_path;
- char *libpath;
-#endif
-
- if (p == NULL) {
- exceptions_throw_nullpointerexception();
- return;
- }
-
- /* get properties from system */
-
- cwd = _Jv_getcwd();
- env_java_home = getenv("JAVA_HOME");
- env_user = getenv("USER");
- env_home = getenv("HOME");
- env_lang = getenv("LANG");
-
- uname(&utsnamebuf);
-
- /* post-initialize the properties */
-
- if (!properties_postinit(p))
- return;
-
- /* set JAVA_HOME to default prefix if not defined */
-
- if (env_java_home == NULL)
- env_java_home = CACAO_PREFIX;
-
- /* fill in system properties */
-
- properties_system_add("java.version", JAVA_VERSION);
- properties_system_add("java.vendor", "GNU Classpath");
- properties_system_add("java.vendor.url", "http://www.gnu.org/software/classpath/");
-
- /* add /jre to java.home property */
-
- len = strlen(env_java_home) + strlen("/jre") + strlen("0");
-
- java_home = MNEW(char, len);
-
- strcpy(java_home, env_java_home);
- strcat(java_home, "/jre");
-
- properties_system_add("java.home", java_home);
-
- MFREE(java_home, char, len);
-
- properties_system_add("java.vm.specification.version", "1.0");
- properties_system_add("java.vm.specification.vendor", "Sun Microsystems Inc.");
- properties_system_add("java.vm.specification.name", "Java Virtual Machine Specification");
- properties_system_add("java.vm.version", VERSION);
- properties_system_add("java.vm.vendor", "CACAO Team");
- properties_system_add("java.vm.name", "CACAO");
- properties_system_add("java.specification.version", "1.4");
- properties_system_add("java.specification.vendor", "Sun Microsystems Inc.");
- properties_system_add("java.specification.name", "Java Platform API Specification");
- properties_system_add("java.class.version", CLASS_VERSION);
- properties_system_add("java.class.path", classpath);
-
- properties_system_add("java.runtime.version", VERSION);
- properties_system_add("java.runtime.name", "CACAO");
-
- /* Set bootclasspath properties. One for GNU classpath and the
- other for compatibility with Sun (required by most
- applications). */
-
- properties_system_add("java.boot.class.path", bootclasspath);
- properties_system_add("sun.boot.class.path", bootclasspath);
-
-#if defined(WITH_STATIC_CLASSPATH)
- properties_system_add("gnu.classpath.boot.library.path", ".");
- properties_system_add("java.library.path" , ".");
-#else /* defined(WITH_STATIC_CLASSPATH) */
- /* fill gnu.classpath.boot.library.path with GNU Classpath library
- path */
-
- len = strlen(CLASSPATH_LIBRARY_PATH) + strlen("0");
-
- libpath = MNEW(char, len);
-
- strcpy(libpath, CLASSPATH_LIBRARY_PATH);
-
- properties_system_add("gnu.classpath.boot.library.path", libpath);
-
- MFREE(libpath, char, len);
-
-
- /* now fill java.library.path */
-
- ld_library_path = getenv("LD_LIBRARY_PATH");
-
- if (ld_library_path) {
- len = strlen(ld_library_path) + strlen("0");
-
- libpath = MNEW(char, len);
-
- strcpy(libpath, ld_library_path);
-
- properties_system_add("java.library.path", libpath);
-
- MFREE(libpath, char, len);
-
- } else {
- properties_system_add("java.library.path", "");
- }
-#endif /* defined(WITH_STATIC_CLASSPATH) */
-
- properties_system_add("java.io.tmpdir", "/tmp");
-
-#if defined(ENABLE_INTRP)
- if (opt_intrp) {
- /* XXX We don't support java.lang.Compiler */
-/* properties_system_add("java.compiler", "cacao.intrp"); */
- properties_system_add("java.vm.info", "interpreted mode");
- properties_system_add("gnu.java.compiler.name", "cacao.intrp");
- }
- else
-#endif
- {
- /* XXX We don't support java.lang.Compiler */
-/* properties_system_add("java.compiler", "cacao.jit"); */
- properties_system_add("java.vm.info", "JIT mode");
- properties_system_add("gnu.java.compiler.name", "cacao.jit");
- }
-
- /* set the java.ext.dirs property */
-
- len = strlen(env_java_home) + strlen("/jre/lib/ext") + strlen("0");
-
- extdirs = MNEW(char, len);
-
- strcpy(extdirs, env_java_home);
- strcat(extdirs, "/jre/lib/ext");
-
- properties_system_add("java.ext.dirs", extdirs);
-
- MFREE(extdirs, char, len);
-
-
-#if defined(DISABLE_GC)
- /* When we disable the GC, we mmap the whole heap to a specific
- address, so we can compare call traces. For this reason we have
- to add the same properties on different machines, otherwise
- more memory may be allocated (e.g. strlen("i386")
- vs. strlen("alpha"). */
-
- properties_system_add("os.arch", "unknown");
- properties_system_add("os.name", "unknown");
- properties_system_add("os.version", "unknown");
-#else
- /* We need to set the os.arch hardcoded to be compatible with SUN. */
-
-#if defined(__I386__)
- /* map all x86 architectures (i386, i486, i686) to i386 */
-
- properties_system_add("os.arch", "i386");
-#elif defined(__POWERPC__)
- properties_system_add("os.arch", "ppc");
-#elif defined(__X86_64__)
- properties_system_add("os.arch", "amd64");
-#else
- /* default to what uname returns */
-
- properties_system_add("os.arch", utsnamebuf.machine);
-#endif
-
- properties_system_add("os.name", utsnamebuf.sysname);
- properties_system_add("os.version", utsnamebuf.release);
-#endif
-
- properties_system_add("file.separator", "/");
- properties_system_add("path.separator", ":");
- properties_system_add("line.separator", "\n");
- properties_system_add("user.name", env_user ? env_user : "null");
- properties_system_add("user.home", env_home ? env_home : "null");
- properties_system_add("user.dir", cwd ? cwd : "null");
-
-#if defined(WITH_STATIC_CLASSPATH)
- /* This is just for debugging purposes and can cause troubles in
- GNU Classpath. */
-
- properties_system_add("gnu.cpu.endian", "unknown");
-#else
-# if WORDS_BIGENDIAN == 1
- properties_system_add("gnu.cpu.endian", "big");
-# else
- properties_system_add("gnu.cpu.endian", "little");
-# endif
-#endif
-
- /* get locale */
-
- if (env_lang != NULL) {
- /* get the local stuff from the environment */
-
- if (strlen(env_lang) <= 2) {
- properties_system_add("user.language", env_lang);
-
- } else {
- if ((env_lang[2] == '_') && (strlen(env_lang) >= 5)) {
- lang = MNEW(char, 3);
- strncpy(lang, (char *) &env_lang[0], 2);
- lang[2] = '\0';
-
- country = MNEW(char, 3);
- strncpy(country, (char *) &env_lang[3], 2);
- country[2] = '\0';
-
- properties_system_add("user.language", lang);
- properties_system_add("user.country", country);
- }
- }
-
- } else {
- /* if no default locale was specified, use `en_US' */
-
- properties_system_add("user.language", "en");
- properties_system_add("user.country", "US");
- }
-
-
- /* Add remaining properties defined on commandline to the Java
- system properties. */
-
- properties_system_add_all();
-
- /* clean up */
-
- MFREE(cwd, char, 0);
-}
-
-
-/*
- * These are local overrides for various environment variables in Emacs.
- * Please do not remove this and leave it at the end of the file, where
- * Emacs will automagically detect them.
- * ---------------------------------------------------------------------
- * Local variables:
- * mode: c
- * indent-tabs-mode: t
- * c-basic-offset: 4
- * tab-width: 4
- * End:
- */
+++ /dev/null
-/* src/native/vm/VMThread.c - java/lang/VMThread
-
- Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
- C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
- E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
- J. Wenninger, Institut f. Computersprachen - TU Wien
-
- This file is part of CACAO.
-
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License as
- published by the Free Software Foundation; either version 2, or (at
- your option) any later version.
-
- This program is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- 02110-1301, USA.
-
- Contact: cacao@cacaojvm.org
-
- Authors: Roman Obermaiser
-
- Changes: Joseph Wenninger
- Christian Thalinger
-
- $Id: VMThread.c 4926 2006-05-15 21:32:09Z edwin $
-
-*/
-
-
-#include "config.h"
-#include "vm/types.h"
-
-#include "native/jni.h"
-#include "native/native.h"
-#include "native/include/java_lang_ThreadGroup.h"
-#include "native/include/java_lang_Object.h" /* java_lang_Thread.h */
-#include "native/include/java_lang_Throwable.h" /* java_lang_Thread.h */
-#include "native/include/java_lang_VMThread.h"
-#include "native/include/java_lang_Thread.h"
-
-#if defined(ENABLE_THREADS)
-# include "threads/native/threads.h"
-#endif
-
-#include "toolbox/logging.h"
-#include "vm/exceptions.h"
-#include "vm/options.h"
-
-
-/*
- * Class: java/lang/VMThread
- * Method: countStackFrames
- * Signature: ()I
- */
-JNIEXPORT s4 JNICALL Java_java_lang_VMThread_countStackFrames(JNIEnv *env, java_lang_VMThread *this)
-{
- log_text("java_lang_VMThread_countStackFrames called");
-
- return 0;
-}
-
-
-/*
- * Class: java/lang/VMThread
- * Method: start
- * Signature: (J)V
- */
-JNIEXPORT void JNICALL Java_java_lang_VMThread_start(JNIEnv *env, java_lang_VMThread *this, s8 stacksize)
-{
-#if defined(ENABLE_THREADS)
- this->thread->vmThread = this;
-
- /* don't pass a function pointer (NULL) since we want Thread.run()V here */
-
- threads_start_thread((java_lang_Thread *) this->thread, NULL);
-#endif
-}
-
-
-/*
- * Class: java/lang/VMThread
- * Method: interrupt
- * Signature: ()V
- */
-JNIEXPORT void JNICALL Java_java_lang_VMThread_interrupt(JNIEnv *env, java_lang_VMThread *this)
-{
-#if defined(ENABLE_THREADS)
- threads_interrupt_thread(this);
-#endif
-}
-
-
-/*
- * Class: java/lang/VMThread
- * Method: isInterrupted
- * Signature: ()Z
- */
-JNIEXPORT s4 JNICALL Java_java_lang_VMThread_isInterrupted(JNIEnv *env, java_lang_VMThread *this)
-{
-#if defined(ENABLE_THREADS)
- return threads_thread_has_been_interrupted(this);
-#endif
-}
-
-
-/*
- * Class: java/lang/VMThread
- * Method: suspend
- * Signature: ()V
- */
-JNIEXPORT void JNICALL Java_java_lang_VMThread_suspend(JNIEnv *env, java_lang_VMThread *this)
-{
-#if defined(ENABLE_THREADS)
-#endif
-}
-
-
-/*
- * Class: java/lang/VMThread
- * Method: resume
- * Signature: ()V
- */
-JNIEXPORT void JNICALL Java_java_lang_VMThread_resume(JNIEnv *env, java_lang_VMThread *this)
-{
-#if defined(ENABLE_THREADS)
-#endif
-}
-
-
-/*
- * Class: java/lang/VMThread
- * Method: nativeSetPriority
- * Signature: (I)V
- */
-JNIEXPORT void JNICALL Java_java_lang_VMThread_nativeSetPriority(JNIEnv *env, java_lang_VMThread *this, s4 priority)
-{
-#if defined(ENABLE_THREADS)
- threads_java_lang_Thread_set_priority((java_lang_Thread *) this->thread,
- priority);
-#endif
-}
-
-
-/*
- * Class: java/lang/VMThread
- * Method: nativeStop
- * Signature: (Ljava/lang/Object;)V
- */
-JNIEXPORT void JNICALL Java_java_lang_VMThread_nativeStop(JNIEnv *env, java_lang_VMThread *this, java_lang_Throwable *t)
-{
-#if defined(ENABLE_THREADS)
-#endif
-}
-
-
-/*
- * Class: java/lang/VMThread
- * Method: currentThread
- * Signature: ()Ljava/lang/Thread;
- */
-JNIEXPORT java_lang_Thread* JNICALL Java_java_lang_VMThread_currentThread(JNIEnv *env, jclass clazz)
-{
- java_lang_Thread *t;
-
-#if defined(ENABLE_THREADS)
- t = ((threadobject*) THREADOBJECT)->o.thread;
-
- if (t == NULL)
- log_text("t ptr is NULL\n");
-
- if (!t->group) {
- /* ThreadGroup of currentThread is not initialized */
-
- t->group = (java_lang_ThreadGroup *)
- native_new_and_init(class_java_lang_ThreadGroup);
-
- if (t->group == NULL)
- log_text("unable to create ThreadGroup");
- }
-#else
- /* we just return a fake java.lang.Thread object, otherwise we get
- NullPointerException's in GNU classpath */
-
- t = (java_lang_Thread *) builtin_new(class_java_lang_Thread);
-#endif
-
- return t;
-}
-
-
-/*
- * Class: java/lang/VMThread
- * Method: yield
- * Signature: ()V
- */
-JNIEXPORT void JNICALL Java_java_lang_VMThread_yield(JNIEnv *env, jclass clazz)
-{
-#if defined(ENABLE_THREADS)
- threads_yield();
-#endif
-}
-
-
-/*
- * Class: java/lang/VMThread
- * Method: interrupted
- * Signature: ()Z
- */
-JNIEXPORT s4 JNICALL Java_java_lang_VMThread_interrupted(JNIEnv *env, jclass clazz)
-{
-#if defined(ENABLE_THREADS)
- return threads_check_if_interrupted_and_reset();
-#endif
-}
-
-
-/*
- * Class: java/lang/VMThread
- * Method: holdsLock
- * Signature: (Ljava/lang/Object;)Z
- */
-JNIEXPORT s4 JNICALL Java_java_lang_VMThread_holdsLock(JNIEnv *env, jclass clazz, java_lang_Object* o)
-{
-#if defined(ENABLE_THREADS)
- return lock_is_held_by_current_thread((java_objectheader *) o);
-#endif
-}
-
-
-/*
- * These are local overrides for various environment variables in Emacs.
- * Please do not remove this and leave it at the end of the file, where
- * Emacs will automagically detect them.
- * ---------------------------------------------------------------------
- * Local variables:
- * mode: c
- * indent-tabs-mode: t
- * c-basic-offset: 4
- * tab-width: 4
- * End:
- */
+++ /dev/null
-/* src/native/vm/VMThrowable.c - java/lang/VMThrowable
-
- Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
- C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
- E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
- J. Wenninger, Institut f. Computersprachen - TU Wien
-
- This file is part of CACAO.
-
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License as
- published by the Free Software Foundation; either version 2, or (at
- your option) any later version.
-
- This program is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- 02110-1301, USA.
-
- Contact: cacao@cacaojvm.org
-
- Authors: Joseph Wenninger
-
- Changes: Christian Thalinger
-
- $Id: VMThrowable.c 4550 2006-03-01 17:00:33Z twisti $
-
-*/
-
-
-#include "config.h"
-
-#include <assert.h>
-
-#include "vm/types.h"
-
-#include "native/jni.h"
-#include "native/native.h"
-#include "native/include/gnu_classpath_Pointer.h"
-#include "native/include/java_lang_Class.h"
-#include "native/include/java_lang_StackTraceElement.h"
-#include "native/include/java_lang_Throwable.h"
-#include "native/include/java_lang_VMClass.h"
-#include "native/include/java_lang_VMThrowable.h"
-#include "vm/builtin.h"
-#include "vm/class.h"
-#include "vm/exceptions.h"
-#include "vm/loader.h"
-#include "vm/stringlocal.h"
-#include "vm/jit/stacktrace.h"
-
-
-/*
- * Class: java/lang/VMThrowable
- * Method: fillInStackTrace
- * Signature: (Ljava/lang/Throwable;)Ljava/lang/VMThrowable;
- */
-JNIEXPORT java_lang_VMThrowable* JNICALL Java_java_lang_VMThrowable_fillInStackTrace(JNIEnv *env, jclass clazz, java_lang_Throwable *t)
-{
- java_lang_VMThrowable *o;
- stacktracebuffer *stb;
-
- o = (java_lang_VMThrowable *)
- native_new_and_init(class_java_lang_VMThrowable);
-
- if (o == NULL)
- return NULL;
-
-#if defined(__ALPHA__) || defined(__ARM__) || defined(__I386__) || defined(__MIPS__) || defined(__POWERPC__) || defined(__X86_64__)
- stb = stacktrace_fillInStackTrace();
-
- if (stb == NULL)
- return NULL;
-
- o->vmData = (gnu_classpath_Pointer *) stb;
-#endif
-
- return o;
-}
-
-
-/*
- * Class: java/lang/VMThrowable
- * Method: getStackTrace
- * Signature: (Ljava/lang/Throwable;)[Ljava/lang/StackTraceElement;
- */
-JNIEXPORT java_objectarray* JNICALL Java_java_lang_VMThrowable_getStackTrace(JNIEnv *env, java_lang_VMThrowable *this, java_lang_Throwable *t)
-{
-#if defined(__ALPHA__) || defined(__ARM__) || defined(__I386__) || defined(__MIPS__) || defined(__POWERPC__) || defined(__X86_64__)
- stacktracebuffer *stb;
- stacktrace_entry *ste;
- stacktrace_entry *tmpste;
- s4 size;
- s4 i;
- classinfo *c;
- bool inexceptionclass;
- bool leftexceptionclass;
-
- methodinfo *m;
- java_objectarray *oa;
- s4 oalength;
- java_lang_StackTraceElement *o;
- java_lang_String *filename;
- s4 linenumber;
- java_lang_String *declaringclass;
-
- /* get the stacktrace buffer from the VMThrowable object */
-
- stb = (stacktracebuffer *) this->vmData;
-
- /* get the class of the Throwable object */
-
- c = t->header.vftbl->class;
-
- assert(stb != NULL);
-
- size = stb->used;
-
- assert(size >= 2);
-
- /* skip first 2 elements in stacktrace buffer: */
- /* 0: VMThrowable.fillInStackTrace */
- /* 1: Throwable.fillInStackTrace */
-
- ste = &(stb->entries[2]);
- size -= 2;
-
- if ((size > 0) && (ste->method != 0)) {
- /* not a builtin native wrapper*/
-
- if ((ste->method->class->name == utf_java_lang_Throwable) &&
- (ste->method->name == utf_init)) {
- /* We assume that we are within the initializer of the
- exception object, the exception object itself should
- not appear in the stack trace, so we skip till we reach
- the first function, which is not an init function. */
-
- inexceptionclass = false;
- leftexceptionclass = false;
-
- while (size > 0) {
- /* check if we are in the exception class */
-
- if (ste->method->class == c)
- inexceptionclass = true;
-
- /* check if we left the exception class */
-
- if (inexceptionclass && (ste->method->class != c))
- leftexceptionclass = true;
-
- /* Found exception start point if we left the
- initalizers or we left the exception class. */
-
- if ((ste->method->name != utf_init) || leftexceptionclass)
- break;
-
- /* go to next stacktrace element */
-
- ste++;
- size--;
- }
- }
- }
-
-
- /* now fill the stacktrace into java objects */
-
- m = class_findmethod(class_java_lang_StackTraceElement,
- utf_init,
- utf_new_char("(Ljava/lang/String;ILjava/lang/String;Ljava/lang/String;Z)V"));
-
- if (!m)
- return NULL;
-
- /* count entries with a method name */
-
- for (oalength = 0, i = size, tmpste = ste; i > 0; i--, tmpste++)
- if (tmpste->method)
- oalength++;
-
- /* create the stacktrace element array */
-
- oa = builtin_anewarray(oalength, class_java_lang_StackTraceElement);
-
- if (!oa)
- return NULL;
-
- for (i = 0; size > 0; size--, ste++, i++) {
- /* skip entries without a method name */
-
- if (ste->method == NULL) {
- i--;
- continue;
- }
-
- /* allocate a new stacktrace element */
-
- o = (java_lang_StackTraceElement *)
- builtin_new(class_java_lang_StackTraceElement);
-
- if (!o)
- return NULL;
-
- /* get filename */
-
- if (!(ste->method->flags & ACC_NATIVE)) {
- if (ste->method->class->sourcefile)
- filename = javastring_new(ste->method->class->sourcefile);
- else
- filename = NULL;
-
- } else {
- filename = NULL;
- }
-
- /* get line number */
-
- if (ste->method->flags & ACC_NATIVE)
- linenumber = -1;
- else
- linenumber = (ste->linenumber == 0) ? -1 : ste->linenumber;
-
- /* get declaring class name */
-
- declaringclass = Java_java_lang_VMClass_getName(env, NULL, (java_lang_Class *) ste->method->class);
-
-
- /* fill the java.lang.StackTraceElement element */
-
- o->fileName = filename;
- o->lineNumber = linenumber;
- o->declaringClass = declaringclass;
- o->methodName = javastring_new(ste->method->name);
- o->isNative = (ste->method->flags & ACC_NATIVE) ? 1 : 0;
-
- oa->data[i] = (java_objectheader *) o;
- }
-
- return oa;
-#else
- return NULL;
-#endif
-}
-
-
-/*
- * These are local overrides for various environment variables in Emacs.
- * Please do not remove this and leave it at the end of the file, where
- * Emacs will automagically detect them.
- * ---------------------------------------------------------------------
- * Local variables:
- * mode: c
- * indent-tabs-mode: t
- * c-basic-offset: 4
- * tab-width: 4
- * End:
- */
--- /dev/null
+/* src/native/vm/VMStackWalker.c - gnu/classpath/VMStackWalker
+
+ Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
+ C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
+ E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
+ J. Wenninger, Institut f. Computersprachen - TU Wien
+
+ This file is part of CACAO.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA.
+
+ Contact: cacao@cacaojvm.org
+
+ Authors: Christian Thalinger
+
+ Changes: Edwin Steiner
+
+ $Id: gnu_classpath_VMStackWalker.c 5153 2006-07-18 08:19:24Z twisti $
+
+*/
+
+
+#include "config.h"
+
+#include "native/jni.h"
+#include "native/native.h"
+#include "native/include/java_lang_Class.h"
+#include "native/include/java_lang_ClassLoader.h"
+#include "vm/builtin.h"
+#include "vm/class.h"
+#include "vm/global.h"
+#include "vm/options.h"
+
+
+/*
+ * Class: gnu/classpath/VMStackWalker
+ * Method: getClassContext
+ * Signature: ()[Ljava/lang/Class;
+ */
+JNIEXPORT java_objectarray* JNICALL Java_gnu_classpath_VMStackWalker_getClassContext(JNIEnv *env, jclass clazz)
+{
+/* if (cacao_initializing) */
+/* return NULL; */
+
+#if defined(__ALPHA__) || defined(__ARM__) || defined(__I386__) || defined(__MIPS__) || defined(__POWERPC__) || defined(__X86_64__)
+ /* these JITs support stacktraces, and so does the interpreter */
+
+ return stacktrace_getClassContext();
+
+#else
+# if defined(ENABLE_INTRP)
+ /* the interpreter supports stacktraces, even if the JIT does not */
+
+ if (opt_intrp) {
+ return stacktrace_getClassContext();
+
+ }
+ else
+# endif
+ {
+ return builtin_anewarray(0, class_java_lang_Class);
+ }
+#endif
+}
+
+
+/*
+ * Class: gnu/classpath/VMStackWalker
+ * Method: getCallingClass
+ * Signature: ()Ljava/lang/Class;
+ */
+JNIEXPORT java_lang_Class* JNICALL Java_gnu_classpath_VMStackWalker_getCallingClass(JNIEnv *env, jclass clazz)
+{
+#if defined(__ALPHA__) || defined(__ARM__) || defined(__I386__) || defined(__MIPS__) || defined(__POWERPC__) || defined(__X86_64__)
+ /* these JITs support stacktraces, and so does the interpreter */
+
+ java_objectarray *oa;
+
+ oa = stacktrace_getClassContext();
+ if (!oa)
+ return NULL;
+
+ if (oa->header.size < 2)
+ return NULL;
+
+ return (java_lang_Class *) oa->data[1];
+
+#else
+# if defined(ENABLE_INTRP)
+ /* the interpreter supports stacktraces, even if the JIT does not */
+
+ if (opt_intrp) {
+ java_objectarray *oa;
+
+ oa = stacktrace_getClassContext();
+ if (!oa)
+ return NULL;
+
+ if (oa->header.size < 2)
+ return NULL;
+
+ return (java_lang_Class *) oa->data[1];
+
+ }
+ else
+# endif
+ {
+ return NULL;
+ }
+#endif
+}
+
+
+/*
+ * Class: gnu/classpath/VMStackWalker
+ * Method: getCallingClassLoader
+ * Signature: ()Ljava/lang/ClassLoader;
+ */
+JNIEXPORT java_lang_ClassLoader* JNICALL Java_gnu_classpath_VMStackWalker_getCallingClassLoader(JNIEnv *env, jclass clazz)
+{
+ java_objectarray *oa;
+ classinfo *c;
+ java_objectheader *cl;
+
+#if defined(__ALPHA__) || defined(__ARM__) || defined(__I386__) || defined(__MIPS__) || defined(__POWERPC__) || defined(__X86_64__)
+ /* these JITs support stacktraces, and so does the interpreter */
+
+ oa = stacktrace_getClassContext();
+ if (!oa)
+ return NULL;
+
+ if (oa->header.size < 2)
+ return NULL;
+
+ c = (classinfo *) oa->data[1];
+
+ cl = c->classloader;
+#else
+# if defined(ENABLE_INTRP)
+ /* the interpreter supports stacktraces, even if the JIT does not */
+
+ if (opt_intrp) {
+ oa = stacktrace_getClassContext();
+ if (!oa)
+ return NULL;
+
+ if (oa->header.size < 2)
+ return NULL;
+
+ c = (classinfo *) oa->data[1];
+
+ cl = c->classloader;
+
+ }
+ else
+# endif
+ {
+ cl = NULL;
+ }
+#endif
+
+ return (java_lang_ClassLoader *) cl;
+}
+
+
+/*
+ * These are local overrides for various environment variables in Emacs.
+ * Please do not remove this and leave it at the end of the file, where
+ * Emacs will automagically detect them.
+ * ---------------------------------------------------------------------
+ * Local variables:
+ * mode: c
+ * indent-tabs-mode: t
+ * c-basic-offset: 4
+ * tab-width: 4
+ * End:
+ * vim:noexpandtab:sw=4:ts=4:
+ */
--- /dev/null
+/* src/native/vm/VMSystemProperties.c - gnu/classpath/VMSystemProperties
+
+ Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
+ C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
+ E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
+ J. Wenninger, Institut f. Computersprachen - TU Wien
+
+ This file is part of CACAO.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA.
+
+ Contact: cacao@cacaojvm.org
+
+ Authors: Christian Thalinger
+
+ Changes:
+
+ $Id: gnu_classpath_VMSystemProperties.c 5153 2006-07-18 08:19:24Z twisti $
+
+*/
+
+
+#include "config.h"
+
+#include <stdlib.h>
+#include <string.h>
+#include <sys/utsname.h>
+#include <time.h>
+
+#include "vm/types.h"
+
+#include "mm/memory.h"
+#include "native/jni.h"
+#include "native/native.h"
+#include "native/include/java_util_Properties.h"
+#include "toolbox/logging.h"
+#include "toolbox/util.h"
+#include "vm/exceptions.h"
+#include "vm/builtin.h"
+#include "vm/loader.h"
+#include "vm/options.h"
+#include "vm/properties.h"
+#include "vm/suck.h"
+
+
+/*
+ * Class: gnu/classpath/VMSystemProperties
+ * Method: preInit
+ * Signature: (Ljava/util/Properties;)V
+ */
+JNIEXPORT void JNICALL Java_gnu_classpath_VMSystemProperties_preInit(JNIEnv *env, jclass clazz, java_util_Properties *p)
+{
+ char *cwd;
+ char *env_java_home;
+ char *env_user;
+ char *env_home;
+ char *env_lang;
+ char *java_home;
+ char *extdirs;
+ char *lang;
+ char *country;
+ struct utsname utsnamebuf;
+ s4 len;
+
+#if !defined(WITH_STATIC_CLASSPATH)
+ char *ld_library_path;
+ char *libpath;
+#endif
+
+ if (p == NULL) {
+ exceptions_throw_nullpointerexception();
+ return;
+ }
+
+ /* get properties from system */
+
+ cwd = _Jv_getcwd();
+ env_java_home = getenv("JAVA_HOME");
+ env_user = getenv("USER");
+ env_home = getenv("HOME");
+ env_lang = getenv("LANG");
+
+ uname(&utsnamebuf);
+
+ /* post-initialize the properties */
+
+ if (!properties_postinit(p))
+ return;
+
+ /* set JAVA_HOME to default prefix if not defined */
+
+ if (env_java_home == NULL)
+ env_java_home = CACAO_PREFIX;
+
+ /* fill in system properties */
+
+ properties_system_add("java.version", JAVA_VERSION);
+ properties_system_add("java.vendor", "GNU Classpath");
+ properties_system_add("java.vendor.url", "http://www.gnu.org/software/classpath/");
+
+ /* add /jre to java.home property */
+
+ len = strlen(env_java_home) + strlen("/jre") + strlen("0");
+
+ java_home = MNEW(char, len);
+
+ strcpy(java_home, env_java_home);
+ strcat(java_home, "/jre");
+
+ properties_system_add("java.home", java_home);
+
+ MFREE(java_home, char, len);
+
+ properties_system_add("java.vm.specification.version", "1.0");
+ properties_system_add("java.vm.specification.vendor", "Sun Microsystems Inc.");
+ properties_system_add("java.vm.specification.name", "Java Virtual Machine Specification");
+ properties_system_add("java.vm.version", VERSION);
+ properties_system_add("java.vm.vendor", "CACAO Team");
+ properties_system_add("java.vm.name", "CACAO");
+ properties_system_add("java.specification.version", "1.4");
+ properties_system_add("java.specification.vendor", "Sun Microsystems Inc.");
+ properties_system_add("java.specification.name", "Java Platform API Specification");
+ properties_system_add("java.class.version", CLASS_VERSION);
+ properties_system_add("java.class.path", classpath);
+
+ properties_system_add("java.runtime.version", VERSION);
+ properties_system_add("java.runtime.name", "CACAO");
+
+ /* Set bootclasspath properties. One for GNU classpath and the
+ other for compatibility with Sun (required by most
+ applications). */
+
+ properties_system_add("java.boot.class.path", bootclasspath);
+ properties_system_add("sun.boot.class.path", bootclasspath);
+
+#if defined(WITH_STATIC_CLASSPATH)
+ properties_system_add("gnu.classpath.boot.library.path", ".");
+ properties_system_add("java.library.path" , ".");
+#else /* defined(WITH_STATIC_CLASSPATH) */
+ /* fill gnu.classpath.boot.library.path with GNU Classpath library
+ path */
+
+ len = strlen(CLASSPATH_LIBRARY_PATH) + strlen("0");
+
+ libpath = MNEW(char, len);
+
+ strcpy(libpath, CLASSPATH_LIBRARY_PATH);
+
+ properties_system_add("gnu.classpath.boot.library.path", libpath);
+
+ MFREE(libpath, char, len);
+
+
+ /* now fill java.library.path */
+
+ ld_library_path = getenv("LD_LIBRARY_PATH");
+
+ if (ld_library_path) {
+ len = strlen(ld_library_path) + strlen("0");
+
+ libpath = MNEW(char, len);
+
+ strcpy(libpath, ld_library_path);
+
+ properties_system_add("java.library.path", libpath);
+
+ MFREE(libpath, char, len);
+
+ } else {
+ properties_system_add("java.library.path", "");
+ }
+#endif /* defined(WITH_STATIC_CLASSPATH) */
+
+ properties_system_add("java.io.tmpdir", "/tmp");
+
+#if defined(ENABLE_INTRP)
+ if (opt_intrp) {
+ /* XXX We don't support java.lang.Compiler */
+/* properties_system_add("java.compiler", "cacao.intrp"); */
+ properties_system_add("java.vm.info", "interpreted mode");
+ properties_system_add("gnu.java.compiler.name", "cacao.intrp");
+ }
+ else
+#endif
+ {
+ /* XXX We don't support java.lang.Compiler */
+/* properties_system_add("java.compiler", "cacao.jit"); */
+ properties_system_add("java.vm.info", "JIT mode");
+ properties_system_add("gnu.java.compiler.name", "cacao.jit");
+ }
+
+ /* set the java.ext.dirs property */
+
+ len = strlen(env_java_home) + strlen("/jre/lib/ext") + strlen("0");
+
+ extdirs = MNEW(char, len);
+
+ strcpy(extdirs, env_java_home);
+ strcat(extdirs, "/jre/lib/ext");
+
+ properties_system_add("java.ext.dirs", extdirs);
+
+ MFREE(extdirs, char, len);
+
+
+#if defined(DISABLE_GC)
+ /* When we disable the GC, we mmap the whole heap to a specific
+ address, so we can compare call traces. For this reason we have
+ to add the same properties on different machines, otherwise
+ more memory may be allocated (e.g. strlen("i386")
+ vs. strlen("alpha"). */
+
+ properties_system_add("os.arch", "unknown");
+ properties_system_add("os.name", "unknown");
+ properties_system_add("os.version", "unknown");
+#else
+ /* We need to set the os.arch hardcoded to be compatible with SUN. */
+
+#if defined(__I386__)
+ /* map all x86 architectures (i386, i486, i686) to i386 */
+
+ properties_system_add("os.arch", "i386");
+#elif defined(__POWERPC__)
+ properties_system_add("os.arch", "ppc");
+#elif defined(__X86_64__)
+ properties_system_add("os.arch", "amd64");
+#else
+ /* default to what uname returns */
+
+ properties_system_add("os.arch", utsnamebuf.machine);
+#endif
+
+ properties_system_add("os.name", utsnamebuf.sysname);
+ properties_system_add("os.version", utsnamebuf.release);
+#endif
+
+ properties_system_add("file.separator", "/");
+ properties_system_add("path.separator", ":");
+ properties_system_add("line.separator", "\n");
+ properties_system_add("user.name", env_user ? env_user : "null");
+ properties_system_add("user.home", env_home ? env_home : "null");
+ properties_system_add("user.dir", cwd ? cwd : "null");
+
+#if defined(WITH_STATIC_CLASSPATH)
+ /* This is just for debugging purposes and can cause troubles in
+ GNU Classpath. */
+
+ properties_system_add("gnu.cpu.endian", "unknown");
+#else
+# if WORDS_BIGENDIAN == 1
+ properties_system_add("gnu.cpu.endian", "big");
+# else
+ properties_system_add("gnu.cpu.endian", "little");
+# endif
+#endif
+
+ /* get locale */
+
+ if (env_lang != NULL) {
+ /* get the local stuff from the environment */
+
+ if (strlen(env_lang) <= 2) {
+ properties_system_add("user.language", env_lang);
+
+ } else {
+ if ((env_lang[2] == '_') && (strlen(env_lang) >= 5)) {
+ lang = MNEW(char, 3);
+ strncpy(lang, (char *) &env_lang[0], 2);
+ lang[2] = '\0';
+
+ country = MNEW(char, 3);
+ strncpy(country, (char *) &env_lang[3], 2);
+ country[2] = '\0';
+
+ properties_system_add("user.language", lang);
+ properties_system_add("user.country", country);
+ }
+ }
+
+ } else {
+ /* if no default locale was specified, use `en_US' */
+
+ properties_system_add("user.language", "en");
+ properties_system_add("user.country", "US");
+ }
+
+
+ /* Add remaining properties defined on commandline to the Java
+ system properties. */
+
+ properties_system_add_all();
+
+ /* clean up */
+
+ MFREE(cwd, char, 0);
+}
+
+
+/*
+ * These are local overrides for various environment variables in Emacs.
+ * Please do not remove this and leave it at the end of the file, where
+ * Emacs will automagically detect them.
+ * ---------------------------------------------------------------------
+ * Local variables:
+ * mode: c
+ * indent-tabs-mode: t
+ * c-basic-offset: 4
+ * tab-width: 4
+ * End:
+ */
--- /dev/null
+/* src/native/vm/VMClass.c - java/lang/VMClass
+
+ Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
+ C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
+ E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
+ J. Wenninger, Institut f. Computersprachen - TU Wien
+
+ This file is part of CACAO.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA.
+
+ Contact: cacao@cacaojvm.org
+
+ Authors: Roman Obermaiser
+
+ Changes: Joseph Wenninger
+ Christian Thalinger
+ Edwin Steiner
+
+ $Id: java_lang_VMClass.c 5153 2006-07-18 08:19:24Z twisti $
+
+*/
+
+
+#include "config.h"
+
+#include <assert.h>
+#include <string.h>
+
+#include "vm/types.h"
+
+#include "mm/memory.h"
+#include "native/jni.h"
+#include "native/native.h"
+#include "native/include/java_lang_Class.h"
+#include "native/include/java_lang_ClassLoader.h"
+#include "native/include/java_lang_Object.h"
+#include "native/include/java_lang_VMClass.h"
+#include "native/include/java_lang_reflect_Constructor.h"
+#include "native/include/java_lang_reflect_Field.h"
+#include "native/include/java_lang_reflect_Method.h"
+#include "native/include/java_security_ProtectionDomain.h"
+#include "toolbox/logging.h"
+#include "vm/builtin.h"
+#include "vm/exceptions.h"
+#include "vm/global.h"
+#include "vm/initialize.h"
+#include "vm/loader.h"
+#include "vm/resolve.h"
+#include "vm/stringlocal.h"
+
+
+/*
+ * Class: java/lang/Class
+ * Method: isInstance
+ * Signature: (Ljava/lang/Object;)Z
+ */
+JNIEXPORT s4 JNICALL Java_java_lang_VMClass_isInstance(JNIEnv *env, jclass clazz, java_lang_Class *klass, java_lang_Object *o)
+{
+ classinfo *c;
+ java_objectheader *ob;
+
+ c = (classinfo *) klass;
+ ob = (java_objectheader *) o;
+
+ if (!(c->state & CLASS_LINKED))
+ if (!link_class(c))
+ return 0;
+
+ return builtin_instanceof(ob, c);
+}
+
+
+/*
+ * Class: java/lang/Class
+ * Method: isAssignableFrom
+ * Signature: (Ljava/lang/Class;)Z
+ */
+JNIEXPORT s4 JNICALL Java_java_lang_VMClass_isAssignableFrom(JNIEnv *env, jclass clazz, java_lang_Class *klass, java_lang_Class *c)
+{
+ classinfo *kc;
+ classinfo *cc;
+
+ kc = (classinfo *) klass;
+ cc = (classinfo *) c;
+
+ if (cc == NULL) {
+ exceptions_throw_nullpointerexception();
+ return 0;
+ }
+
+ if (!(kc->state & CLASS_LINKED))
+ if (!link_class(kc))
+ return 0;
+
+ if (!(cc->state & CLASS_LINKED))
+ if (!link_class(cc))
+ return 0;
+
+ /* XXX this may be wrong for array classes */
+
+ return builtin_isanysubclass(cc, kc);
+}
+
+
+/*
+ * Class: java/lang/Class
+ * Method: isInterface
+ * Signature: ()Z
+ */
+JNIEXPORT s4 JNICALL Java_java_lang_VMClass_isInterface(JNIEnv *env, jclass clazz, java_lang_Class *klass)
+{
+ classinfo *c;
+
+ c = (classinfo *) klass;
+
+ if (c->flags & ACC_INTERFACE)
+ return true;
+
+ return false;
+}
+
+
+/*
+ * Class: java/lang/Class
+ * Method: isPrimitive
+ * Signature: ()Z
+ */
+JNIEXPORT s4 JNICALL Java_java_lang_VMClass_isPrimitive(JNIEnv *env, jclass clazz, java_lang_Class *klass)
+{
+ classinfo *c;
+ s4 i;
+
+ c = (classinfo *) klass;
+
+ /* search table of primitive classes */
+
+ for (i = 0; i < PRIMITIVETYPE_COUNT; i++)
+ if (primitivetype_table[i].class_primitive == c)
+ return true;
+
+ return false;
+}
+
+
+/*
+ * Class: java/lang/VMClass
+ * Method: getName
+ * Signature: ()Ljava/lang/String;
+ */
+JNIEXPORT java_lang_String* JNICALL Java_java_lang_VMClass_getName(JNIEnv *env, jclass clazz, java_lang_Class *klass)
+{
+ classinfo *c;
+ java_lang_String *s;
+ u4 i;
+
+ c = (classinfo *) klass;
+ s = (java_lang_String *) javastring_new(c->name);
+
+ if (!s)
+ return NULL;
+
+ /* return string where '/' is replaced by '.' */
+
+ for (i = 0; i < s->value->header.size; i++) {
+ if (s->value->data[i] == '/')
+ s->value->data[i] = '.';
+ }
+
+ return s;
+}
+
+
+/*
+ * Class: java/lang/Class
+ * Method: getSuperclass
+ * Signature: ()Ljava/lang/Class;
+ */
+JNIEXPORT java_lang_Class* JNICALL Java_java_lang_VMClass_getSuperclass(JNIEnv *env, jclass clazz, java_lang_Class *klass)
+{
+ classinfo *c;
+ classinfo *sc;
+
+ c = (classinfo *) klass;
+
+ /* for java.lang.Object, primitive and Void classes we return NULL */
+ if (!c->super.any)
+ return NULL;
+
+ /* for interfaces we also return NULL */
+ if (c->flags & ACC_INTERFACE)
+ return NULL;
+
+ /* we may have to resolve the super class reference */
+ if (!resolve_classref_or_classinfo(NULL, c->super, resolveEager,
+ true, /* check access */
+ false, /* don't link */
+ &sc))
+ {
+ return NULL;
+ }
+
+ /* store the resolution */
+ c->super.cls = sc;
+
+ return (java_lang_Class *) sc;
+}
+
+
+/*
+ * Class: java/lang/VMClass
+ * Method: getInterfaces
+ * Signature: ()[Ljava/lang/Class;
+ */
+JNIEXPORT java_objectarray* JNICALL Java_java_lang_VMClass_getInterfaces(JNIEnv *env, jclass clazz, java_lang_Class *klass)
+{
+ classinfo *c;
+ classinfo *ic;
+ java_objectarray *oa;
+ u4 i;
+
+ c = (classinfo *) klass;
+
+ if (!(c->state & CLASS_LINKED))
+ if (!link_class(c))
+ return NULL;
+
+ oa = builtin_anewarray(c->interfacescount, class_java_lang_Class);
+
+ if (!oa)
+ return NULL;
+
+ for (i = 0; i < c->interfacescount; i++) {
+ ic = c->interfaces[i].cls;
+
+ oa->data[i] = (java_objectheader *) ic;
+ }
+
+ return oa;
+}
+
+
+/*
+ * Class: java/lang/VMClass
+ * Method: getComponentType
+ * Signature: ()Ljava/lang/Class;
+ */
+JNIEXPORT java_lang_Class* JNICALL Java_java_lang_VMClass_getComponentType(JNIEnv *env, jclass clazz, java_lang_Class *klass)
+{
+ classinfo *c;
+ classinfo *comp;
+ arraydescriptor *desc;
+
+ c = (classinfo *) klass;
+
+ /* XXX maybe we could find a way to do this without linking. */
+ /* This way should be safe and easy, however. */
+
+ if (!(c->state & CLASS_LINKED))
+ if (!link_class(c))
+ return NULL;
+
+ desc = c->vftbl->arraydesc;
+
+ if (desc == NULL)
+ return NULL;
+
+ if (desc->arraytype == ARRAYTYPE_OBJECT)
+ comp = desc->componentvftbl->class;
+ else
+ comp = primitivetype_table[desc->arraytype].class_primitive;
+
+ return (java_lang_Class *) comp;
+}
+
+
+/*
+ * Class: java/lang/VMClass
+ * Method: getModifiers
+ * Signature: (Z)I
+ */
+JNIEXPORT s4 JNICALL Java_java_lang_VMClass_getModifiers(JNIEnv *env, jclass clazz, java_lang_Class *klass, s4 ignoreInnerClassesAttrib)
+{
+ classinfo *c;
+ classref_or_classinfo inner;
+ classref_or_classinfo outer;
+ utf *innername;
+ s4 i;
+
+ c = (classinfo *) klass;
+
+ if (!ignoreInnerClassesAttrib && (c->innerclasscount != 0)) {
+ /* search for passed class as inner class */
+
+ for (i = 0; i < c->innerclasscount; i++) {
+ inner = c->innerclass[i].inner_class;
+ outer = c->innerclass[i].outer_class;
+
+ /* Check if inner is a classref or a real class and get
+ the name of the structure */
+
+ innername = IS_CLASSREF(inner) ? inner.ref->name : inner.cls->name;
+
+ /* innerclass is this class */
+
+ if (innername == c->name) {
+ /* has the class actually an outer class? */
+
+ if (outer.any)
+ /* return flags got from the outer class file */
+ return c->innerclass[i].flags & ACC_CLASS_REFLECT_MASK;
+ else
+ return c->flags & ACC_CLASS_REFLECT_MASK;
+ }
+ }
+ }
+
+ /* passed class is no inner class or it was not requested */
+
+ return c->flags & ACC_CLASS_REFLECT_MASK;
+}
+
+
+/*
+ * Class: java/lang/VMClass
+ * Method: getDeclaringClass
+ * Signature: ()Ljava/lang/Class;
+ */
+JNIEXPORT java_lang_Class* JNICALL Java_java_lang_VMClass_getDeclaringClass(JNIEnv *env, jclass clazz, java_lang_Class *klass)
+{
+ classinfo *c;
+ classref_or_classinfo inner;
+ utf *innername;
+ classinfo *outer;
+ s4 i;
+
+ c = (classinfo *) klass;
+
+ if (!Java_java_lang_VMClass_isPrimitive(env, clazz, klass) &&
+ (c->name->text[0] != '[')) {
+
+ if (c->innerclasscount == 0) /* no innerclasses exist */
+ return NULL;
+
+ for (i = 0; i < c->innerclasscount; i++) {
+ inner = c->innerclass[i].inner_class;
+
+ /* check if inner_class is a classref or a real class and
+ get the class name from the structure */
+
+ innername = IS_CLASSREF(inner) ? inner.ref->name : inner.cls->name;
+
+ /* innerclass is this class */
+
+ if (innername == c->name) {
+ /* maybe the outer class is not loaded yet */
+
+ if (!resolve_classref_or_classinfo(NULL,
+ c->innerclass[i].outer_class,
+ resolveEager, false, false,
+ &outer))
+ return NULL;
+
+ if (!(outer->state & CLASS_LINKED))
+ if (!link_class(outer))
+ return NULL;
+
+ return (java_lang_Class *) outer;
+ }
+ }
+ }
+
+ /* return NULL for arrayclasses and primitive classes */
+
+ return NULL;
+}
+
+
+/*
+ * Class: java/lang/VMClass
+ * Method: getDeclaredClasses
+ * Signature: (Z)[Ljava/lang/Class;
+ */
+JNIEXPORT java_objectarray* JNICALL Java_java_lang_VMClass_getDeclaredClasses(JNIEnv *env, jclass clazz, java_lang_Class *klass, s4 publicOnly)
+{
+ classinfo *c;
+ classref_or_classinfo outer;
+ utf *outername;
+ s4 declaredclasscount; /* number of declared classes */
+ s4 pos; /* current declared class */
+ java_objectarray *oa; /* array of declared classes */
+ s4 i;
+
+ c = (classinfo *) klass;
+ declaredclasscount = 0;
+
+ if (!Java_java_lang_VMClass_isPrimitive(env, clazz, klass) &&
+ (c->name->text[0] != '[')) {
+ /* determine number of declared classes */
+
+ for (i = 0; i < c->innerclasscount; i++) {
+ outer = c->innerclass[i].outer_class;
+
+ /* check if outer_class is a classref or a real class and
+ get the class name from the structure */
+
+ outername = IS_CLASSREF(outer) ? outer.ref->name : outer.cls->name;
+
+ /* outer class is this class */
+
+ if ((outername == c->name) &&
+ ((publicOnly == 0) || (c->innerclass[i].flags & ACC_PUBLIC)))
+ declaredclasscount++;
+ }
+ }
+
+ /* allocate Class[] and check for OOM */
+
+ oa = builtin_anewarray(declaredclasscount, class_java_lang_Class);
+
+ if (!oa)
+ return NULL;
+
+ for (i = 0, pos = 0; i < c->innerclasscount; i++) {
+ outer = c->innerclass[i].outer_class;
+
+ /* check if outer_class is a classref or a real class and
+ get the class name from the structure */
+
+ outername = IS_CLASSREF(outer) ? outer.ref->name : outer.cls->name;
+
+ /* outer class is this class */
+
+ if ((outername == c->name) &&
+ ((publicOnly == 0) || (c->innerclass[i].flags & ACC_PUBLIC))) {
+ classinfo *inner;
+
+ if (!resolve_classref_or_classinfo(NULL,
+ c->innerclass[i].inner_class,
+ resolveEager, false, false,
+ &inner))
+ return NULL;
+
+ if (!(inner->state & CLASS_LINKED))
+ if (!link_class(inner))
+ return NULL;
+
+ oa->data[pos++] = (java_objectheader *) inner;
+ }
+ }
+
+ return oa;
+}
+
+
+/*
+ * Class: java/lang/VMClass
+ * Method: getDeclaredFields
+ * Signature: (Z)[Ljava/lang/reflect/Field;
+ */
+JNIEXPORT java_objectarray* JNICALL Java_java_lang_VMClass_getDeclaredFields(JNIEnv *env, jclass clazz, java_lang_Class *klass, s4 publicOnly)
+{
+ classinfo *c;
+ java_objectarray *oa; /* result: array of field-objects */
+ fieldinfo *f;
+ java_objectheader *o;
+ java_lang_reflect_Field *rf;
+ s4 public_fields; /* number of elements in field-array */
+ s4 pos;
+ s4 i;
+
+ c = (classinfo *) klass;
+
+ /* determine number of fields */
+
+ for (i = 0, public_fields = 0; i < c->fieldscount; i++)
+ if ((c->fields[i].flags & ACC_PUBLIC) || (publicOnly == 0))
+ public_fields++;
+
+ /* create array of fields */
+
+ oa = builtin_anewarray(public_fields, class_java_lang_reflect_Field);
+
+ if (!oa)
+ return NULL;
+
+ /* get the fields and store in the array */
+
+ for (i = 0, pos = 0; i < c->fieldscount; i++) {
+ f = &(c->fields[i]);
+
+ if ((f->flags & ACC_PUBLIC) || (publicOnly == 0)) {
+ /* create Field object */
+
+ if (!(o = native_new_and_init(class_java_lang_reflect_Field)))
+ return NULL;
+
+ /* initialize instance fields */
+
+ rf = (java_lang_reflect_Field *) o;
+
+ rf->declaringClass = (java_lang_Class *) c;
+ rf->name = javastring_new(f->name);
+ rf->slot = i;
+
+ /* store object into array */
+
+ oa->data[pos++] = o;
+ }
+ }
+
+ return oa;
+}
+
+
+/*
+ * Class: java/lang/VMClass
+ * Method: getDeclaredMethods
+ * Signature: (Z)[Ljava/lang/reflect/Method;
+ */
+JNIEXPORT java_objectarray* JNICALL Java_java_lang_VMClass_getDeclaredMethods(JNIEnv *env, jclass clazz, java_lang_Class *klass, s4 publicOnly)
+{
+ classinfo *c;
+ java_objectheader *o;
+ java_lang_reflect_Method *rm;
+ java_objectarray *oa; /* result: array of Method-objects */
+ methodinfo *m; /* the current method to be represented */
+ s4 public_methods; /* number of public methods of the class */
+ s4 pos;
+ s4 i;
+
+ c = (classinfo *) klass;
+ public_methods = 0;
+
+ /* JOWENN: array classes do not declare methods according to mauve
+ test. It should be considered, if we should return to my old
+ clone method overriding instead of declaring it as a member
+ function. */
+
+ if (Java_java_lang_VMClass_isArray(env, clazz, klass))
+ return builtin_anewarray(0, class_java_lang_reflect_Method);
+
+ /* determine number of methods */
+
+ for (i = 0; i < c->methodscount; i++) {
+ m = &c->methods[i];
+
+ if (((m->flags & ACC_PUBLIC) || (publicOnly == false)) &&
+ ((m->name != utf_init) && (m->name != utf_clinit)) &&
+ !(m->flags & ACC_MIRANDA))
+ public_methods++;
+ }
+
+ oa = builtin_anewarray(public_methods, class_java_lang_reflect_Method);
+
+ if (!oa)
+ return NULL;
+
+ for (i = 0, pos = 0; i < c->methodscount; i++) {
+ m = &c->methods[i];
+
+ if (((m->flags & ACC_PUBLIC) || (publicOnly == false)) &&
+ ((m->name != utf_init) && (m->name != utf_clinit)) &&
+ !(m->flags & ACC_MIRANDA)) {
+
+ if (!(o = native_new_and_init(class_java_lang_reflect_Method)))
+ return NULL;
+
+ /* initialize instance fields */
+
+ rm = (java_lang_reflect_Method *) o;
+
+ rm->declaringClass = (java_lang_Class *) m->class;
+ rm->name = javastring_new(m->name);
+ rm->slot = i;
+
+ /* store object into array */
+
+ oa->data[pos++] = o;
+ }
+ }
+
+ return oa;
+}
+
+
+/*
+ * Class: java/lang/VMClass
+ * Method: getDeclaredConstructors
+ * Signature: (Z)[Ljava/lang/reflect/Constructor;
+ */
+JNIEXPORT java_objectarray* JNICALL Java_java_lang_VMClass_getDeclaredConstructors(JNIEnv *env, jclass clazz, java_lang_Class *klass, s4 publicOnly)
+{
+ classinfo *c;
+ methodinfo *m; /* the current method to be represented */
+ java_objectarray *oa; /* result: array of Method-objects */
+ java_objectheader *o;
+ java_lang_reflect_Constructor *rc;
+ s4 public_methods; /* number of public methods of the class */
+ s4 pos;
+ s4 i;
+
+ c = (classinfo *) klass;
+
+ /* determine number of constructors */
+
+ for (i = 0, public_methods = 0; i < c->methodscount; i++) {
+ m = &c->methods[i];
+
+ if (((m->flags & ACC_PUBLIC) || (publicOnly == 0)) &&
+ (m->name == utf_init))
+ public_methods++;
+ }
+
+ oa = builtin_anewarray(public_methods, class_java_lang_reflect_Constructor);
+
+ if (!oa)
+ return NULL;
+
+ for (i = 0, pos = 0; i < c->methodscount; i++) {
+ m = &c->methods[i];
+
+ if (((m->flags & ACC_PUBLIC) || (publicOnly == 0)) &&
+ (m->name == utf_init)) {
+
+ if (!(o = native_new_and_init(class_java_lang_reflect_Constructor)))
+ return NULL;
+
+ /* initialize instance fields */
+
+ rc = (java_lang_reflect_Constructor *) o;
+
+ rc->clazz = (java_lang_Class *) c;
+ rc->slot = i;
+
+ /* store object into array */
+
+ oa->data[pos++] = o;
+ }
+ }
+
+ return oa;
+}
+
+
+/*
+ * Class: java/lang/VMClass
+ * Method: getClassLoader
+ * Signature: ()Ljava/lang/ClassLoader;
+ */
+JNIEXPORT java_lang_ClassLoader* JNICALL Java_java_lang_VMClass_getClassLoader(JNIEnv *env, jclass clazz, java_lang_Class *klass)
+{
+ classinfo *c;
+
+ c = (classinfo *) klass;
+
+ return (java_lang_ClassLoader *) c->classloader;
+}
+
+
+/*
+ * Class: java/lang/VMClass
+ * Method: forName
+ * Signature: (Ljava/lang/String;ZLjava/lang/ClassLoader;)Ljava/lang/Class;
+ */
+JNIEXPORT java_lang_Class* JNICALL Java_java_lang_VMClass_forName(JNIEnv *env, jclass clazz, java_lang_String *name, s4 initialize, java_lang_ClassLoader *loader)
+{
+ classinfo *c;
+ utf *u;
+ u2 *pos;
+ s4 i;
+
+ /* illegal argument */
+
+ if (!name)
+ return NULL;
+
+ /* name must not contain '/' (mauve test) */
+
+ for (i = 0, pos = name->value->data + name->offset; i < name->count; i++, pos++) {
+ if (*pos == '/') {
+ *exceptionptr =
+ new_exception_javastring(string_java_lang_ClassNotFoundException, name);
+ return NULL;
+ }
+ }
+
+ /* create utf string in which '.' is replaced by '/' */
+
+ u = javastring_toutf(name, true);
+
+ /* try to load, ... */
+
+ if (!(c = load_class_from_classloader(u, (java_objectheader *) loader))) {
+ classinfo *xclass;
+
+ xclass = (*exceptionptr)->vftbl->class;
+
+ /* if the exception is a NoClassDefFoundError, we replace it with a
+ ClassNotFoundException, otherwise return the exception */
+
+ if (xclass == class_java_lang_NoClassDefFoundError) {
+ /* clear exceptionptr, because builtin_new checks for
+ ExceptionInInitializerError */
+ *exceptionptr = NULL;
+
+ *exceptionptr =
+ new_exception_javastring(string_java_lang_ClassNotFoundException, name);
+ }
+
+ return NULL;
+ }
+
+ /* link, ... */
+
+ if (!link_class(c))
+ return NULL;
+
+ /* ...and initialize it, if required */
+
+ if (initialize)
+ if (!initialize_class(c))
+ return NULL;
+
+ return (java_lang_Class *) c;
+}
+
+
+/*
+ * Class: java/lang/Class
+ * Method: isArray
+ * Signature: ()Z
+ */
+JNIEXPORT s4 JNICALL Java_java_lang_VMClass_isArray(JNIEnv *env, jclass clazz, java_lang_Class *klass)
+{
+ classinfo *c = (classinfo *) klass;
+
+ if (!(c->state & CLASS_LINKED))
+ if (!link_class(c))
+ return 0;
+
+ return (c->vftbl->arraydesc != NULL);
+}
+
+
+/*
+ * Class: java/lang/VMClass
+ * Method: throwException
+ * Signature: (Ljava/lang/Throwable;)V
+ */
+JNIEXPORT void JNICALL Java_java_lang_VMClass_throwException(JNIEnv *env, jclass clazz, java_lang_Throwable *t)
+{
+ *exceptionptr = (java_objectheader *) t;
+}
+
+
+/*
+ * These are local overrides for various environment variables in Emacs.
+ * Please do not remove this and leave it at the end of the file, where
+ * Emacs will automagically detect them.
+ * ---------------------------------------------------------------------
+ * Local variables:
+ * mode: c
+ * indent-tabs-mode: t
+ * c-basic-offset: 4
+ * tab-width: 4
+ * End:
+ * vim:noexpandtab:sw=4:ts=4:
+ */
--- /dev/null
+/* src/native/vm/VMClassLoader.c - java/lang/VMClassLoader
+
+ Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
+ C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
+ E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
+ J. Wenninger, Institut f. Computersprachen - TU Wien
+
+ This file is part of CACAO.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA.
+
+ Contact: cacao@cacaojvm.org
+
+ Authors: Roman Obermaiser
+
+ Changes: Joseph Wenninger
+ Christian Thalinger
+ Edwin Steiner
+
+ $Id: java_lang_VMClassLoader.c 5153 2006-07-18 08:19:24Z twisti $
+
+*/
+
+
+#include "config.h"
+
+#include <sys/stat.h>
+
+#include "vm/types.h"
+
+#include "mm/memory.h"
+#include "native/jni.h"
+#include "native/native.h"
+#include "native/include/java_lang_Class.h"
+#include "native/include/java_lang_String.h"
+#include "native/include/java_lang_ClassLoader.h"
+#include "native/include/java_security_ProtectionDomain.h"
+#include "native/include/java_util_Vector.h"
+#include "toolbox/logging.h"
+#include "vm/builtin.h"
+#include "vm/class.h"
+#include "vm/classcache.h"
+#include "vm/exceptions.h"
+#include "vm/initialize.h"
+#include "vm/linker.h"
+#include "vm/loader.h"
+#include "vm/options.h"
+#include "vm/statistics.h"
+#include "vm/stringlocal.h"
+#include "vm/suck.h"
+#include "vm/vm.h"
+#include "vm/zip.h"
+#include "vm/jit/asmpart.h"
+
+#if defined(ENABLE_JVMTI)
+#include "native/jvmti/cacaodbg.h"
+#endif
+
+
+/*
+ * Class: java/lang/VMClassLoader
+ * Method: defineClass
+ * Signature: (Ljava/lang/ClassLoader;Ljava/lang/String;[BIILjava/security/ProtectionDomain;)Ljava/lang/Class;
+ */
+JNIEXPORT java_lang_Class* JNICALL Java_java_lang_VMClassLoader_defineClass(JNIEnv *env, jclass clazz, java_lang_ClassLoader *cl, java_lang_String *name, java_bytearray *data, s4 offset, s4 len, java_security_ProtectionDomain *pd)
+{
+ classinfo *c;
+ classinfo *r;
+ classbuffer *cb;
+ utf *utfname;
+#if defined(ENABLE_JVMTI)
+ jint new_class_data_len = 0;
+ unsigned char* new_class_data = NULL;
+#endif
+
+ /* check if data was passed */
+
+ if (data == NULL) {
+ exceptions_throw_nullpointerexception();
+ return NULL;
+ }
+
+ /* check the indexes passed */
+
+ if ((offset < 0) || (len < 0) || ((offset + len) > data->header.size)) {
+ exceptions_throw_arrayindexoutofboundsexception();
+ return NULL;
+ }
+
+ if (name) {
+ /* convert '.' to '/' in java string */
+
+ utfname = javastring_toutf(name, true);
+
+ /* check if this class has already been defined */
+
+ c = classcache_lookup_defined_or_initiated((java_objectheader *) cl, utfname);
+ if (c) {
+ *exceptionptr =
+ exceptions_new_linkageerror("duplicate class definition: ",c);
+ return NULL;
+ }
+ }
+ else {
+ utfname = NULL;
+ }
+
+
+#if defined(ENABLE_JVMTI)
+ /* fire Class File Load Hook JVMTI event */
+ if (jvmti) jvmti_ClassFileLoadHook(utfname, len, (unsigned char*)data->data,
+ (java_objectheader *)cl, (java_objectheader *)pd,
+ &new_class_data_len, &new_class_data);
+#endif
+
+
+ /* create a new classinfo struct */
+
+ c = class_create_classinfo(utfname);
+
+#if defined(ENABLE_STATISTICS)
+ /* measure time */
+
+ if (opt_getloadingtime)
+ loadingtime_start();
+#endif
+
+ /* build a classbuffer with the given data */
+
+ cb = NEW(classbuffer);
+ cb->class = c;
+#if defined(ENABLE_JVMTI)
+ /* check if the JVMTI wants to modify the class */
+ if (new_class_data == NULL) {
+#endif
+ cb->size = len;
+ cb->data = (u1 *) &data->data[offset];
+#if defined(ENABLE_JVMTI)
+ } else {
+ cb->size = new_class_data_len;
+ cb->data = (u1 *) new_class_data;
+ }
+#endif
+ cb->pos = cb->data;
+
+ /* preset the defining classloader */
+
+ c->classloader = (java_objectheader *) cl;
+
+ /* load the class from this buffer */
+
+ r = load_class_from_classbuffer(cb);
+
+ /* free memory */
+
+ FREE(cb, classbuffer);
+
+#if defined(ENABLE_STATISTICS)
+ /* measure time */
+
+ if (opt_getloadingtime)
+ loadingtime_stop();
+#endif
+
+ if (!r) {
+ /* If return value is NULL, we had a problem and the class is not */
+ /* loaded. */
+ /* now free the allocated memory, otherwise we could run into a DOS */
+
+ class_free(c);
+
+ return NULL;
+ }
+
+ /* set ProtectionDomain */
+
+ c->object.pd = pd;
+
+ /* Store the newly defined class in the class cache. This call also */
+ /* checks whether a class of the same name has already been defined by */
+ /* the same defining loader, and if so, replaces the newly created class */
+ /* by the one defined earlier. */
+ /* Important: The classinfo given to classcache_store must be */
+ /* fully prepared because another thread may return this */
+ /* pointer after the lookup at to top of this function */
+ /* directly after the class cache lock has been released. */
+
+ c = classcache_store((java_objectheader *)cl,c,true);
+
+ return (java_lang_Class *) c;
+}
+
+
+/*
+ * Class: java/lang/VMClassLoader
+ * Method: getPrimitiveClass
+ * Signature: (C)Ljava/lang/Class;
+ */
+JNIEXPORT java_lang_Class* JNICALL Java_java_lang_VMClassLoader_getPrimitiveClass(JNIEnv *env, jclass clazz, s4 type)
+{
+ classinfo *c;
+
+ /* get primitive class */
+
+ switch (type) {
+ case 'I':
+ c = primitivetype_table[PRIMITIVETYPE_INT].class_primitive;
+ break;
+ case 'J':
+ c = primitivetype_table[PRIMITIVETYPE_LONG].class_primitive;
+ break;
+ case 'F':
+ c = primitivetype_table[PRIMITIVETYPE_FLOAT].class_primitive;
+ break;
+ case 'D':
+ c = primitivetype_table[PRIMITIVETYPE_DOUBLE].class_primitive;
+ break;
+ case 'B':
+ c = primitivetype_table[PRIMITIVETYPE_BYTE].class_primitive;
+ break;
+ case 'C':
+ c = primitivetype_table[PRIMITIVETYPE_CHAR].class_primitive;
+ break;
+ case 'S':
+ c = primitivetype_table[PRIMITIVETYPE_SHORT].class_primitive;
+ break;
+ case 'Z':
+ c = primitivetype_table[PRIMITIVETYPE_BOOLEAN].class_primitive;
+ break;
+ case 'V':
+ c = primitivetype_table[PRIMITIVETYPE_VOID].class_primitive;
+ break;
+ default:
+ *exceptionptr = new_exception(string_java_lang_ClassNotFoundException);
+ c = NULL;
+ }
+
+ return (java_lang_Class *) c;
+}
+
+
+/*
+ * Class: java/lang/VMClassLoader
+ * Method: resolveClass
+ * Signature: (Ljava/lang/Class;)V
+ */
+JNIEXPORT void JNICALL Java_java_lang_VMClassLoader_resolveClass(JNIEnv *env, jclass clazz, java_lang_Class *c)
+{
+ classinfo *ci;
+
+ ci = (classinfo *) c;
+
+ if (!ci) {
+ exceptions_throw_nullpointerexception();
+ return;
+ }
+
+ /* link the class */
+
+ if (!(ci->state & CLASS_LINKED))
+ (void) link_class(ci);
+
+ return;
+}
+
+
+/*
+ * Class: java/lang/VMClassLoader
+ * Method: loadClass
+ * Signature: (Ljava/lang/String;Z)Ljava/lang/Class;
+ */
+JNIEXPORT java_lang_Class* JNICALL Java_java_lang_VMClassLoader_loadClass(JNIEnv *env, jclass clazz, java_lang_String *name, jboolean resolve)
+{
+ classinfo *c;
+ utf *u;
+
+ if (name == NULL) {
+ exceptions_throw_nullpointerexception();
+ return NULL;
+ }
+
+ /* create utf string in which '.' is replaced by '/' */
+
+ u = javastring_toutf(name, true);
+
+ /* load class */
+
+ if (!(c = load_class_bootstrap(u)))
+ goto exception;
+
+ /* resolve class -- if requested */
+
+/* if (resolve) */
+ if (!link_class(c))
+ goto exception;
+
+ return (java_lang_Class *) c;
+
+ exception:
+ c = (*exceptionptr)->vftbl->class;
+
+ /* if the exception is a NoClassDefFoundError, we replace it with a
+ ClassNotFoundException, otherwise return the exception */
+
+ if (c == class_java_lang_NoClassDefFoundError) {
+ /* clear exceptionptr, because builtin_new checks for
+ ExceptionInInitializerError */
+ *exceptionptr = NULL;
+
+ *exceptionptr =
+ new_exception_javastring(string_java_lang_ClassNotFoundException, name);
+ }
+
+ return NULL;
+}
+
+
+/*
+ * Class: java/lang/VMClassLoader
+ * Method: nativeGetResources
+ * Signature: (Ljava/lang/String;)Ljava/util/Vector;
+ */
+JNIEXPORT java_util_Vector* JNICALL Java_java_lang_VMClassLoader_nativeGetResources(JNIEnv *env, jclass clazz, java_lang_String *name)
+{
+ jobject o; /* vector being created */
+ methodinfo *m; /* "add" method of vector */
+ java_lang_String *path; /* path to be added */
+ list_classpath_entry *lce; /* classpath entry */
+ utf *utfname; /* utf to look for */
+ char *buffer; /* char buffer */
+ char *namestart; /* start of name to use */
+ char *tmppath; /* temporary buffer */
+ s4 namelen; /* length of name to use */
+ s4 searchlen; /* length of name to search */
+ s4 bufsize; /* size of buffer allocated */
+ s4 pathlen; /* name of path to assemble */
+ struct stat buf; /* buffer for stat */
+ jboolean ret; /* return value of "add" */
+
+ /* get the resource name as utf string */
+
+ utfname = javastring_toutf(name, false);
+ if (!utfname)
+ return NULL;
+
+ /* copy it to a char buffer */
+
+ namelen = utf_bytes(utfname);
+ searchlen = namelen;
+ bufsize = namelen + strlen("0");
+ buffer = MNEW(char, bufsize);
+
+ utf_copy(buffer, utfname);
+ namestart = buffer;
+
+ /* skip leading '/' */
+
+ if (namestart[0] == '/') {
+ namestart++;
+ namelen--;
+ searchlen--;
+ }
+
+ /* remove trailing `.class' */
+
+ if (namelen >= 6 && strcmp(namestart + (namelen - 6), ".class") == 0) {
+ searchlen -= 6;
+ }
+
+ /* create a new needle to look for, if necessary */
+
+ if (searchlen != bufsize-1) {
+ utfname = utf_new(namestart, searchlen);
+ if (utfname == NULL)
+ goto return_NULL;
+ }
+
+ /* new Vector() */
+
+ o = native_new_and_init(class_java_util_Vector);
+
+ if (!o)
+ goto return_NULL;
+
+ /* get Vector.add() method */
+
+ m = class_resolveclassmethod(class_java_util_Vector,
+ utf_add,
+ utf_new_char("(Ljava/lang/Object;)Z"),
+ NULL,
+ true);
+
+ if (!m)
+ goto return_NULL;
+
+ /* iterate over all classpath entries */
+
+ for (lce = list_first(list_classpath_entries); lce != NULL;
+ lce = list_next(list_classpath_entries, lce)) {
+ /* clear path pointer */
+ path = NULL;
+
+#if defined(ENABLE_ZLIB)
+ if (lce->type == CLASSPATH_ARCHIVE) {
+
+ if (zip_find(lce, utfname)) {
+ pathlen = strlen("jar:file://") + lce->pathlen + strlen("!/") +
+ namelen + strlen("0");
+
+ tmppath = MNEW(char, pathlen);
+
+ sprintf(tmppath, "jar:file://%s!/%s", lce->path, namestart);
+ path = javastring_new_from_utf_string(tmppath),
+
+ MFREE(tmppath, char, pathlen);
+ }
+
+ } else {
+#endif /* defined(ENABLE_ZLIB) */
+ pathlen = strlen("file://") + lce->pathlen + namelen + strlen("0");
+
+ tmppath = MNEW(char, pathlen);
+
+ sprintf(tmppath, "file://%s%s", lce->path, namestart);
+
+ /* Does this file exist? */
+
+ if (stat(tmppath + strlen("file://") - 1, &buf) == 0)
+ if (!S_ISDIR(buf.st_mode))
+ path = javastring_new_from_utf_string(tmppath);
+
+ MFREE(tmppath, char, pathlen);
+#if defined(ENABLE_ZLIB)
+ }
+#endif
+
+ /* if a resource was found, add it to the vector */
+
+ if (path) {
+ ret = vm_call_method_int(m, o, path);
+
+ if (*exceptionptr)
+ goto return_NULL;
+
+ if (ret == 0)
+ goto return_NULL;
+ }
+ }
+
+ MFREE(buffer, char, bufsize);
+
+ return (java_util_Vector *) o;
+
+return_NULL:
+ MFREE(buffer, char, bufsize);
+
+ return NULL;
+}
+
+
+/*
+ * Class: java/lang/VMClassLoader
+ * Method: defaultAssertionStatus
+ * Signature: ()Z
+ */
+JNIEXPORT s4 JNICALL Java_java_lang_VMClassLoader_defaultAssertionStatus(JNIEnv *env, jclass clazz)
+{
+ return _Jv_jvm->Java_java_lang_VMClassLoader_defaultAssertionStatus;
+}
+
+
+/*
+ * Class: java/lang/VMClassLoader
+ * Method: findLoadedClass
+ * Signature: (Ljava/lang/ClassLoader;Ljava/lang/String;)Ljava/lang/Class;
+ */
+JNIEXPORT java_lang_Class* JNICALL Java_java_lang_VMClassLoader_findLoadedClass(JNIEnv *env, jclass clazz, java_lang_ClassLoader *cl, java_lang_String *name)
+{
+ classinfo *c;
+ utf *u;
+
+ /* replace `.' by `/', this is required by the classcache */
+
+ u = javastring_toutf(name, true);
+
+ /* lookup for defining classloader */
+
+ c = classcache_lookup_defined((classloader *) cl, u);
+
+ /* if not found, lookup for initiating classloader */
+
+ if (c == NULL)
+ c = classcache_lookup((classloader *) cl, u);
+
+ return (java_lang_Class *) c;
+}
+
+
+/*
+ * These are local overrides for various environment variables in Emacs.
+ * Please do not remove this and leave it at the end of the file, where
+ * Emacs will automagically detect them.
+ * ---------------------------------------------------------------------
+ * Local variables:
+ * mode: c
+ * indent-tabs-mode: t
+ * c-basic-offset: 4
+ * tab-width: 4
+ * End:
+ * vim:noexpandtab:sw=4:ts=4:
+ */
--- /dev/null
+/* src/native/vm/VMObject.c - java/lang/VMObject
+
+ Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
+ C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
+ E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
+ J. Wenninger, Institut f. Computersprachen - TU Wien
+
+ This file is part of CACAO.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA.
+
+ Contact: cacao@cacaojvm.org
+
+ Authors: Roman Obermaiser
+
+ Changes: Joseph Wenninger
+ Christian Thalinger
+
+ $Id: java_lang_VMObject.c 5153 2006-07-18 08:19:24Z twisti $
+
+*/
+
+
+#include "config.h"
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "vm/types.h"
+
+#include "mm/boehm.h"
+#include "mm/memory.h"
+#include "toolbox/logging.h"
+#include "native/jni.h"
+#include "native/native.h"
+#include "native/include/java_lang_Class.h"
+#include "native/include/java_lang_Cloneable.h"
+#include "native/include/java_lang_Object.h"
+
+#if defined(ENABLE_THREADS)
+# include "threads/native/threads.h"
+#endif
+
+#include "vm/builtin.h"
+#include "vm/exceptions.h"
+#include "vm/loader.h"
+#include "vm/options.h"
+#include "vm/stringlocal.h"
+
+#if defined(ENABLE_JVMTI)
+#include "native/jvmti/cacaodbg.h"
+#endif
+
+
+/*
+ * Class: java/lang/VMObject
+ * Method: getClass
+ * Signature: (Ljava/lang/Object;)Ljava/lang/Class;
+ */
+JNIEXPORT java_lang_Class* JNICALL Java_java_lang_VMObject_getClass(JNIEnv *env, jclass clazz, java_lang_Object *obj)
+{
+ classinfo *c;
+
+ if (!obj)
+ return NULL;
+
+ c = ((java_objectheader *) obj)->vftbl->class;
+
+ return (java_lang_Class *) c;
+}
+
+
+/*
+ * Class: java/lang/VMObject
+ * Method: clone
+ * Signature: (Ljava/lang/Cloneable;)Ljava/lang/Object;
+ */
+JNIEXPORT java_lang_Object* JNICALL Java_java_lang_VMObject_clone(JNIEnv *env, jclass clazz, java_lang_Cloneable *this)
+{
+ classinfo *c;
+ java_lang_Object *new;
+ arraydescriptor *desc;
+
+ /* we are cloning an array */
+
+ if ((desc = this->header.vftbl->arraydesc) != NULL) {
+
+ u4 size = desc->dataoffset + desc->componentsize * ((java_arrayheader *) this)->size;
+
+ new = (java_lang_Object *)
+ heap_allocate(size, (desc->arraytype == ARRAYTYPE_OBJECT), NULL);
+
+ if (new == NULL)
+ return NULL;
+
+ MCOPY(new, this, u1, size);
+
+#if defined(ENABLE_THREADS)
+ lock_init_object_lock((java_objectheader *) new);
+#endif
+
+ return new;
+ }
+
+ /* we are cloning a non-array */
+
+ if (!builtin_instanceof((java_objectheader *) this, class_java_lang_Cloneable)) {
+ *exceptionptr =
+ new_exception(string_java_lang_CloneNotSupportedException);
+ return NULL;
+ }
+
+ c = this->header.vftbl->class;
+ new = (java_lang_Object *) builtin_new(c);
+
+ if (new == NULL)
+ return NULL;
+
+ MCOPY(new, this, u1, c->instancesize);
+
+#if defined(ENABLE_THREADS)
+ lock_init_object_lock((java_objectheader *) new);
+#endif
+
+ return new;
+}
+
+
+/*
+ * Class: java/lang/VMObject
+ * Method: notify
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_java_lang_VMObject_notify(JNIEnv *env, jclass clazz, java_lang_Object *this)
+{
+#if defined(ENABLE_THREADS)
+ lock_notify_object(&this->header);
+#endif
+}
+
+
+/*
+ * Class: java/lang/VMObject
+ * Method: notifyAll
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_java_lang_VMObject_notifyAll(JNIEnv *env, jclass clazz, java_lang_Object *this)
+{
+#if defined(ENABLE_THREADS)
+ lock_notify_all_object(&this->header);
+#endif
+}
+
+
+/*
+ * Class: java/lang/VMObject
+ * Method: wait
+ * Signature: (Ljava/lang/Object;JI)V
+ */
+JNIEXPORT void JNICALL Java_java_lang_VMObject_wait(JNIEnv *env, jclass clazz, java_lang_Object *o, s8 ms, s4 ns)
+{
+#if defined(ENABLE_JVMTI)
+ /* Monitor Wait */
+ if (jvmti) jvmti_MonitorWaiting(true, o, ms);
+#endif
+
+#if defined(ENABLE_THREADS)
+ lock_wait_for_object(&o->header, ms, ns);
+#endif
+
+#if defined(ENABLE_JVMTI)
+ /* Monitor Waited */
+ /* XXX: How do you know if wait timed out ?*/
+ if (jvmti) jvmti_MonitorWaiting(false, o, 0);
+#endif
+}
+
+
+/*
+ * These are local overrides for various environment variables in Emacs.
+ * Please do not remove this and leave it at the end of the file, where
+ * Emacs will automagically detect them.
+ * ---------------------------------------------------------------------
+ * Local variables:
+ * mode: c
+ * indent-tabs-mode: t
+ * c-basic-offset: 4
+ * tab-width: 4
+ * End:
+ */
--- /dev/null
+/* src/native/vm/VMRuntime.c - java/lang/VMRuntime
+
+ Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
+ C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
+ E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
+ J. Wenninger, Institut f. Computersprachen - TU Wien
+
+ This file is part of CACAO.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA.
+
+ Contact: cacao@cacaojvm.org
+
+ Authors: Roman Obermaiser
+
+ Changes: Joseph Wenninger
+ Christian Thalinger
+ Edwin Steiner
+
+ $Id: java_lang_VMRuntime.c 5153 2006-07-18 08:19:24Z twisti $
+
+*/
+
+
+#include "config.h"
+
+#include <assert.h>
+#include <string.h>
+#include <stdlib.h>
+#include <sys/utsname.h>
+
+#if !defined(WITH_STATIC_CLASSPATH)
+# include <ltdl.h>
+#endif
+
+#if defined(__DARWIN__)
+# define OS_INLINE /* required for <libkern/ppc/OSByteOrder.h> */
+# include <mach/mach.h>
+#endif
+
+#include "vm/types.h"
+
+#include "mm/boehm.h"
+#include "mm/memory.h"
+#include "native/jni.h"
+#include "native/native.h"
+#include "native/include/java_io_File.h"
+#include "native/include/java_lang_String.h"
+#include "native/include/java_lang_Process.h"
+#include "toolbox/logging.h"
+#include "vm/builtin.h"
+#include "vm/exceptions.h"
+#include "vm/loader.h"
+#include "vm/options.h"
+#include "vm/stringlocal.h"
+#include "vm/vm.h"
+
+
+/* this should work on BSD */
+/*
+#if defined(__DARWIN__)
+#include <sys/sysctl.h>
+#endif
+*/
+
+
+/* should we run all finalizers on exit? */
+static bool finalizeOnExit = false;
+
+
+/*
+ * Class: java/lang/VMRuntime
+ * Method: exitInternal
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_java_lang_VMRuntime_exit(JNIEnv *env, jclass clazz, s4 par1)
+{
+ if (finalizeOnExit)
+ gc_finalize_all();
+
+ vm_shutdown(par1);
+}
+
+
+/*
+ * Class: java/lang/VMRuntime
+ * Method: freeMemory
+ * Signature: ()J
+ */
+JNIEXPORT s8 JNICALL Java_java_lang_VMRuntime_freeMemory(JNIEnv *env, jclass clazz)
+{
+ return gc_get_free_bytes();
+}
+
+
+/*
+ * Class: java/lang/VMRuntime
+ * Method: totalMemory
+ * Signature: ()J
+ */
+JNIEXPORT s8 JNICALL Java_java_lang_VMRuntime_totalMemory(JNIEnv *env, jclass clazz)
+{
+ return gc_get_heap_size();
+}
+
+
+/*
+ * Class: java/lang/VMRuntime
+ * Method: maxMemory
+ * Signature: ()J
+ */
+JNIEXPORT s8 JNICALL Java_java_lang_VMRuntime_maxMemory(JNIEnv *env, jclass clazz)
+{
+ return gc_get_max_heap_size();
+}
+
+
+/*
+ * Class: java/lang/VMRuntime
+ * Method: gc
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_java_lang_VMRuntime_gc(JNIEnv *env, jclass clazz)
+{
+ gc_call();
+}
+
+
+/*
+ * Class: java/lang/VMRuntime
+ * Method: runFinalization
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_java_lang_VMRuntime_runFinalization(JNIEnv *env, jclass clazz)
+{
+ gc_invoke_finalizers();
+}
+
+
+/*
+ * Class: java/lang/VMRuntime
+ * Method: runFinalizersOnExit
+ * Signature: (Z)V
+ */
+JNIEXPORT void JNICALL Java_java_lang_VMRuntime_runFinalizersOnExit(JNIEnv *env, jclass clazz, s4 value)
+{
+ /* XXX threading */
+
+ finalizeOnExit = value;
+}
+
+
+/*
+ * Class: java/lang/VMRuntime
+ * Method: runFinalizationsForExit
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_java_lang_VMRuntime_runFinalizationForExit(JNIEnv *env, jclass clazz)
+{
+/* if (finalizeOnExit) { */
+/* gc_call(); */
+ /* gc_finalize_all(); */
+/* } */
+/* log_text("Java_java_lang_VMRuntime_runFinalizationForExit called"); */
+ /*gc_finalize_all();*/
+ /*gc_invoke_finalizers();*/
+ /*gc_call();*/
+}
+
+
+/*
+ * Class: java/lang/VMRuntime
+ * Method: traceInstructions
+ * Signature: (Z)V
+ */
+JNIEXPORT void JNICALL Java_java_lang_VMRuntime_traceInstructions(JNIEnv *env, jclass clazz, s4 par1)
+{
+ /* not supported */
+}
+
+
+/*
+ * Class: java/lang/VMRuntime
+ * Method: traceMethodCalls
+ * Signature: (Z)V
+ */
+JNIEXPORT void JNICALL Java_java_lang_VMRuntime_traceMethodCalls(JNIEnv *env, jclass clazz, s4 par1)
+{
+ /* not supported */
+}
+
+
+/*
+ * Class: java/lang/VMRuntime
+ * Method: availableProcessors
+ * Signature: ()I
+ */
+JNIEXPORT s4 JNICALL Java_java_lang_VMRuntime_availableProcessors(JNIEnv *env, jclass clazz)
+{
+#if defined(_SC_NPROC_ONLN)
+ return (s4) sysconf(_SC_NPROC_ONLN);
+
+#elif defined(_SC_NPROCESSORS_ONLN)
+ return (s4) sysconf(_SC_NPROCESSORS_ONLN);
+
+#elif defined(__DARWIN__)
+ /* this should work in BSD */
+ /*
+ int ncpu, mib[2], rc;
+ size_t len;
+
+ mib[0] = CTL_HW;
+ mib[1] = HW_NCPU;
+ len = sizeof(ncpu);
+ rc = sysctl(mib, 2, &ncpu, &len, NULL, 0);
+
+ return (s4) ncpu;
+ */
+
+ host_basic_info_data_t hinfo;
+ mach_msg_type_number_t hinfo_count = HOST_BASIC_INFO_COUNT;
+ kern_return_t rc;
+
+ rc = host_info(mach_host_self(), HOST_BASIC_INFO,
+ (host_info_t) &hinfo, &hinfo_count);
+
+ if (rc != KERN_SUCCESS) {
+ return -1;
+ }
+
+ return (s4) hinfo.avail_cpus;
+
+#else
+ return 1;
+#endif
+}
+
+
+/*
+ * Class: java/lang/VMRuntime
+ * Method: nativeLoad
+ * Signature: (Ljava/lang/String;Ljava/lang/ClassLoader;)I
+ */
+JNIEXPORT s4 JNICALL Java_java_lang_VMRuntime_nativeLoad(JNIEnv *env, jclass clazz, java_lang_String *filename, java_lang_ClassLoader *loader)
+{
+#if !defined(WITH_STATIC_CLASSPATH)
+ utf *name;
+ lt_dlhandle handle;
+ lt_ptr onload;
+ s4 version;
+#endif
+
+ if (filename == NULL) {
+ exceptions_throw_nullpointerexception();
+ return 0;
+ }
+
+#if defined(WITH_STATIC_CLASSPATH)
+ return 1;
+#else /* defined(WITH_STATIC_CLASSPATH) */
+ name = javastring_toutf(filename, 0);
+
+ /* is the library already loaded? */
+
+ if (native_hashtable_library_find(name, (java_objectheader *) loader))
+ return 1;
+
+ /* try to open the library */
+
+ if (!(handle = lt_dlopen(name->text))) {
+ if (opt_verbose) {
+ log_start();
+ log_print("Java_java_lang_VMRuntime_nativeLoad: ");
+ log_print(lt_dlerror());
+ log_finish();
+ }
+
+ return 0;
+ }
+
+ /* resolve JNI_OnLoad function */
+
+ if ((onload = lt_dlsym(handle, "JNI_OnLoad"))) {
+ JNIEXPORT s4 (JNICALL *JNI_OnLoad) (JavaVM *, void *);
+ JavaVM *vm;
+
+ JNI_OnLoad = (JNIEXPORT s4 (JNICALL *)(JavaVM *, void *)) (ptrint) onload;
+
+ (*env)->GetJavaVM(env, &vm);
+
+ version = JNI_OnLoad(vm, NULL);
+
+ /* if the version is not 1.2 and not 1.4 the library cannot be loaded */
+
+ if ((version != JNI_VERSION_1_2) && (version != JNI_VERSION_1_4)) {
+ lt_dlclose(handle);
+
+ return 0;
+ }
+ }
+
+ /* insert the library name into the library hash */
+
+ native_hashtable_library_add(name, (java_objectheader *) loader, handle);
+
+ return 1;
+#endif /* defined(WITH_STATIC_CLASSPATH) */
+}
+
+
+/*
+ * Class: java/lang/VMRuntime
+ * Method: mapLibraryName
+ * Signature: (Ljava/lang/String;)Ljava/lang/String;
+ */
+JNIEXPORT java_lang_String* JNICALL Java_java_lang_VMRuntime_mapLibraryName(JNIEnv *env, jclass clazz, java_lang_String *libname)
+{
+ utf *u;
+ char *buffer;
+ s4 buffer_len;
+ s4 dumpsize;
+ java_lang_String *s;
+
+ if (!libname) {
+ exceptions_throw_nullpointerexception();
+ return NULL;
+ }
+
+ u = javastring_toutf(libname, 0);
+
+ /* calculate length of library name */
+
+ buffer_len = strlen("lib");
+
+ buffer_len += utf_bytes(u);
+
+#if defined(__DARWIN__)
+ buffer_len += strlen(".dylib");
+#else
+ buffer_len += strlen(".so");
+#endif
+
+ buffer_len += strlen("0");
+
+ dumpsize = dump_size();
+ buffer = DMNEW(char, buffer_len);
+
+ /* generate library name */
+
+ strcpy(buffer, "lib");
+ utf_cat(buffer, u);
+
+#if defined(__DARWIN__)
+ strcat(buffer, ".dylib");
+#else
+ strcat(buffer, ".so");
+#endif
+
+ s = javastring_new_from_utf_string(buffer);
+
+ /* release memory */
+
+ dump_release(dumpsize);
+
+ return s;
+}
+
+
+/*
+ * These are local overrides for various environment variables in Emacs.
+ * Please do not remove this and leave it at the end of the file, where
+ * Emacs will automagically detect them.
+ * ---------------------------------------------------------------------
+ * Local variables:
+ * mode: c
+ * indent-tabs-mode: t
+ * c-basic-offset: 4
+ * tab-width: 4
+ * End:
+ * vim:noexpandtab:sw=4:ts=4:
+ */
--- /dev/null
+/* native/vm/VMString.c - java/lang/VMString
+
+ Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
+ C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
+ E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
+ J. Wenninger, Institut f. Computersprachen - TU Wien
+
+ This file is part of CACAO.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA.
+
+ Contact: cacao@cacaojvm.org
+
+ Authors: Roman Obermaiser
+
+ Changes: Christian Thalinger
+
+ $Id: java_lang_VMString.c 5153 2006-07-18 08:19:24Z twisti $
+
+*/
+
+
+#include <stdlib.h>
+
+#include "native/jni.h"
+#include "native/native.h"
+#include "native/include/java_lang_String.h"
+#include "vm/stringlocal.h"
+
+
+/*
+ * Class: java/lang/VMString
+ * Method: intern
+ * Signature: (Ljava/lang/String;)Ljava/lang/String;
+ */
+JNIEXPORT java_lang_String* JNICALL Java_java_lang_VMString_intern(JNIEnv *env, jclass clazz, java_lang_String *str)
+{
+ java_objectheader *o;
+
+ if (!str)
+ return NULL;
+
+ /* search table so identical strings will get identical pointers */
+
+ o = literalstring_u2(str->value, str->count, str->offset, true);
+
+ return (java_lang_String *) o;
+}
+
+
+/*
+ * These are local overrides for various environment variables in Emacs.
+ * Please do not remove this and leave it at the end of the file, where
+ * Emacs will automagically detect them.
+ * ---------------------------------------------------------------------
+ * Local variables:
+ * mode: c
+ * indent-tabs-mode: t
+ * c-basic-offset: 4
+ * tab-width: 4
+ * End:
+ */
--- /dev/null
+/* src/native/vm/VMSystem.c - java/lang/VMSystem
+
+ Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
+ C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
+ E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
+ J. Wenninger, Institut f. Computersprachen - TU Wien
+
+ This file is part of CACAO.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA.
+
+ Contact: cacao@cacaojvm.org
+
+ Authors: Roman Obermaiser
+
+ Changes: Joseph Wenninger
+ Christian Thalinger
+
+ $Id: java_lang_VMSystem.c 5153 2006-07-18 08:19:24Z twisti $
+
+*/
+
+
+#include <string.h>
+
+#include "config.h"
+#include "vm/types.h"
+
+#include "native/jni.h"
+#include "native/native.h"
+#include "native/include/java_lang_Object.h"
+#include "toolbox/logging.h"
+#include "vm/builtin.h"
+#include "vm/exceptions.h"
+#include "vm/stringlocal.h"
+
+
+/*
+ * Class: java/lang/VMSystem
+ * Method: arraycopy
+ * Signature: (Ljava/lang/Object;ILjava/lang/Object;II)V
+ */
+JNIEXPORT void JNICALL Java_java_lang_VMSystem_arraycopy(JNIEnv *env, jclass clazz, java_lang_Object *source, s4 sp, java_lang_Object *dest, s4 dp, s4 len)
+{
+ java_arrayheader *s;
+ java_arrayheader *d;
+ arraydescriptor *sdesc;
+ arraydescriptor *ddesc;
+ s4 i;
+
+ s = (java_arrayheader *) source;
+ d = (java_arrayheader *) dest;
+
+ if (!s || !d) {
+ exceptions_throw_nullpointerexception();
+ return;
+ }
+
+ sdesc = s->objheader.vftbl->arraydesc;
+ ddesc = d->objheader.vftbl->arraydesc;
+
+ if (!sdesc || !ddesc || (sdesc->arraytype != ddesc->arraytype)) {
+ *exceptionptr = new_arraystoreexception();
+ return;
+ }
+
+ /* we try to throw exception with the same message as SUN does */
+
+ if ((len < 0) || (sp < 0) || (dp < 0) ||
+ (sp + len < 0) || (sp + len > s->size) ||
+ (dp + len < 0) || (dp + len > d->size)) {
+ exceptions_throw_arrayindexoutofboundsexception();
+ return;
+ }
+
+ if (sdesc->componentvftbl == ddesc->componentvftbl) {
+ /* We copy primitive values or references of exactly the same type */
+
+ s4 dataoffset = sdesc->dataoffset;
+ s4 componentsize = sdesc->componentsize;
+
+ memmove(((u1 *) d) + dataoffset + componentsize * dp,
+ ((u1 *) s) + dataoffset + componentsize * sp,
+ (size_t) len * componentsize);
+
+ } else {
+ /* We copy references of different type */
+
+ java_objectarray *oas = (java_objectarray *) s;
+ java_objectarray *oad = (java_objectarray *) d;
+
+ if (dp <= sp) {
+ for (i = 0; i < len; i++) {
+ java_objectheader *o = oas->data[sp + i];
+ if (!builtin_canstore(oad, o)) {
+ *exceptionptr = new_arraystoreexception();
+ return;
+ }
+ oad->data[dp + i] = o;
+ }
+
+ } else {
+ /* XXX this does not completely obey the specification!
+ If an exception is thrown only the elements above the
+ current index have been copied. The specification
+ requires that only the elements *below* the current
+ index have been copied before the throw. */
+
+ for (i = len - 1; i >= 0; i--) {
+ java_objectheader *o = oas->data[sp + i];
+
+ if (!builtin_canstore(oad, o)) {
+ *exceptionptr = new_arraystoreexception();
+ return;
+ }
+
+ oad->data[dp + i] = o;
+ }
+ }
+ }
+}
+
+
+/*
+ * Class: java/lang/VMSystem
+ * Method: identityHashCode
+ * Signature: (Ljava/lang/Object;)I
+ */
+JNIEXPORT s4 JNICALL Java_java_lang_VMSystem_identityHashCode(JNIEnv *env, jclass clazz, java_lang_Object *o)
+{
+ return (s4) ((ptrint) o);
+}
+
+
+/*
+ * These are local overrides for various environment variables in Emacs.
+ * Please do not remove this and leave it at the end of the file, where
+ * Emacs will automagically detect them.
+ * ---------------------------------------------------------------------
+ * Local variables:
+ * mode: c
+ * indent-tabs-mode: t
+ * c-basic-offset: 4
+ * tab-width: 4
+ * End:
+ */
--- /dev/null
+/* src/native/vm/VMThread.c - java/lang/VMThread
+
+ Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
+ C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
+ E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
+ J. Wenninger, Institut f. Computersprachen - TU Wien
+
+ This file is part of CACAO.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA.
+
+ Contact: cacao@cacaojvm.org
+
+ Authors: Roman Obermaiser
+
+ Changes: Joseph Wenninger
+ Christian Thalinger
+
+ $Id: java_lang_VMThread.c 5153 2006-07-18 08:19:24Z twisti $
+
+*/
+
+
+#include "config.h"
+#include "vm/types.h"
+
+#include "native/jni.h"
+#include "native/native.h"
+#include "native/include/java_lang_ThreadGroup.h"
+#include "native/include/java_lang_Object.h" /* java_lang_Thread.h */
+#include "native/include/java_lang_Throwable.h" /* java_lang_Thread.h */
+#include "native/include/java_lang_VMThread.h"
+#include "native/include/java_lang_Thread.h"
+
+#if defined(ENABLE_THREADS)
+# include "threads/native/threads.h"
+#endif
+
+#include "toolbox/logging.h"
+#include "vm/exceptions.h"
+#include "vm/options.h"
+
+
+/*
+ * Class: java/lang/VMThread
+ * Method: countStackFrames
+ * Signature: ()I
+ */
+JNIEXPORT s4 JNICALL Java_java_lang_VMThread_countStackFrames(JNIEnv *env, java_lang_VMThread *this)
+{
+ log_text("java_lang_VMThread_countStackFrames called");
+
+ return 0;
+}
+
+
+/*
+ * Class: java/lang/VMThread
+ * Method: start
+ * Signature: (J)V
+ */
+JNIEXPORT void JNICALL Java_java_lang_VMThread_start(JNIEnv *env, java_lang_VMThread *this, s8 stacksize)
+{
+#if defined(ENABLE_THREADS)
+ this->thread->vmThread = this;
+
+ /* don't pass a function pointer (NULL) since we want Thread.run()V here */
+
+ threads_start_thread((java_lang_Thread *) this->thread, NULL);
+#endif
+}
+
+
+/*
+ * Class: java/lang/VMThread
+ * Method: interrupt
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_java_lang_VMThread_interrupt(JNIEnv *env, java_lang_VMThread *this)
+{
+#if defined(ENABLE_THREADS)
+ threads_interrupt_thread(this);
+#endif
+}
+
+
+/*
+ * Class: java/lang/VMThread
+ * Method: isInterrupted
+ * Signature: ()Z
+ */
+JNIEXPORT s4 JNICALL Java_java_lang_VMThread_isInterrupted(JNIEnv *env, java_lang_VMThread *this)
+{
+#if defined(ENABLE_THREADS)
+ return threads_thread_has_been_interrupted(this);
+#endif
+}
+
+
+/*
+ * Class: java/lang/VMThread
+ * Method: suspend
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_java_lang_VMThread_suspend(JNIEnv *env, java_lang_VMThread *this)
+{
+#if defined(ENABLE_THREADS)
+#endif
+}
+
+
+/*
+ * Class: java/lang/VMThread
+ * Method: resume
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_java_lang_VMThread_resume(JNIEnv *env, java_lang_VMThread *this)
+{
+#if defined(ENABLE_THREADS)
+#endif
+}
+
+
+/*
+ * Class: java/lang/VMThread
+ * Method: nativeSetPriority
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_java_lang_VMThread_nativeSetPriority(JNIEnv *env, java_lang_VMThread *this, s4 priority)
+{
+#if defined(ENABLE_THREADS)
+ threads_java_lang_Thread_set_priority((java_lang_Thread *) this->thread,
+ priority);
+#endif
+}
+
+
+/*
+ * Class: java/lang/VMThread
+ * Method: nativeStop
+ * Signature: (Ljava/lang/Object;)V
+ */
+JNIEXPORT void JNICALL Java_java_lang_VMThread_nativeStop(JNIEnv *env, java_lang_VMThread *this, java_lang_Throwable *t)
+{
+#if defined(ENABLE_THREADS)
+#endif
+}
+
+
+/*
+ * Class: java/lang/VMThread
+ * Method: currentThread
+ * Signature: ()Ljava/lang/Thread;
+ */
+JNIEXPORT java_lang_Thread* JNICALL Java_java_lang_VMThread_currentThread(JNIEnv *env, jclass clazz)
+{
+ java_lang_Thread *t;
+
+#if defined(ENABLE_THREADS)
+ t = ((threadobject*) THREADOBJECT)->o.thread;
+
+ if (t == NULL)
+ log_text("t ptr is NULL\n");
+
+ if (!t->group) {
+ /* ThreadGroup of currentThread is not initialized */
+
+ t->group = (java_lang_ThreadGroup *)
+ native_new_and_init(class_java_lang_ThreadGroup);
+
+ if (t->group == NULL)
+ log_text("unable to create ThreadGroup");
+ }
+#else
+ /* we just return a fake java.lang.Thread object, otherwise we get
+ NullPointerException's in GNU classpath */
+
+ t = (java_lang_Thread *) builtin_new(class_java_lang_Thread);
+#endif
+
+ return t;
+}
+
+
+/*
+ * Class: java/lang/VMThread
+ * Method: yield
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_java_lang_VMThread_yield(JNIEnv *env, jclass clazz)
+{
+#if defined(ENABLE_THREADS)
+ threads_yield();
+#endif
+}
+
+
+/*
+ * Class: java/lang/VMThread
+ * Method: interrupted
+ * Signature: ()Z
+ */
+JNIEXPORT s4 JNICALL Java_java_lang_VMThread_interrupted(JNIEnv *env, jclass clazz)
+{
+#if defined(ENABLE_THREADS)
+ return threads_check_if_interrupted_and_reset();
+#endif
+}
+
+
+/*
+ * Class: java/lang/VMThread
+ * Method: holdsLock
+ * Signature: (Ljava/lang/Object;)Z
+ */
+JNIEXPORT s4 JNICALL Java_java_lang_VMThread_holdsLock(JNIEnv *env, jclass clazz, java_lang_Object* o)
+{
+#if defined(ENABLE_THREADS)
+ return lock_is_held_by_current_thread((java_objectheader *) o);
+#endif
+}
+
+
+/*
+ * These are local overrides for various environment variables in Emacs.
+ * Please do not remove this and leave it at the end of the file, where
+ * Emacs will automagically detect them.
+ * ---------------------------------------------------------------------
+ * Local variables:
+ * mode: c
+ * indent-tabs-mode: t
+ * c-basic-offset: 4
+ * tab-width: 4
+ * End:
+ */
--- /dev/null
+/* src/native/vm/VMThrowable.c - java/lang/VMThrowable
+
+ Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
+ C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
+ E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
+ J. Wenninger, Institut f. Computersprachen - TU Wien
+
+ This file is part of CACAO.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA.
+
+ Contact: cacao@cacaojvm.org
+
+ Authors: Joseph Wenninger
+
+ Changes: Christian Thalinger
+
+ $Id: java_lang_VMThrowable.c 5153 2006-07-18 08:19:24Z twisti $
+
+*/
+
+
+#include "config.h"
+
+#include <assert.h>
+
+#include "vm/types.h"
+
+#include "native/jni.h"
+#include "native/native.h"
+#include "native/include/gnu_classpath_Pointer.h"
+#include "native/include/java_lang_Class.h"
+#include "native/include/java_lang_StackTraceElement.h"
+#include "native/include/java_lang_Throwable.h"
+#include "native/include/java_lang_VMClass.h"
+#include "native/include/java_lang_VMThrowable.h"
+#include "vm/builtin.h"
+#include "vm/class.h"
+#include "vm/exceptions.h"
+#include "vm/loader.h"
+#include "vm/stringlocal.h"
+#include "vm/jit/stacktrace.h"
+
+
+/*
+ * Class: java/lang/VMThrowable
+ * Method: fillInStackTrace
+ * Signature: (Ljava/lang/Throwable;)Ljava/lang/VMThrowable;
+ */
+JNIEXPORT java_lang_VMThrowable* JNICALL Java_java_lang_VMThrowable_fillInStackTrace(JNIEnv *env, jclass clazz, java_lang_Throwable *t)
+{
+ java_lang_VMThrowable *o;
+ stacktracebuffer *stb;
+
+ o = (java_lang_VMThrowable *)
+ native_new_and_init(class_java_lang_VMThrowable);
+
+ if (o == NULL)
+ return NULL;
+
+#if defined(__ALPHA__) || defined(__ARM__) || defined(__I386__) || defined(__MIPS__) || defined(__POWERPC__) || defined(__X86_64__)
+ stb = stacktrace_fillInStackTrace();
+
+ if (stb == NULL)
+ return NULL;
+
+ o->vmData = (gnu_classpath_Pointer *) stb;
+#endif
+
+ return o;
+}
+
+
+/*
+ * Class: java/lang/VMThrowable
+ * Method: getStackTrace
+ * Signature: (Ljava/lang/Throwable;)[Ljava/lang/StackTraceElement;
+ */
+JNIEXPORT java_objectarray* JNICALL Java_java_lang_VMThrowable_getStackTrace(JNIEnv *env, java_lang_VMThrowable *this, java_lang_Throwable *t)
+{
+#if defined(__ALPHA__) || defined(__ARM__) || defined(__I386__) || defined(__MIPS__) || defined(__POWERPC__) || defined(__X86_64__)
+ stacktracebuffer *stb;
+ stacktrace_entry *ste;
+ stacktrace_entry *tmpste;
+ s4 size;
+ s4 i;
+ classinfo *c;
+ bool inexceptionclass;
+ bool leftexceptionclass;
+
+ methodinfo *m;
+ java_objectarray *oa;
+ s4 oalength;
+ java_lang_StackTraceElement *o;
+ java_lang_String *filename;
+ s4 linenumber;
+ java_lang_String *declaringclass;
+
+ /* get the stacktrace buffer from the VMThrowable object */
+
+ stb = (stacktracebuffer *) this->vmData;
+
+ /* get the class of the Throwable object */
+
+ c = t->header.vftbl->class;
+
+ assert(stb != NULL);
+
+ size = stb->used;
+
+ assert(size >= 2);
+
+ /* skip first 2 elements in stacktrace buffer: */
+ /* 0: VMThrowable.fillInStackTrace */
+ /* 1: Throwable.fillInStackTrace */
+
+ ste = &(stb->entries[2]);
+ size -= 2;
+
+ if ((size > 0) && (ste->method != 0)) {
+ /* not a builtin native wrapper*/
+
+ if ((ste->method->class->name == utf_java_lang_Throwable) &&
+ (ste->method->name == utf_init)) {
+ /* We assume that we are within the initializer of the
+ exception object, the exception object itself should
+ not appear in the stack trace, so we skip till we reach
+ the first function, which is not an init function. */
+
+ inexceptionclass = false;
+ leftexceptionclass = false;
+
+ while (size > 0) {
+ /* check if we are in the exception class */
+
+ if (ste->method->class == c)
+ inexceptionclass = true;
+
+ /* check if we left the exception class */
+
+ if (inexceptionclass && (ste->method->class != c))
+ leftexceptionclass = true;
+
+ /* Found exception start point if we left the
+ initalizers or we left the exception class. */
+
+ if ((ste->method->name != utf_init) || leftexceptionclass)
+ break;
+
+ /* go to next stacktrace element */
+
+ ste++;
+ size--;
+ }
+ }
+ }
+
+
+ /* now fill the stacktrace into java objects */
+
+ m = class_findmethod(class_java_lang_StackTraceElement,
+ utf_init,
+ utf_new_char("(Ljava/lang/String;ILjava/lang/String;Ljava/lang/String;Z)V"));
+
+ if (!m)
+ return NULL;
+
+ /* count entries with a method name */
+
+ for (oalength = 0, i = size, tmpste = ste; i > 0; i--, tmpste++)
+ if (tmpste->method)
+ oalength++;
+
+ /* create the stacktrace element array */
+
+ oa = builtin_anewarray(oalength, class_java_lang_StackTraceElement);
+
+ if (!oa)
+ return NULL;
+
+ for (i = 0; size > 0; size--, ste++, i++) {
+ /* skip entries without a method name */
+
+ if (ste->method == NULL) {
+ i--;
+ continue;
+ }
+
+ /* allocate a new stacktrace element */
+
+ o = (java_lang_StackTraceElement *)
+ builtin_new(class_java_lang_StackTraceElement);
+
+ if (!o)
+ return NULL;
+
+ /* get filename */
+
+ if (!(ste->method->flags & ACC_NATIVE)) {
+ if (ste->method->class->sourcefile)
+ filename = javastring_new(ste->method->class->sourcefile);
+ else
+ filename = NULL;
+
+ } else {
+ filename = NULL;
+ }
+
+ /* get line number */
+
+ if (ste->method->flags & ACC_NATIVE)
+ linenumber = -1;
+ else
+ linenumber = (ste->linenumber == 0) ? -1 : ste->linenumber;
+
+ /* get declaring class name */
+
+ declaringclass = Java_java_lang_VMClass_getName(env, NULL, (java_lang_Class *) ste->method->class);
+
+
+ /* fill the java.lang.StackTraceElement element */
+
+ o->fileName = filename;
+ o->lineNumber = linenumber;
+ o->declaringClass = declaringclass;
+ o->methodName = javastring_new(ste->method->name);
+ o->isNative = (ste->method->flags & ACC_NATIVE) ? 1 : 0;
+
+ oa->data[i] = (java_objectheader *) o;
+ }
+
+ return oa;
+#else
+ return NULL;
+#endif
+}
+
+
+/*
+ * These are local overrides for various environment variables in Emacs.
+ * Please do not remove this and leave it at the end of the file, where
+ * Emacs will automagically detect them.
+ * ---------------------------------------------------------------------
+ * Local variables:
+ * mode: c
+ * indent-tabs-mode: t
+ * c-basic-offset: 4
+ * tab-width: 4
+ * End:
+ */
--- /dev/null
+/* src/native/vm/Constructor.c - java/lang/reflect/Constructor
+
+ Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
+ C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
+ E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
+ J. Wenninger, Institut f. Computersprachen - TU Wien
+
+ This file is part of CACAO.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA.
+
+ Contact: cacao@cacaojvm.org
+
+ Authors: Roman Obermaiser
+
+ Changes: Joseph Wenninger
+ Christian Thalinger
+
+ $Id: java_lang_reflect_Constructor.c 5153 2006-07-18 08:19:24Z twisti $
+
+*/
+
+
+#include "config.h"
+
+#include <assert.h>
+#include <stdlib.h>
+
+#include "vm/types.h"
+
+#include "native/jni.h"
+#include "native/native.h"
+#include "native/include/java_lang_Class.h"
+#include "native/include/java_lang_Object.h"
+#include "native/include/java_lang_reflect_Constructor.h"
+#include "toolbox/logging.h"
+#include "vm/class.h"
+#include "vm/exceptions.h"
+#include "vm/method.h"
+#include "vm/stringlocal.h"
+
+
+/*
+ * Class: java/lang/reflect/Constructor
+ * Method: newInstance
+ * Signature: ([Ljava/lang/Object;)Ljava/lang/Object;
+ */
+JNIEXPORT java_lang_Object* JNICALL Java_java_lang_reflect_Constructor_constructNative(JNIEnv *env, java_lang_reflect_Constructor *this, java_objectarray *args, java_lang_Class *declaringClass, s4 slot)
+{
+ classinfo *c;
+ methodinfo *m;
+ java_objectheader *o;
+
+ c = (classinfo *) declaringClass;
+
+#if 0
+ /* find initializer */
+
+ if (!args) {
+ if (this->parameterTypes->header.size != 0) {
+ *exceptionptr =
+ new_exception_message(string_java_lang_IllegalArgumentException,
+ "wrong number of arguments");
+ return NULL;
+ }
+
+ } else {
+ if (this->parameterTypes->header.size != args->header.size) {
+ *exceptionptr =
+ new_exception_message(string_java_lang_IllegalArgumentException,
+ "wrong number of arguments");
+ return NULL;
+ }
+ }
+#endif
+
+ if (this->slot >= c->methodscount) {
+ log_text("illegal index in methods table");
+ return NULL;
+ }
+
+ /* create object */
+
+ o = builtin_new(c);
+
+ if (!o)
+ return NULL;
+
+ m = &(c->methods[this->slot]);
+
+ if (m->name != utf_init) {
+ /* XXX throw an exception here, although this should never happen */
+
+ assert(0);
+ }
+
+ /* call initializer */
+
+ (void) _Jv_jni_invokeNative(m, o, args);
+
+ return (java_lang_Object *) o;
+}
+
+
+/*
+ * Class: java/lang/reflect/Constructor
+ * Method: getModifiersInternal
+ * Signature: ()I
+ */
+JNIEXPORT s4 JNICALL Java_java_lang_reflect_Constructor_getModifiersInternal(JNIEnv *env, java_lang_reflect_Constructor *this)
+{
+ classinfo *c;
+ methodinfo *m;
+
+ c = (classinfo *) (this->clazz);
+ m = &(c->methods[this->slot]);
+
+ return m->flags;
+}
+
+
+/*
+ * Class: java/lang/reflect/Constructor
+ * Method: getParameterTypes
+ * Signature: ()[Ljava/lang/Class;
+ */
+JNIEXPORT java_objectarray* JNICALL Java_java_lang_reflect_Constructor_getParameterTypes(JNIEnv *env, java_lang_reflect_Constructor *this)
+{
+ classinfo *c;
+ methodinfo *m;
+
+ c = (classinfo *) this->clazz;
+
+ if ((this->slot < 0) || (this->slot >= c->methodscount)) {
+ log_text("error illegal slot for constructor in class");
+ assert(0);
+ }
+
+ m = &(c->methods[this->slot]);
+
+ return native_get_parametertypes(m);
+}
+
+
+/*
+ * Class: java/lang/reflect/Constructor
+ * Method: getExceptionTypes
+ * Signature: ()[Ljava/lang/Class;
+ */
+JNIEXPORT java_objectarray* JNICALL Java_java_lang_reflect_Constructor_getExceptionTypes(JNIEnv *env, java_lang_reflect_Constructor *this)
+{
+ classinfo *c;
+ methodinfo *m;
+
+ c = (classinfo *) this->clazz;
+
+ if ((this->slot < 0) || (this->slot >= c->methodscount)) {
+ log_text("error illegal slot for constructor in class");
+ assert(0);
+ }
+
+ m = &(c->methods[this->slot]);
+
+ return native_get_exceptiontypes(m);
+}
+
+
+/*
+ * These are local overrides for various environment variables in Emacs.
+ * Please do not remove this and leave it at the end of the file, where
+ * Emacs will automagically detect them.
+ * ---------------------------------------------------------------------
+ * Local variables:
+ * mode: c
+ * indent-tabs-mode: t
+ * c-basic-offset: 4
+ * tab-width: 4
+ * End:
+ */
--- /dev/null
+/* src/native/vm/Field.c - java/lang/reflect/Field
+
+ Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
+ C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
+ E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
+ J. Wenninger, Institut f. Computersprachen - TU Wien
+
+ This file is part of CACAO.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA.
+
+ Contact: cacao@cacaojvm.org
+
+ Authors: Roman Obermaiser
+
+ Changes: Joseph Wenninger
+ Christian Thalinger
+
+ $Id: java_lang_reflect_Field.c 5153 2006-07-18 08:19:24Z twisti $
+
+*/
+
+
+#include "config.h"
+
+#include <assert.h>
+
+#include "vm/types.h"
+
+#include "native/jni.h"
+#include "native/native.h"
+#include "native/include/java_lang_Boolean.h"
+#include "native/include/java_lang_Byte.h"
+#include "native/include/java_lang_Character.h"
+#include "native/include/java_lang_Short.h"
+#include "native/include/java_lang_Integer.h"
+#include "native/include/java_lang_Long.h"
+#include "native/include/java_lang_Float.h"
+#include "native/include/java_lang_Double.h"
+#include "native/include/java_lang_Object.h"
+#include "native/include/java_lang_Class.h"
+#include "native/include/java_lang_reflect_Field.h"
+#include "vm/access.h"
+#include "vm/builtin.h"
+#include "vm/exceptions.h"
+#include "vm/global.h"
+#include "vm/initialize.h"
+#include "vm/loader.h"
+#include "vm/resolve.h"
+#include "vm/stringlocal.h"
+#include "vm/utf8.h"
+#include "vm/jit/stacktrace.h"
+
+
+#define CHECKFIELDACCESS(this,fi,c,doret)
+
+
+/* cacao_get_field_address *****************************************************
+
+ Return the address of a field of an object.
+
+ IN:
+ this.........the field (a java.lang.reflect.Field object)
+ o............the object of which to get the field
+
+ RETURN VALUE:
+ a pointer to the field, or
+ NULL if an exception has been thrown
+
+*******************************************************************************/
+
+static void *cacao_get_field_address(java_lang_reflect_Field *this,
+ java_lang_Object *o)
+{
+ classinfo *c;
+ fieldinfo *f;
+ java_objectarray *oa;
+ classinfo *callerclass;
+
+ c = (classinfo *) this->declaringClass;
+ f = &c->fields[this->slot];
+
+ /* check field access */
+
+ if (!(f->flags & ACC_PUBLIC)) {
+ /* check if we should bypass security checks (AccessibleObject) */
+
+ if (this->flag == false) {
+ /* get the calling class */
+
+ oa = stacktrace_getClassContext();
+ if (!oa)
+ return NULL;
+
+ /* this function is always called like this:
+
+ java.lang.reflect.Field.xxx (Native Method)
+ [0] <caller>
+ */
+
+ callerclass = (classinfo *) oa->data[0];
+
+ if (!access_is_accessible_member(callerclass, c, f->flags)) {
+ *exceptionptr =
+ new_exception(string_java_lang_IllegalAccessException);
+ return NULL;
+ }
+ }
+ }
+
+ /* get the address of the field */
+
+ if (f->flags & ACC_STATIC) {
+ /* initialize class if required */
+
+ if (!(c->state & CLASS_INITIALIZED))
+ if (!initialize_class(c))
+ return NULL;
+
+ /* return value address */
+
+ return &(f->value);
+
+ } else {
+ /* obj is required for not-static fields */
+
+ if (o == NULL) {
+ exceptions_throw_nullpointerexception();
+ return NULL;
+ }
+
+ if (builtin_instanceof((java_objectheader *) o, c))
+ return (void *) ((ptrint) o + f->offset);
+ }
+
+ /* exception path */
+
+ exceptions_throw_illegalargumentexception();
+
+ return NULL;
+}
+
+
+/*
+ * Class: java/lang/reflect/Field
+ * Method: get
+ * Signature: (Ljava/lang/Object;)Ljava/lang/Object;
+ */
+JNIEXPORT java_lang_Object* JNICALL Java_java_lang_reflect_Field_get(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o)
+{
+ classinfo *c;
+ fieldinfo *f;
+ void *addr;
+
+ c = (classinfo *) this->declaringClass;
+ f = &c->fields[this->slot];
+
+ /* get address of the source field value */
+
+ if ((addr = cacao_get_field_address(this, o)) == NULL)
+ return NULL;
+
+ switch (f->parseddesc->decltype) {
+ case PRIMITIVETYPE_BOOLEAN: {
+ java_lang_Boolean *bo;
+
+ /* create wrapping class */
+
+ if (!(bo = (java_lang_Boolean *) builtin_new(class_java_lang_Boolean)))
+ return NULL;
+
+ /* set the object value */
+
+ bo->value = *((s4 *) addr);
+
+ /* return the wrapped object */
+
+ return (java_lang_Object *) bo;
+ }
+
+ case PRIMITIVETYPE_BYTE: {
+ java_lang_Byte *bo;
+
+ if (!(bo = (java_lang_Byte *) builtin_new(class_java_lang_Byte)))
+ return NULL;
+
+ bo->value = *((s4 *) addr);
+
+ return (java_lang_Object *) bo;
+ }
+
+ case PRIMITIVETYPE_CHAR: {
+ java_lang_Character *co;
+
+ if (!(co = (java_lang_Character *) builtin_new(class_java_lang_Character)))
+ return NULL;
+
+ co->value = *((s4 *) addr);
+
+ return (java_lang_Object *) co;
+ }
+
+ case PRIMITIVETYPE_SHORT: {
+ java_lang_Short *so;
+
+ if (!(so = (java_lang_Short *) builtin_new(class_java_lang_Short)))
+ return NULL;
+
+ so->value = (s4) *((s4 *) addr);
+
+ return (java_lang_Object *) so;
+ }
+
+ case PRIMITIVETYPE_INT: {
+ java_lang_Integer *io;
+
+ if (!(io = (java_lang_Integer *) builtin_new(class_java_lang_Integer)))
+ return NULL;
+
+ io->value = *((s4 *) addr);
+
+ return (java_lang_Object *) io;
+ }
+
+ case PRIMITIVETYPE_LONG: {
+ java_lang_Long *lo;
+
+ if (!(lo = (java_lang_Long *) builtin_new(class_java_lang_Long)))
+ return NULL;
+
+ lo->value = *((s8 *) addr);
+
+ return (java_lang_Object *) lo;
+ }
+
+ case PRIMITIVETYPE_FLOAT: {
+ java_lang_Float *fo;
+
+ if (!(fo = (java_lang_Float *) builtin_new(class_java_lang_Float)))
+ return NULL;
+
+ fo->value = *((float *) addr);
+
+ return (java_lang_Object *) fo;
+ }
+
+ case PRIMITIVETYPE_DOUBLE: {
+ java_lang_Double *_do;
+
+ if (!(_do = (java_lang_Double *) builtin_new(class_java_lang_Double)))
+ return NULL;
+
+ _do->value = *((double *) addr);
+
+ return (java_lang_Object *) _do;
+ }
+
+ case TYPE_ADR:
+ return (java_lang_Object *) *((java_objectheader **) addr);
+ }
+
+ /* this must not happen */
+
+ assert(0);
+
+ /* keep compiler happy */
+
+ return NULL;
+}
+
+
+/*
+ * Class: java/lang/reflect/Field
+ * Method: getBoolean
+ * Signature: (Ljava/lang/Object;)Z
+ */
+JNIEXPORT s4 JNICALL Java_java_lang_reflect_Field_getBoolean(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o)
+{
+ classinfo *c;
+ fieldinfo *f;
+ void *addr;
+
+ /* get the class and the field */
+
+ c = (classinfo *) this->declaringClass;
+ f = &c->fields[this->slot];
+
+ /* get the address of the field with an internal helper */
+
+ if ((addr = cacao_get_field_address(this, o)) == NULL)
+ return 0;
+
+ /* check the field type and return the value */
+
+ switch (f->parseddesc->decltype) {
+ case PRIMITIVETYPE_BOOLEAN:
+ return (s4) *((s4 *) addr);
+ default:
+ exceptions_throw_illegalargumentexception();
+ return 0;
+ }
+}
+
+
+/*
+ * Class: java/lang/reflect/Field
+ * Method: getByte
+ * Signature: (Ljava/lang/Object;)B
+ */
+JNIEXPORT s4 JNICALL Java_java_lang_reflect_Field_getByte(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o)
+{
+ classinfo *c;
+ fieldinfo *f;
+ void *addr;
+
+ /* get the class and the field */
+
+ c = (classinfo *) this->declaringClass;
+ f = &c->fields[this->slot];
+
+ /* get the address of the field with an internal helper */
+
+ if ((addr = cacao_get_field_address(this, o)) == NULL)
+ return 0;
+
+ /* check the field type and return the value */
+
+ switch (f->parseddesc->decltype) {
+ case PRIMITIVETYPE_BYTE:
+ return (s4) *((s4 *) addr);
+ default:
+ exceptions_throw_illegalargumentexception();
+ return 0;
+ }
+}
+
+
+/*
+ * Class: java/lang/reflect/Field
+ * Method: getChar
+ * Signature: (Ljava/lang/Object;)C
+ */
+JNIEXPORT s4 JNICALL Java_java_lang_reflect_Field_getChar(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o)
+{
+ classinfo *c;
+ fieldinfo *f;
+ void *addr;
+
+ /* get the class and the field */
+
+ c = (classinfo *) this->declaringClass;
+ f = &c->fields[this->slot];
+
+ /* get the address of the field with an internal helper */
+
+ if ((addr = cacao_get_field_address(this, o)) == NULL)
+ return 0;
+
+ /* check the field type and return the value */
+
+ switch (f->parseddesc->decltype) {
+ case PRIMITIVETYPE_CHAR:
+ return (s4) *((s4 *) addr);
+ default:
+ exceptions_throw_illegalargumentexception();
+ return 0;
+ }
+}
+
+
+/*
+ * Class: java/lang/reflect/Field
+ * Method: getShort
+ * Signature: (Ljava/lang/Object;)S
+ */
+JNIEXPORT s4 JNICALL Java_java_lang_reflect_Field_getShort(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o)
+{
+ classinfo *c;
+ fieldinfo *f;
+ void *addr;
+
+ /* get the class and the field */
+
+ c = (classinfo *) this->declaringClass;
+ f = &c->fields[this->slot];
+
+ /* get the address of the field with an internal helper */
+
+ if ((addr = cacao_get_field_address(this, o)) == NULL)
+ return 0;
+
+ /* check the field type and return the value */
+
+ switch (f->parseddesc->decltype) {
+ case PRIMITIVETYPE_BYTE:
+ case PRIMITIVETYPE_SHORT:
+ return (s4) *((s4 *) addr);
+ default:
+ exceptions_throw_illegalargumentexception();
+ return 0;
+ }
+}
+
+
+/*
+ * Class: java/lang/reflect/Field
+ * Method: getInt
+ * Signature: (Ljava/lang/Object;)I
+ */
+JNIEXPORT s4 JNICALL Java_java_lang_reflect_Field_getInt(JNIEnv *env , java_lang_reflect_Field *this, java_lang_Object *o)
+{
+ classinfo *c;
+ fieldinfo *f;
+ void *addr;
+
+ /* get the class and the field */
+
+ c = (classinfo *) this->declaringClass;
+ f = &c->fields[this->slot];
+
+ /* get the address of the field with an internal helper */
+
+ if ((addr = cacao_get_field_address(this, o)) == NULL)
+ return 0;
+
+ /* check the field type and return the value */
+
+ switch (f->parseddesc->decltype) {
+ case PRIMITIVETYPE_BYTE:
+ case PRIMITIVETYPE_CHAR:
+ case PRIMITIVETYPE_SHORT:
+ case PRIMITIVETYPE_INT:
+ return (s4) *((s4 *) addr);
+ default:
+ exceptions_throw_illegalargumentexception();
+ return 0;
+ }
+}
+
+
+/*
+ * Class: java/lang/reflect/Field
+ * Method: getLong
+ * Signature: (Ljava/lang/Object;)J
+ */
+JNIEXPORT s8 JNICALL Java_java_lang_reflect_Field_getLong(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o)
+{
+ classinfo *c;
+ fieldinfo *f;
+ void *addr;
+
+ /* get the class and the field */
+
+ c = (classinfo *) this->declaringClass;
+ f = &c->fields[this->slot];
+
+ /* get the address of the field with an internal helper */
+
+ if ((addr = cacao_get_field_address(this, o)) == NULL)
+ return 0;
+
+ /* check the field type and return the value */
+
+ switch (f->parseddesc->decltype) {
+ case PRIMITIVETYPE_BYTE:
+ case PRIMITIVETYPE_CHAR:
+ case PRIMITIVETYPE_SHORT:
+ case PRIMITIVETYPE_INT:
+ return (s8) *((s4 *) addr);
+ case PRIMITIVETYPE_LONG:
+ return (s8) *((s8 *) addr);
+ default:
+ exceptions_throw_illegalargumentexception();
+ return 0;
+ }
+}
+
+
+/*
+ * Class: java/lang/reflect/Field
+ * Method: getFloat
+ * Signature: (Ljava/lang/Object;)F
+ */
+JNIEXPORT float JNICALL Java_java_lang_reflect_Field_getFloat(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o)
+{
+ classinfo *c;
+ fieldinfo *f;
+ void *addr;
+
+ /* get the class and the field */
+
+ c = (classinfo *) this->declaringClass;
+ f = &c->fields[this->slot];
+
+ /* get the address of the field with an internal helper */
+
+ if ((addr = cacao_get_field_address(this, o)) == NULL)
+ return 0;
+
+ /* check the field type and return the value */
+
+ switch (f->parseddesc->decltype) {
+ case PRIMITIVETYPE_BYTE:
+ case PRIMITIVETYPE_CHAR:
+ case PRIMITIVETYPE_SHORT:
+ case PRIMITIVETYPE_INT:
+ return (float) *((s4 *) addr);
+ case PRIMITIVETYPE_LONG:
+ return (float) *((s8 *) addr);
+ case PRIMITIVETYPE_FLOAT:
+ return (float) *((float *) addr);
+ default:
+ exceptions_throw_illegalargumentexception();
+ return 0;
+ }
+}
+
+
+/*
+ * Class: java/lang/reflect/Field
+ * Method: getDouble
+ * Signature: (Ljava/lang/Object;)D
+ */
+JNIEXPORT double JNICALL Java_java_lang_reflect_Field_getDouble(JNIEnv *env , java_lang_reflect_Field *this, java_lang_Object *o)
+{
+ classinfo *c;
+ fieldinfo *f;
+ void *addr;
+
+ /* get the class and the field */
+
+ c = (classinfo *) this->declaringClass;
+ f = &c->fields[this->slot];
+
+ /* get the address of the field with an internal helper */
+
+ if ((addr = cacao_get_field_address(this, o)) == NULL)
+ return 0;
+
+ /* check the field type and return the value */
+
+ switch (f->parseddesc->decltype) {
+ case PRIMITIVETYPE_BYTE:
+ case PRIMITIVETYPE_CHAR:
+ case PRIMITIVETYPE_SHORT:
+ case PRIMITIVETYPE_INT:
+ return (double) *((s4 *) addr);
+ case PRIMITIVETYPE_LONG:
+ return (double) *((s8 *) addr);
+ case PRIMITIVETYPE_FLOAT:
+ return (double) *((float *) addr);
+ case PRIMITIVETYPE_DOUBLE:
+ return (double) *((double *) addr);
+ default:
+ exceptions_throw_illegalargumentexception();
+ return 0;
+ }
+}
+
+
+/*
+ * Class: java/lang/reflect/Field
+ * Method: set
+ * Signature: (Ljava/lang/Object;Ljava/lang/Object;)V
+ */
+JNIEXPORT void JNICALL Java_java_lang_reflect_Field_set(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, java_lang_Object *value)
+{
+ classinfo *sc;
+ classinfo *dc;
+ fieldinfo *sf;
+ fieldinfo *df;
+ void *faddr;
+
+ /* get the class and the field */
+
+ dc = (classinfo *) this->declaringClass;
+ df = &dc->fields[this->slot];
+
+ /* get the address of the destination field */
+
+ if ((faddr = cacao_get_field_address(this, o)) == NULL)
+ return;
+
+ /* get the source classinfo from the object */
+
+ if (value == NULL)
+ sc = NULL;
+ else
+ sc = value->header.vftbl->class;
+
+ /* The fieldid is used to set the new value, for primitive
+ types the value has to be retrieved from the wrapping
+ object */
+
+ switch (df->parseddesc->decltype) {
+ case PRIMITIVETYPE_BOOLEAN: {
+ s4 val;
+
+ /* determine the field to read the value */
+
+ if ((sc == NULL) || !(sf = class_findfield(sc, utf_value, utf_Z)))
+ break;
+
+ switch (sf->parseddesc->decltype) {
+ case PRIMITIVETYPE_BOOLEAN:
+ val = ((java_lang_Boolean *) value)->value;
+ break;
+ default:
+ exceptions_throw_illegalargumentexception();
+ return;
+ }
+
+ *((s4 *) faddr) = val;
+ return;
+ }
+
+ case PRIMITIVETYPE_BYTE: {
+ s4 val;
+
+ if ((sc == NULL) || !(sf = class_findfield(sc, utf_value, utf_B)))
+ break;
+
+ switch (sf->parseddesc->decltype) {
+ case PRIMITIVETYPE_BYTE:
+ val = ((java_lang_Byte *) value)->value;
+ break;
+ default:
+ exceptions_throw_illegalargumentexception();
+ return;
+ }
+
+ *((s4 *) faddr) = val;
+ return;
+ }
+
+ case PRIMITIVETYPE_CHAR: {
+ s4 val;
+
+ if ((sc == NULL) || !(sf = class_findfield(sc, utf_value, utf_C)))
+ break;
+
+ switch (sf->parseddesc->decltype) {
+ case PRIMITIVETYPE_CHAR:
+ val = ((java_lang_Character *) value)->value;
+ break;
+ default:
+ exceptions_throw_illegalargumentexception();
+ return;
+ }
+
+ *((s4 *) faddr) = val;
+ return;
+ }
+
+ case PRIMITIVETYPE_SHORT: {
+ s4 val;
+
+ /* get field only by name, it can be one of B, S */
+
+ if ((sc == NULL) || !(sf = class_findfield_by_name(sc, utf_value)))
+ break;
+
+ switch (sf->parseddesc->decltype) {
+ case PRIMITIVETYPE_BYTE:
+ val = ((java_lang_Byte *) value)->value;
+ break;
+ case PRIMITIVETYPE_SHORT:
+ val = ((java_lang_Short *) value)->value;
+ break;
+ default:
+ exceptions_throw_illegalargumentexception();
+ return;
+ }
+
+ *((s4 *) faddr) = val;
+ return;
+ }
+
+ case PRIMITIVETYPE_INT: {
+ s4 val;
+
+ /* get field only by name, it can be one of B, S, C, I */
+
+ if ((sc == NULL) || !(sf = class_findfield_by_name(sc, utf_value)))
+ break;
+
+ switch (sf->parseddesc->decltype) {
+ case PRIMITIVETYPE_BYTE:
+ val = ((java_lang_Byte *) value)->value;
+ break;
+ case PRIMITIVETYPE_CHAR:
+ val = ((java_lang_Character *) value)->value;
+ break;
+ case PRIMITIVETYPE_SHORT:
+ val = ((java_lang_Short *) value)->value;
+ break;
+ case PRIMITIVETYPE_INT:
+ val = ((java_lang_Integer *) value)->value;
+ break;
+ default:
+ exceptions_throw_illegalargumentexception();
+ return;
+ }
+
+ *((s4 *) faddr) = val;
+ return;
+ }
+
+ case PRIMITIVETYPE_LONG: {
+ s8 val;
+
+ /* get field only by name, it can be one of B, S, C, I, J */
+
+ if ((sc == NULL) || !(sf = class_findfield_by_name(sc, utf_value)))
+ break;
+
+ switch (sf->parseddesc->decltype) {
+ case PRIMITIVETYPE_BYTE:
+ val = ((java_lang_Byte *) value)->value;
+ break;
+ case PRIMITIVETYPE_CHAR:
+ val = ((java_lang_Character *) value)->value;
+ break;
+ case PRIMITIVETYPE_SHORT:
+ val = ((java_lang_Short *) value)->value;
+ break;
+ case PRIMITIVETYPE_INT:
+ val = ((java_lang_Integer *) value)->value;
+ break;
+ case PRIMITIVETYPE_LONG:
+ val = ((java_lang_Long *) value)->value;
+ break;
+ default:
+ exceptions_throw_illegalargumentexception();
+ return;
+ }
+
+ *((s8 *) faddr) = val;
+ return;
+ }
+
+ case PRIMITIVETYPE_FLOAT: {
+ float val;
+
+ /* get field only by name, it can be one of B, S, C, I, J, F */
+
+ if ((sc == NULL) || !(sf = class_findfield_by_name(sc, utf_value)))
+ break;
+
+ switch (sf->parseddesc->decltype) {
+ case PRIMITIVETYPE_BYTE:
+ val = ((java_lang_Byte *) value)->value;
+ break;
+ case PRIMITIVETYPE_CHAR:
+ val = ((java_lang_Character *) value)->value;
+ break;
+ case PRIMITIVETYPE_SHORT:
+ val = ((java_lang_Short *) value)->value;
+ break;
+ case PRIMITIVETYPE_INT:
+ val = ((java_lang_Integer *) value)->value;
+ break;
+ case PRIMITIVETYPE_LONG:
+ val = ((java_lang_Long *) value)->value;
+ break;
+ case PRIMITIVETYPE_FLOAT:
+ val = ((java_lang_Float *) value)->value;
+ break;
+ default:
+ exceptions_throw_illegalargumentexception();
+ return;
+ }
+
+ *((float *) faddr) = val;
+ return;
+ }
+
+ case PRIMITIVETYPE_DOUBLE: {
+ double val;
+
+ /* get field only by name, it can be one of B, S, C, I, J, F, D */
+
+ if ((sc == NULL) || !(sf = class_findfield_by_name(sc, utf_value)))
+ break;
+
+ switch (sf->parseddesc->decltype) {
+ case PRIMITIVETYPE_BYTE:
+ val = ((java_lang_Byte *) value)->value;
+ break;
+ case PRIMITIVETYPE_CHAR:
+ val = ((java_lang_Character *) value)->value;
+ break;
+ case PRIMITIVETYPE_SHORT:
+ val = ((java_lang_Short *) value)->value;
+ break;
+ case PRIMITIVETYPE_INT:
+ val = ((java_lang_Integer *) value)->value;
+ break;
+ case PRIMITIVETYPE_LONG:
+ val = ((java_lang_Long *) value)->value;
+ break;
+ case PRIMITIVETYPE_FLOAT:
+ val = ((java_lang_Float *) value)->value;
+ break;
+ case PRIMITIVETYPE_DOUBLE:
+ val = ((java_lang_Double *) value)->value;
+ break;
+ default:
+ exceptions_throw_illegalargumentexception();
+ return;
+ }
+
+ *((double *) faddr) = val;
+ return;
+ }
+
+ case TYPE_ADR:
+ /* check if value is an instance of the destination class */
+
+ /* XXX TODO */
+ /* if (!builtin_instanceof((java_objectheader *) value, df->class)) */
+ /* break; */
+
+ *((java_lang_Object **) faddr) = value;
+ return;
+ }
+
+ /* raise exception */
+
+ exceptions_throw_illegalargumentexception();
+}
+
+
+/*
+ * Class: java/lang/reflect/Field
+ * Method: setBoolean
+ * Signature: (Ljava/lang/Object;Z)V
+ */
+JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setBoolean(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, s4 value)
+{
+ classinfo *c;
+ fieldinfo *f;
+ void *addr;
+
+ /* get the class and the field */
+
+ c = (classinfo *) this->declaringClass;
+ f = &c->fields[this->slot];
+
+ /* get the address of the field with an internal helper */
+
+ if ((addr = cacao_get_field_address(this, o)) == NULL)
+ return;
+
+ /* check the field type and set the value */
+
+ switch (f->parseddesc->decltype) {
+ case PRIMITIVETYPE_BOOLEAN:
+ *((s4 *) addr) = value;
+ break;
+ default:
+ exceptions_throw_illegalargumentexception();
+ }
+
+ return;
+}
+
+
+/*
+ * Class: java/lang/reflect/Field
+ * Method: setByte
+ * Signature: (Ljava/lang/Object;B)V
+ */
+JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setByte(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, s4 value)
+{
+ classinfo *c;
+ fieldinfo *f;
+ void *addr;
+
+ /* get the class and the field */
+
+ c = (classinfo *) this->declaringClass;
+ f = &c->fields[this->slot];
+
+ /* get the address of the field with an internal helper */
+
+ if ((addr = cacao_get_field_address(this, o)) == NULL)
+ return;
+
+ /* check the field type and set the value */
+
+ switch (f->parseddesc->decltype) {
+ case PRIMITIVETYPE_BYTE:
+ case PRIMITIVETYPE_SHORT:
+ case PRIMITIVETYPE_INT:
+ *((s4 *) addr) = value;
+ break;
+ case PRIMITIVETYPE_LONG:
+ *((s8 *) addr) = value;
+ break;
+ case PRIMITIVETYPE_FLOAT:
+ *((float *) addr) = value;
+ break;
+ case PRIMITIVETYPE_DOUBLE:
+ *((double *) addr) = value;
+ break;
+ default:
+ exceptions_throw_illegalargumentexception();
+ }
+
+ return;
+}
+
+
+/*
+ * Class: java/lang/reflect/Field
+ * Method: setChar
+ * Signature: (Ljava/lang/Object;C)V
+ */
+JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setChar(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, s4 value)
+{
+ classinfo *c;
+ fieldinfo *f;
+ void *addr;
+
+ /* get the class and the field */
+
+ c = (classinfo *) this->declaringClass;
+ f = &c->fields[this->slot];
+
+ /* get the address of the field with an internal helper */
+
+ if ((addr = cacao_get_field_address(this, o)) == NULL)
+ return;
+
+ /* check the field type and set the value */
+
+ switch (f->parseddesc->decltype) {
+ case PRIMITIVETYPE_CHAR:
+ case PRIMITIVETYPE_INT:
+ *((s4 *) addr) = value;
+ break;
+ case PRIMITIVETYPE_LONG:
+ *((s8 *) addr) = value;
+ break;
+ case PRIMITIVETYPE_FLOAT:
+ *((float *) addr) = value;
+ break;
+ case PRIMITIVETYPE_DOUBLE:
+ *((double *) addr) = value;
+ break;
+ default:
+ exceptions_throw_illegalargumentexception();
+ }
+
+ return;
+}
+
+
+/*
+ * Class: java/lang/reflect/Field
+ * Method: setShort
+ * Signature: (Ljava/lang/Object;S)V
+ */
+JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setShort(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, s4 value)
+{
+ classinfo *c;
+ fieldinfo *f;
+ void *addr;
+
+ /* get the class and the field */
+
+ c = (classinfo *) this->declaringClass;
+ f = &c->fields[this->slot];
+
+ /* get the address of the field with an internal helper */
+
+ if ((addr = cacao_get_field_address(this, o)) == NULL)
+ return;
+
+ /* check the field type and set the value */
+
+ switch (f->parseddesc->decltype) {
+ case PRIMITIVETYPE_SHORT:
+ case PRIMITIVETYPE_INT:
+ *((s4 *) addr) = value;
+ break;
+ case PRIMITIVETYPE_LONG:
+ *((s8 *) addr) = value;
+ break;
+ case PRIMITIVETYPE_FLOAT:
+ *((float *) addr) = value;
+ break;
+ case PRIMITIVETYPE_DOUBLE:
+ *((double *) addr) = value;
+ break;
+ default:
+ exceptions_throw_illegalargumentexception();
+ }
+
+ return;
+}
+
+
+/*
+ * Class: java/lang/reflect/Field
+ * Method: setInt
+ * Signature: (Ljava/lang/Object;I)V
+ */
+JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setInt(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, s4 value)
+{
+ classinfo *c;
+ fieldinfo *f;
+ void *addr;
+
+ /* get the class and the field */
+
+ c = (classinfo *) this->declaringClass;
+ f = &c->fields[this->slot];
+
+ /* get the address of the field with an internal helper */
+
+ if ((addr = cacao_get_field_address(this, o)) == NULL)
+ return;
+
+ /* check the field type and set the value */
+
+ switch (f->parseddesc->decltype) {
+ case PRIMITIVETYPE_INT:
+ *((s4 *) addr) = value;
+ break;
+ case PRIMITIVETYPE_LONG:
+ *((s8 *) addr) = value;
+ break;
+ case PRIMITIVETYPE_FLOAT:
+ *((float *) addr) = value;
+ break;
+ case PRIMITIVETYPE_DOUBLE:
+ *((double *) addr) = value;
+ break;
+ default:
+ exceptions_throw_illegalargumentexception();
+ }
+
+ return;
+}
+
+
+/*
+ * Class: java/lang/reflect/Field
+ * Method: setLong
+ * Signature: (Ljava/lang/Object;J)V
+ */
+JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setLong(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, s8 value)
+{
+ classinfo *c;
+ fieldinfo *f;
+ void *addr;
+
+ /* get the class and the field */
+
+ c = (classinfo *) this->declaringClass;
+ f = &c->fields[this->slot];
+
+ /* get the address of the field with an internal helper */
+
+ if ((addr = cacao_get_field_address(this, o)) == NULL)
+ return;
+
+ /* check the field type and set the value */
+
+ switch (f->parseddesc->decltype) {
+ case PRIMITIVETYPE_LONG:
+ *((s8 *) addr) = value;
+ break;
+ case PRIMITIVETYPE_FLOAT:
+ *((float *) addr) = value;
+ break;
+ case PRIMITIVETYPE_DOUBLE:
+ *((double *) addr) = value;
+ break;
+ default:
+ exceptions_throw_illegalargumentexception();
+ }
+
+ return;
+}
+
+
+/*
+ * Class: java/lang/reflect/Field
+ * Method: setFloat
+ * Signature: (Ljava/lang/Object;F)V
+ */
+JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setFloat(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, float value)
+{
+ classinfo *c;
+ fieldinfo *f;
+ void *addr;
+
+ /* get the class and the field */
+
+ c = (classinfo *) this->declaringClass;
+ f = &c->fields[this->slot];
+
+ /* get the address of the field with an internal helper */
+
+ if ((addr = cacao_get_field_address(this, o)) == NULL)
+ return;
+
+ /* check the field type and set the value */
+
+ switch (f->parseddesc->decltype) {
+ case PRIMITIVETYPE_FLOAT:
+ *((float *) addr) = value;
+ break;
+ case PRIMITIVETYPE_DOUBLE:
+ *((double *) addr) = value;
+ break;
+ default:
+ exceptions_throw_illegalargumentexception();
+ }
+
+ return;
+}
+
+
+/*
+ * Class: java/lang/reflect/Field
+ * Method: setDouble
+ * Signature: (Ljava/lang/Object;D)V
+ */
+JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setDouble(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, double value)
+{
+ classinfo *c;
+ fieldinfo *f;
+ void *addr;
+
+ /* get the class and the field */
+
+ c = (classinfo *) this->declaringClass;
+ f = &c->fields[this->slot];
+
+ /* get the address of the field with an internal helper */
+
+ if ((addr = cacao_get_field_address(this, o)) == NULL)
+ return;
+
+ /* check the field type and set the value */
+
+ switch (f->parseddesc->decltype) {
+ case PRIMITIVETYPE_DOUBLE:
+ *((double *) addr) = value;
+ break;
+ default:
+ exceptions_throw_illegalargumentexception();
+ }
+
+ return;
+}
+
+
+/*
+ * Class: java/lang/reflect/Field
+ * Method: getType
+ * Signature: ()Ljava/lang/Class;
+ */
+JNIEXPORT java_lang_Class* JNICALL Java_java_lang_reflect_Field_getType(JNIEnv *env, java_lang_reflect_Field *this)
+{
+ classinfo *c;
+ typedesc *desc;
+ classinfo *ret;
+
+ c = (classinfo *) this->declaringClass;
+ desc = c->fields[this->slot].parseddesc;
+
+ if (!desc)
+ return NULL;
+
+ if (!resolve_class_from_typedesc(desc, true, false, &ret))
+ return NULL;
+
+ return (java_lang_Class *) ret;
+}
+
+
+/*
+ * Class: java/lang/reflect/Field
+ * Method: getModifiersInternal
+ * Signature: ()I
+ */
+JNIEXPORT s4 JNICALL Java_java_lang_reflect_Field_getModifiersInternal(JNIEnv *env, java_lang_reflect_Field *this)
+{
+ classinfo *c;
+ fieldinfo *f;
+
+ c = (classinfo *) this->declaringClass;
+ f = &(c->fields[this->slot]);
+
+ return f->flags;
+}
+
+
+/*
+ * These are local overrides for various environment variables in Emacs.
+ * Please do not remove this and leave it at the end of the file, where
+ * Emacs will automagically detect them.
+ * ---------------------------------------------------------------------
+ * Local variables:
+ * mode: c
+ * indent-tabs-mode: t
+ * c-basic-offset: 4
+ * tab-width: 4
+ * End:
+ */
--- /dev/null
+/* src/native/vm/Method.c - java/lang/reflect/Method
+
+ Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
+ C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
+ E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
+ J. Wenninger, Institut f. Computersprachen - TU Wien
+
+ This file is part of CACAO.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA.
+
+ Contact: cacao@cacaojvm.org
+
+ Authors: Roman Obermaiser
+
+ Changes: Joseph Wenninger
+ Christian Thalinger
+
+ $Id: java_lang_reflect_Method.c 5153 2006-07-18 08:19:24Z twisti $
+
+*/
+
+
+#include "config.h"
+
+#include <assert.h>
+
+#include "vm/types.h"
+
+#include "native/jni.h"
+#include "native/native.h"
+#include "native/include/java_lang_Object.h"
+#include "native/include/java_lang_Class.h"
+#include "native/include/java_lang_reflect_Method.h"
+#include "vm/access.h"
+#include "vm/global.h"
+#include "vm/builtin.h"
+#include "vm/exceptions.h"
+#include "vm/initialize.h"
+#include "vm/stringlocal.h"
+
+
+/*
+ * Class: java/lang/reflect/Method
+ * Method: getModifiersInternal
+ * Signature: ()I
+ */
+JNIEXPORT s4 JNICALL Java_java_lang_reflect_Method_getModifiersInternal(JNIEnv *env, java_lang_reflect_Method *this)
+{
+ classinfo *c;
+ methodinfo *m;
+
+ c = (classinfo *) this->declaringClass;
+ m = &(c->methods[this->slot]);
+
+ return m->flags;
+}
+
+
+/*
+ * Class: java/lang/reflect/Method
+ * Method: getReturnType
+ * Signature: ()Ljava/lang/Class;
+ */
+JNIEXPORT java_lang_Class* JNICALL Java_java_lang_reflect_Method_getReturnType(JNIEnv *env, java_lang_reflect_Method *this)
+{
+ classinfo *c;
+ methodinfo *m;
+
+ c = (classinfo *) this->declaringClass;
+ m = &(c->methods[this->slot]);
+
+ return (java_lang_Class *) native_get_returntype(m);
+}
+
+
+/*
+ * Class: java/lang/reflect/Method
+ * Method: getParameterTypes
+ * Signature: ()[Ljava/lang/Class;
+ */
+JNIEXPORT java_objectarray* JNICALL Java_java_lang_reflect_Method_getParameterTypes(JNIEnv *env, java_lang_reflect_Method *this)
+{
+ classinfo *c;
+ methodinfo *m;
+
+ c = (classinfo *) this->declaringClass;
+ m = &(c->methods[this->slot]);
+
+ return native_get_parametertypes(m);
+}
+
+
+/*
+ * Class: java/lang/reflect/Method
+ * Method: getExceptionTypes
+ * Signature: ()[Ljava/lang/Class;
+ */
+JNIEXPORT java_objectarray* JNICALL Java_java_lang_reflect_Method_getExceptionTypes(JNIEnv *env, java_lang_reflect_Method *this)
+{
+ classinfo *c;
+ methodinfo *m;
+
+ c = (classinfo *) this->declaringClass;
+ m = &(c->methods[this->slot]);
+
+ return native_get_exceptiontypes(m);
+}
+
+
+/*
+ * Class: java/lang/reflect/Method
+ * Method: invokeNative
+ * Signature: (Ljava/lang/Object;[Ljava/lang/Object;Ljava/lang/Class;I)Ljava/lang/Object;
+ */
+JNIEXPORT java_lang_Object* JNICALL Java_java_lang_reflect_Method_invokeNative(JNIEnv *env, java_lang_reflect_Method *this, java_lang_Object *o, java_objectarray *args, java_lang_Class *declaringClass, s4 slot)
+{
+ classinfo *c;
+ methodinfo *m;
+ java_objectarray *oa;
+ classinfo *callerclass;
+
+ c = (classinfo *) declaringClass;
+ m = &(c->methods[slot]);
+
+ /* check method access */
+
+ if (!(m->flags & ACC_PUBLIC) || !(c->flags & ACC_PUBLIC)) {
+ /* check if we should bypass security checks (AccessibleObject) */
+
+ if (this->flag == false) {
+ /* get the calling class */
+
+ oa = stacktrace_getClassContext();
+ if (!oa)
+ return NULL;
+
+ /* this function is always called like this:
+
+ java.lang.reflect.Method.invokeNative (Native Method)
+ [0] java.lang.reflect.Method.invoke (Method.java:329)
+ [1] <caller>
+ */
+
+ callerclass = (classinfo *) oa->data[1];
+
+ if (!access_is_accessible_class(callerclass,c)
+ || !access_is_accessible_member(callerclass, c, m->flags))
+ {
+ *exceptionptr =
+ new_exception(string_java_lang_IllegalAccessException);
+ return NULL;
+ }
+ }
+ }
+
+ /* check if method class is initialized */
+
+ if (!(c->state & CLASS_INITIALIZED))
+ if (!initialize_class(c))
+ return NULL;
+
+ /* call the Java method via a helper function */
+
+ return (java_lang_Object *) _Jv_jni_invokeNative(m, (jobject) o, args);
+}
+
+
+/*
+ * These are local overrides for various environment variables in Emacs.
+ * Please do not remove this and leave it at the end of the file, where
+ * Emacs will automagically detect them.
+ * ---------------------------------------------------------------------
+ * Local variables:
+ * mode: c
+ * indent-tabs-mode: t
+ * c-basic-offset: 4
+ * tab-width: 4
+ * End:
+ */
--- /dev/null
+/* src/native/vm/VMProxy.c - java/lang/reflect/VMProxy
+
+ Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
+ C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
+ E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
+ J. Wenninger, Institut f. Computersprachen - TU Wien
+
+ This file is part of CACAO.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA.
+
+ Contact: cacao@cacaojvm.org
+
+ Authors: Roman Obermaiser
+
+ Changes: Joseph Wenninger
+ Christian Thalinger
+
+ $Id: java_lang_reflect_VMProxy.c 5153 2006-07-18 08:19:24Z twisti $
+
+*/
+
+
+#include <stdlib.h>
+
+#include "native/jni.h"
+#include "native/include/java_lang_Class.h"
+#include "native/include/java_lang_ClassLoader.h"
+#include "toolbox/logging.h"
+
+
+/*
+ * Class: java/lang/reflect/VMProxy
+ * Method: getProxyClass
+ * Signature: (Ljava/lang/ClassLoader;[Ljava/lang/Class;)Ljava/lang/Class;
+ */
+JNIEXPORT java_lang_Class* JNICALL Java_java_lang_reflect_VMProxy_getProxyClass(JNIEnv *env, jclass clazz, java_lang_ClassLoader *par1, java_objectarray *par2)
+{
+ log_text("Java_java_lang_reflect_Proxy_getProxyClass: IMPLEMENT ME!");
+
+ return NULL;
+}
+
+
+/*
+ * Class: java/lang/reflect/VMProxy
+ * Method: getProxyData
+ * Signature: (Ljava/lang/ClassLoader;[Ljava/lang/Class;)Ljava/lang/reflect/Proxy$ProxyData;
+ */
+JNIEXPORT struct java_lang_reflect_Proxy_ProxyData* JNICALL Java_java_lang_reflect_VMProxy_getProxyData(JNIEnv *env, jclass clazz, java_lang_ClassLoader *par1, java_objectarray *par2)
+{
+ log_text("Java_java_lang_reflect_Proxy_getProxyData: IMPLEMENT ME!");
+
+ return NULL;
+}
+
+
+/*
+ * Class: java/lang/reflect/VMProxy
+ * Method: generateProxyClass
+ * Signature: (Ljava/lang/ClassLoader;Ljava/lang/reflect/Proxy$ProxyData;)Ljava/lang/Class;
+ */
+JNIEXPORT java_lang_Class* JNICALL Java_java_lang_reflect_VMProxy_generateProxyClass(JNIEnv *env, jclass clazz, java_lang_ClassLoader *par1, struct java_lang_reflect_Proxy_ProxyData *par2)
+{
+ log_text("Java_java_lang_reflect_Proxy_generateProxyClass: IMPLEMENT ME!");
+
+ return NULL;
+}
+
+
+/*
+ * These are local overrides for various environment variables in Emacs.
+ * Please do not remove this and leave it at the end of the file, where
+ * Emacs will automagically detect them.
+ * ---------------------------------------------------------------------
+ * Local variables:
+ * mode: c
+ * indent-tabs-mode: t
+ * c-basic-offset: 4
+ * tab-width: 4
+ * End:
+ */
--- /dev/null
+/* src/native/vm/VMAccessController.c - java/security/VMAccessController
+
+ Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
+ C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
+ E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
+ J. Wenninger, Institut f. Computersprachen - TU Wien
+
+ This file is part of CACAO.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA.
+
+ Contact: cacao@cacaojvm.org
+
+ Authors: Joseph Wenninger
+
+ Changes: Christian Thalinger
+
+ $Id: java_security_VMAccessController.c 5153 2006-07-18 08:19:24Z twisti $
+
+*/
+
+
+#include "config.h"
+#include "vm/types.h"
+
+#include "native/jni.h"
+#include "vm/builtin.h"
+#include "vm/class.h"
+#include "vm/options.h"
+#include "vm/jit/stacktrace.h"
+
+
+/*
+ * Class: java/security/VMAccessController
+ * Method: getStack
+ * Signature: ()[[Ljava/lang/Object;
+ */
+JNIEXPORT java_objectarray* JNICALL Java_java_security_VMAccessController_getStack(JNIEnv *env, jclass clazz) {
+#if defined(__ALPHA__) || defined(__ARM__) || defined(__I386__) || defined(__MIPS__) || defined(__POWERPC__) || defined (__X86_64__)
+ /* these JITs support stacktraces */
+
+ return stacktrace_getStack();
+
+#else
+# if defined(ENABLE_INTRP)
+ /* the interpreter supports stacktraces, even if the JIT does not */
+
+ if (opt_intrp) {
+ return stacktrace_getStack();
+
+ } else
+# endif
+ {
+ java_objectarray *result;
+ java_objectarray *classes;
+ java_objectarray *methodnames;
+
+ if (!(result = builtin_anewarray(2, arrayclass_java_lang_Object)))
+ return NULL;
+
+ if (!(classes = builtin_anewarray(0, class_java_lang_Class)))
+ return NULL;
+
+ if (!(methodnames = builtin_anewarray(0, class_java_lang_String)))
+ return NULL;
+
+ result->data[0] = (java_objectheader *) classes;
+ result->data[1] = (java_objectheader *) methodnames;
+
+ return result;
+ }
+#endif
+}
+
+
+/*
+ * These are local overrides for various environment variables in Emacs.
+ * Please do not remove this and leave it at the end of the file, where
+ * Emacs will automagically detect them.
+ * ---------------------------------------------------------------------
+ * Local variables:
+ * mode: c
+ * indent-tabs-mode: t
+ * c-basic-offset: 4
+ * tab-width: 4
+ * End:
+ */