2 * Copyright (C) 2014, United States Government, as represented by the
3 * Administrator of the National Aeronautics and Space Administration.
6 * The Java Pathfinder core (jpf-core) platform is licensed under the
7 * Apache License, Version 2.0 (the "License"); you may not use this file except
8 * in compliance with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0.
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 package gov.nasa.jpf.vm;
20 import gov.nasa.jpf.annotation.MJI;
21 import gov.nasa.jpf.vm.ClassInfo;
22 import gov.nasa.jpf.vm.MJIEnv;
23 import gov.nasa.jpf.vm.NativePeer;
24 import gov.nasa.jpf.vm.ThreadInfo;
26 import java.io.PrintWriter;
27 import java.io.StringWriter;
31 * MJI NativePeer class for java.lang.Throwable library abstraction
33 public class JPF_java_lang_Throwable extends NativePeer {
35 * return array of StackTraceElement elements from the snapshot stored in the Throwable
38 public int createStackTrace_____3Ljava_lang_StackTraceElement_2 (MJIEnv env, int objref) {
39 int aref = env.getReferenceField(objref, "snapshot");
40 int[] snap = env.getIntArrayObject(aref);
42 return env.getThreadInfo().createStackTraceElements(snap);
46 public int fillInStackTrace____Ljava_lang_Throwable_2 (MJIEnv env, int objref) {
47 ThreadInfo ti = env.getThreadInfo();
48 int[] snap = ti.getSnapshot(objref);
50 int aref = env.newIntArray(snap);
51 env.setReferenceField(objref, "snapshot", aref);
56 // native because we don't want to waste states
58 public void printStackTrace____V (MJIEnv env, int objRef) {
59 env.getThreadInfo().printStackTrace(objRef);
62 // a helper method to get a string representation of the stacktrace
64 public int getStackTraceAsString____Ljava_lang_String_2 (MJIEnv env, int objRef) {
65 ThreadInfo ti = env.getThreadInfo();
66 StringWriter sw = new StringWriter();
67 PrintWriter pw = new PrintWriter(sw);
69 ti.printStackTrace(pw, objRef);
70 String stackTrace = sw.toString();
73 return env.newString(stackTrace);
77 public int toString____Ljava_lang_String_2 (MJIEnv env, int objRef){
78 ClassInfo ci = env.getClassInfo(objRef);
79 int msgRef = env.getReferenceField(objRef, "detailMessage");
81 String s = ci.getName();
82 if (msgRef != MJIEnv.NULL){
83 s += ": " + env.getStringObject(msgRef);
86 return env.newString(s);