1 /* src/vmcore/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
30 #include "native/vm/reflection.hpp"
32 #include "vm/access.h"
33 #include "vm/builtin.h"
34 #include "vm/global.h"
35 #include "vm/initialize.h"
37 #include "vmcore/globals.hpp"
38 #include "vmcore/javaobjects.hpp"
41 #if defined(ENABLE_JAVASE)
44 * Constructs a Java object with the given
45 * java.lang.reflect.Constructor.
47 * @param args Constructor arguments.
49 * @return Handle to Java object.
51 java_handle_t* java_lang_reflect_Constructor::new_instance(java_handle_objectarray_t* args)
53 methodinfo* m = get_method();
55 // Should we bypass security the checks (AccessibleObject)?
56 if (get_override() == false) {
57 /* This method is always called like this:
58 [0] java.lang.reflect.Constructor.constructNative (Native Method)
59 [1] java.lang.reflect.Constructor.newInstance
63 if (!access_check_method(m, 2))
67 // Create a Java object.
68 java_handle_t* h = builtin_new(m->clazz);
74 (void) Reflection::invoke(m, h, args);
81 * Invokes the given method.
83 * @param args Method arguments.
85 * @return return value of the method
87 java_handle_t* java_lang_reflect_Method::invoke(java_handle_t* o, java_handle_objectarray_t* args)
89 methodinfo* m = get_method();
91 // Should we bypass security the checks (AccessibleObject)?
92 if (get_override() == false) {
93 #if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
94 /* This method is always called like this:
95 [0] java.lang.reflect.Method.invokeNative (Native Method)
96 [1] java.lang.reflect.Method.invoke (Method.java:329)
100 if (!access_check_method(m, 2))
102 #elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
103 /* We only pass 1 here as stacktrace_get_caller_class, which
104 is called from access_check_method, skips
105 java.lang.reflect.Method.invoke(). */
107 if (!access_check_method(m, 1))
110 # error unknown classpath configuration
114 // Check if method class is initialized.
115 if (!(m->clazz->state & CLASS_INITIALIZED))
116 if (!initialize_class(m->clazz))
119 // Call the Java method.
120 java_handle_t* result = Reflection::invoke(m, o, args);
126 // Legacy C interface.
129 java_handle_t* java_lang_reflect_Constructor_create(methodinfo* m) { return java_lang_reflect_Constructor(m).get_handle(); }
130 java_handle_t* java_lang_reflect_Field_create(fieldinfo* f) { return java_lang_reflect_Field(f).get_handle(); }
131 java_handle_t* java_lang_reflect_Method_create(methodinfo* m) { return java_lang_reflect_Method(m).get_handle(); }
134 #endif // ENABLE_JAVASE
138 * These are local overrides for various environment variables in Emacs.
139 * Please do not remove this and leave it at the end of the file, where
140 * Emacs will automagically detect them.
141 * ---------------------------------------------------------------------
144 * indent-tabs-mode: t