annotate jvmci/jdk.vm.ci.code/src/jdk/vm/ci/code/BytecodePosition.java @ 24234:ea6f94ab283b default tip

Added tag jvmci-0.36 for changeset 8128b98d4736
author Gilles Duboscq <gilles.m.duboscq@oracle.com>
date Mon, 18 Sep 2017 18:49:45 +0200
parents c968119ee980
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
22054
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
1 /*
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
2 * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
4 *
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
7 * published by the Free Software Foundation.
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
8 *
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
13 * accompanied this code).
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
14 *
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
18 *
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
21 * questions.
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
22 */
22672
1bbd4a7c274b Rename jdk.internal.jvmci to jdk.vm.ci
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22569
diff changeset
23 package jdk.vm.ci.code;
22054
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
24
22569
ec96f33a101d updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22054
diff changeset
25 import java.util.Objects;
22054
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
26
22672
1bbd4a7c274b Rename jdk.internal.jvmci to jdk.vm.ci
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22569
diff changeset
27 import jdk.vm.ci.meta.ResolvedJavaMethod;
22054
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
28
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
29 /**
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
30 * Represents a code position, that is, a chain of inlined methods with bytecode locations, that is
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
31 * communicated from the compiler to the runtime system. A code position can be used by the runtime
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
32 * system to reconstruct a source-level stack trace for exceptions and to create
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
33 * {@linkplain BytecodeFrame frames} for deoptimization.
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
34 */
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
35 public class BytecodePosition {
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
36
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
37 private final BytecodePosition caller;
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
38 private final ResolvedJavaMethod method;
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
39 private final int bci;
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
40
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
41 /**
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
42 * Constructs a new object representing a given parent/caller, a given method, and a given BCI.
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
43 *
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
44 * @param caller the parent position
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
45 * @param method the method
23770
c968119ee980 improved documentation of BytecodePosition API
Doug Simon <doug.simon@oracle.com>
parents: 23768
diff changeset
46 * @param bci a BCI such that {@code method.codeSize() == 0 || bci < method.getCodeSize()}. That
c968119ee980 improved documentation of BytecodePosition API
Doug Simon <doug.simon@oracle.com>
parents: 23768
diff changeset
47 * is, if code size is 0 then allow any value, otherwise the bci must be less than
c968119ee980 improved documentation of BytecodePosition API
Doug Simon <doug.simon@oracle.com>
parents: 23768
diff changeset
48 * the code size.
22054
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
49 */
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
50 public BytecodePosition(BytecodePosition caller, ResolvedJavaMethod method, int bci) {
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
51 assert method != null;
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
52 this.caller = caller;
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
53 this.method = method;
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
54 this.bci = bci;
23768
be0d95e99204 illegal bci in BytecodePosition causes IllegalArgumentException
Doug Simon <doug.simon@oracle.com>
parents: 23756
diff changeset
55 int codeSize = method.getCodeSize();
be0d95e99204 illegal bci in BytecodePosition causes IllegalArgumentException
Doug Simon <doug.simon@oracle.com>
parents: 23756
diff changeset
56 if (codeSize != 0 && bci >= codeSize) {
be0d95e99204 illegal bci in BytecodePosition causes IllegalArgumentException
Doug Simon <doug.simon@oracle.com>
parents: 23756
diff changeset
57 throw new IllegalArgumentException(String.format("bci %d is out of range for %s %d bytes", bci, method.format("%H.%n(%p)"), codeSize));
23756
d64936a16a13 Disallow too large bci in BytecodePosition
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
58 }
22054
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
59 }
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
60
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
61 /**
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
62 * Converts this code position to a string representation.
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
63 *
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
64 * @return a string representation of this code position
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
65 */
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
66 @Override
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
67 public String toString() {
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
68 return CodeUtil.append(new StringBuilder(100), this).toString();
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
69 }
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
70
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
71 /**
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
72 * Deep equality test.
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
73 */
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
74 @Override
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
75 public boolean equals(Object obj) {
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
76 if (obj == this) {
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
77 return true;
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
78 }
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
79 if (obj != null && getClass() == obj.getClass()) {
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
80 BytecodePosition that = (BytecodePosition) obj;
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
81 if (this.bci == that.bci && Objects.equals(this.getMethod(), that.getMethod()) && Objects.equals(this.caller, that.caller)) {
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
82 return true;
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
83 }
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
84 }
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
85 return false;
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
86 }
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
87
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
88 @Override
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
89 public int hashCode() {
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
90 return getBCI();
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
91 }
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
92
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
93 /**
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
94 * @return The location within the method, as a bytecode index. The constant {@code -1} may be
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
95 * used to indicate the location is unknown, for example within code synthesized by the
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
96 * compiler.
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
97 */
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
98 public int getBCI() {
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
99 return bci;
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
100 }
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
101
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
102 /**
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
103 * @return The runtime interface method for this position.
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
104 */
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
105 public ResolvedJavaMethod getMethod() {
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
106 return method;
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
107 }
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
108
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
109 /**
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
110 * The position where this position has been called, {@code null} if none.
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
111 */
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
112 public BytecodePosition getCaller() {
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
113 return caller;
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
114 }
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
115
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
116 /**
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
117 * Adds a caller to the current position returning the new position.
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
118 */
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
119 public BytecodePosition addCaller(BytecodePosition link) {
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
120 if (getCaller() == null) {
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
121 return new BytecodePosition(link, getMethod(), getBCI());
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
122 } else {
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
123 return new BytecodePosition(getCaller().addCaller(link), getMethod(), getBCI());
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
124 }
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
125 }
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents:
diff changeset
126 }