annotate graal/com.oracle.jvmci.asm/src/com/oracle/jvmci/asm/Label.java @ 21708:6df25b1418be

moved com.oracle.asm.** to jvmci-util.jar (JBS:GRAAL-53)
author Doug Simon <doug.simon@oracle.com>
date Wed, 03 Jun 2015 18:06:44 +0200
parents graal/com.oracle.graal.asm/src/com/oracle/graal/asm/Label.java@5a7b82c1514e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
1 /*
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
2 * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
4 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
8 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
13 * accompanied this code).
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
14 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
18 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
21 * questions.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
22 */
21708
6df25b1418be moved com.oracle.asm.** to jvmci-util.jar (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 17207
diff changeset
23 package com.oracle.jvmci.asm;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
24
10662
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents: 10657
diff changeset
25 import java.util.*;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
26
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
27 /**
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
28 * This class represents a label within assembly code.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
29 */
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
30 public final class Label {
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 6531
diff changeset
31
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
32 private int position = -1;
11892
4ac39f060a9d added block ids to Labels
Doug Simon <doug.simon@oracle.com>
parents: 10662
diff changeset
33 private int blockId = -1;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
34
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
35 /**
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 6531
diff changeset
36 * References to instructions that jump to this unresolved label. These instructions need to be
14034
36d7c19ff005 fixed formatting after renaming
twisti
parents: 14032
diff changeset
37 * patched when the label is bound using the {@link #patchInstructions(Assembler)} method.
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
38 */
11956
8a6d0cd7971b Label: allocate ArrayList lazily
Bernhard Urban <bernhard.urban@jku.at>
parents: 11892
diff changeset
39 private ArrayList<Integer> patchPositions = null;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
40
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
41 /**
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
42 * Returns the position of this label in the code buffer.
17207
5a7b82c1514e [SPARC] Add functionality to be able to do assembly in two passes (knowing offsets of forward branches)
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 14034
diff changeset
43 *
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
44 * @return the position
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
45 */
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
46 public int position() {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
47 assert position >= 0 : "Unbound label is being referenced";
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
48 return position;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
49 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
50
10662
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents: 10657
diff changeset
51 public Label() {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
52 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
53
11892
4ac39f060a9d added block ids to Labels
Doug Simon <doug.simon@oracle.com>
parents: 10662
diff changeset
54 public Label(int id) {
4ac39f060a9d added block ids to Labels
Doug Simon <doug.simon@oracle.com>
parents: 10662
diff changeset
55 blockId = id;
4ac39f060a9d added block ids to Labels
Doug Simon <doug.simon@oracle.com>
parents: 10662
diff changeset
56 }
4ac39f060a9d added block ids to Labels
Doug Simon <doug.simon@oracle.com>
parents: 10662
diff changeset
57
4ac39f060a9d added block ids to Labels
Doug Simon <doug.simon@oracle.com>
parents: 10662
diff changeset
58 public int getBlockId() {
4ac39f060a9d added block ids to Labels
Doug Simon <doug.simon@oracle.com>
parents: 10662
diff changeset
59 return blockId;
4ac39f060a9d added block ids to Labels
Doug Simon <doug.simon@oracle.com>
parents: 10662
diff changeset
60 }
4ac39f060a9d added block ids to Labels
Doug Simon <doug.simon@oracle.com>
parents: 10662
diff changeset
61
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
62 /**
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
63 * Binds the label to the specified position.
17207
5a7b82c1514e [SPARC] Add functionality to be able to do assembly in two passes (knowing offsets of forward branches)
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 14034
diff changeset
64 *
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
65 * @param pos the position
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
66 */
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
67 protected void bind(int pos) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
68 this.position = pos;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
69 assert isBound();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
70 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
71
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
72 public boolean isBound() {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
73 return position >= 0;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
74 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
75
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
76 public void addPatchAt(int branchLocation) {
10662
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents: 10657
diff changeset
77 assert !isBound() : "Label is already bound " + this + " " + branchLocation + " at position " + position;
11956
8a6d0cd7971b Label: allocate ArrayList lazily
Bernhard Urban <bernhard.urban@jku.at>
parents: 11892
diff changeset
78 if (patchPositions == null) {
8a6d0cd7971b Label: allocate ArrayList lazily
Bernhard Urban <bernhard.urban@jku.at>
parents: 11892
diff changeset
79 patchPositions = new ArrayList<>(2);
8a6d0cd7971b Label: allocate ArrayList lazily
Bernhard Urban <bernhard.urban@jku.at>
parents: 11892
diff changeset
80 }
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
81 patchPositions.add(branchLocation);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
82 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
83
14032
d1c1f103d42c renamed com.oracle.graal.asm.AbstractAssembler to com.oracle.graal.asm.Assembler
twisti
parents: 11956
diff changeset
84 protected void patchInstructions(Assembler masm) {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
85 assert isBound() : "Label should be bound";
11956
8a6d0cd7971b Label: allocate ArrayList lazily
Bernhard Urban <bernhard.urban@jku.at>
parents: 11892
diff changeset
86 if (patchPositions != null) {
8a6d0cd7971b Label: allocate ArrayList lazily
Bernhard Urban <bernhard.urban@jku.at>
parents: 11892
diff changeset
87 int target = position;
8a6d0cd7971b Label: allocate ArrayList lazily
Bernhard Urban <bernhard.urban@jku.at>
parents: 11892
diff changeset
88 for (int i = 0; i < patchPositions.size(); ++i) {
8a6d0cd7971b Label: allocate ArrayList lazily
Bernhard Urban <bernhard.urban@jku.at>
parents: 11892
diff changeset
89 int pos = patchPositions.get(i);
8a6d0cd7971b Label: allocate ArrayList lazily
Bernhard Urban <bernhard.urban@jku.at>
parents: 11892
diff changeset
90 masm.patchJumpTarget(pos, target);
8a6d0cd7971b Label: allocate ArrayList lazily
Bernhard Urban <bernhard.urban@jku.at>
parents: 11892
diff changeset
91 }
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
92 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
93 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
94
17207
5a7b82c1514e [SPARC] Add functionality to be able to do assembly in two passes (knowing offsets of forward branches)
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 14034
diff changeset
95 public void reset() {
5a7b82c1514e [SPARC] Add functionality to be able to do assembly in two passes (knowing offsets of forward branches)
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 14034
diff changeset
96 if (this.patchPositions != null) {
5a7b82c1514e [SPARC] Add functionality to be able to do assembly in two passes (knowing offsets of forward branches)
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 14034
diff changeset
97 this.patchPositions.clear();
5a7b82c1514e [SPARC] Add functionality to be able to do assembly in two passes (knowing offsets of forward branches)
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 14034
diff changeset
98 }
5a7b82c1514e [SPARC] Add functionality to be able to do assembly in two passes (knowing offsets of forward branches)
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 14034
diff changeset
99 this.position = -1;
5a7b82c1514e [SPARC] Add functionality to be able to do assembly in two passes (knowing offsets of forward branches)
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 14034
diff changeset
100 }
5a7b82c1514e [SPARC] Add functionality to be able to do assembly in two passes (knowing offsets of forward branches)
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 14034
diff changeset
101
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
102 @Override
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
103 public String toString() {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
104 return isBound() ? String.valueOf(position()) : "?";
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
105 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
106 }