43972
|
1 |
/*
|
|
2 |
* Copyright (c) 2016, 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 org.graalvm.compiler.hotspot;
|
|
24 |
|
|
25 |
import org.graalvm.compiler.core.common.CompilationIdentifier;
|
|
26 |
import org.graalvm.compiler.core.common.CompilationRequestIdentifier;
|
|
27 |
import org.graalvm.compiler.debug.GraalError;
|
|
28 |
|
|
29 |
import jdk.vm.ci.hotspot.HotSpotCompilationRequest;
|
|
30 |
import jdk.vm.ci.runtime.JVMCICompiler;
|
|
31 |
|
|
32 |
/**
|
|
33 |
* {@link CompilationIdentifier} for a {@linkplain HotSpotCompilationRequest hotspot compilation
|
|
34 |
* request}.
|
|
35 |
*/
|
|
36 |
public class HotSpotCompilationIdentifier implements CompilationRequestIdentifier {
|
|
37 |
private final HotSpotCompilationRequest request;
|
|
38 |
|
|
39 |
public HotSpotCompilationIdentifier(HotSpotCompilationRequest request) {
|
|
40 |
this.request = request;
|
|
41 |
}
|
|
42 |
|
|
43 |
public boolean isOsrCompilation() {
|
|
44 |
return request.getEntryBCI() != JVMCICompiler.INVOCATION_ENTRY_BCI;
|
|
45 |
}
|
|
46 |
|
|
47 |
@Override
|
|
48 |
public final String toString() {
|
|
49 |
return toString(Verbosity.DETAILED);
|
|
50 |
}
|
|
51 |
|
|
52 |
@Override
|
|
53 |
public String toString(Verbosity verbosity) {
|
|
54 |
return buildString(new StringBuilder(), verbosity).toString();
|
|
55 |
}
|
|
56 |
|
|
57 |
protected StringBuilder buildString(StringBuilder sb, Verbosity verbosity) {
|
|
58 |
switch (verbosity) {
|
|
59 |
case ID:
|
|
60 |
buildID(sb);
|
|
61 |
break;
|
|
62 |
case NAME:
|
|
63 |
buildName(sb);
|
|
64 |
break;
|
|
65 |
case DETAILED:
|
|
66 |
buildID(sb);
|
|
67 |
sb.append('[');
|
|
68 |
buildName(sb);
|
|
69 |
if (isOsrCompilation()) {
|
|
70 |
sb.append("@");
|
|
71 |
sb.append(request.getEntryBCI());
|
|
72 |
}
|
|
73 |
sb.append(']');
|
|
74 |
break;
|
|
75 |
default:
|
|
76 |
throw new GraalError("unknown verbosity: " + verbosity);
|
|
77 |
}
|
|
78 |
return sb;
|
|
79 |
}
|
|
80 |
|
|
81 |
protected StringBuilder buildName(StringBuilder sb) {
|
|
82 |
return sb.append(request.getMethod().format("%H.%n(%p)"));
|
|
83 |
}
|
|
84 |
|
|
85 |
protected StringBuilder buildID(StringBuilder sb) {
|
|
86 |
if (isOsrCompilation()) {
|
|
87 |
sb.append("HotSpotOSRCompilation-");
|
|
88 |
} else {
|
|
89 |
sb.append("HotSpotCompilation-");
|
|
90 |
}
|
|
91 |
return sb.append(request.getId());
|
|
92 |
}
|
|
93 |
|
|
94 |
@Override
|
|
95 |
public HotSpotCompilationRequest getRequest() {
|
|
96 |
return request;
|
|
97 |
}
|
|
98 |
|
|
99 |
}
|