1 /* 2 * Copyright (c) 2013, 2015, 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.test; 24 25 import org.junit.Assert; 26 import org.junit.Test; 27 28 import org.graalvm.compiler.core.common.type.StampFactory; 29 import org.graalvm.compiler.hotspot.GraalHotSpotVMConfig; 30 31 import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod; 32 import jdk.vm.ci.hotspot.HotSpotResolvedObjectType; 33 import jdk.vm.ci.meta.Constant; 34 import jdk.vm.ci.meta.JavaKind; 35 import jdk.vm.ci.meta.MemoryAccessProvider; 36 import jdk.vm.ci.meta.PrimitiveConstant; 37 38 /** 39 * Tests {@link HotSpotResolvedJavaMethod} functionality. 40 */ 41 public class HotSpotResolvedObjectTypeTest extends HotSpotGraalCompilerTest { 42 43 @Test 44 public void testGetSourceFileName() throws Throwable { 45 Assert.assertEquals("Object.java", HotSpotResolvedObjectType.fromObjectClass(Object.class).getSourceFileName()); 46 Assert.assertEquals("HotSpotResolvedObjectTypeTest.java", HotSpotResolvedObjectType.fromObjectClass(this.getClass()).getSourceFileName()); 47 } 48 49 @Test 50 public void testKlassLayoutHelper() { 51 Constant klass = HotSpotResolvedObjectType.fromObjectClass(this.getClass()).klass(); 52 MemoryAccessProvider memoryAccess = getProviders().getConstantReflection().getMemoryAccessProvider(); 53 GraalHotSpotVMConfig config = runtime().getVMConfig(); 54 Constant c = StampFactory.forKind(JavaKind.Int).readConstant(memoryAccess, klass, config.klassLayoutHelperOffset); 55 assertTrue(c.toString(), c.getClass() == PrimitiveConstant.class); 56 PrimitiveConstant pc = (PrimitiveConstant) c; 57 assertTrue(pc.toString(), pc.getJavaKind() == JavaKind.Int); 58 } 59 }