Mercurial > hg > graal-compiler
comparison c1x4hotspotsrc/HotSpotVM/src/com/sun/hotspot/c1x/HotSpotSignature.java @ 1423:760213a60e8b
* rewrite of the code installation
* partial support for safepoints
* macro-based CiTargetMethod interface
* code stub support
author | Lukas Stadler <lukas.stadler@oracle.com> |
---|---|
date | Mon, 16 Aug 2010 18:59:36 -0700 |
parents | 3483ec571caf |
children | efba53f86c4f |
comparison
equal
deleted
inserted
replaced
1422:3483ec571caf | 1423:760213a60e8b |
---|---|
1 /* | |
2 * Copyright (c) 2009-2010 Sun Microsystems, Inc. All rights reserved. | |
3 * | |
4 * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product that is | |
5 * described in this document. In particular, and without limitation, these intellectual property rights may include one | |
6 * or more of the U.S. patents listed at http://www.sun.com/patents and one or more additional patents or pending patent | |
7 * applications in the U.S. and in other countries. | |
8 * | |
9 * U.S. Government Rights - Commercial software. Government users are subject to the Sun Microsystems, Inc. standard | |
10 * license agreement and applicable provisions of the FAR and its supplements. | |
11 * | |
12 * Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or registered | |
13 * trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks are used under license and | |
14 * are trademarks or registered trademarks of SPARC International, Inc. in the U.S. and other countries. | |
15 * | |
16 * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open Company, Ltd. | |
17 */ | |
1 package com.sun.hotspot.c1x; | 18 package com.sun.hotspot.c1x; |
2 | 19 |
3 import java.util.ArrayList; | 20 import java.util.*; |
4 import java.util.List; | |
5 | 21 |
6 import com.sun.cri.ci.CiKind; | 22 import com.sun.cri.ci.*; |
7 import com.sun.cri.ri.RiSignature; | 23 import com.sun.cri.ri.*; |
8 import com.sun.cri.ri.RiType; | |
9 | 24 |
10 public class HotSpotSignature implements RiSignature { | 25 /** |
26 * Represents a method signature. | |
27 * | |
28 * @author Thomas Wuerthinger, Lukas Stadler | |
29 */ | |
30 public class HotSpotSignature implements RiSignature, CompilerObject { | |
11 | 31 |
12 private final List<String> arguments = new ArrayList<String>(); | 32 private final List<String> arguments = new ArrayList<String>(); |
13 private final String returnType; | 33 private final String returnType; |
14 private final String originalString; | 34 private final String originalString; |
15 | 35 |
22 while (cur < signature.length() && signature.charAt(cur) != ')') { | 42 while (cur < signature.length() && signature.charAt(cur) != ')') { |
23 int nextCur = parseSignature(signature, cur); | 43 int nextCur = parseSignature(signature, cur); |
24 arguments.add(signature.substring(cur, nextCur)); | 44 arguments.add(signature.substring(cur, nextCur)); |
25 cur = nextCur; | 45 cur = nextCur; |
26 } | 46 } |
27 StringBuilder str = new StringBuilder(); | |
28 for (String param : arguments) { | |
29 str.append(param).append(", "); | |
30 } | |
31 Logger.log("signature " + signature + ": " + str); | |
32 | 47 |
33 cur++; | 48 cur++; |
34 int nextCur = parseSignature(signature, cur); | 49 int nextCur = parseSignature(signature, cur); |
35 returnType = signature.substring(cur, nextCur); | 50 returnType = signature.substring(cur, nextCur); |
36 assert nextCur == signature.length(); | 51 assert nextCur == signature.length(); |
38 returnType = null; | 53 returnType = null; |
39 } | 54 } |
40 } | 55 } |
41 | 56 |
42 private int parseSignature(String signature, int cur) { | 57 private int parseSignature(String signature, int cur) { |
58 char first; | |
59 do { | |
60 first = signature.charAt(cur++); | |
61 } while(first == '['); | |
43 | 62 |
44 char first = signature.charAt(cur); | |
45 switch (first) { | 63 switch (first) { |
46 case '[': | |
47 return parseSignature(signature, cur + 1); | |
48 case 'L': | 64 case 'L': |
49 while (signature.charAt(cur) != ';') | 65 while (signature.charAt(cur) != ';') |
50 cur++; | 66 cur++; |
51 cur++; | 67 cur++; |
52 break; | 68 break; |
57 case 'D': | 73 case 'D': |
58 case 'F': | 74 case 'F': |
59 case 'J': | 75 case 'J': |
60 case 'S': | 76 case 'S': |
61 case 'Z': | 77 case 'Z': |
62 cur++; | |
63 break; | 78 break; |
64 default: | 79 default: |
65 assert false; | 80 assert false; |
66 } | 81 } |
67 return cur; | 82 return cur; |
72 return arguments.size() + (withReceiver ? 1 : 0); | 87 return arguments.size() + (withReceiver ? 1 : 0); |
73 } | 88 } |
74 | 89 |
75 @Override | 90 @Override |
76 public CiKind argumentKindAt(int index) { | 91 public CiKind argumentKindAt(int index) { |
77 CiKind kind = CiKind.fromTypeString(arguments.get(index)); | 92 return CiKind.fromTypeString(arguments.get(index)); |
78 System.out.println("argument kind: " + index + " is " + kind); | |
79 return kind; | |
80 } | 93 } |
81 | 94 |
82 @Override | 95 @Override |
83 public int argumentSlots(boolean withReceiver) { | 96 public int argumentSlots(boolean withReceiver) { |
84 | 97 |
90 return argSlots + (withReceiver ? 1 : 0); | 103 return argSlots + (withReceiver ? 1 : 0); |
91 } | 104 } |
92 | 105 |
93 @Override | 106 @Override |
94 public RiType argumentTypeAt(int index, RiType accessingClass) { | 107 public RiType argumentTypeAt(int index, RiType accessingClass) { |
95 Class<?> accessor = null; | 108 long accessor = 0; |
96 if (accessingClass instanceof HotSpotType) { | 109 if (accessingClass instanceof HotSpotTypeResolved) { |
97 accessor = ((HotSpotType) accessingClass).klass; | 110 accessor = (Long) ((HotSpotTypeResolved) accessingClass).getVmId(); |
98 } | 111 } |
99 return Compiler.getVMEntries().RiSignature_lookupType(arguments.get(index), accessor); | 112 return Compiler.getVMEntries().RiSignature_lookupType(arguments.get(index), accessor); |
100 } | 113 } |
101 | 114 |
102 @Override | 115 @Override |
109 return CiKind.fromTypeString(returnType); | 122 return CiKind.fromTypeString(returnType); |
110 } | 123 } |
111 | 124 |
112 @Override | 125 @Override |
113 public RiType returnType(RiType accessingClass) { | 126 public RiType returnType(RiType accessingClass) { |
114 Class<?> accessor = null; | 127 long accessor = 0; |
115 if (accessingClass instanceof HotSpotType) { | 128 if (accessingClass instanceof HotSpotTypeResolved) { |
116 accessor = ((HotSpotType) accessingClass).klass; | 129 accessor = (Long) ((HotSpotTypeResolved) accessingClass).getVmId(); |
117 } | 130 } |
118 return Compiler.getVMEntries().RiSignature_lookupType(returnType, accessor); | 131 return Compiler.getVMEntries().RiSignature_lookupType(returnType, accessor); |
119 } | 132 } |
120 | 133 |
134 @Override | |
135 public String toString() { | |
136 return "HotSpotSignature<" + originalString + ">"; | |
137 } | |
138 | |
121 } | 139 } |