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