1 /* 2 * Copyright (c) 2012, 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.word; 24 25 import org.graalvm.compiler.core.common.type.Stamp; 26 import org.graalvm.compiler.hotspot.nodes.type.KlassPointerStamp; 27 import org.graalvm.compiler.hotspot.nodes.type.MethodCountersPointerStamp; 28 import org.graalvm.compiler.hotspot.nodes.type.MethodPointerStamp; 29 import org.graalvm.compiler.word.WordTypes; 30 31 import jdk.vm.ci.meta.JavaKind; 32 import jdk.vm.ci.meta.JavaType; 33 import jdk.vm.ci.meta.MetaAccessProvider; 34 import jdk.vm.ci.meta.ResolvedJavaType; 35 36 /** 37 * Extends {@link WordTypes} with information about HotSpot metaspace pointer types. 38 */ 39 public class HotSpotWordTypes extends WordTypes { 40 41 /** 42 * Resolved type for {@link MetaspacePointer}. 43 */ 44 private final ResolvedJavaType metaspacePointerType; 45 46 /** 47 * Resolved type for {@link KlassPointer}. 48 */ 49 private final ResolvedJavaType klassPointerType; 50 51 /** 52 * Resolved type for {@link MethodPointer}. 53 */ 54 private final ResolvedJavaType methodPointerType; 55 56 /** 57 * Resolved type for {@link MethodCountersPointer}. 58 */ 59 private final ResolvedJavaType methodCountersPointerType; 60 61 public HotSpotWordTypes(MetaAccessProvider metaAccess, JavaKind wordKind) { 62 super(metaAccess, wordKind); 63 this.metaspacePointerType = metaAccess.lookupJavaType(MetaspacePointer.class); 64 this.klassPointerType = metaAccess.lookupJavaType(KlassPointer.class); 65 this.methodPointerType = metaAccess.lookupJavaType(MethodPointer.class); 66 this.methodCountersPointerType = metaAccess.lookupJavaType(MethodCountersPointer.class); 67 } 68 69 @Override 70 public boolean isWord(JavaType type) { 71 if (type instanceof ResolvedJavaType && metaspacePointerType.isAssignableFrom((ResolvedJavaType) type)) { 72 return true; 73 } 74 return super.isWord(type); 75 } 76 77 @Override 78 public JavaKind asKind(JavaType type) { 79 if (klassPointerType.equals(type) || methodPointerType.equals(type)) { 80 return getWordKind(); 81 } 82 return super.asKind(type); 83 } 84 85 @Override 86 public Stamp getWordStamp(ResolvedJavaType type) { 87 if (type.equals(klassPointerType)) { 88 return KlassPointerStamp.klass(); 89 } else if (type.equals(methodPointerType)) { 90 return MethodPointerStamp.method(); 91 } else if (type.equals(methodCountersPointerType)) { 92 return MethodCountersPointerStamp.methodCounters(); 93 } 94 return super.getWordStamp(type); 95 } 96 }