Mercurial > hg > graal-jvmci-8
comparison graal/com.oracle.max.graal.compiler/src/com/sun/c1x/asm/TargetMethodAssembler.java @ 2872:0341b6424579
Project renaming.
author | Thomas Wuerthinger <thomas@wuerthinger.net> |
---|---|
date | Wed, 08 Jun 2011 08:42:25 +0200 |
parents | graal/GraalCompiler/src/com/sun/c1x/asm/TargetMethodAssembler.java@1cd59ca9ac86 |
children |
comparison
equal
deleted
inserted
replaced
2871:d704eb526603 | 2872:0341b6424579 |
---|---|
1 /* | |
2 * Copyright (c) 2011, 2011, Oracle and/or its affiliates. All rights reserved. | |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
20 * or visit www.oracle.com if you need additional information or have any | |
21 * questions. | |
22 */ | |
23 package com.sun.c1x.asm; | |
24 | |
25 import java.util.*; | |
26 | |
27 import com.oracle.max.asm.*; | |
28 import com.sun.c1x.*; | |
29 import com.sun.c1x.debug.*; | |
30 import com.sun.c1x.lir.*; | |
31 import com.sun.c1x.util.*; | |
32 import com.sun.cri.ci.*; | |
33 import com.sun.cri.ri.*; | |
34 | |
35 public class TargetMethodAssembler { | |
36 public final AbstractAssembler asm; | |
37 public final CiTargetMethod targetMethod; | |
38 public List<ExceptionInfo> exceptionInfoList; | |
39 protected int lastSafepointPos; | |
40 | |
41 public TargetMethodAssembler(AbstractAssembler asm) { | |
42 this.asm = asm; | |
43 this.targetMethod = new CiTargetMethod(); | |
44 } | |
45 | |
46 public void setFrameSize(int frameSize) { | |
47 targetMethod.setFrameSize(frameSize); | |
48 } | |
49 | |
50 public CiTargetMethod.Mark recordMark(Object id, CiTargetMethod.Mark[] references) { | |
51 return targetMethod.recordMark(asm.codeBuffer.position(), id, references); | |
52 } | |
53 | |
54 public void blockComment(String s) { | |
55 targetMethod.addAnnotation(new CiTargetMethod.CodeComment(asm.codeBuffer.position(), s)); | |
56 } | |
57 | |
58 public CiTargetMethod finishTargetMethod(Object name, RiRuntime runtime, int registerRestoreEpilogueOffset, boolean isStub) { | |
59 // Install code, data and frame size | |
60 targetMethod.setTargetCode(asm.codeBuffer.close(false), asm.codeBuffer.position()); | |
61 targetMethod.setRegisterRestoreEpilogueOffset(registerRestoreEpilogueOffset); | |
62 | |
63 // Record exception handlers if they exist | |
64 if (exceptionInfoList != null) { | |
65 for (ExceptionInfo ei : exceptionInfoList) { | |
66 int codeOffset = ei.codeOffset; | |
67 targetMethod.recordExceptionHandler(codeOffset, -1, 0, ei.exceptionEdge.blockEntryPco, -1, null); | |
68 } | |
69 } | |
70 | |
71 if (C1XOptions.PrintMetrics) { | |
72 C1XMetrics.TargetMethods++; | |
73 C1XMetrics.CodeBytesEmitted += targetMethod.targetCodeSize(); | |
74 C1XMetrics.SafepointsEmitted += targetMethod.safepoints.size(); | |
75 C1XMetrics.DirectCallSitesEmitted += targetMethod.directCalls.size(); | |
76 C1XMetrics.IndirectCallSitesEmitted += targetMethod.indirectCalls.size(); | |
77 C1XMetrics.DataPatches += targetMethod.dataReferences.size(); | |
78 C1XMetrics.ExceptionHandlersEmitted += targetMethod.exceptionHandlers.size(); | |
79 } | |
80 | |
81 if (C1XOptions.PrintAssembly && !TTY.isSuppressed() && !isStub) { | |
82 Util.printSection("Target Method", Util.SECTION_CHARACTER); | |
83 TTY.println("Name: " + name); | |
84 TTY.println("Frame size: " + targetMethod.frameSize()); | |
85 TTY.println("Register size: " + asm.target.arch.registerReferenceMapBitCount); | |
86 | |
87 if (C1XOptions.PrintCodeBytes) { | |
88 Util.printSection("Code", Util.SUB_SECTION_CHARACTER); | |
89 TTY.println("Code: %d bytes", targetMethod.targetCodeSize()); | |
90 Util.printBytes(0L, targetMethod.targetCode(), 0, targetMethod.targetCodeSize(), C1XOptions.PrintAssemblyBytesPerLine); | |
91 } | |
92 | |
93 Util.printSection("Disassembly", Util.SUB_SECTION_CHARACTER); | |
94 String disassembly = runtime.disassemble(targetMethod); | |
95 TTY.println(disassembly); | |
96 boolean noDis = disassembly == null || disassembly.length() == 0; | |
97 | |
98 Util.printSection("Safepoints", Util.SUB_SECTION_CHARACTER); | |
99 for (CiTargetMethod.Safepoint x : targetMethod.safepoints) { | |
100 TTY.println(x.toString()); | |
101 if (noDis && x.debugInfo != null) { | |
102 TTY.println(CiUtil.indent(x.debugInfo.toString(), " ")); | |
103 } | |
104 } | |
105 | |
106 Util.printSection("Direct Call Sites", Util.SUB_SECTION_CHARACTER); | |
107 for (CiTargetMethod.Call x : targetMethod.directCalls) { | |
108 TTY.println(x.toString()); | |
109 if (noDis && x.debugInfo != null) { | |
110 TTY.println(CiUtil.indent(x.debugInfo.toString(), " ")); | |
111 } | |
112 } | |
113 | |
114 Util.printSection("Indirect Call Sites", Util.SUB_SECTION_CHARACTER); | |
115 for (CiTargetMethod.Call x : targetMethod.indirectCalls) { | |
116 TTY.println(x.toString()); | |
117 if (noDis && x.debugInfo != null) { | |
118 TTY.println(CiUtil.indent(x.debugInfo.toString(), " ")); | |
119 } | |
120 } | |
121 | |
122 Util.printSection("Data Patches", Util.SUB_SECTION_CHARACTER); | |
123 for (CiTargetMethod.DataPatch x : targetMethod.dataReferences) { | |
124 TTY.println(x.toString()); | |
125 } | |
126 | |
127 Util.printSection("Marks", Util.SUB_SECTION_CHARACTER); | |
128 for (CiTargetMethod.Mark x : targetMethod.marks) { | |
129 TTY.println(x.toString()); | |
130 } | |
131 | |
132 Util.printSection("Exception Handlers", Util.SUB_SECTION_CHARACTER); | |
133 for (CiTargetMethod.ExceptionHandler x : targetMethod.exceptionHandlers) { | |
134 TTY.println(x.toString()); | |
135 } | |
136 } | |
137 | |
138 return targetMethod; | |
139 } | |
140 | |
141 public void recordExceptionHandlers(int pcOffset, LIRDebugInfo info) { | |
142 if (info != null) { | |
143 if (info.exceptionEdge() != null) { | |
144 if (exceptionInfoList == null) { | |
145 exceptionInfoList = new ArrayList<ExceptionInfo>(4); | |
146 } | |
147 exceptionInfoList.add(new ExceptionInfo(pcOffset, info.exceptionEdge(), info.state.bci)); | |
148 } | |
149 } | |
150 } | |
151 | |
152 public void recordImplicitException(int pcOffset, LIRDebugInfo info) { | |
153 // record an implicit exception point | |
154 if (info != null) { | |
155 assert lastSafepointPos < pcOffset; | |
156 lastSafepointPos = pcOffset; | |
157 targetMethod.recordSafepoint(pcOffset, info.debugInfo()); | |
158 assert info.exceptionEdge() == null; | |
159 } | |
160 } | |
161 | |
162 public void recordDirectCall(int posBefore, int posAfter, Object target, LIRDebugInfo info) { | |
163 CiDebugInfo debugInfo = info != null ? info.debugInfo() : null; | |
164 assert lastSafepointPos < posAfter; | |
165 lastSafepointPos = posAfter; | |
166 targetMethod.recordCall(posBefore, target, debugInfo, true); | |
167 } | |
168 | |
169 public void recordIndirectCall(int posBefore, int posAfter, Object target, LIRDebugInfo info) { | |
170 CiDebugInfo debugInfo = info != null ? info.debugInfo() : null; | |
171 assert lastSafepointPos < posAfter; | |
172 lastSafepointPos = posAfter; | |
173 targetMethod.recordCall(posBefore, target, debugInfo, false); | |
174 } | |
175 | |
176 public void recordSafepoint(int pos, LIRDebugInfo info) { | |
177 // safepoints always need debug info | |
178 CiDebugInfo debugInfo = info.debugInfo(); | |
179 assert lastSafepointPos < pos; | |
180 lastSafepointPos = pos; | |
181 targetMethod.recordSafepoint(pos, debugInfo); | |
182 } | |
183 | |
184 public CiAddress recordDataReferenceInCode(CiConstant data) { | |
185 assert data != null; | |
186 | |
187 int pos = asm.codeBuffer.position(); | |
188 | |
189 if (C1XOptions.TraceRelocation) { | |
190 TTY.print("Data reference in code: pos = %d, data = %s", pos, data.toString()); | |
191 } | |
192 | |
193 targetMethod.recordDataReference(pos, data); | |
194 return CiAddress.Placeholder; | |
195 } | |
196 | |
197 public int lastSafepointPos() { | |
198 return lastSafepointPos; | |
199 } | |
200 } |