CACAO
ThreadRuntime-classpath.cpp
Go to the documentation of this file.
1 /* src/threads/ThreadRuntime-classpath.cpp - thread functions specific to the GNU classpath 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 
26 #include "mm/gc.hpp"
27 #include "threads/threadlist.hpp"
28 #include "vm/globals.hpp"
29 #include "vm/global.hpp"
30 #include "vm/javaobjects.hpp"
31 #include "vm/exceptions.hpp"
32 #include "vm/vm.hpp"
33 
34 using namespace cacao;
35 
38 }
39 
41  java_lang_VMThread jlvmt(jlt.get_vmThread());
42  return jlvmt.get_handle();
43 }
44 
46 {
47  return jlt.get_exceptionHandler();
48 }
49 
51 {
52  return class_resolveclassmethod(c,
53  utf8::removeThread,
54  utf8::java_lang_Thread__V,
56  true);
57 }
58 
60 {
62  utf8::init,
63  Utf8String::from_utf8("(Ljava/lang/VMThread;Ljava/lang/String;IZ)V"),
65  true);
66 }
67 
69 {
70  /* Get the java.lang.VMThread object and do some sanity checks. */
71  java_lang_VMThread jlvmt(jlt.get_vmThread());
72 
73  assert(jlvmt.get_handle() != NULL);
74  assert(jlvmt.get_vmdata() == NULL);
75 
76  jlvmt.set_vmdata(t);
77 }
78 
79 void ThreadRuntime::print_thread_name(const java_lang_Thread& jlt, FILE *stream)
80 {
81  java_handle_t* name = jlt.get_name();
82  JavaString(name).fprint(stream);
83 }
84 
86 {
87 }
88 
90 {
91  java_lang_VMThread jlvmt(h);
92  return jlvmt.get_vmdata();
93 }
94 
96 {
97  /* Allocate and initialize the main thread group. */
98 
100 
101  if (*threadgroup_main == NULL)
102  vm_abort("thread_create_initial_threadgroups: failed to allocate main threadgroup");
103 
104  /* Use the same threadgroup for system as for main. */
105 
106  *threadgroup_system = *threadgroup_main;
107 }
108 
110 {
112 
113  if (h == NULL)
114  return false;
115 
116  // Create and initialize a java.lang.VMThread object.
117  java_lang_VMThread jlvmt(h, jlt.get_handle(), t);
118 
119  /* Call:
120  java.lang.Thread.<init>(Ljava/lang/VMThread;Ljava/lang/String;IZ)V */
121 
122  bool isdaemon = thread_is_daemon(t);
123 
124  (void) vm_call_method(thread_method_init, jlt.get_handle(), jlvmt.get_handle(),
125  name, NORM_PRIORITY, isdaemon);
126 
128  return false;
129 
130  // Set the ThreadGroup in the Java thread object.
131  jlt.set_group(group);
132 
133  /* Add thread to the threadgroup. */
134 
135  classinfo* c;
136  LLNI_class_get(group, c);
137 
139  utf8::addThread,
140  utf8::java_lang_Thread__V,
142  true);
143 
144  if (m == NULL)
145  return false;
146 
147  (void) vm_call_method(m, group, jlt.get_handle());
148 
150  return false;
151 
152  return true;
153 }
154 
156 {
157  // Nothing to do.
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
GNU Classpath java/lang/VMThread.
java_handle_t * get_name() const
static void thread_create_initial_threadgroups(java_handle_t **threadgroup_system, java_handle_t **threadgroup_main)
typedef void(JNICALL *jvmtiEventSingleStep)(jvmtiEnv *jvmti_env
void set_vmdata(threadobject *value)
static bool thread_is_daemon(threadobject *t)
Definition: thread.hpp:285
java_handle_t * vm_call_method(methodinfo *m, java_handle_t *o,...)
classinfo * class_java_lang_VMThread
Definition: globals.cpp:48
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
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
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)
void set_group(java_handle_t *value)
static java_handle_t * threadgroup_system
Definition: thread.cpp:63
void fprint(FILE *) const
Definition: string.cpp:466
static methodinfo * get_threadgroup_remove_method(classinfo *c)
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
java_handle_t * get_vmThread() const
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
threadobject * get_vmdata() const
GNU Classpath java/lang/Thread.
java_handle_t * get_exceptionHandler() const
static classinfo * get_thread_class_from_object(java_handle_t *object)
classinfo * class_java_lang_Thread
Definition: globals.cpp:41
static void print_thread_name(const java_lang_Thread &jlt, FILE *stream)
static methodinfo * get_thread_init_method()