annotate graal/com.oracle.graal.lir/src/com/oracle/graal/lir/LIRIntrospection.java @ 19525:35481bcb5882

Remove LIRInstruction interface. Rename LIRInstructionBase to LIRInstruction.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Fri, 20 Feb 2015 18:08:53 +0100
parents d216de21bfe8
children a69a7c0e0ccc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5733
141b15521a39 use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
1 /*
18187
9619ba4daf4c Rename Constant to JavaConstant.
Roland Schatz <roland.schatz@oracle.com>
parents: 18163
diff changeset
2 * Copyright (c) 2012, 2014, 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.*;
15295
21663230ba88 Move FieldIntrospection to graal.compiler.common.
Josef Eisl <josef.eisl@jku.at>
parents: 12503
diff changeset
34 import com.oracle.graal.compiler.common.*;
5733
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
19470
d216de21bfe8 Fix unchecked warnings in NodeClass.
Roland Schatz <roland.schatz@oracle.com>
parents: 18261
diff changeset
38 abstract class LIRIntrospection<T> extends FieldIntrospection<T> {
5733
141b15521a39 use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
39
8164
25fd899b979f Move reusable parts of LIRInstructionClass into base class.
Roland Schatz <roland.schatz@oracle.com>
parents: 8136
diff changeset
40 private static final Class<Value> VALUE_CLASS = Value.class;
18187
9619ba4daf4c Rename Constant to JavaConstant.
Roland Schatz <roland.schatz@oracle.com>
parents: 18163
diff changeset
41 private static final Class<JavaConstant> CONSTANT_CLASS = JavaConstant.class;
11775
b04b94b71649 Finished PTX assembler and Register -> Variable conversion
Morris Meyer <morris.meyer@oracle.com>
parents: 10872
diff changeset
42 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
43 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
44 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
45 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
46
19470
d216de21bfe8 Fix unchecked warnings in NodeClass.
Roland Schatz <roland.schatz@oracle.com>
parents: 18261
diff changeset
47 public LIRIntrospection(Class<T> clazz) {
8164
25fd899b979f Move reusable parts of LIRInstructionClass into base class.
Roland Schatz <roland.schatz@oracle.com>
parents: 8136
diff changeset
48 super(clazz);
5733
141b15521a39 use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
49 }
141b15521a39 use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
50
17244
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
51 protected static class Values extends Fields {
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
52 private final int directCount;
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
53 private final EnumSet<OperandFlag>[] flags;
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
54
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
55 public Values(OperandModeAnnotation mode) {
17358
bf84afcd4b40 LIRIntrospection.Values: remove OperandMode mode.
Josef Eisl <josef.eisl@jku.at>
parents: 17324
diff changeset
56 this(mode.directCount, mode.values);
17244
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
57 }
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
58
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
59 @SuppressWarnings("unchecked")
17358
bf84afcd4b40 LIRIntrospection.Values: remove OperandMode mode.
Josef Eisl <josef.eisl@jku.at>
parents: 17324
diff changeset
60 public Values(int directCount, ArrayList<ValueFieldInfo> fields) {
17244
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
61 super(fields);
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
62 this.directCount = directCount;
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
63 flags = new EnumSet[fields.size()];
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
64 for (int i = 0; i < fields.size(); i++) {
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
65 flags[i] = fields.get(i).flags;
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
66 }
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
67 }
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
68
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
69 public int getDirectCount() {
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
70 return directCount;
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
71 }
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
72
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
73 public EnumSet<OperandFlag> getFlags(int i) {
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
74 return flags[i];
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
75 }
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
76
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
77 protected Value getValue(Object obj, int index) {
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
78 return (Value) getObject(obj, index);
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
79 }
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
80
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
81 protected void setValue(Object obj, int index, Value value) {
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
82 putObject(obj, index, value);
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
83 }
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
84
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
85 protected Value[] getValueArray(Object obj, int index) {
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
86 return (Value[]) getObject(obj, index);
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
87 }
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
88
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
89 protected void setValueArray(Object obj, int index, Value[] valueArray) {
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
90 putObject(obj, index, valueArray);
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
91 }
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
92 }
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
93
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
94 /**
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
95 * The component values in an {@link LIRInstruction} or {@link CompositeValue}.
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
96 */
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
97 protected Values values;
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
98
18261
d66c79acfeac refactored Fields class to make it usable for implementing custom serialization
Doug Simon <doug.simon@oracle.com>
parents: 18187
diff changeset
99 protected static class ValueFieldInfo extends FieldsScanner.FieldInfo {
17244
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
100
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
101 final EnumSet<OperandFlag> flags;
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
102
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
103 public ValueFieldInfo(long offset, String name, Class<?> type, EnumSet<OperandFlag> flags) {
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
104 super(offset, name, type);
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
105 assert VALUE_ARRAY_CLASS.isAssignableFrom(type) || VALUE_CLASS.isAssignableFrom(type);
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
106 this.flags = flags;
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
107 }
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
108
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
109 /**
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
110 * Sorts non-array fields before array fields.
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
111 */
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
112 @Override
18261
d66c79acfeac refactored Fields class to make it usable for implementing custom serialization
Doug Simon <doug.simon@oracle.com>
parents: 18187
diff changeset
113 public int compareTo(FieldsScanner.FieldInfo o) {
17244
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
114 if (VALUE_ARRAY_CLASS.isAssignableFrom(o.type)) {
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
115 if (!VALUE_ARRAY_CLASS.isAssignableFrom(type)) {
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
116 return -1;
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
117 }
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
118 } else {
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
119 if (VALUE_ARRAY_CLASS.isAssignableFrom(type)) {
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
120 return 1;
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
121 }
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
122 }
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
123 return super.compareTo(o);
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
124 }
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
125
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
126 @Override
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
127 public String toString() {
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
128 return super.toString() + flags;
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
129 }
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
130 }
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
131
8164
25fd899b979f Move reusable parts of LIRInstructionClass into base class.
Roland Schatz <roland.schatz@oracle.com>
parents: 8136
diff changeset
132 protected static class OperandModeAnnotation {
5733
141b15521a39 use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
133
17244
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
134 /**
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
135 * Number of non-array fields in {@link #values}.
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
136 */
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
137 public int directCount;
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
138 public final ArrayList<ValueFieldInfo> values = new ArrayList<>();
5733
141b15521a39 use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
139 }
141b15521a39 use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
140
18261
d66c79acfeac refactored Fields class to make it usable for implementing custom serialization
Doug Simon <doug.simon@oracle.com>
parents: 18187
diff changeset
141 protected abstract static class LIRFieldsScanner extends FieldsScanner {
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 5858
diff changeset
142
5733
141b15521a39 use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
143 public final Map<Class<? extends Annotation>, OperandModeAnnotation> valueAnnotations;
18261
d66c79acfeac refactored Fields class to make it usable for implementing custom serialization
Doug Simon <doug.simon@oracle.com>
parents: 18187
diff changeset
144 public final ArrayList<FieldsScanner.FieldInfo> states = new ArrayList<>();
5733
141b15521a39 use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
145
18261
d66c79acfeac refactored Fields class to make it usable for implementing custom serialization
Doug Simon <doug.simon@oracle.com>
parents: 18187
diff changeset
146 public LIRFieldsScanner(FieldsScanner.CalcOffset calc) {
5858
911315a3e642 Factor out common infrastructure from NodeClass and LIRInstructionClass
Christian Wimmer <christian.wimmer@oracle.com>
parents: 5796
diff changeset
147 super(calc);
5733
141b15521a39 use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
148 valueAnnotations = new HashMap<>();
141b15521a39 use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
149 }
141b15521a39 use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
150
8164
25fd899b979f Move reusable parts of LIRInstructionClass into base class.
Roland Schatz <roland.schatz@oracle.com>
parents: 8136
diff changeset
151 protected OperandModeAnnotation getOperandModeAnnotation(Field field) {
5733
141b15521a39 use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
152 OperandModeAnnotation result = null;
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 5858
diff changeset
153 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
154 Annotation annotation = field.getAnnotation(entry.getKey());
141b15521a39 use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
155 if (annotation != null) {
141b15521a39 use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
156 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
157 result = entry.getValue();
141b15521a39 use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
158 }
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 return result;
141b15521a39 use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
161 }
141b15521a39 use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
162
8164
25fd899b979f Move reusable parts of LIRInstructionClass into base class.
Roland Schatz <roland.schatz@oracle.com>
parents: 8136
diff changeset
163 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
164
5858
911315a3e642 Factor out common infrastructure from NodeClass and LIRInstructionClass
Christian Wimmer <christian.wimmer@oracle.com>
parents: 5796
diff changeset
165 @Override
17244
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
166 protected void scanField(Field field, long offset) {
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
167 Class<?> type = field.getType();
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
168 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
169 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
170 OperandModeAnnotation annotation = getOperandModeAnnotation(field);
911315a3e642 Factor out common infrastructure from NodeClass and LIRInstructionClass
Christian Wimmer <christian.wimmer@oracle.com>
parents: 5796
diff changeset
171 assert annotation != null : "Field must have operand mode annotation: " + field;
8191
0e583eb213f1 Check that OperandFlags is consistent with declared type of operand field.
Roland Schatz <roland.schatz@oracle.com>
parents: 8169
diff changeset
172 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
173 assert verifyFlags(field, type, flags);
17244
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
174 annotation.values.add(new ValueFieldInfo(offset, field.getName(), type, flags));
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
175 annotation.directCount++;
5858
911315a3e642 Factor out common infrastructure from NodeClass and LIRInstructionClass
Christian Wimmer <christian.wimmer@oracle.com>
parents: 5796
diff changeset
176 } 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
177 OperandModeAnnotation annotation = getOperandModeAnnotation(field);
911315a3e642 Factor out common infrastructure from NodeClass and LIRInstructionClass
Christian Wimmer <christian.wimmer@oracle.com>
parents: 5796
diff changeset
178 assert annotation != null : "Field must have operand mode annotation: " + field;
8191
0e583eb213f1 Check that OperandFlags is consistent with declared type of operand field.
Roland Schatz <roland.schatz@oracle.com>
parents: 8169
diff changeset
179 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
180 assert verifyFlags(field, type.getComponentType(), flags);
17244
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
181 annotation.values.add(new ValueFieldInfo(offset, field.getName(), type, flags));
5858
911315a3e642 Factor out common infrastructure from NodeClass and LIRInstructionClass
Christian Wimmer <christian.wimmer@oracle.com>
parents: 5796
diff changeset
182 } else {
911315a3e642 Factor out common infrastructure from NodeClass and LIRInstructionClass
Christian Wimmer <christian.wimmer@oracle.com>
parents: 5796
diff changeset
183 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
184 assert field.getAnnotation(LIRInstruction.State.class) == null : "Field must not have state annotation: " + field;
18261
d66c79acfeac refactored Fields class to make it usable for implementing custom serialization
Doug Simon <doug.simon@oracle.com>
parents: 18187
diff changeset
185 super.scanField(field, offset);
5858
911315a3e642 Factor out common infrastructure from NodeClass and LIRInstructionClass
Christian Wimmer <christian.wimmer@oracle.com>
parents: 5796
diff changeset
186 }
5733
141b15521a39 use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
187 }
8191
0e583eb213f1 Check that OperandFlags is consistent with declared type of operand field.
Roland Schatz <roland.schatz@oracle.com>
parents: 8169
diff changeset
188
0e583eb213f1 Check that OperandFlags is consistent with declared type of operand field.
Roland Schatz <roland.schatz@oracle.com>
parents: 8169
diff changeset
189 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
190 if (flags.contains(REG)) {
12503
d7f8dd4fe876 minor reformatting based on 'mx eclipseformat'
Doug Simon <doug.simon@oracle.com>
parents: 11775
diff changeset
191 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
192 }
0e583eb213f1 Check that OperandFlags is consistent with declared type of operand field.
Roland Schatz <roland.schatz@oracle.com>
parents: 8169
diff changeset
193 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
194 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
195 }
0e583eb213f1 Check that OperandFlags is consistent with declared type of operand field.
Roland Schatz <roland.schatz@oracle.com>
parents: 8169
diff changeset
196 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
197 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
198 }
0e583eb213f1 Check that OperandFlags is consistent with declared type of operand field.
Roland Schatz <roland.schatz@oracle.com>
parents: 8169
diff changeset
199 return true;
0e583eb213f1 Check that OperandFlags is consistent with declared type of operand field.
Roland Schatz <roland.schatz@oracle.com>
parents: 8169
diff changeset
200 }
5733
141b15521a39 use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
201 }
141b15521a39 use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
202
17287
0f8b1fb632df Remove InstructionValueProcedureBase (superseded by InstructionValueProcedure).
Josef Eisl <josef.eisl@jku.at>
parents: 17246
diff changeset
203 protected static void forEach(LIRInstruction inst, Values values, OperandMode mode, InstructionValueProcedure proc) {
17244
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
204 for (int i = 0; i < values.getCount(); i++) {
19525
35481bcb5882 Remove LIRInstruction interface. Rename LIRInstructionBase to LIRInstruction.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19470
diff changeset
205 assert LIRInstruction.ALLOWED_FLAGS.get(mode).containsAll(values.getFlags(i));
16740
bc1b601dabc9 Create LIRIntrospection.forEachComponent (copy of LIRIntrospection.forEach).
Josef Eisl <josef.eisl@jku.at>
parents: 16661
diff changeset
206
17244
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
207 if (i < values.getDirectCount()) {
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
208 Value value = values.getValue(inst, i);
16740
bc1b601dabc9 Create LIRIntrospection.forEachComponent (copy of LIRIntrospection.forEach).
Josef Eisl <josef.eisl@jku.at>
parents: 16661
diff changeset
209 Value newValue;
bc1b601dabc9 Create LIRIntrospection.forEachComponent (copy of LIRIntrospection.forEach).
Josef Eisl <josef.eisl@jku.at>
parents: 16661
diff changeset
210 if (value instanceof CompositeValue) {
bc1b601dabc9 Create LIRIntrospection.forEachComponent (copy of LIRIntrospection.forEach).
Josef Eisl <josef.eisl@jku.at>
parents: 16661
diff changeset
211 CompositeValue composite = (CompositeValue) value;
bc1b601dabc9 Create LIRIntrospection.forEachComponent (copy of LIRIntrospection.forEach).
Josef Eisl <josef.eisl@jku.at>
parents: 16661
diff changeset
212 newValue = composite.forEachComponent(inst, mode, proc);
bc1b601dabc9 Create LIRIntrospection.forEachComponent (copy of LIRIntrospection.forEach).
Josef Eisl <josef.eisl@jku.at>
parents: 16661
diff changeset
213 } else {
17287
0f8b1fb632df Remove InstructionValueProcedureBase (superseded by InstructionValueProcedure).
Josef Eisl <josef.eisl@jku.at>
parents: 17246
diff changeset
214 newValue = proc.doValue(inst, value, mode, values.getFlags(i));
16740
bc1b601dabc9 Create LIRIntrospection.forEachComponent (copy of LIRIntrospection.forEach).
Josef Eisl <josef.eisl@jku.at>
parents: 16661
diff changeset
215 }
16742
6052c5456170 LIRIntrospection.forEach: write back only if value has changed.
Josef Eisl <josef.eisl@jku.at>
parents: 16741
diff changeset
216 if (!value.identityEquals(newValue)) {
17244
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
217 values.setValue(inst, i, newValue);
16742
6052c5456170 LIRIntrospection.forEach: write back only if value has changed.
Josef Eisl <josef.eisl@jku.at>
parents: 16741
diff changeset
218 }
16740
bc1b601dabc9 Create LIRIntrospection.forEachComponent (copy of LIRIntrospection.forEach).
Josef Eisl <josef.eisl@jku.at>
parents: 16661
diff changeset
219 } else {
17244
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
220 Value[] valueArray = values.getValueArray(inst, i);
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
221 for (int j = 0; j < valueArray.length; j++) {
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
222 Value value = valueArray[j];
16740
bc1b601dabc9 Create LIRIntrospection.forEachComponent (copy of LIRIntrospection.forEach).
Josef Eisl <josef.eisl@jku.at>
parents: 16661
diff changeset
223 Value newValue;
bc1b601dabc9 Create LIRIntrospection.forEachComponent (copy of LIRIntrospection.forEach).
Josef Eisl <josef.eisl@jku.at>
parents: 16661
diff changeset
224 if (value instanceof CompositeValue) {
bc1b601dabc9 Create LIRIntrospection.forEachComponent (copy of LIRIntrospection.forEach).
Josef Eisl <josef.eisl@jku.at>
parents: 16661
diff changeset
225 CompositeValue composite = (CompositeValue) value;
bc1b601dabc9 Create LIRIntrospection.forEachComponent (copy of LIRIntrospection.forEach).
Josef Eisl <josef.eisl@jku.at>
parents: 16661
diff changeset
226 newValue = composite.forEachComponent(inst, mode, proc);
bc1b601dabc9 Create LIRIntrospection.forEachComponent (copy of LIRIntrospection.forEach).
Josef Eisl <josef.eisl@jku.at>
parents: 16661
diff changeset
227 } else {
17287
0f8b1fb632df Remove InstructionValueProcedureBase (superseded by InstructionValueProcedure).
Josef Eisl <josef.eisl@jku.at>
parents: 17246
diff changeset
228 newValue = proc.doValue(inst, value, mode, values.getFlags(i));
16740
bc1b601dabc9 Create LIRIntrospection.forEachComponent (copy of LIRIntrospection.forEach).
Josef Eisl <josef.eisl@jku.at>
parents: 16661
diff changeset
229 }
16742
6052c5456170 LIRIntrospection.forEach: write back only if value has changed.
Josef Eisl <josef.eisl@jku.at>
parents: 16741
diff changeset
230 if (!value.identityEquals(newValue)) {
17244
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
231 valueArray[j] = newValue;
16742
6052c5456170 LIRIntrospection.forEach: write back only if value has changed.
Josef Eisl <josef.eisl@jku.at>
parents: 16741
diff changeset
232 }
16740
bc1b601dabc9 Create LIRIntrospection.forEachComponent (copy of LIRIntrospection.forEach).
Josef Eisl <josef.eisl@jku.at>
parents: 16661
diff changeset
233 }
bc1b601dabc9 Create LIRIntrospection.forEachComponent (copy of LIRIntrospection.forEach).
Josef Eisl <josef.eisl@jku.at>
parents: 16661
diff changeset
234 }
bc1b601dabc9 Create LIRIntrospection.forEachComponent (copy of LIRIntrospection.forEach).
Josef Eisl <josef.eisl@jku.at>
parents: 16661
diff changeset
235 }
bc1b601dabc9 Create LIRIntrospection.forEachComponent (copy of LIRIntrospection.forEach).
Josef Eisl <josef.eisl@jku.at>
parents: 16661
diff changeset
236 }
bc1b601dabc9 Create LIRIntrospection.forEachComponent (copy of LIRIntrospection.forEach).
Josef Eisl <josef.eisl@jku.at>
parents: 16661
diff changeset
237
17287
0f8b1fb632df Remove InstructionValueProcedureBase (superseded by InstructionValueProcedure).
Josef Eisl <josef.eisl@jku.at>
parents: 17246
diff changeset
238 protected static CompositeValue forEachComponent(LIRInstruction inst, CompositeValue obj, Values values, OperandMode mode, InstructionValueProcedure proc) {
16741
705cebda4776 Clone CompositeValue in LIRIntrospection.forEachComponent().
Josef Eisl <josef.eisl@jku.at>
parents: 16740
diff changeset
239 CompositeValue newCompValue = null;
17244
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
240 for (int i = 0; i < values.getCount(); i++) {
19525
35481bcb5882 Remove LIRInstruction interface. Rename LIRInstructionBase to LIRInstruction.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19470
diff changeset
241 assert LIRInstruction.ALLOWED_FLAGS.get(mode).containsAll(values.getFlags(i));
16138
f315b1c0a590 Introduce InstructionValueProcedure.
Josef Eisl <josef.eisl@jku.at>
parents: 15295
diff changeset
242
17244
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
243 if (i < values.getDirectCount()) {
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
244 Value value = values.getValue(obj, i);
16740
bc1b601dabc9 Create LIRIntrospection.forEachComponent (copy of LIRIntrospection.forEach).
Josef Eisl <josef.eisl@jku.at>
parents: 16661
diff changeset
245 Value newValue;
16138
f315b1c0a590 Introduce InstructionValueProcedure.
Josef Eisl <josef.eisl@jku.at>
parents: 15295
diff changeset
246 if (value instanceof CompositeValue) {
f315b1c0a590 Introduce InstructionValueProcedure.
Josef Eisl <josef.eisl@jku.at>
parents: 15295
diff changeset
247 CompositeValue composite = (CompositeValue) value;
16740
bc1b601dabc9 Create LIRIntrospection.forEachComponent (copy of LIRIntrospection.forEach).
Josef Eisl <josef.eisl@jku.at>
parents: 16661
diff changeset
248 newValue = composite.forEachComponent(inst, mode, proc);
16138
f315b1c0a590 Introduce InstructionValueProcedure.
Josef Eisl <josef.eisl@jku.at>
parents: 15295
diff changeset
249 } else {
17287
0f8b1fb632df Remove InstructionValueProcedureBase (superseded by InstructionValueProcedure).
Josef Eisl <josef.eisl@jku.at>
parents: 17246
diff changeset
250 newValue = proc.doValue(inst, value, mode, values.getFlags(i));
16138
f315b1c0a590 Introduce InstructionValueProcedure.
Josef Eisl <josef.eisl@jku.at>
parents: 15295
diff changeset
251 }
16741
705cebda4776 Clone CompositeValue in LIRIntrospection.forEachComponent().
Josef Eisl <josef.eisl@jku.at>
parents: 16740
diff changeset
252 if (!value.identityEquals(newValue)) {
705cebda4776 Clone CompositeValue in LIRIntrospection.forEachComponent().
Josef Eisl <josef.eisl@jku.at>
parents: 16740
diff changeset
253 // lazy initialize
705cebda4776 Clone CompositeValue in LIRIntrospection.forEachComponent().
Josef Eisl <josef.eisl@jku.at>
parents: 16740
diff changeset
254 if (newCompValue == null) {
705cebda4776 Clone CompositeValue in LIRIntrospection.forEachComponent().
Josef Eisl <josef.eisl@jku.at>
parents: 16740
diff changeset
255 newCompValue = obj.clone();
705cebda4776 Clone CompositeValue in LIRIntrospection.forEachComponent().
Josef Eisl <josef.eisl@jku.at>
parents: 16740
diff changeset
256 }
17244
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
257 values.setValue(newCompValue, i, newValue);
16741
705cebda4776 Clone CompositeValue in LIRIntrospection.forEachComponent().
Josef Eisl <josef.eisl@jku.at>
parents: 16740
diff changeset
258 }
16138
f315b1c0a590 Introduce InstructionValueProcedure.
Josef Eisl <josef.eisl@jku.at>
parents: 15295
diff changeset
259 } else {
17244
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
260 Value[] valueArray = values.getValueArray(obj, i);
16741
705cebda4776 Clone CompositeValue in LIRIntrospection.forEachComponent().
Josef Eisl <josef.eisl@jku.at>
parents: 16740
diff changeset
261 Value[] newValues = null;
17244
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
262 for (int j = 0; j < valueArray.length; j++) {
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
263 Value value = valueArray[j];
16740
bc1b601dabc9 Create LIRIntrospection.forEachComponent (copy of LIRIntrospection.forEach).
Josef Eisl <josef.eisl@jku.at>
parents: 16661
diff changeset
264 Value newValue;
16138
f315b1c0a590 Introduce InstructionValueProcedure.
Josef Eisl <josef.eisl@jku.at>
parents: 15295
diff changeset
265 if (value instanceof CompositeValue) {
f315b1c0a590 Introduce InstructionValueProcedure.
Josef Eisl <josef.eisl@jku.at>
parents: 15295
diff changeset
266 CompositeValue composite = (CompositeValue) value;
16740
bc1b601dabc9 Create LIRIntrospection.forEachComponent (copy of LIRIntrospection.forEach).
Josef Eisl <josef.eisl@jku.at>
parents: 16661
diff changeset
267 newValue = composite.forEachComponent(inst, mode, proc);
16138
f315b1c0a590 Introduce InstructionValueProcedure.
Josef Eisl <josef.eisl@jku.at>
parents: 15295
diff changeset
268 } else {
17287
0f8b1fb632df Remove InstructionValueProcedureBase (superseded by InstructionValueProcedure).
Josef Eisl <josef.eisl@jku.at>
parents: 17246
diff changeset
269 newValue = proc.doValue(inst, value, mode, values.getFlags(i));
16138
f315b1c0a590 Introduce InstructionValueProcedure.
Josef Eisl <josef.eisl@jku.at>
parents: 15295
diff changeset
270 }
16741
705cebda4776 Clone CompositeValue in LIRIntrospection.forEachComponent().
Josef Eisl <josef.eisl@jku.at>
parents: 16740
diff changeset
271 if (!value.identityEquals(newValue)) {
705cebda4776 Clone CompositeValue in LIRIntrospection.forEachComponent().
Josef Eisl <josef.eisl@jku.at>
parents: 16740
diff changeset
272 // lazy initialize
705cebda4776 Clone CompositeValue in LIRIntrospection.forEachComponent().
Josef Eisl <josef.eisl@jku.at>
parents: 16740
diff changeset
273 if (newValues == null) {
705cebda4776 Clone CompositeValue in LIRIntrospection.forEachComponent().
Josef Eisl <josef.eisl@jku.at>
parents: 16740
diff changeset
274 if (newCompValue == null) {
705cebda4776 Clone CompositeValue in LIRIntrospection.forEachComponent().
Josef Eisl <josef.eisl@jku.at>
parents: 16740
diff changeset
275 newCompValue = obj.clone();
705cebda4776 Clone CompositeValue in LIRIntrospection.forEachComponent().
Josef Eisl <josef.eisl@jku.at>
parents: 16740
diff changeset
276 }
17244
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
277 newValues = values.getValueArray(newCompValue, i);
16741
705cebda4776 Clone CompositeValue in LIRIntrospection.forEachComponent().
Josef Eisl <josef.eisl@jku.at>
parents: 16740
diff changeset
278 }
705cebda4776 Clone CompositeValue in LIRIntrospection.forEachComponent().
Josef Eisl <josef.eisl@jku.at>
parents: 16740
diff changeset
279 newValues[j] = newValue;
705cebda4776 Clone CompositeValue in LIRIntrospection.forEachComponent().
Josef Eisl <josef.eisl@jku.at>
parents: 16740
diff changeset
280 }
16138
f315b1c0a590 Introduce InstructionValueProcedure.
Josef Eisl <josef.eisl@jku.at>
parents: 15295
diff changeset
281 }
f315b1c0a590 Introduce InstructionValueProcedure.
Josef Eisl <josef.eisl@jku.at>
parents: 15295
diff changeset
282 }
f315b1c0a590 Introduce InstructionValueProcedure.
Josef Eisl <josef.eisl@jku.at>
parents: 15295
diff changeset
283 }
16741
705cebda4776 Clone CompositeValue in LIRIntrospection.forEachComponent().
Josef Eisl <josef.eisl@jku.at>
parents: 16740
diff changeset
284 return newCompValue != null ? newCompValue : obj;
16138
f315b1c0a590 Introduce InstructionValueProcedure.
Josef Eisl <josef.eisl@jku.at>
parents: 15295
diff changeset
285 }
f315b1c0a590 Introduce InstructionValueProcedure.
Josef Eisl <josef.eisl@jku.at>
parents: 15295
diff changeset
286
17244
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
287 protected static void forEach(LIRInstruction inst, Object obj, Values values, OperandMode mode, ValuePositionProcedure proc, ValuePosition outerPosition) {
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
288 for (int i = 0; i < values.getCount(); i++) {
19525
35481bcb5882 Remove LIRInstruction interface. Rename LIRInstructionBase to LIRInstruction.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19470
diff changeset
289 assert LIRInstruction.ALLOWED_FLAGS.get(mode).containsAll(values.getFlags(i));
16279
69b9980ff5c2 Add ValuePositionProcedure and corresponding forEach methods.
Josef Eisl <josef.eisl@jku.at>
parents: 16214
diff changeset
290
17244
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
291 if (i < values.getDirectCount()) {
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
292 Value value = values.getValue(obj, i);
17324
012277a579ca LIRIntrospection: pass the right Values to ValuePositions.
Josef Eisl <josef.eisl@jku.at>
parents: 17287
diff changeset
293 doForValue(inst, values, mode, proc, outerPosition, i, ValuePosition.NO_SUBINDEX, value);
16279
69b9980ff5c2 Add ValuePositionProcedure and corresponding forEach methods.
Josef Eisl <josef.eisl@jku.at>
parents: 16214
diff changeset
294 } else {
17244
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
295 Value[] valueArray = values.getValueArray(obj, i);
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
296 for (int j = 0; j < valueArray.length; j++) {
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
297 Value value = valueArray[j];
17324
012277a579ca LIRIntrospection: pass the right Values to ValuePositions.
Josef Eisl <josef.eisl@jku.at>
parents: 17287
diff changeset
298 doForValue(inst, values, mode, proc, outerPosition, i, j, value);
16279
69b9980ff5c2 Add ValuePositionProcedure and corresponding forEach methods.
Josef Eisl <josef.eisl@jku.at>
parents: 16214
diff changeset
299 }
69b9980ff5c2 Add ValuePositionProcedure and corresponding forEach methods.
Josef Eisl <josef.eisl@jku.at>
parents: 16214
diff changeset
300 }
69b9980ff5c2 Add ValuePositionProcedure and corresponding forEach methods.
Josef Eisl <josef.eisl@jku.at>
parents: 16214
diff changeset
301 }
69b9980ff5c2 Add ValuePositionProcedure and corresponding forEach methods.
Josef Eisl <josef.eisl@jku.at>
parents: 16214
diff changeset
302 }
69b9980ff5c2 Add ValuePositionProcedure and corresponding forEach methods.
Josef Eisl <josef.eisl@jku.at>
parents: 16214
diff changeset
303
17324
012277a579ca LIRIntrospection: pass the right Values to ValuePositions.
Josef Eisl <josef.eisl@jku.at>
parents: 17287
diff changeset
304 private static void doForValue(LIRInstruction inst, Values values, OperandMode mode, ValuePositionProcedure proc, ValuePosition outerPosition, int index, int subIndex, Value value) {
17244
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
305 ValuePosition position = new ValuePosition(values, index, subIndex, outerPosition);
16281
14e56cef5be8 Start to make ValuePosition aware of CompositeValues.
Josef Eisl <josef.eisl@jku.at>
parents: 16279
diff changeset
306 if (value instanceof CompositeValue) {
14e56cef5be8 Start to make ValuePosition aware of CompositeValues.
Josef Eisl <josef.eisl@jku.at>
parents: 16279
diff changeset
307 CompositeValue composite = (CompositeValue) value;
14e56cef5be8 Start to make ValuePosition aware of CompositeValues.
Josef Eisl <josef.eisl@jku.at>
parents: 16279
diff changeset
308 composite.forEachComponent(inst, mode, proc, position);
14e56cef5be8 Start to make ValuePosition aware of CompositeValues.
Josef Eisl <josef.eisl@jku.at>
parents: 16279
diff changeset
309 } else {
14e56cef5be8 Start to make ValuePosition aware of CompositeValues.
Josef Eisl <josef.eisl@jku.at>
parents: 16279
diff changeset
310 proc.doValue(inst, position);
14e56cef5be8 Start to make ValuePosition aware of CompositeValues.
Josef Eisl <josef.eisl@jku.at>
parents: 16279
diff changeset
311 }
14e56cef5be8 Start to make ValuePosition aware of CompositeValues.
Josef Eisl <josef.eisl@jku.at>
parents: 16279
diff changeset
312 }
14e56cef5be8 Start to make ValuePosition aware of CompositeValues.
Josef Eisl <josef.eisl@jku.at>
parents: 16279
diff changeset
313
17246
44c5817156a9 fixed bug in LIRIntrospection.appendValues
Doug Simon <doug.simon@oracle.com>
parents: 17244
diff changeset
314 protected void appendValues(StringBuilder sb, Object obj, String start, String end, String startMultiple, String endMultiple, String[] prefix, Fields... fieldsList) {
5733
141b15521a39 use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
315 int total = 0;
17244
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
316 for (Fields fields : fieldsList) {
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
317 total += fields.getCount();
5733
141b15521a39 use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
318 }
141b15521a39 use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
319 if (total == 0) {
141b15521a39 use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
320 return;
141b15521a39 use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
321 }
141b15521a39 use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
322
17246
44c5817156a9 fixed bug in LIRIntrospection.appendValues
Doug Simon <doug.simon@oracle.com>
parents: 17244
diff changeset
323 sb.append(start);
5733
141b15521a39 use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
324 if (total > 1) {
17246
44c5817156a9 fixed bug in LIRIntrospection.appendValues
Doug Simon <doug.simon@oracle.com>
parents: 17244
diff changeset
325 sb.append(startMultiple);
5733
141b15521a39 use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
326 }
141b15521a39 use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
327 String sep = "";
17244
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
328 int i = 0;
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
329 for (Fields fields : fieldsList) {
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
330 for (int j = 0; j < fields.getCount(); j++) {
17246
44c5817156a9 fixed bug in LIRIntrospection.appendValues
Doug Simon <doug.simon@oracle.com>
parents: 17244
diff changeset
331 sb.append(sep).append(prefix[i]);
5733
141b15521a39 use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
332 if (total > 1) {
17246
44c5817156a9 fixed bug in LIRIntrospection.appendValues
Doug Simon <doug.simon@oracle.com>
parents: 17244
diff changeset
333 sb.append(fields.getName(j)).append(": ");
5733
141b15521a39 use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
334 }
17246
44c5817156a9 fixed bug in LIRIntrospection.appendValues
Doug Simon <doug.simon@oracle.com>
parents: 17244
diff changeset
335 sb.append(getFieldString(obj, j, fields));
5733
141b15521a39 use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
336 sep = ", ";
141b15521a39 use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
337 }
17246
44c5817156a9 fixed bug in LIRIntrospection.appendValues
Doug Simon <doug.simon@oracle.com>
parents: 17244
diff changeset
338 i++;
5733
141b15521a39 use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
339 }
141b15521a39 use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
340 if (total > 1) {
17246
44c5817156a9 fixed bug in LIRIntrospection.appendValues
Doug Simon <doug.simon@oracle.com>
parents: 17244
diff changeset
341 sb.append(endMultiple);
5733
141b15521a39 use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
342 }
17246
44c5817156a9 fixed bug in LIRIntrospection.appendValues
Doug Simon <doug.simon@oracle.com>
parents: 17244
diff changeset
343 sb.append(end);
5733
141b15521a39 use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
344 }
141b15521a39 use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
345
17244
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
346 protected String getFieldString(Object obj, int index, Fields fields) {
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
347 Object value = fields.get(obj, index);
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
348 Class<?> type = fields.getType(index);
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
349 if (value == null || type.isPrimitive() || !type.isArray()) {
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
350 return String.valueOf(value);
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
351 }
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
352 if (type == int[].class) {
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
353 return Arrays.toString((int[]) value);
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
354 } else if (type == double[].class) {
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
355 return Arrays.toString((double[]) value);
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
356 } else if (type == byte[].class) {
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
357 byte[] byteValue = (byte[]) value;
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
358 if (isPrintableAsciiString(byteValue)) {
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
359 return toString(byteValue);
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
360 } else {
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
361 return Arrays.toString(byteValue);
5733
141b15521a39 use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
362 }
17244
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
363 } else if (!type.getComponentType().isPrimitive()) {
aef31f60e970 converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents: 16797
diff changeset
364 return Arrays.toString((Object[]) value);
5733
141b15521a39 use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
365 }
141b15521a39 use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
366 assert false : "unhandled field type: " + type;
141b15521a39 use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
367 return "";
141b15521a39 use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
368 }
16632
d89cafcc398b LIRIntrospection, print byte[] parameter as string, when array consists solely of printable (ascii) characters or null bytes.
Stefan Anzinger <stefan.anzinger@gmail.com>
parents: 16289
diff changeset
369
d89cafcc398b LIRIntrospection, print byte[] parameter as string, when array consists solely of printable (ascii) characters or null bytes.
Stefan Anzinger <stefan.anzinger@gmail.com>
parents: 16289
diff changeset
370 /**
d89cafcc398b LIRIntrospection, print byte[] parameter as string, when array consists solely of printable (ascii) characters or null bytes.
Stefan Anzinger <stefan.anzinger@gmail.com>
parents: 16289
diff changeset
371 * Tests if all values in this string are printable ASCII characters or value \0 (b in
18163
c88ab4f1f04a re-enabled Checkstyle with the release of 6.0 that supports Java 8; fixed existing Checkstyle warnings
Doug Simon <doug.simon@oracle.com>
parents: 17604
diff changeset
372 * [0x20,0x7F]) or b == 0.
16632
d89cafcc398b LIRIntrospection, print byte[] parameter as string, when array consists solely of printable (ascii) characters or null bytes.
Stefan Anzinger <stefan.anzinger@gmail.com>
parents: 16289
diff changeset
373 *
d89cafcc398b LIRIntrospection, print byte[] parameter as string, when array consists solely of printable (ascii) characters or null bytes.
Stefan Anzinger <stefan.anzinger@gmail.com>
parents: 16289
diff changeset
374 * @param array
d89cafcc398b LIRIntrospection, print byte[] parameter as string, when array consists solely of printable (ascii) characters or null bytes.
Stefan Anzinger <stefan.anzinger@gmail.com>
parents: 16289
diff changeset
375 * @return true if there are only printable ASCII characters and \0, false otherwise
d89cafcc398b LIRIntrospection, print byte[] parameter as string, when array consists solely of printable (ascii) characters or null bytes.
Stefan Anzinger <stefan.anzinger@gmail.com>
parents: 16289
diff changeset
376 */
d89cafcc398b LIRIntrospection, print byte[] parameter as string, when array consists solely of printable (ascii) characters or null bytes.
Stefan Anzinger <stefan.anzinger@gmail.com>
parents: 16289
diff changeset
377 private static boolean isPrintableAsciiString(byte[] array) {
d89cafcc398b LIRIntrospection, print byte[] parameter as string, when array consists solely of printable (ascii) characters or null bytes.
Stefan Anzinger <stefan.anzinger@gmail.com>
parents: 16289
diff changeset
378 for (byte b : array) {
16661
f1fba319d4e3 Fix complaints from findbugs
Stefan Anzinger <stefan.anzinger@gmail.com>
parents: 16632
diff changeset
379 char c = (char) b;
f1fba319d4e3 Fix complaints from findbugs
Stefan Anzinger <stefan.anzinger@gmail.com>
parents: 16632
diff changeset
380 if (c != 0 && c < 0x20 && c > 0x7F) {
16632
d89cafcc398b LIRIntrospection, print byte[] parameter as string, when array consists solely of printable (ascii) characters or null bytes.
Stefan Anzinger <stefan.anzinger@gmail.com>
parents: 16289
diff changeset
381 return false;
d89cafcc398b LIRIntrospection, print byte[] parameter as string, when array consists solely of printable (ascii) characters or null bytes.
Stefan Anzinger <stefan.anzinger@gmail.com>
parents: 16289
diff changeset
382 }
d89cafcc398b LIRIntrospection, print byte[] parameter as string, when array consists solely of printable (ascii) characters or null bytes.
Stefan Anzinger <stefan.anzinger@gmail.com>
parents: 16289
diff changeset
383 }
d89cafcc398b LIRIntrospection, print byte[] parameter as string, when array consists solely of printable (ascii) characters or null bytes.
Stefan Anzinger <stefan.anzinger@gmail.com>
parents: 16289
diff changeset
384 return true;
d89cafcc398b LIRIntrospection, print byte[] parameter as string, when array consists solely of printable (ascii) characters or null bytes.
Stefan Anzinger <stefan.anzinger@gmail.com>
parents: 16289
diff changeset
385 }
d89cafcc398b LIRIntrospection, print byte[] parameter as string, when array consists solely of printable (ascii) characters or null bytes.
Stefan Anzinger <stefan.anzinger@gmail.com>
parents: 16289
diff changeset
386
d89cafcc398b LIRIntrospection, print byte[] parameter as string, when array consists solely of printable (ascii) characters or null bytes.
Stefan Anzinger <stefan.anzinger@gmail.com>
parents: 16289
diff changeset
387 private static String toString(byte[] bytes) {
d89cafcc398b LIRIntrospection, print byte[] parameter as string, when array consists solely of printable (ascii) characters or null bytes.
Stefan Anzinger <stefan.anzinger@gmail.com>
parents: 16289
diff changeset
388 StringBuilder sb = new StringBuilder();
d89cafcc398b LIRIntrospection, print byte[] parameter as string, when array consists solely of printable (ascii) characters or null bytes.
Stefan Anzinger <stefan.anzinger@gmail.com>
parents: 16289
diff changeset
389 sb.append('"');
d89cafcc398b LIRIntrospection, print byte[] parameter as string, when array consists solely of printable (ascii) characters or null bytes.
Stefan Anzinger <stefan.anzinger@gmail.com>
parents: 16289
diff changeset
390 for (byte b : bytes) {
d89cafcc398b LIRIntrospection, print byte[] parameter as string, when array consists solely of printable (ascii) characters or null bytes.
Stefan Anzinger <stefan.anzinger@gmail.com>
parents: 16289
diff changeset
391 if (b == 0) {
d89cafcc398b LIRIntrospection, print byte[] parameter as string, when array consists solely of printable (ascii) characters or null bytes.
Stefan Anzinger <stefan.anzinger@gmail.com>
parents: 16289
diff changeset
392 sb.append("\\0");
d89cafcc398b LIRIntrospection, print byte[] parameter as string, when array consists solely of printable (ascii) characters or null bytes.
Stefan Anzinger <stefan.anzinger@gmail.com>
parents: 16289
diff changeset
393 } else if (b == '"') {
d89cafcc398b LIRIntrospection, print byte[] parameter as string, when array consists solely of printable (ascii) characters or null bytes.
Stefan Anzinger <stefan.anzinger@gmail.com>
parents: 16289
diff changeset
394 sb.append("\\\"");
d89cafcc398b LIRIntrospection, print byte[] parameter as string, when array consists solely of printable (ascii) characters or null bytes.
Stefan Anzinger <stefan.anzinger@gmail.com>
parents: 16289
diff changeset
395 } else if (b == '\n') {
d89cafcc398b LIRIntrospection, print byte[] parameter as string, when array consists solely of printable (ascii) characters or null bytes.
Stefan Anzinger <stefan.anzinger@gmail.com>
parents: 16289
diff changeset
396 sb.append("\\n");
d89cafcc398b LIRIntrospection, print byte[] parameter as string, when array consists solely of printable (ascii) characters or null bytes.
Stefan Anzinger <stefan.anzinger@gmail.com>
parents: 16289
diff changeset
397 } else {
d89cafcc398b LIRIntrospection, print byte[] parameter as string, when array consists solely of printable (ascii) characters or null bytes.
Stefan Anzinger <stefan.anzinger@gmail.com>
parents: 16289
diff changeset
398 sb.append((char) b);
d89cafcc398b LIRIntrospection, print byte[] parameter as string, when array consists solely of printable (ascii) characters or null bytes.
Stefan Anzinger <stefan.anzinger@gmail.com>
parents: 16289
diff changeset
399 }
d89cafcc398b LIRIntrospection, print byte[] parameter as string, when array consists solely of printable (ascii) characters or null bytes.
Stefan Anzinger <stefan.anzinger@gmail.com>
parents: 16289
diff changeset
400 }
d89cafcc398b LIRIntrospection, print byte[] parameter as string, when array consists solely of printable (ascii) characters or null bytes.
Stefan Anzinger <stefan.anzinger@gmail.com>
parents: 16289
diff changeset
401 sb.append('"');
d89cafcc398b LIRIntrospection, print byte[] parameter as string, when array consists solely of printable (ascii) characters or null bytes.
Stefan Anzinger <stefan.anzinger@gmail.com>
parents: 16289
diff changeset
402 return sb.toString();
d89cafcc398b LIRIntrospection, print byte[] parameter as string, when array consists solely of printable (ascii) characters or null bytes.
Stefan Anzinger <stefan.anzinger@gmail.com>
parents: 16289
diff changeset
403 }
5733
141b15521a39 use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
404 }