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;
21 * @author Nastaran Shafiei <nastaran.shafiei@gmail.com>
23 public class FunctionObjectFactory {
25 public int getFunctionObject(int bsIdx, ThreadInfo ti, ClassInfo fiClassInfo, String samUniqueName, BootstrapMethodInfo bmi,
26 String[] freeVariableTypeNames, Object[] freeVariableValues) {
28 ClassLoaderInfo cli = bmi.enclosingClass.getClassLoaderInfo();
30 ClassInfo funcObjType = cli.getResolvedFuncObjType(bsIdx, fiClassInfo, samUniqueName, bmi, freeVariableTypeNames);
32 funcObjType.registerClass(ti);
34 Heap heap = ti.getHeap();
35 ElementInfo ei = heap.newObject(funcObjType, ti);
37 setFuncObjFields(ei, bmi, freeVariableTypeNames, freeVariableValues);
39 return ei.getObjectRef();
42 public void setFuncObjFields(ElementInfo funcObj, BootstrapMethodInfo bmi, String[] freeVarTypeNames, Object[] freeVarValues) {
43 Fields fields = funcObj.getFields();
45 for(int i = 0; i<freeVarTypeNames.length; i++) {
46 String typeName = freeVarTypeNames[i];
47 if (typeName.equals("byte")) {
48 fields.setByteValue(i, (Byte)freeVarValues[i]);
49 } else if (typeName.equals("char")) {
50 fields.setCharValue(i, (Character)freeVarValues[i]);
51 } else if (typeName.equals("short")) {
52 fields.setShortValue(i, (Short)freeVarValues[i]);
53 } else if (typeName.equals("int")) {
54 fields.setIntValue(i, (Integer)freeVarValues[i]);
55 } else if (typeName.equals("float")) {
56 fields.setFloatValue(i, (Float)freeVarValues[i]);
57 } else if (typeName.equals("long")) {
58 fields.setLongValue(i, (Long)freeVarValues[i]);
59 } else if (typeName.equals("double")) {
60 fields.setDoubleValue(i, (Double)freeVarValues[i]);
61 } else if (typeName.equals("boolean")) {
62 fields.setBooleanValue(i, (Boolean)freeVarValues[i]);
64 if(freeVarValues[i] == null) {
65 fields.setReferenceValue(i, MJIEnv.NULL);
67 int val = ((ElementInfo)freeVarValues[i]).getObjectRef();
68 fields.setReferenceValue(i, val);