Mercurial > hg > truffle
annotate graal/com.oracle.graal.lir/src/com/oracle/graal/lir/LIRIntrospection.java @ 12503:d7f8dd4fe876
minor reformatting based on 'mx eclipseformat'
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Mon, 21 Oct 2013 18:10:32 +0200 |
parents | b04b94b71649 |
children | 21663230ba88 |
rev | line source |
---|---|
5733
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
1 /* |
8164
25fd899b979f
Move reusable parts of LIRInstructionClass into base class.
Roland Schatz <roland.schatz@oracle.com>
parents:
8136
diff
changeset
|
2 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. |
5733
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
4 * |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
8 * |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
13 * accompanied this code). |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
14 * |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
18 * |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
21 * questions. |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
22 */ |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
23 package com.oracle.graal.lir; |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
5858
diff
changeset
|
24 |
8191
0e583eb213f1
Check that OperandFlags is consistent with declared type of operand field.
Roland Schatz <roland.schatz@oracle.com>
parents:
8169
diff
changeset
|
25 import static com.oracle.graal.lir.LIRInstruction.OperandFlag.*; |
0e583eb213f1
Check that OperandFlags is consistent with declared type of operand field.
Roland Schatz <roland.schatz@oracle.com>
parents:
8169
diff
changeset
|
26 |
5733
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
27 import java.lang.annotation.*; |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
28 import java.lang.reflect.*; |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
29 import java.util.*; |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
30 import java.util.Map.Entry; |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
31 |
8191
0e583eb213f1
Check that OperandFlags is consistent with declared type of operand field.
Roland Schatz <roland.schatz@oracle.com>
parents:
8169
diff
changeset
|
32 import com.oracle.graal.api.code.*; |
5733
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
33 import com.oracle.graal.api.meta.*; |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
34 import com.oracle.graal.graph.*; |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
35 import com.oracle.graal.lir.LIRInstruction.OperandFlag; |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
36 import com.oracle.graal.lir.LIRInstruction.OperandMode; |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
37 import com.oracle.graal.lir.LIRInstruction.ValueProcedure; |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
38 |
8164
25fd899b979f
Move reusable parts of LIRInstructionClass into base class.
Roland Schatz <roland.schatz@oracle.com>
parents:
8136
diff
changeset
|
39 abstract class LIRIntrospection extends FieldIntrospection { |
5733
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
40 |
8164
25fd899b979f
Move reusable parts of LIRInstructionClass into base class.
Roland Schatz <roland.schatz@oracle.com>
parents:
8136
diff
changeset
|
41 private static final Class<Value> VALUE_CLASS = Value.class; |
25fd899b979f
Move reusable parts of LIRInstructionClass into base class.
Roland Schatz <roland.schatz@oracle.com>
parents:
8136
diff
changeset
|
42 private static final Class<Constant> CONSTANT_CLASS = Constant.class; |
11775
b04b94b71649
Finished PTX assembler and Register -> Variable conversion
Morris Meyer <morris.meyer@oracle.com>
parents:
10872
diff
changeset
|
43 private static final Class<Variable> VARIABLE_CLASS = Variable.class; |
8191
0e583eb213f1
Check that OperandFlags is consistent with declared type of operand field.
Roland Schatz <roland.schatz@oracle.com>
parents:
8169
diff
changeset
|
44 private static final Class<RegisterValue> REGISTER_VALUE_CLASS = RegisterValue.class; |
0e583eb213f1
Check that OperandFlags is consistent with declared type of operand field.
Roland Schatz <roland.schatz@oracle.com>
parents:
8169
diff
changeset
|
45 private static final Class<StackSlot> STACK_SLOT_CLASS = StackSlot.class; |
8164
25fd899b979f
Move reusable parts of LIRInstructionClass into base class.
Roland Schatz <roland.schatz@oracle.com>
parents:
8136
diff
changeset
|
46 private static final Class<Value[]> VALUE_ARRAY_CLASS = Value[].class; |
25fd899b979f
Move reusable parts of LIRInstructionClass into base class.
Roland Schatz <roland.schatz@oracle.com>
parents:
8136
diff
changeset
|
47 |
25fd899b979f
Move reusable parts of LIRInstructionClass into base class.
Roland Schatz <roland.schatz@oracle.com>
parents:
8136
diff
changeset
|
48 public LIRIntrospection(Class<?> clazz) { |
25fd899b979f
Move reusable parts of LIRInstructionClass into base class.
Roland Schatz <roland.schatz@oracle.com>
parents:
8136
diff
changeset
|
49 super(clazz); |
5733
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
50 } |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
51 |
8164
25fd899b979f
Move reusable parts of LIRInstructionClass into base class.
Roland Schatz <roland.schatz@oracle.com>
parents:
8136
diff
changeset
|
52 protected static class OperandModeAnnotation { |
5733
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
53 |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
54 public final ArrayList<Long> scalarOffsets = new ArrayList<>(); |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
55 public final ArrayList<Long> arrayOffsets = new ArrayList<>(); |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
56 public final Map<Long, EnumSet<OperandFlag>> flags = new HashMap<>(); |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
57 } |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
58 |
8164
25fd899b979f
Move reusable parts of LIRInstructionClass into base class.
Roland Schatz <roland.schatz@oracle.com>
parents:
8136
diff
changeset
|
59 protected abstract static class FieldScanner extends BaseFieldScanner { |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
5858
diff
changeset
|
60 |
5733
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
61 public final Map<Class<? extends Annotation>, OperandModeAnnotation> valueAnnotations; |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
62 public final ArrayList<Long> stateOffsets = new ArrayList<>(); |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
63 |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
64 public FieldScanner(CalcOffset calc) { |
5858
911315a3e642
Factor out common infrastructure from NodeClass and LIRInstructionClass
Christian Wimmer <christian.wimmer@oracle.com>
parents:
5796
diff
changeset
|
65 super(calc); |
5733
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
66 |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
67 valueAnnotations = new HashMap<>(); |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
68 } |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
69 |
8164
25fd899b979f
Move reusable parts of LIRInstructionClass into base class.
Roland Schatz <roland.schatz@oracle.com>
parents:
8136
diff
changeset
|
70 protected OperandModeAnnotation getOperandModeAnnotation(Field field) { |
5733
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
71 OperandModeAnnotation result = null; |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
5858
diff
changeset
|
72 for (Entry<Class<? extends Annotation>, OperandModeAnnotation> entry : valueAnnotations.entrySet()) { |
5733
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
73 Annotation annotation = field.getAnnotation(entry.getKey()); |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
74 if (annotation != null) { |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
75 assert result == null : "Field has two operand mode annotations: " + field; |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
76 result = entry.getValue(); |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
77 } |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
78 } |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
79 return result; |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
80 } |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
81 |
8164
25fd899b979f
Move reusable parts of LIRInstructionClass into base class.
Roland Schatz <roland.schatz@oracle.com>
parents:
8136
diff
changeset
|
82 protected abstract EnumSet<OperandFlag> getFlags(Field field); |
5733
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
83 |
5858
911315a3e642
Factor out common infrastructure from NodeClass and LIRInstructionClass
Christian Wimmer <christian.wimmer@oracle.com>
parents:
5796
diff
changeset
|
84 @Override |
911315a3e642
Factor out common infrastructure from NodeClass and LIRInstructionClass
Christian Wimmer <christian.wimmer@oracle.com>
parents:
5796
diff
changeset
|
85 protected void scanField(Field field, Class<?> type, long offset) { |
8136
c66aa27ef4da
Reenable patching of optimized and static calls but without out-of-line stubs.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
7942
diff
changeset
|
86 if (VALUE_CLASS.isAssignableFrom(type) && type != CONSTANT_CLASS) { |
7942
1c05f6f747d3
Remove access modifier restriction for allocatable values.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
7839
diff
changeset
|
87 assert !Modifier.isFinal(field.getModifiers()) : "Value field must not be declared final because it is modified by register allocator: " + field; |
5858
911315a3e642
Factor out common infrastructure from NodeClass and LIRInstructionClass
Christian Wimmer <christian.wimmer@oracle.com>
parents:
5796
diff
changeset
|
88 OperandModeAnnotation annotation = getOperandModeAnnotation(field); |
911315a3e642
Factor out common infrastructure from NodeClass and LIRInstructionClass
Christian Wimmer <christian.wimmer@oracle.com>
parents:
5796
diff
changeset
|
89 assert annotation != null : "Field must have operand mode annotation: " + field; |
911315a3e642
Factor out common infrastructure from NodeClass and LIRInstructionClass
Christian Wimmer <christian.wimmer@oracle.com>
parents:
5796
diff
changeset
|
90 annotation.scalarOffsets.add(offset); |
8191
0e583eb213f1
Check that OperandFlags is consistent with declared type of operand field.
Roland Schatz <roland.schatz@oracle.com>
parents:
8169
diff
changeset
|
91 EnumSet<OperandFlag> flags = getFlags(field); |
0e583eb213f1
Check that OperandFlags is consistent with declared type of operand field.
Roland Schatz <roland.schatz@oracle.com>
parents:
8169
diff
changeset
|
92 assert verifyFlags(field, type, flags); |
5858
911315a3e642
Factor out common infrastructure from NodeClass and LIRInstructionClass
Christian Wimmer <christian.wimmer@oracle.com>
parents:
5796
diff
changeset
|
93 annotation.flags.put(offset, getFlags(field)); |
911315a3e642
Factor out common infrastructure from NodeClass and LIRInstructionClass
Christian Wimmer <christian.wimmer@oracle.com>
parents:
5796
diff
changeset
|
94 } else if (VALUE_ARRAY_CLASS.isAssignableFrom(type)) { |
911315a3e642
Factor out common infrastructure from NodeClass and LIRInstructionClass
Christian Wimmer <christian.wimmer@oracle.com>
parents:
5796
diff
changeset
|
95 OperandModeAnnotation annotation = getOperandModeAnnotation(field); |
911315a3e642
Factor out common infrastructure from NodeClass and LIRInstructionClass
Christian Wimmer <christian.wimmer@oracle.com>
parents:
5796
diff
changeset
|
96 assert annotation != null : "Field must have operand mode annotation: " + field; |
911315a3e642
Factor out common infrastructure from NodeClass and LIRInstructionClass
Christian Wimmer <christian.wimmer@oracle.com>
parents:
5796
diff
changeset
|
97 annotation.arrayOffsets.add(offset); |
8191
0e583eb213f1
Check that OperandFlags is consistent with declared type of operand field.
Roland Schatz <roland.schatz@oracle.com>
parents:
8169
diff
changeset
|
98 EnumSet<OperandFlag> flags = getFlags(field); |
0e583eb213f1
Check that OperandFlags is consistent with declared type of operand field.
Roland Schatz <roland.schatz@oracle.com>
parents:
8169
diff
changeset
|
99 assert verifyFlags(field, type.getComponentType(), flags); |
5858
911315a3e642
Factor out common infrastructure from NodeClass and LIRInstructionClass
Christian Wimmer <christian.wimmer@oracle.com>
parents:
5796
diff
changeset
|
100 annotation.flags.put(offset, getFlags(field)); |
911315a3e642
Factor out common infrastructure from NodeClass and LIRInstructionClass
Christian Wimmer <christian.wimmer@oracle.com>
parents:
5796
diff
changeset
|
101 } else { |
911315a3e642
Factor out common infrastructure from NodeClass and LIRInstructionClass
Christian Wimmer <christian.wimmer@oracle.com>
parents:
5796
diff
changeset
|
102 assert getOperandModeAnnotation(field) == null : "Field must not have operand mode annotation: " + field; |
911315a3e642
Factor out common infrastructure from NodeClass and LIRInstructionClass
Christian Wimmer <christian.wimmer@oracle.com>
parents:
5796
diff
changeset
|
103 assert field.getAnnotation(LIRInstruction.State.class) == null : "Field must not have state annotation: " + field; |
911315a3e642
Factor out common infrastructure from NodeClass and LIRInstructionClass
Christian Wimmer <christian.wimmer@oracle.com>
parents:
5796
diff
changeset
|
104 dataOffsets.add(offset); |
911315a3e642
Factor out common infrastructure from NodeClass and LIRInstructionClass
Christian Wimmer <christian.wimmer@oracle.com>
parents:
5796
diff
changeset
|
105 } |
5733
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
106 } |
8191
0e583eb213f1
Check that OperandFlags is consistent with declared type of operand field.
Roland Schatz <roland.schatz@oracle.com>
parents:
8169
diff
changeset
|
107 |
0e583eb213f1
Check that OperandFlags is consistent with declared type of operand field.
Roland Schatz <roland.schatz@oracle.com>
parents:
8169
diff
changeset
|
108 private static boolean verifyFlags(Field field, Class<?> type, EnumSet<OperandFlag> flags) { |
0e583eb213f1
Check that OperandFlags is consistent with declared type of operand field.
Roland Schatz <roland.schatz@oracle.com>
parents:
8169
diff
changeset
|
109 if (flags.contains(REG)) { |
12503
d7f8dd4fe876
minor reformatting based on 'mx eclipseformat'
Doug Simon <doug.simon@oracle.com>
parents:
11775
diff
changeset
|
110 assert type.isAssignableFrom(REGISTER_VALUE_CLASS) || type.isAssignableFrom(VARIABLE_CLASS) : "Cannot assign RegisterValue / Variable to field with REG flag:" + field; |
8191
0e583eb213f1
Check that OperandFlags is consistent with declared type of operand field.
Roland Schatz <roland.schatz@oracle.com>
parents:
8169
diff
changeset
|
111 } |
0e583eb213f1
Check that OperandFlags is consistent with declared type of operand field.
Roland Schatz <roland.schatz@oracle.com>
parents:
8169
diff
changeset
|
112 if (flags.contains(STACK)) { |
0e583eb213f1
Check that OperandFlags is consistent with declared type of operand field.
Roland Schatz <roland.schatz@oracle.com>
parents:
8169
diff
changeset
|
113 assert type.isAssignableFrom(STACK_SLOT_CLASS) : "Cannot assign StackSlot to field with STACK flag:" + field; |
0e583eb213f1
Check that OperandFlags is consistent with declared type of operand field.
Roland Schatz <roland.schatz@oracle.com>
parents:
8169
diff
changeset
|
114 } |
0e583eb213f1
Check that OperandFlags is consistent with declared type of operand field.
Roland Schatz <roland.schatz@oracle.com>
parents:
8169
diff
changeset
|
115 if (flags.contains(CONST)) { |
0e583eb213f1
Check that OperandFlags is consistent with declared type of operand field.
Roland Schatz <roland.schatz@oracle.com>
parents:
8169
diff
changeset
|
116 assert type.isAssignableFrom(CONSTANT_CLASS) : "Cannot assign Constant to field with CONST flag:" + field; |
0e583eb213f1
Check that OperandFlags is consistent with declared type of operand field.
Roland Schatz <roland.schatz@oracle.com>
parents:
8169
diff
changeset
|
117 } |
0e583eb213f1
Check that OperandFlags is consistent with declared type of operand field.
Roland Schatz <roland.schatz@oracle.com>
parents:
8169
diff
changeset
|
118 return true; |
0e583eb213f1
Check that OperandFlags is consistent with declared type of operand field.
Roland Schatz <roland.schatz@oracle.com>
parents:
8169
diff
changeset
|
119 } |
5733
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
120 } |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
121 |
8164
25fd899b979f
Move reusable parts of LIRInstructionClass into base class.
Roland Schatz <roland.schatz@oracle.com>
parents:
8136
diff
changeset
|
122 protected static void forEach(Object obj, int directCount, long[] offsets, OperandMode mode, EnumSet<OperandFlag>[] flags, ValueProcedure proc) { |
5733
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
123 for (int i = 0; i < offsets.length; i++) { |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
124 assert LIRInstruction.ALLOWED_FLAGS.get(mode).containsAll(flags[i]); |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
125 |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
126 if (i < directCount) { |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
127 Value value = getValue(obj, offsets[i]); |
8165 | 128 if (value instanceof CompositeValue) { |
129 CompositeValue composite = (CompositeValue) value; | |
130 composite.forEachComponent(mode, proc); | |
5733
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
131 } else { |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
132 setValue(obj, offsets[i], proc.doValue(value, mode, flags[i])); |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
133 } |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
134 } else { |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
135 Value[] values = getValueArray(obj, offsets[i]); |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
136 for (int j = 0; j < values.length; j++) { |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
137 Value value = values[j]; |
8165 | 138 if (value instanceof CompositeValue) { |
139 CompositeValue composite = (CompositeValue) value; | |
140 composite.forEachComponent(mode, proc); | |
5733
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
141 } else { |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
142 values[j] = proc.doValue(value, mode, flags[i]); |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
143 } |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
144 } |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
145 } |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
146 } |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
147 } |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
148 |
8164
25fd899b979f
Move reusable parts of LIRInstructionClass into base class.
Roland Schatz <roland.schatz@oracle.com>
parents:
8136
diff
changeset
|
149 protected static Value getValue(Object obj, long offset) { |
5733
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
150 return (Value) unsafe.getObject(obj, offset); |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
151 } |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
152 |
8164
25fd899b979f
Move reusable parts of LIRInstructionClass into base class.
Roland Schatz <roland.schatz@oracle.com>
parents:
8136
diff
changeset
|
153 protected static void setValue(Object obj, long offset, Value value) { |
5733
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
154 unsafe.putObject(obj, offset, value); |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
155 } |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
156 |
8164
25fd899b979f
Move reusable parts of LIRInstructionClass into base class.
Roland Schatz <roland.schatz@oracle.com>
parents:
8136
diff
changeset
|
157 protected static Value[] getValueArray(Object obj, long offset) { |
5733
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
158 return (Value[]) unsafe.getObject(obj, offset); |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
159 } |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
160 |
8164
25fd899b979f
Move reusable parts of LIRInstructionClass into base class.
Roland Schatz <roland.schatz@oracle.com>
parents:
8136
diff
changeset
|
161 protected void appendValues(StringBuilder result, Object obj, String start, String end, String startMultiple, String endMultiple, String[] prefix, long[]... moffsets) { |
5733
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
162 int total = 0; |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
163 for (long[] offsets : moffsets) { |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
164 total += offsets.length; |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
165 } |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
166 if (total == 0) { |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
167 return; |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
168 } |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
169 |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
170 result.append(start); |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
171 if (total > 1) { |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
172 result.append(startMultiple); |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
173 } |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
174 String sep = ""; |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
175 for (int i = 0; i < moffsets.length; i++) { |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
176 long[] offsets = moffsets[i]; |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
177 |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
178 for (int j = 0; j < offsets.length; j++) { |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
179 result.append(sep).append(prefix[i]); |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
180 long offset = offsets[j]; |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
181 if (total > 1) { |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
182 result.append(fieldNames.get(offset)).append(": "); |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
183 } |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
184 result.append(getFieldString(obj, offset)); |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
185 sep = ", "; |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
186 } |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
187 } |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
188 if (total > 1) { |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
189 result.append(endMultiple); |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
190 } |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
191 result.append(end); |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
192 } |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
193 |
8164
25fd899b979f
Move reusable parts of LIRInstructionClass into base class.
Roland Schatz <roland.schatz@oracle.com>
parents:
8136
diff
changeset
|
194 protected String getFieldString(Object obj, long offset) { |
5733
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
195 Class<?> type = fieldTypes.get(offset); |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
196 if (type == int.class) { |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
197 return String.valueOf(unsafe.getInt(obj, offset)); |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
198 } else if (type == long.class) { |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
199 return String.valueOf(unsafe.getLong(obj, offset)); |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
200 } else if (type == boolean.class) { |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
201 return String.valueOf(unsafe.getBoolean(obj, offset)); |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
202 } else if (type == float.class) { |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
203 return String.valueOf(unsafe.getFloat(obj, offset)); |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
204 } else if (type == double.class) { |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
205 return String.valueOf(unsafe.getDouble(obj, offset)); |
10872
33a2ca7c3bc8
Support for byte fields in LIR instructions.
Roland Schatz <roland.schatz@oracle.com>
parents:
8191
diff
changeset
|
206 } else if (type == byte.class) { |
33a2ca7c3bc8
Support for byte fields in LIR instructions.
Roland Schatz <roland.schatz@oracle.com>
parents:
8191
diff
changeset
|
207 return String.valueOf(unsafe.getByte(obj, offset)); |
5733
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
208 } else if (!type.isPrimitive()) { |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
209 Object value = unsafe.getObject(obj, offset); |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
210 if (!type.isArray()) { |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
211 return String.valueOf(value); |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
212 } else if (type == int[].class) { |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
213 return Arrays.toString((int[]) value); |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
214 } else if (type == double[].class) { |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
215 return Arrays.toString((double[]) value); |
10872
33a2ca7c3bc8
Support for byte fields in LIR instructions.
Roland Schatz <roland.schatz@oracle.com>
parents:
8191
diff
changeset
|
216 } else if (type == byte[].class) { |
33a2ca7c3bc8
Support for byte fields in LIR instructions.
Roland Schatz <roland.schatz@oracle.com>
parents:
8191
diff
changeset
|
217 return Arrays.toString((byte[]) value); |
5733
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
218 } else if (!type.getComponentType().isPrimitive()) { |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
219 return Arrays.toString((Object[]) value); |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
220 } |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
221 } |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
222 assert false : "unhandled field type: " + type; |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
223 return ""; |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
224 } |
141b15521a39
use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
225 } |