LCOV - code coverage report
Current view: top level - threads - ThreadRuntime-classpath.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 46 53 86.8 %
Date: 2015-06-10 18:10:59 Functions: 11 12 91.7 %

          Line data    Source code
       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             : 
      25             : #include "threads/ThreadRuntime.hpp"
      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             : 
      36          10 : classinfo *ThreadRuntime::get_thread_class_from_object(java_handle_t *object) {
      37          10 :         return class_java_lang_VMThread;
      38             : }
      39             : 
      40          10 : java_handle_t *ThreadRuntime::get_vmthread_handle(const java_lang_Thread &jlt) {
      41          10 :         java_lang_VMThread jlvmt(jlt.get_vmThread());
      42          10 :         return jlvmt.get_handle();
      43             : }
      44             : 
      45           0 : java_handle_t *ThreadRuntime::get_thread_exception_handler(const java_lang_Thread &jlt)
      46             : {
      47           0 :         return jlt.get_exceptionHandler();
      48             : }
      49             : 
      50         272 : methodinfo *ThreadRuntime::get_threadgroup_remove_method(classinfo *c)
      51             : {
      52             :         return class_resolveclassmethod(c,
      53             :                                                                         utf8::removeThread,
      54             :                                                                         utf8::java_lang_Thread__V,
      55             :                                                                         class_java_lang_ThreadGroup,
      56         272 :                                                                         true);
      57             : }
      58             : 
      59         163 : methodinfo *ThreadRuntime::get_thread_init_method()
      60             : {
      61             :         return class_resolveclassmethod(class_java_lang_Thread,
      62             :                                                                         utf8::init,
      63             :                                                                         Utf8String::from_utf8("(Ljava/lang/VMThread;Ljava/lang/String;IZ)V"),
      64             :                                                                         class_java_lang_Thread,
      65         163 :                                                                         true);
      66             : }
      67             : 
      68          10 : void ThreadRuntime::setup_thread_vmdata(const java_lang_Thread& jlt, threadobject *t)
      69             : {
      70             :         /* Get the java.lang.VMThread object and do some sanity checks. */
      71          10 :         java_lang_VMThread jlvmt(jlt.get_vmThread());
      72             : 
      73          10 :         assert(jlvmt.get_handle() != NULL);
      74          10 :         assert(jlvmt.get_vmdata() == NULL);
      75             : 
      76          10 :         jlvmt.set_vmdata(t);
      77          10 : }
      78             : 
      79          41 : void ThreadRuntime::print_thread_name(const java_lang_Thread& jlt, FILE *stream)
      80             : {
      81          41 :         java_handle_t* name = jlt.get_name();
      82          41 :         JavaString(name).fprint(stream);
      83          41 : }
      84             : 
      85         739 : void ThreadRuntime::set_javathread_state(threadobject *t, int state)
      86             : {
      87         739 : }
      88             : 
      89       20000 : threadobject *ThreadRuntime::get_thread_from_object(java_handle_t *h)
      90             : {
      91       20000 :         java_lang_VMThread jlvmt(h);
      92       20000 :         return jlvmt.get_vmdata();
      93             : }
      94             : 
      95         163 : void ThreadRuntime::thread_create_initial_threadgroups(java_handle_t **threadgroup_system, java_handle_t **threadgroup_main)
      96             : {
      97             :         /* Allocate and initialize the main thread group. */
      98             : 
      99         163 :         *threadgroup_main = native_new_and_init(class_java_lang_ThreadGroup);
     100             : 
     101         163 :         if (*threadgroup_main == NULL)
     102           0 :                 vm_abort("thread_create_initial_threadgroups: failed to allocate main threadgroup");
     103             : 
     104             :         /* Use the same threadgroup for system as for main. */
     105             : 
     106         163 :         *threadgroup_system = *threadgroup_main;
     107         163 : }
     108             : 
     109         783 : bool ThreadRuntime::invoke_thread_initializer(java_lang_Thread& jlt, threadobject *t, methodinfo *thread_method_init, java_handle_t *name, java_handle_t *group)
     110             : {
     111         783 :         java_handle_t *h = builtin_new(class_java_lang_VMThread);
     112             : 
     113         783 :         if (h == NULL)
     114           0 :                 return false;
     115             : 
     116             :         // Create and initialize a java.lang.VMThread object.
     117         783 :         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         783 :         bool isdaemon = thread_is_daemon(t);
     123             : 
     124         783 :         (void) vm_call_method(thread_method_init, jlt.get_handle(), jlvmt.get_handle(),
     125        1566 :                                                   name, NORM_PRIORITY, isdaemon);
     126             : 
     127         783 :         if (exceptions_get_exception())
     128           0 :                 return false;
     129             : 
     130             :         // Set the ThreadGroup in the Java thread object.
     131         783 :         jlt.set_group(group);
     132             : 
     133             :         /* Add thread to the threadgroup. */
     134             : 
     135             :         classinfo* c;
     136         783 :         LLNI_class_get(group, c);
     137             : 
     138             :         methodinfo* m = class_resolveclassmethod(c,
     139             :                                                                                          utf8::addThread,
     140             :                                                                                          utf8::java_lang_Thread__V,
     141             :                                                                                          class_java_lang_ThreadGroup,
     142         783 :                                                                                          true);
     143             : 
     144         783 :         if (m == NULL)
     145           0 :                 return false;
     146             : 
     147         783 :         (void) vm_call_method(m, group, jlt.get_handle());
     148             : 
     149         783 :         if (exceptions_get_exception())
     150           0 :                 return false;
     151             : 
     152         783 :         return true;
     153             : }
     154             : 
     155         282 : void ThreadRuntime::clear_heap_reference(java_lang_Thread& jlt)
     156             : {
     157             :         // Nothing to do.
     158         282 : }
     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             :  */

Generated by: LCOV version 1.11