comparison src/peers/gov/nasa/jpf/vm/JPF_gov_nasa_jpf_SerializationConstructor.java @ 0:61d41facf527

initial v8 import (history reset)
author Peter Mehlitz <Peter.C.Mehlitz@nasa.gov>
date Fri, 23 Jan 2015 10:14:01 -0800
parents
children db918c531e6d
comparison
equal deleted inserted replaced
-1:000000000000 0:61d41facf527
1 /*
2 * Copyright (C) 2014, United States Government, as represented by the
3 * Administrator of the National Aeronautics and Space Administration.
4 * All rights reserved.
5 *
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
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0.
11 *
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.
17 */
18
19 package gov.nasa.jpf.vm;
20
21 import gov.nasa.jpf.annotation.MJI;
22 import gov.nasa.jpf.vm.ClassInfo;
23 import gov.nasa.jpf.vm.DirectCallStackFrame;
24 import gov.nasa.jpf.vm.MJIEnv;
25 import gov.nasa.jpf.vm.MethodInfo;
26 import gov.nasa.jpf.vm.NativePeer;
27 import gov.nasa.jpf.vm.ThreadInfo;
28
29
30 public class JPF_gov_nasa_jpf_SerializationConstructor extends NativePeer {
31
32 /**
33 * create a new instance, but only call the ctor of the first
34 * non-serializable superclass
35 */
36 @MJI
37 public int newInstance___3Ljava_lang_Object_2__Ljava_lang_Object_2 (MJIEnv env, int mthRef, int argsRef) {
38 ThreadInfo ti = env.getThreadInfo();
39 DirectCallStackFrame frame = ti.getReturnedDirectCall();
40
41 int superCtorRef = env.getReferenceField(mthRef, "firstNonSerializableCtor");
42 MethodInfo miCtor = JPF_java_lang_reflect_Constructor.getMethodInfo(env,superCtorRef);
43
44 if (frame == null){ // first time
45 int clsRef = env.getReferenceField(mthRef, "mdc");
46 ClassInfo ci = env.getReferredClassInfo( clsRef);
47
48 if (ci.isAbstract()){
49 env.throwException("java.lang.InstantiationException");
50 return MJIEnv.NULL;
51 }
52
53 int objRef = env.newObjectOfUncheckedClass(ci);
54 frame = miCtor.createDirectCallStackFrame(ti, 1);
55 frame.setReferenceArgument( 0, objRef, null);
56 frame.setLocalReferenceVariable(0, objRef); // (1) we store the reference as a local var for retrieval during reexec
57 ti.pushFrame(frame);
58
59 // check for & push required clinits
60 ci.pushRequiredClinits(ti);
61 env.repeatInvocation();
62 return MJIEnv.NULL;
63
64 } else { // re-execution,
65 int objRef = frame.getLocalVariable(0); // that's the object ref we stored in (1)
66 return objRef;
67 }
68 }
69 }