30 import java.util.List;
31 import java.util.Map;
32
33 import jdk.vm.ci.common.InitTimer;
34
35 /**
36 * Access to VM configuration data.
37 */
38 public final class HotSpotVMConfigStore {
39
40 /**
41 * Gets the C++ symbols whose addresses are exposed by this object.
42 *
43 * @return an unmodifiable map from the symbol names to their addresses
44 */
45 public Map<String, Long> getAddresses() {
46 return Collections.unmodifiableMap(vmAddresses);
47 }
48
49 /**
50 * Gets the C++ type sizes exposed by this object.
51 *
52 * @return an unmodifiable map from C++ type names to their sizes in bytes
53 */
54 public Map<String, Long> getTypeSizes() {
55 return Collections.unmodifiableMap(vmTypeSizes);
56 }
57
58 /**
59 * Gets the C++ constants exposed by this object.
60 *
61 * @return an unmodifiable map from the names of C++ constants to their values
62 */
63 public Map<String, Long> getConstants() {
64 return Collections.unmodifiableMap(vmConstants);
65 }
66
67 /**
68 * Gets the VM flags exposed by this object.
69 *
70 * @return an unmodifiable map from VM flag names to {@link VMFlag} objects
71 */
72 public Map<String, VMFlag> getFlags() {
73 return Collections.unmodifiableMap(vmFlags);
74 }
75
76 /**
77 * Gets the C++ fields exposed by this object.
78 *
79 * @return an unmodifiable map from VM field names to {@link VMField} objects
80 */
81 public Map<String, VMField> getFields() {
82 return Collections.unmodifiableMap(vmFields);
83 }
84
85 /**
86 * Gets the VM intrinsic descriptions exposed by this object.
87 */
88 public List<VMIntrinsicMethod> getIntrinsics() {
89 return Collections.unmodifiableList(vmIntrinsics);
90 }
91
92 final HashMap<String, VMField> vmFields;
93 final HashMap<String, Long> vmTypeSizes;
94 final HashMap<String, Long> vmConstants;
95 final HashMap<String, Long> vmAddresses;
96 final HashMap<String, VMFlag> vmFlags;
97 final List<VMIntrinsicMethod> vmIntrinsics;
98
99 /**
100 * Reads the database of VM info. The return value encodes the info in a nested object array
101 * that is described by the pseudo Java object {@code info} below:
102 *
103 * <pre>
104 * info = [
105 * VMField[] vmFields,
106 * [String name, Long size, ...] vmTypeSizes,
107 * [String name, Long value, ...] vmConstants,
108 * [String name, Long value, ...] vmAddresses,
109 * VMFlag[] vmFlags
110 * VMIntrinsicMethod[] vmIntrinsics
111 * ]
112 * </pre>
113 */
114 @SuppressWarnings("try")
115 HotSpotVMConfigStore(CompilerToVM compilerToVm) {
116 Object[] data;
117 try (InitTimer t = timer("CompilerToVm readConfiguration")) {
118 data = compilerToVm.readConfiguration();
119 }
120 assert data.length == 6 : data.length;
121
122 // @formatter:off
123 VMField[] vmFieldsInfo = (VMField[]) data[0];
124 Object[] vmTypesSizesInfo = (Object[]) data[1];
125 Object[] vmConstantsInfo = (Object[]) data[2];
126 Object[] vmAddressesInfo = (Object[]) data[3];
127 VMFlag[] vmFlagsInfo = (VMFlag[]) data[4];
128
129 vmFields = new HashMap<>(vmFieldsInfo.length);
130 vmTypeSizes = new HashMap<>(vmTypesSizesInfo.length);
131 vmConstants = new HashMap<>(vmConstantsInfo.length);
132 vmAddresses = new HashMap<>(vmAddressesInfo.length);
133 vmFlags = new HashMap<>(vmFlagsInfo.length);
134 vmIntrinsics = Arrays.asList((VMIntrinsicMethod[]) data[5]);
135 // @formatter:on
136
137 try (InitTimer t = timer("HotSpotVMConfigStore<init> fill maps")) {
138 for (VMField vmField : vmFieldsInfo) {
139 vmFields.put(vmField.name, vmField);
140 }
141
142 for (int i = 0; i < vmTypesSizesInfo.length / 2; i++) {
143 String name = (String) vmTypesSizesInfo[i * 2];
144 Long size = (Long) vmTypesSizesInfo[i * 2 + 1];
145 vmTypeSizes.put(name, size);
146 }
147
148 for (int i = 0; i < vmConstantsInfo.length / 2; i++) {
149 String name = (String) vmConstantsInfo[i * 2];
150 Long value = (Long) vmConstantsInfo[i * 2 + 1];
151 vmConstants.put(name, value);
152 }
153
154 for (int i = 0; i < vmAddressesInfo.length / 2; i++) {
155 String name = (String) vmAddressesInfo[i * 2];
156 Long value = (Long) vmAddressesInfo[i * 2 + 1];
157 vmAddresses.put(name, value);
158 }
159
160 for (VMFlag vmFlag : vmFlagsInfo) {
161 vmFlags.put(vmFlag.name, vmFlag);
162 }
163 }
164 }
165 }
|
30 import java.util.List;
31 import java.util.Map;
32
33 import jdk.vm.ci.common.InitTimer;
34
35 /**
36 * Access to VM configuration data.
37 */
38 public final class HotSpotVMConfigStore {
39
40 /**
41 * Gets the C++ symbols whose addresses are exposed by this object.
42 *
43 * @return an unmodifiable map from the symbol names to their addresses
44 */
45 public Map<String, Long> getAddresses() {
46 return Collections.unmodifiableMap(vmAddresses);
47 }
48
49 /**
50 * Gets the C++ constants exposed by this object.
51 *
52 * @return an unmodifiable map from the names of C++ constants to their values
53 */
54 public Map<String, Long> getConstants() {
55 return Collections.unmodifiableMap(vmConstants);
56 }
57
58 /**
59 * Gets the VM flags exposed by this object.
60 *
61 * @return an unmodifiable map from VM flag names to {@link VMFlag} objects
62 */
63 public Map<String, VMFlag> getFlags() {
64 return Collections.unmodifiableMap(vmFlags);
65 }
66
67 /**
68 * Gets the C++ fields exposed by this object.
69 *
70 * @return an unmodifiable map from VM field names to {@link VMField} objects
71 */
72 public Map<String, VMField> getFields() {
73 return Collections.unmodifiableMap(vmFields);
74 }
75
76 /**
77 * Gets the VM intrinsic descriptions exposed by this object.
78 */
79 public List<VMIntrinsicMethod> getIntrinsics() {
80 return Collections.unmodifiableList(vmIntrinsics);
81 }
82
83 final HashMap<String, VMField> vmFields;
84 final HashMap<String, Long> vmConstants;
85 final HashMap<String, Long> vmAddresses;
86 final HashMap<String, VMFlag> vmFlags;
87 final List<VMIntrinsicMethod> vmIntrinsics;
88 final CompilerToVM compilerToVm;
89
90 /**
91 * Reads the database of VM info. The return value encodes the info in a nested object array
92 * that is described by the pseudo Java object {@code info} below:
93 *
94 * <pre>
95 * info = [
96 * VMField[] vmFields,
97 * [String name, Long value, ...] vmConstants,
98 * [String name, Long value, ...] vmAddresses,
99 * VMFlag[] vmFlags
100 * VMIntrinsicMethod[] vmIntrinsics
101 * ]
102 * </pre>
103 */
104 @SuppressWarnings("try")
105 HotSpotVMConfigStore(CompilerToVM compilerToVm) {
106 this.compilerToVm = compilerToVm;
107 Object[] data;
108 try (InitTimer t = timer("CompilerToVm readConfiguration")) {
109 data = compilerToVm.readConfiguration();
110 }
111 assert data.length == 5 : data.length;
112
113 // @formatter:off
114 VMField[] vmFieldsInfo = (VMField[]) data[0];
115 Object[] vmConstantsInfo = (Object[]) data[1];
116 Object[] vmAddressesInfo = (Object[]) data[2];
117 VMFlag[] vmFlagsInfo = (VMFlag[]) data[3];
118
119 vmFields = new HashMap<>(vmFieldsInfo.length);
120 vmConstants = new HashMap<>(vmConstantsInfo.length);
121 vmAddresses = new HashMap<>(vmAddressesInfo.length);
122 vmFlags = new HashMap<>(vmFlagsInfo.length);
123 vmIntrinsics = Arrays.asList((VMIntrinsicMethod[]) data[4]);
124 // @formatter:on
125
126 try (InitTimer t = timer("HotSpotVMConfigStore<init> fill maps")) {
127 for (VMField vmField : vmFieldsInfo) {
128 vmFields.put(vmField.name, vmField);
129 }
130
131 for (int i = 0; i < vmConstantsInfo.length / 2; i++) {
132 String name = (String) vmConstantsInfo[i * 2];
133 Long value = (Long) vmConstantsInfo[i * 2 + 1];
134 vmConstants.put(name, value);
135 }
136
137 for (int i = 0; i < vmAddressesInfo.length / 2; i++) {
138 String name = (String) vmAddressesInfo[i * 2];
139 Long value = (Long) vmAddressesInfo[i * 2 + 1];
140 vmAddresses.put(name, value);
141 }
142
143 for (VMFlag vmFlag : vmFlagsInfo) {
144 vmFlags.put(vmFlag.name, vmFlag);
145 }
146 }
147 }
148 }
|