43972
|
1 |
/*
|
|
2 |
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
|
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation.
|
|
8 |
*
|
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
13 |
* accompanied this code).
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License version
|
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
18 |
*
|
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
20 |
* or visit www.oracle.com if you need additional information or have any
|
|
21 |
* questions.
|
|
22 |
*/
|
|
23 |
package org.graalvm.compiler.hotspot;
|
|
24 |
|
|
25 |
import static jdk.vm.ci.hotspot.HotSpotCompressedNullConstant.COMPRESSED_NULL;
|
|
26 |
|
|
27 |
import java.nio.ByteBuffer;
|
|
28 |
|
|
29 |
import org.graalvm.compiler.code.DataSection.Data;
|
|
30 |
import org.graalvm.compiler.code.DataSection.Patches;
|
|
31 |
import org.graalvm.compiler.code.DataSection.SerializableData;
|
|
32 |
import org.graalvm.compiler.code.DataSection.ZeroData;
|
|
33 |
import org.graalvm.compiler.debug.GraalError;
|
|
34 |
import org.graalvm.compiler.lir.asm.DataBuilder;
|
|
35 |
|
|
36 |
import jdk.vm.ci.code.TargetDescription;
|
|
37 |
import jdk.vm.ci.hotspot.HotSpotConstant;
|
|
38 |
import jdk.vm.ci.meta.Constant;
|
|
39 |
import jdk.vm.ci.meta.JavaConstant;
|
|
40 |
import jdk.vm.ci.meta.SerializableConstant;
|
|
41 |
import jdk.vm.ci.meta.VMConstant;
|
|
42 |
|
|
43 |
public class HotSpotDataBuilder extends DataBuilder {
|
|
44 |
|
|
45 |
private final TargetDescription target;
|
|
46 |
|
|
47 |
public HotSpotDataBuilder(TargetDescription target) {
|
|
48 |
this.target = target;
|
|
49 |
}
|
|
50 |
|
|
51 |
@Override
|
|
52 |
public boolean needDetailedPatchingInformation() {
|
|
53 |
/* The HotSpot VM finds operands that need patching by decoding the instruction. */
|
|
54 |
return false;
|
|
55 |
}
|
|
56 |
|
|
57 |
@Override
|
|
58 |
public Data createDataItem(Constant constant) {
|
48861
|
59 |
if (JavaConstant.isNull(constant)) {
|
|
60 |
boolean compressed = COMPRESSED_NULL.equals(constant);
|
|
61 |
int size = compressed ? 4 : target.wordSize;
|
|
62 |
return ZeroData.create(size, size);
|
|
63 |
} else if (constant instanceof VMConstant) {
|
43972
|
64 |
VMConstant vmConstant = (VMConstant) constant;
|
48861
|
65 |
if (!(constant instanceof HotSpotConstant)) {
|
43972
|
66 |
throw new GraalError(String.valueOf(constant));
|
|
67 |
}
|
|
68 |
|
48861
|
69 |
HotSpotConstant c = (HotSpotConstant) vmConstant;
|
|
70 |
int size = c.isCompressed() ? 4 : target.wordSize;
|
|
71 |
return new Data(size, size) {
|
|
72 |
@Override
|
|
73 |
protected void emit(ByteBuffer buffer, Patches patches) {
|
|
74 |
int position = buffer.position();
|
|
75 |
if (getSize() == Integer.BYTES) {
|
43972
|
76 |
buffer.putInt(0xDEADDEAD);
|
48861
|
77 |
} else {
|
43972
|
78 |
buffer.putLong(0xDEADDEADDEADDEADL);
|
|
79 |
}
|
48861
|
80 |
patches.registerPatch(position, vmConstant);
|
|
81 |
}
|
|
82 |
};
|
43972
|
83 |
} else if (constant instanceof SerializableConstant) {
|
|
84 |
SerializableConstant s = (SerializableConstant) constant;
|
|
85 |
return new SerializableData(s);
|
|
86 |
} else {
|
|
87 |
throw new GraalError(String.valueOf(constant));
|
|
88 |
}
|
|
89 |
}
|
|
90 |
}
|