annotate graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotMetaspaceConstantImpl.java @ 18296:a6e7531d3dd3

made HotSpotMetaspaceConstantImpl.forMetaspaceObject and HotSpotMetaspaceConstantImpl.getMetaspaceObject package private
author Doug Simon <doug.simon@oracle.com>
date Thu, 06 Nov 2014 23:12:41 +0100
parents ae181ec869c5
children fb289eb7243d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15018
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
1 /*
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
2 * Copyright (c) 2014, 2014, Oracle and/or its affiliates. All rights reserved.
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
4 *
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
8 *
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
13 * accompanied this code).
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
14 *
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
18 *
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
21 * questions.
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
22 */
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
23 package com.oracle.graal.hotspot.meta;
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
24
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
25 import java.util.*;
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
26
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
27 import com.oracle.graal.api.meta.*;
18266
ae181ec869c5 converted HotSpotMetaspaceConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents: 18187
diff changeset
28 import com.oracle.graal.hotspot.HotSpotVMConfig.CompressEncoding;
15018
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
29
18266
ae181ec869c5 converted HotSpotMetaspaceConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents: 18187
diff changeset
30 public final class HotSpotMetaspaceConstantImpl extends PrimitiveConstant implements HotSpotMetaspaceConstant, VMConstant {
15018
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
31
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
32 private static final long serialVersionUID = 1003463314013122983L;
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
33
18296
a6e7531d3dd3 made HotSpotMetaspaceConstantImpl.forMetaspaceObject and HotSpotMetaspaceConstantImpl.getMetaspaceObject package private
Doug Simon <doug.simon@oracle.com>
parents: 18266
diff changeset
34 static HotSpotMetaspaceConstantImpl forMetaspaceObject(Kind kind, long primitive, Object metaspaceObject, boolean compressed) {
18266
ae181ec869c5 converted HotSpotMetaspaceConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents: 18187
diff changeset
35 return new HotSpotMetaspaceConstantImpl(kind, primitive, metaspaceObject, compressed);
15018
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
36 }
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
37
18296
a6e7531d3dd3 made HotSpotMetaspaceConstantImpl.forMetaspaceObject and HotSpotMetaspaceConstantImpl.getMetaspaceObject package private
Doug Simon <doug.simon@oracle.com>
parents: 18266
diff changeset
38 static Object getMetaspaceObject(JavaConstant constant) {
18266
ae181ec869c5 converted HotSpotMetaspaceConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents: 18187
diff changeset
39 return ((HotSpotMetaspaceConstantImpl) constant).metaspaceObject;
15018
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
40 }
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
41
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
42 private final Object metaspaceObject;
18176
c2270ad35f57 Better construction of data section and data patches.
Roland Schatz <roland.schatz@oracle.com>
parents: 15909
diff changeset
43 private final boolean compressed;
15018
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
44
18266
ae181ec869c5 converted HotSpotMetaspaceConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents: 18187
diff changeset
45 private HotSpotMetaspaceConstantImpl(Kind kind, long primitive, Object metaspaceObject, boolean compressed) {
15018
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
46 super(kind, primitive);
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
47 this.metaspaceObject = metaspaceObject;
18176
c2270ad35f57 Better construction of data section and data patches.
Roland Schatz <roland.schatz@oracle.com>
parents: 15909
diff changeset
48 this.compressed = compressed;
15018
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
49 }
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
50
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
51 @Override
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
52 public int hashCode() {
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
53 return super.hashCode() ^ System.identityHashCode(metaspaceObject);
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
54 }
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
55
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
56 @Override
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
57 public boolean equals(Object o) {
18266
ae181ec869c5 converted HotSpotMetaspaceConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents: 18187
diff changeset
58 return o == this || (o instanceof HotSpotMetaspaceConstantImpl && super.equals(o) && Objects.equals(metaspaceObject, ((HotSpotMetaspaceConstantImpl) o).metaspaceObject));
15018
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
59 }
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
60
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
61 @Override
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
62 public String toString() {
18176
c2270ad35f57 Better construction of data section and data patches.
Roland Schatz <roland.schatz@oracle.com>
parents: 15909
diff changeset
63 return super.toString() + "{" + metaspaceObject + (compressed ? ";compressed}" : "}");
15018
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
64 }
18266
ae181ec869c5 converted HotSpotMetaspaceConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents: 18187
diff changeset
65
ae181ec869c5 converted HotSpotMetaspaceConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents: 18187
diff changeset
66 public boolean isCompressed() {
ae181ec869c5 converted HotSpotMetaspaceConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents: 18187
diff changeset
67 return compressed;
ae181ec869c5 converted HotSpotMetaspaceConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents: 18187
diff changeset
68 }
ae181ec869c5 converted HotSpotMetaspaceConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents: 18187
diff changeset
69
ae181ec869c5 converted HotSpotMetaspaceConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents: 18187
diff changeset
70 public JavaConstant compress(CompressEncoding encoding) {
ae181ec869c5 converted HotSpotMetaspaceConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents: 18187
diff changeset
71 assert !isCompressed();
ae181ec869c5 converted HotSpotMetaspaceConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents: 18187
diff changeset
72 HotSpotMetaspaceConstantImpl res = HotSpotMetaspaceConstantImpl.forMetaspaceObject(Kind.Int, encoding.compress(asLong()), metaspaceObject, true);
ae181ec869c5 converted HotSpotMetaspaceConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents: 18187
diff changeset
73 assert res.isCompressed();
ae181ec869c5 converted HotSpotMetaspaceConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents: 18187
diff changeset
74 return res;
ae181ec869c5 converted HotSpotMetaspaceConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents: 18187
diff changeset
75 }
ae181ec869c5 converted HotSpotMetaspaceConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents: 18187
diff changeset
76
ae181ec869c5 converted HotSpotMetaspaceConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents: 18187
diff changeset
77 public JavaConstant uncompress(CompressEncoding encoding) {
ae181ec869c5 converted HotSpotMetaspaceConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents: 18187
diff changeset
78 assert isCompressed();
ae181ec869c5 converted HotSpotMetaspaceConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents: 18187
diff changeset
79 HotSpotMetaspaceConstantImpl res = HotSpotMetaspaceConstantImpl.forMetaspaceObject(Kind.Long, encoding.uncompress(asInt()), metaspaceObject, false);
ae181ec869c5 converted HotSpotMetaspaceConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents: 18187
diff changeset
80 assert !res.isCompressed();
ae181ec869c5 converted HotSpotMetaspaceConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents: 18187
diff changeset
81 return res;
ae181ec869c5 converted HotSpotMetaspaceConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents: 18187
diff changeset
82 }
ae181ec869c5 converted HotSpotMetaspaceConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents: 18187
diff changeset
83
ae181ec869c5 converted HotSpotMetaspaceConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents: 18187
diff changeset
84 public HotSpotResolvedObjectType asResolvedJavaType() {
ae181ec869c5 converted HotSpotMetaspaceConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents: 18187
diff changeset
85 if (metaspaceObject instanceof HotSpotResolvedObjectType) {
ae181ec869c5 converted HotSpotMetaspaceConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents: 18187
diff changeset
86 return (HotSpotResolvedObjectType) metaspaceObject;
ae181ec869c5 converted HotSpotMetaspaceConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents: 18187
diff changeset
87 }
ae181ec869c5 converted HotSpotMetaspaceConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents: 18187
diff changeset
88 return null;
ae181ec869c5 converted HotSpotMetaspaceConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents: 18187
diff changeset
89 }
15018
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
90 }