1 /* src/threads/thread-classpath.cpp - thread functions specific to the GNU classpath 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-classpath.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_GNU_CLASSPATH)
40 classinfo *ThreadRuntimeClasspath::get_thread_class_from_object(java_handle_t *object) {
41 return class_java_lang_VMThread;
44 java_handle_t *ThreadRuntimeClasspath::get_vmthread_handle(const java_lang_Thread &jlt) {
45 java_lang_VMThread jlvmt(jlt.get_vmThread());
46 return jlvmt.get_handle();
49 java_handle_t *ThreadRuntimeClasspath::get_thread_exception_handler(const java_lang_Thread &jlt)
51 return jlt.get_exceptionHandler();
54 methodinfo *ThreadRuntimeClasspath::get_threadgroup_remove_method(classinfo *c)
56 return class_resolveclassmethod(c,
58 utf_java_lang_Thread__V,
59 class_java_lang_ThreadGroup,
63 methodinfo *ThreadRuntimeClasspath::get_thread_init_method()
65 return class_resolveclassmethod(class_java_lang_Thread,
67 utf_new_char("(Ljava/lang/VMThread;Ljava/lang/String;IZ)V"),
68 class_java_lang_Thread,
72 void ThreadRuntimeClasspath::setup_thread_vmdata(const java_lang_Thread& jlt, threadobject *t)
74 /* Get the java.lang.VMThread object and do some sanity checks. */
75 java_lang_VMThread jlvmt(jlt.get_vmThread());
77 assert(jlvmt.get_handle() != NULL);
78 assert(jlvmt.get_vmdata() == NULL);
85 void ThreadRuntimeClasspath::print_thread_name(const java_lang_Thread& jlt, FILE *stream)
87 java_handle_t* name = jlt.get_name();
88 javastring_fprint(name, stream);
91 void ThreadRuntimeClasspath::set_javathread_state(threadobject *t, int state)
95 threadobject *ThreadRuntimeClasspath::get_threadobject_from_thread(java_handle_t *h)
97 java_lang_VMThread jlvmt(h);
98 return jlvmt.get_vmdata();
101 void ThreadRuntimeClasspath::thread_create_initial_threadgroups(java_handle_t **threadgroup_system, java_handle_t **threadgroup_main)
103 /* Allocate and initialize the main thread group. */
105 *threadgroup_main = native_new_and_init(class_java_lang_ThreadGroup);
107 if (*threadgroup_main == NULL)
108 vm_abort("thread_create_initial_threadgroups: failed to allocate main threadgroup");
110 /* Use the same threadgroup for system as for main. */
112 *threadgroup_system = *threadgroup_main;
115 bool ThreadRuntimeClasspath::invoke_thread_initializer(java_lang_Thread& jlt, threadobject *t, methodinfo *thread_method_init, java_handle_t *name, java_handle_t *group)
117 java_handle_t *h = builtin_new(class_java_lang_VMThread);
122 // Create and initialize a java.lang.VMThread object.
123 java_lang_VMThread jlvmt(h, jlt.get_handle(), t);
126 java.lang.Thread.<init>(Ljava/lang/VMThread;Ljava/lang/String;IZ)V */
128 bool isdaemon = thread_is_daemon(t);
130 (void) vm_call_method(thread_method_init, jlt.get_handle(), jlvmt.get_handle(),
131 name, NORM_PRIORITY, isdaemon);
133 if (exceptions_get_exception())
136 // Set the ThreadGroup in the Java thread object.
137 jlt.set_group(group);
139 /* Add thread to the threadgroup. */
142 LLNI_class_get(group, c);
144 methodinfo* m = class_resolveclassmethod(c,
146 utf_java_lang_Thread__V,
147 class_java_lang_ThreadGroup,
153 (void) vm_call_method(m, group, jlt.get_handle());
155 if (exceptions_get_exception())
161 #endif /* ENABLE_THREADS && WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH */
165 * These are local overrides for various environment variables in Emacs.
166 * Please do not remove this and leave it at the end of the file, where
167 * Emacs will automagically detect them.
168 * ---------------------------------------------------------------------
171 * indent-tabs-mode: t
175 * vim:noexpandtab:sw=4:ts=4: