comparison c1x4hotspotsrc/HotSpotVM/src/com/sun/hotspot/c1x/VMExits.java @ 1416:1b41af477605

Added HotSpotVM project Java source files.
author Thomas Wuerthinger <thomas.wuerthinger@gmail.com>
date Wed, 23 Jun 2010 16:36:58 +0200
parents
children 44efca8a02d6
comparison
equal deleted inserted replaced
1415:712c7ff1afc1 1416:1b41af477605
1 /*
2 * Copyright (c) 2009 Sun Microsystems, Inc. All rights reserved.
3 *
4 * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product
5 * that is described in this document. In particular, and without limitation, these intellectual property
6 * rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or
7 * more additional patents or pending patent applications in the U.S. and in other countries.
8 *
9 * U.S. Government Rights - Commercial software. Government users are subject to the Sun
10 * Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its
11 * supplements.
12 *
13 * Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or
14 * registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks
15 * are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the
16 * U.S. and other countries.
17 *
18 * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open
19 * Company, Ltd.
20 */
21
22 package com.sun.hotspot.c1x;
23
24 import com.sun.cri.ci.CiCompiler;
25 import com.sun.cri.ci.CiConstant;
26 import com.sun.cri.ci.CiKind;
27 import com.sun.cri.ci.CiResult;
28 import com.sun.cri.ri.RiConstantPool;
29 import com.sun.cri.ri.RiField;
30 import com.sun.cri.ri.RiMethod;
31 import com.sun.cri.ri.RiSignature;
32 import com.sun.cri.ri.RiType;
33
34 /**
35 *
36 * @author Thomas Wuerthinger
37 *
38 * Exits from the HotSpot VM into Java code.
39 *
40 */
41 public class VMExits {
42
43 public static void compileMethod(RiMethod method, int entry_bci) {
44
45 assert method instanceof RiMethod : "And YES, this assert is necessary and a potential life saver as this method is called from the VM ;-)";
46
47 System.out.println("compileMethod in Java code called!!");
48
49 CiCompiler compiler = Compiler.getCompiler();
50 CiResult result = compiler.compileMethod(method, null);
51
52 System.out.println("Compilation result: ");
53 if (result.bailout() != null) {
54 System.out.println("Bailout:");
55 result.bailout().printStackTrace();
56 } else {
57 System.out.println(result.targetMethod());
58 VMEntries.installCode(((HotSpotMethod)method).methodOop, result.targetMethod().targetCode(), result.targetMethod().frameSize());
59 }
60 }
61
62 public static RiMethod createRiMethod(Object methodOop) {
63 System.out.println("creating RiMethod object");
64 RiMethod m = new HotSpotMethod(methodOop);
65 System.out.println("returning " + m);
66 return m;
67 }
68
69 public static RiSignature createRiSignature(Object symbolOop) {
70 System.out.println("Creating RiSignature object");
71 String name = VMEntries.RiSignature_symbolToString(symbolOop);
72 System.out.println("Signature name: " + name);
73 return new HotSpotSignature(name);
74 }
75
76 public static RiField createRiField(RiType holder, Object nameSymbol, RiType type, int offset) {
77 System.out.println("creating RiField object");
78 return new HotSpotField(holder, nameSymbol, type, offset);
79 }
80
81 public static RiType createRiType(Object klassOop) {
82 System.out.println("creating RiType object");
83 return new HotSpotType(klassOop);
84 }
85
86 public static RiType createRiTypePrimitive(int basicType) {
87 System.out.println("Creating primitive type with basicType " + basicType);
88 CiKind kind = null;
89 switch (basicType) {
90 case 4:
91 kind = CiKind.Boolean;
92 break;
93 case 5:
94 kind = CiKind.Char;
95 break;
96 case 6:
97 kind = CiKind.Float;
98 break;
99 case 7:
100 kind = CiKind.Double;
101 break;
102 case 8:
103 kind = CiKind.Byte;
104 break;
105 case 9:
106 kind = CiKind.Short;
107 break;
108 case 10:
109 kind = CiKind.Int;
110 break;
111 case 11:
112 kind = CiKind.Long;
113 break;
114 case 14:
115 kind = CiKind.Void;
116 break;
117 default:
118 throw new IllegalArgumentException("Unknown basic type: " + basicType);
119 }
120 System.out.println("Chosen kind: " + kind);
121 return new HotSpotTypePrimitive(kind);
122 }
123
124 public static RiType createRiTypeUnresolved(Object symbolOop, Object accessingKlassOop) {
125 System.out.println("Creating unresolved RiType object");
126 String name = VMEntries.RiSignature_symbolToString(symbolOop);
127 System.out.println("Class name: " + name);
128 return new HotSpotTypeUnresolved(name);
129 }
130
131 public static RiConstantPool createRiConstantPool(Object constantPoolOop) {
132 System.out.println("creating RiConstantPool object");
133 return new HotSpotConstantPool(constantPoolOop);
134 }
135
136 public static CiConstant createCiConstantInt(int value) {
137 return CiConstant.forInt(value);
138 }
139
140 public static CiConstant createCiConstantLong(long value) {
141 return CiConstant.forLong(value);
142 }
143
144 public static CiConstant createCiConstantFloat(float value) {
145 return CiConstant.forFloat(value);
146 }
147
148 public static CiConstant createCiConstantDouble(double value) {
149 return CiConstant.forDouble(value);
150 }
151
152 public static CiConstant createCiConstantObject(Object value) {
153 return CiConstant.forObject(value);
154 }
155
156 public static void main(String[] args) throws InterruptedException {
157 System.out.println(C1XHotSpotTests.add(1, 2));
158 Thread.sleep(5000);
159 System.out.println(C1XHotSpotTests.add(1, 2));
160 }
161 }