1 /* src/threads/thread-openjdk.cpp - thread functions specific to the OpenJDK library
3 Copyright (C) 1996-2011
4 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
6 This file is part of CACAO.
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2, or (at
11 your option) any later version.
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26 #include "thread-openjdk.hpp"
28 #include "vm/global.h"
29 #include "vm/globals.hpp"
32 #include "vm/globals.hpp"
33 #include "vm/javaobjects.hpp"
34 #include "vm/exceptions.hpp"
36 #include "threadlist.hpp"
38 #if defined(ENABLE_THREADS) && defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
40 classinfo *ThreadRuntimeOpenjdk::get_thread_class_from_object(java_handle_t *object) {
42 LLNI_class_get(object, c);
46 java_handle_t *ThreadRuntimeOpenjdk::get_vmthread_handle(const java_lang_Thread &jlt) {
47 return jlt.get_handle();
50 java_handle_t *ThreadRuntimeOpenjdk::get_thread_exception_handler(const java_lang_Thread &jlt)
52 return jlt.get_uncaughtExceptionHandler();
55 methodinfo *ThreadRuntimeOpenjdk::get_threadgroup_remove_method(classinfo *c)
57 return class_resolveclassmethod(c,
59 utf_java_lang_Thread__V,
60 class_java_lang_ThreadGroup,
64 methodinfo *ThreadRuntimeOpenjdk::get_thread_init_method()
66 return class_resolveclassmethod(class_java_lang_Thread,
68 utf_new_char("(Ljava/lang/ThreadGroup;Ljava/lang/String;)V"),
69 class_java_lang_Thread,
73 void ThreadRuntimeOpenjdk::setup_thread_vmdata(const java_lang_Thread& jlt, threadobject *t)
78 void ThreadRuntimeOpenjdk::print_thread_name(const java_lang_Thread& jlt, FILE *stream)
80 /* FIXME: In OpenJDK and CLDC the name is a char[]. */
81 //java_chararray_t *name;
83 /* FIXME This prints to stdout. */
84 utf_display_printable_ascii(utf_null);
87 void ThreadRuntimeOpenjdk::set_javathread_state(threadobject *t, int state)
89 // Set the state of the java.lang.Thread object.
90 java_lang_Thread thread(thread_get_object(t));
91 assert(thread.is_non_null());
92 thread.set_threadStatus(state);
95 threadobject *ThreadRuntimeOpenjdk::get_threadobject_from_thread(java_handle_t *h)
97 /* XXX This is just a quick hack. */
98 return ThreadList::get_thread_from_java_object(h);
101 void ThreadRuntimeOpenjdk::thread_create_initial_threadgroups(java_handle_t **threadgroup_system, java_handle_t **threadgroup_main)
106 /* Allocate and initialize the system thread group. */
108 *threadgroup_system = native_new_and_init(class_java_lang_ThreadGroup);
110 if (*threadgroup_system == NULL)
111 vm_abort("thread_create_initial_threadgroups: failed to allocate system threadgroup");
113 /* Allocate and initialize the main thread group. */
115 *threadgroup_main = builtin_new(class_java_lang_ThreadGroup);
117 if (*threadgroup_main == NULL)
118 vm_abort("thread_create_initial_threadgroups: failed to allocate main threadgroup");
120 name = javastring_new(utf_main);
122 m = class_resolveclassmethod(class_java_lang_ThreadGroup,
124 utf_Ljava_lang_ThreadGroup_Ljava_lang_String__V,
125 class_java_lang_ThreadGroup,
129 vm_abort("thread_create_initial_threadgroups: failed to resolve threadgroup init method");
131 (void) vm_call_method(m, *threadgroup_main, *threadgroup_system, name);
133 if (exceptions_get_exception())
134 vm_abort("thread_create_initial_threadgroups: exception while initializing main threadgroup");
138 bool ThreadRuntimeOpenjdk::invoke_thread_initializer(java_lang_Thread& jlt, threadobject *t, methodinfo *thread_method_init, java_handle_t *name, java_handle_t *group)
140 /* Set the priority. java.lang.Thread.<init> requires it because
141 it sets the priority of the current thread to the parent's one
142 (which is the current thread in this case). */
143 jlt.set_priority(NORM_PRIORITY);
145 // Call: java.lang.Thread.<init>(Ljava/lang/ThreadGroup;Ljava/lang/String;)V
147 (void) vm_call_method(thread_method_init, jlt.get_handle(), group, name);
149 if (exceptions_get_exception())
155 #endif /* ENABLE_THREADS && WITH_JAVA_RUNTIME_LIBRARY_OPENJDK */
159 * These are local overrides for various environment variables in Emacs.
160 * Please do not remove this and leave it at the end of the file, where
161 * Emacs will automagically detect them.
162 * ---------------------------------------------------------------------
165 * indent-tabs-mode: t
169 * vim:noexpandtab:sw=4:ts=4: