CACAO
ThreadRuntime-openjdk.cpp
Go to the documentation of this file.
1 /* src/threads/ThreadRuntime-openjdk.cpp - thread functions specific to the OpenJDK library
2 
3  Copyright (C) 1996-2013
4  CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5 
6  This file is part of CACAO.
7 
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.
12 
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.
17 
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
21  02110-1301, USA.
22 
23 */
24 
25 
27 #include "mm/gc.hpp"
28 #include "threads/threadlist.hpp"
29 #include "vm/globals.hpp"
30 #include "vm/global.hpp"
31 #include "vm/javaobjects.hpp"
32 #include "vm/exceptions.hpp"
33 #include "vm/vm.hpp"
34 
35 using namespace cacao;
36 
38  classinfo *c;
39  LLNI_class_get(object, c);
40  return c;
41 }
42 
44  return jlt.get_handle();
45 }
46 
48 {
49  return jlt.get_uncaughtExceptionHandler();
50 }
51 
53 {
54  return class_resolveclassmethod(c,
55  utf8::remove,
56  utf8::java_lang_Thread__V,
58  true);
59 }
60 
62 {
64  utf8::init,
65  Utf8String::from_utf8("(Ljava/lang/ThreadGroup;Ljava/lang/String;)V"),
67  true);
68 }
69 
71 {
72  // Nothing to do.
73 }
74 
75 void ThreadRuntime::print_thread_name(const java_lang_Thread& jlt, FILE *stream)
76 {
77  /* FIXME: In OpenJDK and CLDC the name is a char[]. */
78  //java_chararray_t *name;
79 
80  /* FIXME This prints to stdout. */
81  utf_display_printable_ascii(utf8::null);
82 }
83 
85 {
86  // Set the state of the java.lang.Thread object.
88  assert(thread.is_non_null());
89  thread.set_threadStatus(state);
90 }
91 
93 {
94  /* XXX This is just a quick hack. */
96 }
97 
99 {
101  methodinfo *m;
102 
103  /* Allocate and initialize the system thread group. */
104 
105  *threadgroup_system = native_new_and_init(class_java_lang_ThreadGroup);
106 
107  if (*threadgroup_system == NULL)
108  vm_abort("thread_create_initial_threadgroups: failed to allocate system threadgroup");
109 
110  /* Allocate and initialize the main thread group. */
111 
112  *threadgroup_main = builtin_new(class_java_lang_ThreadGroup);
113 
114  if (*threadgroup_main == NULL)
115  vm_abort("thread_create_initial_threadgroups: failed to allocate main threadgroup");
116 
118 
120  utf8::init,
121  utf8::Ljava_lang_ThreadGroup_Ljava_lang_String__V,
123  true);
124 
125  if (m == NULL)
126  vm_abort("thread_create_initial_threadgroups: failed to resolve threadgroup init method");
127 
128  (void) vm_call_method(m, *threadgroup_main, *threadgroup_system, name);
129 
131  vm_abort("thread_create_initial_threadgroups: exception while initializing main threadgroup");
132 
133 }
134 
136 {
137  /* Set the priority. java.lang.Thread.<init> requires it because
138  it sets the priority of the current thread to the parent's one
139  (which is the current thread in this case). */
140  jlt.set_priority(NORM_PRIORITY);
141 
142  // Call: java.lang.Thread.<init>(Ljava/lang/ThreadGroup;Ljava/lang/String;)V
143 
144  (void) vm_call_method(thread_method_init, jlt.get_handle(), group, name);
145 
147  return false;
148 
149  return true;
150 }
151 
153 {
154 #ifndef WITH_JAVA_RUNTIME_LIBRARY_OPENJDK_7
155  jlt.set_me(0);
156 #endif
157 }
158 
159 
160 /*
161  * These are local overrides for various environment variables in Emacs.
162  * Please do not remove this and leave it at the end of the file, where
163  * Emacs will automagically detect them.
164  * ---------------------------------------------------------------------
165  * Local variables:
166  * mode: c++
167  * indent-tabs-mode: t
168  * c-basic-offset: 4
169  * tab-width: 4
170  * End:
171  * vim:noexpandtab:sw=4:ts=4:
172  */
static threadobject * get_thread_from_object(java_handle_t *h)
classinfo * class_java_lang_ThreadGroup
Definition: globals.cpp:42
methodinfo * class_resolveclassmethod(classinfo *c, Utf8String name, Utf8String desc, classinfo *referer, bool throwexception)
Definition: class.cpp:1211
virtual java_handle_t * get_handle() const
static JavaString from_utf8(Utf8String)
Definition: string.cpp:184
static void thread_create_initial_threadgroups(java_handle_t **threadgroup_system, java_handle_t **threadgroup_main)
typedef void(JNICALL *jvmtiEventSingleStep)(jvmtiEnv *jvmti_env
java_handle_t * vm_call_method(methodinfo *m, java_handle_t *o,...)
static java_handle_t * get_thread_exception_handler(const java_lang_Thread &jlt)
JNIEnv jclass jobject const char * name
Definition: jvmti.h:312
static void set_javathread_state(threadobject *t, int state)
static methodinfo * thread_method_init
Definition: thread.cpp:62
int main(int argc, char **argv)
Definition: cacao.cpp:61
java_handle_t * builtin_new(classinfo *c)
Definition: builtin.cpp:816
void vm_abort(const char *text,...)
Definition: vm.cpp:2586
static java_handle_t * threadgroup_main
Definition: thread.cpp:64
#define LLNI_class_get(obj, variable)
Definition: llni.hpp:60
#define LLNI_WRAP(obj)
Definition: llni.hpp:51
static ThreadList * get()
Provides access to singleton.
Definition: threadlist.hpp:62
JNIEnv jthread thread
Definition: jvmti.h:207
static Utf8String from_utf8(const char *, size_t)
Definition: utf8.cpp:335
static bool invoke_thread_initializer(java_lang_Thread &jlt, threadobject *t, methodinfo *thread_method_init, java_handle_t *name, java_handle_t *group)
static void clear_heap_reference(java_lang_Thread &jlt)
static java_handle_t * threadgroup_system
Definition: thread.cpp:63
static methodinfo * get_threadgroup_remove_method(classinfo *c)
void utf_display_printable_ascii(Utf8String u)
Definition: utf8.cpp:532
java_handle_t * native_new_and_init(classinfo *c)
Registers a new native agent by specified by it&#39;s library name and with an optional options string...
Definition: native.cpp:729
static java_handle_t * get_vmthread_handle(const java_lang_Thread &jlt)
static void setup_thread_vmdata(const java_lang_Thread &jlt, threadobject *t)
java_handle_t * exceptions_get_exception(void)
Definition: exceptions.cpp:76
GNU Classpath java/lang/Thread.
java_object_t * object
Definition: thread.hpp:93
static classinfo * get_thread_class_from_object(java_handle_t *object)
classinfo * class_java_lang_Thread
Definition: globals.cpp:41
threadobject * get_thread_from_java_object(java_handle_t *h)
Return the Java thread object from the given thread object.
Definition: threadlist.cpp:251
static void print_thread_name(const java_lang_Thread &jlt, FILE *stream)
static methodinfo * get_thread_init_method()