Mercurial > hg > truffle
comparison graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotMetaspaceConstantImpl.java @ 21551:5324104ac4f3
moved com.oracle.graal.hotspot.jvmci classes to com.oracle.jvmci.hotspot module (JBS:GRAAL-53)
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Tue, 26 May 2015 17:13:37 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
21550:f48a6cea31eb | 21551:5324104ac4f3 |
---|---|
1 /* | |
2 * Copyright (c) 2014, 2014, 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 com.oracle.jvmci.hotspot; | |
24 | |
25 import java.util.*; | |
26 | |
27 import com.oracle.graal.api.meta.*; | |
28 import com.oracle.jvmci.hotspot.HotSpotVMConfig.*; | |
29 | |
30 public final class HotSpotMetaspaceConstantImpl extends PrimitiveConstant implements HotSpotMetaspaceConstant, VMConstant, HotSpotProxified { | |
31 | |
32 static HotSpotMetaspaceConstantImpl forMetaspaceObject(Kind kind, long primitive, Object metaspaceObject, boolean compressed) { | |
33 return new HotSpotMetaspaceConstantImpl(kind, primitive, metaspaceObject, compressed); | |
34 } | |
35 | |
36 static Object getMetaspaceObject(Constant constant) { | |
37 return ((HotSpotMetaspaceConstantImpl) constant).metaspaceObject; | |
38 } | |
39 | |
40 private final Object metaspaceObject; | |
41 private final boolean compressed; | |
42 | |
43 private HotSpotMetaspaceConstantImpl(Kind kind, long primitive, Object metaspaceObject, boolean compressed) { | |
44 super(kind, primitive); | |
45 this.metaspaceObject = metaspaceObject; | |
46 this.compressed = compressed; | |
47 } | |
48 | |
49 @Override | |
50 public int hashCode() { | |
51 return super.hashCode() ^ System.identityHashCode(metaspaceObject); | |
52 } | |
53 | |
54 @Override | |
55 public boolean equals(Object o) { | |
56 return o == this || (o instanceof HotSpotMetaspaceConstantImpl && super.equals(o) && Objects.equals(metaspaceObject, ((HotSpotMetaspaceConstantImpl) o).metaspaceObject)); | |
57 } | |
58 | |
59 @Override | |
60 public String toString() { | |
61 return super.toString() + "{" + metaspaceObject + (compressed ? ";compressed}" : "}"); | |
62 } | |
63 | |
64 public boolean isCompressed() { | |
65 return compressed; | |
66 } | |
67 | |
68 public JavaConstant compress(CompressEncoding encoding) { | |
69 assert !isCompressed(); | |
70 HotSpotMetaspaceConstantImpl res = HotSpotMetaspaceConstantImpl.forMetaspaceObject(Kind.Int, encoding.compress(asLong()), metaspaceObject, true); | |
71 assert res.isCompressed(); | |
72 return res; | |
73 } | |
74 | |
75 public JavaConstant uncompress(CompressEncoding encoding) { | |
76 assert isCompressed(); | |
77 HotSpotMetaspaceConstantImpl res = HotSpotMetaspaceConstantImpl.forMetaspaceObject(Kind.Long, encoding.uncompress(asInt()), metaspaceObject, false); | |
78 assert !res.isCompressed(); | |
79 return res; | |
80 } | |
81 | |
82 public HotSpotResolvedObjectType asResolvedJavaType() { | |
83 if (metaspaceObject instanceof HotSpotResolvedObjectType) { | |
84 return (HotSpotResolvedObjectType) metaspaceObject; | |
85 } | |
86 return null; | |
87 } | |
88 | |
89 public long rawValue() { | |
90 return asLong(); | |
91 } | |
92 } |