From 345ceab5946711a40fdeefb55a0cf469960146d0 Mon Sep 17 00:00:00 2001 From: Christian Thalinger Date: Fri, 1 Aug 2008 14:46:18 +0200 Subject: [PATCH] This commit introduces C++ wrapper classes for Java heap objects. These classes will replace all LLNI macros. This commit also removes cacaoh and the need to have vmcore/ and vm/ seperated. But the merge of these two directories will be another commit. Currently working only for GNU Classpath. --HG-- branch : twisti rename : src/native/vm/reflect.h => src/native/vm/reflection.hpp --- configure.ac | 2 - doc/doxygen/Makefile.am | 2 +- m4/cacaoh.m4 | 34 - src/Makefile.am | 10 +- src/cacaoh/Makefile.am | 66 - src/cacaoh/cacaoh.c | 366 ---- src/cacaoh/dummy.cpp | 875 --------- src/cacaoh/headers.c | 508 ----- src/native/Makefile.am | 1 - src/native/include/Makefile.am | 126 +- src/native/jni.cpp | 444 ++--- src/native/llni.h | 2 +- src/native/vm/Makefile.am | 8 +- .../gnu_classpath_VMStackWalker.cpp | 26 +- .../gnu_classpath_VMSystemProperties.cpp | 13 +- .../gnu_java_lang_VMCPStringBuilder.cpp | 29 +- ...ng_management_VMClassLoadingMXBeanImpl.cpp | 15 +- ...ava_lang_management_VMMemoryMXBeanImpl.cpp | 40 +- ...va_lang_management_VMRuntimeMXBeanImpl.cpp | 7 +- ...ava_lang_management_VMThreadMXBeanImpl.cpp | 26 +- .../vm/gnuclasspath/java_lang_VMClass.cpp | 246 ++- .../gnuclasspath/java_lang_VMClassLoader.cpp | 74 +- .../vm/gnuclasspath/java_lang_VMObject.cpp | 25 +- .../vm/gnuclasspath/java_lang_VMRuntime.cpp | 33 +- .../vm/gnuclasspath/java_lang_VMString.cpp | 13 +- .../vm/gnuclasspath/java_lang_VMSystem.cpp | 16 +- .../vm/gnuclasspath/java_lang_VMThread.cpp | 55 +- .../vm/gnuclasspath/java_lang_VMThrowable.cpp | 150 +- ...java_lang_management_VMManagementFactory.c | 59 +- .../java_lang_reflect_VMConstructor.cpp | 206 +- .../java_lang_reflect_VMField.cpp | 687 +++---- .../java_lang_reflect_VMMethod.cpp | 282 +-- .../gnuclasspath/java_lang_reflect_VMProxy.c | 14 +- .../java_security_VMAccessController.cpp | 11 +- ...java_util_concurrent_atomic_AtomicLong.cpp | 14 +- .../gnuclasspath/sun_reflect_ConstantPool.cpp | 124 +- src/native/vm/reflect.c | 692 ------- src/native/vm/reflect.h | 103 - src/native/vm/reflection.cpp | 327 ++++ .../headers.h => native/vm/reflection.hpp} | 50 +- src/native/vm/sun_misc_Unsafe.cpp | 214 +- src/threads/posix/thread-posix.cpp | 141 +- src/threads/thread.cpp | 148 +- src/vm/exceptions.cpp | 88 +- src/vm/jit/codegen-common.c | 13 - src/vm/jit/stacktrace.cpp | 37 +- src/vm/jit/trace.cpp | 48 +- src/vm/jit/trace.hpp | 15 +- src/vm/package.cpp | 2 - src/vm/primitive.cpp | 229 ++- src/vm/properties.c | 7 +- src/vm/string.cpp | 293 ++- src/vm/vm.cpp | 15 +- src/vmcore/Makefile.am | 8 +- src/vmcore/class.c | 41 +- src/vmcore/javaobjects.cpp | 290 +++ src/vmcore/javaobjects.hpp | 1723 +++++++++++++++++ src/vmcore/linker.c | 67 - 58 files changed, 4008 insertions(+), 5152 deletions(-) delete mode 100644 m4/cacaoh.m4 delete mode 100644 src/cacaoh/Makefile.am delete mode 100644 src/cacaoh/cacaoh.c delete mode 100644 src/cacaoh/dummy.cpp delete mode 100644 src/cacaoh/headers.c delete mode 100644 src/native/vm/reflect.c delete mode 100644 src/native/vm/reflect.h create mode 100644 src/native/vm/reflection.cpp rename src/{cacaoh/headers.h => native/vm/reflection.hpp} (53%) create mode 100644 src/vmcore/javaobjects.cpp create mode 100644 src/vmcore/javaobjects.hpp diff --git a/configure.ac b/configure.ac index e5e0e821f..e50b39d12 100644 --- a/configure.ac +++ b/configure.ac @@ -549,7 +549,6 @@ AC_DEFINE_UNQUOTED([CACAO_VM_ZIP], "${CACAO_VM_ZIP}", [CACAO's vm.zip]) AC_SUBST(CACAO_VM_ZIP) -AC_CHECK_WITH_CACAOH AC_CHECK_WITH_JAVA_RUNTIME_LIBRARY dnl Now we check for jre-layout so we can skip some checks that are @@ -653,7 +652,6 @@ AC_CONFIG_FILES([Makefile] [man/Makefile] [src/Makefile] [src/cacao/Makefile] - [src/cacaoh/Makefile] [src/classes/Makefile] [src/fdlibm/Makefile] [src/mm/Makefile] diff --git a/doc/doxygen/Makefile.am b/doc/doxygen/Makefile.am index c75bf12b8..2ea19e9a5 100644 --- a/doc/doxygen/Makefile.am +++ b/doc/doxygen/Makefile.am @@ -25,7 +25,7 @@ dist_noinst_DATA = \ Doxyfile doxygen: - doxygen + doxygen $(srcdir)/Doxyfile clean-local: -rm -rf html latex diff --git a/m4/cacaoh.m4 b/m4/cacaoh.m4 deleted file mode 100644 index 1c19667e8..000000000 --- a/m4/cacaoh.m4 +++ /dev/null @@ -1,34 +0,0 @@ -dnl m4/cacaoh.m4 -dnl -dnl Copyright (C) 2007, 2008 -dnl CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO -dnl -dnl This file is part of CACAO. -dnl -dnl This program is free software; you can redistribute it and/or -dnl modify it under the terms of the GNU General Public License as -dnl published by the Free Software Foundation; either version 2, or (at -dnl your option) any later version. -dnl -dnl This program is distributed in the hope that it will be useful, but -dnl WITHOUT ANY WARRANTY; without even the implied warranty of -dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -dnl General Public License for more details. -dnl -dnl You should have received a copy of the GNU General Public License -dnl along with this program; if not, write to the Free Software -dnl Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -dnl 02110-1301, USA. - - -dnl check which cacaoh to use - -AC_DEFUN([AC_CHECK_WITH_CACAOH],[ -AC_MSG_CHECKING(which cacaoh to use (for crosscompilation)) -AC_ARG_WITH([cacaoh], - [AS_HELP_STRING(--with-cacaoh,which cacaoh to use [[default=$(top_builddir)/src/cacaoh/cacaoh]])], - [CACAOH="${withval}"], - [CACAOH=["\$(top_builddir)/src/cacaoh/cacaoh"]]) -AC_MSG_RESULT(${CACAOH}) -AC_SUBST(CACAOH) -]) diff --git a/src/Makefile.am b/src/Makefile.am index b2cb8bf2a..5cab68ae8 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -23,7 +23,6 @@ DIST_SUBDIRS = \ cacao \ - cacaoh \ classes \ fdlibm \ mm \ @@ -37,15 +36,14 @@ DIST_SUBDIRS = \ # DON'T CHANGE THIS ORDER!!! SUBDIRS = \ - toolbox \ - vmcore \ - cacaoh \ classes \ - native \ fdlibm \ + toolbox \ mm \ - threads \ + vmcore \ vm \ + threads \ + native \ cacao \ scripts diff --git a/src/cacaoh/Makefile.am b/src/cacaoh/Makefile.am deleted file mode 100644 index 042e5a9e1..000000000 --- a/src/cacaoh/Makefile.am +++ /dev/null @@ -1,66 +0,0 @@ -## src/cacaoh/Makefile.am -## -## Copyright (C) 1996-2005, 2006, 2007, 2008 -## CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO -## -## 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. - - -AM_CPPFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/src/vm/jit/$(ARCH_DIR) -I$(top_srcdir)/src/vm/jit/$(ARCH_DIR)/$(OS_DIR) - -if ENABLE_RT_TIMING -cacaoh_LDFLAGS = -lrt -endif - -noinst_LTLIBRARIES = \ - libcacaoh.la - -libcacaoh_la_SOURCES = \ - dummy.cpp \ - headers.c \ - headers.h - -libcacaoh_la_LIBADD = \ - $(top_builddir)/src/toolbox/libtoolbox.la \ - $(top_builddir)/src/vmcore/libvmcore.la - -noinst_PROGRAMS = \ - cacaoh - -cacaoh_SOURCES = \ - cacaoh.c - -# Dummy C++ source to cause C++ linking. -# http://www.gnu.org/software/automake/manual/automake.html#Libtool-Convenience-Libraries -nodist_EXTRA_cacaoh_SOURCES = \ - foo.cxx - -cacaoh_LDADD = \ - libcacaoh.la - -cacaoh_DEPENDENCIES = \ - $(cacaoh_LDADD) - - -## Local variables: -## mode: Makefile -## indent-tabs-mode: t -## c-basic-offset: 4 -## tab-width: 8 -## compile-command: "automake --add-missing" -## End: diff --git a/src/cacaoh/cacaoh.c b/src/cacaoh/cacaoh.c deleted file mode 100644 index bd7d38cb9..000000000 --- a/src/cacaoh/cacaoh.c +++ /dev/null @@ -1,366 +0,0 @@ -/* src/cacaoh/cacaoh.c - main for header generation (cacaoh) - - Copyright (C) 1996-2005, 2006, 2007, 2008 - CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO - - 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. - -*/ - - -#include "config.h" - -#include -#include -#include - -#include "vm/types.h" - -#include "cacaoh/headers.h" - -#include "mm/gc.hpp" -#include "mm/memory.h" - -#include "toolbox/hashtable.h" -#include "toolbox/logging.h" - -#include "vm/global.h" -#include "vm/string.hpp" -#include "vm/vm.hpp" - -#include "vmcore/classcache.h" -#include "vmcore/loader.h" -#include "vmcore/options.h" -#include "vmcore/statistics.h" -#include "vmcore/suck.h" - - -/* define cacaoh options ******************************************************/ - -enum { - OPT_HELP, - OPT_VERSION, - OPT_VERBOSE, - OPT_DIRECTORY, - OPT_CLASSPATH, - OPT_BOOTCLASSPATH, - - DUMMY -}; - - -opt_struct opts[] = { - { "help", false, OPT_HELP }, - { "version", false, OPT_VERSION }, - { "verbose", false, OPT_VERBOSE }, - { "d", true, OPT_DIRECTORY }, - { "classpath", true, OPT_CLASSPATH }, - { "bootclasspath", true, OPT_BOOTCLASSPATH }, - { NULL, false, 0 } -}; - - -/* usage *********************************************************************** - - Obviously prints usage information of cacaoh. - -*******************************************************************************/ - -void usage(void) -{ - printf("Usage: cacaoh [options] \n" - "\n" - "Options:\n" - " -help Print this message\n" - " -classpath \n" - " -bootclasspath \n" - " -d Output directory\n" - " -version Print version information\n" - " -verbose Enable verbose output\n"); - - /* exit with error code */ - - exit(1); -} - - -/* version ********************************************************************* - - Prints cacaoh version information. - -*******************************************************************************/ - -static void version(void) -{ - printf("cacaoh version "VERSION"\n"); - printf("Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,\n"); - printf("C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,\n"); - printf("E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,\n"); - printf("J. Wenninger, Institut f. Computersprachen - TU Wien\n\n"); - - printf("This program is free software; you can redistribute it and/or\n"); - printf("modify it under the terms of the GNU General Public License as\n"); - printf("published by the Free Software Foundation; either version 2, or (at\n"); - printf("your option) any later version.\n\n"); - - printf("This program is distributed in the hope that it will be useful, but\n"); - printf("WITHOUT ANY WARRANTY; without even the implied warranty of\n"); - printf("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n"); - printf("General Public License for more details.\n"); - - exit(0); -} - - -/* forward declarations *******************************************************/ - -static JavaVMInitArgs *cacaoh_options_prepare(int argc, char **argv); - - -/* main ************************************************************************ - - Main program. - -*******************************************************************************/ - -int main(int argc, char **argv) -{ - JavaVMInitArgs *vm_args; - s4 i, j; - s4 opt; - classinfo *c; - char *opt_directory; - - /********** internal (only used by main) *****************************/ - - char *bootclasspath; - char *classpath; - char *cp; - s4 cplen; - - if (argc < 2) - usage(); - - /* set the bootclasspath */ - - cp = getenv("BOOTCLASSPATH"); - - if (cp) { - bootclasspath = MNEW(char, strlen(cp) + strlen("0")); - strcpy(bootclasspath, cp); - } - else { - cplen = -#if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH) - strlen(CACAO_VM_ZIP) + - strlen(":") + -#endif - strlen(JAVA_RUNTIME_LIBRARY_CLASSES) + - strlen("0"); - - bootclasspath = MNEW(char, cplen); -#if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH) - strcat(bootclasspath, CACAO_VM_ZIP); - strcat(bootclasspath, ":"); -#endif - strcat(bootclasspath, JAVA_RUNTIME_LIBRARY_CLASSES); - } - - - /* set the classpath */ - - cp = getenv("CLASSPATH"); - - if (cp != NULL) { - classpath = MNEW(char, strlen(cp) + strlen("0")); - strcat(classpath, cp); - } - else { - classpath = MNEW(char, strlen(".") + strlen("0")); - strcpy(classpath, "."); - } - - - /* initialize options with default values */ - - opt_verbose = false; - opt_directory = NULL; - - - /* parse the options ******************************************************/ - - vm_args = cacaoh_options_prepare(argc, argv); - - while ((opt = options_get(opts, vm_args)) != OPT_DONE) { - switch (opt) { - case OPT_IGNORE: - break; - - case OPT_HELP: - usage(); - break; - - case OPT_CLASSPATH: - /* forget old classpath and set the argument as new classpath */ - MFREE(classpath, char, strlen(classpath)); - - classpath = MNEW(char, strlen(opt_arg) + strlen("0")); - strcpy(classpath, opt_arg); - break; - - case OPT_BOOTCLASSPATH: - /* Forget default bootclasspath and set the argument as - new boot classpath. */ - MFREE(bootclasspath, char, strlen(bootclasspath)); - - bootclasspath = MNEW(char, strlen(opt_arg) + strlen("0")); - strcpy(bootclasspath, opt_arg); - break; - - case OPT_DIRECTORY: - opt_directory = MNEW(char, strlen(opt_arg) + strlen("0")); - strcpy(opt_directory, opt_arg); - break; - - case OPT_VERSION: - version(); - break; - - case OPT_VERBOSE: - opt_verbose = true; - loadverbose = true; - break; - - default: - usage(); - } - } - - /**************************** Program start **************************/ - - if (opt_verbose) { - log_init(NULL); - log_println("Java - header-generator started"); - } - - utf8_init(); - - /* initialize the classcache hashtable stuff: lock, hashtable - (must be done _after_ threads_preinit) */ - - if (!classcache_init()) - vm_abort("classcache_init failed\n"); - - /* initialize the loader with bootclasspath (must be done _after_ - thread_preinit) */ - - if (!suck_init()) - vm_abort("suck_init failed\n"); - - suck_add(bootclasspath); - - /* Also add the normal classpath, so the bootstrap class loader - can find the files. */ - - suck_add(classpath); - - /* AFTER: classcache_init */ - - loader_preinit(); - loader_init(); - - - /* load Java classes ******************************************************/ - - for (i = opt_index; i < vm_args->nOptions; i++) { - cp = vm_args->options[i].optionString; - - /* convert classname */ - - for (j = strlen(cp) - 1; j >= 0; j--) { - switch (cp[j]) { - case '.': - cp[j] = '/'; - break; - case '_': - cp[j] = '$'; - break; - } - } - - /* exceptions are catched with new_exception call */ - - if (!(c = load_class_bootstrap(utf_new_char(cp)))) - vm_abort("java.lang.NoClassDefFoundError: %s\n", cp); - - if (!link_class(c)) - vm_abort("java.lang.LinkageError: %s\n", cp); - - headerfile_generate(c, opt_directory); - } - - /************************ Release all resources **********************/ - - loader_close(); - - if (opt_verbose) { - log_println("Java - header-generator stopped"); -#if defined(ENABLE_STATISTICS) - statistics_print_memory_usage(); -#endif - } - - return 0; -} - - -/* cacaoh_options_prepare ****************************************************** - - Prepare the JavaVMInitArgs. - -*******************************************************************************/ - -static JavaVMInitArgs *cacaoh_options_prepare(int argc, char **argv) -{ - JavaVMInitArgs *vm_args; - s4 i; - - vm_args = NEW(JavaVMInitArgs); - - vm_args->nOptions = argc - 1; - vm_args->options = MNEW(JavaVMOption, argc); - - for (i = 1; i < argc; i++) - vm_args->options[i - 1].optionString = argv[i]; - - return vm_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: - */ diff --git a/src/cacaoh/dummy.cpp b/src/cacaoh/dummy.cpp deleted file mode 100644 index aba4772b1..000000000 --- a/src/cacaoh/dummy.cpp +++ /dev/null @@ -1,875 +0,0 @@ -/* src/cacaoh/dummy.cpp - dummy functions for cacaoh - - Copyright (C) 2007, 2008 - CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO - - 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. - -*/ - - -#include "config.h" - -#include -#include -#include -#include -#include -#include - -#include "mm/gc.hpp" -#include "mm/memory.h" - -#include "native/llni.h" - -#include "toolbox/logging.h" - -#include "vm/exceptions.hpp" -#include "vm/global.h" -#include "vm/primitive.hpp" -#include "vm/vm.hpp" - -#include "vm/jit/code.h" - -#include "vmcore/class.h" -#include "vmcore/classcache.h" -#include "vmcore/field.h" -#include "vmcore/loader.h" -#include "vmcore/method.h" -#include "vmcore/utf8.h" -#include "vmcore/os.hpp" - - -// Below this line are C exports. -extern "C" { - -/* global variables ***********************************************************/ - -bool vm_initializing = true; -char *_Jv_bootclasspath; - - -java_handle_t *javastring_new_slash_to_dot(utf *u) -{ - vm_abort("javastring_new_slash_to_dot"); - - return NULL; -} - - -/* access *********************************************************************/ - -bool access_is_accessible_class(classinfo *referer, classinfo *cls) -{ - return true; -} - -bool access_is_accessible_member(classinfo *referer, classinfo *declarer, - int32_t memberflags) -{ - vm_abort("access_is_accessible_member"); - - return true; -} - - -/* array **********************************************************************/ - -java_handle_t *array_objectarray_element_get(java_handle_objectarray_t *a, int32_t index) -{ - java_handle_t *value; - int32_t size; - - if (a == NULL) { - log_println("array_objectarray_element_get(a=%p, index=%d): NullPointerException", a, index); - return NULL; - } - - size = LLNI_array_size(a); - - if ((index < 0) || (index > size)) { - log_println("array_objectarray_element_get(a=%p, index=%d): ArrayIndexOutOfBoundsException", a, index); - return NULL; - } - - value = LLNI_WRAP(LLNI_array_direct(a, index)); - - return value; -} - -void array_objectarray_element_set(java_handle_objectarray_t *a, int32_t index, java_handle_t *value) -{ - int32_t size; - - if (a == NULL) { - log_println("array_objectarray_element_set(a=%p, index=%d): NullPointerException", a, index); - return; - } - - size = LLNI_array_size(a); - - if ((index < 0) || (index > size)) { - log_println("array_objectarray_element_set(a=%p, index=%d): ArrayIndexOutOfBoundsException", a, index); - return; - } - - LLNI_array_direct(a, index) = LLNI_UNWRAP(value); -} - -int32_t array_length_get(java_handle_t *a) -{ - if (a == NULL) { - log_println("array_length_get(a=%p): NullPointerException", a); - return 0; - } - - return LLNI_array_size(a); -} - - -/* asm ************************************************************************/ - -void asm_abstractmethoderror(void) -{ - abort(); -} - -void intrp_asm_abstractmethoderror(void) -{ - abort(); -} - - -/* builtin ********************************************************************/ - -java_handle_t *builtin_clone(void *env, java_handle_t *o) -{ - vm_abort("builtin_clone: Not implemented."); - return NULL; -} - -bool builtin_isanysubclass(classinfo *sub, classinfo *super) -{ - vm_abort("builtin_isanysubclass: Not implemented."); - return 0; -} - -bool builtin_instanceof(java_handle_t *o, classinfo *c) -{ - vm_abort("builtin_instanceof: Not implemented."); - return 0; -} - -java_handle_t *builtin_new(classinfo *c) -{ - vm_abort("builtin_new: Not implemented."); - return NULL; -} - -java_handle_objectarray_t *builtin_anewarray(int32_t size, classinfo *componentclass) -{ - java_objectarray_t *oa = (java_objectarray_t*) mem_alloc( - sizeof(java_array_t) + size * sizeof(java_object_t*)); - java_handle_objectarray_t *h = (java_handle_objectarray_t*) LLNI_WRAP( - (java_object_t*) oa); - - if (h != NULL) { - LLNI_array_size(h) = size; - } - - return h; -} - -java_handle_bytearray_t *builtin_newarray_byte(int32_t size) -{ - java_bytearray_t *ba = (java_bytearray_t*) mem_alloc( - sizeof(java_array_t) + size * sizeof(int8_t)); - java_handle_bytearray_t *h = (java_handle_bytearray_t*) LLNI_WRAP( - (java_object_t*) ba); - - if (h != NULL) { - LLNI_array_size(h) = size; - } - - return h; -} - - -/* code ***********************************************************************/ - -void code_free_code_of_method(methodinfo *m) -{ -} - - -methodinfo *code_get_methodinfo_for_pv(void *pv) -{ - return NULL; -} - - -/* codegen ********************************************************************/ - -u1 *codegen_generate_stub_compiler(methodinfo *m) -{ - return NULL; -} - -codeinfo *codegen_generate_stub_native(methodinfo *m, functionptr f) -{ - return NULL; -} - -#if defined(ENABLE_INTRP) -u1 *intrp_createcompilerstub(methodinfo *m) -{ - return NULL; -} -#endif - -void removecompilerstub(u1 *stub) -{ -} - -void removenativestub(u1 *stub) -{ -} - - -/* exceptions *****************************************************************/ - -void exceptions_clear_exception(void) -{ -} - -void exceptions_print_current_exception(void) -{ - abort(); -} - -void exceptions_throw_abstractmethoderror(void) -{ - fprintf(stderr, "java.lang.AbstractMethodError\n"); - - abort(); -} - -void exceptions_throw_classcircularityerror(classinfo *c) -{ - fprintf(stderr, "java.lang.ClassCircularityError: "); - - utf_display_printable_ascii(c->name); - fputc('\n', stderr); - - abort(); -} - -void exceptions_throw_classformaterror(classinfo *c, const char *message, ...) -{ - va_list ap; - - fprintf(stderr, "java.lang.ClassFormatError: "); - - utf_display_printable_ascii(c->name); - fprintf(stderr, ": "); - - va_start(ap, message); - vfprintf(stderr, message, ap); - va_end(ap); - - fputc('\n', stderr); - - abort(); -} - -void exceptions_throw_incompatibleclasschangeerror(classinfo *c, const char *message) -{ - fprintf(stderr, "java.lang.IncompatibleClassChangeError: "); - - if (c != NULL) - utf_fprint_printable_ascii_classname(stderr, c->name); - - fputc('\n', stderr); - - abort(); -} - -void exceptions_throw_internalerror(const char *message, ...) -{ - va_list ap; - - fprintf(stderr, "java.lang.InternalError: "); - - va_start(ap, message); - vfprintf(stderr, message, ap); - va_end(ap); - - abort(); -} - -void exceptions_throw_linkageerror(const char *message, classinfo *c) -{ - fprintf(stderr, "java.lang.LinkageError: %s", message); - - if (c != NULL) - utf_fprint_printable_ascii_classname(stderr, c->name); - - fputc('\n', stderr); - - abort(); -} - -void exceptions_throw_noclassdeffounderror(utf *name) -{ - fprintf(stderr, "java.lang.NoClassDefFoundError: "); - utf_fprint_printable_ascii(stderr, name); - fputc('\n', stderr); - - abort(); -} - -void exceptions_throw_noclassdeffounderror_wrong_name(classinfo *c, utf *name) -{ - fprintf(stderr, "java.lang.NoClassDefFoundError: "); - utf_fprint_printable_ascii(stderr, c->name); - fprintf(stderr, " (wrong name: "); - utf_fprint_printable_ascii(stderr, name); - fprintf(stderr, ")\n"); - - abort(); -} - -void exceptions_throw_verifyerror(methodinfo *m, const char *message, ...) -{ - fprintf(stderr, "java.lang.VerifyError: "); - utf_fprint_printable_ascii(stderr, m->name); - fprintf(stderr, ": %s", message); - - abort(); -} - -void exceptions_throw_nosuchfielderror(classinfo *c, utf *name) -{ - fprintf(stderr, "java.lang.NoSuchFieldError: "); - utf_fprint_printable_ascii(stderr, c->name); - fprintf(stderr, "."); - utf_fprint_printable_ascii(stderr, name); - fputc('\n', stderr); - - abort(); -} - -void exceptions_throw_nosuchmethoderror(classinfo *c, utf *name, utf *desc) -{ - fprintf(stderr, "java.lang.NoSuchMethodError: "); - utf_fprint_printable_ascii(stderr, c->name); - fprintf(stderr, "."); - utf_fprint_printable_ascii(stderr, name); - utf_fprint_printable_ascii(stderr, desc); - fputc('\n', stderr); - - abort(); -} - -void exceptions_throw_unsupportedclassversionerror(classinfo *c, u4 ma, u4 mi) -{ - fprintf(stderr, "java.lang.UnsupportedClassVersionError: " ); - utf_display_printable_ascii(c->name); - fprintf(stderr, " (Unsupported major.minor version %d.%d)\n", ma, mi); - - abort(); -} - -void exceptions_throw_classnotfoundexception(utf *name) -{ - fprintf(stderr, "java.lang.ClassNotFoundException: "); - utf_fprint_printable_ascii(stderr, name); - fputc('\n', stderr); - - abort(); -} - -void exceptions_throw_nullpointerexception(void) -{ - fprintf(stderr, "java.lang.NullPointerException\n"); - - abort(); -} - - -/* finalizer ******************************************************************/ - -void finalizer_notify(void) -{ - vm_abort("finalizer_notify"); -} - -void finalizer_run(void *o, void *p) -{ - vm_abort("finalizer_run"); -} - - -/* gc *************************************************************************/ - -void gc_reference_register(java_object_t **ref, int32_t reftype) -{ - vm_abort("gc_reference_register"); -} - -int64_t gc_get_heap_size(void) -{ - return 0; -} - -int64_t gc_get_free_bytes(void) -{ - return 0; -} - -int64_t gc_get_total_bytes(void) -{ - return 0; -} - -int64_t gc_get_max_heap_size(void) -{ - return 0; -} - - -/* heap ***********************************************************************/ - -void *heap_alloc_uncollectable(size_t bytelength) -{ - return calloc(bytelength, 1); -} - -s4 heap_get_hashcode(java_object_t *o) -{ - return 0; -} - - -/* instruction ****************************************************************/ - -methoddesc *instruction_call_site(const instruction *iptr) -{ - return NULL; -} - - -/* jit ************************************************************************/ - -icmdtable_entry_t icmd_table[256] = {}; - -void jit_invalidate_code(methodinfo *m) -{ - vm_abort("jit_invalidate_code"); -} - - -/* llni ***********************************************************************/ - -void llni_critical_start() -{ -} - -void llni_critical_end() -{ -} - - -/* localref *******************************************************************/ - -java_handle_t *localref_add(java_object_t *o) -{ -#if defined(ENABLE_HANDLES) - java_handle_t *h = (java_handle_t*) mem_alloc(sizeof(java_handle_t)); - - h->heap_object = o; - - return h; -#else - return (java_handle_t*) o; -#endif -} - - -/* lock ***********************************************************************/ - -void lock_init_object_lock(java_object_t *o) -{ -} - -bool lock_monitor_enter(java_handle_t *o) -{ - return true; -} - -bool lock_monitor_exit(java_handle_t *o) -{ - return true; -} - - -/* md *************************************************************************/ - -void md_param_alloc(methoddesc *md) -{ -} - -void md_param_alloc_native(methoddesc *md) -{ -} - - -/* memory *********************************************************************/ - -void *mem_alloc(int32_t size) -{ - /* real implementation in src/mm/memory.c clears memory */ - - return calloc(size, 1); -} - -void *mem_realloc(void *src, int32_t len1, int32_t len2) -{ - return realloc(src, len2); -} - -void mem_free(void *m, int32_t size) -{ - free(m); -} - -void *dumpmemory_get(size_t size) -{ - return malloc(size); -} - -int32_t dumpmemory_marker(void) -{ - return 0; -} - -void dumpmemory_release(int32_t size) -{ -} - - -/* package ********************************************************************/ - -/* void Package_add(java_handle_t *packagename) */ -void Package_add(utf *packagename) -{ - /* Do nothing. */ -} - - -/* primitive ******************************************************************/ - -classinfo *Primitive_get_arrayclass_by_type(int type) -{ - return NULL; -} - -classinfo *Primitive_get_class_by_type(int type) -{ - abort(); - return NULL; -} - -classinfo *Primitive_get_class_by_char(char ch) -{ - abort(); - return NULL; -} - - -/* properties *****************************************************************/ - -void properties_add(char *key, char *value) -{ -} - -char *properties_get(char *key) -{ - return NULL; -} - - -/* reflect ********************************************************************/ - -java_handle_t *reflect_constructor_new(fieldinfo *f) -{ - vm_abort("reflect_constructor_new: Not implemented."); - return NULL; -} - -java_handle_t *reflect_field_new(fieldinfo *f) -{ - vm_abort("reflect_field_new: Not implemented."); - return NULL; -} - -java_handle_t *reflect_method_new(methodinfo *m) -{ - vm_abort("reflect_method_new: Not implemented."); - return NULL; -} - - -/* resolve ********************************************************************/ - -void resolve_handle_pending_exception(bool throwError) -{ - vm_abort("resolve_handle_pending_exception: Not implemented."); -} - -bool resolve_class_from_typedesc(typedesc *d, bool checkaccess, bool link, classinfo **result) -{ - abort(); - - return false; -} - -/* stupid resolving implementation used by resolve_classref_or_classinfo_eager */ -/* This function does eager resolving without any access checks. */ - -static classinfo * dummy_resolve_class_from_name(classinfo *referer, - utf *classname, - bool checkaccess) -{ - classinfo *cls = NULL; - char *utf_ptr; - int len; - - assert(referer); - assert(classname); - - /* lookup if this class has already been loaded */ - - cls = classcache_lookup(referer->classloader, classname); - - if (!cls) { - /* resolve array types */ - - if (classname->text[0] == '[') { - utf_ptr = classname->text + 1; - len = classname->blength - 1; - - /* classname is an array type name */ - - switch (*utf_ptr) { - case 'L': - utf_ptr++; - len -= 2; - /* FALLTHROUGH */ - case '[': - /* the component type is a reference type */ - /* resolve the component type */ - if ((cls = dummy_resolve_class_from_name(referer, - utf_new(utf_ptr,len), - checkaccess)) == NULL) - return NULL; /* exception */ - - /* create the array class */ - cls = class_array_of(cls,false); - if (!cls) - return NULL; /* exception */ - } - } - - /* load the class */ - if (!cls) { - if (!(cls = load_class_from_classloader(classname, - referer->classloader))) - return false; /* exception */ - } - } - - /* the class is now loaded */ - assert(cls); - assert(cls->state & CLASS_LOADED); - - return cls; -} - - -classinfo * resolve_classref_or_classinfo_eager(classref_or_classinfo cls, - bool checkaccess) -{ - classinfo *c; - - assert(cls.any); - - if (IS_CLASSREF(cls)) { - /* we must resolve this reference */ - - if ((c = dummy_resolve_class_from_name(cls.ref->referer, cls.ref->name, - checkaccess)) == NULL) - return NULL; - } - else { - /* cls has already been resolved */ - c = cls.cls; - } - - assert(c); - assert(c->state & CLASS_LOADED); - - /* succeeded */ - return c; -} - - -/* stacktrace *****************************************************************/ - -java_handle_objectarray_t *stacktrace_getClassContext() -{ - return NULL; -} - - -/* threads ********************************************************************/ - -#if defined(HAVE___THREAD) -__thread threadobject *thread_current; -#else -#include -pthread_key_t thread_current_key; -#endif - -intptr_t threads_get_current_tid(void) -{ - return 0; -} - -void threads_cast_stopworld(void) -{ -} - -void threads_cast_startworld(void) -{ -} - - -/* vm *************************************************************************/ - -void vm_printconfig(void) -{ -} - -void vm_abort(const char *text, ...) -{ - va_list ap; - - va_start(ap, text); - vfprintf(stderr, text, ap); - va_end(ap); - - os::abort(); -} - -void vm_abort_errno(const char *text, ...) -{ - va_list ap; - - va_start(ap, text); - vm_abort_errnum(errno, text, ap); - va_end(ap); -} - -void vm_abort_errnum(int errnum, const char *text, ...) -{ - va_list ap; - - log_start(); - - va_start(ap, text); - log_vprint(text, ap); - va_end(ap); - - log_print(": %s", os::strerror(errnum)); - log_finish(); - - os::abort(); -} - -java_handle_t *vm_call_method(methodinfo *m, java_handle_t *o, ...) -{ - return NULL; -} - - -/* XXX */ - -void stringtable_update(void) -{ - log_println("stringtable_update: REMOVE ME!"); -} - -java_object_t *literalstring_new(utf *u) -{ - log_println("literalstring_new: REMOVE ME!"); - - return NULL; -} - - -void print_dynamic_super_statistics(void) -{ -} - - -#if defined(ENABLE_VMLOG) -void vmlog_cacao_set_prefix(const char *arg) -{ -} - -void vmlog_cacao_set_stringprefix(const char *arg) -{ -} - -void vmlog_cacao_set_ignoreprefix(const char *arg) -{ -} -#endif - - -/* Legacy C interface *********************************************************/ - -bool VM_is_initializing() { return true; } - -} // extern "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: - */ diff --git a/src/cacaoh/headers.c b/src/cacaoh/headers.c deleted file mode 100644 index 6f2ec0b5a..000000000 --- a/src/cacaoh/headers.c +++ /dev/null @@ -1,508 +0,0 @@ -/* src/cacaoh/headers.c - functions for header generation - - Copyright (C) 1996-2005, 2006, 2007, 2008 - CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO - - 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. - -*/ - - -#include "config.h" - -#include -#include -#include -#include -#include -#include - -#if defined(ENABLE_THREADS) -# if defined(__DARWIN__) -# include -# endif -# include -#endif - -#include "mm/gc.hpp" -#include "mm/memory.h" - -#include "toolbox/chain.h" -#include "toolbox/logging.h" - -#include "vm/builtin.h" -#include "vm/global.h" -#include "vm/string.hpp" - -#include "vmcore/class.h" -#include "vmcore/method.h" -#include "vmcore/loader.h" -#include "vmcore/options.h" - - -/************************ global variables **********************/ - -#define ACC_NATIVELY_OVERLOADED 0x10000000 - -#if defined(ENABLE_HANDLES) -# define HEAP_PREFIX "heap_" -#else -# define HEAP_PREFIX "" -#endif - -chain *ident_chain; /* chain with method and field names in current class */ -FILE *file = NULL; -static uint32_t outputsize; -static bool dopadding; - - -static void printIDpart(int c) -{ - if ((c >= 'a' && c <= 'z') || - (c >= 'A' && c <= 'Z') || - (c >= '0' && c <= '9') || - (c == '_')) - putc(c, file); - else - putc('_', file); -} - - -void printID(utf *u) -{ - char *utf_ptr = u->text; - int i; - - for (i = 0; i < utf_get_number_of_u2s(u); i++) - printIDpart(utf_nextu2(&utf_ptr)); -} - - -static void addoutputsize(int len) -{ - uint32_t newsize; - int32_t i; - - if (!dopadding) - return; - - newsize = MEMORY_ALIGN(outputsize, len); - - for (i = outputsize; i < newsize; i++) - fprintf(file, " uint8_t pad%d\n", (int) i); - - outputsize = newsize; -} - - -void printOverloadPart(utf *desc) -{ - char *utf_ptr=desc->text; - uint16_t c; - - fprintf(file, "__"); - - while ((c = utf_nextu2(&utf_ptr)) != ')') { - switch (c) { - case 'I': - case 'S': - case 'B': - case 'C': - case 'Z': - case 'J': - case 'F': - case 'D': - fprintf(file, "%c", (char) c); - break; - case '[': - fprintf(file, "_3"); - break; - case 'L': - putc('L', file); - while ((c = utf_nextu2(&utf_ptr)) != ';') - printIDpart(c); - fprintf(file, "_2"); - break; - case '(': - break; - default: - log_text("invalid method descriptor"); - assert(0); - } - } -} - -static char *printtype(char *utf_ptr, char *prefix, char *infix) -{ - uint16_t c; - - switch (utf_nextu2(&utf_ptr)) { - case 'V': - fprintf(file, "void"); - break; - case 'I': - case 'S': - case 'B': - case 'C': - case 'Z': - addoutputsize(4); - fprintf(file, "int32_t"); - break; - case 'J': - addoutputsize(8); - fprintf(file, "int64_t"); - break; - case 'F': - addoutputsize(4); - fprintf(file, "float"); - break; - case 'D': - addoutputsize(8); - fprintf(file, "double"); - break; - case '[': - addoutputsize ( sizeof(java_array_t*) ); - switch (utf_nextu2(&utf_ptr)) { - case 'I': fprintf (file, "java%s_intarray_t*", infix); break; - case 'J': fprintf (file, "java%s_longarray_t*", infix); break; - case 'Z': fprintf (file, "java%s_booleanarray_t*", infix); break; - case 'B': fprintf (file, "java%s_bytearray_t*", infix); break; - case 'S': fprintf (file, "java%s_shortarray_t*", infix); break; - case 'C': fprintf (file, "java%s_chararray_t*", infix); break; - case 'F': fprintf (file, "java%s_floatarray_t*", infix); break; - case 'D': fprintf (file, "java%s_doublearray_t*", infix); break; - - case '[': fprintf(file, "java%s_objectarray_t*", infix); - while ((c = utf_nextu2(&utf_ptr)) == '['); - if (c == 'L') - while (utf_nextu2(&utf_ptr) != ';'); - break; - - case 'L': fprintf(file, "java%s_objectarray_t*", infix); - while (utf_nextu2(&utf_ptr) != ';'); - break; - default: - log_text("invalid type descriptor"); - assert(0); - } - break; - - case 'L': - addoutputsize ( sizeof(java_object_t*)); - fprintf (file, "struct %s", prefix); - while ( (c = utf_nextu2(&utf_ptr)) != ';' ) printIDpart (c); - fprintf (file, "*"); - break; - - default: - log_text("Unknown type in field descriptor"); - assert(0); - } - - return utf_ptr; -} - - -/***** determine the number of entries of a utf string in the ident chain *****/ - -static int searchidentchain_utf(utf *ident) -{ - utf *u = chain_first(ident_chain); /* first element of list */ - int count = 0; - - while (u) { - if (u==ident) count++; /* string found */ - u = chain_next(ident_chain); /* next element in list */ - } - - return count; -} - - -/************** print structure for direct access to objects ******************/ - -static void printfields(classinfo *c) -{ - int32_t i; - fieldinfo *f; - int ident_count; - - if (!c) { - addoutputsize(sizeof(java_object_t)); - fprintf(file, " java_object_t header;\n"); - return; - } - - printfields(c->super); - - for (i = 0; i < c->fieldscount; i++) { - f = &(c->fields[i]); - - if (!(f->flags & ACC_STATIC)) { - fprintf(file, " "); - printtype(f->descriptor->text, HEAP_PREFIX, ""); - fprintf(file, " "); - utf_fprint_printable_ascii(file, f->name); - - /* rename multiple fieldnames */ - if ((ident_count = searchidentchain_utf(f->name))) - fprintf(file, "%d", ident_count - 1); - chain_addlast(ident_chain, f->name); - - fprintf(file, ";\n"); - } - } -} - - -/***************** store prototype for native method in file ******************/ - -void printmethod(methodinfo *m) -{ - char *utf_ptr; - int32_t paramnum = 1; - - /* search for return-type in descriptor */ - utf_ptr = m->descriptor->text; - while (utf_nextu2(&utf_ptr) != ')'); - - /* create remarks */ - fprintf(file, "\n/*\n * Class: "); - utf_fprint_printable_ascii(file, m->clazz->name); - fprintf(file, "\n * Method: "); - utf_fprint_printable_ascii(file, m->name); - fprintf(file, "\n * Signature: "); - utf_fprint_printable_ascii(file, m->descriptor); - fprintf(file, "\n */\n"); - - /* create prototype */ - fprintf(file, "JNIEXPORT "); - printtype(utf_ptr, "", "_handle"); - fprintf(file, " JNICALL Java_"); - printID(m->clazz->name); - - chain_addlast(ident_chain, m->name); - - fprintf(file, "_"); - printID(m->name); - - /* ATTENTION: We use a dummy flag here. */ - - if (m->flags & ACC_NATIVELY_OVERLOADED) - printOverloadPart(m->descriptor); - - fprintf(file, "(JNIEnv *env"); - - utf_ptr = m->descriptor->text + 1; - - if (!(m->flags & ACC_STATIC)) { - fprintf(file, ", struct "); - printID(m->clazz->name); - fprintf(file, "* _this"); - - } else { - fprintf(file, ", jclass clazz"); - } - - if ((*utf_ptr) != ')') fprintf(file, ", "); - - while ((*utf_ptr) != ')') { - utf_ptr = printtype(utf_ptr, "", "_handle"); - fprintf(file, " par%d", paramnum++); - if ((*utf_ptr)!=')') fprintf(file, ", "); - } - - fprintf(file, ");\n\n"); -} - - -/******* remove package-name in fully-qualified classname *********************/ - -void gen_header_filename(char *buffer, utf *u) -{ - int32_t i; - - for (i = 0; i < utf_get_number_of_u2s(u); i++) { - if ((u->text[i] == '/') || (u->text[i] == '$')) { - buffer[i] = '_'; /* convert '$' and '/' to '_' */ - - } else { - buffer[i] = u->text[i]; - } - } - buffer[utf_get_number_of_u2s(u)] = '\0'; -} - - -/* create headerfile for classes and store native methods in chain ************/ - -void headerfile_generate(classinfo *c, char *opt_directory) -{ - char header_filename[1024] = ""; - char classname[1024]; - char uclassname[1024]; - int32_t i; - methodinfo *m; - int32_t j; - methodinfo *m2; - bool nativelyoverloaded; - - /* prevent compiler warnings */ - - nativelyoverloaded = false; - - /* open headerfile for class */ - gen_header_filename(classname, c->name); - - /* create chain for renaming fields */ - ident_chain = chain_new(); - - if (opt_directory) { - sprintf(header_filename, "%s/%s.h", opt_directory, classname); - - } else { - sprintf(header_filename, "%s.h", classname); - } - - file = fopen(header_filename, "w"); - if (!file) { - log_text("Can not open file to store header information"); - assert(0); - } - - fprintf(file, "/* This file is machine generated, don't edit it! */\n\n"); - - /* convert to uppercase */ - for (i = 0; classname[i]; i++) { - uclassname[i] = toupper(classname[i]); - } - uclassname[i] = '\0'; - - fprintf(file, "#ifndef _%s_H\n#define _%s_H\n\n", uclassname, uclassname); - - /* create structure for direct access to objects */ - fprintf(file, "/* Structure information for class: "); - utf_fprint_printable_ascii(file, c->name); - fprintf(file, " */\n\n"); - fprintf(file, "typedef struct %s", HEAP_PREFIX); - printID(c->name); - fprintf(file, " {\n"); - outputsize = 0; - dopadding = true; - - printfields(c); - - fprintf(file, "} %s", HEAP_PREFIX); - printID(c->name); - fprintf(file, ";\n\n"); - -#if defined(ENABLE_HANDLES) - /* create structure for indirection cell */ - fprintf(file, "typedef struct "); - printID(c->name); - fprintf(file, " {\n"); - fprintf(file, " %s", HEAP_PREFIX); - printID(c->name); - fprintf(file, " *heap_object;\n"); - fprintf(file, "} "); - printID(c->name); - fprintf(file, ";\n\n"); -#endif - - /* create chain for renaming overloaded methods */ - chain_free(ident_chain); - ident_chain = chain_new(); - - /* create method-prototypes */ - - /* find overloaded methods */ - - for (i = 0; i < c->methodscount; i++) { - m = &(c->methods[i]); - - if (!(m->flags & ACC_NATIVE)) - continue; - - /* We use a dummy flag here. */ - - if (!(m->flags & ACC_NATIVELY_OVERLOADED)) { - nativelyoverloaded = false; - - for (j = i + 1; j < c->methodscount; j++) { - m2 = &(c->methods[j]); - - if (!(m2->flags & ACC_NATIVE)) - continue; - - if (m->name == m2->name) { - m2->flags |= ACC_NATIVELY_OVERLOADED; - nativelyoverloaded = true; - } - } - } - - if (nativelyoverloaded == true) - m->flags |= ACC_NATIVELY_OVERLOADED; - } - - for (i = 0; i < c->methodscount; i++) { - m = &(c->methods[i]); - - if (m->flags & ACC_NATIVE) - printmethod(m); - } - - chain_free(ident_chain); - - fprintf(file, "#endif\n\n"); - - fclose(file); -} - - -/******** print classname, '$' used to seperate inner-class name ***********/ - -void print_classname(classinfo *clazz) -{ - utf *u = clazz->name; - char *endpos = u->text + u->blength; - char *utf_ptr = u->text; - uint16_t c; - - while (utf_ptr < endpos) { - if ((c = utf_nextu2(&utf_ptr)) == '_') - putc('$', file); - else - putc(c, file); - } -} - - -/* - * 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: - */ diff --git a/src/native/Makefile.am b/src/native/Makefile.am index 5ae4d6f8f..facd048b9 100644 --- a/src/native/Makefile.am +++ b/src/native/Makefile.am @@ -26,7 +26,6 @@ AM_CPPFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/src/vm/jit/$(ARCH_DIR) -I$(top LIBS = SUBDIRS = \ - include \ vm if ENABLE_JVMTI diff --git a/src/native/include/Makefile.am b/src/native/include/Makefile.am index 8dbd8bff0..5876bedf4 100644 --- a/src/native/include/Makefile.am +++ b/src/native/include/Makefile.am @@ -24,72 +24,8 @@ JAVAH = $(CACAOH) JAVAHCMD = $(JAVAH) -bootclasspath $(BOOTCLASSPATH) -COMMON_HEADER_FILES = \ - java_lang_Class.h \ - java_lang_Object.h \ - java_lang_String.h \ - java_lang_Thread.h \ - java_lang_Throwable.h \ - \ - java_io_InputStream.h \ - java_io_PrintStream.h \ - \ - java_lang_Boolean.h \ - java_lang_Byte.h \ - java_lang_Character.h \ - java_lang_Double.h \ - java_lang_Float.h \ - java_lang_Integer.h \ - java_lang_Long.h \ - java_lang_Short.h - -JAVASE_HEADER_FILES = \ - java_lang_ClassLoader.h \ - java_lang_Cloneable.h \ - java_lang_ThreadGroup.h \ - java_util_Properties.h \ - \ - java_lang_Process.h \ - java_lang_StackTraceElement.h \ - java_lang_reflect_Constructor.h \ - java_lang_reflect_Field.h \ - java_lang_reflect_Method.h \ - java_nio_Buffer.h \ - java_security_ProtectionDomain.h \ - java_util_HashMap.h \ - java_util_Map.h \ - java_util_concurrent_atomic_AtomicLong.h \ - sun_misc_Unsafe.h - -if WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH -JAVASE_HEADER_FILES += \ - java_lang_VMThread.h \ - java_lang_VMThrowable.h \ - \ - gnu_classpath_Pointer.h \ - gnu_classpath_Pointer32.h \ - gnu_classpath_Pointer64.h \ - gnu_java_lang_VMCPStringBuilder.h \ - java_lang_VMObject.h \ - java_lang_reflect_VMConstructor.h \ - java_lang_reflect_VMField.h \ - java_lang_reflect_VMMethod.h \ - java_nio_DirectByteBufferImpl.h - -if ENABLE_ANNOTATIONS -JAVASE_HEADER_FILES += \ - sun_reflect_ConstantPool.h -endif -endif - -if WITH_JAVA_RUNTIME_LIBRARY_OPENJDK -JAVASE_HEADER_FILES += \ - java_lang_AssertionStatusDirectives.h \ - java_nio_ByteBuffer.h \ - sun_reflect_ConstantPool.h -endif - -JAVAME_CLDC1_1_HEADER_FILES = \ +if WITH_JAVA_RUNTIME_LIBRARY_CLDC1_1 +IMPLEMENTED_VM_CLASSES_HEADER_FILES = \ com_sun_cldc_io_ResourceInputStream.h \ com_sun_cldc_io_j2me_socket_Protocol.h \ com_sun_cldchi_io_ConsoleOutputStream.h \ @@ -98,56 +34,60 @@ JAVAME_CLDC1_1_HEADER_FILES = \ java_lang_Math.h \ java_lang_Runtime.h \ java_lang_System.h - -JVMTI_HEADER_FILES = \ - gnu_classpath_jdwp_VMFrame.h \ - gnu_classpath_jdwp_VMMethod.h \ - gnu_classpath_jdwp_VMVirtualMachine.h \ - gnu_classpath_jdwp_event_EventRequest.h \ - gnu_classpath_jdwp_util_VariableTable.h +endif if WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH -ADDITIONAL_IMPLEMENTED_VM_CLASSES_HEADER_FILES = \ +IMPLEMENTED_VM_CLASSES_HEADER_FILES = \ gnu_classpath_VMStackWalker.h \ gnu_classpath_VMSystemProperties.h \ + gnu_java_lang_VMCPStringBuilder.h \ gnu_java_lang_management_VMClassLoadingMXBeanImpl.h \ gnu_java_lang_management_VMMemoryMXBeanImpl.h \ gnu_java_lang_management_VMRuntimeMXBeanImpl.h \ gnu_java_lang_management_VMThreadMXBeanImpl.h \ java_lang_VMClass.h \ java_lang_VMClassLoader.h \ + java_lang_VMObject.h \ java_lang_VMRuntime.h \ java_lang_VMString.h \ java_lang_VMSystem.h \ - java_lang_management_MemoryUsage.h \ - java_lang_management_ThreadInfo.h \ + java_lang_VMThread.h \ + java_lang_VMThrowable.h \ java_lang_management_VMManagementFactory.h \ + java_lang_reflect_VMConstructor.h \ + java_lang_reflect_VMField.h \ + java_lang_reflect_VMMethod.h \ java_lang_reflect_VMProxy.h \ - java_security_VMAccessController.h -endif - -CLEANFILES = \ - *.h - -DO_HEADER_FILES = \ - $(COMMON_HEADER_FILES) + java_security_VMAccessController.h \ + java_util_concurrent_atomic_AtomicLong.h \ + sun_misc_Unsafe.h -if ENABLE_JAVASE -DO_HEADER_FILES += \ - $(JAVASE_HEADER_FILES) \ - $(ADDITIONAL_IMPLEMENTED_VM_CLASSES_HEADER_FILES) +if ENABLE_ANNOTATIONS +IMPLEMENTED_VM_CLASSES_HEADER_FILES += \ + sun_reflect_ConstantPool.h +endif endif -if ENABLE_JAVAME_CLDC1_1 -DO_HEADER_FILES += \ - $(JAVAME_CLDC1_1_HEADER_FILES) +if WITH_JAVA_RUNTIME_LIBRARY_OPENJDK +IMPLEMENTED_VM_CLASSES_HEADER_FILES = \ + sun_misc_Unsafe.h endif if ENABLE_JVMTI -DO_HEADER_FILES += \ - $(GEN_JVMTI_HEADER_FILES) +JVMTI_HEADER_FILES = \ + gnu_classpath_jdwp_VMFrame.h \ + gnu_classpath_jdwp_VMMethod.h \ + gnu_classpath_jdwp_VMVirtualMachine.h \ + gnu_classpath_jdwp_event_EventRequest.h \ + gnu_classpath_jdwp_util_VariableTable.h endif +CLEANFILES = \ + *.h + +DO_HEADER_FILES = \ + $(IMPLEMENTED_VM_CLASSES_HEADER_FILES) + if WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH if ENABLE_ZLIB VM_ZIP = $(top_builddir)/src/classes/vm.zip diff --git a/src/native/jni.cpp b/src/native/jni.cpp index 85f08132a..e64e99949 100644 --- a/src/native/jni.cpp +++ b/src/native/jni.cpp @@ -39,62 +39,10 @@ #include "native/localref.h" #include "native/native.h" -#if defined(ENABLE_JAVASE) -# if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH) -# include "native/include/gnu_classpath_Pointer.h" - -# if SIZEOF_VOID_P == 8 -# include "native/include/gnu_classpath_Pointer64.h" -# else -# include "native/include/gnu_classpath_Pointer32.h" -# endif -# endif -#endif - -#include "native/include/java_lang_Object.h" -#include "native/include/java_lang_String.h" -#include "native/include/java_lang_Throwable.h" - -#if defined(ENABLE_JAVASE) - -# if defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK) -# include "native/include/java_nio_ByteBuffer.h" /* required by j.l.CL */ -# endif - -/* java_lang_ClassLoader is used in java_lang_Class and vice versa, so - we pre-define it here to prevent a compiler warning for Sun - configurations. */ - -struct java_lang_ClassLoader; - -# include "native/include/java_lang_Class.h" -# include "native/include/java_lang_ClassLoader.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_nio_Buffer.h" - -# if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH) -# include "native/include/java_lang_reflect_VMConstructor.h" -# include "native/include/java_lang_reflect_VMField.h" -# include "native/include/java_lang_reflect_VMMethod.h" - -# include "native/include/java_nio_DirectByteBufferImpl.h" -# endif -#elif defined(ENABLE_JAVAME_CLDC1_1) -# include "native/include/java_lang_Class.h" -#endif - #if defined(ENABLE_JVMTI) # include "native/jvmti/cacaodbg.h" #endif -#if defined(ENABLE_JAVASE) -# include "native/vm/reflect.h" -#endif - #include "threads/lock-common.h" #include "threads/thread.hpp" @@ -116,6 +64,7 @@ struct java_lang_ClassLoader; #include "vm/jit/stacktrace.hpp" #include "vmcore/globals.hpp" +#include "vmcore/javaobjects.hpp" #include "vmcore/loader.h" #include "vmcore/options.h" #include "vmcore/statistics.h" @@ -861,29 +810,28 @@ jint _Jv_JNI_GetVersion(JNIEnv *env) *******************************************************************************/ -jclass _Jv_JNI_DefineClass(JNIEnv *env, const char *name, jobject loader, - const jbyte *buf, jsize bufLen) +jclass jni_DefineClass(JNIEnv *env, const char *name, jobject loader, const jbyte *buf, jsize bufLen) { #if defined(ENABLE_JAVASE) - utf *u; - classloader_t *cl; - classinfo *c; - java_lang_Class *co; + utf *u; + classloader_t *cl; + classinfo *c; + java_handle_t* h; - TRACEJNICALLS(("_Jv_JNI_DefineClass(env=%p, name=%s, loader=%p, buf=%p, bufLen=%d)", env, name, loader, buf, bufLen)); + TRACEJNICALLS(("jni_DefineClass(env=%p, name=%s, loader=%p, buf=%p, bufLen=%d)", env, name, loader, buf, bufLen)); u = utf_new_char(name); cl = loader_hashtable_classloader_add((java_handle_t *) loader); c = class_define(u, cl, bufLen, (uint8_t *) buf, NULL); - co = LLNI_classinfo_wrap(c); + h = LLNI_classinfo_wrap(c); - return (jclass) jni_NewLocalRef(env, (jobject) co); + return (jclass) jni_NewLocalRef(env, (jobject) h); #else - vm_abort("_Jv_JNI_DefineClass: not implemented in this configuration"); + vm_abort("jni_DefineClass: Not implemented in this configuration"); - /* keep compiler happy */ + // Keep compiler happy. return 0; #endif @@ -902,10 +850,10 @@ jclass jni_FindClass(JNIEnv *env, const char *name) { #if defined(ENABLE_JAVASE) - utf *u; - classinfo *cc; - classinfo *c; - java_lang_Class *co; + utf* u; + classinfo* cc; + classinfo* c; + java_handle_t* h; TRACEJNICALLS(("jni_FindClass(env=%p, name=%s)", env, name)); @@ -947,9 +895,9 @@ jclass jni_FindClass(JNIEnv *env, const char *name) if (!link_class(c)) return NULL; - co = LLNI_classinfo_wrap(c); + h = LLNI_classinfo_wrap(c); - return (jclass) jni_NewLocalRef(env, (jobject) co); + return (jclass) jni_NewLocalRef(env, (jobject) h); #elif defined(ENABLE_JAVAME_CLDC1_1) @@ -989,13 +937,12 @@ jclass jni_FindClass(JNIEnv *env, const char *name) *******************************************************************************/ -jclass _Jv_JNI_GetSuperclass(JNIEnv *env, jclass sub) +jclass jni_GetSuperclass(JNIEnv *env, jclass sub) { - classinfo *c; - classinfo *super; - java_lang_Class *co; + classinfo* c; + classinfo* super; - TRACEJNICALLS(("_Jv_JNI_GetSuperclass(env=%p, sub=%p)", env, sub)); + TRACEJNICALLS(("jni_GetSuperclass(env=%p, sub=%p)", env, sub)); c = LLNI_classinfo_unwrap(sub); @@ -1004,9 +951,9 @@ jclass _Jv_JNI_GetSuperclass(JNIEnv *env, jclass sub) super = class_get_superclass(c); - co = LLNI_classinfo_wrap(super); + java_handle_t* h = LLNI_classinfo_wrap(super); - return (jclass) jni_NewLocalRef(env, (jobject) co); + return (jclass) jni_NewLocalRef(env, (jobject) h); } @@ -1449,13 +1396,12 @@ jobject _Jv_JNI_NewObjectA(JNIEnv* env, jclass clazz, jmethodID methodID, *******************************************************************************/ -jclass _Jv_JNI_GetObjectClass(JNIEnv *env, jobject obj) +jclass jni_GetObjectClass(JNIEnv *env, jobject obj) { - java_handle_t *o; - classinfo *c; - java_lang_Class *co; + java_handle_t* o; + classinfo* c; - STATISTICS(jniinvokation()); + TRACEJNICALLS(("jni_GetObjectClass(env=%p, obj=%p)", env, obj)); o = (java_handle_t *) obj; @@ -1464,9 +1410,9 @@ jclass _Jv_JNI_GetObjectClass(JNIEnv *env, jobject obj) LLNI_class_get(o, c); - co = LLNI_classinfo_wrap(c); + java_handle_t* h = LLNI_classinfo_wrap(c); - return (jclass) jni_NewLocalRef(env, (jobject) co); + return (jclass) jni_NewLocalRef(env, (jobject) h); } @@ -1503,17 +1449,8 @@ jboolean _Jv_JNI_IsInstanceOf(JNIEnv *env, jobject obj, jclass clazz) jmethodID jni_FromReflectedMethod(JNIEnv *env, jobject method) { #if defined(ENABLE_JAVASE) - java_handle_t *o; - java_lang_reflect_Method *rm; - java_lang_reflect_Constructor *rc; - classinfo *c; - methodinfo *m; - int32_t slot; - -#if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH) - java_lang_reflect_VMMethod *rvmm; - java_lang_reflect_VMConstructor *rvmc; -#endif + java_handle_t* o; + methodinfo* m; TRACEJNICALLS(("jni_FromReflectedMethod(env=%p, method=%p)", env, method)); @@ -1522,14 +1459,13 @@ jmethodID jni_FromReflectedMethod(JNIEnv *env, jobject method) if (o == NULL) return NULL; + // FIXME We can't access the object here directly. if (o->vftbl->clazz == class_java_lang_reflect_Constructor) { - rc = (java_lang_reflect_Constructor *) method; + java_lang_reflect_Constructor rc(method); #if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH) - - LLNI_field_get_ref(rc, cons , rvmc); - LLNI_field_get_cls(rvmc, clazz, c); - LLNI_field_get_val(rvmc, slot , slot); + java_lang_reflect_VMConstructor rvmc(rc.get_cons()); + m = rvmc.get_method(); #elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK) @@ -1541,16 +1477,15 @@ jmethodID jni_FromReflectedMethod(JNIEnv *env, jobject method) #endif } else { + // FIXME We can't access the object here directly. assert(o->vftbl->clazz == class_java_lang_reflect_Method); - rm = (java_lang_reflect_Method *) method; + java_lang_reflect_Method rm(method); #if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH) - LLNI_field_get_ref(rm, m , rvmm); - LLNI_field_get_cls(rvmm, clazz, c); - LLNI_field_get_val(rvmm, slot , slot); - + java_lang_reflect_VMMethod rvmm(rm.get_m()); + m = rvmm.get_method(); #elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK) LLNI_field_get_cls(rm, clazz, c); @@ -1561,8 +1496,6 @@ jmethodID jni_FromReflectedMethod(JNIEnv *env, jobject method) #endif } - m = &(c->methods[slot]); - return (jmethodID) m; #else vm_abort("jni_FromReflectedMethod: Not implemented in this configuration."); @@ -1583,27 +1516,21 @@ jmethodID jni_FromReflectedMethod(JNIEnv *env, jobject method) jfieldID jni_FromReflectedField(JNIEnv* env, jobject field) { #if defined(ENABLE_JAVASE) - java_lang_reflect_Field *rf; - classinfo *c; - fieldinfo *f; - int32_t slot; #if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH) - java_lang_reflect_VMField *rvmf; #endif TRACEJNICALLS(("jni_FromReflectedField(env=%p, field=%p)", env, field)); - rf = (java_lang_reflect_Field *) field; - - if (rf == NULL) + if (field == NULL) return NULL; + java_lang_reflect_Field rf(field); + #if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH) - LLNI_field_get_ref(rf, f, rvmf); - LLNI_field_get_cls(rvmf, clazz, c); - LLNI_field_get_val(rvmf, slot , slot); + java_lang_reflect_VMField rvmf(rf.get_f()); + fieldinfo* f = rvmf.get_field(); #elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK) @@ -1614,8 +1541,6 @@ jfieldID jni_FromReflectedField(JNIEnv* env, jobject field) # error unknown configuration #endif - f = &(c->fields[slot]); - return (jfieldID) f; #else vm_abort("jni_FromReflectedField: Not implemented in this configuration."); @@ -1635,34 +1560,29 @@ jfieldID jni_FromReflectedField(JNIEnv* env, jobject field) *******************************************************************************/ -jobject _Jv_JNI_ToReflectedMethod(JNIEnv* env, jclass cls, jmethodID methodID, - jboolean isStatic) +jobject jni_ToReflectedMethod(JNIEnv* env, jclass cls, jmethodID methodID, jboolean isStatic) { #if defined(ENABLE_JAVASE) - methodinfo *m; - java_lang_reflect_Constructor *rc; - java_lang_reflect_Method *rm; - - TRACEJNICALLS(("_Jv_JNI_ToReflectedMethod(env=%p, cls=%p, methodID=%p, isStatic=%d)", env, cls, methodID, isStatic)); + TRACEJNICALLS(("jni_ToReflectedMethod(env=%p, cls=%p, methodID=%p, isStatic=%d)", env, cls, methodID, isStatic)); - m = (methodinfo *) methodID; + methodinfo* m = (methodinfo *) methodID; /* HotSpot does the same assert. */ assert(((m->flags & ACC_STATIC) != 0) == (isStatic != 0)); - if (m->name == utf_init) { - rc = reflect_constructor_new(m); + java_handle_t* h; - return (jobject) rc; + if (m->name == utf_init) { + h = java_lang_reflect_Constructor::create(m); } else { - rm = reflect_method_new(m); - - return (jobject) rm; + h = java_lang_reflect_Method::create(m); } + + return (jobject) h; #else - vm_abort("_Jv_JNI_ToReflectedMethod: not implemented in this configuration"); + vm_abort("jni_ToReflectedMethod: Not implemented in this configuration."); /* keep compiler happy */ @@ -2606,30 +2526,27 @@ void _Jv_JNI_SetStaticObjectField(JNIEnv *env, jclass clazz, jfieldID fieldID, *******************************************************************************/ -jstring _Jv_JNI_NewString(JNIEnv *env, const jchar *buf, jsize len) +jstring jni_NewString(JNIEnv *env, const jchar *buf, jsize len) { - java_lang_String *s; - java_handle_chararray_t *a; - int32_t i; - - STATISTICS(jniinvokation()); + TRACEJNICALLS(("jni_NewString(env=%p, buf=%p, len=%d)", env, buf, len)); - s = (java_lang_String *) builtin_new(class_java_lang_String); - a = builtin_newarray_char(len); + java_handle_chararray_t* a = builtin_newarray_char(len); - /* javastring or characterarray could not be created */ - if ((a == NULL) || (s == NULL)) + if (a == NULL) return NULL; /* copy text */ - for (i = 0; i < len; i++) + for (jsize i = 0; i < len; i++) LLNI_array_direct(a, i) = buf[i]; - LLNI_field_set_ref(s, value , a); - LLNI_field_set_val(s, offset, 0); - LLNI_field_set_val(s, count , len); + java_handle_t* h = builtin_new(class_java_lang_String); + + if (h == NULL) + return NULL; + + java_lang_String s(h, a, len, 0); - return (jstring) jni_NewLocalRef(env, (jobject) s); + return (jstring) jni_NewLocalRef(env, (jobject) s.get_handle()); } @@ -2642,18 +2559,16 @@ static jchar emptyStringJ[]={0,0}; *******************************************************************************/ -jsize _Jv_JNI_GetStringLength(JNIEnv *env, jstring str) +jsize jni_GetStringLength(JNIEnv *env, jstring str) { - java_lang_String *s; - jsize len; + TRACEJNICALLSENTER(("jni_GetStringLength(env=%p, str=%p)", env, str)); - TRACEJNICALLS(("_Jv_JNI_GetStringLength(env=%p, str=%p)", env, str)); + java_lang_String s(str); + jsize count = s.get_count(); - s = (java_lang_String *) str; + TRACEJNICALLSEXIT(("->%d)", count)); - LLNI_field_get_val(s, count, len); - - return len; + return count; } @@ -2666,12 +2581,8 @@ jsize _Jv_JNI_GetStringLength(JNIEnv *env, jstring str) const jchar* jni_GetStringChars(JNIEnv *env, jstring str, jboolean *isCopy) { - java_lang_String *s; - java_handle_chararray_t *a; - u2 *stringbuffer; - int32_t count; - int32_t offset; - int32_t i; + u2 *stringbuffer; + int32_t i; TRACEJNICALLS(("jni_GetStringChars(env=%p, str=%p, isCopy=%p)", env, str, isCopy)); @@ -2679,16 +2590,15 @@ const jchar* jni_GetStringChars(JNIEnv *env, jstring str, jboolean *isCopy) // FIXME This is really ugly. return emptyStringJ; - s = (java_lang_String *) str; - - LLNI_field_get_ref(s, value, a); + java_lang_String s(str); - if (a == NULL) + java_handle_chararray_t* ca = s.get_value(); + int32_t count = s.get_count(); + int32_t offset = s.get_offset(); + + if (ca == NULL) return NULL; - LLNI_field_get_val(s, count, count); - LLNI_field_get_val(s, offset, offset); - /* allocate memory */ stringbuffer = MNEW(u2, count + 1); @@ -2696,7 +2606,7 @@ const jchar* jni_GetStringChars(JNIEnv *env, jstring str, jboolean *isCopy) /* copy text */ for (i = 0; i < count; i++) - stringbuffer[i] = LLNI_array_direct(a, offset + i); + stringbuffer[i] = LLNI_array_direct(ca, offset + i); /* terminate string */ @@ -2719,16 +2629,16 @@ const jchar* jni_GetStringChars(JNIEnv *env, jstring str, jboolean *isCopy) void _Jv_JNI_ReleaseStringChars(JNIEnv *env, jstring str, const jchar *chars) { - java_lang_String *s; - - STATISTICS(jniinvokation()); + TRACEJNICALLS(("jni_ReleaseStringChars(env=%p, str=%p, chars=%p)", env, str, chars)); + // FIXME if (chars == emptyStringJ) return; - s = (java_lang_String *) str; + java_lang_String s(str); + int32_t count = s.get_count(); - MFREE(((jchar *) chars), jchar, LLNI_field_direct(s, count) + 1); + MFREE(((jchar*) chars), jchar, count + 1); } @@ -2739,30 +2649,28 @@ void _Jv_JNI_ReleaseStringChars(JNIEnv *env, jstring str, const jchar *chars) *******************************************************************************/ -jstring _Jv_JNI_NewStringUTF(JNIEnv *env, const char *bytes) +jstring jni_NewStringUTF(JNIEnv *env, const char *bytes) { - java_lang_String *s; - - TRACEJNICALLS(("_Jv_JNI_NewStringUTF(env=%p, bytes=%s)", env, bytes)); + TRACEJNICALLS(("jni_NewStringUTF(env=%p, bytes=%s)", env, bytes)); - s = (java_lang_String *) javastring_safe_new_from_utf8(bytes); + java_handle_t *h = javastring_safe_new_from_utf8(bytes); - return (jstring) jni_NewLocalRef(env, (jobject) s); + return (jstring) jni_NewLocalRef(env, (jobject) h); } /****************** returns the utf8 length in bytes of a string *******************/ -jsize _Jv_JNI_GetStringUTFLength(JNIEnv *env, jstring string) +jsize jni_GetStringUTFLength(JNIEnv *env, jstring string) { - java_lang_String *s; - s4 length; - - TRACEJNICALLS(("_Jv_JNI_GetStringUTFLength(env=%p, string=%p)", env, string)); + TRACEJNICALLS(("jni_GetStringUTFLength(env=%p, string=%p)", env, string)); - s = (java_lang_String *) string; + java_lang_String s(string); + java_handle_chararray_t* ca = s.get_value(); + int32_t count = s.get_count(); - length = u2_utflength(LLNI_field_direct(s, value)->data, LLNI_field_direct(s, count)); + // FIXME GC critical section! + int32_t length = u2_utflength(ca->data, count); return length; } @@ -3230,19 +3138,13 @@ jint _Jv_JNI_GetJavaVM(JNIEnv *env, JavaVM **javavm) *******************************************************************************/ -void _Jv_JNI_GetStringRegion(JNIEnv* env, jstring str, jsize start, jsize len, - jchar *buf) +void jni_GetStringRegion(JNIEnv* env, jstring str, jsize start, jsize len, jchar *buf) { - java_lang_String *s; - java_handle_chararray_t *ca; - - STATISTICS(jniinvokation()); - - s = (java_lang_String *) str; - LLNI_field_get_ref(s, value, ca); + java_lang_String s(str); + java_handle_chararray_t* ca = s.get_value(); + int32_t count = s.get_count(); - if ((start < 0) || (len < 0) || (start > LLNI_field_direct(s, count)) || - (start + len > LLNI_field_direct(s, count))) { + if ((start < 0) || (len < 0) || (start > count) || (start + len > count)) { exceptions_throw_stringindexoutofboundsexception(); return; } @@ -3261,27 +3163,22 @@ void _Jv_JNI_GetStringRegion(JNIEnv* env, jstring str, jsize start, jsize len, *******************************************************************************/ -void _Jv_JNI_GetStringUTFRegion(JNIEnv* env, jstring str, jsize start, - jsize len, char *buf) +void jni_GetStringUTFRegion(JNIEnv* env, jstring str, jsize start, jsize len, char *buf) { - java_lang_String *s; - java_handle_chararray_t *ca; - s4 i; - int32_t count; - int32_t offset; - - TRACEJNICALLS(("_Jv_JNI_GetStringUTFRegion(env=%p, str=%p, start=%d, len=%d, buf=%p)", env, str, start, len, buf)); + TRACEJNICALLS(("jni_GetStringUTFRegion(env=%p, str=%p, start=%d, len=%d, buf=%p)", env, str, start, len, buf)); - s = (java_lang_String *) str; - LLNI_field_get_ref(s, value, ca); - LLNI_field_get_val(s, count, count); - LLNI_field_get_val(s, offset, offset); + java_lang_String s(str); + java_handle_chararray_t* ca = s.get_value(); + int32_t count = s.get_count(); + int32_t offset = s.get_offset(); if ((start < 0) || (len < 0) || (start > count) || (start + len > count)) { exceptions_throw_stringindexoutofboundsexception(); return; } + int32_t i; + for (i = 0; i < len; i++) buf[i] = LLNI_array_direct(ca, offset + start + i); @@ -3577,38 +3474,29 @@ jobject jni_NewDirectByteBuffer(JNIEnv *env, void *address, jlong capacity) { #if defined(ENABLE_JAVASE) # if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH) - java_handle_t *nbuf; - -# if SIZEOF_VOID_P == 8 - gnu_classpath_Pointer64 *paddress; -# else - gnu_classpath_Pointer32 *paddress; -# endif - TRACEJNICALLSENTER(("jni_NewDirectByteBuffer(env=%p, address=%p, capacity=%ld)", env, address, capacity)); - /* alocate a gnu.classpath.Pointer{32,64} object */ + // Allocate a gnu.classpath.Pointer{32,64} object. # if SIZEOF_VOID_P == 8 - if (!(paddress = (gnu_classpath_Pointer64 *) - builtin_new(class_gnu_classpath_Pointer64))) + java_handle_t* h = builtin_new(class_gnu_classpath_Pointer64); # else - if (!(paddress = (gnu_classpath_Pointer32 *) - builtin_new(class_gnu_classpath_Pointer32))) + java_handle_t* h = builtin_new(class_gnu_classpath_Pointer32); # endif - return NULL; - /* fill gnu.classpath.Pointer{32,64} with address */ + if (h == NULL) + return NULL; - LLNI_field_set_val(paddress, data, (ptrint) address); + gnu_classpath_Pointer p(h, address); - /* create a java.nio.DirectByteBufferImpl$ReadWrite object */ + // Create a java.nio.DirectByteBufferImpl$ReadWrite object. - nbuf = (java_handle_t*) jni_NewObject(env, (jclass) class_java_nio_DirectByteBufferImpl_ReadWrite, - (jmethodID) dbbirw_init, NULL, paddress, - (jint) capacity, (jint) capacity, (jint) 0); + java_handle_t* nbuf = + (java_handle_t*) jni_NewObject(env, (jclass) class_java_nio_DirectByteBufferImpl_ReadWrite, + (jmethodID) dbbirw_init, NULL, p.get_handle(), + (jint) capacity, (jint) capacity, (jint) 0); - /* add local reference and return the value */ + // Add a local reference and return the value. TRACEJNICALLSEXIT(("->%p", nbuf)); @@ -3657,55 +3545,34 @@ jobject jni_NewDirectByteBuffer(JNIEnv *env, void *address, jlong capacity) *******************************************************************************/ -void *_Jv_JNI_GetDirectBufferAddress(JNIEnv *env, jobject buf) +void* jni_GetDirectBufferAddress(JNIEnv *env, jobject buf) { #if defined(ENABLE_JAVASE) - java_handle_t *h; - # if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH) - java_nio_DirectByteBufferImpl *nbuf; - gnu_classpath_Pointer *po; -# if SIZEOF_VOID_P == 8 - gnu_classpath_Pointer64 *paddress; - int64_t address; -# else - gnu_classpath_Pointer32 *paddress; - int32_t address; -# endif - void *p; - - TRACEJNICALLSENTER(("_Jv_JNI_GetDirectBufferAddress(env=%p, buf=%p)", env, buf)); + TRACEJNICALLSENTER(("jni_GetDirectBufferAddress(env=%p, buf=%p)", env, buf)); /* Prevent compiler warning. */ - h = (java_handle_t *) buf; + java_handle_t* h = (java_handle_t *) buf; if ((h != NULL) && !builtin_instanceof(h, class_java_nio_Buffer)) return NULL; - nbuf = (java_nio_DirectByteBufferImpl *) buf; - - LLNI_field_get_ref(nbuf, address, po); + java_nio_DirectByteBufferImpl dbb(buf); + java_handle_t* address = dbb.get_address(); -# if SIZEOF_VOID_P == 8 - paddress = (gnu_classpath_Pointer64 *) po; -# else - paddress = (gnu_classpath_Pointer32 *) po; -# endif - - if (paddress == NULL) { + if (address == NULL) { TRACEJNICALLSEXIT(("->%p", NULL)); return NULL; } - LLNI_field_get_val(paddress, data, address); - - p = (void *) (intptr_t) address; + gnu_classpath_Pointer p(address); + void* data = p.get_data(); - TRACEJNICALLSEXIT(("->%p", p)); + TRACEJNICALLSEXIT(("->%p", data)); - return p; + return data; # elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK) @@ -3753,29 +3620,24 @@ void *_Jv_JNI_GetDirectBufferAddress(JNIEnv *env, jobject buf) *******************************************************************************/ -jlong _Jv_JNI_GetDirectBufferCapacity(JNIEnv* env, jobject buf) +jlong jni_GetDirectBufferCapacity(JNIEnv* env, jobject buf) { #if defined(ENABLE_JAVASE) && defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH) - java_handle_t *o; - java_nio_Buffer *nbuf; - jlong capacity; - - STATISTICS(jniinvokation()); + TRACEJNICALLS(("jni_GetDirectBufferCapacity(env=%p, buf=%p)", env, buf)); - o = (java_handle_t *) buf; + java_handle_t* h = (java_handle_t *) buf; - if (!builtin_instanceof(o, class_java_nio_DirectByteBufferImpl)) + if (!builtin_instanceof(h, class_java_nio_DirectByteBufferImpl)) return -1; - nbuf = (java_nio_Buffer *) o; - - LLNI_field_get_val(nbuf, cap, capacity); + java_nio_Buffer b(h); + jlong capacity = b.get_cap(); return capacity; #else - vm_abort("_Jv_JNI_GetDirectBufferCapacity: not implemented in this configuration"); + vm_abort("jni_GetDirectBufferCapacity: not implemented in this configuration"); - /* keep compiler happy */ + // Keep compiler happy. return 0; #endif @@ -4036,12 +3898,12 @@ struct JNINativeInterface_ _Jv_JNINativeInterface = { NULL, _Jv_JNI_GetVersion, - _Jv_JNI_DefineClass, + jni_DefineClass, jni_FindClass, jni_FromReflectedMethod, jni_FromReflectedField, - _Jv_JNI_ToReflectedMethod, - _Jv_JNI_GetSuperclass, + jni_ToReflectedMethod, + jni_GetSuperclass, _Jv_JNI_IsAssignableFrom, _Jv_JNI_ToReflectedField, @@ -4066,7 +3928,7 @@ struct JNINativeInterface_ _Jv_JNINativeInterface = { _Jv_JNI_NewObjectV, _Jv_JNI_NewObjectA, - _Jv_JNI_GetObjectClass, + jni_GetObjectClass, _Jv_JNI_IsInstanceOf, _Jv_JNI_GetMethodID, @@ -4208,13 +4070,13 @@ struct JNINativeInterface_ _Jv_JNINativeInterface = { _Jv_JNI_SetStaticFloatField, _Jv_JNI_SetStaticDoubleField, - _Jv_JNI_NewString, - _Jv_JNI_GetStringLength, + jni_NewString, + jni_GetStringLength, jni_GetStringChars, _Jv_JNI_ReleaseStringChars, - _Jv_JNI_NewStringUTF, - _Jv_JNI_GetStringUTFLength, + jni_NewStringUTF, + jni_GetStringUTFLength, _Jv_JNI_GetStringUTFChars, _Jv_JNI_ReleaseStringUTFChars, @@ -4278,8 +4140,8 @@ struct JNINativeInterface_ _Jv_JNINativeInterface = { /* New JNI 1.2 functions. */ - _Jv_JNI_GetStringRegion, - _Jv_JNI_GetStringUTFRegion, + jni_GetStringRegion, + jni_GetStringUTFRegion, jni_GetPrimitiveArrayCritical, jni_ReleasePrimitiveArrayCritical, @@ -4295,8 +4157,8 @@ struct JNINativeInterface_ _Jv_JNINativeInterface = { /* New JNI 1.4 functions. */ jni_NewDirectByteBuffer, - _Jv_JNI_GetDirectBufferAddress, - _Jv_JNI_GetDirectBufferCapacity, + jni_GetDirectBufferAddress, + jni_GetDirectBufferCapacity, /* New JNI 1.6 functions. */ @@ -4393,7 +4255,7 @@ jint JNI_CreateJavaVM(JavaVM **p_vm, void **p_env, void *vm_args) * Emacs will automagically detect them. * --------------------------------------------------------------------- * Local variables: - * mode: c + * mode: c++ * indent-tabs-mode: t * c-basic-offset: 4 * tab-width: 4 diff --git a/src/native/llni.h b/src/native/llni.h index 85162111d..d36381d4b 100644 --- a/src/native/llni.h +++ b/src/native/llni.h @@ -147,7 +147,7 @@ extern "C" { *******************************************************************************/ #define LLNI_classinfo_wrap(classinfo) \ - ((java_lang_Class *) LLNI_WRAP(classinfo)) + ((java_handle_t*) LLNI_WRAP(classinfo)) #define LLNI_classinfo_unwrap(clazz) \ ((classinfo *) LLNI_UNWRAP((java_handle_t *) (clazz))) diff --git a/src/native/vm/Makefile.am b/src/native/vm/Makefile.am index a5e873ef1..f819ead80 100644 --- a/src/native/vm/Makefile.am +++ b/src/native/vm/Makefile.am @@ -55,9 +55,9 @@ NATIVEVM_LIB = \ endif if ENABLE_JAVASE -REFLECT_SOURCES = \ - reflect.c \ - reflect.h +REFLECTION_SOURCES = \ + reflection.c \ + reflection.h SUN_MISC_UNSAFE_SOURCES = \ sun_misc_Unsafe.cpp @@ -69,7 +69,7 @@ noinst_LTLIBRARIES = \ libnativevm_la_SOURCES = \ nativevm.c \ nativevm.h \ - $(REFLECT_SOURCES) \ + $(REFLECTION_SOURCES) \ $(SUN_MISC_UNSAFE_SOURCES) libnativevm_la_LIBADD = \ diff --git a/src/native/vm/gnuclasspath/gnu_classpath_VMStackWalker.cpp b/src/native/vm/gnuclasspath/gnu_classpath_VMStackWalker.cpp index a9a7b2850..a0b58becf 100644 --- a/src/native/vm/gnuclasspath/gnu_classpath_VMStackWalker.cpp +++ b/src/native/vm/gnuclasspath/gnu_classpath_VMStackWalker.cpp @@ -30,13 +30,9 @@ #include "native/jni.h" #include "native/native.h" -#include "native/include/java_lang_Class.h" -#include "native/include/java_lang_ClassLoader.h" - -// FIXME -extern "C" { -#include "native/include/gnu_classpath_VMStackWalker.h" -} +#if defined(ENABLE_JNI_HEADERS) +# include "native/vm/include/gnu_classpath_VMStackWalker.h" +#endif #include "vm/global.h" @@ -54,13 +50,13 @@ extern "C" { * Method: getClassContext * Signature: ()[Ljava/lang/Class; */ -JNIEXPORT java_handle_objectarray_t* JNICALL Java_gnu_classpath_VMStackWalker_getClassContext(JNIEnv *env, jclass clazz) +JNIEXPORT jobjectArray JNICALL Java_gnu_classpath_VMStackWalker_getClassContext(JNIEnv *env, jclass clazz) { java_handle_objectarray_t *oa; oa = stacktrace_getClassContext(); - return oa; + return (jobjectArray) oa; } @@ -69,13 +65,13 @@ JNIEXPORT java_handle_objectarray_t* JNICALL Java_gnu_classpath_VMStackWalker_ge * Method: getCallingClass * Signature: ()Ljava/lang/Class; */ -JNIEXPORT java_lang_Class* JNICALL Java_gnu_classpath_VMStackWalker_getCallingClass(JNIEnv *env, jclass clazz) +JNIEXPORT jclass JNICALL Java_gnu_classpath_VMStackWalker_getCallingClass(JNIEnv *env, jclass clazz) { classinfo *c; c = stacktrace_get_caller_class(2); - return (java_lang_Class *) c; + return (jclass) c; } @@ -84,7 +80,7 @@ JNIEXPORT java_lang_Class* JNICALL Java_gnu_classpath_VMStackWalker_getCallingCl * Method: getCallingClassLoader * Signature: ()Ljava/lang/ClassLoader; */ -JNIEXPORT java_lang_ClassLoader* JNICALL Java_gnu_classpath_VMStackWalker_getCallingClassLoader(JNIEnv *env, jclass clazz) +JNIEXPORT jobject JNICALL Java_gnu_classpath_VMStackWalker_getCallingClassLoader(JNIEnv *env, jclass clazz) { classinfo *c; classloader_t *cl; @@ -92,7 +88,7 @@ JNIEXPORT java_lang_ClassLoader* JNICALL Java_gnu_classpath_VMStackWalker_getCal c = stacktrace_get_caller_class(2); cl = class_get_classloader(c); - return (java_lang_ClassLoader *) cl; + return (jobject) cl; } @@ -101,13 +97,13 @@ JNIEXPORT java_lang_ClassLoader* JNICALL Java_gnu_classpath_VMStackWalker_getCal * Method: firstNonNullClassLoader * Signature: ()Ljava/lang/ClassLoader; */ -JNIEXPORT java_lang_ClassLoader* JNICALL Java_gnu_classpath_VMStackWalker_firstNonNullClassLoader(JNIEnv *env, jclass clazz) +JNIEXPORT jobject JNICALL Java_gnu_classpath_VMStackWalker_firstNonNullClassLoader(JNIEnv *env, jclass clazz) { classloader_t *cl; cl = stacktrace_first_nonnull_classloader(); - return (java_lang_ClassLoader *) cl; + return (jobject) cl; } } // extern "C" diff --git a/src/native/vm/gnuclasspath/gnu_classpath_VMSystemProperties.cpp b/src/native/vm/gnuclasspath/gnu_classpath_VMSystemProperties.cpp index d93127d54..ebd09b040 100644 --- a/src/native/vm/gnuclasspath/gnu_classpath_VMSystemProperties.cpp +++ b/src/native/vm/gnuclasspath/gnu_classpath_VMSystemProperties.cpp @@ -35,12 +35,9 @@ #include "native/jni.h" #include "native/native.h" -#include "native/include/java_util_Properties.h" - -/// FIXME -extern "C" { -#include "native/include/gnu_classpath_VMSystemProperties.h" -} +#if defined(ENABLE_JNI_HEADERS) +# include "native/include/gnu_classpath_VMSystemProperties.h" +#endif #include "vm/exceptions.hpp" #include "vm/properties.h" @@ -55,7 +52,7 @@ extern "C" { * Method: preInit * Signature: (Ljava/util/Properties;)V */ -JNIEXPORT void JNICALL Java_gnu_classpath_VMSystemProperties_preInit(JNIEnv *env, jclass clazz, java_util_Properties *properties) +JNIEXPORT void JNICALL Java_gnu_classpath_VMSystemProperties_preInit(JNIEnv *env, jclass clazz, jobject properties) { java_handle_t *p; @@ -77,7 +74,7 @@ JNIEXPORT void JNICALL Java_gnu_classpath_VMSystemProperties_preInit(JNIEnv *env * Method: postInit * Signature: (Ljava/util/Properties;)V */ -JNIEXPORT void JNICALL Java_gnu_classpath_VMSystemProperties_postInit(JNIEnv *env, jclass clazz, java_util_Properties *properties) +JNIEXPORT void JNICALL Java_gnu_classpath_VMSystemProperties_postInit(JNIEnv *env, jclass clazz, jobject properties) { java_handle_t *p; #if defined(ENABLE_JRE_LAYOUT) diff --git a/src/native/vm/gnuclasspath/gnu_java_lang_VMCPStringBuilder.cpp b/src/native/vm/gnuclasspath/gnu_java_lang_VMCPStringBuilder.cpp index dbde800cf..f760417d2 100644 --- a/src/native/vm/gnuclasspath/gnu_java_lang_VMCPStringBuilder.cpp +++ b/src/native/vm/gnuclasspath/gnu_java_lang_VMCPStringBuilder.cpp @@ -31,17 +31,14 @@ #include "native/llni.h" #include "native/native.h" -#include "native/include/java_lang_String.h" - // FIXME -extern "C" { -#include "native/include/gnu_java_lang_VMCPStringBuilder.h" -} +//#include "native/include/gnu_java_lang_VMCPStringBuilder.h" #include "vm/builtin.h" #include "vm/exceptions.hpp" #include "vmcore/globals.hpp" +#include "vmcore/javaobjects.hpp" /* @@ -49,12 +46,8 @@ extern "C" { * Method: toString * Signature: ([CII)Ljava/lang/String; */ -JNIEXPORT java_lang_String* JNICALL Java_gnu_java_lang_VMCPStringBuilder_toString(JNIEnv *env, jclass clazz, java_handle_chararray_t *value, int32_t startIndex, int32_t count) +JNIEXPORT jstring JNICALL Java_gnu_java_lang_VMCPStringBuilder_toString(JNIEnv *env, jclass clazz, jcharArray value, jint startIndex, jint count) { - int32_t length; - java_handle_t *o; - java_lang_String *s; - /* This is a native version of java.lang.String.([CIIZ)Ljava/lang/String; */ @@ -72,8 +65,10 @@ JNIEXPORT java_lang_String* JNICALL Java_gnu_java_lang_VMCPStringBuilder_toStrin /* equivalent to: offset + count < 0 || offset + count > data.length */ + java_handle_chararray_t* ca = (java_handle_chararray_t*) value; + LLNI_CRITICAL_START; - length = LLNI_array_size(value); + int32_t length = LLNI_array_size(ca); LLNI_CRITICAL_END; if (length - startIndex < count) { @@ -82,18 +77,14 @@ JNIEXPORT java_lang_String* JNICALL Java_gnu_java_lang_VMCPStringBuilder_toStrin return NULL; } - o = builtin_new(class_java_lang_String); + java_handle_t* h = builtin_new(class_java_lang_String); - if (o == NULL) + if (h == NULL) return NULL; - s = (java_lang_String *) o; - - LLNI_field_set_ref(s, value, value); - LLNI_field_set_val(s, count, count); - LLNI_field_set_val(s, offset, startIndex); + java_lang_String s(h, ca, (int32_t) count, (int32_t) startIndex); - return s; + return (jstring) s.get_handle(); } diff --git a/src/native/vm/gnuclasspath/gnu_java_lang_management_VMClassLoadingMXBeanImpl.cpp b/src/native/vm/gnuclasspath/gnu_java_lang_management_VMClassLoadingMXBeanImpl.cpp index b39b8c043..dc70fe7ad 100644 --- a/src/native/vm/gnuclasspath/gnu_java_lang_management_VMClassLoadingMXBeanImpl.cpp +++ b/src/native/vm/gnuclasspath/gnu_java_lang_management_VMClassLoadingMXBeanImpl.cpp @@ -32,10 +32,9 @@ #include "native/jni.h" #include "native/native.h" -// FIXME -extern "C" { -#include "native/include/gnu_java_lang_management_VMClassLoadingMXBeanImpl.h" -} +#if defined(ENABLE_JNI_HEADERS) +# include "native/vm/include/gnu_java_lang_management_VMClassLoadingMXBeanImpl.h" +#endif #include "toolbox/logging.h" @@ -53,7 +52,7 @@ extern "C" { * Method: getLoadedClassCount * Signature: ()I */ -JNIEXPORT int32_t JNICALL Java_gnu_java_lang_management_VMClassLoadingMXBeanImpl_getLoadedClassCount(JNIEnv *env, jclass clazz) +JNIEXPORT jint JNICALL Java_gnu_java_lang_management_VMClassLoadingMXBeanImpl_getLoadedClassCount(JNIEnv *env, jclass clazz) { int32_t count; @@ -68,7 +67,7 @@ JNIEXPORT int32_t JNICALL Java_gnu_java_lang_management_VMClassLoadingMXBeanImpl * Method: getUnloadedClassCount * Signature: ()J */ -JNIEXPORT int64_t JNICALL Java_gnu_java_lang_management_VMClassLoadingMXBeanImpl_getUnloadedClassCount(JNIEnv *env, jclass clazz) +JNIEXPORT jlong JNICALL Java_gnu_java_lang_management_VMClassLoadingMXBeanImpl_getUnloadedClassCount(JNIEnv *env, jclass clazz) { log_println("Java_gnu_java_lang_management_VMClassLoadingMXBeanImpl_getUnloadedClassCount: IMPLEMENT ME!"); @@ -81,7 +80,7 @@ JNIEXPORT int64_t JNICALL Java_gnu_java_lang_management_VMClassLoadingMXBeanImpl * Method: isVerbose * Signature: ()Z */ -JNIEXPORT int32_t JNICALL Java_gnu_java_lang_management_VMClassLoadingMXBeanImpl_isVerbose(JNIEnv *env, jclass clazz) +JNIEXPORT jboolean JNICALL Java_gnu_java_lang_management_VMClassLoadingMXBeanImpl_isVerbose(JNIEnv *env, jclass clazz) { /* return _Jv_jvm->Java_gnu_java_lang_management_VMClassLoadingMXBeanImpl_verbose; */ #warning Move to C++ @@ -94,7 +93,7 @@ JNIEXPORT int32_t JNICALL Java_gnu_java_lang_management_VMClassLoadingMXBeanImpl * Method: setVerbose * Signature: (Z)V */ -JNIEXPORT void JNICALL Java_gnu_java_lang_management_VMClassLoadingMXBeanImpl_setVerbose(JNIEnv *env, jclass clazz, int32_t verbose) +JNIEXPORT void JNICALL Java_gnu_java_lang_management_VMClassLoadingMXBeanImpl_setVerbose(JNIEnv *env, jclass clazz, jboolean verbose) { /* _Jv_jvm->Java_gnu_java_lang_management_VMClassLoadingMXBeanImpl_verbose = verbose; */ #warning Move to C++ diff --git a/src/native/vm/gnuclasspath/gnu_java_lang_management_VMMemoryMXBeanImpl.cpp b/src/native/vm/gnuclasspath/gnu_java_lang_management_VMMemoryMXBeanImpl.cpp index d3910a970..f375a7f17 100644 --- a/src/native/vm/gnuclasspath/gnu_java_lang_management_VMMemoryMXBeanImpl.cpp +++ b/src/native/vm/gnuclasspath/gnu_java_lang_management_VMMemoryMXBeanImpl.cpp @@ -32,12 +32,9 @@ #include "native/jni.h" #include "native/native.h" -#include "native/include/java_lang_management_MemoryUsage.h" - -// FIXME -extern "C" { -#include "native/include/gnu_java_lang_management_VMMemoryMXBeanImpl.h" -} +#if defined(ENABLE_JNI_HEADERS) +# include "native/vm/include/gnu_java_lang_management_VMMemoryMXBeanImpl.h" +#endif #include "vm/builtin.h" #include "vm/global.h" @@ -56,16 +53,15 @@ extern "C" { * Method: getHeapMemoryUsage * Signature: ()Ljava/lang/management/MemoryUsage; */ -JNIEXPORT java_lang_management_MemoryUsage* JNICALL Java_gnu_java_lang_management_VMMemoryMXBeanImpl_getHeapMemoryUsage(JNIEnv *env, jclass clazz) +JNIEXPORT jobject JNICALL Java_gnu_java_lang_management_VMMemoryMXBeanImpl_getHeapMemoryUsage(JNIEnv *env, jclass clazz) { - classinfo *class_java_lang_management_MemoryUsage; - java_handle_t *o; - java_lang_management_MemoryUsage *mu; - methodinfo *m; - int64_t init; - int64_t used; - int64_t commited; - int64_t maximum; + classinfo *class_java_lang_management_MemoryUsage; + java_handle_t *o; + methodinfo *m; + int64_t init; + int64_t used; + int64_t commited; + int64_t maximum; /* get the class */ /* XXX optimize me! sometime... */ @@ -80,10 +76,6 @@ JNIEXPORT java_lang_management_MemoryUsage* JNICALL Java_gnu_java_lang_managemen if (o == NULL) return NULL; - /* cast the object to a MemoryUsage object (for debugability) */ - - mu = (java_lang_management_MemoryUsage *) o; - /* find initializer */ m = class_findmethod(class_java_lang_management_MemoryUsage, @@ -106,7 +98,7 @@ JNIEXPORT java_lang_management_MemoryUsage* JNICALL Java_gnu_java_lang_managemen (void) vm_call_method(m, o, init, used, commited, maximum); - return mu; + return (jobject) o; } @@ -115,7 +107,7 @@ JNIEXPORT java_lang_management_MemoryUsage* JNICALL Java_gnu_java_lang_managemen * Method: getNonHeapMemoryUsage * Signature: ()Ljava/lang/management/MemoryUsage; */ -JNIEXPORT java_lang_management_MemoryUsage* JNICALL Java_gnu_java_lang_management_VMMemoryMXBeanImpl_getNonHeapMemoryUsage(JNIEnv *env, jclass clazz) +JNIEXPORT jobject JNICALL Java_gnu_java_lang_management_VMMemoryMXBeanImpl_getNonHeapMemoryUsage(JNIEnv *env, jclass clazz) { log_println("Java_gnu_java_lang_management_VMMemoryMXBeanImpl_getNonHeapMemoryUsage: IMPLEMENT ME!"); @@ -128,7 +120,7 @@ JNIEXPORT java_lang_management_MemoryUsage* JNICALL Java_gnu_java_lang_managemen * Method: getObjectPendingFinalizationCount * Signature: ()I */ -JNIEXPORT int32_t JNICALL Java_gnu_java_lang_management_VMMemoryMXBeanImpl_getObjectPendingFinalizationCount(JNIEnv *env, jclass clazz) +JNIEXPORT jint JNICALL Java_gnu_java_lang_management_VMMemoryMXBeanImpl_getObjectPendingFinalizationCount(JNIEnv *env, jclass clazz) { log_println("Java_gnu_java_lang_management_VMMemoryMXBeanImpl_getObjectPendingFinalizationCount: IMPLEMENT ME!"); @@ -141,7 +133,7 @@ JNIEXPORT int32_t JNICALL Java_gnu_java_lang_management_VMMemoryMXBeanImpl_getOb * Method: isVerbose * Signature: ()Z */ -JNIEXPORT int32_t JNICALL Java_gnu_java_lang_management_VMMemoryMXBeanImpl_isVerbose(JNIEnv *env, jclass clazz) +JNIEXPORT jboolean JNICALL Java_gnu_java_lang_management_VMMemoryMXBeanImpl_isVerbose(JNIEnv *env, jclass clazz) { /* return _Jv_jvm->Java_gnu_java_lang_management_VMMemoryMXBeanImpl_verbose; */ #warning Move to C++ @@ -155,7 +147,7 @@ JNIEXPORT int32_t JNICALL Java_gnu_java_lang_management_VMMemoryMXBeanImpl_isVer * Method: setVerbose * Signature: (Z)V */ -JNIEXPORT void JNICALL Java_gnu_java_lang_management_VMMemoryMXBeanImpl_setVerbose(JNIEnv *env, jclass clazz, int32_t verbose) +JNIEXPORT void JNICALL Java_gnu_java_lang_management_VMMemoryMXBeanImpl_setVerbose(JNIEnv *env, jclass clazz, jboolean verbose) { /* _Jv_jvm->Java_gnu_java_lang_management_VMMemoryMXBeanImpl_verbose = verbose; */ #warning Move to C++ diff --git a/src/native/vm/gnuclasspath/gnu_java_lang_management_VMRuntimeMXBeanImpl.cpp b/src/native/vm/gnuclasspath/gnu_java_lang_management_VMRuntimeMXBeanImpl.cpp index 5eadcc52e..ec7061413 100644 --- a/src/native/vm/gnuclasspath/gnu_java_lang_management_VMRuntimeMXBeanImpl.cpp +++ b/src/native/vm/gnuclasspath/gnu_java_lang_management_VMRuntimeMXBeanImpl.cpp @@ -30,10 +30,9 @@ #include "native/jni.h" #include "native/native.h" -// FIXME -extern "C" { -#include "native/include/gnu_java_lang_management_VMRuntimeMXBeanImpl.h" -} +#if defined(ENABLE_JNI_HEADERS) +# include "native/vm/include/gnu_java_lang_management_VMRuntimeMXBeanImpl.h" +#endif #include "vm/builtin.h" #include "vm/global.h" diff --git a/src/native/vm/gnuclasspath/gnu_java_lang_management_VMThreadMXBeanImpl.cpp b/src/native/vm/gnuclasspath/gnu_java_lang_management_VMThreadMXBeanImpl.cpp index de5132b4a..b54481321 100644 --- a/src/native/vm/gnuclasspath/gnu_java_lang_management_VMThreadMXBeanImpl.cpp +++ b/src/native/vm/gnuclasspath/gnu_java_lang_management_VMThreadMXBeanImpl.cpp @@ -32,13 +32,9 @@ #include "native/jni.h" #include "native/native.h" -#include "native/include/java_lang_Throwable.h" -#include "native/include/java_lang_management_ThreadInfo.h" - -// FIXME -extern "C" { -#include "native/include/gnu_java_lang_management_VMThreadMXBeanImpl.h" -} +#if defined(ENABLE_JNI_HEADERS) +# include "native/vm/include/gnu_java_lang_management_VMThreadMXBeanImpl.h" +#endif #include "toolbox/logging.h" @@ -56,7 +52,7 @@ extern "C" { * Method: findMonitorDeadlockedThreads * Signature: ()[J */ -JNIEXPORT java_handle_longarray_t* JNICALL Java_gnu_java_lang_management_VMThreadMXBeanImpl_findMonitorDeadlockedThreads(JNIEnv *env, jclass clazz) +JNIEXPORT jlongArray JNICALL Java_gnu_java_lang_management_VMThreadMXBeanImpl_findMonitorDeadlockedThreads(JNIEnv *env, jclass clazz) { log_println("Java_gnu_java_lang_management_VMThreadMXBeanImpl_findMonitorDeadlockedThreads: IMPLEMENT ME!"); @@ -69,7 +65,7 @@ JNIEXPORT java_handle_longarray_t* JNICALL Java_gnu_java_lang_management_VMThrea * Method: getCurrentThreadCpuTime * Signature: ()J */ -JNIEXPORT int64_t JNICALL Java_gnu_java_lang_management_VMThreadMXBeanImpl_getCurrentThreadCpuTime(JNIEnv *env, jclass clazz) +JNIEXPORT jlong JNICALL Java_gnu_java_lang_management_VMThreadMXBeanImpl_getCurrentThreadCpuTime(JNIEnv *env, jclass clazz) { log_println("Java_gnu_java_lang_management_VMThreadMXBeanImpl_getCurrentThreadCpuTime: IMPLEMENT ME!"); @@ -82,7 +78,7 @@ JNIEXPORT int64_t JNICALL Java_gnu_java_lang_management_VMThreadMXBeanImpl_getCu * Method: getCurrentThreadUserTime * Signature: ()J */ -JNIEXPORT int64_t JNICALL Java_gnu_java_lang_management_VMThreadMXBeanImpl_getCurrentThreadUserTime(JNIEnv *env, jclass clazz) +JNIEXPORT jlong JNICALL Java_gnu_java_lang_management_VMThreadMXBeanImpl_getCurrentThreadUserTime(JNIEnv *env, jclass clazz) { log_println("Java_gnu_java_lang_management_VMThreadMXBeanImpl_getCurrentThreadUserTime: IMPLEMENT ME!"); @@ -95,7 +91,7 @@ JNIEXPORT int64_t JNICALL Java_gnu_java_lang_management_VMThreadMXBeanImpl_getCu * Method: getPeakThreadCount * Signature: ()I */ -JNIEXPORT int32_t JNICALL Java_gnu_java_lang_management_VMThreadMXBeanImpl_getPeakThreadCount(JNIEnv *env, jclass clazz) +JNIEXPORT jint JNICALL Java_gnu_java_lang_management_VMThreadMXBeanImpl_getPeakThreadCount(JNIEnv *env, jclass clazz) { /* return _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount; */ #warning Move to C++ @@ -109,7 +105,7 @@ JNIEXPORT int32_t JNICALL Java_gnu_java_lang_management_VMThreadMXBeanImpl_getPe * Method: getThreadCpuTime * Signature: (J)J */ -JNIEXPORT int64_t JNICALL Java_gnu_java_lang_management_VMThreadMXBeanImpl_getThreadCpuTime(JNIEnv *env, jclass clazz, int64_t id) +JNIEXPORT jlong JNICALL Java_gnu_java_lang_management_VMThreadMXBeanImpl_getThreadCpuTime(JNIEnv *env, jclass clazz, jlong id) { log_println("Java_gnu_java_lang_management_VMThreadMXBeanImpl_getThreadCpuTime: IMPLEMENT ME!"); @@ -122,7 +118,7 @@ JNIEXPORT int64_t JNICALL Java_gnu_java_lang_management_VMThreadMXBeanImpl_getTh * Method: getThreadInfoForId * Signature: (JI)Ljava/lang/management/ThreadInfo; */ -JNIEXPORT java_lang_management_ThreadInfo* JNICALL Java_gnu_java_lang_management_VMThreadMXBeanImpl_getThreadInfoForId(JNIEnv *env, jclass clazz, int64_t id, int32_t maxDepth) +JNIEXPORT jobject JNICALL Java_gnu_java_lang_management_VMThreadMXBeanImpl_getThreadInfoForId(JNIEnv *env, jclass clazz, jlong id, jint maxDepth) { log_println("Java_gnu_java_lang_management_VMThreadMXBeanImpl_getThreadInfoForId: IMPLEMENT ME!"); @@ -135,7 +131,7 @@ JNIEXPORT java_lang_management_ThreadInfo* JNICALL Java_gnu_java_lang_management * Method: getThreadUserTime * Signature: (J)J */ -JNIEXPORT int64_t JNICALL Java_gnu_java_lang_management_VMThreadMXBeanImpl_getThreadUserTime(JNIEnv *env, jclass clazz, int64_t par1) +JNIEXPORT jlong JNICALL Java_gnu_java_lang_management_VMThreadMXBeanImpl_getThreadUserTime(JNIEnv *env, jclass clazz, jlong par1) { log_println("Java_gnu_java_lang_management_VMThreadMXBeanImpl_getThreadUserTime: IMPLEMENT ME!"); @@ -148,7 +144,7 @@ JNIEXPORT int64_t JNICALL Java_gnu_java_lang_management_VMThreadMXBeanImpl_getTh * Method: getTotalStartedThreadCount * Signature: ()J */ -JNIEXPORT int64_t JNICALL Java_gnu_java_lang_management_VMThreadMXBeanImpl_getTotalStartedThreadCount(JNIEnv *env, jclass clazz) +JNIEXPORT jlong JNICALL Java_gnu_java_lang_management_VMThreadMXBeanImpl_getTotalStartedThreadCount(JNIEnv *env, jclass clazz) { /* return _Jv_jvm->java_lang_management_ThreadMXBean_TotalStartedThreadCount; */ #warning Move to C++ diff --git a/src/native/vm/gnuclasspath/java_lang_VMClass.cpp b/src/native/vm/gnuclasspath/java_lang_VMClass.cpp index 0714944b2..8e7e6cd14 100644 --- a/src/native/vm/gnuclasspath/java_lang_VMClass.cpp +++ b/src/native/vm/gnuclasspath/java_lang_VMClass.cpp @@ -31,18 +31,8 @@ #include "native/llni.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_String.h" -#include "native/include/java_lang_Throwable.h" -#include "native/include/java_lang_reflect_Constructor.h" -#include "native/include/java_lang_reflect_Method.h" - -//FIXME -extern "C" { -#include "native/include/java_lang_VMClass.h" -} +// FIXME +//#include "native/include/java_lang_VMClass.h" #include "vm/exceptions.hpp" #include "vm/initialize.h" @@ -50,69 +40,15 @@ extern "C" { #include "vmcore/class.h" #include "vmcore/globals.hpp" +#include "vmcore/javaobjects.hpp" #if defined(ENABLE_ANNOTATIONS) -#include "native/include/sun_reflect_ConstantPool.h" - #include "vm/vm.hpp" #include "vmcore/annotation.h" #endif -/* native methods implemented by this file ************************************/ - -static JNINativeMethod methods[] = { - { (char*) "isInstance", (char*) "(Ljava/lang/Class;Ljava/lang/Object;)Z", (void*) (uintptr_t) &Java_java_lang_VMClass_isInstance }, - { (char*) "isAssignableFrom", (char*) "(Ljava/lang/Class;Ljava/lang/Class;)Z", (void*) (uintptr_t) &Java_java_lang_VMClass_isAssignableFrom }, - { (char*) "isInterface", (char*) "(Ljava/lang/Class;)Z", (void*) (uintptr_t) &Java_java_lang_VMClass_isInterface }, - { (char*) "isPrimitive", (char*) "(Ljava/lang/Class;)Z", (void*) (uintptr_t) &Java_java_lang_VMClass_isPrimitive }, - { (char*) "getName", (char*) "(Ljava/lang/Class;)Ljava/lang/String;", (void*) (uintptr_t) &Java_java_lang_VMClass_getName }, - { (char*) "getSuperclass", (char*) "(Ljava/lang/Class;)Ljava/lang/Class;", (void*) (uintptr_t) &Java_java_lang_VMClass_getSuperclass }, - { (char*) "getInterfaces", (char*) "(Ljava/lang/Class;)[Ljava/lang/Class;", (void*) (uintptr_t) &Java_java_lang_VMClass_getInterfaces }, - { (char*) "getComponentType", (char*) "(Ljava/lang/Class;)Ljava/lang/Class;", (void*) (uintptr_t) &Java_java_lang_VMClass_getComponentType }, - { (char*) "getModifiers", (char*) "(Ljava/lang/Class;Z)I", (void*) (uintptr_t) &Java_java_lang_VMClass_getModifiers }, - { (char*) "getDeclaringClass", (char*) "(Ljava/lang/Class;)Ljava/lang/Class;", (void*) (uintptr_t) &Java_java_lang_VMClass_getDeclaringClass }, - { (char*) "getDeclaredClasses", (char*) "(Ljava/lang/Class;Z)[Ljava/lang/Class;", (void*) (uintptr_t) &Java_java_lang_VMClass_getDeclaredClasses }, - { (char*) "getDeclaredFields", (char*) "(Ljava/lang/Class;Z)[Ljava/lang/reflect/Field;", (void*) (uintptr_t) &Java_java_lang_VMClass_getDeclaredFields }, - { (char*) "getDeclaredMethods", (char*) "(Ljava/lang/Class;Z)[Ljava/lang/reflect/Method;", (void*) (uintptr_t) &Java_java_lang_VMClass_getDeclaredMethods }, - { (char*) "getDeclaredConstructors", (char*) "(Ljava/lang/Class;Z)[Ljava/lang/reflect/Constructor;", (void*) (uintptr_t) &Java_java_lang_VMClass_getDeclaredConstructors }, - { (char*) "getClassLoader", (char*) "(Ljava/lang/Class;)Ljava/lang/ClassLoader;", (void*) (uintptr_t) &Java_java_lang_VMClass_getClassLoader }, - { (char*) "forName", (char*) "(Ljava/lang/String;ZLjava/lang/ClassLoader;)Ljava/lang/Class;", (void*) (uintptr_t) &Java_java_lang_VMClass_forName }, - { (char*) "isArray", (char*) "(Ljava/lang/Class;)Z", (void*) (uintptr_t) &Java_java_lang_VMClass_isArray }, - { (char*) "throwException", (char*) "(Ljava/lang/Throwable;)V", (void*) (uintptr_t) &Java_java_lang_VMClass_throwException }, -#if defined(ENABLE_ANNOTATIONS) - { (char*) "getDeclaredAnnotations", (char*) "(Ljava/lang/Class;)[Ljava/lang/annotation/Annotation;", (void*) (uintptr_t) &Java_java_lang_VMClass_getDeclaredAnnotations }, -#endif - { (char*) "getEnclosingClass", (char*) "(Ljava/lang/Class;)Ljava/lang/Class;", (void*) (uintptr_t) &Java_java_lang_VMClass_getEnclosingClass }, - { (char*) "getEnclosingConstructor", (char*) "(Ljava/lang/Class;)Ljava/lang/reflect/Constructor;", (void*) (uintptr_t) &Java_java_lang_VMClass_getEnclosingConstructor }, - { (char*) "getEnclosingMethod", (char*) "(Ljava/lang/Class;)Ljava/lang/reflect/Method;", (void*) (uintptr_t) &Java_java_lang_VMClass_getEnclosingMethod }, - { (char*) "getClassSignature", (char*) "(Ljava/lang/Class;)Ljava/lang/String;", (void*) (uintptr_t) &Java_java_lang_VMClass_getClassSignature }, - { (char*) "isAnonymousClass", (char*) "(Ljava/lang/Class;)Z", (void*) (uintptr_t) &Java_java_lang_VMClass_isAnonymousClass }, - { (char*) "isLocalClass", (char*) "(Ljava/lang/Class;)Z", (void*) (uintptr_t) &Java_java_lang_VMClass_isLocalClass }, - { (char*) "isMemberClass", (char*) "(Ljava/lang/Class;)Z", (void*) (uintptr_t) &Java_java_lang_VMClass_isMemberClass }, -}; - - -/* _Jv_java_lang_VMClass_init ************************************************** - - Register native functions. - -*******************************************************************************/ - -// FIXME -extern "C" { -void _Jv_java_lang_VMClass_init(void) -{ - utf *u; - - u = utf_new_char("java/lang/VMClass"); - - native_method_register(u, methods, NATIVE_METHODS_COUNT); -} -} - - // Native functions are exported as C functions. extern "C" { @@ -121,7 +57,7 @@ extern "C" { * Method: isInstance * Signature: (Ljava/lang/Class;Ljava/lang/Object;)Z */ -JNIEXPORT int32_t JNICALL Java_java_lang_VMClass_isInstance(JNIEnv *env, jclass clazz, java_lang_Class *klass, java_lang_Object *o) +JNIEXPORT jboolean JNICALL Java_java_lang_VMClass_isInstance(JNIEnv *env, jclass clazz, jclass klass, jobject o) { classinfo *c; java_handle_t *h; @@ -138,7 +74,7 @@ JNIEXPORT int32_t JNICALL Java_java_lang_VMClass_isInstance(JNIEnv *env, jclass * Method: isAssignableFrom * Signature: (Ljava/lang/Class;Ljava/lang/Class;)Z */ -JNIEXPORT int32_t JNICALL Java_java_lang_VMClass_isAssignableFrom(JNIEnv *env, jclass clazz, java_lang_Class *klass, java_lang_Class *c) +JNIEXPORT jboolean JNICALL Java_java_lang_VMClass_isAssignableFrom(JNIEnv *env, jclass clazz, jclass klass, jclass c) { classinfo *to; classinfo *from; @@ -160,7 +96,7 @@ JNIEXPORT int32_t JNICALL Java_java_lang_VMClass_isAssignableFrom(JNIEnv *env, j * Method: isInterface * Signature: (Ljava/lang/Class;)Z */ -JNIEXPORT int32_t JNICALL Java_java_lang_VMClass_isInterface(JNIEnv *env, jclass clazz, java_lang_Class *klass) +JNIEXPORT jboolean JNICALL Java_java_lang_VMClass_isInterface(JNIEnv *env, jclass clazz, jclass klass) { classinfo *c; @@ -175,7 +111,7 @@ JNIEXPORT int32_t JNICALL Java_java_lang_VMClass_isInterface(JNIEnv *env, jclass * Method: isPrimitive * Signature: (Ljava/lang/Class;)Z */ -JNIEXPORT int32_t JNICALL Java_java_lang_VMClass_isPrimitive(JNIEnv *env, jclass clazz, java_lang_Class *klass) +JNIEXPORT jboolean JNICALL Java_java_lang_VMClass_isPrimitive(JNIEnv *env, jclass clazz, jclass klass) { classinfo *c; @@ -190,13 +126,13 @@ JNIEXPORT int32_t JNICALL Java_java_lang_VMClass_isPrimitive(JNIEnv *env, jclass * Method: getName * Signature: (Ljava/lang/Class;)Ljava/lang/String; */ -JNIEXPORT java_lang_String* JNICALL Java_java_lang_VMClass_getName(JNIEnv *env, jclass clazz, java_lang_Class *klass) +JNIEXPORT jstring JNICALL Java_java_lang_VMClass_getName(JNIEnv *env, jclass clazz, jclass klass) { classinfo* c; c = LLNI_classinfo_unwrap(klass); - return (java_lang_String*) class_get_classname(c); + return (jstring) class_get_classname(c); } @@ -205,7 +141,7 @@ JNIEXPORT java_lang_String* JNICALL Java_java_lang_VMClass_getName(JNIEnv *env, * Method: getSuperclass * Signature: (Ljava/lang/Class;)Ljava/lang/Class; */ -JNIEXPORT java_lang_Class* JNICALL Java_java_lang_VMClass_getSuperclass(JNIEnv *env, jclass clazz, java_lang_Class *klass) +JNIEXPORT jclass JNICALL Java_java_lang_VMClass_getSuperclass(JNIEnv *env, jclass clazz, jclass klass) { classinfo *c; classinfo *super; @@ -214,7 +150,7 @@ JNIEXPORT java_lang_Class* JNICALL Java_java_lang_VMClass_getSuperclass(JNIEnv * super = class_get_superclass(c); - return LLNI_classinfo_wrap(super); + return (jclass) LLNI_classinfo_wrap(super); } @@ -223,7 +159,7 @@ JNIEXPORT java_lang_Class* JNICALL Java_java_lang_VMClass_getSuperclass(JNIEnv * * Method: getInterfaces * Signature: (Ljava/lang/Class;)[Ljava/lang/Class; */ -JNIEXPORT java_handle_objectarray_t* JNICALL Java_java_lang_VMClass_getInterfaces(JNIEnv *env, jclass clazz, java_lang_Class *klass) +JNIEXPORT jobjectArray JNICALL Java_java_lang_VMClass_getInterfaces(JNIEnv *env, jclass clazz, jclass klass) { classinfo *c; java_handle_objectarray_t *oa; @@ -232,7 +168,7 @@ JNIEXPORT java_handle_objectarray_t* JNICALL Java_java_lang_VMClass_getInterface oa = class_get_interfaces(c); - return oa; + return (jobjectArray) oa; } @@ -241,7 +177,7 @@ JNIEXPORT java_handle_objectarray_t* JNICALL Java_java_lang_VMClass_getInterface * Method: getComponentType * Signature: (Ljava/lang/Class;)Ljava/lang/Class; */ -JNIEXPORT java_lang_Class* JNICALL Java_java_lang_VMClass_getComponentType(JNIEnv *env, jclass clazz, java_lang_Class *klass) +JNIEXPORT jclass JNICALL Java_java_lang_VMClass_getComponentType(JNIEnv *env, jclass clazz, jclass klass) { classinfo *c; classinfo *component; @@ -250,7 +186,7 @@ JNIEXPORT java_lang_Class* JNICALL Java_java_lang_VMClass_getComponentType(JNIEn component = class_get_componenttype(c); - return LLNI_classinfo_wrap(component); + return (jclass) LLNI_classinfo_wrap(component); } @@ -259,7 +195,7 @@ JNIEXPORT java_lang_Class* JNICALL Java_java_lang_VMClass_getComponentType(JNIEn * Method: getModifiers * Signature: (Ljava/lang/Class;Z)I */ -JNIEXPORT int32_t JNICALL Java_java_lang_VMClass_getModifiers(JNIEnv *env, jclass clazz, java_lang_Class *klass, int32_t ignoreInnerClassesAttrib) +JNIEXPORT jint JNICALL Java_java_lang_VMClass_getModifiers(JNIEnv *env, jclass clazz, jclass klass, jboolean ignoreInnerClassesAttrib) { classinfo *c; int32_t flags; @@ -277,7 +213,7 @@ JNIEXPORT int32_t JNICALL Java_java_lang_VMClass_getModifiers(JNIEnv *env, jclas * Method: getDeclaringClass * Signature: (Ljava/lang/Class;)Ljava/lang/Class; */ -JNIEXPORT java_lang_Class* JNICALL Java_java_lang_VMClass_getDeclaringClass(JNIEnv *env, jclass clazz, java_lang_Class *klass) +JNIEXPORT jclass JNICALL Java_java_lang_VMClass_getDeclaringClass(JNIEnv *env, jclass clazz, jclass klass) { classinfo *c; classinfo *dc; @@ -286,7 +222,7 @@ JNIEXPORT java_lang_Class* JNICALL Java_java_lang_VMClass_getDeclaringClass(JNIE dc = class_get_declaringclass(c); - return LLNI_classinfo_wrap(dc); + return (jclass) LLNI_classinfo_wrap(dc); } @@ -295,7 +231,7 @@ JNIEXPORT java_lang_Class* JNICALL Java_java_lang_VMClass_getDeclaringClass(JNIE * Method: getDeclaredClasses * Signature: (Ljava/lang/Class;Z)[Ljava/lang/Class; */ -JNIEXPORT java_handle_objectarray_t* JNICALL Java_java_lang_VMClass_getDeclaredClasses(JNIEnv *env, jclass clazz, java_lang_Class *klass, int32_t publicOnly) +JNIEXPORT jobjectArray JNICALL Java_java_lang_VMClass_getDeclaredClasses(JNIEnv *env, jclass clazz, jclass klass, jboolean publicOnly) { classinfo *c; java_handle_objectarray_t *oa; @@ -304,7 +240,7 @@ JNIEXPORT java_handle_objectarray_t* JNICALL Java_java_lang_VMClass_getDeclaredC oa = class_get_declaredclasses(c, publicOnly); - return oa; + return (jobjectArray) oa; } @@ -313,7 +249,7 @@ JNIEXPORT java_handle_objectarray_t* JNICALL Java_java_lang_VMClass_getDeclaredC * Method: getDeclaredFields * Signature: (Ljava/lang/Class;Z)[Ljava/lang/reflect/Field; */ -JNIEXPORT java_handle_objectarray_t* JNICALL Java_java_lang_VMClass_getDeclaredFields(JNIEnv *env, jclass clazz, java_lang_Class *klass, int32_t publicOnly) +JNIEXPORT jobjectArray JNICALL Java_java_lang_VMClass_getDeclaredFields(JNIEnv *env, jclass clazz, jclass klass, jboolean publicOnly) { classinfo *c; java_handle_objectarray_t *oa; @@ -322,7 +258,7 @@ JNIEXPORT java_handle_objectarray_t* JNICALL Java_java_lang_VMClass_getDeclaredF oa = class_get_declaredfields(c, publicOnly); - return oa; + return (jobjectArray) oa; } @@ -331,7 +267,7 @@ JNIEXPORT java_handle_objectarray_t* JNICALL Java_java_lang_VMClass_getDeclaredF * Method: getDeclaredMethods * Signature: (Ljava/lang/Class;Z)[Ljava/lang/reflect/Method; */ -JNIEXPORT java_handle_objectarray_t* JNICALL Java_java_lang_VMClass_getDeclaredMethods(JNIEnv *env, jclass clazz, java_lang_Class *klass, int32_t publicOnly) +JNIEXPORT jobjectArray JNICALL Java_java_lang_VMClass_getDeclaredMethods(JNIEnv *env, jclass clazz, jclass klass, jboolean publicOnly) { classinfo *c; java_handle_objectarray_t *oa; @@ -340,7 +276,7 @@ JNIEXPORT java_handle_objectarray_t* JNICALL Java_java_lang_VMClass_getDeclaredM oa = class_get_declaredmethods(c, publicOnly); - return oa; + return (jobjectArray) oa; } @@ -349,7 +285,7 @@ JNIEXPORT java_handle_objectarray_t* JNICALL Java_java_lang_VMClass_getDeclaredM * Method: getDeclaredConstructors * Signature: (Ljava/lang/Class;Z)[Ljava/lang/reflect/Constructor; */ -JNIEXPORT java_handle_objectarray_t* JNICALL Java_java_lang_VMClass_getDeclaredConstructors(JNIEnv *env, jclass clazz, java_lang_Class *klass, int32_t publicOnly) +JNIEXPORT jobjectArray JNICALL Java_java_lang_VMClass_getDeclaredConstructors(JNIEnv *env, jclass clazz, jclass klass, jboolean publicOnly) { classinfo *c; java_handle_objectarray_t *oa; @@ -358,7 +294,7 @@ JNIEXPORT java_handle_objectarray_t* JNICALL Java_java_lang_VMClass_getDeclaredC oa = class_get_declaredconstructors(c, publicOnly); - return oa; + return (jobjectArray) oa; } @@ -367,7 +303,7 @@ JNIEXPORT java_handle_objectarray_t* JNICALL Java_java_lang_VMClass_getDeclaredC * Method: getClassLoader * Signature: (Ljava/lang/Class;)Ljava/lang/ClassLoader; */ -JNIEXPORT java_lang_ClassLoader* JNICALL Java_java_lang_VMClass_getClassLoader(JNIEnv *env, jclass clazz, java_lang_Class *klass) +JNIEXPORT jobject JNICALL Java_java_lang_VMClass_getClassLoader(JNIEnv *env, jclass clazz, jclass klass) { classinfo *c; classloader_t *cl; @@ -375,7 +311,7 @@ JNIEXPORT java_lang_ClassLoader* JNICALL Java_java_lang_VMClass_getClassLoader(J c = LLNI_classinfo_unwrap(klass); cl = class_get_classloader(c); - return (java_lang_ClassLoader *) cl; + return (jobject) cl; } @@ -384,13 +320,13 @@ JNIEXPORT java_lang_ClassLoader* JNICALL Java_java_lang_VMClass_getClassLoader(J * 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, int32_t initialize, java_lang_ClassLoader *loader) +JNIEXPORT jclass JNICALL Java_java_lang_VMClass_forName(JNIEnv *env, jclass clazz, jstring name, jboolean initialize, jobject loader) { classloader_t *cl; utf *ufile; utf *uname; classinfo *c; - u2 *pos; + char* pos; int32_t i; cl = loader_hashtable_classloader_add((java_handle_t *) loader); @@ -409,7 +345,8 @@ JNIEXPORT java_lang_Class* JNICALL Java_java_lang_VMClass_forName(JNIEnv *env, j /* name must not contain '/' (mauve test) */ - for (i = 0, pos = LLNI_field_direct(name, value)->data + LLNI_field_direct(name, offset); i < LLNI_field_direct(name, count); i++, pos++) { + // FIXME Move this check into a function. + for (i = 0, pos = uname->text; i < uname->blength; i++, pos++) { if (*pos == '/') { exceptions_throw_classnotfoundexception(uname); return NULL; @@ -434,7 +371,7 @@ JNIEXPORT java_lang_Class* JNICALL Java_java_lang_VMClass_forName(JNIEnv *env, j if (!initialize_class(c)) return NULL; - return LLNI_classinfo_wrap(c); + return (jclass) LLNI_classinfo_wrap(c); } @@ -443,7 +380,7 @@ JNIEXPORT java_lang_Class* JNICALL Java_java_lang_VMClass_forName(JNIEnv *env, j * Method: isArray * Signature: (Ljava/lang/Class;)Z */ -JNIEXPORT int32_t JNICALL Java_java_lang_VMClass_isArray(JNIEnv *env, jclass clazz, java_lang_Class *klass) +JNIEXPORT jboolean JNICALL Java_java_lang_VMClass_isArray(JNIEnv *env, jclass clazz, jclass klass) { classinfo *c; @@ -458,7 +395,7 @@ JNIEXPORT int32_t JNICALL Java_java_lang_VMClass_isArray(JNIEnv *env, jclass cla * Method: throwException * Signature: (Ljava/lang/Throwable;)V */ -JNIEXPORT void JNICALL Java_java_lang_VMClass_throwException(JNIEnv *env, jclass clazz, java_lang_Throwable *t) +JNIEXPORT void JNICALL Java_java_lang_VMClass_throwException(JNIEnv *env, jclass clazz, jobject t) { java_handle_t *o; @@ -474,44 +411,33 @@ JNIEXPORT void JNICALL Java_java_lang_VMClass_throwException(JNIEnv *env, jclass * Method: getDeclaredAnnotations * Signature: (Ljava/lang/Class;)[Ljava/lang/annotation/Annotation; */ -JNIEXPORT java_handle_objectarray_t* JNICALL Java_java_lang_VMClass_getDeclaredAnnotations(JNIEnv *env, jclass clazz, java_lang_Class* klass) +JNIEXPORT jobjectArray JNICALL Java_java_lang_VMClass_getDeclaredAnnotations(JNIEnv *env, jclass clazz, jclass klass) { - classinfo *c = NULL; /* classinfo for the java.lang.Class object 'klass' */ - static methodinfo *m_parseAnnotationsIntoArray = NULL; /* parser method (cached, therefore static) */ - utf *utf_parseAnnotationsIntoArray = NULL; /* parser method name */ - utf *utf_desc = NULL; /* parser method descriptor (signature) */ - java_handle_bytearray_t *annotations = NULL; /* unparsed annotations */ - sun_reflect_ConstantPool *constantPool = NULL; /* constant pool of klass */ - java_lang_Object *constantPoolOop = (java_lang_Object*)klass; /* constantPoolOop field of */ - /* sun.reflect.ConstantPool */ + static methodinfo* m_parseAnnotationsIntoArray = NULL; if (klass == NULL) { exceptions_throw_nullpointerexception(); return NULL; } - c = LLNI_classinfo_unwrap(klass); + classinfo* c = LLNI_classinfo_unwrap(klass); /* get annotations: */ - annotations = class_get_annotations(c); + java_handle_bytearray_t* annotations = class_get_annotations(c); - constantPool = - (sun_reflect_ConstantPool*)native_new_and_init( - class_sun_reflect_ConstantPool); + java_handle_t* h = native_new_and_init(class_sun_reflect_ConstantPool); - if (constantPool == NULL) { - /* out of memory */ + if (h == NULL) return NULL; - } - LLNI_field_set_ref(constantPool, constantPoolOop, constantPoolOop); + sun_reflect_ConstantPool cp(h); + cp.set_constantPoolOop(klass); /* only resolve the parser method the first time */ if (m_parseAnnotationsIntoArray == NULL) { - utf_parseAnnotationsIntoArray = utf_new_char("parseAnnotationsIntoArray"); - utf_desc = utf_new_char( - "([BLsun/reflect/ConstantPool;Ljava/lang/Class;)" - "[Ljava/lang/annotation/Annotation;"); + utf* utf_parseAnnotationsIntoArray = utf_new_char("parseAnnotationsIntoArray"); + utf* utf_desc = utf_new_char("([BLsun/reflect/ConstantPool;Ljava/lang/Class;)" + "[Ljava/lang/annotation/Annotation;"); if (utf_parseAnnotationsIntoArray == NULL || utf_desc == NULL) { /* out of memory */ @@ -531,9 +457,8 @@ JNIEXPORT java_handle_objectarray_t* JNICALL Java_java_lang_VMClass_getDeclaredA } } - return (java_handle_objectarray_t*)vm_call_method( - m_parseAnnotationsIntoArray, NULL, - annotations, constantPool, klass); + java_handle_objectarray_t* oa = (java_handle_objectarray_t*) vm_call_method(m_parseAnnotationsIntoArray, NULL, annotations, cp.get_handle(), klass); + return (jobjectArray) oa; } #endif @@ -543,7 +468,7 @@ JNIEXPORT java_handle_objectarray_t* JNICALL Java_java_lang_VMClass_getDeclaredA * Method: getEnclosingClass * Signature: (Ljava/lang/Class;)Ljava/lang/Class; */ -JNIEXPORT java_lang_Class* JNICALL Java_java_lang_VMClass_getEnclosingClass(JNIEnv *env, jclass clazz, java_lang_Class *klass) +JNIEXPORT jclass JNICALL Java_java_lang_VMClass_getEnclosingClass(JNIEnv *env, jclass clazz, jclass klass) { classinfo *c; classinfo *result; @@ -552,7 +477,7 @@ JNIEXPORT java_lang_Class* JNICALL Java_java_lang_VMClass_getEnclosingClass(JNIE result = class_get_enclosingclass(c); - return LLNI_classinfo_wrap(result); + return (jclass) LLNI_classinfo_wrap(result); } @@ -561,7 +486,7 @@ JNIEXPORT java_lang_Class* JNICALL Java_java_lang_VMClass_getEnclosingClass(JNIE * Method: getEnclosingConstructor * Signature: (Ljava/lang/Class;)Ljava/lang/reflect/Constructor; */ -JNIEXPORT java_lang_reflect_Constructor* JNICALL Java_java_lang_VMClass_getEnclosingConstructor(JNIEnv *env, jclass clazz, java_lang_Class *klass) +JNIEXPORT jobject JNICALL Java_java_lang_VMClass_getEnclosingConstructor(JNIEnv *env, jclass clazz, jclass klass) { classinfo* c; java_handle_t* h; @@ -569,7 +494,7 @@ JNIEXPORT java_lang_reflect_Constructor* JNICALL Java_java_lang_VMClass_getEnclo c = LLNI_classinfo_unwrap(klass); h = class_get_enclosingconstructor(c); - return (java_lang_reflect_Constructor*) h; + return (jobject) h; } @@ -578,7 +503,7 @@ JNIEXPORT java_lang_reflect_Constructor* JNICALL Java_java_lang_VMClass_getEnclo * Method: getEnclosingMethod * Signature: (Ljava/lang/Class;)Ljava/lang/reflect/Method; */ -JNIEXPORT java_lang_reflect_Method* JNICALL Java_java_lang_VMClass_getEnclosingMethod(JNIEnv *env, jclass clazz, java_lang_Class *klass) +JNIEXPORT jobject JNICALL Java_java_lang_VMClass_getEnclosingMethod(JNIEnv *env, jclass clazz, jclass klass) { classinfo* c; java_handle_t* h; @@ -586,7 +511,7 @@ JNIEXPORT java_lang_reflect_Method* JNICALL Java_java_lang_VMClass_getEnclosingM c = LLNI_classinfo_unwrap(klass); h = class_get_enclosingmethod(c); - return (java_lang_reflect_Method*) h; + return (jobject) h; } @@ -595,7 +520,7 @@ JNIEXPORT java_lang_reflect_Method* JNICALL Java_java_lang_VMClass_getEnclosingM * Method: getClassSignature * Signature: (Ljava/lang/Class;)Ljava/lang/String; */ -JNIEXPORT java_lang_String* JNICALL Java_java_lang_VMClass_getClassSignature(JNIEnv *env, jclass clazz, java_lang_Class* klass) +JNIEXPORT jstring JNICALL Java_java_lang_VMClass_getClassSignature(JNIEnv *env, jclass clazz, jclass klass) { classinfo *c; utf *u; @@ -612,7 +537,7 @@ JNIEXPORT java_lang_String* JNICALL Java_java_lang_VMClass_getClassSignature(JNI /* in error case s is NULL */ - return (java_lang_String *) s; + return (jstring) s; } @@ -621,7 +546,7 @@ JNIEXPORT java_lang_String* JNICALL Java_java_lang_VMClass_getClassSignature(JNI * Method: isAnonymousClass * Signature: (Ljava/lang/Class;)Z */ -JNIEXPORT int32_t JNICALL Java_java_lang_VMClass_isAnonymousClass(JNIEnv *env, jclass clazz, java_lang_Class *klass) +JNIEXPORT jboolean JNICALL Java_java_lang_VMClass_isAnonymousClass(JNIEnv *env, jclass clazz, jclass klass) { return class_is_anonymousclass(LLNI_classinfo_unwrap(klass)); } @@ -632,7 +557,7 @@ JNIEXPORT int32_t JNICALL Java_java_lang_VMClass_isAnonymousClass(JNIEnv *env, j * Method: isLocalClass * Signature: (Ljava/lang/Class;)Z */ -JNIEXPORT int32_t JNICALL Java_java_lang_VMClass_isLocalClass(JNIEnv *env, jclass clazz, java_lang_Class *klass) +JNIEXPORT jboolean JNICALL Java_java_lang_VMClass_isLocalClass(JNIEnv *env, jclass clazz, jclass klass) { return class_is_localclass(LLNI_classinfo_unwrap(klass)); } @@ -643,7 +568,7 @@ JNIEXPORT int32_t JNICALL Java_java_lang_VMClass_isLocalClass(JNIEnv *env, jclas * Method: isMemberClass * Signature: (Ljava/lang/Class;)Z */ -JNIEXPORT int32_t JNICALL Java_java_lang_VMClass_isMemberClass(JNIEnv *env, jclass clazz, java_lang_Class *klass) +JNIEXPORT jboolean JNICALL Java_java_lang_VMClass_isMemberClass(JNIEnv *env, jclass clazz, jclass klass) { return class_is_memberclass(LLNI_classinfo_unwrap(klass)); } @@ -651,6 +576,59 @@ JNIEXPORT int32_t JNICALL Java_java_lang_VMClass_isMemberClass(JNIEnv *env, jcla } // extern "C" +/* native methods implemented by this file ************************************/ + +static JNINativeMethod methods[] = { + { (char*) "isInstance", (char*) "(Ljava/lang/Class;Ljava/lang/Object;)Z", (void*) (uintptr_t) &Java_java_lang_VMClass_isInstance }, + { (char*) "isAssignableFrom", (char*) "(Ljava/lang/Class;Ljava/lang/Class;)Z", (void*) (uintptr_t) &Java_java_lang_VMClass_isAssignableFrom }, + { (char*) "isInterface", (char*) "(Ljava/lang/Class;)Z", (void*) (uintptr_t) &Java_java_lang_VMClass_isInterface }, + { (char*) "isPrimitive", (char*) "(Ljava/lang/Class;)Z", (void*) (uintptr_t) &Java_java_lang_VMClass_isPrimitive }, + { (char*) "getName", (char*) "(Ljava/lang/Class;)Ljava/lang/String;", (void*) (uintptr_t) &Java_java_lang_VMClass_getName }, + { (char*) "getSuperclass", (char*) "(Ljava/lang/Class;)Ljava/lang/Class;", (void*) (uintptr_t) &Java_java_lang_VMClass_getSuperclass }, + { (char*) "getInterfaces", (char*) "(Ljava/lang/Class;)[Ljava/lang/Class;", (void*) (uintptr_t) &Java_java_lang_VMClass_getInterfaces }, + { (char*) "getComponentType", (char*) "(Ljava/lang/Class;)Ljava/lang/Class;", (void*) (uintptr_t) &Java_java_lang_VMClass_getComponentType }, + { (char*) "getModifiers", (char*) "(Ljava/lang/Class;Z)I", (void*) (uintptr_t) &Java_java_lang_VMClass_getModifiers }, + { (char*) "getDeclaringClass", (char*) "(Ljava/lang/Class;)Ljava/lang/Class;", (void*) (uintptr_t) &Java_java_lang_VMClass_getDeclaringClass }, + { (char*) "getDeclaredClasses", (char*) "(Ljava/lang/Class;Z)[Ljava/lang/Class;", (void*) (uintptr_t) &Java_java_lang_VMClass_getDeclaredClasses }, + { (char*) "getDeclaredFields", (char*) "(Ljava/lang/Class;Z)[Ljava/lang/reflect/Field;", (void*) (uintptr_t) &Java_java_lang_VMClass_getDeclaredFields }, + { (char*) "getDeclaredMethods", (char*) "(Ljava/lang/Class;Z)[Ljava/lang/reflect/Method;", (void*) (uintptr_t) &Java_java_lang_VMClass_getDeclaredMethods }, + { (char*) "getDeclaredConstructors", (char*) "(Ljava/lang/Class;Z)[Ljava/lang/reflect/Constructor;", (void*) (uintptr_t) &Java_java_lang_VMClass_getDeclaredConstructors }, + { (char*) "getClassLoader", (char*) "(Ljava/lang/Class;)Ljava/lang/ClassLoader;", (void*) (uintptr_t) &Java_java_lang_VMClass_getClassLoader }, + { (char*) "forName", (char*) "(Ljava/lang/String;ZLjava/lang/ClassLoader;)Ljava/lang/Class;", (void*) (uintptr_t) &Java_java_lang_VMClass_forName }, + { (char*) "isArray", (char*) "(Ljava/lang/Class;)Z", (void*) (uintptr_t) &Java_java_lang_VMClass_isArray }, + { (char*) "throwException", (char*) "(Ljava/lang/Throwable;)V", (void*) (uintptr_t) &Java_java_lang_VMClass_throwException }, +#if defined(ENABLE_ANNOTATIONS) + { (char*) "getDeclaredAnnotations", (char*) "(Ljava/lang/Class;)[Ljava/lang/annotation/Annotation;", (void*) (uintptr_t) &Java_java_lang_VMClass_getDeclaredAnnotations }, +#endif + { (char*) "getEnclosingClass", (char*) "(Ljava/lang/Class;)Ljava/lang/Class;", (void*) (uintptr_t) &Java_java_lang_VMClass_getEnclosingClass }, + { (char*) "getEnclosingConstructor", (char*) "(Ljava/lang/Class;)Ljava/lang/reflect/Constructor;", (void*) (uintptr_t) &Java_java_lang_VMClass_getEnclosingConstructor }, + { (char*) "getEnclosingMethod", (char*) "(Ljava/lang/Class;)Ljava/lang/reflect/Method;", (void*) (uintptr_t) &Java_java_lang_VMClass_getEnclosingMethod }, + { (char*) "getClassSignature", (char*) "(Ljava/lang/Class;)Ljava/lang/String;", (void*) (uintptr_t) &Java_java_lang_VMClass_getClassSignature }, + { (char*) "isAnonymousClass", (char*) "(Ljava/lang/Class;)Z", (void*) (uintptr_t) &Java_java_lang_VMClass_isAnonymousClass }, + { (char*) "isLocalClass", (char*) "(Ljava/lang/Class;)Z", (void*) (uintptr_t) &Java_java_lang_VMClass_isLocalClass }, + { (char*) "isMemberClass", (char*) "(Ljava/lang/Class;)Z", (void*) (uintptr_t) &Java_java_lang_VMClass_isMemberClass }, +}; + + +/* _Jv_java_lang_VMClass_init ************************************************** + + Register native functions. + +*******************************************************************************/ + +// FIXME +extern "C" { +void _Jv_java_lang_VMClass_init(void) +{ + utf *u; + + u = utf_new_char("java/lang/VMClass"); + + native_method_register(u, methods, NATIVE_METHODS_COUNT); +} +} + + /* * 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 diff --git a/src/native/vm/gnuclasspath/java_lang_VMClassLoader.cpp b/src/native/vm/gnuclasspath/java_lang_VMClassLoader.cpp index 1e0473520..8df3967d2 100644 --- a/src/native/vm/gnuclasspath/java_lang_VMClassLoader.cpp +++ b/src/native/vm/gnuclasspath/java_lang_VMClassLoader.cpp @@ -34,18 +34,9 @@ #include "native/jni.h" #include "native/llni.h" #include "native/native.h" -#include "native/include/java_lang_Class.h" -#include "native/include/java_lang_String.h" -#include "native/include/java_security_ProtectionDomain.h" /* required by... */ -#include "native/include/java_lang_ClassLoader.h" -#include "native/include/java_util_HashMap.h" -#include "native/include/java_util_Map.h" -#include "native/include/java_lang_Boolean.h" // FIXME -extern "C" { -#include "native/include/java_lang_VMClassLoader.h" -} +//#include "native/include/java_lang_VMClassLoader.h" #include "toolbox/logging.h" #include "toolbox/list.h" @@ -66,6 +57,7 @@ extern "C" { #include "vmcore/class.h" #include "vmcore/classcache.h" #include "vmcore/globals.hpp" +#include "vmcore/javaobjects.hpp" #include "vmcore/linker.h" #include "vmcore/loader.h" #include "vmcore/options.h" @@ -86,12 +78,13 @@ extern "C" { * 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_handle_bytearray_t *data, int32_t offset, int32_t len, java_security_ProtectionDomain *pd) +JNIEXPORT jclass JNICALL Java_java_lang_VMClassLoader_defineClass(JNIEnv *env, jclass clazz, jobject cl, jstring name, jbyteArray data, jint offset, jint len, jobject pd) { utf *utfname; classinfo *c; classloader_t *loader; - java_lang_Class *o; + java_handle_bytearray_t* ba; + uint8_t* stream; #if defined(ENABLE_JVMTI) jint new_class_data_len = 0; @@ -145,20 +138,23 @@ JNIEXPORT java_lang_Class* JNICALL Java_java_lang_VMClassLoader_defineClass(JNIE c = class_define(utfname, loader, new_class_data_len, new_class_data, pd); else #endif - c = class_define(utfname, loader, len, (uint8_t *) &LLNI_array_direct(data, offset), (java_handle_t *) pd); + { + ba = (java_handle_bytearray_t*) data; + stream = (uint8_t *) &LLNI_array_direct(ba, offset); + c = class_define(utfname, loader, len, stream, (java_handle_t *) pd); + } if (c == NULL) return NULL; - /* for convenience */ - - o = LLNI_classinfo_wrap(c); - - /* set ProtectionDomain */ + // REMOVEME + java_handle_t* h = LLNI_classinfo_wrap(c); - LLNI_field_set_ref(o, pd, pd); + // Set ProtectionDomain. + java_lang_Class jlc(h); + jlc.set_pd(pd); - return o; + return (jclass) jlc.get_handle(); } @@ -167,7 +163,7 @@ JNIEXPORT java_lang_Class* JNICALL Java_java_lang_VMClassLoader_defineClass(JNIE * Method: getPrimitiveClass * Signature: (C)Ljava/lang/Class; */ -JNIEXPORT java_lang_Class* JNICALL Java_java_lang_VMClassLoader_getPrimitiveClass(JNIEnv *env, jclass clazz, int32_t type) +JNIEXPORT jclass JNICALL Java_java_lang_VMClassLoader_getPrimitiveClass(JNIEnv *env, jclass clazz, jchar type) { classinfo *c; @@ -178,7 +174,7 @@ JNIEXPORT java_lang_Class* JNICALL Java_java_lang_VMClassLoader_getPrimitiveClas return NULL; } - return LLNI_classinfo_wrap(c); + return (jclass) LLNI_classinfo_wrap(c); } @@ -187,7 +183,7 @@ JNIEXPORT java_lang_Class* JNICALL Java_java_lang_VMClassLoader_getPrimitiveClas * Method: resolveClass * Signature: (Ljava/lang/Class;)V */ -JNIEXPORT void JNICALL Java_java_lang_VMClassLoader_resolveClass(JNIEnv *env, jclass clazz, java_lang_Class *c) +JNIEXPORT void JNICALL Java_java_lang_VMClassLoader_resolveClass(JNIEnv *env, jclass clazz, jclass c) { classinfo *ci; @@ -212,7 +208,7 @@ JNIEXPORT void JNICALL Java_java_lang_VMClassLoader_resolveClass(JNIEnv *env, jc * 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, int32_t resolve) +JNIEXPORT jclass JNICALL Java_java_lang_VMClassLoader_loadClass(JNIEnv *env, jclass clazz, jstring name, jboolean resolve) { classinfo *c; utf *u; @@ -239,7 +235,7 @@ JNIEXPORT java_lang_Class* JNICALL Java_java_lang_VMClassLoader_loadClass(JNIEnv if (!link_class(c)) return NULL; - return LLNI_classinfo_wrap(c); + return (jclass) LLNI_classinfo_wrap(c); } @@ -248,7 +244,7 @@ JNIEXPORT java_lang_Class* JNICALL Java_java_lang_VMClassLoader_loadClass(JNIEnv * Method: nativeGetResources * Signature: (Ljava/lang/String;)Ljava/util/Vector; */ -JNIEXPORT struct java_util_Vector* JNICALL Java_java_lang_VMClassLoader_nativeGetResources(JNIEnv *env, jclass clazz, java_lang_String *name) +JNIEXPORT jobject JNICALL Java_java_lang_VMClassLoader_nativeGetResources(JNIEnv *env, jclass clazz, jstring name) { java_handle_t *o; /* vector being created */ methodinfo *m; /* "add" method of vector */ @@ -378,7 +374,7 @@ JNIEXPORT struct java_util_Vector* JNICALL Java_java_lang_VMClassLoader_nativeGe MFREE(buffer, char, bufsize); - return (struct java_util_Vector *) o; + return (jobject) o; return_NULL: MFREE(buffer, char, bufsize); @@ -392,7 +388,7 @@ return_NULL: * Method: defaultAssertionStatus * Signature: ()Z */ -JNIEXPORT int32_t JNICALL Java_java_lang_VMClassLoader_defaultAssertionStatus(JNIEnv *env, jclass clazz) +JNIEXPORT jboolean JNICALL Java_java_lang_VMClassLoader_defaultAssertionStatus(JNIEnv *env, jclass clazz) { #if defined(ENABLE_ASSERTION) return assertion_system_enabled; @@ -406,7 +402,7 @@ JNIEXPORT int32_t JNICALL Java_java_lang_VMClassLoader_defaultAssertionStatus(JN * Method: userAssertionStatus * Signature: ()Z */ -JNIEXPORT int32_t JNICALL Java_java_lang_VMClassLoader_defaultUserAssertionStatus(JNIEnv *env, jclass clazz) +JNIEXPORT jboolean JNICALL Java_java_lang_VMClassLoader_defaultUserAssertionStatus(JNIEnv *env, jclass clazz) { #if defined(ENABLE_ASSERTION) return assertion_user_enabled; @@ -418,9 +414,9 @@ JNIEXPORT int32_t JNICALL Java_java_lang_VMClassLoader_defaultUserAssertionStatu /* * Class: java/lang/VMClassLoader * Method: packageAssertionStatus - * Signature: ()Ljava_util_Map; + * Signature: (Ljava/lang/Boolean;Ljava/lang/Boolean;)Ljava/util/Map; */ -JNIEXPORT java_util_Map* JNICALL Java_java_lang_VMClassLoader_packageAssertionStatus0(JNIEnv *env, jclass clazz, java_lang_Boolean *jtrue, java_lang_Boolean *jfalse) +JNIEXPORT jobject JNICALL Java_java_lang_VMClassLoader_packageAssertionStatus0(JNIEnv *env, jclass clazz, jobject jtrue, jobject jfalse) { java_handle_t *hm; #if defined(ENABLE_ASSERTION) @@ -440,7 +436,7 @@ JNIEXPORT java_util_Map* JNICALL Java_java_lang_VMClassLoader_packageAssertionSt /* if nothing todo, return now */ if (assertion_package_count == 0) { - return (java_util_Map *) hm; + return (jobject) hm; } /* get HashMap.put method */ @@ -485,15 +481,15 @@ JNIEXPORT java_util_Map* JNICALL Java_java_lang_VMClassLoader_packageAssertionSt } #endif - return (java_util_Map *) hm; + return (jobject) hm; } /* * Class: java/lang/VMClassLoader * Method: classAssertionStatus - * Signature: ()Ljava_util_Map; + * Signature: (Ljava/lang/Boolean;Ljava/lang/Boolean;)Ljava/util/Map; */ -JNIEXPORT java_util_Map* JNICALL Java_java_lang_VMClassLoader_classAssertionStatus0(JNIEnv *env, jclass clazz, java_lang_Boolean *jtrue, java_lang_Boolean *jfalse) +JNIEXPORT jobject JNICALL Java_java_lang_VMClassLoader_classAssertionStatus0(JNIEnv *env, jclass clazz, jobject jtrue, jobject jfalse) { java_handle_t *hm; #if defined(ENABLE_ASSERTION) @@ -513,7 +509,7 @@ JNIEXPORT java_util_Map* JNICALL Java_java_lang_VMClassLoader_classAssertionStat /* if nothing todo, return now */ if (assertion_class_count == 0) { - return (java_util_Map *) hm; + return (jobject) hm; } /* get HashMap.put method */ @@ -552,7 +548,7 @@ JNIEXPORT java_util_Map* JNICALL Java_java_lang_VMClassLoader_classAssertionStat } #endif - return (java_util_Map *) hm; + return (jobject) hm; } @@ -561,7 +557,7 @@ JNIEXPORT java_util_Map* JNICALL Java_java_lang_VMClassLoader_classAssertionStat * 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 *loader, java_lang_String *name) +JNIEXPORT jclass JNICALL Java_java_lang_VMClassLoader_findLoadedClass(JNIEnv *env, jclass clazz, jobject loader, jstring name) { classloader_t *cl; classinfo *c; @@ -584,7 +580,7 @@ JNIEXPORT java_lang_Class* JNICALL Java_java_lang_VMClassLoader_findLoadedClass( if (c == NULL) c = classcache_lookup(cl, u); - return LLNI_classinfo_wrap(c); + return (jclass) LLNI_classinfo_wrap(c); } } // extern "C" diff --git a/src/native/vm/gnuclasspath/java_lang_VMObject.cpp b/src/native/vm/gnuclasspath/java_lang_VMObject.cpp index 098fd29d8..be694bd34 100644 --- a/src/native/vm/gnuclasspath/java_lang_VMObject.cpp +++ b/src/native/vm/gnuclasspath/java_lang_VMObject.cpp @@ -31,14 +31,9 @@ #include "native/llni.h" #include "native/native.h" -#include "native/include/java_lang_Class.h" /* required by j.l.VMO */ -#include "native/include/java_lang_Cloneable.h" /* required by j.l.VMO */ -#include "native/include/java_lang_Object.h" /* required by j.l.VMO */ - -//FIXME -extern "C" { -#include "native/include/java_lang_VMObject.h" -} +#if defined(ENABLE_JNI_HEADERS) +# include "native/vm/include/java_lang_VMObject.h" +#endif #include "threads/lock-common.h" @@ -56,7 +51,7 @@ extern "C" { * 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) +JNIEXPORT jclass JNICALL Java_java_lang_VMObject_getClass(JNIEnv *env, jclass clazz, jobject obj) { classinfo *c; @@ -67,7 +62,7 @@ JNIEXPORT java_lang_Class* JNICALL Java_java_lang_VMObject_getClass(JNIEnv *env, LLNI_class_get(obj, c); - return LLNI_classinfo_wrap(c); + return (jclass) LLNI_classinfo_wrap(c); } @@ -76,7 +71,7 @@ JNIEXPORT java_lang_Class* JNICALL Java_java_lang_VMObject_getClass(JNIEnv *env, * 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) +JNIEXPORT jobject JNICALL Java_java_lang_VMObject_clone(JNIEnv *env, jclass clazz, jobject _this) { java_handle_t *o; java_handle_t *co; @@ -85,7 +80,7 @@ JNIEXPORT java_lang_Object* JNICALL Java_java_lang_VMObject_clone(JNIEnv *env, j co = builtin_clone(NULL, o); - return (java_lang_Object *) co; + return (jobject) co; } @@ -94,7 +89,7 @@ JNIEXPORT java_lang_Object* JNICALL Java_java_lang_VMObject_clone(JNIEnv *env, j * Method: notify * Signature: (Ljava/lang/Object;)V */ -JNIEXPORT void JNICALL Java_java_lang_VMObject_notify(JNIEnv *env, jclass clazz, java_lang_Object *_this) +JNIEXPORT void JNICALL Java_java_lang_VMObject_notify(JNIEnv *env, jclass clazz, jobject _this) { #if defined(ENABLE_THREADS) lock_notify_object((java_handle_t *) _this); @@ -107,7 +102,7 @@ JNIEXPORT void JNICALL Java_java_lang_VMObject_notify(JNIEnv *env, jclass clazz, * Method: notifyAll * Signature: (Ljava/lang/Object;)V */ -JNIEXPORT void JNICALL Java_java_lang_VMObject_notifyAll(JNIEnv *env, jclass clazz, java_lang_Object *_this) +JNIEXPORT void JNICALL Java_java_lang_VMObject_notifyAll(JNIEnv *env, jclass clazz, jobject _this) { #if defined(ENABLE_THREADS) lock_notify_all_object((java_handle_t *) _this); @@ -120,7 +115,7 @@ JNIEXPORT void JNICALL Java_java_lang_VMObject_notifyAll(JNIEnv *env, jclass cla * Method: wait * Signature: (Ljava/lang/Object;JI)V */ -JNIEXPORT void JNICALL Java_java_lang_VMObject_wait(JNIEnv *env, jclass clazz, java_lang_Object *o, int64_t ms, int32_t ns) +JNIEXPORT void JNICALL Java_java_lang_VMObject_wait(JNIEnv *env, jclass clazz, jobject o, jlong ms, jint ns) { #if defined(ENABLE_JVMTI) /* Monitor Wait */ diff --git a/src/native/vm/gnuclasspath/java_lang_VMRuntime.cpp b/src/native/vm/gnuclasspath/java_lang_VMRuntime.cpp index 9460130f3..ce4689689 100644 --- a/src/native/vm/gnuclasspath/java_lang_VMRuntime.cpp +++ b/src/native/vm/gnuclasspath/java_lang_VMRuntime.cpp @@ -45,14 +45,9 @@ #include "native/jni.h" #include "native/native.h" -#include "native/include/java_lang_ClassLoader.h" -#include "native/include/java_lang_String.h" -#include "native/include/java_lang_Process.h" - -// FIXME -extern "C" { -#include "native/include/java_lang_VMRuntime.h" -} +#if defined(ENABLE_JNI_HEADERS) +# include "native/vm/include/java_lang_VMRuntime.h" +#endif #include "vm/builtin.h" #include "vm/exceptions.hpp" @@ -74,7 +69,7 @@ extern "C" { * Method: exit * Signature: (I)V */ -JNIEXPORT void JNICALL Java_java_lang_VMRuntime_exit(JNIEnv *env, jclass clazz, int32_t status) +JNIEXPORT void JNICALL Java_java_lang_VMRuntime_exit(JNIEnv *env, jclass clazz, jint status) { if (finalizeOnExit) gc_finalize_all(); @@ -88,7 +83,7 @@ JNIEXPORT void JNICALL Java_java_lang_VMRuntime_exit(JNIEnv *env, jclass clazz, * Method: freeMemory * Signature: ()J */ -JNIEXPORT int64_t JNICALL Java_java_lang_VMRuntime_freeMemory(JNIEnv *env, jclass clazz) +JNIEXPORT jlong JNICALL Java_java_lang_VMRuntime_freeMemory(JNIEnv *env, jclass clazz) { return gc_get_free_bytes(); } @@ -99,7 +94,7 @@ JNIEXPORT int64_t JNICALL Java_java_lang_VMRuntime_freeMemory(JNIEnv *env, jclas * Method: totalMemory * Signature: ()J */ -JNIEXPORT int64_t JNICALL Java_java_lang_VMRuntime_totalMemory(JNIEnv *env, jclass clazz) +JNIEXPORT jlong JNICALL Java_java_lang_VMRuntime_totalMemory(JNIEnv *env, jclass clazz) { return gc_get_heap_size(); } @@ -110,7 +105,7 @@ JNIEXPORT int64_t JNICALL Java_java_lang_VMRuntime_totalMemory(JNIEnv *env, jcla * Method: maxMemory * Signature: ()J */ -JNIEXPORT int64_t JNICALL Java_java_lang_VMRuntime_maxMemory(JNIEnv *env, jclass clazz) +JNIEXPORT jlong JNICALL Java_java_lang_VMRuntime_maxMemory(JNIEnv *env, jclass clazz) { return gc_get_max_heap_size(); } @@ -143,7 +138,7 @@ JNIEXPORT void JNICALL Java_java_lang_VMRuntime_runFinalization(JNIEnv *env, jcl * Method: runFinalizersOnExit * Signature: (Z)V */ -JNIEXPORT void JNICALL Java_java_lang_VMRuntime_runFinalizersOnExit(JNIEnv *env, jclass clazz, int32_t value) +JNIEXPORT void JNICALL Java_java_lang_VMRuntime_runFinalizersOnExit(JNIEnv *env, jclass clazz, jboolean value) { /* XXX threading */ @@ -174,7 +169,7 @@ JNIEXPORT void JNICALL Java_java_lang_VMRuntime_runFinalizationForExit(JNIEnv *e * Method: traceInstructions * Signature: (Z)V */ -JNIEXPORT void JNICALL Java_java_lang_VMRuntime_traceInstructions(JNIEnv *env, jclass clazz, int32_t par1) +JNIEXPORT void JNICALL Java_java_lang_VMRuntime_traceInstructions(JNIEnv *env, jclass clazz, jboolean par1) { /* not supported */ } @@ -185,7 +180,7 @@ JNIEXPORT void JNICALL Java_java_lang_VMRuntime_traceInstructions(JNIEnv *env, j * Method: traceMethodCalls * Signature: (Z)V */ -JNIEXPORT void JNICALL Java_java_lang_VMRuntime_traceMethodCalls(JNIEnv *env, jclass clazz, int32_t par1) +JNIEXPORT void JNICALL Java_java_lang_VMRuntime_traceMethodCalls(JNIEnv *env, jclass clazz, jboolean par1) { /* not supported */ } @@ -196,7 +191,7 @@ JNIEXPORT void JNICALL Java_java_lang_VMRuntime_traceMethodCalls(JNIEnv *env, jc * Method: availableProcessors * Signature: ()I */ -JNIEXPORT int32_t JNICALL Java_java_lang_VMRuntime_availableProcessors(JNIEnv *env, jclass clazz) +JNIEXPORT jint JNICALL Java_java_lang_VMRuntime_availableProcessors(JNIEnv *env, jclass clazz) { return os::processors_online(); } @@ -207,7 +202,7 @@ JNIEXPORT int32_t JNICALL Java_java_lang_VMRuntime_availableProcessors(JNIEnv *e * Method: nativeLoad * Signature: (Ljava/lang/String;Ljava/lang/ClassLoader;)I */ -JNIEXPORT int32_t JNICALL Java_java_lang_VMRuntime_nativeLoad(JNIEnv *env, jclass clazz, java_lang_String *libname, java_lang_ClassLoader *loader) +JNIEXPORT jint JNICALL Java_java_lang_VMRuntime_nativeLoad(JNIEnv *env, jclass clazz, jstring libname, jobject loader) { classloader_t *cl; utf *name; @@ -232,7 +227,7 @@ JNIEXPORT int32_t JNICALL Java_java_lang_VMRuntime_nativeLoad(JNIEnv *env, jclas * 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) +JNIEXPORT jstring JNICALL Java_java_lang_VMRuntime_mapLibraryName(JNIEnv *env, jclass clazz, jstring libname) { utf *u; char *buffer; @@ -271,7 +266,7 @@ JNIEXPORT java_lang_String* JNICALL Java_java_lang_VMRuntime_mapLibraryName(JNIE DRELEASE; - return (java_lang_String *) o; + return (jstring) o; } } // extern "C" diff --git a/src/native/vm/gnuclasspath/java_lang_VMString.cpp b/src/native/vm/gnuclasspath/java_lang_VMString.cpp index fc4c34ffc..632c429b8 100644 --- a/src/native/vm/gnuclasspath/java_lang_VMString.cpp +++ b/src/native/vm/gnuclasspath/java_lang_VMString.cpp @@ -31,12 +31,9 @@ #include "native/jni.h" #include "native/native.h" -#include "native/include/java_lang_String.h" - -// FIXME -extern "C" { -#include "native/include/java_lang_VMString.h" -} +#if defined(ENABLE_JNI_HEADERS) +# include "native/vm/include/java_lang_VMString.h" +#endif #include "vm/string.hpp" @@ -49,12 +46,12 @@ extern "C" { * 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) +JNIEXPORT jstring JNICALL Java_java_lang_VMString_intern(JNIEnv *env, jclass clazz, jstring str) { if (str == NULL) return NULL; - return (java_lang_String *) javastring_intern((java_handle_t *) str); + return (jstring) javastring_intern((java_handle_t *) str); } } // extern "C" diff --git a/src/native/vm/gnuclasspath/java_lang_VMSystem.cpp b/src/native/vm/gnuclasspath/java_lang_VMSystem.cpp index 21f1ad614..fcdc273ae 100644 --- a/src/native/vm/gnuclasspath/java_lang_VMSystem.cpp +++ b/src/native/vm/gnuclasspath/java_lang_VMSystem.cpp @@ -34,14 +34,9 @@ #include "native/llni.h" #include "native/native.h" -#include "native/include/java_lang_Object.h" -#include "native/include/java_io_InputStream.h" /* required by j.l.VMS */ -#include "native/include/java_io_PrintStream.h" /* required by j.l.VMS */ - -// FIXME -extern "C" { -#include "native/include/java_lang_VMSystem.h" -} +#if defined(ENABLE_JNI_HEADERS) +# include "native/vminclude/java_lang_VMSystem.h" +#endif #include "vm/builtin.h" @@ -54,7 +49,7 @@ extern "C" { * 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 *src, int32_t srcStart, java_lang_Object *dest, int32_t destStart, int32_t len) +JNIEXPORT void JNICALL Java_java_lang_VMSystem_arraycopy(JNIEnv *env, jclass clazz, jobject src, jint srcStart, jobject dest, jint destStart, jint len) { builtin_arraycopy((java_handle_t *) src, srcStart, (java_handle_t *) dest, destStart, len); @@ -66,10 +61,11 @@ JNIEXPORT void JNICALL Java_java_lang_VMSystem_arraycopy(JNIEnv *env, jclass cla * Method: identityHashCode * Signature: (Ljava/lang/Object;)I */ -JNIEXPORT int32_t JNICALL Java_java_lang_VMSystem_identityHashCode(JNIEnv *env, jclass clazz, java_lang_Object *o) +JNIEXPORT jint JNICALL Java_java_lang_VMSystem_identityHashCode(JNIEnv *env, jclass clazz, jobject o) { int32_t hashcode; + // XXX This critical section should be inside the heap function. LLNI_CRITICAL_START; hashcode = heap_hashcode(LLNI_UNWRAP((java_handle_t *) o)); diff --git a/src/native/vm/gnuclasspath/java_lang_VMThread.cpp b/src/native/vm/gnuclasspath/java_lang_VMThread.cpp index 3b7b07a8f..7f1817f92 100644 --- a/src/native/vm/gnuclasspath/java_lang_VMThread.cpp +++ b/src/native/vm/gnuclasspath/java_lang_VMThread.cpp @@ -31,17 +31,9 @@ #include "native/llni.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 */ - -// FIXME -extern "C" { -#include "native/include/java_lang_VMThread.h" -} - -#include "native/include/java_lang_String.h" -#include "native/include/java_lang_Thread.h" +#if defined(ENABLE_JNI_HEADERS) +# include "native/vm/include/java_lang_VMThread.h" +#endif #include "threads/lock-common.h" #include "threads/thread.hpp" @@ -49,6 +41,7 @@ extern "C" { #include "vm/exceptions.hpp" #include "vm/string.hpp" +#include "vmcore/javaobjects.hpp" #include "vmcore/utf8.h" @@ -60,7 +53,7 @@ extern "C" { * Method: countStackFrames * Signature: ()I */ -JNIEXPORT int32_t JNICALL Java_java_lang_VMThread_countStackFrames(JNIEnv *env, java_lang_VMThread *_this) +JNIEXPORT jint JNICALL Java_java_lang_VMThread_countStackFrames(JNIEnv *env, jobject _this) { log_println("Java_java_lang_VMThread_countStackFrames: Deprecated. Not implemented."); @@ -73,14 +66,12 @@ JNIEXPORT int32_t JNICALL Java_java_lang_VMThread_countStackFrames(JNIEnv *env, * Method: start * Signature: (J)V */ -JNIEXPORT void JNICALL Java_java_lang_VMThread_start(JNIEnv *env, java_lang_VMThread *_this, int64_t stacksize) +JNIEXPORT void JNICALL Java_java_lang_VMThread_start(JNIEnv *env, jobject _this, jlong stacksize) { - java_lang_Thread *thread; - - LLNI_field_get_ref(_this, thread, thread); - #if defined(ENABLE_THREADS) - threads_thread_start((java_handle_t *) thread); + java_lang_VMThread jlvmt(_this); + + threads_thread_start(jlvmt.get_thread()); #endif } @@ -90,7 +81,7 @@ JNIEXPORT void JNICALL Java_java_lang_VMThread_start(JNIEnv *env, java_lang_VMTh * Method: interrupt * Signature: ()V */ -JNIEXPORT void JNICALL Java_java_lang_VMThread_interrupt(JNIEnv *env, java_lang_VMThread *_this) +JNIEXPORT void JNICALL Java_java_lang_VMThread_interrupt(JNIEnv *env, jobject _this) { #if defined(ENABLE_THREADS) java_handle_t *h; @@ -109,7 +100,7 @@ JNIEXPORT void JNICALL Java_java_lang_VMThread_interrupt(JNIEnv *env, java_lang_ * Method: isInterrupted * Signature: ()Z */ -JNIEXPORT int32_t JNICALL Java_java_lang_VMThread_isInterrupted(JNIEnv *env, java_lang_VMThread *_this) +JNIEXPORT jboolean JNICALL Java_java_lang_VMThread_isInterrupted(JNIEnv *env, jobject _this) { #if defined(ENABLE_THREADS) java_handle_t *h; @@ -130,7 +121,7 @@ JNIEXPORT int32_t JNICALL Java_java_lang_VMThread_isInterrupted(JNIEnv *env, jav * Method: suspend * Signature: ()V */ -JNIEXPORT void JNICALL Java_java_lang_VMThread_suspend(JNIEnv *env, java_lang_VMThread *_this) +JNIEXPORT void JNICALL Java_java_lang_VMThread_suspend(JNIEnv *env, jobject _this) { #if defined(ENABLE_THREADS) log_println("Java_java_lang_VMThread_suspend: Deprecated. Not implemented."); @@ -143,7 +134,7 @@ JNIEXPORT void JNICALL Java_java_lang_VMThread_suspend(JNIEnv *env, java_lang_VM * Method: resume * Signature: ()V */ -JNIEXPORT void JNICALL Java_java_lang_VMThread_resume(JNIEnv *env, java_lang_VMThread *_this) +JNIEXPORT void JNICALL Java_java_lang_VMThread_resume(JNIEnv *env, jobject _this) { #if defined(ENABLE_THREADS) log_println("Java_java_lang_VMThread_resume: Deprecated. Not implemented."); @@ -156,7 +147,7 @@ JNIEXPORT void JNICALL Java_java_lang_VMThread_resume(JNIEnv *env, java_lang_VMT * Method: nativeSetPriority * Signature: (I)V */ -JNIEXPORT void JNICALL Java_java_lang_VMThread_nativeSetPriority(JNIEnv *env, java_lang_VMThread *_this, int32_t priority) +JNIEXPORT void JNICALL Java_java_lang_VMThread_nativeSetPriority(JNIEnv *env, jobject _this, jint priority) { #if defined(ENABLE_THREADS) java_handle_t *h; @@ -175,7 +166,7 @@ JNIEXPORT void JNICALL Java_java_lang_VMThread_nativeSetPriority(JNIEnv *env, ja * Method: nativeStop * Signature: (Ljava/lang/Throwable;)V */ -JNIEXPORT void JNICALL Java_java_lang_VMThread_nativeStop(JNIEnv *env, java_lang_VMThread *_this, java_lang_Throwable *t) +JNIEXPORT void JNICALL Java_java_lang_VMThread_nativeStop(JNIEnv *env, jobject _this, jobject t) { #if defined(ENABLE_THREADS) log_println("Java_java_lang_VMThread_nativeStop: Deprecated. Not implemented."); @@ -188,13 +179,13 @@ JNIEXPORT void JNICALL Java_java_lang_VMThread_nativeStop(JNIEnv *env, java_lang * Method: currentThread * Signature: ()Ljava/lang/Thread; */ -JNIEXPORT java_lang_Thread* JNICALL Java_java_lang_VMThread_currentThread(JNIEnv *env, jclass clazz) +JNIEXPORT jobject JNICALL Java_java_lang_VMThread_currentThread(JNIEnv *env, jclass clazz) { - java_lang_Thread *to; + java_handle_t* h; - to = (java_lang_Thread *) thread_get_current_object(); + h = thread_get_current_object(); - return to; + return (jobject) h; } @@ -229,7 +220,7 @@ JNIEXPORT void JNICALL Java_java_lang_VMThread_sleep(JNIEnv *env, jclass clazz, * Method: interrupted * Signature: ()Z */ -JNIEXPORT int32_t JNICALL Java_java_lang_VMThread_interrupted(JNIEnv *env, jclass clazz) +JNIEXPORT jboolean JNICALL Java_java_lang_VMThread_interrupted(JNIEnv *env, jclass clazz) { #if defined(ENABLE_THREADS) threadobject *t; @@ -254,7 +245,7 @@ JNIEXPORT int32_t JNICALL Java_java_lang_VMThread_interrupted(JNIEnv *env, jclas * Method: holdsLock * Signature: (Ljava/lang/Object;)Z */ -JNIEXPORT int32_t JNICALL Java_java_lang_VMThread_holdsLock(JNIEnv *env, jclass clazz, java_lang_Object* o) +JNIEXPORT jboolean JNICALL Java_java_lang_VMThread_holdsLock(JNIEnv *env, jclass clazz, jobject o) { #if defined(ENABLE_THREADS) java_handle_t *h; @@ -278,7 +269,7 @@ JNIEXPORT int32_t JNICALL Java_java_lang_VMThread_holdsLock(JNIEnv *env, jclass * Method: getState * Signature: ()Ljava/lang/String; */ -JNIEXPORT java_lang_String* JNICALL Java_java_lang_VMThread_getState(JNIEnv *env, java_lang_VMThread *_this) +JNIEXPORT jstring JNICALL Java_java_lang_VMThread_getState(JNIEnv *env, jobject _this) { #if defined(ENABLE_THREADS) java_handle_t *h; @@ -321,7 +312,7 @@ JNIEXPORT java_lang_String* JNICALL Java_java_lang_VMThread_getState(JNIEnv *env o = javastring_new(u); - return (java_lang_String *) o; + return (jstring) o; #else return NULL; #endif diff --git a/src/native/vm/gnuclasspath/java_lang_VMThrowable.cpp b/src/native/vm/gnuclasspath/java_lang_VMThrowable.cpp index eaff3364c..176bdf629 100644 --- a/src/native/vm/gnuclasspath/java_lang_VMThrowable.cpp +++ b/src/native/vm/gnuclasspath/java_lang_VMThrowable.cpp @@ -34,16 +34,8 @@ #include "native/llni.h" #include "native/native.h" -#include "native/include/java_lang_Object.h" -#include "native/include/java_lang_Class.h" -#include "native/include/java_lang_String.h" -#include "native/include/java_lang_StackTraceElement.h" -#include "native/include/java_lang_Throwable.h" - // FIXME -extern "C" { -#include "native/include/java_lang_VMThrowable.h" -} +//#include "native/include/java_lang_VMThrowable.h" #include "vm/array.h" #include "vm/builtin.h" @@ -55,35 +47,10 @@ extern "C" { #include "vm/jit/stacktrace.hpp" #include "vmcore/globals.hpp" +#include "vmcore/javaobjects.hpp" #include "vmcore/loader.h" -/* native methods implemented by this file ************************************/ - -static JNINativeMethod methods[] = { - { (char*) "fillInStackTrace", (char*) "(Ljava/lang/Throwable;)Ljava/lang/VMThrowable;", (void*) (uintptr_t) &Java_java_lang_VMThrowable_fillInStackTrace }, - { (char*) "getStackTrace", (char*) "(Ljava/lang/Throwable;)[Ljava/lang/StackTraceElement;", (void*) (uintptr_t) &Java_java_lang_VMThrowable_getStackTrace }, -}; - - -/* _Jv_java_lang_VMThrowable_init ********************************************** - - Register native functions. - -*******************************************************************************/ - -extern "C" { -void _Jv_java_lang_VMThrowable_init(void) -{ - utf *u; - - u = utf_new_char("java/lang/VMThrowable"); - - native_method_register(u, methods, NATIVE_METHODS_COUNT); -} -} - - // Native functions are exported as C functions. extern "C" { @@ -92,28 +59,26 @@ extern "C" { * 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) +JNIEXPORT jobject JNICALL Java_java_lang_VMThrowable_fillInStackTrace(JNIEnv *env, jclass clazz, jobject t) { - java_lang_VMThrowable *vmto; - java_handle_bytearray_t *ba; - java_lang_Object *o; + java_handle_t* h; + java_handle_bytearray_t* ba; - vmto = (java_lang_VMThrowable *) - native_new_and_init(class_java_lang_VMThrowable); + h = native_new_and_init(class_java_lang_VMThrowable); - if (vmto == NULL) + if (h == NULL) return NULL; + java_lang_VMThrowable vmt(h); + ba = stacktrace_get_current(); if (ba == NULL) return NULL; - o = (java_lang_Object *) ba; - - LLNI_field_set_ref(vmto, vmdata, o); + vmt.set_vmdata(ba); - return vmto; + return (jobject) vmt.get_handle(); } @@ -122,59 +87,41 @@ JNIEXPORT java_lang_VMThrowable* JNICALL Java_java_lang_VMThrowable_fillInStackT * Method: getStackTrace * Signature: (Ljava/lang/Throwable;)[Ljava/lang/StackTraceElement; */ -JNIEXPORT java_handle_objectarray_t* JNICALL Java_java_lang_VMThrowable_getStackTrace(JNIEnv *env, java_lang_VMThrowable *_this, java_lang_Throwable *t) +JNIEXPORT jobjectArray JNICALL Java_java_lang_VMThrowable_getStackTrace(JNIEnv *env, jobject _this, jobject t) { - java_lang_Object *o; - java_handle_bytearray_t *ba; - stacktrace_t *st; - stacktrace_entry_t *ste; - java_handle_objectarray_t *oa; - java_lang_StackTraceElement *steo; - codeinfo *code; - methodinfo *m; - java_lang_String *filename; - s4 linenumber; - java_handle_t *declaringclass; - int i; + java_lang_VMThrowable vmt(_this); - /* Get the stacktrace from the VMThrowable object. */ + // Get the stacktrace from the VMThrowable object. - LLNI_field_get_ref(_this, vmdata, o); + java_handle_bytearray_t* ba = vmt.get_vmdata(); - ba = (java_handle_bytearray_t *) o; - - st = (stacktrace_t *) LLNI_array_data(ba); + // XXX Critical GC section? + stacktrace_t* st = (stacktrace_t*) LLNI_array_data(ba); assert(st != NULL); - ste = st->entries; + stacktrace_entry_t* ste = st->entries; /* Create the stacktrace element array. */ - oa = builtin_anewarray(st->length, class_java_lang_StackTraceElement); + java_handle_objectarray_t* oa = builtin_anewarray(st->length, class_java_lang_StackTraceElement); if (oa == NULL) return NULL; - for (i = 0; i < st->length; i++, ste++) { - /* allocate a new stacktrace element */ - - steo = (java_lang_StackTraceElement *) - builtin_new(class_java_lang_StackTraceElement); - - if (steo == NULL) - return NULL; - + for (int i = 0; i < st->length; i++, ste++) { /* Get the codeinfo and methodinfo. */ - code = ste->code; - m = code->m; + codeinfo* code = ste->code; + methodinfo* m = code->m; /* Get filename. */ + java_handle_t* filename; + if (!(m->flags & ACC_NATIVE)) { if (m->clazz->sourcefile) - filename = (java_lang_String *) javastring_new(m->clazz->sourcefile); + filename = javastring_new(m->clazz->sourcefile); else filename = NULL; } @@ -183,6 +130,8 @@ JNIEXPORT java_handle_objectarray_t* JNICALL Java_java_lang_VMThrowable_getStack /* get line number */ + int32_t linenumber; + if (m->flags & ACC_NATIVE) { linenumber = -1; } @@ -197,25 +146,52 @@ JNIEXPORT java_handle_objectarray_t* JNICALL Java_java_lang_VMThrowable_getStack /* get declaring class name */ - declaringclass = class_get_classname(m->clazz); + java_handle_t* declaringclass = class_get_classname(m->clazz); - /* Fill the java.lang.StackTraceElement object. */ + /* allocate a new stacktrace element */ - LLNI_field_set_ref(steo, fileName , filename); - LLNI_field_set_val(steo, lineNumber , linenumber); - LLNI_field_set_ref(steo, declaringClass, (java_lang_String*) declaringclass); - LLNI_field_set_ref(steo, methodName , (java_lang_String *) javastring_new(m->name)); - LLNI_field_set_val(steo, isNative , (m->flags & ACC_NATIVE) ? 1 : 0); + java_handle_t* h = builtin_new(class_java_lang_StackTraceElement); - array_objectarray_element_set(oa, i, (java_handle_t *) steo); + if (h == NULL) + return NULL; + + java_lang_StackTraceElement ste(h, filename, linenumber, declaringclass, javastring_new(m->name), ((m->flags & ACC_NATIVE) ? 1 : 0)); + + array_objectarray_element_set(oa, i, ste.get_handle()); } - return oa; + return (jobjectArray) oa; } } // extern "C" +/* native methods implemented by this file ************************************/ + +static JNINativeMethod methods[] = { + { (char*) "fillInStackTrace", (char*) "(Ljava/lang/Throwable;)Ljava/lang/VMThrowable;", (void*) (uintptr_t) &Java_java_lang_VMThrowable_fillInStackTrace }, + { (char*) "getStackTrace", (char*) "(Ljava/lang/Throwable;)[Ljava/lang/StackTraceElement;", (void*) (uintptr_t) &Java_java_lang_VMThrowable_getStackTrace }, +}; + + +/* _Jv_java_lang_VMThrowable_init ********************************************** + + Register native functions. + +*******************************************************************************/ + +extern "C" { +void _Jv_java_lang_VMThrowable_init(void) +{ + utf *u; + + u = utf_new_char("java/lang/VMThrowable"); + + native_method_register(u, methods, NATIVE_METHODS_COUNT); +} +} + + /* * 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 diff --git a/src/native/vm/gnuclasspath/java_lang_management_VMManagementFactory.c b/src/native/vm/gnuclasspath/java_lang_management_VMManagementFactory.c index c5331d2bf..fa7f17240 100644 --- a/src/native/vm/gnuclasspath/java_lang_management_VMManagementFactory.c +++ b/src/native/vm/gnuclasspath/java_lang_management_VMManagementFactory.c @@ -32,7 +32,8 @@ #include "native/jni.h" #include "native/native.h" -#include "native/include/java_lang_management_VMManagementFactory.h" +// FIXME +//#include "native/include/java_lang_management_VMManagementFactory.h" #include "toolbox/logging.h" @@ -41,37 +42,12 @@ #include "vmcore/globals.hpp" -/* native methods implemented by this file ************************************/ - -static JNINativeMethod methods[] = { - { "getMemoryPoolNames", "()[Ljava/lang/String;", (void *) (ptrint) &Java_java_lang_management_VMManagementFactory_getMemoryPoolNames }, - { "getMemoryManagerNames", "()[Ljava/lang/String;", (void *) (ptrint) &Java_java_lang_management_VMManagementFactory_getMemoryManagerNames }, - { "getGarbageCollectorNames", "()[Ljava/lang/String;", (void *) (ptrint) &Java_java_lang_management_VMManagementFactory_getGarbageCollectorNames }, -}; - - -/* _Jv_java_lang_management_VMManagementFactory_init *************************** - - Register native functions. - -*******************************************************************************/ - -void _Jv_java_lang_management_VMManagementFactory_init(void) -{ - utf *u; - - u = utf_new_char("java/lang/management/VMManagementFactory"); - - native_method_register(u, methods, NATIVE_METHODS_COUNT); -} - - /* * Class: java/lang/management/VMManagementFactory * Method: getMemoryPoolNames * Signature: ()[Ljava/lang/String; */ -JNIEXPORT java_handle_objectarray_t* JNICALL Java_java_lang_management_VMManagementFactory_getMemoryPoolNames(JNIEnv *env, jclass clazz) +JNIEXPORT jobjectArray JNICALL Java_java_lang_management_VMManagementFactory_getMemoryPoolNames(JNIEnv *env, jclass clazz) { java_handle_objectarray_t *oa; @@ -88,7 +64,7 @@ JNIEXPORT java_handle_objectarray_t* JNICALL Java_java_lang_management_VMManagem * Method: getMemoryManagerNames * Signature: ()[Ljava/lang/String; */ -JNIEXPORT java_handle_objectarray_t* JNICALL Java_java_lang_management_VMManagementFactory_getMemoryManagerNames(JNIEnv *env, jclass clazz) +JNIEXPORT jobjectArray JNICALL Java_java_lang_management_VMManagementFactory_getMemoryManagerNames(JNIEnv *env, jclass clazz) { java_handle_objectarray_t *oa; @@ -105,7 +81,7 @@ JNIEXPORT java_handle_objectarray_t* JNICALL Java_java_lang_management_VMManagem * Method: getGarbageCollectorNames * Signature: ()[Ljava/lang/String; */ -JNIEXPORT java_handle_objectarray_t* JNICALL Java_java_lang_management_VMManagementFactory_getGarbageCollectorNames(JNIEnv *env, jclass clazz) +JNIEXPORT jobjectArray JNICALL Java_java_lang_management_VMManagementFactory_getGarbageCollectorNames(JNIEnv *env, jclass clazz) { java_handle_objectarray_t *oa; @@ -117,6 +93,31 @@ JNIEXPORT java_handle_objectarray_t* JNICALL Java_java_lang_management_VMManagem } +/* native methods implemented by this file ************************************/ + +static JNINativeMethod methods[] = { + { "getMemoryPoolNames", "()[Ljava/lang/String;", (void*) (uintptr_t) &Java_java_lang_management_VMManagementFactory_getMemoryPoolNames }, + { "getMemoryManagerNames", "()[Ljava/lang/String;", (void*) (uintptr_t) &Java_java_lang_management_VMManagementFactory_getMemoryManagerNames }, + { "getGarbageCollectorNames", "()[Ljava/lang/String;", (void*) (uintptr_t) &Java_java_lang_management_VMManagementFactory_getGarbageCollectorNames }, +}; + + +/* _Jv_java_lang_management_VMManagementFactory_init *************************** + + Register native functions. + +*******************************************************************************/ + +void _Jv_java_lang_management_VMManagementFactory_init(void) +{ + utf *u; + + u = utf_new_char("java/lang/management/VMManagementFactory"); + + native_method_register(u, methods, NATIVE_METHODS_COUNT); +} + + /* * 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 diff --git a/src/native/vm/gnuclasspath/java_lang_reflect_VMConstructor.cpp b/src/native/vm/gnuclasspath/java_lang_reflect_VMConstructor.cpp index 85a771528..3207ff1e5 100644 --- a/src/native/vm/gnuclasspath/java_lang_reflect_VMConstructor.cpp +++ b/src/native/vm/gnuclasspath/java_lang_reflect_VMConstructor.cpp @@ -32,61 +32,17 @@ #include "native/llni.h" #include "native/native.h" -#include "native/include/java_lang_Class.h" -#include "native/include/java_lang_Object.h" -#include "native/include/java_lang_String.h" - -#if defined(ENABLE_ANNOTATIONS) -# include "native/include/java_util_Map.h" -# include "native/include/sun_reflect_ConstantPool.h" -#endif - -#include "native/include/java_lang_reflect_Constructor.h" // FIXME -extern "C" { -#include "native/include/java_lang_reflect_VMConstructor.h" -} +//#include "native/include/java_lang_reflect_VMConstructor.h" -#include "native/vm/reflect.h" +#include "native/vm/reflection.hpp" #include "vm/string.hpp" +#include "vmcore/javaobjects.hpp" #include "vmcore/utf8.h" -/* native methods implemented by this file ************************************/ - -static JNINativeMethod methods[] = { - { (char*) "getModifiersInternal", (char*) "()I", (void*) (uintptr_t) &Java_java_lang_reflect_VMConstructor_getModifiersInternal }, - { (char*) "getParameterTypes", (char*) "()[Ljava/lang/Class;", (void*) (uintptr_t) &Java_java_lang_reflect_VMConstructor_getParameterTypes }, - { (char*) "getExceptionTypes", (char*) "()[Ljava/lang/Class;", (void*) (uintptr_t) &Java_java_lang_reflect_VMConstructor_getExceptionTypes }, - { (char*) "construct", (char*) "([Ljava/lang/Object;)Ljava/lang/Object;", (void*) (uintptr_t) &Java_java_lang_reflect_VMConstructor_construct }, - { (char*) "getSignature", (char*) "()Ljava/lang/String;", (void*) (uintptr_t) &Java_java_lang_reflect_VMConstructor_getSignature }, -#if defined(ENABLE_ANNOTATIONS) - { (char*) "declaredAnnotations", (char*) "()Ljava/util/Map;", (void*) (uintptr_t) &Java_java_lang_reflect_VMConstructor_declaredAnnotations }, - { (char*) "getParameterAnnotations", (char*) "()[[Ljava/lang/annotation/Annotation;", (void*) (uintptr_t) &Java_java_lang_reflect_VMConstructor_getParameterAnnotations }, -#endif -}; - - -/* _Jv_java_lang_reflect_VMConstructor_init ************************************ - - Register native functions. - -*******************************************************************************/ - -extern "C" { -void _Jv_java_lang_reflect_VMConstructor_init(void) -{ - utf *u; - - u = utf_new_char("java/lang/reflect/VMConstructor"); - - native_method_register(u, methods, NATIVE_METHODS_COUNT); -} -} - - // Native functions are exported as C functions. extern "C" { @@ -95,17 +51,10 @@ extern "C" { * Method: getModifiersInternal * Signature: ()I */ -JNIEXPORT int32_t JNICALL Java_java_lang_reflect_VMConstructor_getModifiersInternal(JNIEnv *env, java_lang_reflect_VMConstructor *_this) +JNIEXPORT jint JNICALL Java_java_lang_reflect_VMConstructor_getModifiersInternal(JNIEnv *env, jobject _this) { - classinfo *c; - methodinfo *m; - int32_t slot; - - LLNI_field_get_cls(_this, clazz, c); - LLNI_field_get_val(_this, slot, slot); - - m = &(c->methods[slot]); - + java_lang_reflect_VMConstructor rvmc(_this); + methodinfo* m = rvmc.get_method(); return m->flags; } @@ -115,18 +64,14 @@ JNIEXPORT int32_t JNICALL Java_java_lang_reflect_VMConstructor_getModifiersInter * Method: getParameterTypes * Signature: ()[Ljava/lang/Class; */ -JNIEXPORT java_handle_objectarray_t* JNICALL Java_java_lang_reflect_VMConstructor_getParameterTypes(JNIEnv *env, java_lang_reflect_VMConstructor *_this) +JNIEXPORT jobjectArray JNICALL Java_java_lang_reflect_VMConstructor_getParameterTypes(JNIEnv *env, jobject _this) { - classinfo *c; - methodinfo *m; - int32_t slot; + java_lang_reflect_VMConstructor rvmc(_this); + methodinfo* m = rvmc.get_method(); - LLNI_field_get_cls(_this, clazz, c); - LLNI_field_get_val(_this, slot, slot); + java_handle_objectarray_t* hoa = method_get_parametertypearray(m); - m = &(c->methods[slot]); - - return method_get_parametertypearray(m); + return (jobjectArray) hoa; } @@ -135,18 +80,14 @@ JNIEXPORT java_handle_objectarray_t* JNICALL Java_java_lang_reflect_VMConstructo * Method: getExceptionTypes * Signature: ()[Ljava/lang/Class; */ -JNIEXPORT java_handle_objectarray_t* JNICALL Java_java_lang_reflect_VMConstructor_getExceptionTypes(JNIEnv *env, java_lang_reflect_VMConstructor *_this) +JNIEXPORT jobjectArray JNICALL Java_java_lang_reflect_VMConstructor_getExceptionTypes(JNIEnv *env, jobject _this) { - classinfo *c; - methodinfo *m; - int32_t slot; - - LLNI_field_get_cls(_this, clazz, c); - LLNI_field_get_val(_this, slot, slot); + java_lang_reflect_VMConstructor rvmc(_this); + methodinfo* m = rvmc.get_method(); - m = &(c->methods[slot]); + java_handle_objectarray_t* hoa = method_get_exceptionarray(m); - return method_get_exceptionarray(m); + return (jobjectArray) hoa; } @@ -155,26 +96,16 @@ JNIEXPORT java_handle_objectarray_t* JNICALL Java_java_lang_reflect_VMConstructo * Method: construct * Signature: ([Ljava/lang/Object;Ljava/lang/Class;I)Ljava/lang/Object; */ -JNIEXPORT java_lang_Object* JNICALL Java_java_lang_reflect_VMConstructor_construct(JNIEnv *env, java_lang_reflect_VMConstructor *_this, java_handle_objectarray_t *args) +JNIEXPORT jobject JNICALL Java_java_lang_reflect_VMConstructor_construct(JNIEnv *env, jobject _this, jobjectArray args) { - classinfo *c; - int32_t slot; - java_lang_reflect_Constructor *rc; - int32_t override; - methodinfo *m; - java_handle_t *o; - - LLNI_field_get_cls(_this, clazz, c); - LLNI_field_get_val(_this, slot, slot); + java_lang_reflect_VMConstructor rvmc(_this); + java_lang_reflect_Constructor rc(rvmc.get_cons()); + methodinfo* m = rvmc.get_method(); + int32_t override = rc.get_flag(); - LLNI_field_get_ref(_this, cons, rc); - LLNI_field_get_val(rc, flag, override); + java_handle_t* o = java_lang_reflect_Constructor::new_instance(m, (java_handle_objectarray_t*) args, override); - m = &(c->methods[slot]); - - o = reflect_constructor_newinstance(m, args, override); - - return (java_lang_Object *) o; + return (jobject) o; } @@ -183,17 +114,11 @@ JNIEXPORT java_lang_Object* JNICALL Java_java_lang_reflect_VMConstructor_constru * Method: getSignature * Signature: ()Ljava/lang/String; */ -JNIEXPORT java_lang_String* JNICALL Java_java_lang_reflect_VMConstructor_getSignature(JNIEnv *env, java_lang_reflect_VMConstructor *_this) +JNIEXPORT jstring JNICALL Java_java_lang_reflect_VMConstructor_getSignature(JNIEnv *env, jobject _this) { - classinfo *c; - methodinfo *m; + java_lang_reflect_VMConstructor rvmc(_this); + methodinfo* m = rvmc.get_method(); java_handle_t *o; - int32_t slot; - - LLNI_field_get_cls(_this, clazz, c); - LLNI_field_get_val(_this, slot, slot); - - m = &(c->methods[slot]); if (m->signature == NULL) return NULL; @@ -202,7 +127,7 @@ JNIEXPORT java_lang_String* JNICALL Java_java_lang_reflect_VMConstructor_getSign /* In error case o is NULL. */ - return (java_lang_String *) o; + return (jstring) o; } @@ -215,28 +140,26 @@ JNIEXPORT java_lang_String* JNICALL Java_java_lang_reflect_VMConstructor_getSign * Parses the annotations (if they aren't parsed yet) and stores them into * the declaredAnnotations map and return this map. */ -JNIEXPORT struct java_util_Map* JNICALL Java_java_lang_reflect_VMConstructor_declaredAnnotations(JNIEnv *env, java_lang_reflect_VMConstructor *_this) +JNIEXPORT jobject JNICALL Java_java_lang_reflect_VMConstructor_declaredAnnotations(JNIEnv *env, jobject _this) { - java_util_Map *declaredAnnotations = NULL; /* parsed annotations */ - java_handle_bytearray_t *annotations = NULL; /* unparsed annotations */ - java_lang_Class *declaringClass = NULL; /* the constant pool of this class is used */ - classinfo *referer = NULL; /* class, which calles the annotation parser */ - /* (for the parameter 'referer' of vm_call_method()) */ + java_lang_reflect_VMConstructor rvmc(_this); - LLNI_field_get_ref(_this, declaredAnnotations, declaredAnnotations); + java_handle_t* declaredAnnotations = rvmc.get_declaredAnnotations(); /* are the annotations parsed yet? */ if (declaredAnnotations == NULL) { - LLNI_field_get_ref(_this, annotations, annotations); - LLNI_field_get_ref(_this, clazz, declaringClass); + java_handle_bytearray_t* annotations = rvmc.get_annotations(); + classinfo* declaringClass = rvmc.get_clazz(); + + classinfo *referer; LLNI_class_get(_this, referer); - declaredAnnotations = reflect_get_declaredannotations(annotations, (classinfo*) declaringClass, referer); + declaredAnnotations = Reflection::get_declaredannotations(annotations, declaringClass, referer); - LLNI_field_set_ref(_this, declaredAnnotations, declaredAnnotations); + rvmc.set_declaredAnnotations(declaredAnnotations); } - return declaredAnnotations; + return (jobject) declaredAnnotations; } @@ -247,29 +170,58 @@ JNIEXPORT struct java_util_Map* JNICALL Java_java_lang_reflect_VMConstructor_dec * * Parses the parameter annotations and returns them in an 2 dimensional array. */ -JNIEXPORT java_handle_objectarray_t* JNICALL Java_java_lang_reflect_VMConstructor_getParameterAnnotations(JNIEnv *env, java_lang_reflect_VMConstructor *_this) +JNIEXPORT jobjectArray JNICALL Java_java_lang_reflect_VMConstructor_getParameterAnnotations(JNIEnv *env, jobject _this) { - java_handle_bytearray_t *parameterAnnotations = NULL; /* unparsed parameter annotations */ - int32_t slot = -1; /* slot of the method */ - classinfo *c; - methodinfo *m; - classinfo *referer = NULL; /* class, which calles the annotation parser */ - /* (for the parameter 'referer' of vm_call_method()) */ + java_lang_reflect_VMConstructor rvmc(_this); + + java_handle_bytearray_t* parameterAnnotations = rvmc.get_parameterAnnotations(); + methodinfo* m = rvmc.get_method(); - LLNI_field_get_ref(_this, parameterAnnotations, parameterAnnotations); - LLNI_field_get_val(_this, slot, slot); - LLNI_field_get_cls(_this, clazz, c); - m = &(c->methods[slot]); + classinfo* referer; + LLNI_class_get((java_lang_reflect_VMConstructor*) _this, referer); - LLNI_class_get(_this, referer); + java_handle_objectarray_t* oa = Reflection::get_parameterannotations(parameterAnnotations, m, referer); - return reflect_get_parameterannotations((java_handle_t*)parameterAnnotations, m, referer); + return (jobjectArray) oa; } #endif } // extern "C" +/* native methods implemented by this file ************************************/ + +static JNINativeMethod methods[] = { + { (char*) "getModifiersInternal", (char*) "()I", (void*) (uintptr_t) &Java_java_lang_reflect_VMConstructor_getModifiersInternal }, + { (char*) "getParameterTypes", (char*) "()[Ljava/lang/Class;", (void*) (uintptr_t) &Java_java_lang_reflect_VMConstructor_getParameterTypes }, + { (char*) "getExceptionTypes", (char*) "()[Ljava/lang/Class;", (void*) (uintptr_t) &Java_java_lang_reflect_VMConstructor_getExceptionTypes }, + { (char*) "construct", (char*) "([Ljava/lang/Object;)Ljava/lang/Object;", (void*) (uintptr_t) &Java_java_lang_reflect_VMConstructor_construct }, + { (char*) "getSignature", (char*) "()Ljava/lang/String;", (void*) (uintptr_t) &Java_java_lang_reflect_VMConstructor_getSignature }, +#if defined(ENABLE_ANNOTATIONS) + { (char*) "declaredAnnotations", (char*) "()Ljava/util/Map;", (void*) (uintptr_t) &Java_java_lang_reflect_VMConstructor_declaredAnnotations }, + { (char*) "getParameterAnnotations", (char*) "()[[Ljava/lang/annotation/Annotation;", (void*) (uintptr_t) &Java_java_lang_reflect_VMConstructor_getParameterAnnotations }, +#endif +}; + + +/* _Jv_java_lang_reflect_VMConstructor_init ************************************ + + Register native functions. + +*******************************************************************************/ + +extern "C" { +void _Jv_java_lang_reflect_VMConstructor_init(void) +{ + utf *u; + + u = utf_new_char("java/lang/reflect/VMConstructor"); + + native_method_register(u, methods, NATIVE_METHODS_COUNT); +} +} + + /* * 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 diff --git a/src/native/vm/gnuclasspath/java_lang_reflect_VMField.cpp b/src/native/vm/gnuclasspath/java_lang_reflect_VMField.cpp index c30ad41cc..b19ae1949 100644 --- a/src/native/vm/gnuclasspath/java_lang_reflect_VMField.cpp +++ b/src/native/vm/gnuclasspath/java_lang_reflect_VMField.cpp @@ -32,29 +32,12 @@ #include "native/llni.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_String.h" - -#include "native/include/java_lang_reflect_Field.h" - // FIXME -extern "C" { -#include "native/include/java_lang_reflect_VMField.h" -} +//#include "native/include/java_lang_reflect_VMField.h" #if defined(ENABLE_ANNOTATIONS) -#include "native/include/java_util_Map.h" -#include "native/include/sun_reflect_ConstantPool.h" -#include "native/vm/reflect.h" +// REMOVEME +# include "native/vm/reflection.hpp" #endif #include "vm/access.h" @@ -66,59 +49,11 @@ extern "C" { #include "vm/resolve.h" #include "vm/string.hpp" +#include "vmcore/javaobjects.hpp" #include "vmcore/loader.h" #include "vmcore/utf8.h" -/* native methods implemented by this file ************************************/ - -static const JNINativeMethod methods[] = { - { (char*) "getModifiersInternal", (char*) "()I", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_getModifiersInternal }, - { (char*) "getType", (char*) "()Ljava/lang/Class;", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_getType }, - { (char*) "get", (char*) "(Ljava/lang/Object;)Ljava/lang/Object;", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_get }, - { (char*) "getBoolean", (char*) "(Ljava/lang/Object;)Z", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_getBoolean }, - { (char*) "getByte", (char*) "(Ljava/lang/Object;)B", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_getByte }, - { (char*) "getChar", (char*) "(Ljava/lang/Object;)C", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_getChar }, - { (char*) "getShort", (char*) "(Ljava/lang/Object;)S", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_getShort }, - { (char*) "getInt", (char*) "(Ljava/lang/Object;)I", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_getInt }, - { (char*) "getLong", (char*) "(Ljava/lang/Object;)J", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_getLong }, - { (char*) "getFloat", (char*) "(Ljava/lang/Object;)F", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_getFloat }, - { (char*) "getDouble", (char*) "(Ljava/lang/Object;)D", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_getDouble }, - { (char*) "set", (char*) "(Ljava/lang/Object;Ljava/lang/Object;)V", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_set }, - { (char*) "setBoolean", (char*) "(Ljava/lang/Object;Z)V", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_setBoolean }, - { (char*) "setByte", (char*) "(Ljava/lang/Object;B)V", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_setByte }, - { (char*) "setChar", (char*) "(Ljava/lang/Object;C)V", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_setChar }, - { (char*) "setShort", (char*) "(Ljava/lang/Object;S)V", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_setShort }, - { (char*) "setInt", (char*) "(Ljava/lang/Object;I)V", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_setInt }, - { (char*) "setLong", (char*) "(Ljava/lang/Object;J)V", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_setLong }, - { (char*) "setFloat", (char*) "(Ljava/lang/Object;F)V", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_setFloat }, - { (char*) "setDouble", (char*) "(Ljava/lang/Object;D)V", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_setDouble }, - { (char*) "getSignature", (char*) "()Ljava/lang/String;", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_getSignature }, -#if defined(ENABLE_ANNOTATIONS) - { (char*) "declaredAnnotations", (char*) "()Ljava/util/Map;", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_declaredAnnotations }, -#endif -}; - - -/* _Jv_java_lang_reflect_VMField_init ****************************************** - - Register native functions. - -*******************************************************************************/ - -// FIXME -extern "C" { -void _Jv_java_lang_reflect_VMField_init(void) -{ - utf *u; - - u = utf_new_char("java/lang/reflect/VMField"); - - native_method_register(u, methods, NATIVE_METHODS_COUNT); -} -} - - /* _field_access_check ********************************************************* Checks if the field can be accessed. @@ -129,18 +64,14 @@ void _Jv_java_lang_reflect_VMField_init(void) *******************************************************************************/ -static bool _field_access_check(java_lang_reflect_VMField *_this, - fieldinfo *f, java_handle_t *o) +static bool _field_access_check(const java_lang_reflect_VMField& rvmf, fieldinfo *f, java_handle_t *o) { - java_lang_reflect_Field *rf; - int32_t flag; - - /* check if we should bypass security checks (AccessibleObject) */ + // Check if we should bypass security checks (AccessibleObject). - LLNI_field_get_ref(_this, f, rf); - LLNI_field_get_val(rf, flag, flag); + java_lang_reflect_Field rf(rvmf.get_f()); + int32_t override = rf.get_flag(); - if (flag == false) { + if (override == false) { /* This function is always called like this: [0] java.lang.reflect.VMField.xxx (Native Method) [1] java.lang.reflect.Field.xxx @@ -190,37 +121,37 @@ static bool _field_access_check(java_lang_reflect_VMField *_this, *******************************************************************************/ #define _FIELD_GET_TYPE(name, type, uniontype) \ -static inline type _field_get_##name(fieldinfo *f, java_lang_Object *o) \ +static inline type _field_get_##name(fieldinfo *f, java_handle_t* h) \ { \ type ret; \ if (f->flags & ACC_STATIC) { \ ret = f->value->uniontype; \ } else { \ LLNI_CRITICAL_START; \ - ret = *(type *) (((intptr_t) LLNI_DIRECT(o)) + f->offset); \ + ret = *(type *) (((intptr_t) LLNI_DIRECT(h)) + f->offset); \ LLNI_CRITICAL_END; \ } \ return ret; \ } -static inline java_handle_t *_field_get_handle(fieldinfo *f, java_lang_Object *o) +static inline java_handle_t *_field_get_handle(fieldinfo *f, java_handle_t* h) { - java_object_t *obj; - java_handle_t *hdl; + java_object_t* result; + java_handle_t* hresult; LLNI_CRITICAL_START; if (f->flags & ACC_STATIC) { - obj = (java_object_t*) f->value->a; + result = (java_object_t*) f->value->a; } else { - obj = *(java_object_t **) (((intptr_t) LLNI_DIRECT(o)) + f->offset); + result = *(java_object_t**) (((intptr_t) LLNI_DIRECT(h)) + f->offset); } - hdl = LLNI_WRAP(obj); + hresult = LLNI_WRAP(result); LLNI_CRITICAL_END; - return hdl; + return hresult; } _FIELD_GET_TYPE(int, int32_t, i) @@ -236,25 +167,25 @@ _FIELD_GET_TYPE(double, double, d) *******************************************************************************/ #define _FIELD_SET_TYPE(name, type, uniontype) \ -static inline void _field_set_##name(fieldinfo *f, java_lang_Object *o, type value) \ +static inline void _field_set_##name(fieldinfo* f, java_handle_t* h, type value) \ { \ if (f->flags & ACC_STATIC) { \ f->value->uniontype = value; \ } else { \ LLNI_CRITICAL_START; \ - *(type *) (((intptr_t) LLNI_DIRECT(o)) + f->offset) = value; \ + *(type *) (((intptr_t) LLNI_DIRECT(h)) + f->offset) = value; \ LLNI_CRITICAL_END; \ } \ } -static inline void _field_set_handle(fieldinfo *f, java_lang_Object *o, java_handle_t *value) +static inline void _field_set_handle(fieldinfo* f, java_handle_t* h, java_handle_t* hvalue) { LLNI_CRITICAL_START; if (f->flags & ACC_STATIC) { - f->value->a = LLNI_DIRECT(value); + f->value->a = LLNI_DIRECT(hvalue); } else { - *(java_object_t **) (((intptr_t) LLNI_DIRECT(o)) + f->offset) = LLNI_DIRECT(value); + *(java_object_t**) (((intptr_t) LLNI_DIRECT(h)) + f->offset) = LLNI_DIRECT(hvalue); } LLNI_CRITICAL_END; @@ -274,16 +205,10 @@ extern "C" { * Method: getModifiersInternal * Signature: ()I */ -JNIEXPORT int32_t JNICALL Java_java_lang_reflect_VMField_getModifiersInternal(JNIEnv *env, java_lang_reflect_VMField *_this) +JNIEXPORT jint JNICALL Java_java_lang_reflect_VMField_getModifiersInternal(JNIEnv *env, jobject _this) { - classinfo *c; - fieldinfo *f; - int32_t slot; - - LLNI_field_get_cls(_this, clazz, c); - LLNI_field_get_val(_this, slot , slot); - f = &(c->fields[slot]); - + java_lang_reflect_VMField rvmf(_this); + fieldinfo* f = rvmf.get_field(); return f->flags; } @@ -293,16 +218,13 @@ JNIEXPORT int32_t JNICALL Java_java_lang_reflect_VMField_getModifiersInternal(JN * Method: getType * Signature: ()Ljava/lang/Class; */ -JNIEXPORT java_lang_Class* JNICALL Java_java_lang_reflect_VMField_getType(JNIEnv *env, java_lang_reflect_VMField *_this) +JNIEXPORT jclass JNICALL Java_java_lang_reflect_VMField_getType(JNIEnv *env, jobject _this) { - classinfo *c; - typedesc *desc; + java_lang_reflect_VMField rvmf(_this); + fieldinfo* f = rvmf.get_field(); classinfo *ret; - int32_t slot; - LLNI_field_get_cls(_this, clazz, c); - LLNI_field_get_val(_this, slot , slot); - desc = c->fields[slot].parseddesc; + typedesc* desc = f->parseddesc; if (desc == NULL) return NULL; @@ -310,7 +232,7 @@ JNIEXPORT java_lang_Class* JNICALL Java_java_lang_reflect_VMField_getType(JNIEnv if (!resolve_class_from_typedesc(desc, true, false, &ret)) return NULL; - return LLNI_classinfo_wrap(ret); + return (jclass) LLNI_classinfo_wrap(ret); } @@ -319,53 +241,50 @@ JNIEXPORT java_lang_Class* JNICALL Java_java_lang_reflect_VMField_getType(JNIEnv * Method: get * Signature: (Ljava/lang/Object;)Ljava/lang/Object; */ -JNIEXPORT java_lang_Object* JNICALL Java_java_lang_reflect_VMField_get(JNIEnv *env, java_lang_reflect_VMField *_this, java_lang_Object *o) +JNIEXPORT jobject JNICALL Java_java_lang_reflect_VMField_get(JNIEnv *env, jobject _this, jobject o) { - classinfo *c; - fieldinfo *f; - int32_t slot; - imm_union value; - java_handle_t *object; + java_lang_reflect_VMField rvmf(_this); + fieldinfo* f = rvmf.get_field(); - LLNI_field_get_cls(_this, clazz, c); - LLNI_field_get_val(_this, slot , slot); - f = &c->fields[slot]; + java_handle_t* ho = (java_handle_t*) o; /* check if the field can be accessed */ - if (!_field_access_check(_this, f, (java_handle_t *) o)) + if (!_field_access_check(rvmf, f, ho)) return NULL; + imm_union value; + switch (f->parseddesc->decltype) { case PRIMITIVETYPE_BOOLEAN: case PRIMITIVETYPE_BYTE: case PRIMITIVETYPE_CHAR: case PRIMITIVETYPE_SHORT: case PRIMITIVETYPE_INT: - value.i = _field_get_int(f, o); + value.i = _field_get_int(f, ho); break; case PRIMITIVETYPE_LONG: - value.l = _field_get_long(f, o); + value.l = _field_get_long(f, ho); break; case PRIMITIVETYPE_FLOAT: - value.f = _field_get_float(f, o); + value.f = _field_get_float(f, ho); break; case PRIMITIVETYPE_DOUBLE: - value.d = _field_get_double(f, o); + value.d = _field_get_double(f, ho); break; case TYPE_ADR: - return (java_lang_Object *) _field_get_handle(f, o); + return (jobject) _field_get_handle(f, ho); } /* Now box the primitive types. */ - object = Primitive::box(f->parseddesc->decltype, value); + java_handle_t* object = Primitive::box(f->parseddesc->decltype, value); - return (java_lang_Object *) object; + return (jobject) object; } @@ -374,28 +293,23 @@ JNIEXPORT java_lang_Object* JNICALL Java_java_lang_reflect_VMField_get(JNIEnv *e * Method: getBoolean * Signature: (Ljava/lang/Object;)Z */ -JNIEXPORT int32_t JNICALL Java_java_lang_reflect_VMField_getBoolean(JNIEnv *env, java_lang_reflect_VMField *_this, java_lang_Object *o) +JNIEXPORT jboolean JNICALL Java_java_lang_reflect_VMField_getBoolean(JNIEnv *env, jobject _this, jobject o) { - classinfo *c; - fieldinfo *f; - int32_t slot; + java_lang_reflect_VMField rvmf(_this); + fieldinfo* f = rvmf.get_field(); - /* get the class and the field */ - - LLNI_field_get_cls(_this, clazz, c); - LLNI_field_get_val(_this, slot , slot); - f = &c->fields[slot]; + java_handle_t* ho = (java_handle_t*) o; /* check if the field can be accessed */ - if (!_field_access_check(_this, f, (java_handle_t *) o)) + if (!_field_access_check(rvmf, f, ho)) return 0; /* check the field type and return the value */ switch (f->parseddesc->decltype) { case PRIMITIVETYPE_BOOLEAN: - return (int32_t) _field_get_int(f, o); + return (int32_t) _field_get_int(f, ho); default: exceptions_throw_illegalargumentexception(); return 0; @@ -408,28 +322,23 @@ JNIEXPORT int32_t JNICALL Java_java_lang_reflect_VMField_getBoolean(JNIEnv *env, * Method: getByte * Signature: (Ljava/lang/Object;)B */ -JNIEXPORT int32_t JNICALL Java_java_lang_reflect_VMField_getByte(JNIEnv *env, java_lang_reflect_VMField *_this, java_lang_Object *o) +JNIEXPORT jbyte JNICALL Java_java_lang_reflect_VMField_getByte(JNIEnv *env, jobject _this, jobject o) { - classinfo *c; - fieldinfo *f; - int32_t slot; - - /* get the class and the field */ + java_lang_reflect_VMField rvmf(_this); + fieldinfo* f = rvmf.get_field(); - LLNI_field_get_cls(_this, clazz, c); - LLNI_field_get_val(_this, slot , slot); - f = &c->fields[slot]; + java_handle_t* ho = (java_handle_t*) o; /* check if the field can be accessed */ - if (!_field_access_check(_this, f, (java_handle_t *) o)) + if (!_field_access_check(rvmf, f, ho)) return 0; /* check the field type and return the value */ switch (f->parseddesc->decltype) { case PRIMITIVETYPE_BYTE: - return (int32_t) _field_get_int(f, o); + return (int32_t) _field_get_int(f, ho); default: exceptions_throw_illegalargumentexception(); return 0; @@ -442,28 +351,23 @@ JNIEXPORT int32_t JNICALL Java_java_lang_reflect_VMField_getByte(JNIEnv *env, ja * Method: getChar * Signature: (Ljava/lang/Object;)C */ -JNIEXPORT int32_t JNICALL Java_java_lang_reflect_VMField_getChar(JNIEnv *env, java_lang_reflect_VMField *_this, java_lang_Object *o) +JNIEXPORT jchar JNICALL Java_java_lang_reflect_VMField_getChar(JNIEnv *env, jobject _this, jobject o) { - classinfo *c; - fieldinfo *f; - int32_t slot; + java_lang_reflect_VMField rvmf(_this); + fieldinfo* f = rvmf.get_field(); - /* get the class and the field */ - - LLNI_field_get_cls(_this, clazz, c); - LLNI_field_get_val(_this, slot , slot); - f = &c->fields[slot]; + java_handle_t* ho = (java_handle_t*) o; /* check if the field can be accessed */ - if (!_field_access_check(_this, f, (java_handle_t *) o)) + if (!_field_access_check(rvmf, f, ho)) return 0; /* check the field type and return the value */ switch (f->parseddesc->decltype) { case PRIMITIVETYPE_CHAR: - return (int32_t) _field_get_int(f, o); + return (int32_t) _field_get_int(f, ho); default: exceptions_throw_illegalargumentexception(); return 0; @@ -476,21 +380,16 @@ JNIEXPORT int32_t JNICALL Java_java_lang_reflect_VMField_getChar(JNIEnv *env, ja * Method: getShort * Signature: (Ljava/lang/Object;)S */ -JNIEXPORT int32_t JNICALL Java_java_lang_reflect_VMField_getShort(JNIEnv *env, java_lang_reflect_VMField *_this, java_lang_Object *o) +JNIEXPORT jshort JNICALL Java_java_lang_reflect_VMField_getShort(JNIEnv *env, jobject _this, jobject o) { - classinfo *c; - fieldinfo *f; - int32_t slot; - - /* get the class and the field */ + java_lang_reflect_VMField rvmf(_this); + fieldinfo* f = rvmf.get_field(); - LLNI_field_get_cls(_this, clazz, c); - LLNI_field_get_val(_this, slot , slot); - f = &c->fields[slot]; + java_handle_t* ho = (java_handle_t*) o; /* check if the field can be accessed */ - if (!_field_access_check(_this, f, (java_handle_t *) o)) + if (!_field_access_check(rvmf, f, ho)) return 0; /* check the field type and return the value */ @@ -498,7 +397,7 @@ JNIEXPORT int32_t JNICALL Java_java_lang_reflect_VMField_getShort(JNIEnv *env, j switch (f->parseddesc->decltype) { case PRIMITIVETYPE_BYTE: case PRIMITIVETYPE_SHORT: - return (int32_t) _field_get_int(f, o); + return (int32_t) _field_get_int(f, ho); default: exceptions_throw_illegalargumentexception(); return 0; @@ -511,21 +410,16 @@ JNIEXPORT int32_t JNICALL Java_java_lang_reflect_VMField_getShort(JNIEnv *env, j * Method: getInt * Signature: (Ljava/lang/Object;)I */ -JNIEXPORT int32_t JNICALL Java_java_lang_reflect_VMField_getInt(JNIEnv *env , java_lang_reflect_VMField *_this, java_lang_Object *o) +JNIEXPORT jint JNICALL Java_java_lang_reflect_VMField_getInt(JNIEnv *env , jobject _this, jobject o) { - classinfo *c; - fieldinfo *f; - int32_t slot; + java_lang_reflect_VMField rvmf(_this); + fieldinfo* f = rvmf.get_field(); - /* get the class and the field */ - - LLNI_field_get_cls(_this, clazz, c); - LLNI_field_get_val(_this, slot , slot); - f = &c->fields[slot]; + java_handle_t* ho = (java_handle_t*) o; /* check if the field can be accessed */ - if (!_field_access_check(_this, f, (java_handle_t *) o)) + if (!_field_access_check(rvmf, f, ho)) return 0; /* check the field type and return the value */ @@ -535,7 +429,7 @@ JNIEXPORT int32_t JNICALL Java_java_lang_reflect_VMField_getInt(JNIEnv *env , ja case PRIMITIVETYPE_CHAR: case PRIMITIVETYPE_SHORT: case PRIMITIVETYPE_INT: - return (int32_t) _field_get_int(f, o); + return (int32_t) _field_get_int(f, ho); default: exceptions_throw_illegalargumentexception(); return 0; @@ -548,21 +442,16 @@ JNIEXPORT int32_t JNICALL Java_java_lang_reflect_VMField_getInt(JNIEnv *env , ja * Method: getLong * Signature: (Ljava/lang/Object;)J */ -JNIEXPORT int64_t JNICALL Java_java_lang_reflect_VMField_getLong(JNIEnv *env, java_lang_reflect_VMField *_this, java_lang_Object *o) +JNIEXPORT jlong JNICALL Java_java_lang_reflect_VMField_getLong(JNIEnv *env, jobject _this, jobject o) { - classinfo *c; - fieldinfo *f; - int32_t slot; - - /* get the class and the field */ + java_lang_reflect_VMField rvmf(_this); + fieldinfo* f = rvmf.get_field(); - LLNI_field_get_cls(_this, clazz, c); - LLNI_field_get_val(_this, slot , slot); - f = &c->fields[slot]; + java_handle_t* ho = (java_handle_t*) o; /* check if the field can be accessed */ - if (!_field_access_check(_this, f, (java_handle_t *) o)) + if (!_field_access_check(rvmf, f, ho)) return 0; /* check the field type and return the value */ @@ -572,9 +461,9 @@ JNIEXPORT int64_t JNICALL Java_java_lang_reflect_VMField_getLong(JNIEnv *env, ja case PRIMITIVETYPE_CHAR: case PRIMITIVETYPE_SHORT: case PRIMITIVETYPE_INT: - return (int64_t) _field_get_int(f, o); + return (int64_t) _field_get_int(f, ho); case PRIMITIVETYPE_LONG: - return (int64_t) _field_get_long(f, o); + return (int64_t) _field_get_long(f, ho); default: exceptions_throw_illegalargumentexception(); return 0; @@ -587,21 +476,16 @@ JNIEXPORT int64_t JNICALL Java_java_lang_reflect_VMField_getLong(JNIEnv *env, ja * Method: getFloat * Signature: (Ljava/lang/Object;)F */ -JNIEXPORT float JNICALL Java_java_lang_reflect_VMField_getFloat(JNIEnv *env, java_lang_reflect_VMField *_this, java_lang_Object *o) +JNIEXPORT jfloat JNICALL Java_java_lang_reflect_VMField_getFloat(JNIEnv *env, jobject _this, jobject o) { - classinfo *c; - fieldinfo *f; - int32_t slot; + java_lang_reflect_VMField rvmf(_this); + fieldinfo* f = rvmf.get_field(); - /* get the class and the field */ - - LLNI_field_get_cls(_this, clazz, c); - LLNI_field_get_val(_this, slot , slot); - f = &c->fields[slot]; + java_handle_t* ho = (java_handle_t*) o; /* check if the field can be accessed */ - if (!_field_access_check(_this, f, (java_handle_t *) o)) + if (!_field_access_check(rvmf, f, ho)) return 0; /* check the field type and return the value */ @@ -611,11 +495,11 @@ JNIEXPORT float JNICALL Java_java_lang_reflect_VMField_getFloat(JNIEnv *env, jav case PRIMITIVETYPE_CHAR: case PRIMITIVETYPE_SHORT: case PRIMITIVETYPE_INT: - return (float) _field_get_int(f, o); + return (float) _field_get_int(f, ho); case PRIMITIVETYPE_LONG: - return (float) _field_get_long(f, o); + return (float) _field_get_long(f, ho); case PRIMITIVETYPE_FLOAT: - return (float) _field_get_float(f, o); + return (float) _field_get_float(f, ho); default: exceptions_throw_illegalargumentexception(); return 0; @@ -628,21 +512,16 @@ JNIEXPORT float JNICALL Java_java_lang_reflect_VMField_getFloat(JNIEnv *env, jav * Method: getDouble * Signature: (Ljava/lang/Object;)D */ -JNIEXPORT double JNICALL Java_java_lang_reflect_VMField_getDouble(JNIEnv *env , java_lang_reflect_VMField *_this, java_lang_Object *o) +JNIEXPORT jdouble JNICALL Java_java_lang_reflect_VMField_getDouble(JNIEnv *env , jobject _this, jobject o) { - classinfo *c; - fieldinfo *f; - int32_t slot; - - /* get the class and the field */ + java_lang_reflect_VMField rvmf(_this); + fieldinfo* f = rvmf.get_field(); - LLNI_field_get_cls(_this, clazz, c); - LLNI_field_get_val(_this, slot , slot); - f = &c->fields[slot]; + java_handle_t* ho = (java_handle_t*) o; /* check if the field can be accessed */ - if (!_field_access_check(_this, f, (java_handle_t *) o)) + if (!_field_access_check(rvmf, f, ho)) return 0; /* check the field type and return the value */ @@ -652,13 +531,13 @@ JNIEXPORT double JNICALL Java_java_lang_reflect_VMField_getDouble(JNIEnv *env , case PRIMITIVETYPE_CHAR: case PRIMITIVETYPE_SHORT: case PRIMITIVETYPE_INT: - return (double) _field_get_int(f, o); + return (jdouble) _field_get_int(f, ho); case PRIMITIVETYPE_LONG: - return (double) _field_get_long(f, o); + return (jdouble) _field_get_long(f, ho); case PRIMITIVETYPE_FLOAT: - return (double) _field_get_float(f, o); + return (jdouble) _field_get_float(f, ho); case PRIMITIVETYPE_DOUBLE: - return (double) _field_get_double(f, o); + return (jdouble) _field_get_double(f, ho); default: exceptions_throw_illegalargumentexception(); return 0; @@ -671,31 +550,28 @@ JNIEXPORT double JNICALL Java_java_lang_reflect_VMField_getDouble(JNIEnv *env , * Method: set * Signature: (Ljava/lang/Object;Ljava/lang/Object;)V */ -JNIEXPORT void JNICALL Java_java_lang_reflect_VMField_set(JNIEnv *env, java_lang_reflect_VMField *_this, java_lang_Object *o, java_lang_Object *value) +JNIEXPORT void JNICALL Java_java_lang_reflect_VMField_set(JNIEnv *env, jobject _this, jobject o, jobject value) { - classinfo *sc; - classinfo *dc; - fieldinfo *sf; - fieldinfo *df; - int32_t slot; + java_lang_reflect_VMField rvmf(_this); + fieldinfo* df = rvmf.get_field(); - /* get the class and the field */ + java_handle_t* ho = (java_handle_t*) o; + java_handle_t* hvalue = (java_handle_t*) value; - LLNI_field_get_cls(_this, clazz, dc); - LLNI_field_get_val(_this, slot , slot); - df = &dc->fields[slot]; + classinfo *sc; + fieldinfo *sf; /* check if the field can be accessed */ - if (!_field_access_check(_this, df, (java_handle_t *) o)) + if (!_field_access_check(rvmf, df, ho)) return; /* get the source classinfo from the object */ - if (value == NULL) + if (hvalue == NULL) sc = NULL; else - LLNI_class_get(value, sc); + LLNI_class_get(hvalue, sc); /* The fieldid is used to set the new value, for primitive types the value has to be retrieved from the wrapping @@ -712,14 +588,14 @@ JNIEXPORT void JNICALL Java_java_lang_reflect_VMField_set(JNIEnv *env, java_lang switch (sf->parseddesc->decltype) { case PRIMITIVETYPE_BOOLEAN: - LLNI_field_get_val((java_lang_Boolean *) value, value, val); + val = java_lang_Boolean(hvalue).get_value(); break; default: exceptions_throw_illegalargumentexception(); return; } - _field_set_int(df, o, val); + _field_set_int(df, ho, val); return; } @@ -731,14 +607,14 @@ JNIEXPORT void JNICALL Java_java_lang_reflect_VMField_set(JNIEnv *env, java_lang switch (sf->parseddesc->decltype) { case PRIMITIVETYPE_BYTE: - LLNI_field_get_val((java_lang_Byte *) value, value, val); + val = java_lang_Byte(hvalue).get_value(); break; default: exceptions_throw_illegalargumentexception(); return; } - _field_set_int(df, o, val); + _field_set_int(df, ho, val); return; } @@ -750,14 +626,14 @@ JNIEXPORT void JNICALL Java_java_lang_reflect_VMField_set(JNIEnv *env, java_lang switch (sf->parseddesc->decltype) { case PRIMITIVETYPE_CHAR: - LLNI_field_get_val((java_lang_Character *) value, value, val); + val = java_lang_Character(hvalue).get_value(); break; default: exceptions_throw_illegalargumentexception(); return; } - _field_set_int(df, o, val); + _field_set_int(df, ho, val); return; } @@ -771,17 +647,17 @@ JNIEXPORT void JNICALL Java_java_lang_reflect_VMField_set(JNIEnv *env, java_lang switch (sf->parseddesc->decltype) { case PRIMITIVETYPE_BYTE: - LLNI_field_get_val((java_lang_Byte *) value, value, val); + val = java_lang_Byte(hvalue).get_value(); break; case PRIMITIVETYPE_SHORT: - LLNI_field_get_val((java_lang_Short *) value, value, val); + val = java_lang_Short(hvalue).get_value(); break; default: exceptions_throw_illegalargumentexception(); return; } - _field_set_int(df, o, val); + _field_set_int(df, ho, val); return; } @@ -795,23 +671,23 @@ JNIEXPORT void JNICALL Java_java_lang_reflect_VMField_set(JNIEnv *env, java_lang switch (sf->parseddesc->decltype) { case PRIMITIVETYPE_BYTE: - LLNI_field_get_val((java_lang_Byte *) value, value, val); + val = java_lang_Byte(hvalue).get_value(); break; case PRIMITIVETYPE_CHAR: - LLNI_field_get_val((java_lang_Character *) value, value, val); + val = java_lang_Character(hvalue).get_value(); break; case PRIMITIVETYPE_SHORT: - LLNI_field_get_val((java_lang_Short *) value, value, val); + val = java_lang_Short(hvalue).get_value(); break; case PRIMITIVETYPE_INT: - LLNI_field_get_val((java_lang_Integer *) value, value, val); + val = java_lang_Integer(hvalue).get_value(); break; default: exceptions_throw_illegalargumentexception(); return; } - _field_set_int(df, o, val); + _field_set_int(df, ho, val); return; } @@ -825,26 +701,26 @@ JNIEXPORT void JNICALL Java_java_lang_reflect_VMField_set(JNIEnv *env, java_lang switch (sf->parseddesc->decltype) { case PRIMITIVETYPE_BYTE: - LLNI_field_get_val((java_lang_Byte *) value, value, val); + val = java_lang_Byte(hvalue).get_value(); break; case PRIMITIVETYPE_CHAR: - LLNI_field_get_val((java_lang_Character *) value, value, val); + val = java_lang_Character(hvalue).get_value(); break; case PRIMITIVETYPE_SHORT: - LLNI_field_get_val((java_lang_Short *) value, value, val); + val = java_lang_Short(hvalue).get_value(); break; case PRIMITIVETYPE_INT: - LLNI_field_get_val((java_lang_Integer *) value, value, val); + val = java_lang_Integer(hvalue).get_value(); break; case PRIMITIVETYPE_LONG: - LLNI_field_get_val((java_lang_Long *) value, value, val); + val = java_lang_Long(hvalue).get_value(); break; default: exceptions_throw_illegalargumentexception(); return; } - _field_set_long(df, o, val); + _field_set_long(df, ho, val); return; } @@ -858,29 +734,29 @@ JNIEXPORT void JNICALL Java_java_lang_reflect_VMField_set(JNIEnv *env, java_lang switch (sf->parseddesc->decltype) { case PRIMITIVETYPE_BYTE: - LLNI_field_get_val((java_lang_Byte *) value, value, val); + val = java_lang_Byte(hvalue).get_value(); break; case PRIMITIVETYPE_CHAR: - LLNI_field_get_val((java_lang_Character *) value, value, val); + val = java_lang_Character(hvalue).get_value(); break; case PRIMITIVETYPE_SHORT: - LLNI_field_get_val((java_lang_Short *) value, value, val); + val = java_lang_Short(hvalue).get_value(); break; case PRIMITIVETYPE_INT: - LLNI_field_get_val((java_lang_Integer *) value, value, val); + val = java_lang_Integer(hvalue).get_value(); break; case PRIMITIVETYPE_LONG: - LLNI_field_get_val((java_lang_Long *) value, value, val); + val = java_lang_Long(hvalue).get_value(); break; case PRIMITIVETYPE_FLOAT: - LLNI_field_get_val((java_lang_Float *) value, value, val); + val = java_lang_Float(hvalue).get_value(); break; default: exceptions_throw_illegalargumentexception(); return; } - _field_set_float(df, o, val); + _field_set_float(df, ho, val); return; } @@ -894,32 +770,32 @@ JNIEXPORT void JNICALL Java_java_lang_reflect_VMField_set(JNIEnv *env, java_lang switch (sf->parseddesc->decltype) { case PRIMITIVETYPE_BYTE: - LLNI_field_get_val((java_lang_Byte *) value, value, val); + val = java_lang_Byte(hvalue).get_value(); break; case PRIMITIVETYPE_CHAR: - LLNI_field_get_val((java_lang_Character *) value, value, val); + val = java_lang_Character(hvalue).get_value(); break; case PRIMITIVETYPE_SHORT: - LLNI_field_get_val((java_lang_Short *) value, value, val); + val = java_lang_Short(hvalue).get_value(); break; case PRIMITIVETYPE_INT: - LLNI_field_get_val((java_lang_Integer *) value, value, val); + val = java_lang_Integer(hvalue).get_value(); break; case PRIMITIVETYPE_LONG: - LLNI_field_get_val((java_lang_Long *) value, value, val); + val = java_lang_Long(hvalue).get_value(); break; case PRIMITIVETYPE_FLOAT: - LLNI_field_get_val((java_lang_Float *) value, value, val); + val = java_lang_Float(hvalue).get_value(); break; case PRIMITIVETYPE_DOUBLE: - LLNI_field_get_val((java_lang_Double *) value, value, val); + val = java_lang_Double(hvalue).get_value(); break; default: exceptions_throw_illegalargumentexception(); return; } - _field_set_double(df, o, val); + _field_set_double(df, ho, val); return; } @@ -930,7 +806,7 @@ JNIEXPORT void JNICALL Java_java_lang_reflect_VMField_set(JNIEnv *env, java_lang /* if (!builtin_instanceof((java_handle_t *) value, df->class)) */ /* break; */ - _field_set_handle(df, o, (java_handle_t *) value); + _field_set_handle(df, ho, hvalue); return; } @@ -945,34 +821,27 @@ JNIEXPORT void JNICALL Java_java_lang_reflect_VMField_set(JNIEnv *env, java_lang * Method: setBoolean * Signature: (Ljava/lang/Object;Z)V */ -JNIEXPORT void JNICALL Java_java_lang_reflect_VMField_setBoolean(JNIEnv *env, java_lang_reflect_VMField *_this, java_lang_Object *o, int32_t value) +JNIEXPORT void JNICALL Java_java_lang_reflect_VMField_setBoolean(JNIEnv *env, jobject _this, jobject o, jboolean value) { - classinfo *c; - fieldinfo *f; - int32_t slot; + java_lang_reflect_VMField rvmf(_this); + fieldinfo* f = rvmf.get_field(); - /* get the class and the field */ - - LLNI_field_get_cls(_this, clazz, c); - LLNI_field_get_val(_this, slot , slot); - f = &c->fields[slot]; + java_handle_t* ho = (java_handle_t*) o; /* check if the field can be accessed */ - if (!_field_access_check(_this, f, (java_handle_t *) o)) + if (!_field_access_check(rvmf, f, ho)) return; /* check the field type and set the value */ switch (f->parseddesc->decltype) { case PRIMITIVETYPE_BOOLEAN: - _field_set_int(f, o, value); + _field_set_int(f, ho, value); break; default: exceptions_throw_illegalargumentexception(); } - - return; } @@ -981,21 +850,16 @@ JNIEXPORT void JNICALL Java_java_lang_reflect_VMField_setBoolean(JNIEnv *env, ja * Method: setByte * Signature: (Ljava/lang/Object;B)V */ -JNIEXPORT void JNICALL Java_java_lang_reflect_VMField_setByte(JNIEnv *env, java_lang_reflect_VMField *_this, java_lang_Object *o, int32_t value) +JNIEXPORT void JNICALL Java_java_lang_reflect_VMField_setByte(JNIEnv *env, jobject _this, jobject o, jbyte value) { - classinfo *c; - fieldinfo *f; - int32_t slot; - - /* get the class and the field */ + java_lang_reflect_VMField rvmf(_this); + fieldinfo* f = rvmf.get_field(); - LLNI_field_get_cls(_this, clazz, c); - LLNI_field_get_val(_this, slot , slot); - f = &c->fields[slot]; + java_handle_t* ho = (java_handle_t*) o; /* check if the field can be accessed */ - if (!_field_access_check(_this, f, (java_handle_t *) o)) + if (!_field_access_check(rvmf, f, ho)) return; /* check the field type and set the value */ @@ -1004,22 +868,20 @@ JNIEXPORT void JNICALL Java_java_lang_reflect_VMField_setByte(JNIEnv *env, java_ case PRIMITIVETYPE_BYTE: case PRIMITIVETYPE_SHORT: case PRIMITIVETYPE_INT: - _field_set_int(f, o, value); + _field_set_int(f, ho, value); break; case PRIMITIVETYPE_LONG: - _field_set_long(f, o, value); + _field_set_long(f, ho, value); break; case PRIMITIVETYPE_FLOAT: - _field_set_float(f, o, value); + _field_set_float(f, ho, value); break; case PRIMITIVETYPE_DOUBLE: - _field_set_double(f, o, value); + _field_set_double(f, ho, value); break; default: exceptions_throw_illegalargumentexception(); } - - return; } @@ -1028,21 +890,16 @@ JNIEXPORT void JNICALL Java_java_lang_reflect_VMField_setByte(JNIEnv *env, java_ * Method: setChar * Signature: (Ljava/lang/Object;C)V */ -JNIEXPORT void JNICALL Java_java_lang_reflect_VMField_setChar(JNIEnv *env, java_lang_reflect_VMField *_this, java_lang_Object *o, int32_t value) +JNIEXPORT void JNICALL Java_java_lang_reflect_VMField_setChar(JNIEnv *env, jobject _this, jobject o, jchar value) { - classinfo *c; - fieldinfo *f; - int32_t slot; - - /* get the class and the field */ + java_lang_reflect_VMField rvmf(_this); + fieldinfo* f = rvmf.get_field(); - LLNI_field_get_cls(_this, clazz, c); - LLNI_field_get_val(_this, slot , slot); - f = &c->fields[slot]; + java_handle_t* ho = (java_handle_t*) o; /* check if the field can be accessed */ - if (!_field_access_check(_this, f, (java_handle_t *) o)) + if (!_field_access_check(rvmf, f, ho)) return; /* check the field type and set the value */ @@ -1050,22 +907,20 @@ JNIEXPORT void JNICALL Java_java_lang_reflect_VMField_setChar(JNIEnv *env, java_ switch (f->parseddesc->decltype) { case PRIMITIVETYPE_CHAR: case PRIMITIVETYPE_INT: - _field_set_int(f, o, value); + _field_set_int(f, ho, value); break; case PRIMITIVETYPE_LONG: - _field_set_long(f, o, value); + _field_set_long(f, ho, value); break; case PRIMITIVETYPE_FLOAT: - _field_set_float(f, o, value); + _field_set_float(f, ho, value); break; case PRIMITIVETYPE_DOUBLE: - _field_set_double(f, o, value); + _field_set_double(f, ho, value); break; default: exceptions_throw_illegalargumentexception(); } - - return; } @@ -1074,21 +929,16 @@ JNIEXPORT void JNICALL Java_java_lang_reflect_VMField_setChar(JNIEnv *env, java_ * Method: setShort * Signature: (Ljava/lang/Object;S)V */ -JNIEXPORT void JNICALL Java_java_lang_reflect_VMField_setShort(JNIEnv *env, java_lang_reflect_VMField *_this, java_lang_Object *o, int32_t value) +JNIEXPORT void JNICALL Java_java_lang_reflect_VMField_setShort(JNIEnv *env, jobject _this, jobject o, jshort value) { - classinfo *c; - fieldinfo *f; - int32_t slot; - - /* get the class and the field */ + java_lang_reflect_VMField rvmf(_this); + fieldinfo* f = rvmf.get_field(); - LLNI_field_get_cls(_this, clazz, c); - LLNI_field_get_val(_this, slot , slot); - f = &c->fields[slot]; + java_handle_t* ho = (java_handle_t*) o; /* check if the field can be accessed */ - if (!_field_access_check(_this, f, (java_handle_t *) o)) + if (!_field_access_check(rvmf, f, ho)) return; /* check the field type and set the value */ @@ -1096,22 +946,20 @@ JNIEXPORT void JNICALL Java_java_lang_reflect_VMField_setShort(JNIEnv *env, java switch (f->parseddesc->decltype) { case PRIMITIVETYPE_SHORT: case PRIMITIVETYPE_INT: - _field_set_int(f, o, value); + _field_set_int(f, ho, value); break; case PRIMITIVETYPE_LONG: - _field_set_long(f, o, value); + _field_set_long(f, ho, value); break; case PRIMITIVETYPE_FLOAT: - _field_set_float(f, o, value); + _field_set_float(f, ho, value); break; case PRIMITIVETYPE_DOUBLE: - _field_set_double(f, o, value); + _field_set_double(f, ho, value); break; default: exceptions_throw_illegalargumentexception(); } - - return; } @@ -1120,43 +968,36 @@ JNIEXPORT void JNICALL Java_java_lang_reflect_VMField_setShort(JNIEnv *env, java * Method: setInt * Signature: (Ljava/lang/Object;I)V */ -JNIEXPORT void JNICALL Java_java_lang_reflect_VMField_setInt(JNIEnv *env, java_lang_reflect_VMField *_this, java_lang_Object *o, int32_t value) +JNIEXPORT void JNICALL Java_java_lang_reflect_VMField_setInt(JNIEnv *env, jobject _this, jobject o, jint value) { - classinfo *c; - fieldinfo *f; - int32_t slot; - - /* get the class and the field */ + java_lang_reflect_VMField rvmf(_this); + fieldinfo* f = rvmf.get_field(); - LLNI_field_get_cls(_this, clazz, c); - LLNI_field_get_val(_this, slot , slot); - f = &c->fields[slot]; + java_handle_t* ho = (java_handle_t*) o; /* check if the field can be accessed */ - if (!_field_access_check(_this, f, (java_handle_t *) o)) + if (!_field_access_check(rvmf, f, ho)) return; /* check the field type and set the value */ switch (f->parseddesc->decltype) { case PRIMITIVETYPE_INT: - _field_set_int(f, o, value); + _field_set_int(f, ho, value); break; case PRIMITIVETYPE_LONG: - _field_set_long(f, o, value); + _field_set_long(f, ho, value); break; case PRIMITIVETYPE_FLOAT: - _field_set_float(f, o, value); + _field_set_float(f, ho, value); break; case PRIMITIVETYPE_DOUBLE: - _field_set_double(f, o, value); + _field_set_double(f, ho, value); break; default: exceptions_throw_illegalargumentexception(); } - - return; } @@ -1165,40 +1006,33 @@ JNIEXPORT void JNICALL Java_java_lang_reflect_VMField_setInt(JNIEnv *env, java_l * Method: setLong * Signature: (Ljava/lang/Object;J)V */ -JNIEXPORT void JNICALL Java_java_lang_reflect_VMField_setLong(JNIEnv *env, java_lang_reflect_VMField *_this, java_lang_Object *o, int64_t value) +JNIEXPORT void JNICALL Java_java_lang_reflect_VMField_setLong(JNIEnv *env, jobject _this, jobject o, jlong value) { - classinfo *c; - fieldinfo *f; - int32_t slot; - - /* get the class and the field */ + java_lang_reflect_VMField rvmf(_this); + fieldinfo* f = rvmf.get_field(); - LLNI_field_get_cls(_this, clazz, c); - LLNI_field_get_val(_this, slot , slot); - f = &c->fields[slot]; + java_handle_t* ho = (java_handle_t*) o; /* check if the field can be accessed */ - if (!_field_access_check(_this, f, (java_handle_t *) o)) + if (!_field_access_check(rvmf, f, ho)) return; /* check the field type and set the value */ switch (f->parseddesc->decltype) { case PRIMITIVETYPE_LONG: - _field_set_long(f, o, value); + _field_set_long(f, ho, value); break; case PRIMITIVETYPE_FLOAT: - _field_set_float(f, o, value); + _field_set_float(f, ho, value); break; case PRIMITIVETYPE_DOUBLE: - _field_set_double(f, o, value); + _field_set_double(f, ho, value); break; default: exceptions_throw_illegalargumentexception(); } - - return; } @@ -1207,37 +1041,30 @@ JNIEXPORT void JNICALL Java_java_lang_reflect_VMField_setLong(JNIEnv *env, java_ * Method: setFloat * Signature: (Ljava/lang/Object;F)V */ -JNIEXPORT void JNICALL Java_java_lang_reflect_VMField_setFloat(JNIEnv *env, java_lang_reflect_VMField *_this, java_lang_Object *o, float value) +JNIEXPORT void JNICALL Java_java_lang_reflect_VMField_setFloat(JNIEnv *env, jobject _this, jobject o, jfloat value) { - classinfo *c; - fieldinfo *f; - int32_t slot; - - /* get the class and the field */ + java_lang_reflect_VMField rvmf(_this); + fieldinfo* f = rvmf.get_field(); - LLNI_field_get_cls(_this, clazz, c); - LLNI_field_get_val(_this, slot , slot); - f = &c->fields[slot]; + java_handle_t* ho = (java_handle_t*) o; /* check if the field can be accessed */ - if (!_field_access_check(_this, f, (java_handle_t *) o)) + if (!_field_access_check(rvmf, f, ho)) return; /* check the field type and set the value */ switch (f->parseddesc->decltype) { case PRIMITIVETYPE_FLOAT: - _field_set_float(f, o, value); + _field_set_float(f, ho, value); break; case PRIMITIVETYPE_DOUBLE: - _field_set_double(f, o, value); + _field_set_double(f, ho, value); break; default: exceptions_throw_illegalargumentexception(); } - - return; } @@ -1246,34 +1073,27 @@ JNIEXPORT void JNICALL Java_java_lang_reflect_VMField_setFloat(JNIEnv *env, java * Method: setDouble * Signature: (Ljava/lang/Object;D)V */ -JNIEXPORT void JNICALL Java_java_lang_reflect_VMField_setDouble(JNIEnv *env, java_lang_reflect_VMField *_this, java_lang_Object *o, double value) +JNIEXPORT void JNICALL Java_java_lang_reflect_VMField_setDouble(JNIEnv *env, jobject _this, jobject o, jdouble value) { - classinfo *c; - fieldinfo *f; - int32_t slot; - - /* get the class and the field */ + java_lang_reflect_VMField rvmf(_this); + fieldinfo* f = rvmf.get_field(); - LLNI_field_get_cls(_this, clazz, c); - LLNI_field_get_val(_this, slot , slot); - f = &c->fields[slot]; + java_handle_t* ho = (java_handle_t*) o; /* check if the field can be accessed */ - if (!_field_access_check(_this, f, (java_handle_t *) o)) + if (!_field_access_check(rvmf, f, ho)) return; /* check the field type and set the value */ switch (f->parseddesc->decltype) { case PRIMITIVETYPE_DOUBLE: - _field_set_double(f, o, value); + _field_set_double(f, ho, value); break; default: exceptions_throw_illegalargumentexception(); } - - return; } @@ -1282,27 +1102,19 @@ JNIEXPORT void JNICALL Java_java_lang_reflect_VMField_setDouble(JNIEnv *env, jav * Method: getSignature * Signature: ()Ljava/lang/String; */ -JNIEXPORT java_lang_String* JNICALL Java_java_lang_reflect_VMField_getSignature(JNIEnv *env, java_lang_reflect_VMField* _this) +JNIEXPORT jstring JNICALL Java_java_lang_reflect_VMField_getSignature(JNIEnv *env, jobject _this) { - classinfo *c; - fieldinfo *f; - java_handle_t *o; - int32_t slot; - - /* get the class and the field */ - - LLNI_field_get_cls(_this, clazz, c); - LLNI_field_get_val(_this, slot , slot); - f = &c->fields[slot]; + java_lang_reflect_VMField rvmf(_this); + fieldinfo* f = rvmf.get_field(); if (f->signature == NULL) return NULL; - o = javastring_new(f->signature); + java_handle_t* o = javastring_new(f->signature); /* in error case o is NULL */ - return (java_lang_String *) o; + return (jstring) o; } @@ -1312,34 +1124,81 @@ JNIEXPORT java_lang_String* JNICALL Java_java_lang_reflect_VMField_getSignature( * Method: declaredAnnotations * Signature: ()Ljava/util/Map; */ -JNIEXPORT struct java_util_Map* JNICALL Java_java_lang_reflect_VMField_declaredAnnotations(JNIEnv *env, java_lang_reflect_VMField *_this) +JNIEXPORT jobject JNICALL Java_java_lang_reflect_VMField_declaredAnnotations(JNIEnv *env, jobject _this) { - java_util_Map *declaredAnnotations = NULL; /* parsed annotations */ - java_handle_bytearray_t *annotations = NULL; /* unparsed annotations */ - java_lang_Class *declaringClass = NULL; /* the constant pool of this class is used */ - classinfo *referer = NULL; /* class, which calles the annotation parser */ - /* (for the parameter 'referer' of vm_call_method()) */ + java_lang_reflect_VMField rvmf(_this); - LLNI_field_get_ref(_this, declaredAnnotations, declaredAnnotations); + java_handle_t* declaredAnnotations = rvmf.get_declaredAnnotations(); - /* are the annotations parsed yet? */ + // Are the annotations parsed yet? if (declaredAnnotations == NULL) { - LLNI_field_get_ref(_this, annotations, annotations); - LLNI_field_get_ref(_this, clazz, declaringClass); + java_handle_bytearray_t* annotations = rvmf.get_annotations(); + classinfo* declaringClass = rvmf.get_clazz(); + + classinfo* referer; LLNI_class_get(_this, referer); - declaredAnnotations = reflect_get_declaredannotations(annotations, (classinfo*) declaringClass, referer); + declaredAnnotations = Reflection::get_declaredannotations(annotations, declaringClass, referer); - LLNI_field_set_ref(_this, declaredAnnotations, declaredAnnotations); + rvmf.set_declaredAnnotations(declaredAnnotations); } - return declaredAnnotations; + return (jobject) declaredAnnotations; } #endif } // extern "C" +/* native methods implemented by this file ************************************/ + +static const JNINativeMethod methods[] = { + { (char*) "getModifiersInternal", (char*) "()I", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_getModifiersInternal }, + { (char*) "getType", (char*) "()Ljava/lang/Class;", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_getType }, + { (char*) "get", (char*) "(Ljava/lang/Object;)Ljava/lang/Object;", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_get }, + { (char*) "getBoolean", (char*) "(Ljava/lang/Object;)Z", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_getBoolean }, + { (char*) "getByte", (char*) "(Ljava/lang/Object;)B", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_getByte }, + { (char*) "getChar", (char*) "(Ljava/lang/Object;)C", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_getChar }, + { (char*) "getShort", (char*) "(Ljava/lang/Object;)S", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_getShort }, + { (char*) "getInt", (char*) "(Ljava/lang/Object;)I", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_getInt }, + { (char*) "getLong", (char*) "(Ljava/lang/Object;)J", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_getLong }, + { (char*) "getFloat", (char*) "(Ljava/lang/Object;)F", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_getFloat }, + { (char*) "getDouble", (char*) "(Ljava/lang/Object;)D", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_getDouble }, + { (char*) "set", (char*) "(Ljava/lang/Object;Ljava/lang/Object;)V", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_set }, + { (char*) "setBoolean", (char*) "(Ljava/lang/Object;Z)V", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_setBoolean }, + { (char*) "setByte", (char*) "(Ljava/lang/Object;B)V", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_setByte }, + { (char*) "setChar", (char*) "(Ljava/lang/Object;C)V", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_setChar }, + { (char*) "setShort", (char*) "(Ljava/lang/Object;S)V", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_setShort }, + { (char*) "setInt", (char*) "(Ljava/lang/Object;I)V", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_setInt }, + { (char*) "setLong", (char*) "(Ljava/lang/Object;J)V", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_setLong }, + { (char*) "setFloat", (char*) "(Ljava/lang/Object;F)V", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_setFloat }, + { (char*) "setDouble", (char*) "(Ljava/lang/Object;D)V", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_setDouble }, + { (char*) "getSignature", (char*) "()Ljava/lang/String;", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_getSignature }, +#if defined(ENABLE_ANNOTATIONS) + { (char*) "declaredAnnotations", (char*) "()Ljava/util/Map;", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_declaredAnnotations }, +#endif +}; + + +/* _Jv_java_lang_reflect_VMField_init ****************************************** + + Register native functions. + +*******************************************************************************/ + +// FIXME +extern "C" { +void _Jv_java_lang_reflect_VMField_init(void) +{ + utf *u; + + u = utf_new_char("java/lang/reflect/VMField"); + + native_method_register(u, methods, NATIVE_METHODS_COUNT); +} +} + + /* * 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 diff --git a/src/native/vm/gnuclasspath/java_lang_reflect_VMMethod.cpp b/src/native/vm/gnuclasspath/java_lang_reflect_VMMethod.cpp index 168161276..4eea085f2 100644 --- a/src/native/vm/gnuclasspath/java_lang_reflect_VMMethod.cpp +++ b/src/native/vm/gnuclasspath/java_lang_reflect_VMMethod.cpp @@ -35,23 +35,10 @@ #include "native/llni.h" #include "native/native.h" -#include "native/include/java_lang_Object.h" -#include "native/include/java_lang_Class.h" -#include "native/include/java_lang_String.h" - -#if defined(ENABLE_ANNOTATIONS) -# include "native/include/java_util_Map.h" -# include "native/include/sun_reflect_ConstantPool.h" -#endif - -#include "native/include/java_lang_reflect_Method.h" - // FIXME -extern "C" { -#include "native/include/java_lang_reflect_VMMethod.h" -} +//#include "native/include/java_lang_reflect_VMMethod.h" -#include "native/vm/reflect.h" +#include "native/vm/reflection.hpp" #include "vm/access.h" #include "vm/global.h" @@ -61,46 +48,12 @@ extern "C" { #include "vm/resolve.h" #include "vm/string.hpp" +#include "vmcore/class.h" #include "vmcore/globals.hpp" +#include "vmcore/javaobjects.hpp" #include "vmcore/method.h" -/* native methods implemented by this file ************************************/ - -static JNINativeMethod methods[] = { - { (char*) "getModifiersInternal", (char*) "()I", (void*) (uintptr_t) &Java_java_lang_reflect_VMMethod_getModifiersInternal }, - { (char*) "getReturnType", (char*) "()Ljava/lang/Class;", (void*) (uintptr_t) &Java_java_lang_reflect_VMMethod_getReturnType }, - { (char*) "getParameterTypes", (char*) "()[Ljava/lang/Class;", (void*) (uintptr_t) &Java_java_lang_reflect_VMMethod_getParameterTypes }, - { (char*) "getExceptionTypes", (char*) "()[Ljava/lang/Class;", (void*) (uintptr_t) &Java_java_lang_reflect_VMMethod_getExceptionTypes }, - { (char*) "invoke", (char*) "(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;", (void*) (uintptr_t) &Java_java_lang_reflect_VMMethod_invoke }, - { (char*) "getSignature", (char*) "()Ljava/lang/String;", (void*) (uintptr_t) &Java_java_lang_reflect_VMMethod_getSignature }, -#if defined(ENABLE_ANNOTATIONS) - { (char*) "getDefaultValue", (char*) "()Ljava/lang/Object;", (void*) (uintptr_t) &Java_java_lang_reflect_VMMethod_getDefaultValue }, - { (char*) "declaredAnnotations", (char*) "()Ljava/util/Map;", (void*) (uintptr_t) &Java_java_lang_reflect_VMMethod_declaredAnnotations }, - { (char*) "getParameterAnnotations", (char*) "()[[Ljava/lang/annotation/Annotation;", (void*) (uintptr_t) &Java_java_lang_reflect_VMMethod_getParameterAnnotations }, -#endif -}; - - -/* _Jv_java_lang_reflect_VMMethod_init ***************************************** - - Register native functions. - -*******************************************************************************/ - -// FIXME -extern "C" { -void _Jv_java_lang_reflect_VMMethod_init(void) -{ - utf *u; - - u = utf_new_char("java/lang/reflect/VMMethod"); - - native_method_register(u, methods, NATIVE_METHODS_COUNT); -} -} - - // Native functions are exported as C functions. extern "C" { @@ -109,16 +62,10 @@ extern "C" { * Method: getModifiersInternal * Signature: ()I */ -JNIEXPORT int32_t JNICALL Java_java_lang_reflect_VMMethod_getModifiersInternal(JNIEnv *env, java_lang_reflect_VMMethod *_this) +JNIEXPORT jint JNICALL Java_java_lang_reflect_VMMethod_getModifiersInternal(JNIEnv *env, jobject _this) { - classinfo *c; - methodinfo *m; - int32_t slot; - - LLNI_field_get_cls(_this, clazz, c); - LLNI_field_get_val(_this, slot , slot); - m = &(c->methods[slot]); - + java_lang_reflect_VMMethod rvmm(_this); + methodinfo* m = rvmm.get_method(); return m->flags; } @@ -128,20 +75,13 @@ JNIEXPORT int32_t JNICALL Java_java_lang_reflect_VMMethod_getModifiersInternal(J * Method: getReturnType * Signature: ()Ljava/lang/Class; */ -JNIEXPORT java_lang_Class* JNICALL Java_java_lang_reflect_VMMethod_getReturnType(JNIEnv *env, java_lang_reflect_VMMethod *_this) +JNIEXPORT jclass JNICALL Java_java_lang_reflect_VMMethod_getReturnType(JNIEnv *env, jobject _this) { - classinfo *c; - methodinfo *m; - classinfo *result; - int32_t slot; - - LLNI_field_get_cls(_this, clazz, c); - LLNI_field_get_val(_this, slot , slot); - m = &(c->methods[slot]); - - result = method_returntype_get(m); + java_lang_reflect_VMMethod rvmm(_this); + methodinfo* m = rvmm.get_method(); + classinfo* c = method_returntype_get(m); - return LLNI_classinfo_wrap(result); + return (jclass) LLNI_classinfo_wrap(c); } @@ -150,17 +90,12 @@ JNIEXPORT java_lang_Class* JNICALL Java_java_lang_reflect_VMMethod_getReturnType * Method: getParameterTypes * Signature: ()[Ljava/lang/Class; */ -JNIEXPORT java_handle_objectarray_t* JNICALL Java_java_lang_reflect_VMMethod_getParameterTypes(JNIEnv *env, java_lang_reflect_VMMethod *_this) +JNIEXPORT jobjectArray JNICALL Java_java_lang_reflect_VMMethod_getParameterTypes(JNIEnv *env, jobject _this) { - classinfo *c; - methodinfo *m; - int32_t slot; - - LLNI_field_get_cls(_this, clazz, c); - LLNI_field_get_val(_this, slot , slot); - m = &(c->methods[slot]); - - return method_get_parametertypearray(m); + java_lang_reflect_VMMethod rvmm(_this); + methodinfo* m = rvmm.get_method(); + java_handle_objectarray_t* oa = method_get_parametertypearray(m); + return (jobjectArray) oa; } @@ -169,17 +104,12 @@ JNIEXPORT java_handle_objectarray_t* JNICALL Java_java_lang_reflect_VMMethod_get * Method: getExceptionTypes * Signature: ()[Ljava/lang/Class; */ -JNIEXPORT java_handle_objectarray_t* JNICALL Java_java_lang_reflect_VMMethod_getExceptionTypes(JNIEnv *env, java_lang_reflect_VMMethod *_this) +JNIEXPORT jobjectArray JNICALL Java_java_lang_reflect_VMMethod_getExceptionTypes(JNIEnv *env, jobject _this) { - classinfo *c; - methodinfo *m; - int32_t slot; - - LLNI_field_get_cls(_this, clazz, c); - LLNI_field_get_val(_this, slot , slot); - m = &(c->methods[slot]); - - return method_get_exceptionarray(m); + java_lang_reflect_VMMethod rvmm(_this); + methodinfo* m = rvmm.get_method(); + java_handle_objectarray_t* oa = method_get_exceptionarray(m); + return (jobjectArray) oa; } @@ -188,26 +118,17 @@ JNIEXPORT java_handle_objectarray_t* JNICALL Java_java_lang_reflect_VMMethod_get * Method: invoke * Signature: (Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object; */ -JNIEXPORT java_lang_Object* JNICALL Java_java_lang_reflect_VMMethod_invoke(JNIEnv *env, java_lang_reflect_VMMethod *_this, java_lang_Object *o, java_handle_objectarray_t *args) +JNIEXPORT jobject JNICALL Java_java_lang_reflect_VMMethod_invoke(JNIEnv *env, jobject _this, jobject o, jobjectArray args) { - classinfo *c; - int32_t slot; - java_lang_reflect_Method *rm; - int32_t override; - methodinfo *m; - java_handle_t *ro; - - LLNI_field_get_cls(_this, clazz, c); - LLNI_field_get_val(_this, slot, slot); + java_lang_reflect_VMMethod rvmm(_this); + java_lang_reflect_Method rm(rvmm.get_m()); - LLNI_field_get_ref(_this, m, rm); - LLNI_field_get_val(rm, flag, override); + methodinfo* m = rvmm.get_method(); + int32_t override = rm.get_flag(); - m = &(c->methods[slot]); + java_handle_t* result = Reflection::method_invoke(m, (java_handle_t*) o, (java_handle_objectarray_t*) args, override); - ro = reflect_method_invoke(m, (java_handle_t *) o, args, override); - - return (java_lang_Object *) ro; + return (jobject) result; } @@ -216,27 +137,22 @@ JNIEXPORT java_lang_Object* JNICALL Java_java_lang_reflect_VMMethod_invoke(JNIEn * Method: getSignature * Signature: ()Ljava/lang/String; */ -JNIEXPORT java_lang_String* JNICALL Java_java_lang_reflect_VMMethod_getSignature(JNIEnv *env, java_lang_reflect_VMMethod* _this) +JNIEXPORT jstring JNICALL Java_java_lang_reflect_VMMethod_getSignature(JNIEnv *env, jobject _this) { - classinfo *c; - methodinfo *m; - java_handle_t *o; - int32_t slot; - - LLNI_field_get_cls(_this, clazz, c); - LLNI_field_get_val(_this, slot , slot); - m = &(c->methods[slot]); + java_lang_reflect_VMMethod rvmm(_this); + methodinfo* m = rvmm.get_method(); if (m->signature == NULL) return NULL; - o = javastring_new(m->signature); + java_handle_t* s = javastring_new(m->signature); /* in error case o is NULL */ - return (java_lang_String *) o; + return (jstring) s; } + #if defined(ENABLE_ANNOTATIONS) /* * Class: java/lang/reflect/VMMethod @@ -245,35 +161,28 @@ JNIEXPORT java_lang_String* JNICALL Java_java_lang_reflect_VMMethod_getSignature * * Parses the annotation default value and returnes it (boxed, if it's a primitive). */ -JNIEXPORT struct java_lang_Object* JNICALL Java_java_lang_reflect_VMMethod_getDefaultValue(JNIEnv *env, struct java_lang_reflect_VMMethod* _this) +JNIEXPORT jobject JNICALL Java_java_lang_reflect_VMMethod_getDefaultValue(JNIEnv *env, jobject _this) { - java_handle_bytearray_t *annotationDefault = NULL; /* unparsed annotation default value */ static methodinfo *m_parseAnnotationDefault = NULL; /* parser method (will be chached, therefore static) */ utf *utf_parseAnnotationDefault = NULL; /* parser method name */ utf *utf_desc = NULL; /* parser method descriptor (signature) */ - sun_reflect_ConstantPool *constantPool = NULL; /* constant pool object to use */ - java_lang_Class *constantPoolOop = NULL; /* methods declaring class */ - classinfo *referer = NULL; /* class, which calles the annotation parser */ - /* (for the parameter 'referer' of vm_call_method()) */ - java_lang_reflect_Method* rm; - java_handle_t* h; if (_this == NULL) { exceptions_throw_nullpointerexception(); return NULL; } - constantPool = - (sun_reflect_ConstantPool*)native_new_and_init( - class_sun_reflect_ConstantPool); - - if (constantPool == NULL) { - /* out of memory */ + // TODO Use a constructor. + java_handle_t* h = native_new_and_init(class_sun_reflect_ConstantPool); + + if (h == NULL) return NULL; - } - LLNI_field_get_ref(_this, clazz, constantPoolOop); - LLNI_field_set_ref(constantPool, constantPoolOop, (java_lang_Object*)constantPoolOop); + sun_reflect_ConstantPool cp(h); + + java_lang_reflect_VMMethod rvmm(_this); + classinfo* declaringClass = rvmm.get_clazz(); + cp.set_constantPoolOop(declaringClass); /* only resolve the parser method the first time */ if (m_parseAnnotationDefault == NULL) { @@ -287,7 +196,8 @@ JNIEXPORT struct java_lang_Object* JNICALL Java_java_lang_reflect_VMMethod_getDe return NULL; } - LLNI_class_get(_this, referer); + classinfo *referer; + LLNI_class_get((java_lang_reflect_VMMethod *) _this, referer); m_parseAnnotationDefault = class_resolveclassmethod( class_sun_reflect_annotation_AnnotationParser, @@ -302,12 +212,12 @@ JNIEXPORT struct java_lang_Object* JNICALL Java_java_lang_reflect_VMMethod_getDe } } - LLNI_field_get_ref(_this, m, rm); - LLNI_field_get_ref(_this, annotationDefault, annotationDefault); + java_lang_reflect_Method rm(rvmm.get_m()); + java_handle_bytearray_t* annotationDefault = rvmm.get_annotationDefault(); - h = vm_call_method(m_parseAnnotationDefault, NULL, rm, annotationDefault, constantPool); + java_handle_t* result = vm_call_method(m_parseAnnotationDefault, NULL, rm.get_handle(), annotationDefault, cp.get_handle()); - return (java_lang_Object*) h; + return (jobject) result; } @@ -315,32 +225,26 @@ JNIEXPORT struct java_lang_Object* JNICALL Java_java_lang_reflect_VMMethod_getDe * Class: java/lang/reflect/VMMethod * Method: declaredAnnotations * Signature: ()Ljava/util/Map; - * - * Parses the annotations (if they aren't parsed yet) and stores them into - * the declaredAnnotations map and return this map. */ -JNIEXPORT struct java_util_Map* JNICALL Java_java_lang_reflect_VMMethod_declaredAnnotations(JNIEnv *env, java_lang_reflect_VMMethod *_this) +JNIEXPORT jobject JNICALL Java_java_lang_reflect_VMMethod_declaredAnnotations(JNIEnv *env, jobject _this) { - java_util_Map *declaredAnnotations = NULL; /* parsed annotations */ - java_handle_bytearray_t *annotations = NULL; /* unparsed annotations */ - java_lang_Class *declaringClass = NULL; /* the constant pool of _this class is used */ - classinfo *referer = NULL; /* class, which calles the annotation parser */ - /* (for the parameter 'referer' of vm_call_method()) */ + java_lang_reflect_VMMethod rvmm(_this); + java_handle_t* declaredAnnotations = rvmm.get_declaredAnnotations(); - LLNI_field_get_ref(_this, declaredAnnotations, declaredAnnotations); - - /* are the annotations parsed yet? */ + // Are the annotations parsed yet? if (declaredAnnotations == NULL) { - LLNI_field_get_ref(_this, annotations, annotations); - LLNI_field_get_ref(_this, clazz, declaringClass); - LLNI_class_get(_this, referer); + java_handle_bytearray_t* annotations = rvmm.get_annotations(); + classinfo* declaringClass = rvmm.get_clazz(); + + classinfo *referer; + LLNI_class_get((java_lang_reflect_VMMethod *) _this, referer); - declaredAnnotations = reflect_get_declaredannotations(annotations, (classinfo*) declaringClass, referer); + declaredAnnotations = Reflection::get_declaredannotations(annotations, declaringClass, referer); - LLNI_field_set_ref(_this, declaredAnnotations, declaredAnnotations); + rvmm.set_declaredAnnotations(declaredAnnotations); } - return declaredAnnotations; + return (jobject) declaredAnnotations; } @@ -348,32 +252,60 @@ JNIEXPORT struct java_util_Map* JNICALL Java_java_lang_reflect_VMMethod_declared * Class: java/lang/reflect/VMMethod * Method: getParameterAnnotations * Signature: ()[[Ljava/lang/annotation/Annotation; - * - * Parses the parameter annotations and returns them in an 2 dimensional array. */ -JNIEXPORT java_handle_objectarray_t* JNICALL Java_java_lang_reflect_VMMethod_getParameterAnnotations(JNIEnv *env, java_lang_reflect_VMMethod *_this) +JNIEXPORT jobjectArray JNICALL Java_java_lang_reflect_VMMethod_getParameterAnnotations(JNIEnv *env, jobject _this) { - java_handle_bytearray_t *parameterAnnotations = NULL; /* unparsed parameter annotations */ - int32_t slot = -1; /* slot of the method */ - classinfo *c; - methodinfo* m; - classinfo *referer = NULL; /* class, which calles the annotation parser */ - /* (for the parameter 'referer' of vm_call_method()) */ + java_lang_reflect_VMMethod rvmm(_this); + java_handle_bytearray_t* parameterAnnotations = rvmm.get_parameterAnnotations(); + methodinfo* m = rvmm.get_method(); - LLNI_field_get_ref(_this, parameterAnnotations, parameterAnnotations); - LLNI_field_get_val(_this, slot, slot); - LLNI_field_get_cls(_this, clazz, c); - m = &(c->methods[slot]); + classinfo* referer; + LLNI_class_get((java_lang_reflect_VMMethod *) _this, referer); - LLNI_class_get(_this, referer); - - return reflect_get_parameterannotations((java_handle_t*)parameterAnnotations, m, referer); + java_handle_objectarray_t* oa = Reflection::get_parameterannotations(parameterAnnotations, m, referer); + return (jobjectArray) oa; } #endif } // extern "C" +/* native methods implemented by this file ************************************/ + +static JNINativeMethod methods[] = { + { (char*) "getModifiersInternal", (char*) "()I", (void*) (uintptr_t) &Java_java_lang_reflect_VMMethod_getModifiersInternal }, + { (char*) "getReturnType", (char*) "()Ljava/lang/Class;", (void*) (uintptr_t) &Java_java_lang_reflect_VMMethod_getReturnType }, + { (char*) "getParameterTypes", (char*) "()[Ljava/lang/Class;", (void*) (uintptr_t) &Java_java_lang_reflect_VMMethod_getParameterTypes }, + { (char*) "getExceptionTypes", (char*) "()[Ljava/lang/Class;", (void*) (uintptr_t) &Java_java_lang_reflect_VMMethod_getExceptionTypes }, + { (char*) "invoke", (char*) "(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;", (void*) (uintptr_t) &Java_java_lang_reflect_VMMethod_invoke }, + { (char*) "getSignature", (char*) "()Ljava/lang/String;", (void*) (uintptr_t) &Java_java_lang_reflect_VMMethod_getSignature }, +#if defined(ENABLE_ANNOTATIONS) + { (char*) "getDefaultValue", (char*) "()Ljava/lang/Object;", (void*) (uintptr_t) &Java_java_lang_reflect_VMMethod_getDefaultValue }, + { (char*) "declaredAnnotations", (char*) "()Ljava/util/Map;", (void*) (uintptr_t) &Java_java_lang_reflect_VMMethod_declaredAnnotations }, + { (char*) "getParameterAnnotations", (char*) "()[[Ljava/lang/annotation/Annotation;", (void*) (uintptr_t) &Java_java_lang_reflect_VMMethod_getParameterAnnotations }, +#endif +}; + + +/* _Jv_java_lang_reflect_VMMethod_init ***************************************** + + Register native functions. + +*******************************************************************************/ + +// FIXME +extern "C" { +void _Jv_java_lang_reflect_VMMethod_init(void) +{ + utf *u; + + u = utf_new_char("java/lang/reflect/VMMethod"); + + native_method_register(u, methods, NATIVE_METHODS_COUNT); +} +} + + /* * 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 diff --git a/src/native/vm/gnuclasspath/java_lang_reflect_VMProxy.c b/src/native/vm/gnuclasspath/java_lang_reflect_VMProxy.c index b2138421f..f40678c14 100644 --- a/src/native/vm/gnuclasspath/java_lang_reflect_VMProxy.c +++ b/src/native/vm/gnuclasspath/java_lang_reflect_VMProxy.c @@ -1,9 +1,7 @@ -/* src/native/vm/gnu/java_lang_reflect_VMProxy.c - java/lang/reflect/VMProxy +/* src/native/vm/gnuclasspath/java_lang_reflect_VMProxy.c - java/lang/reflect/VMProxy - Copyright (C) 1996-2005, 2006, 2007 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 + Copyright (C) 1996-2005, 2006, 2007, 2008 + CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO This file is part of CACAO. @@ -32,10 +30,8 @@ #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_reflect_VMProxy.h" +// FIXME +//#include "native/include/java_lang_reflect_VMProxy.h" /* native methods implemented by this file ************************************/ diff --git a/src/native/vm/gnuclasspath/java_security_VMAccessController.cpp b/src/native/vm/gnuclasspath/java_security_VMAccessController.cpp index 8a9e04381..75da75a8a 100644 --- a/src/native/vm/gnuclasspath/java_security_VMAccessController.cpp +++ b/src/native/vm/gnuclasspath/java_security_VMAccessController.cpp @@ -30,10 +30,9 @@ #include "native/jni.h" #include "native/native.h" -// FIXME -extern "C" { -#include "native/include/java_security_VMAccessController.h" -} +#if defined(ENABLE_JNI_HEADERS) +# include "native/vm/include/java_security_VMAccessController.h" +#endif #include "vm/global.h" @@ -50,9 +49,9 @@ extern "C" { * Method: getStack * Signature: ()[[Ljava/lang/Object; */ -JNIEXPORT java_handle_objectarray_t* JNICALL Java_java_security_VMAccessController_getStack(JNIEnv *env, jclass clazz) +JNIEXPORT jobjectArray JNICALL Java_java_security_VMAccessController_getStack(JNIEnv *env, jclass clazz) { - return stacktrace_get_stack(); + return (jobjectArray) stacktrace_get_stack(); } } // extern "C" diff --git a/src/native/vm/gnuclasspath/java_util_concurrent_atomic_AtomicLong.cpp b/src/native/vm/gnuclasspath/java_util_concurrent_atomic_AtomicLong.cpp index 69d2c871f..2f7795592 100644 --- a/src/native/vm/gnuclasspath/java_util_concurrent_atomic_AtomicLong.cpp +++ b/src/native/vm/gnuclasspath/java_util_concurrent_atomic_AtomicLong.cpp @@ -1,4 +1,4 @@ -/* src/native/vm/gnu/java_util_concurrent_atomic_AtomicLong.cpp +/* src/native/vm/gnuclasspath/java_util_concurrent_atomic_AtomicLong.cpp Copyright (C) 2007, 2008 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO @@ -30,10 +30,9 @@ #include "native/jni.h" #include "native/native.h" -// FIXME -extern "C" { -#include "native/include/java_util_concurrent_atomic_AtomicLong.h" -} +#if defined(ENABLE_JNI_HEADERS) +# include "native/include/java_util_concurrent_atomic_AtomicLong.h" +#endif #include "vmcore/utf8.h" @@ -46,10 +45,9 @@ extern "C" { * Method: VMSupportsCS8 * Signature: ()Z */ -JNIEXPORT int32_t JNICALL Java_java_util_concurrent_atomic_AtomicLong_VMSupportsCS8(JNIEnv *env, jclass clazz) +JNIEXPORT jboolean JNICALL Java_java_util_concurrent_atomic_AtomicLong_VMSupportsCS8(JNIEnv *env, jclass clazz) { - /* IMPLEMENT ME */ - + // IMPLEMENT ME return 0; } diff --git a/src/native/vm/gnuclasspath/sun_reflect_ConstantPool.cpp b/src/native/vm/gnuclasspath/sun_reflect_ConstantPool.cpp index 9bf6ee10f..8ec93342c 100644 --- a/src/native/vm/gnuclasspath/sun_reflect_ConstantPool.cpp +++ b/src/native/vm/gnuclasspath/sun_reflect_ConstantPool.cpp @@ -46,15 +46,10 @@ #include "native/llni.h" #include "native/native.h" -#include "native/include/java_lang_Object.h" -#include "native/include/java_lang_Class.h" - // FIXME -extern "C" { -#include "native/include/sun_reflect_ConstantPool.h" -} +//#include "native/include/sun_reflect_ConstantPool.h" -#include "native/vm/reflect.h" +#include "native/vm/reflection.hpp" #include "toolbox/logging.h" @@ -64,44 +59,10 @@ extern "C" { #include "vm/string.hpp" #include "vmcore/class.h" +#include "vmcore/javaobjects.hpp" #include "vmcore/utf8.h" -/* native methods implemented by this file ************************************/ - -static JNINativeMethod methods[] = { - { (char*) "getSize0", (char*) "(Ljava/lang/Object;I)I", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getSize0 }, - { (char*) "getClassAt0", (char*) "(Ljava/lang/Object;I)Ljava/lang/Class;", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getClassAt0 }, - { (char*) "getClassAtIfLoaded0", (char*) "(Ljava/lang/Object;I)Ljava/lang/Class;", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getClassAtIfLoaded0 }, - { (char*) "getMethodAt0", (char*) "(Ljava/lang/Object;I)Ljava/lang/reflect/Member;", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getMethodAt0 }, - { (char*) "getMethodAtIfLoaded0", (char*) "(Ljava/lang/Object;I)Ljava/lang/reflect/Member;", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getMethodAtIfLoaded0 }, - { (char*) "getFieldAt0", (char*) "(Ljava/lang/Object;I)Ljava/lang/reflect/Field;", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getFieldAt0 }, - { (char*) "getFieldAtIfLoaded0", (char*) "(Ljava/lang/Object;I)Ljava/lang/reflect/Field;", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getFieldAtIfLoaded0 }, - { (char*) "getMemberRefInfoAt0", (char*) "(Ljava/lang/Object;I)[Ljava/lang/String;", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getMemberRefInfoAt0 }, - { (char*) "getIntAt0", (char*) "(Ljava/lang/Object;I)I", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getIntAt0 }, - { (char*) "getLongAt0", (char*) "(Ljava/lang/Object;I)J", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getLongAt0 }, - { (char*) "getFloatAt0", (char*) "(Ljava/lang/Object;I)F", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getFloatAt0 }, - { (char*) "getDoubleAt0", (char*) "(Ljava/lang/Object;I)D", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getDoubleAt0 }, - { (char*) "getStringAt0", (char*) "(Ljava/lang/Object;I)Ljava/lang/String;", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getStringAt0 }, - { (char*) "getUTF8At0", (char*) "(Ljava/lang/Object;I)Ljava/lang/String;", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getUTF8At0 }, -}; - - -/* _Jv_sun_reflect_ConstantPool_init ****************************************** - - Register native functions. - -*******************************************************************************/ - -// FIXME -extern "C" { -void _Jv_sun_reflect_ConstantPool_init(void) -{ - native_method_register(utf_new_char("sun/reflect/ConstantPool"), methods, NATIVE_METHODS_COUNT); -} -} - - extern "C" { /* @@ -109,7 +70,7 @@ extern "C" { * Method: getSize0 * Signature: (Ljava/lang/Object;)I */ -JNIEXPORT int32_t JNICALL Java_sun_reflect_ConstantPool_getSize0(JNIEnv *env, struct sun_reflect_ConstantPool* _this, struct java_lang_Object* jcpool) +JNIEXPORT jint JNICALL Java_sun_reflect_ConstantPool_getSize0(JNIEnv *env, jobject _this, jobject jcpool) { classinfo *cls = LLNI_classinfo_unwrap(jcpool); return cls->cpcount; @@ -121,7 +82,7 @@ JNIEXPORT int32_t JNICALL Java_sun_reflect_ConstantPool_getSize0(JNIEnv *env, st * Method: getClassAt0 * Signature: (Ljava/lang/Object;I)Ljava/lang/Class; */ -JNIEXPORT struct java_lang_Class* JNICALL Java_sun_reflect_ConstantPool_getClassAt0(JNIEnv *env, struct sun_reflect_ConstantPool* _this, struct java_lang_Object* jcpool, int32_t index) +JNIEXPORT jclass JNICALL Java_sun_reflect_ConstantPool_getClassAt0(JNIEnv *env, jobject _this, jobject jcpool, jint index) { constant_classref *ref; classinfo *cls = LLNI_classinfo_unwrap(jcpool); @@ -134,7 +95,7 @@ JNIEXPORT struct java_lang_Class* JNICALL Java_sun_reflect_ConstantPool_getClass return NULL; } - return LLNI_classinfo_wrap(resolve_classref_eager(ref)); + return (jclass) LLNI_classinfo_wrap(resolve_classref_eager(ref)); } @@ -143,7 +104,7 @@ JNIEXPORT struct java_lang_Class* JNICALL Java_sun_reflect_ConstantPool_getClass * Method: getClassAtIfLoaded0 * Signature: (Ljava/lang/Object;I)Ljava/lang/Class; */ -JNIEXPORT struct java_lang_Class* JNICALL Java_sun_reflect_ConstantPool_getClassAtIfLoaded0(JNIEnv *env, struct sun_reflect_ConstantPool* _this, struct java_lang_Object* jcpool, int32_t index) +JNIEXPORT jclass JNICALL Java_sun_reflect_ConstantPool_getClassAtIfLoaded0(JNIEnv *env, jobject _this, jobject jcpool, jint index) { constant_classref *ref; classinfo *c = NULL; @@ -165,7 +126,7 @@ JNIEXPORT struct java_lang_Class* JNICALL Java_sun_reflect_ConstantPool_getClass return NULL; } - return LLNI_classinfo_wrap(c); + return (jclass) LLNI_classinfo_wrap(c); } @@ -174,7 +135,7 @@ JNIEXPORT struct java_lang_Class* JNICALL Java_sun_reflect_ConstantPool_getClass * Method: getMethodAt0 * Signature: (Ljava/lang/Object;I)Ljava/lang/reflect/Member; */ -JNIEXPORT struct java_lang_reflect_Member* JNICALL Java_sun_reflect_ConstantPool_getMethodAt0(JNIEnv *env, struct sun_reflect_ConstantPool* _this, struct java_lang_Object* jcpool, int32_t index) +JNIEXPORT jobject JNICALL Java_sun_reflect_ConstantPool_getMethodAt0(JNIEnv *env, jobject _this, jobject jcpool, jint index) { constant_FMIref *ref; classinfo *cls = LLNI_classinfo_unwrap(jcpool); @@ -188,7 +149,7 @@ JNIEXPORT struct java_lang_reflect_Member* JNICALL Java_sun_reflect_ConstantPool } /* XXX: is that right? or do I have to use resolve_method_*? */ - return (struct java_lang_reflect_Member*) reflect_method_new(ref->p.method); + return (jobject) java_lang_reflect_Method::create(ref->p.method); } @@ -197,7 +158,7 @@ JNIEXPORT struct java_lang_reflect_Member* JNICALL Java_sun_reflect_ConstantPool * Method: getMethodAtIfLoaded0 * Signature: (Ljava/lang/Object;I)Ljava/lang/reflect/Member; */ -JNIEXPORT struct java_lang_reflect_Member* JNICALL Java_sun_reflect_ConstantPool_getMethodAtIfLoaded0(JNIEnv *env, struct sun_reflect_ConstantPool* _this, struct java_lang_Object* jcpool, int32_t index) +JNIEXPORT jobject JNICALL Java_sun_reflect_ConstantPool_getMethodAtIfLoaded0(JNIEnv *env, jobject _this, jobject jcpool, jint index) { constant_FMIref *ref; classinfo *c = NULL; @@ -219,7 +180,7 @@ JNIEXPORT struct java_lang_reflect_Member* JNICALL Java_sun_reflect_ConstantPool return NULL; } - return (struct java_lang_reflect_Member*) reflect_method_new(ref->p.method); + return (jobject) java_lang_reflect_Method::create(ref->p.method); } @@ -228,7 +189,7 @@ JNIEXPORT struct java_lang_reflect_Member* JNICALL Java_sun_reflect_ConstantPool * Method: getFieldAt0 * Signature: (Ljava/lang/Object;I)Ljava/lang/reflect/Field; */ -JNIEXPORT struct java_lang_reflect_Field* JNICALL Java_sun_reflect_ConstantPool_getFieldAt0(JNIEnv *env, struct sun_reflect_ConstantPool* _this, struct java_lang_Object* jcpool, int32_t index) +JNIEXPORT jobject JNICALL Java_sun_reflect_ConstantPool_getFieldAt0(JNIEnv *env, jobject _this, jobject jcpool, jint index) { constant_FMIref *ref; classinfo *cls = LLNI_classinfo_unwrap(jcpool); @@ -241,7 +202,7 @@ JNIEXPORT struct java_lang_reflect_Field* JNICALL Java_sun_reflect_ConstantPool_ return NULL; } - return (struct java_lang_reflect_Field*) reflect_field_new(ref->p.field); + return (jobject) java_lang_reflect_Field::create(ref->p.field); } @@ -250,7 +211,7 @@ JNIEXPORT struct java_lang_reflect_Field* JNICALL Java_sun_reflect_ConstantPool_ * Method: getFieldAtIfLoaded0 * Signature: (Ljava/lang/Object;I)Ljava/lang/reflect/Field; */ -JNIEXPORT struct java_lang_reflect_Field* JNICALL Java_sun_reflect_ConstantPool_getFieldAtIfLoaded0(JNIEnv *env, struct sun_reflect_ConstantPool* _this, struct java_lang_Object* jcpool, int32_t index) +JNIEXPORT jobject JNICALL Java_sun_reflect_ConstantPool_getFieldAtIfLoaded0(JNIEnv *env, jobject _this, jobject jcpool, jint index) { constant_FMIref *ref; classinfo *c; @@ -272,7 +233,7 @@ JNIEXPORT struct java_lang_reflect_Field* JNICALL Java_sun_reflect_ConstantPool_ return NULL; } - return (struct java_lang_reflect_Field*) reflect_field_new(ref->p.field); + return (jobject) java_lang_reflect_Field::create(ref->p.field); } @@ -281,7 +242,7 @@ JNIEXPORT struct java_lang_reflect_Field* JNICALL Java_sun_reflect_ConstantPool_ * Method: getMemberRefInfoAt0 * Signature: (Ljava/lang/Object;I)[Ljava/lang/String; */ -JNIEXPORT java_handle_objectarray_t* JNICALL Java_sun_reflect_ConstantPool_getMemberRefInfoAt0(JNIEnv *env, struct sun_reflect_ConstantPool* _this, struct java_lang_Object* jcpool, int32_t index) +JNIEXPORT jobjectArray JNICALL Java_sun_reflect_ConstantPool_getMemberRefInfoAt0(JNIEnv *env, jobject _this, jobject jcpool, jint index) { log_println("Java_sun_reflect_ConstantPool_getMemberRefInfoAt0(env=%p, jcpool=%p, index=%d): IMPLEMENT ME!", env, jcpool, index); return NULL; @@ -293,7 +254,7 @@ JNIEXPORT java_handle_objectarray_t* JNICALL Java_sun_reflect_ConstantPool_getMe * Method: getIntAt0 * Signature: (Ljava/lang/Object;I)I */ -JNIEXPORT int32_t JNICALL Java_sun_reflect_ConstantPool_getIntAt0(JNIEnv *env, struct sun_reflect_ConstantPool* _this, struct java_lang_Object* jcpool, int32_t index) +JNIEXPORT jint JNICALL Java_sun_reflect_ConstantPool_getIntAt0(JNIEnv *env, jobject _this, jobject jcpool, jint index) { constant_integer *ref; classinfo *cls = LLNI_classinfo_unwrap(jcpool); @@ -315,7 +276,7 @@ JNIEXPORT int32_t JNICALL Java_sun_reflect_ConstantPool_getIntAt0(JNIEnv *env, s * Method: getLongAt0 * Signature: (Ljava/lang/Object;I)J */ -JNIEXPORT int64_t JNICALL Java_sun_reflect_ConstantPool_getLongAt0(JNIEnv *env, struct sun_reflect_ConstantPool* _this, struct java_lang_Object* jcpool, int32_t index) +JNIEXPORT jlong JNICALL Java_sun_reflect_ConstantPool_getLongAt0(JNIEnv *env, jobject _this, jobject jcpool, jint index) { constant_long *ref; classinfo *cls = LLNI_classinfo_unwrap(jcpool); @@ -337,7 +298,7 @@ JNIEXPORT int64_t JNICALL Java_sun_reflect_ConstantPool_getLongAt0(JNIEnv *env, * Method: getFloatAt0 * Signature: (Ljava/lang/Object;I)F */ -JNIEXPORT float JNICALL Java_sun_reflect_ConstantPool_getFloatAt0(JNIEnv *env, struct sun_reflect_ConstantPool* _this, struct java_lang_Object* jcpool, int32_t index) +JNIEXPORT float JNICALL Java_sun_reflect_ConstantPool_getFloatAt0(JNIEnv *env, jobject _this, jobject jcpool, jint index) { constant_float *ref; classinfo *cls = LLNI_classinfo_unwrap(jcpool); @@ -359,7 +320,7 @@ JNIEXPORT float JNICALL Java_sun_reflect_ConstantPool_getFloatAt0(JNIEnv *env, s * Method: getDoubleAt0 * Signature: (Ljava/lang/Object;I)D */ -JNIEXPORT double JNICALL Java_sun_reflect_ConstantPool_getDoubleAt0(JNIEnv *env, struct sun_reflect_ConstantPool* _this, struct java_lang_Object* jcpool, int32_t index) +JNIEXPORT double JNICALL Java_sun_reflect_ConstantPool_getDoubleAt0(JNIEnv *env, jobject _this, jobject jcpool, jint index) { constant_double *ref; classinfo *cls = LLNI_classinfo_unwrap(jcpool); @@ -381,7 +342,7 @@ JNIEXPORT double JNICALL Java_sun_reflect_ConstantPool_getDoubleAt0(JNIEnv *env, * Method: getStringAt0 * Signature: (Ljava/lang/Object;I)Ljava/lang/String; */ -JNIEXPORT struct java_lang_String* JNICALL Java_sun_reflect_ConstantPool_getStringAt0(JNIEnv *env, struct sun_reflect_ConstantPool* _this, struct java_lang_Object* jcpool, int32_t index) +JNIEXPORT jstring JNICALL Java_sun_reflect_ConstantPool_getStringAt0(JNIEnv *env, jobject _this, jobject jcpool, jint index) { utf *ref; classinfo *cls = LLNI_classinfo_unwrap(jcpool); @@ -394,7 +355,7 @@ JNIEXPORT struct java_lang_String* JNICALL Java_sun_reflect_ConstantPool_getStri } /* XXX: I hope literalstring_new is the right Function. */ - return (java_lang_String*)literalstring_new(ref); + return (jstring) literalstring_new(ref); } @@ -403,7 +364,7 @@ JNIEXPORT struct java_lang_String* JNICALL Java_sun_reflect_ConstantPool_getStri * Method: getUTF8At0 * Signature: (Ljava/lang/Object;I)Ljava/lang/String; */ -JNIEXPORT struct java_lang_String* JNICALL Java_sun_reflect_ConstantPool_getUTF8At0(JNIEnv *env, struct sun_reflect_ConstantPool* _this, struct java_lang_Object* jcpool, int32_t index) +JNIEXPORT jstring JNICALL Java_sun_reflect_ConstantPool_getUTF8At0(JNIEnv *env, jobject _this, jobject jcpool, jint index) { utf *ref; classinfo *cls = LLNI_classinfo_unwrap(jcpool); @@ -416,12 +377,47 @@ JNIEXPORT struct java_lang_String* JNICALL Java_sun_reflect_ConstantPool_getUTF8 } /* XXX: I hope literalstring_new is the right Function. */ - return (java_lang_String*)literalstring_new(ref); + return (jstring) literalstring_new(ref); } } // extern "C" +/* native methods implemented by this file ************************************/ + +static JNINativeMethod methods[] = { + { (char*) "getSize0", (char*) "(Ljava/lang/Object;I)I", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getSize0 }, + { (char*) "getClassAt0", (char*) "(Ljava/lang/Object;I)Ljava/lang/Class;", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getClassAt0 }, + { (char*) "getClassAtIfLoaded0", (char*) "(Ljava/lang/Object;I)Ljava/lang/Class;", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getClassAtIfLoaded0 }, + { (char*) "getMethodAt0", (char*) "(Ljava/lang/Object;I)Ljava/lang/reflect/Member;", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getMethodAt0 }, + { (char*) "getMethodAtIfLoaded0", (char*) "(Ljava/lang/Object;I)Ljava/lang/reflect/Member;", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getMethodAtIfLoaded0 }, + { (char*) "getFieldAt0", (char*) "(Ljava/lang/Object;I)Ljava/lang/reflect/Field;", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getFieldAt0 }, + { (char*) "getFieldAtIfLoaded0", (char*) "(Ljava/lang/Object;I)Ljava/lang/reflect/Field;", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getFieldAtIfLoaded0 }, + { (char*) "getMemberRefInfoAt0", (char*) "(Ljava/lang/Object;I)[Ljava/lang/String;", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getMemberRefInfoAt0 }, + { (char*) "getIntAt0", (char*) "(Ljava/lang/Object;I)I", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getIntAt0 }, + { (char*) "getLongAt0", (char*) "(Ljava/lang/Object;I)J", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getLongAt0 }, + { (char*) "getFloatAt0", (char*) "(Ljava/lang/Object;I)F", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getFloatAt0 }, + { (char*) "getDoubleAt0", (char*) "(Ljava/lang/Object;I)D", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getDoubleAt0 }, + { (char*) "getStringAt0", (char*) "(Ljava/lang/Object;I)Ljava/lang/String;", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getStringAt0 }, + { (char*) "getUTF8At0", (char*) "(Ljava/lang/Object;I)Ljava/lang/String;", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getUTF8At0 }, +}; + + +/* _Jv_sun_reflect_ConstantPool_init ****************************************** + + Register native functions. + +*******************************************************************************/ + +// FIXME +extern "C" { +void _Jv_sun_reflect_ConstantPool_init(void) +{ + native_method_register(utf_new_char("sun/reflect/ConstantPool"), methods, NATIVE_METHODS_COUNT); +} +} + + /* * 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 diff --git a/src/native/vm/reflect.c b/src/native/vm/reflect.c deleted file mode 100644 index c1108bb2c..000000000 --- a/src/native/vm/reflect.c +++ /dev/null @@ -1,692 +0,0 @@ -/* src/native/vm/reflect.c - helper functions for java/lang/reflect - - Copyright (C) 2007, 2008 - CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO - - 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. - -*/ - - -#include "config.h" - -#include - -#include "native/jni.h" -#include "native/llni.h" -#include "native/native.h" - -/* keep this order of the native includes */ - -#include "native/include/java_lang_String.h" - -#if defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK) -# include "native/include/java_nio_ByteBuffer.h" /* required by j.l.CL */ -#endif -#include "native/include/java_lang_ClassLoader.h" - -#include "native/include/java_lang_Object.h" -#include "native/include/java_lang_Class.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" - -#if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH) -# include "native/include/java_lang_reflect_VMConstructor.h" -# include "native/include/java_lang_reflect_VMField.h" -# include "native/include/java_lang_reflect_VMMethod.h" -#endif - -#if defined(ENABLE_ANNOTATIONS) && defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH) -# include "vm/vm.hpp" -# include "native/include/sun_reflect_ConstantPool.h" -#endif - -#include "native/vm/reflect.h" - -#include "vm/access.h" -#include "vm/builtin.h" -#include "vm/exceptions.hpp" -#include "vm/global.h" -#include "vm/initialize.h" -#include "vm/string.hpp" - -#include "vmcore/globals.hpp" -#include "vmcore/method.h" - - -/* reflect_constructor_new ***************************************************** - - Allocates a new java.lang.reflect.Constructor object and - initializes the fields with the method passed. - -*******************************************************************************/ - -java_lang_reflect_Constructor *reflect_constructor_new(methodinfo *m) -{ - java_handle_t *o; - java_lang_reflect_Constructor *rc; - int32_t slot; - -#if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH) - java_lang_reflect_VMConstructor *rvmc; -#endif - - /* Allocate a java.lang.reflect.Constructor object. */ - - o = builtin_new(class_java_lang_reflect_Constructor); - - if (o == NULL) - return NULL; - - /* Initialize instance fields. */ - - rc = (java_lang_reflect_Constructor *) o; - - /* Calculate the slot. */ - - slot = m - m->clazz->methods; - -#if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH) - - /* Allocate a java.lang.reflect.VMConstructor object. */ - - o = builtin_new(class_java_lang_reflect_VMConstructor); - - if (o == NULL) - return NULL; - - rvmc = (java_lang_reflect_VMConstructor *) o; - - /* Link the two Java objects. */ - - LLNI_field_set_ref(rc, cons, rvmc); - LLNI_field_set_ref(rvmc, cons, rc); - - /* Set Java object instance fields. */ - - LLNI_field_set_cls(rvmc, clazz, m->clazz); - LLNI_field_set_val(rvmc, slot, slot); - LLNI_field_set_ref(rvmc, annotations, method_get_annotations(m)); - LLNI_field_set_ref(rvmc, parameterAnnotations, method_get_parameterannotations(m)); - -#elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK) - - /* Set Java object instance fields. */ - - LLNI_field_set_cls(rc, clazz , m->clazz); - LLNI_field_set_ref(rc, parameterTypes , method_get_parametertypearray(m)); - LLNI_field_set_ref(rc, exceptionTypes , method_get_exceptionarray(m)); - LLNI_field_set_val(rc, modifiers , m->flags & ACC_CLASS_REFLECT_MASK); - LLNI_field_set_val(rc, slot , slot); - LLNI_field_set_ref(rc, signature , m->signature ? (java_lang_String *) javastring_new(m->signature) : NULL); - LLNI_field_set_ref(rc, annotations , method_get_annotations(m)); - LLNI_field_set_ref(rc, parameterAnnotations, method_get_parameterannotations(m)); - -#else -# error unknown classpath configuration -#endif - - return rc; -} - - -/* reflect_field_new *********************************************************** - - Allocates a new java.lang.reflect.Field object and initializes the - fields with the field passed. - -*******************************************************************************/ - -java_lang_reflect_Field *reflect_field_new(fieldinfo *f) -{ - java_handle_t *o; - java_lang_reflect_Field *rf; - int32_t slot; - -#if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH) - java_lang_reflect_VMField *rvmf; -#endif - - /* Allocate a java.lang.reflect.Field object. */ - - o = builtin_new(class_java_lang_reflect_Field); - - if (o == NULL) - return NULL; - - /* initialize instance fields */ - - rf = (java_lang_reflect_Field *) o; - - /* Calculate the slot. */ - - slot = f - f->clazz->fields; - -#if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH) - - /* Allocate a java.lang.reflect.VMField object. */ - - o = builtin_new(class_java_lang_reflect_VMField); - - if (o == NULL) - return NULL; - - rvmf = (java_lang_reflect_VMField *) o; - - /* Link the two Java objects. */ - - LLNI_field_set_ref(rf, f, rvmf); - LLNI_field_set_ref(rvmf, f, rf); - - /* Set the Java object fields. */ - - LLNI_field_set_cls(rvmf, clazz, f->clazz); - - /* The name needs to be interned */ - /* XXX implement me better! */ - - LLNI_field_set_ref(rvmf, name, (java_lang_String *) javastring_intern(javastring_new(f->name))); - LLNI_field_set_val(rvmf, slot, slot); - LLNI_field_set_ref(rvmf, annotations, field_get_annotations(f)); - -#elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK) - - /* Set the Java object fields. */ - - LLNI_field_set_cls(rf, clazz, f->clazz); - - /* The name needs to be interned */ - /* XXX implement me better! */ - - LLNI_field_set_ref(rf, name, (java_lang_String *) javastring_intern(javastring_new(f->name))); - LLNI_field_set_cls(rf, type, (java_lang_Class *) field_get_type(f)); - LLNI_field_set_val(rf, modifiers, f->flags); - LLNI_field_set_val(rf, slot, slot); - LLNI_field_set_ref(rf, signature, f->signature ? (java_lang_String *) javastring_new(f->signature) : NULL); - LLNI_field_set_ref(rf, annotations, field_get_annotations(f)); - -#else -# error unknown classpath configuration -#endif - - return rf; -} - - -/* reflect_method_new ********************************************************** - - Allocates a new java.lang.reflect.Method object and initializes the - fields with the method passed. - -*******************************************************************************/ - -java_lang_reflect_Method *reflect_method_new(methodinfo *m) -{ - java_handle_t *o; - java_lang_reflect_Method *rm; - int32_t slot; - -#if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH) - java_lang_reflect_VMMethod *rvmm; -#endif - - /* Allocate a java.lang.reflect.Method object. */ - - o = builtin_new(class_java_lang_reflect_Method); - - if (o == NULL) - return NULL; - - /* initialize instance fields */ - - rm = (java_lang_reflect_Method *) o; - - /* Calculate the slot. */ - - slot = m - m->clazz->methods; - -#if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH) - - /* Allocate a java.lang.reflect.VMMethod object. */ - - o = builtin_new(class_java_lang_reflect_VMMethod); - - if (o == NULL) - return NULL; - - rvmm = (java_lang_reflect_VMMethod *) o; - - /* Link the two Java objects. */ - - LLNI_field_set_ref(rm, m, rvmm); - LLNI_field_set_ref(rvmm, m, rm); - - /* Set Java object instance fields. */ - - LLNI_field_set_cls(rvmm, clazz, m->clazz); - - /* The name needs to be interned */ - /* XXX implement me better! */ - - LLNI_field_set_ref(rvmm, name, (java_lang_String *) javastring_intern(javastring_new(m->name))); - LLNI_field_set_val(rvmm, slot, slot); - LLNI_field_set_ref(rvmm, annotations, method_get_annotations(m)); - LLNI_field_set_ref(rvmm, parameterAnnotations, method_get_parameterannotations(m)); - LLNI_field_set_ref(rvmm, annotationDefault, method_get_annotationdefault(m)); - -#elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK) - - LLNI_field_set_cls(rm, clazz, m->clazz); - - /* The name needs to be interned */ - /* XXX implement me better! */ - - LLNI_field_set_ref(rm, name, (java_lang_String *) javastring_intern(javastring_new(m->name))); - LLNI_field_set_ref(rm, parameterTypes, method_get_parametertypearray(m)); - LLNI_field_set_cls(rm, returnType, (java_lang_Class *) method_returntype_get(m)); - LLNI_field_set_ref(rm, exceptionTypes, method_get_exceptionarray(m)); - LLNI_field_set_val(rm, modifiers, m->flags & ACC_CLASS_REFLECT_MASK); - LLNI_field_set_val(rm, slot, slot); - LLNI_field_set_ref(rm, signature, m->signature ? (java_lang_String *) javastring_new(m->signature) : NULL); - LLNI_field_set_ref(rm, annotations, method_get_annotations(m)); - LLNI_field_set_ref(rm, parameterAnnotations, method_get_parameterannotations(m)); - LLNI_field_set_ref(rm, annotationDefault, method_get_annotationdefault(m)); - -#else -# error unknown classpath configuration -#endif - - return rm; -} - - -/* reflect_invoke ************************************************************** - - Invoke a method on the given object with the given arguments. - - For instance methods OBJ must be != NULL and the method is looked up - in the vftbl of the object. - - For static methods, OBJ is ignored. - -*******************************************************************************/ - -static java_handle_t *reflect_invoke(methodinfo *m, java_handle_t *o, java_handle_objectarray_t *params) -{ - methodinfo *resm; - java_handle_t *ro; - int argcount; - int paramcount; - - /* Sanity check. */ - - assert(m != NULL); - - argcount = m->parseddesc->paramcount; - paramcount = argcount; - - /* If method is non-static, remove the `this' pointer. */ - - if (!(m->flags & ACC_STATIC)) - paramcount--; - - /* For instance methods the object has to be an instance of the - class the method belongs to. For static methods the obj - parameter is ignored. */ - - if (!(m->flags & ACC_STATIC) && o && (!builtin_instanceof(o, m->clazz))) { - exceptions_throw_illegalargumentexception(); - return NULL; - } - - /* check if we got the right number of arguments */ - - if (((params == NULL) && (paramcount != 0)) || - (params && (LLNI_array_size(params) != paramcount))) - { - exceptions_throw_illegalargumentexception(); - return NULL; - } - - /* for instance methods we need an object */ - - if (!(m->flags & ACC_STATIC) && (o == NULL)) { - /* XXX not sure if that is the correct exception */ - exceptions_throw_nullpointerexception(); - return NULL; - } - - /* for static methods, zero object to make subsequent code simpler */ - if (m->flags & ACC_STATIC) - o = NULL; - - if (o != NULL) { - /* for instance methods we must do a vftbl lookup */ - resm = method_vftbl_lookup(LLNI_vftbl_direct(o), m); - } - else { - /* for static methods, just for convenience */ - resm = m; - } - - ro = vm_call_method_objectarray(resm, o, params); - - return ro; -} - - -/* reflect_constructor_newinstance ******************************************** - - Creates an Java object instance of the given constructor. - - ARGUMENTS: - m .......... methodinfo of the constructor - args ....... constructor arguments - override ... override security checks - - RETURN: - constructed Java object - -*******************************************************************************/ - -java_handle_t *reflect_constructor_newinstance(methodinfo *m, java_handle_objectarray_t *args, bool override) -{ - java_handle_t *o; - - /* Should we bypass security the checks (AccessibleObject)? */ - - if (override == false) { - /* This method is always called like this: - [0] java.lang.reflect.Constructor.constructNative (Native Method) - [1] java.lang.reflect.Constructor.newInstance - [2] - */ - - if (!access_check_method(m, 2)) - return NULL; - } - - /* Create a Java object. */ - - o = builtin_new(m->clazz); - - if (o == NULL) - return NULL; - - /* Call initializer. */ - - (void) reflect_invoke(m, o, args); - - return o; -} - - -/* reflect_method_invoke ******************************************************* - - Invokes the given method. - - ARGUMENTS: - m .......... methodinfo - args ....... method arguments - override ... override security checks - - RETURN: - return value of the method - -*******************************************************************************/ - -java_handle_t *reflect_method_invoke(methodinfo *m, java_handle_t *o, java_handle_objectarray_t *args, bool override) -{ - java_handle_t *ro; - - /* Should we bypass security the checks (AccessibleObject)? */ - - if (override == false) { -#if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH) - /* This method is always called like this: - [0] java.lang.reflect.Method.invokeNative (Native Method) - [1] java.lang.reflect.Method.invoke (Method.java:329) - [2] - */ - - if (!access_check_method(m, 2)) - return NULL; -#elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK) - /* We only pass 1 here as stacktrace_get_caller_class, which - is called from access_check_method, skips - java.lang.reflect.Method.invoke(). */ - - if (!access_check_method(m, 1)) - return NULL; -#else -# error unknown classpath configuration -#endif - } - - /* Check if method class is initialized. */ - - if (!(m->clazz->state & CLASS_INITIALIZED)) - if (!initialize_class(m->clazz)) - return NULL; - - /* Call the Java method. */ - - ro = reflect_invoke(m, o, args); - - return ro; -} - - -#if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH) && defined(ENABLE_ANNOTATIONS) -/* reflect_get_declaredannotations ********************************************* - - Calls the annotation parser with the unparsed annotations and returnes - the parsed annotations as a map. - - IN: - annotations........the unparsed annotations - declaringClass.....the class in which the annotated element is declared - referer............the calling class (for the 'referer' parameter of - vm_call_method()) - - RETURN VALUE: - The parsed annotations as a - java.util.Map, Annotation>. - -*******************************************************************************/ - -struct java_util_Map* reflect_get_declaredannotations( - java_handle_bytearray_t *annotations, - classinfo *declaringClass, - classinfo *referer) -{ - static methodinfo *m_parseAnnotations = NULL; - /* parser method (chached, therefore static) */ - utf *utf_parseAnnotations = NULL; - /* parser method name */ - utf *utf_desc = NULL; - /* parser method descriptor (signature) */ - sun_reflect_ConstantPool *constantPool = NULL; - /* constant pool of the declaring class */ - java_lang_Object *constantPoolOop = (java_lang_Object*)declaringClass; - /* constantPoolOop field of the constant pool */ - /* object (sun.reflect.ConstantPool) */ - - constantPool = - (sun_reflect_ConstantPool*)native_new_and_init( - class_sun_reflect_ConstantPool); - - if(constantPool == NULL) { - /* out of memory */ - return NULL; - } - - LLNI_field_set_ref(constantPool, constantPoolOop, constantPoolOop); - - /* only resolve the parser method the first time */ - if (m_parseAnnotations == NULL) { - utf_parseAnnotations = utf_new_char("parseAnnotations"); - utf_desc = utf_new_char( - "([BLsun/reflect/ConstantPool;Ljava/lang/Class;)" - "Ljava/util/Map;"); - - if (utf_parseAnnotations == NULL || utf_desc == NULL) { - /* out of memory */ - return NULL; - } - - m_parseAnnotations = class_resolveclassmethod( - class_sun_reflect_annotation_AnnotationParser, - utf_parseAnnotations, - utf_desc, - referer, - true); - - if (m_parseAnnotations == NULL) { - /* method not found */ - return NULL; - } - } - - return (struct java_util_Map*)vm_call_method( - m_parseAnnotations, NULL, annotations, - constantPool, declaringClass); -} - - -/* reflect_get_parameterannotations ******************************************* - - Calls the annotation parser with the unparsed parameter annotations of - a method and returnes the parsed parameter annotations in a 2 dimensional - array. - - IN: - parameterAnnotations....the unparsed parameter annotations - slot....................the slot of the method - declaringClass..........the class in which the annotated element is - declared - referer.................the calling class (for the 'referer' parameter - of vm_call_method()) - - RETURN VALUE: - The parsed parameter annotations in a 2 dimensional array. - -*******************************************************************************/ - -java_handle_objectarray_t* reflect_get_parameterannotations( - java_handle_t *parameterAnnotations, - methodinfo *m, - classinfo *referer) -{ - /* This method in java would be basically the following. - * We don't do it in java because we don't want to make a - * public method with wich you can get a ConstantPool, because - * with that you could read any kind of constants (even private - * ones). - * - * ConstantPool constPool = new ConstantPool(); - * constPool.constantPoolOop = method.getDeclaringClass(); - * return sun.reflect.AnnotationParser.parseParameterAnnotations( - * parameterAnnotations, - * constPool, - * method.getDeclaringClass(), - * method.getParameterTypes().length); - */ - static methodinfo *m_parseParameterAnnotations = NULL; - /* parser method (cached, therefore static) */ - utf *utf_parseParameterAnnotations = NULL; - /* parser method name */ - utf *utf_desc = NULL; - /* parser method descriptor (signature) */ - sun_reflect_ConstantPool *constantPool = NULL; - /* constant pool of the declaring class */ - int32_t numParameters = -1; - /* parameter count of the annotated method */ - - /* get parameter count */ - - numParameters = method_get_parametercount(m); - - if (numParameters < 0) { - /* error parsing descriptor */ - return NULL; - } - - /* get ConstantPool */ - - constantPool = - (sun_reflect_ConstantPool*)native_new_and_init( - class_sun_reflect_ConstantPool); - - if(constantPool == NULL) { - /* out of memory */ - return NULL; - } - - // XXX I'm not sure what the correct LLNI macro would be. - LLNI_field_set_cls(constantPool, constantPoolOop, (java_lang_Object*) m->clazz); - - /* only resolve the parser method the first time */ - if (m_parseParameterAnnotations == NULL) { - utf_parseParameterAnnotations = utf_new_char("parseParameterAnnotations"); - utf_desc = utf_new_char( - "([BLsun/reflect/ConstantPool;Ljava/lang/Class;I)" - "[[Ljava/lang/annotation/Annotation;"); - - if (utf_parseParameterAnnotations == NULL || utf_desc == NULL) { - /* out of memory */ - return NULL; - } - - /* get parser method */ - - m_parseParameterAnnotations = class_resolveclassmethod( - class_sun_reflect_annotation_AnnotationParser, - utf_parseParameterAnnotations, - utf_desc, - referer, - true); - - if (m_parseParameterAnnotations == NULL) - { - /* method not found */ - return NULL; - } - } - - return (java_handle_objectarray_t*)vm_call_method( - m_parseParameterAnnotations, NULL, parameterAnnotations, - constantPool, m->clazz, numParameters); -} -#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: - * vim:noexpandtab:sw=4:ts=4: - */ diff --git a/src/native/vm/reflect.h b/src/native/vm/reflect.h deleted file mode 100644 index 5fd61ba36..000000000 --- a/src/native/vm/reflect.h +++ /dev/null @@ -1,103 +0,0 @@ -/* src/native/vm/reflect.h - helper functions for java/lang/reflect - - Copyright (C) 2007, 2008 - CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO - - 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. - -*/ - - -#ifndef _REFLECT_H -#define _REFLECT_H - -#include "config.h" - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -#include "native/jni.h" -#include "native/native.h" - -/* Keep this order of the native includes. */ - -#include "native/include/java_lang_String.h" - -#if defined(ENABLE_JAVASE) -# if defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK) -# include "native/include/java_nio_ByteBuffer.h" /* required by j.l.CL */ -# endif -# include "native/include/java_lang_ClassLoader.h" -#endif - -#include "native/include/java_lang_Object.h" -#include "native/include/java_lang_Class.h" - -#if defined(ENABLE_JAVASE) -# include "native/include/java_lang_reflect_Constructor.h" -# include "native/include/java_lang_reflect_Field.h" -# include "native/include/java_lang_reflect_Method.h" -#endif - -#include "vmcore/field.h" -#include "vmcore/method.h" - - -/* function prototypes ********************************************************/ - -java_lang_reflect_Constructor *reflect_constructor_new(methodinfo *m); -java_lang_reflect_Field *reflect_field_new(fieldinfo *f); -java_lang_reflect_Method *reflect_method_new(methodinfo *m); -java_handle_t *reflect_constructor_newinstance(methodinfo *m, java_handle_objectarray_t *args, bool override); -java_handle_t *reflect_method_invoke(methodinfo *m, java_handle_t *o, java_handle_objectarray_t *args, bool override); - -#if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH) && defined(ENABLE_ANNOTATIONS) -struct java_util_Map* reflect_get_declaredannotations( - java_handle_bytearray_t *annotations, - classinfo *declaringClass, - classinfo *referer); - -java_handle_objectarray_t* reflect_get_parameterannotations( - java_handle_t *parameterAnnotations, - methodinfo *m, - classinfo *referer); -#endif - -#ifdef __cplusplus -} -#endif - -#endif /* _REFLECT_H */ - - -/* - * 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: - */ diff --git a/src/native/vm/reflection.cpp b/src/native/vm/reflection.cpp new file mode 100644 index 000000000..5156dc2e9 --- /dev/null +++ b/src/native/vm/reflection.cpp @@ -0,0 +1,327 @@ +/* src/native/vm/reflection.cpp - helper functions for java/lang/reflect + + Copyright (C) 2007, 2008 + CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO + + 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. + +*/ + + +#include "config.h" + +#include + +#include "native/jni.h" +#include "native/llni.h" +#include "native/native.h" + +#if defined(ENABLE_ANNOTATIONS) && defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH) +# include "vm/vm.hpp" +#endif + +#include "native/vm/reflection.hpp" + +#include "vm/access.h" +#include "vm/builtin.h" +#include "vm/exceptions.hpp" +#include "vm/global.h" +#include "vm/initialize.h" +#include "vm/string.hpp" + +#include "vmcore/globals.hpp" +#include "vmcore/javaobjects.hpp" +#include "vmcore/method.h" + + +/** + * Invoke a method on the given object with the given arguments. + * + * For instance methods OBJ must be != NULL and the method is looked up + * in the vftbl of the object. + * + * For static methods, OBJ is ignored. + */ +java_handle_t* Reflection::invoke(methodinfo *m, java_handle_t *o, java_handle_objectarray_t *params) +{ + methodinfo *resm; + java_handle_t *ro; + int argcount; + int paramcount; + + /* Sanity check. */ + + assert(m != NULL); + + argcount = m->parseddesc->paramcount; + paramcount = argcount; + + /* If method is non-static, remove the `this' pointer. */ + + if (!(m->flags & ACC_STATIC)) + paramcount--; + + /* For instance methods the object has to be an instance of the + class the method belongs to. For static methods the obj + parameter is ignored. */ + + if (!(m->flags & ACC_STATIC) && o && (!builtin_instanceof(o, m->clazz))) { + exceptions_throw_illegalargumentexception(); + return NULL; + } + + /* check if we got the right number of arguments */ + + if (((params == NULL) && (paramcount != 0)) || + (params && (LLNI_array_size(params) != paramcount))) + { + exceptions_throw_illegalargumentexception(); + return NULL; + } + + /* for instance methods we need an object */ + + if (!(m->flags & ACC_STATIC) && (o == NULL)) { + /* XXX not sure if that is the correct exception */ + exceptions_throw_nullpointerexception(); + return NULL; + } + + /* for static methods, zero object to make subsequent code simpler */ + if (m->flags & ACC_STATIC) + o = NULL; + + if (o != NULL) { + /* for instance methods we must do a vftbl lookup */ + resm = method_vftbl_lookup(LLNI_vftbl_direct(o), m); + } + else { + /* for static methods, just for convenience */ + resm = m; + } + + ro = vm_call_method_objectarray(resm, o, params); + + return ro; +} + + +/* reflect_method_invoke ******************************************************* + + Invokes the given method. + + ARGUMENTS: + m .......... methodinfo + args ....... method arguments + override ... override security checks + + RETURN: + return value of the method + +*******************************************************************************/ + +java_handle_t* Reflection::method_invoke(methodinfo *m, java_handle_t *o, java_handle_objectarray_t *args, bool override) +{ + java_handle_t *ro; + + /* Should we bypass security the checks (AccessibleObject)? */ + + if (override == false) { +#if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH) + /* This method is always called like this: + [0] java.lang.reflect.Method.invokeNative (Native Method) + [1] java.lang.reflect.Method.invoke (Method.java:329) + [2] + */ + + if (!access_check_method(m, 2)) + return NULL; +#elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK) + /* We only pass 1 here as stacktrace_get_caller_class, which + is called from access_check_method, skips + java.lang.reflect.Method.invoke(). */ + + if (!access_check_method(m, 1)) + return NULL; +#else +# error unknown classpath configuration +#endif + } + + /* Check if method class is initialized. */ + + if (!(m->clazz->state & CLASS_INITIALIZED)) + if (!initialize_class(m->clazz)) + return NULL; + + /* Call the Java method. */ + + ro = invoke(m, o, args); + + return ro; +} + + +#if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH) && defined(ENABLE_ANNOTATIONS) +/* reflect_get_declaredannotations ********************************************* + + Calls the annotation parser with the unparsed annotations and returnes + the parsed annotations as a map. + + IN: + annotations........the unparsed annotations + declaringClass.....the class in which the annotated element is declared + referer............the calling class (for the 'referer' parameter of + vm_call_method()) + + RETURN VALUE: + The parsed annotations as a + java.util.Map, Annotation>. + +*******************************************************************************/ + +java_handle_t* Reflection::get_declaredannotations(java_handle_bytearray_t *annotations, classinfo* declaringClass, classinfo *referer) +{ + static methodinfo* m_parseAnnotations = NULL; + + java_handle_t* h = native_new_and_init(class_sun_reflect_ConstantPool); + + if (h == NULL) + return NULL; + + sun_reflect_ConstantPool cp(h); + cp.set_constantPoolOop(declaringClass); + + /* only resolve the parser method the first time */ + if (m_parseAnnotations == NULL) { + // FIXME Use globals. + utf* utf_parseAnnotations = utf_new_char("parseAnnotations"); + utf* utf_desc = utf_new_char("([BLsun/reflect/ConstantPool;Ljava/lang/Class;)Ljava/util/Map;"); + + if (utf_parseAnnotations == NULL || utf_desc == NULL) + return NULL; + + m_parseAnnotations = class_resolveclassmethod( + class_sun_reflect_annotation_AnnotationParser, + utf_parseAnnotations, + utf_desc, + referer, + true); + + if (m_parseAnnotations == NULL) + return NULL; + } + + return (java_handle_t*) vm_call_method(m_parseAnnotations, NULL, annotations, cp.get_handle(), declaringClass); +} + + +/* reflect_get_parameterannotations ******************************************* + + Calls the annotation parser with the unparsed parameter annotations of + a method and returnes the parsed parameter annotations in a 2 dimensional + array. + + IN: + parameterAnnotations....the unparsed parameter annotations + slot....................the slot of the method + declaringClass..........the class in which the annotated element is + declared + referer.................the calling class (for the 'referer' parameter + of vm_call_method()) + + RETURN VALUE: + The parsed parameter annotations in a 2 dimensional array. + +*******************************************************************************/ + +java_handle_objectarray_t* Reflection::get_parameterannotations(java_handle_bytearray_t* parameterAnnotations, methodinfo* m, classinfo* referer) +{ + /* This method in java would be basically the following. + * We don't do it in java because we don't want to make a + * public method with wich you can get a ConstantPool, because + * with that you could read any kind of constants (even private + * ones). + * + * ConstantPool constPool = new ConstantPool(); + * constPool.constantPoolOop = method.getDeclaringClass(); + * return sun.reflect.AnnotationParser.parseParameterAnnotations( + * parameterAnnotations, + * constPool, + * method.getDeclaringClass(), + * method.getParameterTypes().length); + */ + + static methodinfo* m_parseParameterAnnotations = NULL; + + /* get parameter count */ + + int32_t numParameters = method_get_parametercount(m); + + if (numParameters < 0) + return NULL; + + /* get ConstantPool */ + + java_handle_t* h = native_new_and_init(class_sun_reflect_ConstantPool); + + if (h == NULL) + return NULL; + + sun_reflect_ConstantPool cp(h); + cp.set_constantPoolOop(m->clazz); + + /* only resolve the parser method the first time */ + if (m_parseParameterAnnotations == NULL) { + utf* utf_parseParameterAnnotations = utf_new_char("parseParameterAnnotations"); + utf* utf_desc = utf_new_char("([BLsun/reflect/ConstantPool;Ljava/lang/Class;I)[[Ljava/lang/annotation/Annotation;"); + + if (utf_parseParameterAnnotations == NULL || utf_desc == NULL) + return NULL; + + /* get parser method */ + + m_parseParameterAnnotations = class_resolveclassmethod( + class_sun_reflect_annotation_AnnotationParser, + utf_parseParameterAnnotations, + utf_desc, + referer, + true); + + if (m_parseParameterAnnotations == NULL) + return NULL; + } + + return (java_handle_objectarray_t*) vm_call_method(m_parseParameterAnnotations, NULL, parameterAnnotations, cp.get_handle(), m->clazz, numParameters); +} +#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: + * vim:noexpandtab:sw=4:ts=4: + */ diff --git a/src/cacaoh/headers.h b/src/native/vm/reflection.hpp similarity index 53% rename from src/cacaoh/headers.h rename to src/native/vm/reflection.hpp index de8ed7116..151222fc7 100644 --- a/src/cacaoh/headers.h +++ b/src/native/vm/reflection.hpp @@ -1,9 +1,7 @@ -/* src/cacaoh/headers.h - export functions for header generation +/* src/native/vm/reflection.hpp - helper functions for java/lang/reflect - Copyright (C) 1996-2005, 2006, 2007 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 + Copyright (C) 2007, 2008 + CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO This file is part of CACAO. @@ -24,38 +22,33 @@ */ -#ifndef _HEADERS_H -#define _HEADERS_H + +#ifndef _REFLECTION_HPP +#define _REFLECTION_HPP #include "config.h" -#include "toolbox/chain.h" +#include -#include "vm/global.h" +#include "native/jni.h" +#include "native/native.h" -#include "vmcore/class.h" +#include "vmcore/field.h" #include "vmcore/method.h" -#include "vmcore/utf8.h" - - -/* export variables ***********************************************************/ - -extern chain *nativemethod_chain; -extern chain *nativeclass_chain; -extern chain *ident_chain; -extern FILE *file; -/* function prototypes ********************************************************/ +class Reflection { +public: + static java_handle_t* invoke(methodinfo *m, java_handle_t *o, java_handle_objectarray_t *params); + static java_handle_t* method_invoke(methodinfo *m, java_handle_t *o, java_handle_objectarray_t *args, bool override); -void printID(utf *u); -void printOverloadPart(utf *desc); -void printmethod(methodinfo *m); -void gen_header_filename(char *buffer, utf *u); -void headerfile_generate(classinfo *c, char *opt_directory); -void print_classname(classinfo *clazz); +#if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH) && defined(ENABLE_ANNOTATIONS) + static java_handle_t* get_declaredannotations(java_handle_bytearray_t *annotations, classinfo* declaringClass, classinfo *referer); + static java_handle_objectarray_t* get_parameterannotations(java_handle_bytearray_t* parameterAnnotations, methodinfo* m, classinfo *referer); +#endif +}; -#endif /* _HEADERS_H */ +#endif // _REFLECTION_HPP /* @@ -64,9 +57,10 @@ void print_classname(classinfo *clazz); * Emacs will automagically detect them. * --------------------------------------------------------------------- * Local variables: - * mode: c + * mode: c++ * indent-tabs-mode: t * c-basic-offset: 4 * tab-width: 4 * End: + * vim:noexpandtab:sw=4:ts=4: */ diff --git a/src/native/vm/sun_misc_Unsafe.cpp b/src/native/vm/sun_misc_Unsafe.cpp index e406db615..f9dbb59b0 100644 --- a/src/native/vm/sun_misc_Unsafe.cpp +++ b/src/native/vm/sun_misc_Unsafe.cpp @@ -36,35 +36,16 @@ #include "native/llni.h" #include "native/native.h" -#include "native/include/java_lang_Object.h" /* before c.l.C */ -#include "native/include/java_lang_String.h" /* required by j.l.CL */ - -#if defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK) -# include "native/include/java_nio_ByteBuffer.h" /* required by j.l.CL */ -#endif - -#include "native/include/java_lang_ClassLoader.h" /* required by j.l.C */ -#include "native/include/java_lang_Class.h" -#include "native/include/java_lang_reflect_Field.h" -#include "native/include/java_lang_Thread.h" /* required by s.m.U */ -#include "native/include/java_lang_Throwable.h" - -#if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH) -# include "native/include/java_lang_reflect_VMField.h" +#if defined(ENABLE_JNI_HEADERS) +# include "native/include/sun_misc_Unsafe.h" #endif -#include "native/include/java_security_ProtectionDomain.h" /* required by smU */ - -// FIXME -extern "C" { -#include "native/include/sun_misc_Unsafe.h" -} - #include "vm/builtin.h" #include "vm/exceptions.hpp" #include "vm/initialize.h" #include "vm/string.hpp" +#include "vmcore/javaobjects.hpp" #include "vmcore/os.hpp" #include "vmcore/utf8.h" @@ -90,7 +71,7 @@ JNIEXPORT void JNICALL Java_sun_misc_Unsafe_registerNatives(JNIEnv *env, jclass * Method: getInt * Signature: (Ljava/lang/Object;J)I */ -JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_getInt__Ljava_lang_Object_2J(JNIEnv *env, sun_misc_Unsafe *_this, java_lang_Object *o, int64_t offset) +JNIEXPORT jint JNICALL Java_sun_misc_Unsafe_getInt__Ljava_lang_Object_2J(JNIEnv *env, jobject _this, jobject o, jlong offset) { int32_t *p; int32_t value; @@ -108,7 +89,7 @@ JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_getInt__Ljava_lang_Object_2J(JNIE * Method: putInt * Signature: (Ljava/lang/Object;JI)V */ -JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putInt__Ljava_lang_Object_2JI(JNIEnv *env, sun_misc_Unsafe *_this, java_lang_Object *o, int64_t offset, int32_t x) +JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putInt__Ljava_lang_Object_2JI(JNIEnv *env, jobject _this, jobject o, jlong offset, jint x) { int32_t *p; @@ -123,7 +104,7 @@ JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putInt__Ljava_lang_Object_2JI(JNIEnv * Method: getObject * Signature: (Ljava/lang/Object;J)Ljava/lang/Object; */ -JNIEXPORT java_lang_Object* JNICALL Java_sun_misc_Unsafe_getObject(JNIEnv *env, sun_misc_Unsafe *_this, java_lang_Object *o, int64_t offset) +JNIEXPORT jobject JNICALL Java_sun_misc_Unsafe_getObject(JNIEnv *env, jobject _this, jobject o, jlong offset) { void **p; void *value; @@ -132,7 +113,7 @@ JNIEXPORT java_lang_Object* JNICALL Java_sun_misc_Unsafe_getObject(JNIEnv *env, value = *p; - return (java_lang_Object*) value; + return (jobject) value; } @@ -141,7 +122,7 @@ JNIEXPORT java_lang_Object* JNICALL Java_sun_misc_Unsafe_getObject(JNIEnv *env, * Method: putObject * Signature: (Ljava/lang/Object;JLjava/lang/Object;)V */ -JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putObject(JNIEnv *env, sun_misc_Unsafe *_this, java_lang_Object *o, int64_t offset, java_lang_Object *x) +JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putObject(JNIEnv *env, jobject _this, jobject o, jlong offset, jobject x) { void **p; @@ -156,7 +137,7 @@ JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putObject(JNIEnv *env, sun_misc_Unsa * Method: getBoolean * Signature: (Ljava/lang/Object;J)Z */ -JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_getBoolean(JNIEnv *env, sun_misc_Unsafe *_this, java_lang_Object *o, int64_t offset) +JNIEXPORT jboolean JNICALL Java_sun_misc_Unsafe_getBoolean(JNIEnv *env, jobject _this, jobject o, jlong offset) { int32_t *p; int32_t value; @@ -174,7 +155,7 @@ JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_getBoolean(JNIEnv *env, sun_misc_ * Method: putBoolean * Signature: (Ljava/lang/Object;JZ)V */ -JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putBoolean(JNIEnv *env, sun_misc_Unsafe *_this, java_lang_Object *o, int64_t offset, int32_t x) +JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putBoolean(JNIEnv *env, jobject _this, jobject o, jlong offset, jboolean x) { int32_t *p; @@ -189,7 +170,7 @@ JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putBoolean(JNIEnv *env, sun_misc_Uns * Method: getByte * Signature: (Ljava/lang/Object;J)B */ -JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_getByte__Ljava_lang_Object_2J(JNIEnv *env, sun_misc_Unsafe *_this, java_lang_Object *o, int64_t offset) +JNIEXPORT jbyte JNICALL Java_sun_misc_Unsafe_getByte__Ljava_lang_Object_2J(JNIEnv *env, jobject _this, jobject o, jlong offset) { int32_t *p; int32_t value; @@ -207,7 +188,7 @@ JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_getByte__Ljava_lang_Object_2J(JNI * Method: putByte * Signature: (Ljava/lang/Object;JB)V */ -JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putByte__Ljava_lang_Object_2JB(JNIEnv *env, sun_misc_Unsafe *_this, java_lang_Object *o, int64_t offset, int32_t x) +JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putByte__Ljava_lang_Object_2JB(JNIEnv *env, jobject _this, jobject o, jlong offset, jbyte x) { int32_t *p; @@ -222,7 +203,7 @@ JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putByte__Ljava_lang_Object_2JB(JNIEn * Method: getShort * Signature: (Ljava/lang/Object;J)S */ -JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_getShort__Ljava_lang_Object_2J(JNIEnv *env, sun_misc_Unsafe *_this, java_lang_Object *o, int64_t offset) +JNIEXPORT jshort JNICALL Java_sun_misc_Unsafe_getShort__Ljava_lang_Object_2J(JNIEnv *env, jobject _this, jobject o, jlong offset) { int32_t *p; int32_t value; @@ -240,7 +221,7 @@ JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_getShort__Ljava_lang_Object_2J(JN * Method: putShort * Signature: (Ljava/lang/Object;JS)V */ -JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putShort__Ljava_lang_Object_2JS(JNIEnv *env, sun_misc_Unsafe *_this, java_lang_Object *o, int64_t offset, int32_t x) +JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putShort__Ljava_lang_Object_2JS(JNIEnv *env, jobject _this, jobject o, jlong offset, jshort x) { int32_t *p; @@ -255,7 +236,7 @@ JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putShort__Ljava_lang_Object_2JS(JNIE * Method: getChar * Signature: (Ljava/lang/Object;J)C */ -JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_getChar__Ljava_lang_Object_2J(JNIEnv *env, sun_misc_Unsafe *_this, java_lang_Object *o, int64_t offset) +JNIEXPORT jchar JNICALL Java_sun_misc_Unsafe_getChar__Ljava_lang_Object_2J(JNIEnv *env, jobject _this, jobject o, jlong offset) { int32_t *p; int32_t value; @@ -273,7 +254,7 @@ JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_getChar__Ljava_lang_Object_2J(JNI * Method: putChar * Signature: (Ljava/lang/Object;JC)V */ -JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putChar__Ljava_lang_Object_2JC(JNIEnv *env, sun_misc_Unsafe *_this, java_lang_Object *o, int64_t offset, int32_t x) +JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putChar__Ljava_lang_Object_2JC(JNIEnv *env, jobject _this, jobject o, jlong offset, jchar x) { int32_t *p; @@ -288,7 +269,7 @@ JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putChar__Ljava_lang_Object_2JC(JNIEn * Method: getLong * Signature: (Ljava/lang/Object;J)J */ -JNIEXPORT int64_t JNICALL Java_sun_misc_Unsafe_getLong__Ljava_lang_Object_2J(JNIEnv *env, sun_misc_Unsafe *_this, java_lang_Object *o, int64_t offset) +JNIEXPORT jlong JNICALL Java_sun_misc_Unsafe_getLong__Ljava_lang_Object_2J(JNIEnv *env, jobject _this, jobject o, jlong offset) { int64_t *p; int64_t value; @@ -306,7 +287,7 @@ JNIEXPORT int64_t JNICALL Java_sun_misc_Unsafe_getLong__Ljava_lang_Object_2J(JNI * Method: putLong * Signature: (Ljava/lang/Object;JJ)V */ -JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putLong__Ljava_lang_Object_2JJ(JNIEnv *env, sun_misc_Unsafe *_this, java_lang_Object *o, int64_t offset, int64_t x) +JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putLong__Ljava_lang_Object_2JJ(JNIEnv *env, jobject _this, jobject o, jlong offset, jlong x) { int64_t *p; @@ -321,7 +302,7 @@ JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putLong__Ljava_lang_Object_2JJ(JNIEn * Method: getFloat * Signature: (Ljava/lang/Object;J)F */ -JNIEXPORT float JNICALL Java_sun_misc_Unsafe_getFloat__Ljava_lang_Object_2J(JNIEnv *env, sun_misc_Unsafe *_this, java_lang_Object *o, int64_t offset) +JNIEXPORT jfloat JNICALL Java_sun_misc_Unsafe_getFloat__Ljava_lang_Object_2J(JNIEnv *env, jobject _this, jobject o, jlong offset) { float *p; float value; @@ -339,7 +320,7 @@ JNIEXPORT float JNICALL Java_sun_misc_Unsafe_getFloat__Ljava_lang_Object_2J(JNIE * Method: putFloat * Signature: (Ljava/lang/Object;JF)V */ -JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putFloat__Ljava_lang_Object_2JF(JNIEnv *env, sun_misc_Unsafe *_this, java_lang_Object *o, int64_t offset, float x) +JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putFloat__Ljava_lang_Object_2JF(JNIEnv *env, jobject _this, jobject o, jlong offset, jfloat x) { float *p; @@ -354,7 +335,7 @@ JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putFloat__Ljava_lang_Object_2JF(JNIE * Method: getDouble * Signature: (Ljava/lang/Object;J)D */ -JNIEXPORT double JNICALL Java_sun_misc_Unsafe_getDouble__Ljava_lang_Object_2J(JNIEnv *env, sun_misc_Unsafe *_this, java_lang_Object *o, int64_t offset) +JNIEXPORT jdouble JNICALL Java_sun_misc_Unsafe_getDouble__Ljava_lang_Object_2J(JNIEnv *env, jobject _this, jobject o, jlong offset) { double *p; double value; @@ -372,7 +353,7 @@ JNIEXPORT double JNICALL Java_sun_misc_Unsafe_getDouble__Ljava_lang_Object_2J(JN * Method: putDouble * Signature: (Ljava/lang/Object;JD)V */ -JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putDouble__Ljava_lang_Object_2JD(JNIEnv *env, sun_misc_Unsafe *_this, java_lang_Object *o, int64_t offset, double x) +JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putDouble__Ljava_lang_Object_2JD(JNIEnv *env, jobject _this, jobject o, jlong offset, jdouble x) { double *p; @@ -387,7 +368,7 @@ JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putDouble__Ljava_lang_Object_2JD(JNI * Method: getByte * Signature: (J)B */ -JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_getByte__J(JNIEnv *env, sun_misc_Unsafe *_this, int64_t address) +JNIEXPORT jbyte JNICALL Java_sun_misc_Unsafe_getByte__J(JNIEnv *env, jobject _this, jlong address) { int8_t *p; int8_t value; @@ -405,7 +386,7 @@ JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_getByte__J(JNIEnv *env, sun_misc_ * Method: putByte * Signature: (JB)V */ -JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putByte__JB(JNIEnv *env, sun_misc_Unsafe *_this, int64_t address, int32_t value) +JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putByte__JB(JNIEnv *env, jobject _this, jlong address, jbyte value) { int8_t *p; @@ -420,7 +401,7 @@ JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putByte__JB(JNIEnv *env, sun_misc_Un * Method: getShort * Signature: (J)S */ -JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_getShort__J(JNIEnv *env, sun_misc_Unsafe *_this, int64_t address) +JNIEXPORT jshort JNICALL Java_sun_misc_Unsafe_getShort__J(JNIEnv *env, jobject _this, jlong address) { int16_t *p; int16_t value; @@ -438,7 +419,7 @@ JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_getShort__J(JNIEnv *env, sun_misc * Method: putShort * Signature: (JS)V */ -JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putShort__JS(JNIEnv *env, sun_misc_Unsafe *_this, int64_t address, int32_t value) +JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putShort__JS(JNIEnv *env, jobject _this, jlong address, jshort value) { int16_t *p; @@ -453,7 +434,7 @@ JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putShort__JS(JNIEnv *env, sun_misc_U * Method: getChar * Signature: (J)C */ -JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_getChar__J(JNIEnv *env, sun_misc_Unsafe *_this, int64_t address) +JNIEXPORT jchar JNICALL Java_sun_misc_Unsafe_getChar__J(JNIEnv *env, jobject _this, jlong address) { uint16_t *p; uint16_t value; @@ -471,7 +452,7 @@ JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_getChar__J(JNIEnv *env, sun_misc_ * Method: putChar * Signature: (JC)V */ -JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putChar__JC(JNIEnv *env, sun_misc_Unsafe *_this, int64_t address, int32_t value) +JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putChar__JC(JNIEnv *env, jobject _this, jlong address, jchar value) { uint16_t *p; @@ -486,7 +467,7 @@ JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putChar__JC(JNIEnv *env, sun_misc_Un * Method: getInt * Signature: (J)I */ -JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_getInt__J(JNIEnv *env, sun_misc_Unsafe *_this, int64_t address) +JNIEXPORT jint JNICALL Java_sun_misc_Unsafe_getInt__J(JNIEnv *env, jobject _this, jlong address) { int32_t *p; int32_t value; @@ -504,7 +485,7 @@ JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_getInt__J(JNIEnv *env, sun_misc_U * Method: putInt * Signature: (JI)V */ -JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putInt__JI(JNIEnv *env, struct sun_misc_Unsafe* _this, int64_t address, int32_t value) +JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putInt__JI(JNIEnv *env, jobject _this, jlong address, jint value) { int32_t *p; @@ -519,7 +500,7 @@ JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putInt__JI(JNIEnv *env, struct sun_m * Method: getLong * Signature: (J)J */ -JNIEXPORT int64_t JNICALL Java_sun_misc_Unsafe_getLong__J(JNIEnv *env, sun_misc_Unsafe *_this, int64_t address) +JNIEXPORT jlong JNICALL Java_sun_misc_Unsafe_getLong__J(JNIEnv *env, jobject _this, jlong address) { int64_t *p; int64_t value; @@ -537,7 +518,7 @@ JNIEXPORT int64_t JNICALL Java_sun_misc_Unsafe_getLong__J(JNIEnv *env, sun_misc_ * Method: putLong * Signature: (JJ)V */ -JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putLong__JJ(JNIEnv *env, sun_misc_Unsafe *_this, int64_t address, int64_t value) +JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putLong__JJ(JNIEnv *env, jobject _this, jlong address, jlong value) { int64_t *p; @@ -552,7 +533,7 @@ JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putLong__JJ(JNIEnv *env, sun_misc_Un * Method: getFloat * Signature: (J)F */ -JNIEXPORT float JNICALL Java_sun_misc_Unsafe_getFloat__J(JNIEnv *env, sun_misc_Unsafe *_this, int64_t address) +JNIEXPORT jfloat JNICALL Java_sun_misc_Unsafe_getFloat__J(JNIEnv *env, jobject _this, jlong address) { float *p; float value; @@ -570,7 +551,7 @@ JNIEXPORT float JNICALL Java_sun_misc_Unsafe_getFloat__J(JNIEnv *env, sun_misc_U * Method: putFloat * Signature: (JF)V */ -JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putFloat__JF(JNIEnv *env, struct sun_misc_Unsafe* __this, int64_t address, float value) +JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putFloat__JF(JNIEnv *env, jobject _this, jlong address, jfloat value) { float* p; @@ -585,34 +566,24 @@ JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putFloat__JF(JNIEnv *env, struct sun * Method: objectFieldOffset * Signature: (Ljava/lang/reflect/Field;)J */ -JNIEXPORT int64_t JNICALL Java_sun_misc_Unsafe_objectFieldOffset(JNIEnv *env, sun_misc_Unsafe *_this, java_lang_reflect_Field *field) +JNIEXPORT jlong JNICALL Java_sun_misc_Unsafe_objectFieldOffset(JNIEnv *env, jobject _this, jobject field) { - classinfo *c; - fieldinfo *f; - int32_t slot; - -#if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH) - java_lang_reflect_VMField *rvmf; -#endif - #if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH) - LLNI_field_get_ref(field, f, rvmf); - LLNI_field_get_cls(rvmf, clazz, c); - LLNI_field_get_val(rvmf, slot , slot); + java_lang_reflect_Field rf(field); + java_lang_reflect_VMField rvmf(rf.get_f()); + fieldinfo* f = rvmf.get_field(); #elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK) - LLNI_field_get_cls(field, clazz, c); - LLNI_field_get_val(field, slot , slot); + LLNI_field_get_cls((java_lang_reflect_Field *) field, clazz, c); + LLNI_field_get_val((java_lang_reflect_Field *) field, slot , slot); #else # error unknown configuration #endif - f = &(c->fields[slot]); - - return (int64_t) f->offset; + return (jlong) f->offset; } @@ -621,7 +592,7 @@ JNIEXPORT int64_t JNICALL Java_sun_misc_Unsafe_objectFieldOffset(JNIEnv *env, su * Method: allocateMemory * Signature: (J)J */ -JNIEXPORT int64_t JNICALL Java_sun_misc_Unsafe_allocateMemory(JNIEnv *env, sun_misc_Unsafe *_this, int64_t bytes) +JNIEXPORT jlong JNICALL Java_sun_misc_Unsafe_allocateMemory(JNIEnv *env, jobject _this, jlong bytes) { size_t length; void *p; @@ -647,7 +618,7 @@ JNIEXPORT int64_t JNICALL Java_sun_misc_Unsafe_allocateMemory(JNIEnv *env, sun_m * Method: setMemory * Signature: (Ljava/lang/Object;JJB)V */ -JNIEXPORT void JNICALL Java_sun_misc_Unsafe_setMemory(JNIEnv *env, sun_misc_Unsafe *_this, java_lang_Object *o, int64_t offset, int64_t bytes, int32_t value) +JNIEXPORT void JNICALL Java_sun_misc_Unsafe_setMemory(JNIEnv *env, jobject _this, jobject o, jlong offset, jlong bytes, jbyte value) { size_t length; void *p; @@ -674,7 +645,7 @@ JNIEXPORT void JNICALL Java_sun_misc_Unsafe_setMemory(JNIEnv *env, sun_misc_Unsa * Method: copyMemory * Signature: (Ljava/lang/Object;JLjava/lang/Object;JJ)V */ -JNIEXPORT void JNICALL Java_sun_misc_Unsafe_copyMemory(JNIEnv *env, sun_misc_Unsafe *_this, java_lang_Object *srcBase, int64_t srcOffset, java_lang_Object *destBase, int64_t destOffset, int64_t bytes) +JNIEXPORT void JNICALL Java_sun_misc_Unsafe_copyMemory(JNIEnv *env, jobject _this, jobject srcBase, jlong srcOffset, jobject destBase, jlong destOffset, jlong bytes) { size_t length; void *src; @@ -703,7 +674,7 @@ JNIEXPORT void JNICALL Java_sun_misc_Unsafe_copyMemory(JNIEnv *env, sun_misc_Uns * Method: setMemory * Signature: (JJB)V */ -JNIEXPORT void JNICALL Java_sun_misc_Unsafe_setMemory(JNIEnv *env, sun_misc_Unsafe *_this, int64_t address, int64_t bytes, int32_t value) +JNIEXPORT void JNICALL Java_sun_misc_Unsafe_setMemory(JNIEnv *env, jobject _this, jlong address, jlong bytes, jbyte value) { size_t length; void *p; @@ -728,7 +699,7 @@ JNIEXPORT void JNICALL Java_sun_misc_Unsafe_setMemory(JNIEnv *env, sun_misc_Unsa * Method: copyMemory * Signature: (JJJ)V */ -JNIEXPORT void JNICALL Java_sun_misc_Unsafe_copyMemory(JNIEnv *env, sun_misc_Unsafe *_this, int64_t srcAddress, int64_t destAddress, int64_t bytes) +JNIEXPORT void JNICALL Java_sun_misc_Unsafe_copyMemory(JNIEnv *env, jobject _this, jlong srcAddress, jlong destAddress, jlong bytes) { size_t length; void *src; @@ -757,7 +728,7 @@ JNIEXPORT void JNICALL Java_sun_misc_Unsafe_copyMemory(JNIEnv *env, sun_misc_Uns * Method: freeMemory * Signature: (J)V */ -JNIEXPORT void JNICALL Java_sun_misc_Unsafe_freeMemory(JNIEnv *env, sun_misc_Unsafe *_this, int64_t address) +JNIEXPORT void JNICALL Java_sun_misc_Unsafe_freeMemory(JNIEnv *env, jobject _this, jlong address) { void *p; @@ -777,7 +748,7 @@ JNIEXPORT void JNICALL Java_sun_misc_Unsafe_freeMemory(JNIEnv *env, sun_misc_Uns * Method: staticFieldOffset * Signature: (Ljava/lang/reflect/Field;)J */ -JNIEXPORT int64_t JNICALL Java_sun_misc_Unsafe_staticFieldOffset(JNIEnv *env, sun_misc_Unsafe *_this, java_lang_reflect_Field *f) +JNIEXPORT jlong JNICALL Java_sun_misc_Unsafe_staticFieldOffset(JNIEnv *env, jobject _this, jobject f) { /* The offset of static fields is 0. */ @@ -790,34 +761,24 @@ JNIEXPORT int64_t JNICALL Java_sun_misc_Unsafe_staticFieldOffset(JNIEnv *env, su * Method: staticFieldBase * Signature: (Ljava/lang/reflect/Field;)Ljava/lang/Object; */ -JNIEXPORT java_lang_Object* JNICALL Java_sun_misc_Unsafe_staticFieldBase(JNIEnv *env, sun_misc_Unsafe *_this, java_lang_reflect_Field *rf) +JNIEXPORT jobject JNICALL Java_sun_misc_Unsafe_staticFieldBase(JNIEnv *env, jobject _this, jobject field) { - classinfo *c; - fieldinfo *f; - int32_t slot; - -#if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH) - java_lang_reflect_VMField *rvmf; -#endif - #if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH) - LLNI_field_get_ref(rf, f, rvmf); - LLNI_field_get_cls(rvmf, clazz, c); - LLNI_field_get_val(rvmf, slot , slot); + java_lang_reflect_Field rf(field); + java_lang_reflect_VMField rvmf(rf.get_f()); + fieldinfo* f = rvmf.get_field(); #elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK) - LLNI_field_get_cls(rf, clazz, c); - LLNI_field_get_val(rf, slot , slot); + LLNI_field_get_cls((java_lang_reflect_Field *) rf, clazz, c); + LLNI_field_get_val((java_lang_reflect_Field *) rf, slot , slot); #else # error unknown configuration #endif - f = &(c->fields[slot]); - - return (java_lang_Object *) (f->value); + return (jobject) (f->value); } @@ -826,7 +787,7 @@ JNIEXPORT java_lang_Object* JNICALL Java_sun_misc_Unsafe_staticFieldBase(JNIEnv * Method: ensureClassInitialized * Signature: (Ljava/lang/Class;)V */ -JNIEXPORT void JNICALL Java_sun_misc_Unsafe_ensureClassInitialized(JNIEnv *env, sun_misc_Unsafe *_this, java_lang_Class *clazz) +JNIEXPORT void JNICALL Java_sun_misc_Unsafe_ensureClassInitialized(JNIEnv *env, jobject _this, jclass clazz) { classinfo *c; @@ -842,7 +803,7 @@ JNIEXPORT void JNICALL Java_sun_misc_Unsafe_ensureClassInitialized(JNIEnv *env, * Method: arrayBaseOffset * Signature: (Ljava/lang/Class;)I */ -JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_arrayBaseOffset(JNIEnv *env, sun_misc_Unsafe *_this, java_lang_Class *arrayClass) +JNIEXPORT jint JNICALL Java_sun_misc_Unsafe_arrayBaseOffset(JNIEnv *env, jobject _this, jclass arrayClass) { classinfo *c; arraydescriptor *ad; @@ -865,7 +826,7 @@ JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_arrayBaseOffset(JNIEnv *env, sun_ * Method: arrayIndexScale * Signature: (Ljava/lang/Class;)I */ -JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_arrayIndexScale(JNIEnv *env, sun_misc_Unsafe *_this, java_lang_Class *arrayClass) +JNIEXPORT jint JNICALL Java_sun_misc_Unsafe_arrayIndexScale(JNIEnv *env, jobject _this, jclass arrayClass) { classinfo *c; arraydescriptor *ad; @@ -888,7 +849,7 @@ JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_arrayIndexScale(JNIEnv *env, sun_ * Method: addressSize * Signature: ()I */ -JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_addressSize(JNIEnv *env, sun_misc_Unsafe *_this) +JNIEXPORT jint JNICALL Java_sun_misc_Unsafe_addressSize(JNIEnv *env, jobject _this) { return SIZEOF_VOID_P; } @@ -899,7 +860,7 @@ JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_addressSize(JNIEnv *env, sun_misc * Method: pageSize * Signature: ()I */ -JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_pageSize(JNIEnv *env, sun_misc_Unsafe *_this) +JNIEXPORT jint JNICALL Java_sun_misc_Unsafe_pageSize(JNIEnv *env, jobject _this) { int sz; @@ -914,12 +875,11 @@ JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_pageSize(JNIEnv *env, sun_misc_Un * Method: defineClass * Signature: (Ljava/lang/String;[BIILjava/lang/ClassLoader;Ljava/security/ProtectionDomain;)Ljava/lang/Class; */ -JNIEXPORT java_lang_Class* JNICALL Java_sun_misc_Unsafe_defineClass__Ljava_lang_String_2_3BIILjava_lang_ClassLoader_2Ljava_security_ProtectionDomain_2(JNIEnv *env, sun_misc_Unsafe *_this, java_lang_String *name, java_handle_bytearray_t *b, int32_t off, int32_t len, java_lang_ClassLoader *loader, java_security_ProtectionDomain *protectionDomain) +JNIEXPORT jclass JNICALL Java_sun_misc_Unsafe_defineClass__Ljava_lang_String_2_3BIILjava_lang_ClassLoader_2Ljava_security_ProtectionDomain_2(JNIEnv *env, jobject _this, jstring name, jbyteArray b, jint off, jint len, jobject loader, jobject protectionDomain) { classloader_t *cl; utf *utfname; classinfo *c; - java_lang_Class *o; cl = loader_hashtable_classloader_add((java_handle_t *) loader); @@ -948,23 +908,21 @@ JNIEXPORT java_lang_Class* JNICALL Java_sun_misc_Unsafe_defineClass__Ljava_lang_ /* define the class */ - c = class_define(utfname, cl, len, (uint8_t *) &(LLNI_array_direct(b, off)), + c = class_define(utfname, cl, len, (uint8_t *) &(LLNI_array_direct((java_handle_bytearray_t*) b, off)), (java_handle_t *) protectionDomain); if (c == NULL) return NULL; - /* for convenience */ - - o = LLNI_classinfo_wrap(c); + java_handle_t* h = LLNI_classinfo_wrap(c); + java_lang_Class jlc(h); #if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH) - /* set ProtectionDomain */ - - LLNI_field_set_ref(o, pd, protectionDomain); + // Set ProtectionDomain. + jlc.set_pd(protectionDomain); #endif - return o; + return (jclass) jlc.get_handle(); } @@ -973,7 +931,7 @@ JNIEXPORT java_lang_Class* JNICALL Java_sun_misc_Unsafe_defineClass__Ljava_lang_ * Method: allocateInstance * Signature: (Ljava/lang/Class;)Ljava/lang/Object; */ -JNIEXPORT java_lang_Object* JNICALL Java_sun_misc_Unsafe_allocateInstance(JNIEnv *env, sun_misc_Unsafe *_this, java_lang_Class *cls) +JNIEXPORT jobject JNICALL Java_sun_misc_Unsafe_allocateInstance(JNIEnv *env, jobject _this, jclass cls) { classinfo *c; java_handle_t *o; @@ -982,7 +940,7 @@ JNIEXPORT java_lang_Object* JNICALL Java_sun_misc_Unsafe_allocateInstance(JNIEnv o = builtin_new(c); - return (java_lang_Object *) o; + return (jobject ) o; } @@ -991,7 +949,7 @@ JNIEXPORT java_lang_Object* JNICALL Java_sun_misc_Unsafe_allocateInstance(JNIEnv * Method: throwException * Signature: (Ljava/lang/Throwable;)V */ -JNIEXPORT void JNICALL Java_sun_misc_Unsafe_throwException(JNIEnv *env, sun_misc_Unsafe *_this, java_lang_Throwable *ee) +JNIEXPORT void JNICALL Java_sun_misc_Unsafe_throwException(JNIEnv *env, jobject _this, jobject ee) { java_handle_t *o; @@ -1006,7 +964,7 @@ JNIEXPORT void JNICALL Java_sun_misc_Unsafe_throwException(JNIEnv *env, sun_misc * Method: compareAndSwapObject * Signature: (Ljava/lang/Object;JLjava/lang/Object;Ljava/lang/Object;)Z */ -JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_compareAndSwapObject(JNIEnv *env, sun_misc_Unsafe *_this, java_lang_Object *o, int64_t offset, java_lang_Object *expected, java_lang_Object *x) +JNIEXPORT jboolean JNICALL Java_sun_misc_Unsafe_compareAndSwapObject(JNIEnv *env, jobject _this, jobject o, jlong offset, jobject expected, jobject x) { volatile void **p; void *result; @@ -1029,7 +987,7 @@ JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_compareAndSwapObject(JNIEnv *env, * Method: compareAndSwapInt * Signature: (Ljava/lang/Object;JII)Z */ -JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_compareAndSwapInt(JNIEnv *env, sun_misc_Unsafe* _this, java_lang_Object* o, int64_t offset, int32_t expected, int32_t x) +JNIEXPORT jboolean JNICALL Java_sun_misc_Unsafe_compareAndSwapInt(JNIEnv *env, jobject _this, jobject o, jlong offset, jint expected, jint x) { uint32_t *p; uint32_t result; @@ -1052,7 +1010,7 @@ JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_compareAndSwapInt(JNIEnv *env, su * Method: compareAndSwapLong * Signature: (Ljava/lang/Object;JJJ)Z */ -JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_compareAndSwapLong(JNIEnv *env, sun_misc_Unsafe *_this, java_lang_Object *o, int64_t offset, int64_t expected, int64_t x) +JNIEXPORT jboolean JNICALL Java_sun_misc_Unsafe_compareAndSwapLong(JNIEnv *env, jobject _this, jobject o, jlong offset, jlong expected, jlong x) { uint64_t *p; uint64_t result; @@ -1075,7 +1033,7 @@ JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_compareAndSwapLong(JNIEnv *env, s * Method: getObjectVolatile * Signature: (Ljava/lang/Object;J)Ljava/lang/Object; */ -JNIEXPORT java_lang_Object* JNICALL Java_sun_misc_Unsafe_getObjectVolatile(JNIEnv *env, sun_misc_Unsafe *_this, java_lang_Object *o, int64_t offset) +JNIEXPORT jobject JNICALL Java_sun_misc_Unsafe_getObjectVolatile(JNIEnv *env, jobject _this, jobject o, jlong offset) { volatile void **p; volatile void *value; @@ -1084,7 +1042,7 @@ JNIEXPORT java_lang_Object* JNICALL Java_sun_misc_Unsafe_getObjectVolatile(JNIEn value = *p; - return (java_lang_Object *) value; + return (jobject ) value; } @@ -1093,7 +1051,7 @@ JNIEXPORT java_lang_Object* JNICALL Java_sun_misc_Unsafe_getObjectVolatile(JNIEn * Method: putObjectVolatile * Signature: (Ljava/lang/Object;JLjava/lang/Object;)V */ -JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putObjectVolatile(JNIEnv *env, sun_misc_Unsafe *_this, java_lang_Object *o, int64_t offset, java_lang_Object *x) +JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putObjectVolatile(JNIEnv *env, jobject _this, jobject o, jlong offset, jobject x) { volatile void **p; @@ -1147,7 +1105,7 @@ JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putObjectVolatile(JNIEnv *env, sun_m * Method: getIntVolatile * Signature: (Ljava/lang/Object;J)I */ -JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_getIntVolatile(JNIEnv *env, sun_misc_Unsafe *_this, java_lang_Object *o, int64_t offset) +JNIEXPORT jint JNICALL Java_sun_misc_Unsafe_getIntVolatile(JNIEnv *env, jobject _this, jobject o, jlong offset) { UNSAFE_GET_VOLATILE(int32_t); } @@ -1158,7 +1116,7 @@ JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_getIntVolatile(JNIEnv *env, sun_m * Method: putIntVolatile * Signature: (Ljava/lang/Object;JI)V */ -JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putIntVolatile(JNIEnv *env, sun_misc_Unsafe *_this, java_lang_Object *o, int64_t offset, int32_t x) +JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putIntVolatile(JNIEnv *env, jobject _this, jobject o, jlong offset, jint x) { UNSAFE_PUT_VOLATILE(int32_t); } @@ -1169,7 +1127,7 @@ JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putIntVolatile(JNIEnv *env, sun_misc * Method: getLongVolatile * Signature: (Ljava/lang/Object;J)J */ -JNIEXPORT int64_t JNICALL Java_sun_misc_Unsafe_getLongVolatile(JNIEnv *env, sun_misc_Unsafe *_this, java_lang_Object *o, int64_t offset) +JNIEXPORT jlong JNICALL Java_sun_misc_Unsafe_getLongVolatile(JNIEnv *env, jobject _this, jobject o, jlong offset) { UNSAFE_GET_VOLATILE(int64_t); } @@ -1180,7 +1138,7 @@ JNIEXPORT int64_t JNICALL Java_sun_misc_Unsafe_getLongVolatile(JNIEnv *env, sun_ * Method: putLongVolatile * Signature: (Ljava/lang/Object;JJ)V */ -JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putLongVolatile(JNIEnv *env, sun_misc_Unsafe *_this, java_lang_Object *o, int64_t offset, int64_t x) +JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putLongVolatile(JNIEnv *env, jobject _this, jobject o, jlong offset, jlong x) { UNSAFE_PUT_VOLATILE(int64_t); } @@ -1191,7 +1149,7 @@ JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putLongVolatile(JNIEnv *env, sun_mis * Method: getDoubleVolatile * Signature: (Ljava/lang/Object;J)D */ -JNIEXPORT double JNICALL Java_sun_misc_Unsafe_getDoubleVolatile(JNIEnv *env, sun_misc_Unsafe* __this, java_lang_Object* o, int64_t offset) +JNIEXPORT jdouble JNICALL Java_sun_misc_Unsafe_getDoubleVolatile(JNIEnv *env, jobject __this, jobject o, jlong offset) { UNSAFE_GET_VOLATILE(double); } @@ -1202,7 +1160,7 @@ JNIEXPORT double JNICALL Java_sun_misc_Unsafe_getDoubleVolatile(JNIEnv *env, sun * Method: putOrderedObject * Signature: (Ljava/lang/Object;JLjava/lang/Object;)V */ -JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putOrderedObject(JNIEnv *env, sun_misc_Unsafe *_this, java_lang_Object *o, int64_t offset, java_lang_Object *x) +JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putOrderedObject(JNIEnv *env, jobject _this, jobject o, jlong offset, jobject x) { java_handle_t *_h; java_handle_t *_hx; @@ -1232,7 +1190,7 @@ JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putOrderedObject(JNIEnv *env, sun_mi * Method: putOrderedInt * Signature: (Ljava/lang/Object;JI)V */ -JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putOrderedInt(JNIEnv *env, sun_misc_Unsafe *_this, java_lang_Object *o, int64_t offset, int32_t x) +JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putOrderedInt(JNIEnv *env, jobject _this, jobject o, jlong offset, jint x) { UNSAFE_PUT_VOLATILE(int32_t); } @@ -1243,7 +1201,7 @@ JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putOrderedInt(JNIEnv *env, sun_misc_ * Method: putOrderedLong * Signature: (Ljava/lang/Object;JJ)V */ -JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putOrderedLong(JNIEnv *env, sun_misc_Unsafe *_this, java_lang_Object *o, int64_t offset, int64_t x) +JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putOrderedLong(JNIEnv *env, jobject _this, jobject o, jlong offset, jlong x) { UNSAFE_PUT_VOLATILE(int64_t); } @@ -1254,7 +1212,7 @@ JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putOrderedLong(JNIEnv *env, sun_misc * Method: unpark * Signature: (Ljava/lang/Object;)V */ -JNIEXPORT void JNICALL Java_sun_misc_Unsafe_unpark(JNIEnv *env, sun_misc_Unsafe *_this, java_lang_Object *thread) +JNIEXPORT void JNICALL Java_sun_misc_Unsafe_unpark(JNIEnv *env, jobject _this, jobject thread) { /* XXX IMPLEMENT ME */ } @@ -1265,7 +1223,7 @@ JNIEXPORT void JNICALL Java_sun_misc_Unsafe_unpark(JNIEnv *env, sun_misc_Unsafe * Method: park * Signature: (ZJ)V */ -JNIEXPORT void JNICALL Java_sun_misc_Unsafe_park(JNIEnv *env, sun_misc_Unsafe *_this, int32_t isAbsolute, int64_t time) +JNIEXPORT void JNICALL Java_sun_misc_Unsafe_park(JNIEnv *env, jobject _this, jboolean isAbsolute, jlong time) { /* XXX IMPLEMENT ME */ } diff --git a/src/threads/posix/thread-posix.cpp b/src/threads/posix/thread-posix.cpp index 8b789d6d3..aef67d8e6 100644 --- a/src/threads/posix/thread-posix.cpp +++ b/src/threads/posix/thread-posix.cpp @@ -53,19 +53,6 @@ #include "native/llni.h" #include "native/native.h" -#include "native/include/java_lang_Object.h" -#include "native/include/java_lang_String.h" -#include "native/include/java_lang_Throwable.h" -#include "native/include/java_lang_Thread.h" - -#if defined(ENABLE_JAVASE) -# include "native/include/java_lang_ThreadGroup.h" -#endif - -#if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH) -# include "native/include/java_lang_VMThread.h" -#endif - #include "threads/condition.hpp" #include "threads/lock-common.h" #include "threads/mutex.hpp" @@ -84,6 +71,7 @@ #include "vm/jit/asmpart.h" #include "vmcore/globals.hpp" +#include "vmcore/javaobjects.hpp" #include "vmcore/options.h" #if defined(ENABLE_STATISTICS) @@ -756,17 +744,12 @@ void threads_impl_init(void) static void *threads_startup_thread(void *arg) { - startupinfo *startup; - threadobject *t; - java_lang_Thread *object; -#if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH) - java_lang_VMThread *vmt; -#endif - sem_t *psem; - classinfo *c; - methodinfo *m; - java_handle_t *o; - functionptr function; + startupinfo *startup; + threadobject *t; + sem_t *psem; + classinfo *c; + methodinfo *m; + functionptr function; #if defined(ENABLE_GC_BOEHM) # if !defined(__DARWIN__) @@ -829,13 +812,13 @@ static void *threads_startup_thread(void *arg) # endif #endif - /* get the java.lang.Thread object for this thread */ - - object = (java_lang_Thread *) thread_get_object(t); + // Get the java.lang.Thread object for this thread. + java_handle_t* object = thread_get_object(t); + java_lang_Thread jlt(object); /* set our priority */ - threads_set_thread_priority(t->tid, LLNI_field_direct(object, priority)); + threads_set_thread_priority(t->tid, jlt.get_priority()); /* Thread is completely initialized. */ @@ -895,20 +878,22 @@ static void *threads_startup_thread(void *arg) #warning Move to C++ #if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH) - /* we need to start the run method of java.lang.VMThread */ - LLNI_field_get_ref(object, vmThread, vmt); - o = (java_handle_t *) vmt; + // We need to start the run method of java.lang.VMThread. + java_lang_VMThread jlvmt(jlt.get_vmThread()); + java_handle_t* h = jlvmt.get_handle(); #elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK) || defined(WITH_JAVA_RUNTIME_LIBRARY_CLDC1_1) - o = (java_handle_t *) object; + + java_handle_t* h = jlt.get_handle(); + #else # error unknown classpath configuration #endif /* Run the thread. */ - (void) vm_call_method(m, o); + (void) vm_call_method(m, h); } else { /* set ThreadMXBean variables */ @@ -1056,19 +1041,7 @@ void threads_set_thread_priority(pthread_t tid, int priority) */ bool thread_detach_current_thread(void) { - threadobject *t; - bool result; - java_lang_Thread *object; - java_handle_t *o; -#if defined(ENABLE_JAVASE) - java_lang_ThreadGroup *group; - java_handle_t *e; - void *handler; - classinfo *c; - methodinfo *m; -#endif - - t = thread_get_current(); + threadobject* t = thread_get_current(); /* Sanity check. */ @@ -1077,23 +1050,22 @@ bool thread_detach_current_thread(void) /* If the given thread has already been detached, this operation is a no-op. */ - result = thread_is_attached(t); - - if (result == false) + if (thread_is_attached(t) == false) return true; DEBUGTHREADS("detaching", t); - object = (java_lang_Thread *) thread_get_object(t); + java_handle_t* object = thread_get_object(t); + java_lang_Thread jlt(object); #if defined(ENABLE_JAVASE) - LLNI_field_get_ref(object, group, group); + java_handle_t* group = jlt.get_group(); /* If there's an uncaught exception, call uncaughtException on the thread's exception handler, or the thread's group if this is unset. */ - e = exceptions_get_and_clear_exception(); + java_handle_t* e = exceptions_get_and_clear_exception(); if (e != NULL) { /* We use the type void* for handler here, as it's not trivial @@ -1101,30 +1073,37 @@ bool thread_detach_current_thread(void) header file with cacaoh. */ # if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH) - LLNI_field_get_ref(object, exceptionHandler, handler); + + java_handle_t* handler = jlt.get_exceptionHandler(); + # elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK) + LLNI_field_get_ref(object, uncaughtExceptionHandler, handler); + # endif + classinfo* c; + java_handle_t* h; + if (handler != NULL) { LLNI_class_get(handler, c); - o = (java_handle_t *) handler; + h = (java_handle_t *) handler; } else { LLNI_class_get(group, c); - o = (java_handle_t *) group; + h = (java_handle_t *) group; } - m = class_resolveclassmethod(c, - utf_uncaughtException, - utf_java_lang_Thread_java_lang_Throwable__V, - NULL, - true); + methodinfo* m = class_resolveclassmethod(c, + utf_uncaughtException, + utf_java_lang_Thread_java_lang_Throwable__V, + NULL, + true); if (m == NULL) return false; - (void) vm_call_method(m, o, object, e); + (void) vm_call_method(m, h, object, e); if (exceptions_get_exception()) return false; @@ -1135,20 +1114,21 @@ bool thread_detach_current_thread(void) /* Remove thread from the thread group. */ if (group != NULL) { + classinfo* c; LLNI_class_get(group, c); # if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH) - m = class_resolveclassmethod(c, - utf_removeThread, - utf_java_lang_Thread__V, - class_java_lang_ThreadGroup, - true); + methodinfo* m = class_resolveclassmethod(c, + utf_removeThread, + utf_java_lang_Thread__V, + class_java_lang_ThreadGroup, + true); # elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK) - m = class_resolveclassmethod(c, - utf_remove, - utf_java_lang_Thread__V, - class_java_lang_ThreadGroup, - true); + methodinfo* m = class_resolveclassmethod(c, + utf_remove, + utf_java_lang_Thread__V, + class_java_lang_ThreadGroup, + true); # else # error unknown classpath configuration # endif @@ -1156,17 +1136,14 @@ bool thread_detach_current_thread(void) if (m == NULL) return false; - o = (java_handle_t *) group; - - (void) vm_call_method(m, o, object); + (void) vm_call_method(m, group, object); if (exceptions_get_exception()) return false; - /* Reset the threadgroup in the Java thread object (Mauve - test: gnu/testlet/java/lang/Thread/getThreadGroup). */ - - LLNI_field_set_ref(object, group, NULL); + // Clear the ThreadGroup in the Java thread object (Mauve + // test: gnu/testlet/java/lang/Thread/getThreadGroup). + jlt.set_group(NULL); } #endif @@ -1177,15 +1154,13 @@ bool thread_detach_current_thread(void) /* Notify all threads waiting on this thread. These are joining this thread. */ - o = (java_handle_t *) object; - /* XXX Care about exceptions? */ - (void) lock_monitor_enter(o); + (void) lock_monitor_enter(jlt.get_handle()); - lock_notify_all_object(o); + lock_notify_all_object(jlt.get_handle()); /* XXX Care about exceptions? */ - (void) lock_monitor_exit(o); + (void) lock_monitor_exit(jlt.get_handle()); /* Enter the join-mutex before calling thread_free, so threads_join_all_threads gets the correct number of non-daemon diff --git a/src/threads/thread.cpp b/src/threads/thread.cpp index 9011a6321..005080884 100644 --- a/src/threads/thread.cpp +++ b/src/threads/thread.cpp @@ -43,18 +43,6 @@ #include "native/llni.h" #include "native/native.h" -#include "native/include/java_lang_Object.h" -#include "native/include/java_lang_String.h" -#include "native/include/java_lang_Thread.h" - -#if defined(ENABLE_JAVASE) -# include "native/include/java_lang_ThreadGroup.h" -#endif - -#if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH) -# include "native/include/java_lang_VMThread.h" -#endif - #include "threads/lock-common.h" #include "threads/threadlist.h" #include "threads/thread.hpp" @@ -68,6 +56,7 @@ #include "vmcore/class.h" #include "vmcore/globals.hpp" +#include "vmcore/javaobjects.hpp" #include "vmcore/method.h" #include "vmcore/options.h" @@ -245,76 +234,58 @@ void threads_init(void) static bool thread_create_object(threadobject *t, java_handle_t *name, java_handle_t *group) { - java_handle_t *o; - java_lang_Thread *to; - -#if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH) - java_lang_VMThread *vmto; - classinfo *c; - methodinfo *m; - bool isdaemon; -#endif - /* Create a java.lang.Thread Java object. */ - o = builtin_new(class_java_lang_Thread); + java_handle_t* h = builtin_new(class_java_lang_Thread); - if (o == NULL) + if (h == NULL) return false; - to = (java_lang_Thread *) o; + java_lang_Thread jlt(h); - /* Set the Java object in the thread data-structure. This - indicates that the thread is attached to the VM. */ - - thread_set_object(t, (java_handle_t *) to); + // Set the Java object in the thread data-structure. This + // indicates that the thread is attached to the VM. + thread_set_object(t, jlt.get_handle()); #if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH) - /* Create a java.lang.VMThread Java object. */ - - vmto = (java_lang_VMThread *) builtin_new(class_java_lang_VMThread); + h = builtin_new(class_java_lang_VMThread); - if (vmto == NULL) + if (h == NULL) return false; - /* Set the Java thread object in the Java VM-thread object. */ - - LLNI_field_set_ref(vmto, thread, to); - - /* Set the thread data-structure in the Java VM-thread object. */ - - LLNI_field_set_val(vmto, vmdata, (java_lang_Object *) t); + // Create and initialize a java.lang.VMThread object. + java_lang_VMThread jlvmt(h, jlt.get_handle(), t); /* Call: java.lang.Thread.(Ljava/lang/VMThread;Ljava/lang/String;IZ)V */ - isdaemon = thread_is_daemon(t); + bool isdaemon = thread_is_daemon(t); - (void) vm_call_method(thread_method_init, o, vmto, name, NORM_PRIORITY, - isdaemon); + (void) vm_call_method(thread_method_init, jlt.get_handle(), jlvmt.get_handle(), + name, NORM_PRIORITY, isdaemon); if (exceptions_get_exception()) return false; - /* Set the threadgroup in the Java thread object. */ - - LLNI_field_set_ref(to, group, (java_lang_ThreadGroup *) group); + // Set the ThreadGroup in the Java thread object. + jlt.set_group(group); /* Add thread to the threadgroup. */ + classinfo* c; LLNI_class_get(group, c); - m = class_resolveclassmethod(c, - utf_addThread, - utf_java_lang_Thread__V, - class_java_lang_ThreadGroup, - true); + methodinfo* m = class_resolveclassmethod(c, + utf_addThread, + utf_java_lang_Thread__V, + class_java_lang_ThreadGroup, + true); if (m == NULL) return false; - (void) vm_call_method(m, group, to); + (void) vm_call_method(m, group, jlt.get_handle()); if (exceptions_get_exception()) return false; @@ -664,13 +635,7 @@ bool threads_thread_start_internal(utf *name, functionptr f) void threads_thread_start(java_handle_t *object) { - java_lang_Thread *to; - threadobject *t; -#if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH) - java_lang_VMThread *vmto; -#endif - - to = (java_lang_Thread *) object; + java_lang_Thread jlt(object); /* Enter the join-mutex, so if the main-thread is currently waiting to join all threads, the number of non-daemon threads @@ -680,7 +645,7 @@ void threads_thread_start(java_handle_t *object) /* Create internal thread data-structure. */ - t = thread_new(); + threadobject* t = thread_new(); /* this is a normal Java thread */ @@ -689,7 +654,7 @@ void threads_thread_start(java_handle_t *object) #if defined(ENABLE_JAVASE) /* Is this a daemon thread? */ - if (LLNI_field_direct(to, daemon) == true) + if (jlt.get_daemon() == true) t->flags |= THREAD_FLAG_DAEMON; #endif @@ -705,13 +670,12 @@ void threads_thread_start(java_handle_t *object) #if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH) /* Get the java.lang.VMThread object and do some sanity checks. */ + java_lang_VMThread jlvmt(jlt.get_vmThread()); - LLNI_field_get_ref(to, vmThread, vmto); - - assert(vmto); - assert(LLNI_field_direct(vmto, vmdata) == NULL); + assert(jlvmt.get_handle() != NULL); + assert(jlvmt.get_vmdata() == NULL); - LLNI_field_set_val(vmto, vmdata, (java_lang_Object *) t); + jlvmt.set_vmdata(t); #elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK) @@ -919,28 +883,21 @@ bool thread_detach_current_external_thread(void) void thread_fprint_name(threadobject *t, FILE *stream) { - java_lang_Thread *to; - -#if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH) - java_lang_String *name; -#elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK) || defined(WITH_JAVA_RUNTIME_LIBRARY_CLDC1_1) - java_chararray_t *name; -#endif - - to = (java_lang_Thread *) thread_get_object(t); - - if (to == NULL) + if (thread_get_object(t) == NULL) vm_abort(""); - LLNI_field_get_ref(to, name, name); + java_lang_Thread jlt(thread_get_object(t)); #if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH) - javastring_fprint((java_handle_t *) name, stream); + java_handle_t* name = jlt.get_name(); + javastring_fprint(name, stream); #elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK) || defined(WITH_JAVA_RUNTIME_LIBRARY_CLDC1_1) /* FIXME: In OpenJDK and CLDC the name is a char[]. */ + java_chararray_t *name; + /* FIXME This prints to stdout. */ utf_display_printable_ascii(utf_null); @@ -961,16 +918,11 @@ void thread_fprint_name(threadobject *t, FILE *stream) void thread_print_info(threadobject *t) { - java_lang_Thread *to; - int state; - - /* If the thread is currently in initalization, don't print it. */ - - to = (java_lang_Thread *) thread_get_object(t); + java_lang_Thread jlt(thread_get_object(t)); /* Print as much as we can when we are in state NEW. */ - if (to != NULL) { + if (jlt.get_handle() != NULL) { /* Print thread name. */ printf("\""); @@ -983,8 +935,8 @@ void thread_print_info(threadobject *t) if (thread_is_daemon(t)) printf(" daemon"); - if (to != NULL) { - printf(" prio=%d", LLNI_field_direct(to, priority)); + if (jlt.get_handle() != NULL) { + printf(" prio=%d", jlt.get_priority()); } #if SIZEOF_VOID_P == 8 @@ -999,7 +951,7 @@ void thread_print_info(threadobject *t) /* Print thread state. */ - state = cacaothread_get_state(t); + int state = cacaothread_get_state(t); switch (state) { case THREAD_STATE_NEW: @@ -1161,26 +1113,16 @@ void thread_set_state_terminated(threadobject *t) threadobject *thread_get_thread(java_handle_t *h) { - threadobject *t; -#if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH) - java_lang_VMThread *vmto; - java_lang_Object *to; -#endif -#if defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK) - bool equal; -#endif - #if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH) - vmto = (java_lang_VMThread *) h; - - LLNI_field_get_val(vmto, vmdata, to); - - t = (threadobject *) to; + java_lang_VMThread jlvmt(h); + threadobject* t = jlvmt.get_vmdata(); #elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK) /* XXX This is just a quick hack. */ + threadobject* t; + bool equal; threadlist_lock(); diff --git a/src/vm/exceptions.cpp b/src/vm/exceptions.cpp index ec712c6f2..521b2db93 100644 --- a/src/vm/exceptions.cpp +++ b/src/vm/exceptions.cpp @@ -1,4 +1,4 @@ -/* src/vm/exceptions.c - exception related functions +/* src/vm/exceptions.cpp - exception related functions Copyright (C) 1996-2005, 2006, 2007, 2008 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO @@ -41,10 +41,6 @@ #include "native/llni.h" #include "native/native.h" -#include "native/include/java_lang_String.h" -#include "native/include/java_lang_Thread.h" -#include "native/include/java_lang_Throwable.h" - #include "threads/lock-common.h" #include "threads/thread.hpp" @@ -66,6 +62,7 @@ #include "vmcore/class.h" #include "vmcore/globals.hpp" +#include "vmcore/javaobjects.hpp" #include "vmcore/loader.h" #include "vmcore/method.h" #include "vmcore/options.h" @@ -457,14 +454,12 @@ static void exceptions_throw_utf_throwable(utf *classname, java_handle_t *cause) { classinfo *c; - java_handle_t *o; methodinfo *m; - java_lang_Throwable *object; if (vm->is_initializing()) exceptions_abort(classname, NULL); - object = (java_lang_Throwable *) cause; + java_lang_Throwable jlt(cause); c = load_class_bootstrap(classname); @@ -473,9 +468,9 @@ static void exceptions_throw_utf_throwable(utf *classname, /* create object */ - o = builtin_new(c); - - if (o == NULL) + java_handle_t* h = builtin_new(c); + + if (h == NULL) return; /* call initializer */ @@ -489,9 +484,9 @@ static void exceptions_throw_utf_throwable(utf *classname, if (m == NULL) return; - (void) vm_call_method(m, o, cause); + (void) vm_call_method(m, h, jlt.get_handle()); - exceptions_set_exception(o); + exceptions_set_exception(h); } @@ -558,43 +553,35 @@ static void exceptions_throw_utf_exception(utf *classname, static void exceptions_throw_utf_cause(utf *classname, java_handle_t *cause) { - classinfo *c; - java_handle_t *o; - methodinfo *m; - java_lang_String *s; - java_lang_Throwable *object; - if (vm->is_initializing()) exceptions_abort(classname, NULL); - object = (java_lang_Throwable *) cause; + java_lang_Throwable jltcause(cause); - c = load_class_bootstrap(classname); + classinfo* c = load_class_bootstrap(classname); if (c == NULL) return; /* create object */ - o = builtin_new(c); + java_handle_t* h = builtin_new(c); - if (o == NULL) + if (h == NULL) return; /* call initializer */ - m = class_resolveclassmethod(c, - utf_init, - utf_java_lang_String__void, - NULL, - true); + methodinfo* m = class_resolveclassmethod(c, + utf_init, + utf_java_lang_String__void, + NULL, + true); if (m == NULL) return; - LLNI_field_get_ref(object, detailMessage, s); - - (void) vm_call_method(m, o, s); + (void) vm_call_method(m, h, jltcause.get_detailMessage()); /* call initCause */ @@ -607,9 +594,9 @@ static void exceptions_throw_utf_cause(utf *classname, java_handle_t *cause) if (m == NULL) return; - (void) vm_call_method(m, o, cause); + (void) vm_call_method(m, h, jltcause.get_handle()); - exceptions_set_exception(o); + exceptions_set_exception(h); } @@ -1906,34 +1893,26 @@ exceptions_handle_exception_return: void exceptions_print_exception(java_handle_t *xptr) { - java_lang_Throwable *t; -#if defined(ENABLE_JAVASE) - java_lang_Throwable *cause; -#endif - java_lang_String *s; - classinfo *c; - utf *u; - - t = (java_lang_Throwable *) xptr; + java_lang_Throwable jlt(xptr); - if (t == NULL) { + if (jlt.is_null()) { puts("NULL\n"); return; } #if defined(ENABLE_JAVASE) - LLNI_field_get_ref(t, cause, cause); + java_lang_Throwable jltcause(jlt.get_cause()); #endif /* print the root exception */ - LLNI_class_get(t, c); + classinfo* c = jlt.get_Class(); utf_display_printable_ascii_classname(c->name); - LLNI_field_get_ref(t, detailMessage, s); + java_lang_String jls(jlt.get_detailMessage()); - if (s != NULL) { - u = javastring_toutf((java_handle_t *) s, false); + if (!jls.is_null()) { + utf* u = javastring_toutf(jls.get_handle(), false); printf(": "); utf_display_printable_ascii(u); @@ -1944,16 +1923,17 @@ void exceptions_print_exception(java_handle_t *xptr) #if defined(ENABLE_JAVASE) /* print the cause if available */ - if ((cause != NULL) && (cause != t)) { + // FIXME cause != t compare with operator override. + if ((!jltcause.is_null()) && (jltcause.get_handle() != jlt.get_handle())) { printf("Caused by: "); - - LLNI_class_get(cause, c); + + c = jltcause.get_Class(); utf_display_printable_ascii_classname(c->name); - LLNI_field_get_ref(cause, detailMessage, s); + java_lang_String jlscause(jlt.get_detailMessage()); - if (s != NULL) { - u = javastring_toutf((java_handle_t *) s, false); + if (jlscause.get_handle() != NULL) { + utf* u = javastring_toutf(jlscause.get_handle(), false); printf(": "); utf_display_printable_ascii(u); diff --git a/src/vm/jit/codegen-common.c b/src/vm/jit/codegen-common.c index c9552b81b..1c51ebb96 100644 --- a/src/vm/jit/codegen-common.c +++ b/src/vm/jit/codegen-common.c @@ -62,19 +62,6 @@ #include "native/localref.h" #include "native/native.h" -#if defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK) -# include "native/include/java_lang_Object.h" -# include "native/include/java_lang_String.h" /* required by j.l.CL */ -# include "native/include/java_nio_ByteBuffer.h" /* required by j.l.CL */ -# include "native/include/java_lang_ClassLoader.h" -#endif - -#if defined(WITH_JAVA_RUNTIME_LIBRARY_CLDC1_1) -# include "native/include/java_lang_String.h" -#endif - -#include "native/include/java_lang_Class.h" - #include "threads/thread.hpp" #include "vm/builtin.h" diff --git a/src/vm/jit/stacktrace.cpp b/src/vm/jit/stacktrace.cpp index f1ac6c92e..768cb6758 100644 --- a/src/vm/jit/stacktrace.cpp +++ b/src/vm/jit/stacktrace.cpp @@ -43,14 +43,6 @@ #include "native/jni.h" #include "native/llni.h" -#include "native/include/java_lang_Object.h" -#include "native/include/java_lang_Throwable.h" - -#if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH) -# include "native/include/gnu_classpath_Pointer.h" -# include "native/include/java_lang_VMThrowable.h" -#endif - #include "threads/thread.hpp" #include "toolbox/logging.h" @@ -70,6 +62,7 @@ #include "vmcore/class.h" #include "vmcore/globals.hpp" +#include "vmcore/javaobjects.hpp" #include "vmcore/loader.h" #include "vmcore/method.h" #include "vmcore/options.h" @@ -1256,27 +1249,17 @@ void stacktrace_print_of_thread(threadobject *t) void stacktrace_print_exception(java_handle_t *h) { - java_lang_Throwable *o; - -#if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH) - java_lang_VMThrowable *vmt; -#endif - - java_lang_Object *backtrace; - java_handle_bytearray_t *ba; - stacktrace_t *st; - - o = (java_lang_Throwable *) h; - - if (o == NULL) + if (h == NULL) return; + java_lang_Throwable t(h); + /* now print the stacktrace */ #if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH) - LLNI_field_get_ref(o, vmState, vmt); - LLNI_field_get_ref(vmt, vmdata, backtrace); + java_lang_VMThrowable vmt(t.get_vmState()); + java_handle_bytearray_t* backtrace = vmt.get_vmdata(); #elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK) || defined(WITH_JAVA_RUNTIME_LIBRARY_CLDC1_1) @@ -1286,18 +1269,16 @@ void stacktrace_print_exception(java_handle_t *h) # error unknown classpath configuration #endif - ba = (java_handle_bytearray_t *) backtrace; - - /* Sanity check. */ + // Sanity check. - assert(ba != NULL); + assert(backtrace != NULL); /* We need a critical section here as we use the byte-array data pointer directly. */ LLNI_CRITICAL_START; - st = (stacktrace_t *) LLNI_array_data(ba); + stacktrace_t* st = (stacktrace_t*) LLNI_array_data(backtrace); stacktrace_print(st); diff --git a/src/vm/jit/trace.cpp b/src/vm/jit/trace.cpp index b2c877702..f596ed848 100644 --- a/src/vm/jit/trace.cpp +++ b/src/vm/jit/trace.cpp @@ -23,9 +23,6 @@ */ -// FIXME For now we export everything as C functions. -extern "C" { - #include "config.h" #include @@ -38,9 +35,6 @@ extern "C" { #include "native/jni.h" #include "native/llni.h" -#include "native/include/java_lang_String.h" -#include "native/include/java_lang_Throwable.h" - #include "threads/thread.hpp" #include "toolbox/logging.h" @@ -53,12 +47,15 @@ extern "C" { #include "vm/jit/show.h" #include "vmcore/globals.hpp" +#include "vmcore/javaobjects.hpp" #include "vmcore/options.h" #include "vmcore/utf8.h" #if !defined(NDEBUG) +// FIXME For now we export everything as C functions. +extern "C" { /* global variables ***********************************************************/ @@ -566,32 +563,33 @@ void trace_exception(java_object_t *xptr, methodinfo *m, void *pos) *******************************************************************************/ -void trace_exception_builtin(java_object_t *xptr) +void trace_exception_builtin(java_handle_t* h) { - java_lang_Throwable *t; - java_lang_String *s; char *logtext; s4 logtextlen; int32_t dumpmarker; - t = (java_lang_Throwable *) xptr; + java_lang_Throwable jlt(h); + + // Get detail message. + java_handle_t* s = NULL; + + if (jlt.get_handle() != NULL) + s = jlt.get_detailMessage(); - /* get detail message */ - if (t) - LLNI_field_get_ref(t, detailMessage, s); + java_lang_String jls(s); /* calculate message length */ logtextlen = strlen("Builtin exception thrown: ") + strlen("0"); - if (t) { - logtextlen += - utf_bytes(xptr->vftbl->clazz->name); - if (s) { + if (jlt.get_handle() != NULL) { + logtextlen += utf_bytes(jlt.get_vftbl()->clazz->name); + + if (jls.get_handle()) { + // FIXME This is not handle capable! logtextlen += strlen(": ") + - u2_utflength(LLNI_field_direct(s, value)->data - + LLNI_field_direct(s, offset), - LLNI_field_direct(s,count)); + u2_utflength(jls.get_value()->data + jls.get_offset(), jls.get_count()); } } else { @@ -606,13 +604,13 @@ void trace_exception_builtin(java_object_t *xptr) strcpy(logtext, "Builtin exception thrown: "); - if (t) { - utf_cat_classname(logtext, xptr->vftbl->clazz->name); + if (jlt.get_handle()) { + utf_cat_classname(logtext, jlt.get_vftbl()->clazz->name); if (s) { char *buf; - buf = javastring_tochar((java_handle_t *) s); + buf = javastring_tochar(jls.get_handle()); strcat(logtext, ": "); strcat(logtext, buf); MFREE(buf, char, strlen(buf) + 1); @@ -629,10 +627,10 @@ void trace_exception_builtin(java_object_t *xptr) DRELEASE; } -#endif /* !defined(NDEBUG) */ - } // extern "C" +#endif /* !defined(NDEBUG) */ + /* * These are local overrides for various environment variables in Emacs. diff --git a/src/vm/jit/trace.hpp b/src/vm/jit/trace.hpp index c382678ff..b7aa39d2f 100644 --- a/src/vm/jit/trace.hpp +++ b/src/vm/jit/trace.hpp @@ -26,11 +26,6 @@ #ifndef _VM_JIT_TRACE_HPP #define _VM_JIT_TRACE_HPP -// FIXME For now we export everything as C functions. -#ifdef __cplusplus -extern "C" { -#endif - #include "config.h" #include @@ -39,18 +34,24 @@ extern "C" { #if !defined(NDEBUG) +// FIXME For now we export everything as C functions. +#ifdef __cplusplus +extern "C" { +#endif + + void trace_java_call_enter(methodinfo *m, uint64_t *arg_regs, uint64_t *stack); void trace_java_call_exit(methodinfo *m, uint64_t *return_regs); void trace_exception(java_object_t *xptr, methodinfo *m, void *pos); void trace_exception_builtin(java_object_t *xptr); -#endif /* !defined(NDEBUG) */ - #ifdef __cplusplus } #endif +#endif /* !defined(NDEBUG) */ + #endif // _VM_JIT_TRACE_HPP diff --git a/src/vm/package.cpp b/src/vm/package.cpp index c0513bee1..ef293f6b5 100644 --- a/src/vm/package.cpp +++ b/src/vm/package.cpp @@ -33,8 +33,6 @@ #include "native/jni.h" -#include "native/include/java_lang_String.h" - #include "vm/package.hpp" #include "vm/string.hpp" diff --git a/src/vm/primitive.cpp b/src/vm/primitive.cpp index 1fe9e6d0b..12d66e4e8 100644 --- a/src/vm/primitive.cpp +++ b/src/vm/primitive.cpp @@ -31,15 +31,6 @@ #include "native/jni.h" #include "native/llni.h" -#include "native/include/java_lang_Boolean.h" -#include "native/include/java_lang_Byte.h" -#include "native/include/java_lang_Short.h" -#include "native/include/java_lang_Character.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 "vm/builtin.h" #include "vm/global.h" #include "vm/primitive.hpp" @@ -47,6 +38,7 @@ #include "vmcore/class.h" #include "vmcore/globals.hpp" +#include "vmcore/javaobjects.hpp" #include "vmcore/utf8.h" @@ -304,67 +296,172 @@ imm_union Primitive::unbox(java_handle_t *h) } -/* primitive_box_xxx *********************************************************** - - Box a primitive type. - -*******************************************************************************/ - -#define PRIMITIVE_BOX_TYPE(name, object, type) \ -java_handle_t* Primitive::box(type value) \ -{ \ - java_handle_t *o; \ - java_lang_##object *jo; \ - \ - o = builtin_new(class_java_lang_##object); \ - \ - if (o == NULL) \ - return NULL; \ - \ - jo = (java_lang_##object *) o; \ - \ - LLNI_field_set_val(jo, value, value); \ - \ - return o; \ +/** + * Box a primitive type. + */ +java_handle_t* Primitive::box(uint8_t value) +{ + java_handle_t *h = builtin_new(class_java_lang_Boolean); + + if (h == NULL) + return NULL; + + java_lang_Boolean b(h); + b.set_value(value); + + return h; +} + +java_handle_t* Primitive::box(int8_t value) +{ + java_handle_t *h = builtin_new(class_java_lang_Byte); + + if (h == NULL) + return NULL; + + java_lang_Byte b(h); + b.set_value(value); + + return h; +} + +java_handle_t* Primitive::box(uint16_t value) +{ + java_handle_t *h = builtin_new(class_java_lang_Character); + + if (h == NULL) + return NULL; + + java_lang_Character c(h); + c.set_value(value); + + return h; +} + +java_handle_t* Primitive::box(int16_t value) +{ + java_handle_t *h = builtin_new(class_java_lang_Short); + + if (h == NULL) + return NULL; + + java_lang_Short s(h); + s.set_value(value); + + return h; +} + +java_handle_t* Primitive::box(int32_t value) +{ + java_handle_t *h = builtin_new(class_java_lang_Integer); + + if (h == NULL) + return NULL; + + java_lang_Integer i(h); + i.set_value(value); + + return h; +} + +java_handle_t* Primitive::box(int64_t value) +{ + java_handle_t *h = builtin_new(class_java_lang_Long); + + if (h == NULL) + return NULL; + + java_lang_Long l(h); + l.set_value(value); + + return h; } -PRIMITIVE_BOX_TYPE(boolean, Boolean, uint8_t) -PRIMITIVE_BOX_TYPE(byte, Byte, int8_t) -PRIMITIVE_BOX_TYPE(char, Character, uint16_t) -PRIMITIVE_BOX_TYPE(short, Short, int16_t) -PRIMITIVE_BOX_TYPE(int, Integer, int32_t) -PRIMITIVE_BOX_TYPE(long, Long, int64_t) -PRIMITIVE_BOX_TYPE(float, Float, float) -PRIMITIVE_BOX_TYPE(double, Double, double) - - -/* primitive_unbox_xxx ********************************************************* - - Unbox a primitive type. - -*******************************************************************************/ - -#define PRIMITIVE_UNBOX_TYPE(name, object, type) \ -type Primitive::unbox_##name(java_handle_t *h) \ -{ \ - java_lang_##object *jo; \ - type value; \ - \ - jo = (java_lang_##object *) h; \ - \ - LLNI_field_get_val(jo, value, value); \ - \ - return value; \ +java_handle_t* Primitive::box(float value) +{ + java_handle_t *h = builtin_new(class_java_lang_Float); + + if (h == NULL) + return NULL; + + java_lang_Float f(h); + f.set_value(value); + + return h; +} + +java_handle_t* Primitive::box(double value) +{ + java_handle_t *h = builtin_new(class_java_lang_Double); + + if (h == NULL) + return NULL; + + java_lang_Double d(h); + d.set_value(value); + + return h; +} + + + +/** + * Unbox a primitive type. + */ + +// template T Primitive::unbox(java_handle_t *h) +// { +// return java_lang_Boolean::get_value(h); +// } + +inline uint8_t Primitive::unbox_boolean(java_handle_t *h) +{ + java_lang_Boolean b(h); + return b.get_value(); +} + +inline int8_t Primitive::unbox_byte(java_handle_t *h) +{ + java_lang_Byte b(h); + return b.get_value(); +} + +inline uint16_t Primitive::unbox_char(java_handle_t *h) +{ + java_lang_Character c(h); + return c.get_value(); +} + +inline int16_t Primitive::unbox_short(java_handle_t *h) +{ + java_lang_Short s(h); + return s.get_value(); +} + +inline int32_t Primitive::unbox_int(java_handle_t *h) +{ + java_lang_Integer i(h); + return i.get_value(); +} + +inline int64_t Primitive::unbox_long(java_handle_t *h) +{ + java_lang_Long l(h); + return l.get_value(); +} + +inline float Primitive::unbox_float(java_handle_t *h) +{ + java_lang_Float f(h); + return f.get_value(); +} + +inline double Primitive::unbox_double(java_handle_t *h) +{ + java_lang_Double d(h); + return d.get_value(); } -PRIMITIVE_UNBOX_TYPE(boolean, Boolean, uint8_t) -PRIMITIVE_UNBOX_TYPE(byte, Byte, int8_t) -PRIMITIVE_UNBOX_TYPE(char, Character, uint16_t) -PRIMITIVE_UNBOX_TYPE(short, Short, int16_t) -PRIMITIVE_UNBOX_TYPE(int, Integer, int32_t) -PRIMITIVE_UNBOX_TYPE(long, Long, int64_t) -PRIMITIVE_UNBOX_TYPE(float, Float, float) -PRIMITIVE_UNBOX_TYPE(double, Double, double) // Legacy C interface. diff --git a/src/vm/properties.c b/src/vm/properties.c index e41b32132..599e05879 100644 --- a/src/vm/properties.c +++ b/src/vm/properties.c @@ -25,6 +25,7 @@ #include "config.h" +#include #include #include #include @@ -32,19 +33,15 @@ #include #include -#include "vm/types.h" - #include "mm/memory.h" #include "native/jni.h" #include "native/llni.h" -#include "vm/global.h" /* required by java_lang_String.h */ -#include "native/include/java_lang_String.h" - #include "toolbox/list.h" #include "toolbox/util.h" +#include "vm/global.h" #include "vm/properties.h" #include "vm/string.hpp" #include "vm/vm.hpp" diff --git a/src/vm/string.cpp b/src/vm/string.cpp index ee0b2c866..725879fb0 100644 --- a/src/vm/string.cpp +++ b/src/vm/string.cpp @@ -38,8 +38,6 @@ #include "native/jni.h" #include "native/llni.h" -#include "native/include/java_lang_String.h" - #include "threads/lock-common.h" #include "vm/array.h" @@ -50,6 +48,7 @@ #include "vm/vm.hpp" #include "vmcore/globals.hpp" +#include "vmcore/javaobjects.hpp" #include "vmcore/options.h" #include "vmcore/statistics.h" #include "vmcore/utf8.h" @@ -68,16 +67,6 @@ static java_object_t *lock_hashtable_string; #endif -/* XXX preliminary typedef, will be removed once string.c and utf8.c are - unified. */ - -#if defined(ENABLE_HANDLES) -typedef heap_java_lang_String heapstring_t; -#else -typedef java_lang_String heapstring_t; -#endif - - /* string_init ***************************************************************** Initialize the string hashtable lock. @@ -116,7 +105,6 @@ bool string_init(void) void stringtable_update(void) { - heapstring_t *js; java_chararray_t *a; literalstring *s; /* hashtable entry */ @@ -125,22 +113,22 @@ void stringtable_update(void) if (s) { while (s) { - js = (heapstring_t *) s->string; + // FIXME + java_lang_String js(LLNI_WRAP(s->string)); - if ((js == NULL) || (js->value == NULL)) { + if (js.is_null() || (js.get_value() == NULL)) { /* error in hashtable found */ vm_abort("stringtable_update: invalid literalstring in hashtable"); } - a = js->value; + a = LLNI_UNWRAP(js.get_value()); - if (!js->header.vftbl) - /* vftbl of javastring is NULL */ - js->header.vftbl = class_java_lang_String->vftbl; + if (js.get_vftbl() == NULL) + // FIXME + LLNI_UNWRAP(js.get_handle())->vftbl = class_java_lang_String->vftbl; - if (!a->header.objheader.vftbl) - /* vftbl of character-array is NULL */ + if (a->header.objheader.vftbl == NULL) a->header.objheader.vftbl = Primitive::get_arrayclass_by_type(ARRAYTYPE_CHAR)->vftbl; /* follow link in external hash chain */ @@ -166,44 +154,34 @@ void stringtable_update(void) *******************************************************************************/ -static java_handle_t *javastring_new_from_utf_buffer(const char *buffer, - u4 blength) +static java_handle_t *javastring_new_from_utf_buffer(const char *buffer, u4 blength) { const char *utf_ptr; /* current utf character in utf string */ - u4 utflength; /* length of utf-string if uncompressed */ - java_handle_t *o; - java_lang_String *s; /* result-string */ - java_handle_chararray_t *a; - u4 i; assert(buffer); - utflength = utf_get_number_of_u2s_for_buffer(buffer,blength); + int32_t utflength = utf_get_number_of_u2s_for_buffer(buffer, blength); - o = builtin_new(class_java_lang_String); - a = builtin_newarray_char(utflength); + java_handle_t* h = builtin_new(class_java_lang_String); + java_handle_chararray_t* ca = builtin_newarray_char(utflength); /* javastring or character-array could not be created */ - if ((o == NULL) || (a == NULL)) + if ((h == NULL) || (ca == NULL)) return NULL; /* decompress utf-string */ utf_ptr = buffer; - for (i = 0; i < utflength; i++) - LLNI_array_direct(a, i) = utf_nextu2((char **) &utf_ptr); + for (int32_t i = 0; i < utflength; i++) + LLNI_array_direct(ca, i) = utf_nextu2((char **) &utf_ptr); /* set fields of the javastring-object */ - s = (java_lang_String *) o; - - LLNI_field_set_ref(s, value , a); - LLNI_field_set_val(s, offset, 0); - LLNI_field_set_val(s, count , utflength); + java_lang_String jls(h, ca, utflength); - return o; + return jls.get_handle(); } @@ -224,47 +202,37 @@ static java_handle_t *javastring_new_from_utf_buffer(const char *buffer, java_handle_t *javastring_safe_new_from_utf8(const char *text) { - java_handle_t *o; - java_handle_chararray_t *a; - java_lang_String *s; - s4 nbytes; - s4 len; - if (text == NULL) return NULL; /* Get number of bytes. We need this to completely emulate the messy */ /* behaviour of the RI. :( */ - nbytes = strlen(text); + int32_t nbytes = strlen(text); /* calculate number of Java characters */ - len = utf8_safe_number_of_u2s(text, nbytes); + int32_t len = utf8_safe_number_of_u2s(text, nbytes); /* allocate the String object and the char array */ - o = builtin_new(class_java_lang_String); - a = builtin_newarray_char(len); + java_handle_t* h = builtin_new(class_java_lang_String); + java_handle_chararray_t* ca = builtin_newarray_char(len); /* javastring or character-array could not be created? */ - if ((o == NULL) || (a == NULL)) + if ((h == NULL) || (ca == NULL)) return NULL; /* decompress UTF-8 string */ - utf8_safe_convert_to_u2s(text, nbytes, LLNI_array_data(a)); + utf8_safe_convert_to_u2s(text, nbytes, LLNI_array_data(ca)); /* set fields of the String object */ - s = (java_lang_String *) o; - - LLNI_field_set_ref(s, value , a); - LLNI_field_set_val(s, offset, 0); - LLNI_field_set_val(s, count , len); + java_lang_String jls(h, ca, len); - return o; + return jls.get_handle(); } @@ -302,42 +270,32 @@ java_handle_t *javastring_new_from_utf_string(const char *utfstr) java_handle_t *javastring_new(utf *u) { - char *utf_ptr; /* current utf character in utf string */ - int32_t utflength; /* length of utf-string if uncompressed */ - java_handle_t *o; - java_handle_chararray_t *a; - java_lang_String *s; - if (u == NULL) { exceptions_throw_nullpointerexception(); return NULL; } - utf_ptr = u->text; - utflength = utf_get_number_of_u2s(u); + char* utf_ptr = u->text; + int32_t utflength = utf_get_number_of_u2s(u); - o = builtin_new(class_java_lang_String); - a = builtin_newarray_char(utflength); + java_handle_t* h = builtin_new(class_java_lang_String); + java_handle_chararray_t* ca = builtin_newarray_char(utflength); /* javastring or character-array could not be created */ - if ((o == NULL) || (a == NULL)) + if ((h == NULL) || (ca == NULL)) return NULL; /* decompress utf-string */ for (int32_t i = 0; i < utflength; i++) - LLNI_array_direct(a, i) = utf_nextu2(&utf_ptr); + LLNI_array_direct(ca, i) = utf_nextu2(&utf_ptr); /* set fields of the javastring-object */ - s = (java_lang_String *) o; - - LLNI_field_set_ref(s, value , a); - LLNI_field_set_val(s, offset, 0); - LLNI_field_set_val(s, count , utflength); + java_lang_String jls(h, ca, utflength); - return o; + return jls.get_handle(); } @@ -352,46 +310,37 @@ java_handle_t *javastring_new(utf *u) java_handle_t *javastring_new_slash_to_dot(utf *u) { - char *utf_ptr; /* current utf character in utf string */ - int32_t utflength; /* length of utf-string if uncompressed */ - java_handle_t *o; - java_handle_chararray_t *a; - java_lang_String *s; - u2 ch; - if (u == NULL) { exceptions_throw_nullpointerexception(); return NULL; } - utf_ptr = u->text; - utflength = utf_get_number_of_u2s(u); + char* utf_ptr = u->text; + int32_t utflength = utf_get_number_of_u2s(u); - o = builtin_new(class_java_lang_String); - a = builtin_newarray_char(utflength); + java_handle_t* h = builtin_new(class_java_lang_String); + java_handle_chararray_t* ca = builtin_newarray_char(utflength); /* javastring or character-array could not be created */ - if ((o == NULL) || (a == NULL)) + if ((h == NULL) || (ca == NULL)) return NULL; /* decompress utf-string */ for (int32_t i = 0; i < utflength; i++) { - ch = utf_nextu2(&utf_ptr); + uint16_t ch = utf_nextu2(&utf_ptr); + if (ch == '/') ch = '.'; - LLNI_array_direct(a, i) = ch; + + LLNI_array_direct(ca, i) = ch; } /* set fields of the javastring-object */ - s = (java_lang_String *) o; + java_lang_String jls(h, ca, utflength); - LLNI_field_set_ref(s, value , a); - LLNI_field_set_val(s, offset, 0); - LLNI_field_set_val(s, count , utflength); - - return o; + return jls.get_handle(); } @@ -411,41 +360,31 @@ java_handle_t *javastring_new_slash_to_dot(utf *u) java_handle_t *javastring_new_from_ascii(const char *text) { - s4 i; - s4 len; /* length of the string */ - java_handle_t *o; - java_lang_String *s; - java_handle_chararray_t *a; - if (text == NULL) { exceptions_throw_nullpointerexception(); return NULL; } - len = strlen(text); + int32_t len = strlen(text); - o = builtin_new(class_java_lang_String); - a = builtin_newarray_char(len); + java_handle_t* h = builtin_new(class_java_lang_String); + java_handle_chararray_t* ca = builtin_newarray_char(len); /* javastring or character-array could not be created */ - if ((o == NULL) || (a == NULL)) + if ((h == NULL) || (ca == NULL)) return NULL; /* copy text */ - for (i = 0; i < len; i++) - LLNI_array_direct(a, i) = text[i]; + for (int32_t i = 0; i < len; i++) + LLNI_array_direct(ca, i) = text[i]; /* set fields of the javastring-object */ - s = (java_lang_String *) o; - - LLNI_field_set_ref(s, value , a); - LLNI_field_set_val(s, offset, 0); - LLNI_field_set_val(s, count , len); + java_lang_String jls(h, ca, len); - return o; + return jls.get_handle(); } @@ -459,30 +398,26 @@ java_handle_t *javastring_new_from_ascii(const char *text) *******************************************************************************/ -char *javastring_tochar(java_handle_t *so) +char* javastring_tochar(java_handle_t* h) { - java_lang_String *s = (java_lang_String *) so; - java_handle_chararray_t *a; - int32_t count; - int32_t offset; - char *buf; - s4 i; - - if (!s) + java_lang_String jls(h); + + if (jls.is_null()) return (char*) ""; - LLNI_field_get_ref(s, value, a); + java_handle_chararray_t* ca = jls.get_value(); - if (!a) + if (ca == NULL) return (char*) ""; - LLNI_field_get_val(s, count, count); - LLNI_field_get_val(s, offset, offset); + int32_t count = jls.get_count(); + int32_t offset = jls.get_offset(); - buf = MNEW(char, count + 1); + char* buf = MNEW(char, count + 1); + int32_t i; for (i = 0; i < count; i++) - buf[i] = LLNI_array_direct(a, offset + i); + buf[i] = LLNI_array_direct(ca, offset + i); buf[i] = '\0'; @@ -498,23 +433,18 @@ char *javastring_tochar(java_handle_t *so) utf *javastring_toutf(java_handle_t *string, bool isclassname) { - java_lang_String *s; - java_handle_chararray_t *value; - int32_t count; - int32_t offset; + java_lang_String jls(string); - s = (java_lang_String *) string; - - if (s == NULL) + if (jls.is_null()) return utf_null; - LLNI_field_get_ref(s, value, value); + java_handle_chararray_t* value = jls.get_value(); - if (value == NULL) + if (jls.get_value() == NULL) return utf_null; - LLNI_field_get_val(s, count, count); - LLNI_field_get_val(s, offset, offset); + int32_t count = jls.get_count(); + int32_t offset = jls.get_offset(); return utf_new_u2(LLNI_array_data(value) + offset, count, isclassname); } @@ -533,7 +463,6 @@ static java_object_t *literalstring_u2(java_chararray_t *a, int32_t length, u4 offset, bool copymode) { literalstring *s; /* hashtable element */ - heapstring_t *js; /* u2-array wrapped in javastring */ java_chararray_t *ca; /* copy of u2-array */ u4 key; u4 slot; @@ -548,13 +477,16 @@ static java_object_t *literalstring_u2(java_chararray_t *a, int32_t length, s = (literalstring*) hashtable_string.ptr[slot]; while (s) { - js = (heapstring_t *) s->string; + // FIXME + java_lang_String js(LLNI_WRAP(s->string)); - if (length == js->count) { + if (length == js.get_count()) { /* compare text */ for (i = 0; i < length; i++) - if (a->data[offset + i] != js->value->data[i]) + // FIXME This is not handle capable! + + if (a->data[offset + i] != ((java_chararray_t*) LLNI_UNWRAP(js.get_value()))->data[i]) goto nomatch; /* string already in hashtable, free memory */ @@ -564,7 +496,7 @@ static java_object_t *literalstring_u2(java_chararray_t *a, int32_t length, LOCK_MONITOR_EXIT(lock_hashtable_string); - return (java_object_t *) js; + return (java_object_t*) LLNI_UNWRAP(js.get_handle()); } nomatch: @@ -579,8 +511,8 @@ static java_object_t *literalstring_u2(java_chararray_t *a, int32_t length, /* memcpy(ca, a, arraysize); */ memcpy(&(ca->header), &(a->header), sizeof(java_array_t)); memcpy(&(ca->data), &(a->data) + offset, sizeof(u2) * (length - 1) + 10); - - } else { + } + else { ca = a; } @@ -592,23 +524,24 @@ static java_object_t *literalstring_u2(java_chararray_t *a, int32_t length, assert(class_java_lang_String); assert(class_java_lang_String->state & CLASS_LOADED); - /* create new javastring */ - - js = NEW(heapstring_t); + // Create a new java.lang.String object on the system heap. + java_object_t* o = (java_object_t*) MNEW(uint8_t, class_java_lang_String->instancesize); + // FIXME + java_handle_t* h = LLNI_WRAP(o); #if defined(ENABLE_STATISTICS) if (opt_stat) - size_string += sizeof(heapstring_t); + size_string += sizeof(class_java_lang_String->instancesize); #endif #if defined(ENABLE_THREADS) - lock_init_object_lock(&js->header); + lock_init_object_lock(o); #endif - js->header.vftbl = class_java_lang_String->vftbl; - js->value = ca; - js->offset = 0; - js->count = length; + o->vftbl = class_java_lang_String->vftbl; + + // FIXME + java_lang_String jls(h, LLNI_WRAP(ca), length); /* create new literalstring */ @@ -620,7 +553,7 @@ static java_object_t *literalstring_u2(java_chararray_t *a, int32_t length, #endif s->hashlink = (literalstring*) hashtable_string.ptr[slot]; - s->string = (java_object_t *) js; + s->string = (java_object_t*) LLNI_UNWRAP(jls.get_handle()); hashtable_string.ptr[slot] = s; /* update number of hashtable entries */ @@ -636,7 +569,6 @@ static java_object_t *literalstring_u2(java_chararray_t *a, int32_t length, u4 i; literalstring *s; literalstring *nexts; - heapstring_t *tmpjs; hashtable newhash; /* the new hashtable */ /* create new hashtable, double the size */ @@ -651,8 +583,9 @@ static java_object_t *literalstring_u2(java_chararray_t *a, int32_t length, while (s) { nexts = s->hashlink; - tmpjs = (heapstring_t *) s->string; - slot = unicode_hashkey(tmpjs->value->data, tmpjs->count) & (newhash.size - 1); + java_lang_String tmpjls(LLNI_WRAP(s->string)); + // FIXME This is not handle capable! + slot = unicode_hashkey(((java_chararray_t*) LLNI_UNWRAP(tmpjls.get_value()))->data, tmpjls.get_count()) & (newhash.size - 1); s->hashlink = (literalstring*) newhash.ptr[slot]; newhash.ptr[slot] = s; @@ -670,7 +603,7 @@ static java_object_t *literalstring_u2(java_chararray_t *a, int32_t length, LOCK_MONITOR_EXIT(lock_hashtable_string); - return (java_object_t *) js; + return (java_object_t*) LLNI_UNWRAP(jls.get_handle()); } @@ -738,22 +671,18 @@ static void literalstring_free(java_object_t* string) *******************************************************************************/ -java_handle_t *javastring_intern(java_handle_t *s) +java_handle_t *javastring_intern(java_handle_t *string) { - java_lang_String *so; - java_chararray_t *value; - int32_t count; - int32_t offset; -/* java_lang_String *o; */ - java_object_t *o; /* XXX see note above */ + java_lang_String jls(string); - so = (java_lang_String *) s; + java_handle_chararray_t* value = jls.get_value(); + // FIXME + java_chararray_t* ca = LLNI_UNWRAP(value); /* XXX see note above */ - value = LLNI_field_direct(so, value); /* XXX see note above */ - LLNI_field_get_val(so, count, count); - LLNI_field_get_val(so, offset, offset); + int32_t count = jls.get_count(); + int32_t offset = jls.get_offset(); - o = literalstring_u2(value, count, offset, true); + java_object_t* o = literalstring_u2(ca, count, offset, true); /* XXX see note above */ return LLNI_WRAP(o); /* XXX see note above */ } @@ -767,21 +696,15 @@ java_handle_t *javastring_intern(java_handle_t *s) void javastring_fprint(java_handle_t *s, FILE *stream) { - java_lang_String *so; - java_handle_chararray_t *value; - int32_t count; - int32_t offset; - uint16_t c; - int i; + java_lang_String jls(s); - so = (java_lang_String *) s; + java_handle_chararray_t* value = jls.get_value(); - LLNI_field_get_ref(so, value, value); - LLNI_field_get_val(so, count, count); - LLNI_field_get_val(so, offset, offset); + int32_t count = jls.get_count(); + int32_t offset = jls.get_offset(); - for (i = offset; i < offset + count; i++) { - c = LLNI_array_direct(value, i); + for (int32_t i = offset; i < offset + count; i++) { + uint16_t c = LLNI_array_direct(value, i); fputc(c, stream); } } diff --git a/src/vm/vm.cpp b/src/vm/vm.cpp index 2000a5480..660f54544 100644 --- a/src/vm/vm.cpp +++ b/src/vm/vm.cpp @@ -49,16 +49,6 @@ #include "native/localref.h" #include "native/native.h" -#include "native/include/java_lang_Object.h" /* required by j.l.C */ -#include "native/include/java_lang_String.h" /* required by j.l.C */ - -#if defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK) -# include "native/include/java_nio_ByteBuffer.h" /* required by j.l.CL */ -# include "native/include/java_lang_ClassLoader.h" /* required by j.l.C */ -#endif - -#include "native/include/java_lang_Class.h" - #include "native/vm/nativevm.h" #include "threads/lock-common.h" @@ -820,8 +810,9 @@ VM::VM(JavaVMInitArgs* vm_args) is smaller or equal than the assumption made in src/vmcore/class.h. */ - if (sizeof(java_lang_Class) > sizeof(dummy_java_lang_Class)) - vm_abort("vm_create: java_lang_Class structure is bigger than classinfo.object (%d > %d)", sizeof(java_lang_Class), sizeof(dummy_java_lang_Class)); +#warning FIXME We need to check the size of java.lang.Class!!! +// if (sizeof(java_lang_Class) > sizeof(dummy_java_lang_Class)) +// vm_abort("vm_create: java_lang_Class structure is bigger than classinfo.object (%d > %d)", sizeof(java_lang_Class), sizeof(dummy_java_lang_Class)); /* set the VM starttime */ diff --git a/src/vmcore/Makefile.am b/src/vmcore/Makefile.am index 04900c22c..cdc732505 100644 --- a/src/vmcore/Makefile.am +++ b/src/vmcore/Makefile.am @@ -1,9 +1,7 @@ ## src/vmcore/Makefile.am ## -## Copyright (C) 2007 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 +## Copyright (C) 2007, 2008 +## CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO ## ## This file is part of CACAO. ## @@ -72,6 +70,8 @@ libvmcore_la_SOURCES = \ field.h \ globals.cpp \ globals.hpp \ + javaobjects.hpp \ + javaobjects.cpp \ linker.c \ linker.h \ loader.c \ diff --git a/src/vmcore/class.c b/src/vmcore/class.c index f08f784f5..bdbdb21a7 100644 --- a/src/vmcore/class.c +++ b/src/vmcore/class.c @@ -53,6 +53,7 @@ #include "vmcore/class.h" #include "vmcore/classcache.h" #include "vmcore/globals.hpp" +#include "vmcore/javaobjects.hpp" #include "vmcore/linker.h" #include "vmcore/loader.h" #include "vmcore/options.h" @@ -65,17 +66,6 @@ #include "vmcore/utf8.h" -#if defined(ENABLE_JAVASE) -/* We need to define some reflection functions here since we cannot - include native/vm/reflect.h as it includes generated header - files. */ - -java_object_t *reflect_constructor_new(methodinfo *m); -java_object_t *reflect_field_new(fieldinfo *f); -java_object_t *reflect_method_new(methodinfo *m); -#endif - - /* class_set_packagename ******************************************************* Derive the package name from the class name and store it in the @@ -1716,12 +1706,9 @@ java_handle_objectarray_t *class_get_declaredconstructors(classinfo *c, bool pub if (((m->flags & ACC_PUBLIC) || (publicOnly == 0)) && (m->name == utf_init)) { - /* Create Constructor object. This is actualy a - java_lang_reflect_Constructor pointer, but we use a - java_handle_t here, because we don't have the header - available when building vmcore. */ + // Create a java.lang.reflect.Constructor object. - rc = reflect_constructor_new(m); + rc = java_lang_reflect_Constructor_create(m); /* Store object into array. */ @@ -1779,12 +1766,9 @@ java_handle_objectarray_t *class_get_declaredfields(classinfo *c, bool publicOnl f = &(c->fields[i]); if ((f->flags & ACC_PUBLIC) || (publicOnly == 0)) { - /* Create Field object. This is actualy a - java_lang_reflect_Field pointer, but we use a - java_handle_t here, because we don't have the header - available when building vmcore. */ + // Create a java.lang.reflect.Field object. - h = reflect_field_new(f); + h = java_lang_reflect_Field_create(f); /* Store object into array. */ @@ -1857,12 +1841,9 @@ java_handle_objectarray_t *class_get_declaredmethods(classinfo *c, bool publicOn if (((m->flags & ACC_PUBLIC) || (publicOnly == false)) && ((m->name != utf_init) && (m->name != utf_clinit)) && !(m->flags & ACC_MIRANDA)) { - /* Create method object. This is actualy a - java_lang_reflect_Method pointer, but we use a - java_handle_t here, because we don't have the header - available when building vmcore. */ + // Create java.lang.reflect.Method object. - h = reflect_method_new(m); + h = java_lang_reflect_Method_create(m); /* Store object into array. */ @@ -1979,9 +1960,9 @@ java_handle_t* class_get_enclosingconstructor(classinfo *c) if (m->name != utf_init) return NULL; - /* Create Constructor object. */ + // Create a java.lang.reflect.Constructor object. - rc = reflect_constructor_new(m); + rc = java_lang_reflect_Constructor_create(m); return rc; } @@ -2056,9 +2037,9 @@ java_handle_t* class_get_enclosingmethod(classinfo *c) if (m->name == utf_init) return NULL; - /* create java.lang.reflect.Method object */ + // Create a java.lang.reflect.Method object. - rm = reflect_method_new(m); + rm = java_lang_reflect_Method_create(m); return rm; } diff --git a/src/vmcore/javaobjects.cpp b/src/vmcore/javaobjects.cpp new file mode 100644 index 000000000..af8943eb1 --- /dev/null +++ b/src/vmcore/javaobjects.cpp @@ -0,0 +1,290 @@ +/* src/vmcore/javaobjects.cpp - functions to create and access Java objects + + Copyright (C) 2008 + CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO + + 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. + +*/ + + +#include "config.h" + +#include + +// REMOVEME +#include "native/vm/reflection.hpp" + +#include "vm/access.h" +#include "vm/builtin.h" +#include "vm/global.h" + +#include "vmcore/globals.hpp" +#include "vmcore/javaobjects.hpp" + + +/** + * Allocates a new java.lang.reflect.Constructor object and + * initializes the fields with the method passed. + */ +java_handle_t* java_lang_reflect_Constructor::create(methodinfo *m) +{ + java_handle_t* h; + + /* Allocate a java.lang.reflect.Constructor object. */ + + h = builtin_new(class_java_lang_reflect_Constructor); + + if (h == NULL) + return NULL; + + java_lang_reflect_Constructor rc(h); + +#if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH) + + /* Allocate a java.lang.reflect.VMConstructor object. */ + + h = builtin_new(class_java_lang_reflect_VMConstructor); + + if (h == NULL) + return NULL; + + java_lang_reflect_VMConstructor rvmc(h, m); + + // Link the two Java objects. + + rc.set_cons(rvmc.get_handle()); + rvmc.set_cons(rc.get_handle()); + +#elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK) + + /* Calculate the slot. */ + + int slot = m - m->clazz->methods; + + /* Set Java object instance fields. */ + + LLNI_field_set_cls(rc, clazz , m->clazz); + LLNI_field_set_ref(rc, parameterTypes , method_get_parametertypearray(m)); + LLNI_field_set_ref(rc, exceptionTypes , method_get_exceptionarray(m)); + LLNI_field_set_val(rc, modifiers , m->flags & ACC_CLASS_REFLECT_MASK); + LLNI_field_set_val(rc, slot , slot); + LLNI_field_set_ref(rc, signature , m->signature ? (java_lang_String *) javastring_new(m->signature) : NULL); + LLNI_field_set_ref(rc, annotations , method_get_annotations(m)); + LLNI_field_set_ref(rc, parameterAnnotations, method_get_parameterannotations(m)); + +#else +# error unknown classpath configuration +#endif + + return rc.get_handle(); +} + + +/** + * Constructs a Java object with the given + * java.lang.reflect.Constructor. + * + * @param m Method structure of the constructor. + * @param args Constructor arguments. + * @param override Override security checks. + * + * @return Handle to Java object. + */ +java_handle_t* java_lang_reflect_Constructor::new_instance(methodinfo* m, java_handle_objectarray_t* args, bool override) +{ + java_handle_t* h; + + // Should we bypass security the checks (AccessibleObject)? + if (override == false) { + /* This method is always called like this: + [0] java.lang.reflect.Constructor.constructNative (Native Method) + [1] java.lang.reflect.Constructor.newInstance + [2] + */ + + if (!access_check_method(m, 2)) + return NULL; + } + + // Create a Java object. + h = builtin_new(m->clazz); + + if (h == NULL) + return NULL; + + // Call initializer. + (void) Reflection::invoke(m, h, args); + + return h; +} + + +/** + * Creates a java.lang.reflect.Field object on the GC heap and + * intializes it with the given field. + * + * @param f Field structure. + * + * @return Handle to Java object. + */ +java_handle_t* java_lang_reflect_Field::create(fieldinfo* f) +{ + java_handle_t* h; + + /* Allocate a java.lang.reflect.Field object. */ + + h = builtin_new(class_java_lang_reflect_Field); + + if (h == NULL) + return NULL; + + java_lang_reflect_Field rf(h); + +#if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH) + + // Allocate a java.lang.reflect.VMField object. + + h = builtin_new(class_java_lang_reflect_VMField); + + if (h == NULL) + return NULL; + + java_lang_reflect_VMField rvmf(h, f); + + // Link the two Java objects. + + rf.set_f(rvmf.get_handle()); + rvmf.set_f(rf.get_handle()); + +#elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK) + + /* Calculate the slot. */ + + int slot = f - f->clazz->fields; + + /* Set the Java object fields. */ + + LLNI_field_set_cls(rf, clazz, f->clazz); + + /* The name needs to be interned */ + /* XXX implement me better! */ + + LLNI_field_set_ref(rf, name, (java_lang_String *) javastring_intern(javastring_new(f->name))); + LLNI_field_set_cls(rf, type, (java_lang_Class *) field_get_type(f)); + LLNI_field_set_val(rf, modifiers, f->flags); + LLNI_field_set_val(rf, slot, slot); + LLNI_field_set_ref(rf, signature, f->signature ? (java_lang_String *) javastring_new(f->signature) : NULL); + LLNI_field_set_ref(rf, annotations, field_get_annotations(f)); + +#else +# error unknown classpath configuration +#endif + + return rf.get_handle(); +} + + +/* + * Allocates a new java.lang.reflect.Method object and initializes the + * fields with the method passed. + * + * @param m Method structure. + * + * @return Handle to Java object. + */ +java_handle_t* java_lang_reflect_Method::create(methodinfo *m) +{ + java_handle_t* h; + + /* Allocate a java.lang.reflect.Method object. */ + + h = builtin_new(class_java_lang_reflect_Method); + + if (h == NULL) + return NULL; + + java_lang_reflect_Method rm(h); + +#if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH) + + /* Allocate a java.lang.reflect.VMMethod object. */ + + h = builtin_new(class_java_lang_reflect_VMMethod); + + if (h == NULL) + return NULL; + + java_lang_reflect_VMMethod rvmm(h, m); + + // Link the two Java objects. + + rm.set_m(rvmm.get_handle()); + rvmm.set_m(rm.get_handle()); + +#elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK) + + /* Calculate the slot. */ + + int slot = m - m->clazz->methods; + + LLNI_field_set_cls(rm, clazz, m->clazz); + + /* The name needs to be interned */ + /* XXX implement me better! */ + + LLNI_field_set_ref(rm, name, (java_lang_String *) javastring_intern(javastring_new(m->name))); + LLNI_field_set_ref(rm, parameterTypes, method_get_parametertypearray(m)); + LLNI_field_set_cls(rm, returnType, (java_lang_Class *) method_returntype_get(m)); + LLNI_field_set_ref(rm, exceptionTypes, method_get_exceptionarray(m)); + LLNI_field_set_val(rm, modifiers, m->flags & ACC_CLASS_REFLECT_MASK); + LLNI_field_set_val(rm, slot, slot); + LLNI_field_set_ref(rm, signature, m->signature ? (java_lang_String *) javastring_new(m->signature) : NULL); + LLNI_field_set_ref(rm, annotations, method_get_annotations(m)); + LLNI_field_set_ref(rm, parameterAnnotations, method_get_parameterannotations(m)); + LLNI_field_set_ref(rm, annotationDefault, method_get_annotationdefault(m)); + +#else +# error unknown classpath configuration +#endif + + return rm.get_handle(); +} + + +// Legacy C interface. + +extern "C" { +java_handle_t* java_lang_reflect_Constructor_create(methodinfo* m) { return java_lang_reflect_Constructor::create(m); } +java_handle_t* java_lang_reflect_Field_create(fieldinfo* f) { return java_lang_reflect_Field::create(f); } +java_handle_t* java_lang_reflect_Method_create(methodinfo* m) { return java_lang_reflect_Method::create(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: + */ diff --git a/src/vmcore/javaobjects.hpp b/src/vmcore/javaobjects.hpp new file mode 100644 index 000000000..dadae2ab7 --- /dev/null +++ b/src/vmcore/javaobjects.hpp @@ -0,0 +1,1723 @@ +/* src/vmcore/javaobjects.hpp - functions to create and access Java objects + + Copyright (C) 2008 + CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO + + 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. + +*/ + + +#ifndef _JAVAOBJECTS_HPP +#define _JAVAOBJECTS_HPP + +#include "config.h" + +#include + +#include "native/llni.h" + +#include "vm/global.h" + +#include "vmcore/field.h" +#include "vmcore/method.h" + + +#ifdef __cplusplus + +/** + * This class provides low-level functions to access Java object + * instance fields. + * + * These functions do NOT take care about the GC critical section! + * Please use FieldAccess wherever possible. + */ +class RawFieldAccess { +protected: + template static inline T raw_get(void* address, const off_t offset); + template static inline void raw_set(void* address, const off_t offset, T value); +}; + + +template inline T RawFieldAccess::raw_get(void* address, const off_t offset) +{ + T* p = (T*) (((uintptr_t) address) + offset); + return *p; +} + + +template inline void RawFieldAccess::raw_set(void* address, const off_t offset, T value) +{ + T* p = (T*) (((uintptr_t) address) + offset); + *p = value; +} + + +/** + * This classes provides functions to access Java object instance + * fields. These functions enter a critical GC section before + * accessing the Java object throught the handle and leave it + * afterwards. + */ +class FieldAccess : private RawFieldAccess { +protected: + template static inline T get(java_handle_t* h, const off_t offset); + template static inline void set(java_handle_t* h, const off_t offset, T value); +}; + +template inline T FieldAccess::get(java_handle_t* h, const off_t offset) +{ + java_object_t* o; + T result; + + // XXX Move this to a GC inline function, e.g. + // gc->enter_critical(); + LLNI_CRITICAL_START; + + // XXX This should be _handle->get_object(); + o = LLNI_UNWRAP(h); + + result = raw_get(o, offset); + + // XXX Move this to a GC inline function. + // gc->leave_critical(); + LLNI_CRITICAL_END; + + return result; +} + +template<> inline java_handle_t* FieldAccess::get(java_handle_t* h, const off_t offset) +{ + java_object_t* o; + java_object_t* result; + java_handle_t* hresult; + + // XXX Move this to a GC inline function, e.g. + // gc->enter_critical(); + LLNI_CRITICAL_START; + + // XXX This should be _handle->get_object(); + o = LLNI_UNWRAP(h); + + result = raw_get(o, offset); + + hresult = LLNI_WRAP(result); + + // XXX Move this to a GC inline function. + // gc->leave_critical(); + LLNI_CRITICAL_END; + + return result; +} + + +template inline void FieldAccess::set(java_handle_t* h, const off_t offset, T value) +{ + java_object_t* o; + + // XXX Move this to a GC inline function, e.g. + // gc->enter_critical(); + LLNI_CRITICAL_START; + + // XXX This should be h->get_object(); + o = LLNI_UNWRAP(h); + + raw_set(o, offset, value); + + // XXX Move this to a GC inline function. + // gc->leave_critical(); + LLNI_CRITICAL_END; +} + +template<> inline void FieldAccess::set(java_handle_t* h, const off_t offset, java_handle_t* value) +{ + java_object_t* o; + java_object_t* ovalue; + + // XXX Move this to a GC inline function, e.g. + // gc->enter_critical(); + LLNI_CRITICAL_START; + + // XXX This should be h->get_object(); + o = LLNI_UNWRAP(h); + ovalue = LLNI_UNWRAP(value); + + raw_set(o, offset, ovalue); + + // XXX Move this to a GC inline function. + // gc->leave_critical(); + LLNI_CRITICAL_END; +} + + +/** + * java/lang/Object + * + * Object layout: + * + * 0. object header + */ +class java_lang_Object { +protected: + // Handle of Java object. + java_handle_t* _handle; + +protected: + java_lang_Object(java_handle_t* h) : _handle(h) {} + java_lang_Object(jobject h) : _handle((java_handle_t*) h) {} + +public: + // Getters. + virtual inline java_handle_t* get_handle() const { return _handle; } + inline vftbl_t* get_vftbl () const; + inline classinfo* get_Class () const; + + inline bool is_null() const; +}; + + +inline vftbl_t* java_lang_Object::get_vftbl() const +{ + // XXX Move this to a GC inline function, e.g. + // gc->enter_critical(); + LLNI_CRITICAL_START; + + // XXX This should be h->get_object(); + java_object_t* o = LLNI_UNWRAP(_handle); + vftbl_t* vftbl = o->vftbl; + + // XXX Move this to a GC inline function. + // gc->leave_critical(); + LLNI_CRITICAL_END; + + return vftbl; +} + +inline classinfo* java_lang_Object::get_Class() const +{ + return get_vftbl()->clazz; +} + + +inline bool java_lang_Object::is_null() const +{ + return (_handle == NULL); +} + + +/** + * java/lang/Boolean + * + * Object layout: + * + * 0. object header + * 1. boolean value; + */ +class java_lang_Boolean : public java_lang_Object, private FieldAccess { +private: + // Static offsets of the object's instance fields. + // TODO These offsets need to be checked on VM startup. + static const off_t offset_value = sizeof(java_object_t); + +public: + java_lang_Boolean(java_handle_t* h) : java_lang_Object(h) {} + + inline uint8_t get_value(); + inline void set_value(uint8_t value); +}; + +inline uint8_t java_lang_Boolean::get_value() +{ + return get(_handle, offset_value); +} + +inline void java_lang_Boolean::set_value(uint8_t value) +{ + set(_handle, offset_value, (uint32_t) value); +} + + +/** + * java/lang/Byte + * + * Object layout: + * + * 0. object header + * 1. byte value; + */ +class java_lang_Byte : public java_lang_Object, private FieldAccess { +private: + // Static offsets of the object's instance fields. + // TODO These offsets need to be checked on VM startup. + static const off_t offset_value = sizeof(java_object_t); + +public: + java_lang_Byte(java_handle_t* h) : java_lang_Object(h) {} + + inline int8_t get_value(); + inline void set_value(int8_t value); +}; + +inline int8_t java_lang_Byte::get_value() +{ + return get(_handle, offset_value); +} + +inline void java_lang_Byte::set_value(int8_t value) +{ + set(_handle, offset_value, (int32_t) value); +} + + +/** + * java/lang/Character + * + * Object layout: + * + * 0. object header + * 1. char value; + */ +class java_lang_Character : public java_lang_Object, private FieldAccess { +private: + // Static offsets of the object's instance fields. + // TODO These offsets need to be checked on VM startup. + static const off_t offset_value = sizeof(java_object_t); + +public: + java_lang_Character(java_handle_t* h) : java_lang_Object(h) {} + + inline uint16_t get_value(); + inline void set_value(uint16_t value); +}; + +inline uint16_t java_lang_Character::get_value() +{ + return get(_handle, offset_value); +} + +inline void java_lang_Character::set_value(uint16_t value) +{ + set(_handle, offset_value, (uint32_t) value); +} + + +/** + * java/lang/Short + * + * Object layout: + * + * 0. object header + * 1. short value; + */ +class java_lang_Short : public java_lang_Object, private FieldAccess { +private: + // Static offsets of the object's instance fields. + // TODO These offsets need to be checked on VM startup. + static const off_t offset_value = sizeof(java_object_t); + +public: + java_lang_Short(java_handle_t* h) : java_lang_Object(h) {} + + inline int16_t get_value(); + inline void set_value(int16_t value); +}; + +inline int16_t java_lang_Short::get_value() +{ + return get(_handle, offset_value); +} + +inline void java_lang_Short::set_value(int16_t value) +{ + set(_handle, offset_value, (int32_t) value); +} + + +/** + * java/lang/Integer + * + * Object layout: + * + * 0. object header + * 1. int value; + */ +class java_lang_Integer : public java_lang_Object, private FieldAccess { +private: + // Static offsets of the object's instance fields. + // TODO These offsets need to be checked on VM startup. + static const off_t offset_value = sizeof(java_object_t); + +public: + java_lang_Integer(java_handle_t* h) : java_lang_Object(h) {} + + inline int32_t get_value(); + inline void set_value(int32_t value); +}; + +inline int32_t java_lang_Integer::get_value() +{ + return get(_handle, offset_value); +} + +inline void java_lang_Integer::set_value(int32_t value) +{ + set(_handle, offset_value, value); +} + + +/** + * java/lang/Long + * + * Object layout: + * + * 0. object header + * 1. long value; + */ +class java_lang_Long : public java_lang_Object, private FieldAccess { +private: + // Static offsets of the object's instance fields. + // TODO These offsets need to be checked on VM startup. + static const off_t offset_value = sizeof(java_object_t); + +public: + java_lang_Long(java_handle_t* h) : java_lang_Object(h) {} + + inline int64_t get_value(); + inline void set_value(int64_t value); +}; + +inline int64_t java_lang_Long::get_value() +{ + return get(_handle, offset_value); +} + +inline void java_lang_Long::set_value(int64_t value) +{ + set(_handle, offset_value, value); +} + + +/** + * java/lang/Float + * + * Object layout: + * + * 0. object header + * 1. float value; + */ +class java_lang_Float : public java_lang_Object, private FieldAccess { +private: + // Static offsets of the object's instance fields. + // TODO These offsets need to be checked on VM startup. + static const off_t offset_value = sizeof(java_object_t); + +public: + java_lang_Float(java_handle_t* h) : java_lang_Object(h) {} + + inline float get_value(); + inline void set_value(float value); +}; + +inline float java_lang_Float::get_value() +{ + return get(_handle, offset_value); +} + +inline void java_lang_Float::set_value(float value) +{ + set(_handle, offset_value, value); +} + + +/** + * java/lang/Double + * + * Object layout: + * + * 0. object header + * 1. double value; + */ +class java_lang_Double : public java_lang_Object, private FieldAccess { +private: + // Static offsets of the object's instance fields. + // TODO These offsets need to be checked on VM startup. + static const off_t offset_value = sizeof(java_object_t); + +public: + java_lang_Double(java_handle_t* h) : java_lang_Object(h) {} + + inline double get_value(); + inline void set_value(double value); +}; + +inline double java_lang_Double::get_value() +{ + return get(_handle, offset_value); +} + +inline void java_lang_Double::set_value(double value) +{ + set(_handle, offset_value, value); +} + + +#if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH) + +/** + * GNU Classpath java/lang/Class + * + * Object layout: + * + * 0. object header + * 1. java.lang.Object[] signers; + * 2. java.security.ProtectionDomain pd; + * 3. java.lang.Object vmdata; + * 4. java.lang.reflect.Constructor constructor; + */ +class java_lang_Class : public java_lang_Object, private FieldAccess { +private: + // Static offsets of the object's instance fields. + // TODO These offsets need to be checked on VM startup. + static const off_t offset_signers = sizeof(java_object_t); + static const off_t offset_pd = offset_signers + SIZEOF_VOID_P; + static const off_t offset_vmdata = offset_pd + SIZEOF_VOID_P; + static const off_t offset_constructor = offset_vmdata + SIZEOF_VOID_P; + +public: + java_lang_Class(java_handle_t* h) : java_lang_Object(h) {} + + // Setters. + inline void set_pd(java_handle_t* value); + inline void set_pd(jobject value); +}; + +inline void java_lang_Class::set_pd(java_handle_t* value) +{ + set(_handle, offset_pd, value); +} + +inline void java_lang_Class::set_pd(jobject value) +{ + set_pd((java_handle_t*) value); +} + + +/** + * GNU Classpath java/lang/StackTraceElement + * + * Object layout: + * + * 0. object header + * 1. java.lang.String fileName; + * 2. int lineNumber; + * 3. java.lang.String declaringClass; + * 4. java.lang.String methodName; + * 5. boolean isNative; + */ +class java_lang_StackTraceElement : public java_lang_Object, private FieldAccess { +private: + // Static offsets of the object's instance fields. + // TODO These offsets need to be checked on VM startup. + static const off_t offset_fileName = sizeof(java_object_t); + static const off_t offset_lineNumber = offset_fileName + SIZEOF_VOID_P; + static const off_t offset_declaringClass = offset_lineNumber + sizeof(int32_t) + 4; + static const off_t offset_methodName = offset_declaringClass + SIZEOF_VOID_P; + static const off_t offset_isNative = offset_methodName + SIZEOF_VOID_P; + +public: + java_lang_StackTraceElement(java_handle_t* h) : java_lang_Object(h) {} + java_lang_StackTraceElement(java_handle_t* h, java_handle_t* fileName, int32_t lineNumber, java_handle_t* declaringClass, java_handle_t* methodName, uint8_t isNative); +}; + +inline java_lang_StackTraceElement::java_lang_StackTraceElement(java_handle_t* h, java_handle_t* fileName, int32_t lineNumber, java_handle_t* declaringClass, java_handle_t* methodName, uint8_t isNative) : java_lang_Object(h) +{ + java_lang_StackTraceElement((java_handle_t*) h); + + set(_handle, offset_fileName, fileName); + set(_handle, offset_lineNumber, lineNumber); + set(_handle, offset_declaringClass, declaringClass); + set(_handle, offset_methodName, methodName); + set(_handle, offset_isNative, isNative); +} + + +/** + * GNU Classpath java/lang/String + * + * Object layout: + * + * 0. object header + * 1. char[] value; + * 2. int count; + * 3. int cachedHashCode; + * 4. int offset; + */ +class java_lang_String : public java_lang_Object, private FieldAccess { +private: + // Static offsets of the object's instance fields. + // TODO These offsets need to be checked on VM startup. + static const off_t offset_value = sizeof(java_object_t); + static const off_t offset_count = offset_value + SIZEOF_VOID_P; + static const off_t offset_cachedHashCode = offset_count + sizeof(int32_t); + static const off_t offset_offset = offset_cachedHashCode + sizeof(int32_t); + +public: + java_lang_String(java_handle_t* h) : java_lang_Object(h) {} + java_lang_String(jstring h); + java_lang_String(java_handle_t* h, java_handle_chararray_t* value, int32_t count, int32_t offset = 0); + + // Getters. + inline java_handle_chararray_t* get_value () const; + inline int32_t get_count () const; + inline int32_t get_offset() const; + + // Setters. + inline void set_value (java_handle_chararray_t* value); + inline void set_count (int32_t value); + inline void set_offset(int32_t value); +}; + +inline java_lang_String::java_lang_String(jstring h) : java_lang_Object(h) +{ + java_lang_String((java_handle_t*) h); +} + +inline java_lang_String::java_lang_String(java_handle_t* h, java_handle_chararray_t* value, int32_t count, int32_t offset) : java_lang_Object(h) +{ + set_value(value); + set_count(count); + set_offset(offset); +} + +inline java_handle_chararray_t* java_lang_String::get_value() const +{ + return get(_handle, offset_value); +} + +inline int32_t java_lang_String::get_count() const +{ + return get(_handle, offset_count); +} + +inline int32_t java_lang_String::get_offset() const +{ + return get(_handle, offset_offset); +} + +inline void java_lang_String::set_value(java_handle_chararray_t* value) +{ + set(_handle, offset_value, value); +} + +inline void java_lang_String::set_count(int32_t value) +{ + set(_handle, offset_count, value); +} + +inline void java_lang_String::set_offset(int32_t value) +{ + set(_handle, offset_offset, value); +} + + +/** + * GNU Classpath java/lang/Thread + * + * Object layout: + * + * 0. object header + * 1. java.lang.VMThread vmThread; + * 2. java.lang.ThreadGroup group; + * 3. java.lang.Runnable runnable; + * 4. java.lang.String name; + * 5. boolean daemon; + * 6. int priority; + * 7. long stacksize; + * 8. java.lang.Throwable stillborn; + * 9. java.lang.ClassLoader contextClassLoader; + * 10. boolean contextClassLoaderIsSystemClassLoader; + * 11. long threadId; + * 12. java.lang.Object parkBlocker; + * 13. gnu.java.util.WeakIdentityHashMap locals; + * 14. java_lang_Thread_UncaughtExceptionHandler exceptionHandler; + */ +class java_lang_Thread : public java_lang_Object, private FieldAccess { +private: + // Static offsets of the object's instance fields. + // TODO These offsets need to be checked on VM startup. + static const off_t offset_vmThread = sizeof(java_object_t); + static const off_t offset_group = offset_vmThread + SIZEOF_VOID_P; + static const off_t offset_runnable = offset_group + SIZEOF_VOID_P; + static const off_t offset_name = offset_runnable + SIZEOF_VOID_P; + static const off_t offset_daemon = offset_name + SIZEOF_VOID_P; + static const off_t offset_priority = offset_daemon + sizeof(int32_t); // FIXME + static const off_t offset_stacksize = offset_priority + sizeof(int32_t); // FIXME + static const off_t offset_stillborn = offset_stacksize + sizeof(int64_t); // FIXME + static const off_t offset_contextClassLoader = offset_stillborn + SIZEOF_VOID_P; + static const off_t offset_contextClassLoaderIsSystemClassLoader = offset_contextClassLoader + SIZEOF_VOID_P; + static const off_t offset_threadId = offset_contextClassLoaderIsSystemClassLoader + sizeof(int32_t); // FIXME + static const off_t offset_parkBlocker = offset_threadId + sizeof(int64_t); // FIXME + static const off_t offset_locals = offset_parkBlocker + SIZEOF_VOID_P; + static const off_t offset_exceptionHandler = offset_locals + SIZEOF_VOID_P; + +public: + java_lang_Thread(java_handle_t* h) : java_lang_Object(h) {} +// java_lang_Thread(threadobject* t); + + // Getters. + inline java_handle_t* get_vmThread () const; + inline java_handle_t* get_group () const; + inline java_handle_t* get_name () const; + inline int32_t get_daemon () const; + inline int32_t get_priority () const; + inline java_handle_t* get_exceptionHandler() const; + + // Setters. + inline void set_group(java_handle_t* value); +}; + + +// inline java_lang_Thread::java_lang_Thread(threadobject* t) : java_lang_Object(h) +// { +// java_lang_Thread(thread_get_object(t)); +// } + + +inline java_handle_t* java_lang_Thread::get_vmThread() const +{ + return get(_handle, offset_vmThread); +} + +inline java_handle_t* java_lang_Thread::get_group() const +{ + return get(_handle, offset_group); +} + +inline java_handle_t* java_lang_Thread::get_name() const +{ + return get(_handle, offset_name); +} + +inline int32_t java_lang_Thread::get_daemon() const +{ + return get(_handle, offset_daemon); +} + +inline int32_t java_lang_Thread::get_priority() const +{ + return get(_handle, offset_priority); +} + +inline java_handle_t* java_lang_Thread::get_exceptionHandler() const +{ + return get(_handle, offset_exceptionHandler); +} + + +inline void java_lang_Thread::set_group(java_handle_t* value) +{ + set(_handle, offset_group, value); +} + + +/** + * GNU Classpath java/lang/VMThread + * + * Object layout: + * + * 0. object header + * 1. java.lang.Thread thread; + * 2. boolean running; + * 3. java.lang.VMThread vmdata; + */ +class java_lang_VMThread : public java_lang_Object, private FieldAccess { +private: + // Static offsets of the object's instance fields. + // TODO These offsets need to be checked on VM startup. + static const off_t offset_thread = sizeof(java_object_t); + static const off_t offset_running = offset_thread + SIZEOF_VOID_P; + static const off_t offset_vmdata = offset_running + sizeof(int32_t); // FIXME + +public: + java_lang_VMThread(java_handle_t* h) : java_lang_Object(h) {} + java_lang_VMThread(jobject h); + java_lang_VMThread(java_handle_t* h, java_handle_t* thread, threadobject* vmdata); + + // Getters. + inline java_handle_t* get_thread() const; + inline threadobject* get_vmdata() const; + + // Setters. + inline void set_thread(java_handle_t* value); + inline void set_vmdata(threadobject* value); +}; + + +inline java_lang_VMThread::java_lang_VMThread(jobject h) : java_lang_Object(h) +{ + java_lang_VMThread((java_handle_t*) h); +} + +inline java_lang_VMThread::java_lang_VMThread(java_handle_t* h, java_handle_t* thread, threadobject* vmdata) : java_lang_Object(h) +{ + set_thread(thread); + set_vmdata(vmdata); +} + + +inline java_handle_t* java_lang_VMThread::get_thread() const +{ + return get(_handle, offset_thread); +} + +inline threadobject* java_lang_VMThread::get_vmdata() const +{ + return get(_handle, offset_vmdata); +} + + +inline void java_lang_VMThread::set_thread(java_handle_t* value) +{ + set(_handle, offset_thread, value); +} + +inline void java_lang_VMThread::set_vmdata(threadobject* value) +{ + set(_handle, offset_vmdata, value); +} + + +/** + * GNU Classpath java/lang/Throwable + * + * Object layout: + * + * 0. object header + * 1. java.lang.String detailMessage; + * 2. java.lang.Throwable cause; + * 3. java.lang.StackTraceElement[] stackTrace; + * 4. java.lang.VMThrowable vmState; + */ +class java_lang_Throwable : public java_lang_Object, private FieldAccess { +private: + // Static offsets of the object's instance fields. + // TODO These offsets need to be checked on VM startup. + static const off_t offset_detailMessage = sizeof(java_object_t); + static const off_t offset_cause = offset_detailMessage + SIZEOF_VOID_P; + static const off_t offset_stackTrace = offset_cause + SIZEOF_VOID_P; + static const off_t offset_vmState = offset_stackTrace + SIZEOF_VOID_P; + +public: + java_lang_Throwable(java_handle_t* h) : java_lang_Object(h) {} + + // Getters. + inline java_handle_t* get_detailMessage() const; + inline java_handle_t* get_cause () const; + inline java_handle_t* get_vmState () const; +}; + + +inline java_handle_t* java_lang_Throwable::get_detailMessage() const +{ + return get(_handle, offset_detailMessage); +} + +inline java_handle_t* java_lang_Throwable::get_cause() const +{ + return get(_handle, offset_cause); +} + +inline java_handle_t* java_lang_Throwable::get_vmState() const +{ + return get(_handle, offset_vmState); +} + + +/** + * GNU Classpath java/lang/VMThrowable + * + * Object layout: + * + * 0. object header + * 1. java.lang.Object vmdata; + */ +class java_lang_VMThrowable : public java_lang_Object, private FieldAccess { +private: + // Static offsets of the object's instance fields. + // TODO These offsets need to be checked on VM startup. + static const off_t offset_vmdata = sizeof(java_object_t); + +public: + java_lang_VMThrowable(java_handle_t* h) : java_lang_Object(h) {} + java_lang_VMThrowable(jobject h); + + inline java_handle_bytearray_t* get_vmdata() const; + inline void set_vmdata(java_handle_bytearray_t* value); +}; + +inline java_lang_VMThrowable::java_lang_VMThrowable(jobject h) : java_lang_Object(h) +{ + java_lang_VMThrowable((java_handle_t*) h); +} + +inline java_handle_bytearray_t* java_lang_VMThrowable::get_vmdata() const +{ + return get(_handle, offset_vmdata); +} + +inline void java_lang_VMThrowable::set_vmdata(java_handle_bytearray_t* value) +{ + set(_handle, offset_vmdata, value); +} + + +/** + * GNU Classpath java/lang/reflect/Constructor + * + * Object layout: + * + * 0. object header + * 1. boolean flag; + * 2. gnu.java.lang.reflect.MethodSignatureParser p; + * 3. java.lang.reflect.VMConstructor cons; + */ +class java_lang_reflect_Constructor : public java_lang_Object, private FieldAccess { +private: + // Static offsets of the object's instance fields. + // TODO These offsets need to be checked on VM startup. + static const off_t offset_flag = sizeof(java_object_t); + static const off_t offset_p = offset_flag + sizeof(int32_t) + 4; + static const off_t offset_cons = offset_p + SIZEOF_VOID_P; + +public: + java_lang_reflect_Constructor(java_handle_t* h) : java_lang_Object(h) {} + java_lang_reflect_Constructor(jobject h); + + static java_handle_t* create(methodinfo* m); + static java_handle_t* new_instance(methodinfo* m, java_handle_objectarray_t* args, bool override); + + // Getters. + inline int32_t get_flag() const; + inline java_handle_t* get_cons() const; + + // Setters. + inline void set_cons(java_handle_t* value); +}; + +inline java_lang_reflect_Constructor::java_lang_reflect_Constructor(jobject h) : java_lang_Object(h) +{ + java_lang_reflect_Constructor((java_handle_t*) h); +} + +inline int32_t java_lang_reflect_Constructor::get_flag() const +{ + return get(_handle, offset_flag); +} + +inline java_handle_t* java_lang_reflect_Constructor::get_cons() const +{ + return get(_handle, offset_cons); +} + +inline void java_lang_reflect_Constructor::set_cons(java_handle_t* value) +{ + set(_handle, offset_cons, value); +} + + +/** + * GNU Classpath java/lang/reflect/VMConstructor + * + * Object layout: + * + * 0. object header + * 1. java.lang.Class clazz; + * 2. int slot; + * 3. byte[] annotations; + * 4. byte[] parameterAnnotations; + * 5. java.util.Map declaredAnnotations; + * 6. java.lang.reflect.Constructor cons; + */ +class java_lang_reflect_VMConstructor : public java_lang_Object, private FieldAccess { +private: + // Static offsets of the object's instance fields. + // TODO These offsets need to be checked on VM startup. + static const off_t offset_clazz = sizeof(java_object_t); + static const off_t offset_slot = offset_clazz + SIZEOF_VOID_P; + static const off_t offset_annotations = offset_slot + sizeof(int32_t) + 4; + static const off_t offset_parameterAnnotations = offset_annotations + SIZEOF_VOID_P; + static const off_t offset_declaredAnnotations = offset_parameterAnnotations + SIZEOF_VOID_P; + static const off_t offset_cons = offset_declaredAnnotations + SIZEOF_VOID_P; + +public: + java_lang_reflect_VMConstructor(java_handle_t* h) : java_lang_Object(h) {} + java_lang_reflect_VMConstructor(jobject h); + java_lang_reflect_VMConstructor(java_handle_t* h, methodinfo* m); + + // Getters. + inline classinfo* get_clazz () const; + inline int32_t get_slot () const; + inline java_handle_bytearray_t* get_annotations () const; + inline java_handle_bytearray_t* get_parameterAnnotations() const; + inline java_handle_t* get_declaredAnnotations () const; + inline java_handle_t* get_cons () const; + + // Setters. + inline void set_clazz (classinfo* value); + inline void set_slot (int32_t value); + inline void set_annotations (java_handle_bytearray_t* value); + inline void set_parameterAnnotations(java_handle_bytearray_t* value); + inline void set_declaredAnnotations (java_handle_t* value); + inline void set_cons (java_handle_t* value); + + // Convenience functions. + inline methodinfo* get_method(); +}; + +inline java_lang_reflect_VMConstructor::java_lang_reflect_VMConstructor(jobject h) : java_lang_Object(h) +{ + java_lang_reflect_VMConstructor((java_handle_t*) h); +} + +inline java_lang_reflect_VMConstructor::java_lang_reflect_VMConstructor(java_handle_t* h, methodinfo* m) : java_lang_Object(h) +{ + int slot = m - m->clazz->methods; + java_handle_bytearray_t* annotations = method_get_annotations(m); + java_handle_bytearray_t* parameterAnnotations = method_get_parameterannotations(m); + + set_clazz(m->clazz); + set_slot(slot); + set_annotations(annotations); + set_parameterAnnotations(parameterAnnotations); +} + +inline classinfo* java_lang_reflect_VMConstructor::get_clazz() const +{ + return get(_handle, offset_clazz); +} + +inline int32_t java_lang_reflect_VMConstructor::get_slot() const +{ + return get(_handle, offset_slot); +} + +inline java_handle_bytearray_t* java_lang_reflect_VMConstructor::get_annotations() const +{ + return get(_handle, offset_annotations); +} + +inline java_handle_bytearray_t* java_lang_reflect_VMConstructor::get_parameterAnnotations() const +{ + return get(_handle, offset_parameterAnnotations); +} + +inline java_handle_t* java_lang_reflect_VMConstructor::get_declaredAnnotations() const +{ + return get(_handle, offset_declaredAnnotations); +} + +inline java_handle_t* java_lang_reflect_VMConstructor::get_cons() const +{ + return get(_handle, offset_cons); +} + +inline void java_lang_reflect_VMConstructor::set_clazz(classinfo* value) +{ + set(_handle, offset_clazz, value); +} + +inline void java_lang_reflect_VMConstructor::set_slot(int32_t value) +{ + set(_handle, offset_slot, value); +} + +inline void java_lang_reflect_VMConstructor::set_annotations(java_handle_bytearray_t* value) +{ + set(_handle, offset_annotations, value); +} + +inline void java_lang_reflect_VMConstructor::set_parameterAnnotations(java_handle_bytearray_t* value) +{ + set(_handle, offset_parameterAnnotations, value); +} + +inline void java_lang_reflect_VMConstructor::set_declaredAnnotations(java_handle_t* value) +{ + set(_handle, offset_declaredAnnotations, value); +} + +inline void java_lang_reflect_VMConstructor::set_cons(java_handle_t* value) +{ + set(_handle, offset_cons, value); +} + +inline methodinfo* java_lang_reflect_VMConstructor::get_method() +{ + classinfo* c = get_clazz(); + int32_t slot = get_slot(); + methodinfo* m = &(c->methods[slot]); + return m; +} + + +/** + * GNU Classpath java/lang/reflect/Field + * + * Object layout: + * + * 0. object header + * 1. boolean flag; + * 2. gnu.java.lang.reflect.FieldSignatureParser p; + * 3. java.lang.reflect.VMField f; + */ +class java_lang_reflect_Field : public java_lang_Object, private FieldAccess { +private: + // Static offsets of the object's instance fields. + // TODO These offsets need to be checked on VM startup. + static const off_t offset_flag = sizeof(java_object_t); + // Currently we align 64-bit data types to 8-bytes. + static const off_t offset_p = offset_flag + sizeof(int32_t) + 4; + static const off_t offset_f = offset_p + SIZEOF_VOID_P; + +public: + java_lang_reflect_Field(java_handle_t* h) : java_lang_Object(h) {} + java_lang_reflect_Field(jobject h); + + static java_handle_t* create(fieldinfo* f); + + // Getters. + inline int32_t get_flag() const; + inline java_handle_t* get_f() const; + + // Setters. + inline void set_f(java_handle_t* value); +}; + +inline java_lang_reflect_Field::java_lang_reflect_Field(jobject h) : java_lang_Object(h) +{ + java_lang_reflect_Field((java_handle_t*) h); +} + +inline int32_t java_lang_reflect_Field::get_flag() const +{ + return get(_handle, offset_flag); +} + +inline java_handle_t* java_lang_reflect_Field::get_f() const +{ + return get(_handle, offset_f); +} + +inline void java_lang_reflect_Field::set_f(java_handle_t* value) +{ + set(_handle, offset_f, value); +} + + +/** + * GNU Classpath java/lang/reflect/VMField + * + * Object layout: + * + * 0. object header + * 1. java.lang.Class clazz; + * 2. java.lang.String name; + * 3. int slot; + * 4. byte[] annotations; + * 5. java.lang.Map declaredAnnotations; + * 6. java.lang.reflect.Field f; + */ +class java_lang_reflect_VMField : public java_lang_Object, private FieldAccess { +private: + // Static offsets of the object's instance fields. + // TODO These offsets need to be checked on VM startup. + static const off_t offset_clazz = sizeof(java_object_t); + static const off_t offset_name = offset_clazz + SIZEOF_VOID_P; + static const off_t offset_slot = offset_name + SIZEOF_VOID_P; + static const off_t offset_annotations = offset_slot + sizeof(int32_t) + 4; + static const off_t offset_declaredAnnotations = offset_annotations + SIZEOF_VOID_P; + static const off_t offset_f = offset_declaredAnnotations + SIZEOF_VOID_P; + +public: + java_lang_reflect_VMField(java_handle_t* h) : java_lang_Object(h) {} + java_lang_reflect_VMField(jobject h); + java_lang_reflect_VMField(java_handle_t* h, fieldinfo* f); + + // Getters. + inline classinfo* get_clazz () const; + inline int32_t get_slot () const; + inline java_handle_bytearray_t* get_annotations () const; + inline java_handle_t* get_declaredAnnotations() const; + inline java_handle_t* get_f () const; + + // Setters. + inline void set_clazz (classinfo* value); + inline void set_name (java_handle_t* value); + inline void set_slot (int32_t value); + inline void set_annotations (java_handle_bytearray_t* value); + inline void set_declaredAnnotations(java_handle_t* value); + inline void set_f (java_handle_t* value); + + // Convenience functions. + inline fieldinfo* get_field() const; +}; + +inline java_lang_reflect_VMField::java_lang_reflect_VMField(jobject h) : java_lang_Object(h) +{ + java_lang_reflect_VMField((java_handle_t*) h); +} + +inline java_lang_reflect_VMField::java_lang_reflect_VMField(java_handle_t* h, fieldinfo* f) : java_lang_Object(h) +{ + java_handle_t* name = javastring_intern(javastring_new(f->name)); + int slot = f - f->clazz->fields; + java_handle_bytearray_t* annotations = field_get_annotations(f); + + set_clazz(f->clazz); + set_name(name); + set_slot(slot); + set_annotations(annotations); +} + +inline classinfo* java_lang_reflect_VMField::get_clazz() const +{ + return get(_handle, offset_clazz); +} + +inline int32_t java_lang_reflect_VMField::get_slot() const +{ + return get(_handle, offset_slot); +} + +inline java_handle_bytearray_t* java_lang_reflect_VMField::get_annotations() const +{ + return get(_handle, offset_annotations); +} + +inline java_handle_t* java_lang_reflect_VMField::get_declaredAnnotations() const +{ + return get(_handle, offset_declaredAnnotations); +} + +inline java_handle_t* java_lang_reflect_VMField::get_f() const +{ + return get(_handle, offset_f); +} + +inline void java_lang_reflect_VMField::set_clazz(classinfo* value) +{ + set(_handle, offset_clazz, value); +} + +inline void java_lang_reflect_VMField::set_name(java_handle_t* value) +{ + set(_handle, offset_name, value); +} + +inline void java_lang_reflect_VMField::set_slot(int32_t value) +{ + set(_handle, offset_slot, value); +} + +inline void java_lang_reflect_VMField::set_annotations(java_handle_bytearray_t* value) +{ + set(_handle, offset_annotations, value); +} + +inline void java_lang_reflect_VMField::set_declaredAnnotations(java_handle_t* value) +{ + set(_handle, offset_declaredAnnotations, value); +} + +inline void java_lang_reflect_VMField::set_f(java_handle_t* value) +{ + set(_handle, offset_f, value); +} + +inline fieldinfo* java_lang_reflect_VMField::get_field() const +{ + classinfo* c = get_clazz(); + int32_t slot = get_slot(); + fieldinfo* f = &(c->fields[slot]); + return f; +} + + +/** + * GNU Classpath java/lang/reflect/Method + * + * Object layout: + * + * 0. object header + * 1. boolean flag; + * 2. gnu.java.lang.reflect.MethodSignatureParser p; + * 3. java.lang.reflect.VMMethod m; + */ +class java_lang_reflect_Method : public java_lang_Object, private FieldAccess { +private: + // Static offsets of the object's instance fields. + // TODO These offsets need to be checked on VM startup. + static const off_t offset_flag = sizeof(java_object_t); + // Currently we align 64-bit data types to 8-bytes. + static const off_t offset_p = offset_flag + sizeof(int32_t) + 4; + static const off_t offset_m = offset_p + SIZEOF_VOID_P; + +public: + java_lang_reflect_Method(java_handle_t* h) : java_lang_Object(h) {} + java_lang_reflect_Method(jobject h); + + static java_handle_t* create(methodinfo* m); + + // Getters. + inline int32_t get_flag() const; + inline java_handle_t* get_m() const; + + // Setters. + inline void set_m(java_handle_t* value); +}; + +inline java_lang_reflect_Method::java_lang_reflect_Method(jobject h) : java_lang_Object(h) +{ + java_lang_reflect_Method((java_handle_t*) h); +} + +inline int32_t java_lang_reflect_Method::get_flag() const +{ + return get(_handle, offset_flag); +} + +inline java_handle_t* java_lang_reflect_Method::get_m() const +{ + return get(_handle, offset_m); +} + +inline void java_lang_reflect_Method::set_m(java_handle_t* value) +{ + set(_handle, offset_m, value); +} + + +/** + * GNU Classpath java/lang/reflect/VMMethod + * + * Object layout: + * + * 0. object header + * 1. java.lang.Class clazz; + * 2. java.lang.String name; + * 3. int slot; + * 4. byte[] annotations; + * 5. byte[] parameterAnnotations; + * 6. byte[] annotationDefault; + * 7. java.lang.Map declaredAnnotations; + * 8. java.lang.reflect.Method m; + */ +class java_lang_reflect_VMMethod : public java_lang_Object, private FieldAccess { +private: + // Static offsets of the object's instance fields. + // TODO These offsets need to be checked on VM startup. + static const off_t offset_clazz = sizeof(java_object_t); + static const off_t offset_name = offset_clazz + SIZEOF_VOID_P; + static const off_t offset_slot = offset_name + SIZEOF_VOID_P; + static const off_t offset_annotations = offset_slot + sizeof(int32_t) + 4; + static const off_t offset_parameterAnnotations = offset_annotations + SIZEOF_VOID_P; + static const off_t offset_annotationDefault = offset_parameterAnnotations + SIZEOF_VOID_P; + static const off_t offset_declaredAnnotations = offset_annotationDefault + SIZEOF_VOID_P; + static const off_t offset_m = offset_declaredAnnotations + SIZEOF_VOID_P; + +public: + java_lang_reflect_VMMethod(java_handle_t* h) : java_lang_Object(h) {} + java_lang_reflect_VMMethod(jobject h); + java_lang_reflect_VMMethod(java_handle_t* h, methodinfo* m); + + // Getters. + inline classinfo* get_clazz () const; + inline int32_t get_slot () const; + inline java_handle_bytearray_t* get_annotations () const; + inline java_handle_bytearray_t* get_parameterAnnotations() const; + inline java_handle_bytearray_t* get_annotationDefault () const; + inline java_handle_t* get_declaredAnnotations () const; + inline java_handle_t* get_m () const; + + // Setters. + inline void set_clazz (classinfo* value); + inline void set_name (java_handle_t* value); + inline void set_slot (int32_t value); + inline void set_annotations (java_handle_bytearray_t* value); + inline void set_parameterAnnotations(java_handle_bytearray_t* value); + inline void set_annotationDefault (java_handle_bytearray_t* value); + inline void set_declaredAnnotations (java_handle_t* value); + inline void set_m (java_handle_t* value); + + // Convenience functions. + inline methodinfo* get_method() const; +}; + +inline java_lang_reflect_VMMethod::java_lang_reflect_VMMethod(jobject h) : java_lang_Object(h) +{ + java_lang_reflect_VMMethod((java_handle_t*) h); +} + +inline java_lang_reflect_VMMethod::java_lang_reflect_VMMethod(java_handle_t* h, methodinfo* m) : java_lang_Object(h) +{ + java_handle_t* name = javastring_intern(javastring_new(m->name)); + int slot = m - m->clazz->methods; + java_handle_bytearray_t* annotations = method_get_annotations(m); + java_handle_bytearray_t* parameterAnnotations = method_get_parameterannotations(m); + java_handle_bytearray_t* annotationDefault = method_get_annotationdefault(m); + + set_clazz(m->clazz); + set_name(name); + set_slot(slot); + set_annotations(annotations); + set_parameterAnnotations(parameterAnnotations); + set_annotationDefault(annotationDefault); +} + +inline classinfo* java_lang_reflect_VMMethod::get_clazz() const +{ + return get(_handle, offset_clazz); +} + +inline int32_t java_lang_reflect_VMMethod::get_slot() const +{ + return get(_handle, offset_slot); +} + +inline java_handle_bytearray_t* java_lang_reflect_VMMethod::get_annotations() const +{ + return get(_handle, offset_annotations); +} + +inline java_handle_bytearray_t* java_lang_reflect_VMMethod::get_parameterAnnotations() const +{ + return get(_handle, offset_parameterAnnotations); +} + +inline java_handle_bytearray_t* java_lang_reflect_VMMethod::get_annotationDefault() const +{ + return get(_handle, offset_annotationDefault); +} + +inline java_handle_t* java_lang_reflect_VMMethod::get_declaredAnnotations() const +{ + return get(_handle, offset_declaredAnnotations); +} + +inline java_handle_t* java_lang_reflect_VMMethod::get_m() const +{ + return get(_handle, offset_m); +} + +inline void java_lang_reflect_VMMethod::set_clazz(classinfo* value) +{ + set(_handle, offset_clazz, value); +} + +inline void java_lang_reflect_VMMethod::set_name(java_handle_t* value) +{ + set(_handle, offset_name, value); +} + +inline void java_lang_reflect_VMMethod::set_slot(int32_t value) +{ + set(_handle, offset_slot, value); +} + +inline void java_lang_reflect_VMMethod::set_annotations(java_handle_bytearray_t* value) +{ + set(_handle, offset_annotations, value); +} + +inline void java_lang_reflect_VMMethod::set_parameterAnnotations(java_handle_bytearray_t* value) +{ + set(_handle, offset_parameterAnnotations, value); +} + +inline void java_lang_reflect_VMMethod::set_annotationDefault(java_handle_bytearray_t* value) +{ + set(_handle, offset_annotationDefault, value); +} + +inline void java_lang_reflect_VMMethod::set_declaredAnnotations(java_handle_t* value) +{ + set(_handle, offset_declaredAnnotations, value); +} + +inline void java_lang_reflect_VMMethod::set_m(java_handle_t* value) +{ + set(_handle, offset_m, value); +} + +inline methodinfo* java_lang_reflect_VMMethod::get_method() const +{ + classinfo* c = get_clazz(); + int32_t slot = get_slot(); + methodinfo* m = &(c->methods[slot]); + return m; +} + + +/** + * GNU Classpath java/nio/Buffer + * + * Object layout: + * + * 0. object header + * 1. int cap; + * 2. int limit; + * 3. int pos; + * 4. int mark; + * 5. gnu.classpath.Pointer address; + */ +class java_nio_Buffer : public java_lang_Object, private FieldAccess { +private: + // Static offsets of the object's instance fields. + // TODO These offsets need to be checked on VM startup. + static const off_t offset_cap = sizeof(java_object_t); + static const off_t offset_limit = offset_cap + sizeof(int32_t); + static const off_t offset_pos = offset_limit + sizeof(int32_t); + static const off_t offset_mark = offset_pos + sizeof(int32_t); + static const off_t offset_address = offset_mark + sizeof(int32_t); + +public: + java_nio_Buffer(java_handle_t* h) : java_lang_Object(h) {} + + // Getters. + inline int32_t get_cap() const; +}; + +inline int32_t java_nio_Buffer::get_cap() const +{ + return get(_handle, offset_cap); +} + + +/** + * GNU Classpath java/nio/DirectByteBufferImpl + * + * Object layout: + * + * 0. object header + * 1. int cap; + * 2. int limit; + * 3. int pos; + * 4. int mark; + * 5. gnu.classpath.Pointer address; + * 6. java.nio.ByteOrder endian; + * 7. byte[] backing_buffer; + * 8. int array_offset; + * 9. java.lang.Object owner; + */ +class java_nio_DirectByteBufferImpl : public java_lang_Object, private FieldAccess { +private: + // Static offsets of the object's instance fields. + // TODO These offsets need to be checked on VM startup. + static const off_t offset_cap = sizeof(java_object_t); + static const off_t offset_limit = offset_cap + sizeof(int32_t); + static const off_t offset_pos = offset_limit + sizeof(int32_t); + static const off_t offset_mark = offset_pos + sizeof(int32_t); + static const off_t offset_address = offset_mark + sizeof(int32_t); + static const off_t offset_endian = offset_address + SIZEOF_VOID_P; + static const off_t offset_backing_buffer = offset_endian + SIZEOF_VOID_P; + static const off_t offset_array_offset = offset_backing_buffer + SIZEOF_VOID_P; + static const off_t offset_owner = offset_array_offset + sizeof(int32_t); + +public: + java_nio_DirectByteBufferImpl(java_handle_t* h) : java_lang_Object(h) {} + java_nio_DirectByteBufferImpl(jobject h); + + // Getters. + inline java_handle_t* get_address() const; +}; + +inline java_nio_DirectByteBufferImpl::java_nio_DirectByteBufferImpl(jobject h) : java_lang_Object(h) +{ + java_nio_DirectByteBufferImpl((java_handle_t*) h); +} + +inline java_handle_t* java_nio_DirectByteBufferImpl::get_address() const +{ + return get(_handle, offset_address); +} + + +/** + * GNU Classpath gnu/classpath/Pointer + * + * Actually there are two classes, gnu.classpath.Pointer32 and + * gnu.classpath.Pointer64, but we only define the abstract super + * class and use the int/long field as void* type. + * + * Object layout: + * + * 0. object header + * 1. int/long data; + */ +class gnu_classpath_Pointer : public java_lang_Object, private FieldAccess { +private: + // Static offsets of the object's instance fields. + // TODO These offsets need to be checked on VM startup. + static const off_t offset_data = sizeof(java_object_t); + +public: + gnu_classpath_Pointer(java_handle_t* h) : java_lang_Object(h) {} + gnu_classpath_Pointer(java_handle_t* h, void* data); + + // Setters. + inline void* get_data() const; + + // Setters. + inline void set_data(void* value); +}; + +inline gnu_classpath_Pointer::gnu_classpath_Pointer(java_handle_t* h, void* data) : java_lang_Object(h) +{ + set_data(data); +} + +inline void* gnu_classpath_Pointer::get_data() const +{ + return get(_handle, offset_data); +} + +inline void gnu_classpath_Pointer::set_data(void* value) +{ + set(_handle, offset_data, value); +} + + +# if defined(ENABLE_ANNOTATIONS) +/** + * GNU Classpath sun/reflect/ConstantPool + * + * Object layout: + * + * 0. object header + * 1. java.lang.Object constantPoolOop; + */ +class sun_reflect_ConstantPool : public java_lang_Object, private FieldAccess { +private: + // Static offsets of the object's instance fields. + // TODO These offsets need to be checked on VM startup. + static const off_t offset_constantPoolOop = sizeof(java_object_t); + +public: + sun_reflect_ConstantPool(java_handle_t* h) : java_lang_Object(h) {} + + // Setters. + inline void set_constantPoolOop(classinfo* value); + inline void set_constantPoolOop(jclass value); +}; + +inline void sun_reflect_ConstantPool::set_constantPoolOop(classinfo* value) +{ + set(_handle, offset_constantPoolOop, value); +} + +inline void sun_reflect_ConstantPool::set_constantPoolOop(jclass value) +{ + // XXX jclass is a boxed object. + set_constantPoolOop(LLNI_classinfo_unwrap(value)); +} +# endif // ENABLE_ANNOTATIONS + +#endif // WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH + + +#if defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK) + +/** + * OpenJDK java/lang/reflect/Constructor + * + * Object layout: + * + * 0. object header + * 1. boolean flag; + * 2. gnu.java.lang.reflect.MethodSignatureParser p; + * 3. java.lang.reflect.VMConstructor cons; + */ +class java_lang_reflect_Constructor : public java_lang_Object, private FieldAccess { +private: + // Static offsets of the object's instance fields. + // TODO These offsets need to be checked on VM startup. + static const off_t offset_flag = sizeof(java_object_t); + static const off_t offset_p = offset_flag + sizeof(int32_t) + 4; + static const off_t offset_cons = offset_p + SIZEOF_VOID_P; + +public: + java_lang_reflect_Constructor(java_handle_t* h) : java_lang_Object(h) {} + java_lang_reflect_Constructor(jobject h); + + static java_handle_t* create(methodinfo* m); + static java_handle_t* new_instance(methodinfo* m, java_handle_objectarray_t* args, bool override); + + // Getters. + inline int32_t get_flag() const; + inline java_handle_t* get_cons() const; + + // Setters. + inline void set_cons(java_handle_t* value); +}; + +inline java_lang_reflect_Constructor::java_lang_reflect_Constructor(jobject h) : java_lang_Object(h) +{ + java_lang_reflect_Constructor((java_handle_t*) h); +} + +inline int32_t java_lang_reflect_Constructor::get_flag() const +{ + return get(_handle, offset_flag); +} + +inline java_handle_t* java_lang_reflect_Constructor::get_cons() const +{ + return get(_handle, offset_cons); +} + +inline void java_lang_reflect_Constructor::set_cons(java_handle_t* value) +{ + set(_handle, offset_cons, value); +} + +#endif // WITH_JAVA_RUNTIME_LIBRARY_OPENJDK + +#else + +// Legacy C interface. +java_handle_t* java_lang_reflect_Constructor_create(methodinfo* m); +java_handle_t* java_lang_reflect_Field_create(fieldinfo* f); +java_handle_t* java_lang_reflect_Method_create(methodinfo* m); + +#endif + +#endif // _JAVAOBJECTS_HPP + + +/* + * 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: + */ diff --git a/src/vmcore/linker.c b/src/vmcore/linker.c index 49cf74a67..eb32c0590 100644 --- a/src/vmcore/linker.c +++ b/src/vmcore/linker.c @@ -106,22 +106,6 @@ static bool linker_addinterface(classinfo *c, classinfo *ic); static s4 class_highestinterface(classinfo *c); -/* dummy structures for alinment checks ***************************************/ - -typedef struct dummy_alignment_long_t dummy_alignment_long_t; -typedef struct dummy_alignment_double_t dummy_alignment_double_t; - -struct dummy_alignment_long_t { - int32_t i; - int64_t l; -}; - -struct dummy_alignment_double_t { - int32_t i; - double d; -}; - - /* linker_init ***************************************************************** Initializes the linker subsystem and links classes required for the @@ -133,35 +117,6 @@ void linker_preinit(void) { TRACESUBSYSTEMINITIALIZATION("linker_preinit"); - /* Check for if alignment for long and double matches what we - assume for the current architecture. */ - -#if defined(__I386__) || (defined(__ARM__) && !defined(__ARM_EABI__)) || (defined(__POWERPC__) && defined(__DARWIN__)) || defined(__M68K__) - /* Define a define here which is later checked when we use this - offset. */ - -# define LINKER_ALIGNMENT_LONG_DOUBLE 4 - - if (OFFSET(dummy_alignment_long_t, l) != 4) - vm_abort("linker_preinit: long alignment is different from what assumed: %d != %d", - OFFSET(dummy_alignment_long_t, l), 4); - - if (OFFSET(dummy_alignment_double_t, d) != 4) - vm_abort("linker_preinit: double alignment is different from what assumed: %d != %d", - OFFSET(dummy_alignment_double_t, d), 4); -#else - -# define LINKER_ALIGNMENT_LONG_DOUBLE 8 - - if (OFFSET(dummy_alignment_long_t, l) != 8) - vm_abort("linker_preinit: long alignment is different from what assumed: %d != %d", - OFFSET(dummy_alignment_long_t, l), 8); - - if (OFFSET(dummy_alignment_double_t, d) != 8) - vm_abort("linker_preinit: double alignment is different from what assumed: %d != %d", - OFFSET(dummy_alignment_double_t, d), 8); -#endif - /* Reset interface index. */ interfaceindex = 0; @@ -917,29 +872,7 @@ static classinfo *link_class_intern(classinfo *c) if (!(f->flags & ACC_STATIC)) { dsize = descriptor_typesize(f->parseddesc); - -#if defined(__I386__) || (defined(__ARM__) && !defined(__ARM_EABI__)) || (defined(__POWERPC__) && defined(__DARWIN__)) || defined(__M68K__) - /* On some architectures and configurations we need to - align long (int64_t) and double fields to 4-bytes to - match what GCC does for struct members. We must do the - same as GCC here because the offsets in native header - structs like java_lang_Double must match the offsets of - the Java fields (eg. java.lang.Double.value). */ - -# if LINKER_ALIGNMENT_LONG_DOUBLE != 4 -# error alignment of long and double is not 4 -# endif - - c->instancesize = MEMORY_ALIGN(c->instancesize, 4); -#else - -# if LINKER_ALIGNMENT_LONG_DOUBLE != 8 -# error alignment of long and double is not 8 -# endif - c->instancesize = MEMORY_ALIGN(c->instancesize, dsize); -#endif - f->offset = c->instancesize; c->instancesize += dsize; } -- 2.25.1