LCOV - code coverage report
Current view: top level - native/vm/gnuclasspath - java_lang_VMThrowable.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 19 21 90.5 %
Date: 2017-07-14 10:03:36 Functions: 3 3 100.0 %

          Line data    Source code
       1             : /* src/native/vm/gnuclasspath/java_lang_VMThrowable.cpp
       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             : 
      26             : #include "config.h"
      27             : 
      28             : #include <stdint.h>
      29             : #include <assert.h>
      30             : 
      31             : #include "vm/types.hpp"
      32             : 
      33             : #include "native/jni.hpp"
      34             : #include "native/llni.hpp"
      35             : #include "native/native.hpp"
      36             : 
      37             : #if defined(ENABLE_JNI_HEADERS)
      38             : # include "native/vm/include/java_lang_VMThrowable.h"
      39             : #endif
      40             : 
      41             : #include "vm/array.hpp"
      42             : #include "vm/jit/builtin.hpp"
      43             : #include "vm/exceptions.hpp"
      44             : #include "vm/globals.hpp"
      45             : #include "vm/javaobjects.hpp"
      46             : #include "vm/loader.hpp"
      47             : #include "vm/string.hpp"
      48             : #include "vm/vm.hpp"
      49             : 
      50             : #include "vm/jit/code.hpp"
      51             : #include "vm/jit/linenumbertable.hpp"
      52             : #include "vm/jit/stacktrace.hpp"
      53             : 
      54             : 
      55             : 
      56             : // Native functions are exported as C functions.
      57             : extern "C" {
      58             : 
      59             : /*
      60             :  * Class:     java/lang/VMThrowable
      61             :  * Method:    fillInStackTrace
      62             :  * Signature: (Ljava/lang/Throwable;)Ljava/lang/VMThrowable;
      63             :  */
      64       21051 : JNIEXPORT jobject JNICALL Java_java_lang_VMThrowable_fillInStackTrace(JNIEnv *env, jclass clazz, jobject t)
      65             : {
      66             :         java_handle_t* h;
      67             :         java_handle_bytearray_t* ba;
      68             : 
      69       21051 :         h = native_new_and_init(class_java_lang_VMThrowable);
      70             : 
      71       21051 :         if (h == NULL)
      72           0 :                 return NULL;
      73             : 
      74       21051 :         java_lang_VMThrowable vmt(h);
      75             : 
      76       21051 :         ba = stacktrace_get_current();
      77             : 
      78       21051 :         if (ba == NULL)
      79           0 :                 return NULL;
      80             : 
      81       21051 :         vmt.set_vmdata(ba);
      82             : 
      83       21051 :         return (jobject) vmt.get_handle();
      84             : }
      85             : 
      86             : 
      87             : /*
      88             :  * Class:     java/lang/VMThrowable
      89             :  * Method:    getStackTrace
      90             :  * Signature: (Ljava/lang/Throwable;)[Ljava/lang/StackTraceElement;
      91             :  */
      92          66 : JNIEXPORT jobjectArray JNICALL Java_java_lang_VMThrowable_getStackTrace(JNIEnv *env, jobject _this, jobject t)
      93             : {
      94          66 :         java_lang_VMThrowable vmt(_this);
      95             : 
      96             :         // Get the stacktrace from the VMThrowable object.
      97             : 
      98          66 :         ByteArray ba(vmt.get_vmdata());
      99             : 
     100             :         // XXX Critical GC section?
     101          66 :         stacktrace_t* st = (stacktrace_t*) ba.get_raw_data_ptr();
     102             : 
     103          66 :         assert(st != NULL);
     104             : 
     105          66 :         return stacktrace_get_StackTraceElements(st);
     106             : }
     107             : 
     108             : } // extern "C"
     109             : 
     110             : 
     111             : /* native methods implemented by this file ************************************/
     112             : 
     113             : static JNINativeMethod methods[] = {
     114             :         { (char*) "fillInStackTrace", (char*) "(Ljava/lang/Throwable;)Ljava/lang/VMThrowable;",        (void*) (uintptr_t) &Java_java_lang_VMThrowable_fillInStackTrace },
     115             :         { (char*) "getStackTrace",    (char*) "(Ljava/lang/Throwable;)[Ljava/lang/StackTraceElement;", (void*) (uintptr_t) &Java_java_lang_VMThrowable_getStackTrace    },
     116             : };
     117             : 
     118             : 
     119             : /* _Jv_java_lang_VMThrowable_init **********************************************
     120             : 
     121             :    Register native functions.
     122             : 
     123             : *******************************************************************************/
     124             : 
     125         163 : void _Jv_java_lang_VMThrowable_init(void)
     126             : {
     127         163 :         Utf8String u = Utf8String::from_utf8("java/lang/VMThrowable");
     128             : 
     129         163 :         NativeMethods& nm = VM::get_current()->get_nativemethods();
     130         163 :         nm.register_methods(u, methods, NATIVE_METHODS_COUNT);
     131         163 : }
     132             : 
     133             : 
     134             : /*
     135             :  * These are local overrides for various environment variables in Emacs.
     136             :  * Please do not remove this and leave it at the end of the file, where
     137             :  * Emacs will automagically detect them.
     138             :  * ---------------------------------------------------------------------
     139             :  * Local variables:
     140             :  * mode: c++
     141             :  * indent-tabs-mode: t
     142             :  * c-basic-offset: 4
     143             :  * tab-width: 4
     144             :  * End:
     145             :  */

Generated by: LCOV version 1.11