1/*
2 * Copyright (c) 2015, 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 */
23package jdk.vm.ci.hotspot;
24
25import jdk.vm.ci.code.CompilationRequest;
26import jdk.vm.ci.code.CompilationRequestResult;
27
28/**
29 * HotSpot specific information about the result of a {@link CompilationRequest}.
30 */
31public final class HotSpotCompilationRequestResult implements CompilationRequestResult {
32
33    /**
34     * A user readable description of the failure.
35     *
36     * This field is read by the VM.
37     */
38    private final String failureMessage;
39
40    /**
41     * Whether this is a transient failure where retrying would help.
42     *
43     * This field is read by the VM.
44     */
45    private final boolean retry;
46
47    /**
48     * Number of bytecodes inlined into the compilation, exclusive of the bytecodes in the root
49     * method.
50     *
51     * This field is read by the VM.
52     */
53    private final int inlinedBytecodes;
54
55    private HotSpotCompilationRequestResult(String failureMessage, boolean retry, int inlinedBytecodes) {
56        this.failureMessage = failureMessage;
57        this.retry = retry;
58        this.inlinedBytecodes = inlinedBytecodes;
59    }
60
61    public Object getFailure() {
62        return failureMessage;
63    }
64
65    /**
66     * Creates a result representing a successful compilation.
67     *
68     * @param inlinedBytecodes number of bytecodes inlined into the compilation, exclusive of the
69     *            bytecodes in the root method
70     */
71    public static HotSpotCompilationRequestResult success(int inlinedBytecodes) {
72        return new HotSpotCompilationRequestResult(null, true, inlinedBytecodes);
73    }
74
75    /**
76     * Creates a result representing a failed compilation.
77     *
78     * @param failureMessage a description of the failure
79     * @param retry whether this is a transient failure where retrying may succeed
80     */
81    public static HotSpotCompilationRequestResult failure(String failureMessage, boolean retry) {
82        return new HotSpotCompilationRequestResult(failureMessage, retry, 0);
83    }
84
85    public String getFailureMessage() {
86        return failureMessage;
87    }
88
89    public boolean getRetry() {
90        return retry;
91    }
92
93    public int getInlinedBytecodes() {
94        return inlinedBytecodes;
95    }
96}
97