annotate graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotSymbol.java @ 14145:4ff08c0366ae

Encapsulate LIR class fields.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Tue, 11 Mar 2014 16:55:57 +0100
parents 0ffe9e4bb364
children 96bb07a5d667
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
13254
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents:
diff changeset
1 /*
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents:
diff changeset
2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents:
diff changeset
4 *
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents:
diff changeset
7 * published by the Free Software Foundation.
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents:
diff changeset
8 *
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents:
diff changeset
13 * accompanied this code).
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents:
diff changeset
14 *
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents:
diff changeset
18 *
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents:
diff changeset
21 * questions.
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents:
diff changeset
22 */
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents:
diff changeset
23 package com.oracle.graal.hotspot;
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents:
diff changeset
24
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents:
diff changeset
25 import static com.oracle.graal.graph.UnsafeAccess.*;
13261
0ffe9e4bb364 don't go through VM to create HotSpotResolvedObjectType (part 1)
twisti
parents: 13254
diff changeset
26 import static com.oracle.graal.hotspot.HotSpotGraalRuntime.*;
13254
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents:
diff changeset
27
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents:
diff changeset
28 import java.io.*;
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents:
diff changeset
29
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents:
diff changeset
30 import com.oracle.graal.graph.*;
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents:
diff changeset
31
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents:
diff changeset
32 /**
13261
0ffe9e4bb364 don't go through VM to create HotSpotResolvedObjectType (part 1)
twisti
parents: 13254
diff changeset
33 * Represents a metaspace {@code Symbol}.
13254
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents:
diff changeset
34 */
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents:
diff changeset
35 public class HotSpotSymbol {
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents:
diff changeset
36
13261
0ffe9e4bb364 don't go through VM to create HotSpotResolvedObjectType (part 1)
twisti
parents: 13254
diff changeset
37 private final long metaspaceSymbol;
13254
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents:
diff changeset
38
13261
0ffe9e4bb364 don't go through VM to create HotSpotResolvedObjectType (part 1)
twisti
parents: 13254
diff changeset
39 public HotSpotSymbol(long metaspaceSymbol) {
0ffe9e4bb364 don't go through VM to create HotSpotResolvedObjectType (part 1)
twisti
parents: 13254
diff changeset
40 assert metaspaceSymbol != 0;
0ffe9e4bb364 don't go through VM to create HotSpotResolvedObjectType (part 1)
twisti
parents: 13254
diff changeset
41 this.metaspaceSymbol = metaspaceSymbol;
13254
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents:
diff changeset
42 }
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents:
diff changeset
43
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents:
diff changeset
44 /**
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents:
diff changeset
45 * Decodes this {@code Symbol} and returns the symbol string as {@link java.lang.String}.
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents:
diff changeset
46 */
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents:
diff changeset
47 public String asString() {
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents:
diff changeset
48 return readModifiedUTF8(asByteArray());
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents:
diff changeset
49 }
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents:
diff changeset
50
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents:
diff changeset
51 private static String readModifiedUTF8(byte[] buf) {
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents:
diff changeset
52 try {
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents:
diff changeset
53 final int length = buf.length;
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents:
diff changeset
54 byte[] tmp = new byte[length + 2];
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents:
diff changeset
55 // write modified UTF-8 length as short in big endian
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents:
diff changeset
56 tmp[0] = (byte) ((length >>> 8) & 0xFF);
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents:
diff changeset
57 tmp[1] = (byte) ((length >>> 0) & 0xFF);
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents:
diff changeset
58 // copy the data
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents:
diff changeset
59 System.arraycopy(buf, 0, tmp, 2, length);
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents:
diff changeset
60 DataInputStream dis = new DataInputStream(new ByteArrayInputStream(tmp));
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents:
diff changeset
61 return dis.readUTF();
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents:
diff changeset
62 } catch (IOException e) {
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents:
diff changeset
63 // This should never happen so let's fail hard here.
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents:
diff changeset
64 throw GraalInternalError.shouldNotReachHere("error reading symbol: " + e);
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents:
diff changeset
65 }
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents:
diff changeset
66 }
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents:
diff changeset
67
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents:
diff changeset
68 private byte[] asByteArray() {
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents:
diff changeset
69 final int length = getLength();
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents:
diff changeset
70 byte[] result = new byte[length];
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents:
diff changeset
71 for (int index = 0; index < length; index++) {
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents:
diff changeset
72 result[index] = getByteAt(index);
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents:
diff changeset
73 }
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents:
diff changeset
74 return result;
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents:
diff changeset
75 }
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents:
diff changeset
76
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents:
diff changeset
77 private int getLength() {
13261
0ffe9e4bb364 don't go through VM to create HotSpotResolvedObjectType (part 1)
twisti
parents: 13254
diff changeset
78 return unsafe.getShort(metaspaceSymbol + runtime().getConfig().symbolLengthOffset);
13254
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents:
diff changeset
79 }
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents:
diff changeset
80
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents:
diff changeset
81 private byte getByteAt(int index) {
13261
0ffe9e4bb364 don't go through VM to create HotSpotResolvedObjectType (part 1)
twisti
parents: 13254
diff changeset
82 return unsafe.getByte(metaspaceSymbol + runtime().getConfig().symbolBodyOffset + index);
13254
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents:
diff changeset
83 }
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents:
diff changeset
84 }