01: //
02: // Copyright (C) 2005 United States Government as represented by the
03: // Administrator of the National Aeronautics and Space Administration
04: // (NASA). All Rights Reserved.
05: //
06: // This software is distributed under the NASA Open Source Agreement
07: // (NOSA), version 1.3. The NOSA has been approved by the Open Source
08: // Initiative. See the file NOSA-1.3-JPF at the top of the distribution
09: // directory tree for the complete NOSA document.
10: //
11: // THE SUBJECT SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY OF ANY
12: // KIND, EITHER EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT
13: // LIMITED TO, ANY WARRANTY THAT THE SUBJECT SOFTWARE WILL CONFORM TO
14: // SPECIFICATIONS, ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR
15: // A PARTICULAR PURPOSE, OR FREEDOM FROM INFRINGEMENT, ANY WARRANTY THAT
16: // THE SUBJECT SOFTWARE WILL BE ERROR FREE, OR ANY WARRANTY THAT
17: // DOCUMENTATION, IF PROVIDED, WILL CONFORM TO THE SUBJECT SOFTWARE.
18: //
19:
20: package gov.nasa.jpf.jvm;
21:
22: /**
23: * native peer class for unit testing MJI
24: */
25: public class JPF_gov_nasa_jpf_jvm_TestNativePeer {
26: public static void $clinit(MJIEnv env, int rcls) {
27: env.setStaticIntField(rcls, "sdata", 42);
28: }
29:
30: public static void $init__I(MJIEnv env, int robj, int i) {
31: env.setIntField(robj, "idata", i);
32: }
33:
34: public static int nativeCreate2DimIntArray(MJIEnv env, int robj,
35: int size1, int size2) {
36: int ar = env.newObjectArray("[I", size1);
37:
38: for (int i = 0; i < size1; i++) {
39: int ea = env.newIntArray(size2);
40:
41: if (i == 1) {
42: env.setIntArrayElement(ea, 1, 42);
43: }
44:
45: env.setReferenceArrayElement(ar, i, ea);
46: }
47:
48: return ar;
49: }
50:
51: public static int nativeCreateIntArray(MJIEnv env, int robj,
52: int size) {
53: int ar = env.newIntArray(size);
54:
55: env.setIntArrayElement(ar, 1, 1);
56:
57: return ar;
58: }
59:
60: public static int nativeCreateStringArray(MJIEnv env, int robj,
61: int size) {
62: int ar = env.newObjectArray("Ljava/lang/String;", size);
63:
64: env.setReferenceArrayElement(ar, 1, env.newString("one"));
65:
66: return ar;
67: }
68:
69: public static void nativeException(MJIEnv env, int robj) {
70: env.throwException("java.lang.UnsupportedOperationException",
71: "caught me");
72: }
73:
74: public static int nativeCrash(MJIEnv env, int robj) {
75: String s = null;
76: return s.length();
77: }
78:
79: public static int nativeInstanceMethod(MJIEnv env, int robj,
80: double d, char c, boolean b, int i) {
81: if ((d == 2.0) && (c == '?') && b) {
82: return i + 2;
83: }
84:
85: return 0;
86: }
87:
88: public static long nativeStaticMethod(MJIEnv env, int rcls, long l,
89: int stringRef) {
90: String s = env.getStringObject(stringRef);
91:
92: if ("Blah".equals(s)) {
93: return l + 2;
94: }
95:
96: return 0;
97: }
98: }
|