Showing the changes to java (2 of 2 files). Show all
Unified · Split
| @@ -0,0 +1,95 @@ | |||
| 1 | implement Throwable_L; | ||
| 2 | |||
| 3 | # javal v1.2 generated file: edit with care | ||
| 4 | |||
| 5 | include "jni.m"; | ||
| 6 | jni : JNI; | ||
| 7 | ClassModule, | ||
| 8 | JString, | ||
| 9 | JArray, | ||
| 10 | JArrayI, | ||
| 11 | JArrayC, | ||
| 12 | JArrayB, | ||
| 13 | JArrayS, | ||
| 14 | JArrayJ, | ||
| 15 | JArrayF, | ||
| 16 | JArrayD, | ||
| 17 | JArrayZ, | ||
| 18 | JArrayJObject, | ||
| 19 | JArrayJClass, | ||
| 20 | JArrayJString, | ||
| 21 | JClass, | ||
| 22 | JObject : import jni; | ||
| 23 | |||
| 24 | #>> extra pre includes here | ||
| 25 | |||
| 26 | #<< | ||
| 27 | |||
| 28 | include "Throwable_L.m"; | ||
| 29 | |||
| 30 | #>> extra post includes here | ||
| 31 | |||
| 32 | #<< | ||
| 33 | |||
| 34 | init( jni_p : JNI ) | ||
| 35 | { | ||
| 36 | # save java native inteface mod instance | ||
| 37 | jni = jni_p; | ||
| 38 | #>>extra initialization here | ||
| 39 | #<< | ||
| 40 | } | ||
| 41 | |||
| 42 | printStackTrace0_rObject_V( this : ref Throwable_obj, p0 : JObject) | ||
| 43 | {#>> | ||
| 44 | Value : import jni; | ||
| 45 | jldr := jni->jldr; | ||
| 46 | Object : import jldr; | ||
| 47 | |||
| 48 | if ( this.backtrace != nil ) | ||
| 49 | { | ||
| 50 | args := array [1] of ref Value; | ||
| 51 | args[0] = ref Value.TObject( jni->NewStringObject( string this.backtrace ) ); | ||
| 52 | |||
| 53 | (nil,nil):=jni->CallMethod( p0, "println", "(Ljava/lang/String;)V", args ); | ||
| 54 | # ignore any erros | ||
| 55 | } | ||
| 56 | |||
| 57 | }#<< | ||
| 58 | |||
| 59 | fillInStackTrace_rThrowable( this : ref Throwable_obj) : ref Throwable_obj | ||
| 60 | {#>> | ||
| 61 | # attempt to open the local "prog" device (i.e. '#p') | ||
| 62 | # and read the call stack into an array of bytes | ||
| 63 | pid := jni->sys->pctl(0,nil); | ||
| 64 | progfile := "#p/"+ (string pid) +"/stack"; | ||
| 65 | fd := jni->sys->open( progfile, Sys->OREAD ); | ||
| 66 | if ( fd != nil ) | ||
| 67 | { | ||
| 68 | # must spin a thread to read my own call-stack | ||
| 69 | result := chan of array of byte; # channel for thd results | ||
| 70 | spawn ReadCallStack( fd, result ); | ||
| 71 | this.backtrace = <- result; # wait for results | ||
| 72 | |||
| 73 | } | ||
| 74 | else | ||
| 75 | this.backtrace = array of byte jni->sys->sprint("could not open %s:%r\n", progfile ); | ||
| 76 | |||
| 77 | return( this ); | ||
| 78 | }#<< | ||
| 79 | |||
| 80 | ####### private functions | ||
| 81 | |||
| 82 | |||
| 83 | ReadCallStack( fd : ref Sys->FD, result : chan of array of byte ) | ||
| 84 | { | ||
| 85 | buf := array[8000] of byte; #about 10 frames | ||
| 86 | n := jni->sys->read(fd, buf, len buf - 1); | ||
| 87 | fd = nil; | ||
| 88 | if(n < 0) | ||
| 89 | buf = array of byte jni->sys->sprint("could not read call-stack:%r\n"); | ||
| 90 | else | ||
| 91 | buf[n] = byte 0; | ||
| 92 | |||
| 93 | result <- = buf[:n+1]; | ||
| 94 | } | ||
| 95 | |||
| @@ -0,0 +1,16 @@ | |||
| 1 | # javal v1.2 generated file: edit with care | ||
| 2 | |||
| 3 | Throwable_L : module | ||
| 4 | { | ||
| 5 | Throwable_obj : adt | ||
| 6 | { | ||
| 7 | cl_mod : ClassModule; | ||
| 8 | backtrace : array of byte; | ||
| 9 | detailMessage : JString; | ||
| 10 | }; | ||
| 11 | |||
| 12 | init : fn( jni_p : JNI ); | ||
| 13 | printStackTrace0_rObject_V : fn( this : ref Throwable_obj, p0 : JObject); | ||
| 14 | fillInStackTrace_rThrowable : fn( this : ref Throwable_obj) : ref Throwable_obj; | ||
| 15 | |||
| 16 | }; | ||