1 /* src/vm/javaobjects.cpp - functions to create and access Java objects
3 Copyright (C) 2008 Theobroma Systems Ltd.
5 This file is part of CACAO.
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2, or (at
10 your option) any later version.
12 This program is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
29 #include "native/vm/reflection.hpp"
31 #include "vm/access.h"
32 #include "vm/builtin.h"
33 #include "vm/global.h"
34 #include "vm/globals.hpp"
35 #include "vm/initialize.h"
36 #include "vm/javaobjects.hpp"
39 #if defined(ENABLE_JAVASE)
42 * Constructs a Java object with the given
43 * java.lang.reflect.Constructor.
45 * @param args Constructor arguments.
47 * @return Handle to Java object.
49 java_handle_t* java_lang_reflect_Constructor::new_instance(java_handle_objectarray_t* args)
51 methodinfo* m = get_method();
53 // Should we bypass security the checks (AccessibleObject)?
54 if (get_override() == false) {
55 /* This method is always called like this:
56 [0] java.lang.reflect.Constructor.constructNative (Native Method)
57 [1] java.lang.reflect.Constructor.newInstance
61 if (!access_check_method(m, 2))
65 // Create a Java object.
66 java_handle_t* h = builtin_new(m->clazz);
72 (void) Reflection::invoke(m, h, args);
79 * Invokes the given method.
81 * @param args Method arguments.
83 * @return return value of the method
85 java_handle_t* java_lang_reflect_Method::invoke(java_handle_t* o, java_handle_objectarray_t* args)
87 methodinfo* m = get_method();
89 // Should we bypass security the checks (AccessibleObject)?
90 if (get_override() == false) {
91 #if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
92 /* This method is always called like this:
93 [0] java.lang.reflect.Method.invokeNative (Native Method)
94 [1] java.lang.reflect.Method.invoke (Method.java:329)
98 if (!access_check_method(m, 2))
100 #elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
101 /* We only pass 1 here as stacktrace_get_caller_class, which
102 is called from access_check_method, skips
103 java.lang.reflect.Method.invoke(). */
105 if (!access_check_method(m, 1))
108 # error unknown classpath configuration
112 // Check if method class is initialized.
113 if (!(m->clazz->state & CLASS_INITIALIZED))
114 if (!initialize_class(m->clazz))
117 // Call the Java method.
118 java_handle_t* result = Reflection::invoke(m, o, args);
124 // Legacy C interface.
127 java_handle_t* java_lang_reflect_Constructor_create(methodinfo* m) { return java_lang_reflect_Constructor(m).get_handle(); }
128 java_handle_t* java_lang_reflect_Field_create(fieldinfo* f) { return java_lang_reflect_Field(f).get_handle(); }
129 java_handle_t* java_lang_reflect_Method_create(methodinfo* m) { return java_lang_reflect_Method(m).get_handle(); }
132 #endif // ENABLE_JAVASE
136 * These are local overrides for various environment variables in Emacs.
137 * Please do not remove this and leave it at the end of the file, where
138 * Emacs will automagically detect them.
139 * ---------------------------------------------------------------------
142 * indent-tabs-mode: t