# HG changeset patch # User Tom Rodriguez # Date 1433441292 25200 # Node ID 27943aac2e3cc4ddde88707e7cffe7d0fa85b91c # Parent bc2ec35a7189524433420d09ff7523044c8b6353# Parent 009842dce4f01224356f354cc265800a83763c34 Merge diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.amd64/src/com/oracle/graal/amd64/AMD64.java --- a/graal/com.oracle.graal.amd64/src/com/oracle/graal/amd64/AMD64.java Thu Jun 04 10:46:23 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,207 +0,0 @@ -/* - * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.amd64; - -import com.oracle.jvmci.code.Architecture; -import com.oracle.jvmci.code.Register; -import com.oracle.jvmci.meta.Kind; -import com.oracle.jvmci.meta.PlatformKind; -import static com.oracle.jvmci.code.MemoryBarriers.*; -import static com.oracle.jvmci.code.Register.*; - -import java.nio.*; -import java.util.*; - -import com.oracle.jvmci.code.Register.RegisterCategory; - -/** - * Represents the AMD64 architecture. - */ -public class AMD64 extends Architecture { - - public static final RegisterCategory CPU = new RegisterCategory("CPU"); - - // @formatter:off - - // General purpose CPU registers - public static final Register rax = new Register(0, 0, "rax", CPU); - public static final Register rcx = new Register(1, 1, "rcx", CPU); - public static final Register rdx = new Register(2, 2, "rdx", CPU); - public static final Register rbx = new Register(3, 3, "rbx", CPU); - public static final Register rsp = new Register(4, 4, "rsp", CPU); - public static final Register rbp = new Register(5, 5, "rbp", CPU); - public static final Register rsi = new Register(6, 6, "rsi", CPU); - public static final Register rdi = new Register(7, 7, "rdi", CPU); - - public static final Register r8 = new Register(8, 8, "r8", CPU); - public static final Register r9 = new Register(9, 9, "r9", CPU); - public static final Register r10 = new Register(10, 10, "r10", CPU); - public static final Register r11 = new Register(11, 11, "r11", CPU); - public static final Register r12 = new Register(12, 12, "r12", CPU); - public static final Register r13 = new Register(13, 13, "r13", CPU); - public static final Register r14 = new Register(14, 14, "r14", CPU); - public static final Register r15 = new Register(15, 15, "r15", CPU); - - public static final Register[] cpuRegisters = { - rax, rcx, rdx, rbx, rsp, rbp, rsi, rdi, - r8, r9, r10, r11, r12, r13, r14, r15 - }; - - private static final int XMM_REFERENCE_MAP_SHIFT = 2; - - public static final RegisterCategory XMM = new RegisterCategory("XMM", cpuRegisters.length, XMM_REFERENCE_MAP_SHIFT); - - // XMM registers - public static final Register xmm0 = new Register(16, 0, "xmm0", XMM); - public static final Register xmm1 = new Register(17, 1, "xmm1", XMM); - public static final Register xmm2 = new Register(18, 2, "xmm2", XMM); - public static final Register xmm3 = new Register(19, 3, "xmm3", XMM); - public static final Register xmm4 = new Register(20, 4, "xmm4", XMM); - public static final Register xmm5 = new Register(21, 5, "xmm5", XMM); - public static final Register xmm6 = new Register(22, 6, "xmm6", XMM); - public static final Register xmm7 = new Register(23, 7, "xmm7", XMM); - - public static final Register xmm8 = new Register(24, 8, "xmm8", XMM); - public static final Register xmm9 = new Register(25, 9, "xmm9", XMM); - public static final Register xmm10 = new Register(26, 10, "xmm10", XMM); - public static final Register xmm11 = new Register(27, 11, "xmm11", XMM); - public static final Register xmm12 = new Register(28, 12, "xmm12", XMM); - public static final Register xmm13 = new Register(29, 13, "xmm13", XMM); - public static final Register xmm14 = new Register(30, 14, "xmm14", XMM); - public static final Register xmm15 = new Register(31, 15, "xmm15", XMM); - - public static final Register[] xmmRegisters = { - xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, - xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15 - }; - - public static final Register[] cpuxmmRegisters = { - rax, rcx, rdx, rbx, rsp, rbp, rsi, rdi, - r8, r9, r10, r11, r12, r13, r14, r15, - xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, - xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15 - }; - - /** - * Register used to construct an instruction-relative address. - */ - public static final Register rip = new Register(32, -1, "rip", SPECIAL); - - public static final Register[] allRegisters = { - rax, rcx, rdx, rbx, rsp, rbp, rsi, rdi, - r8, r9, r10, r11, r12, r13, r14, r15, - xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, - xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15, - rip - }; - - // @formatter:on - - /** - * Basic set of CPU features mirroring what is returned from the cpuid instruction. - */ - public static enum CPUFeature { - SSE, - SSE2, - SSE3, - SSE4a, - SSE4_1, - SSE4_2, - SSSE3, - POPCNT, - LZCNT, - AVX, - AVX2, - ERMS, - AMD_3DNOW_PREFETCH, - AES, - BMI1 - } - - private final EnumSet features; - - /** - * Set of flags to control code emission. - */ - public static enum Flag { - UseCountLeadingZerosInstruction, - UseCountTrailingZerosInstruction - } - - private final EnumSet flags; - - public AMD64(EnumSet features, EnumSet flags) { - super("AMD64", 8, ByteOrder.LITTLE_ENDIAN, true, allRegisters, LOAD_STORE | STORE_STORE, 1, cpuRegisters.length + (xmmRegisters.length << XMM_REFERENCE_MAP_SHIFT), 8); - this.features = features; - this.flags = flags; - assert features.contains(CPUFeature.SSE2) : "minimum config for x64"; - } - - public EnumSet getFeatures() { - return features; - } - - public EnumSet getFlags() { - return flags; - } - - @Override - public boolean canStoreValue(RegisterCategory category, PlatformKind platformKind) { - if (!(platformKind instanceof Kind)) { - return false; - } - - Kind kind = (Kind) platformKind; - if (category.equals(CPU)) { - switch (kind) { - case Boolean: - case Byte: - case Char: - case Short: - case Int: - case Long: - case Object: - return true; - } - } else if (category.equals(XMM)) { - switch (kind) { - case Float: - case Double: - return true; - } - } - - return false; - } - - @Override - public PlatformKind getLargestStorableKind(RegisterCategory category) { - if (category.equals(CPU)) { - return Kind.Long; - } else if (category.equals(XMM)) { - return Kind.Double; - } else { - return Kind.Illegal; - } - } -} diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.api.directives.test/src/com/oracle/graal/api/directives/test/ControlFlowAnchorDirectiveTest.java --- a/graal/com.oracle.graal.api.directives.test/src/com/oracle/graal/api/directives/test/ControlFlowAnchorDirectiveTest.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.api.directives.test/src/com/oracle/graal/api/directives/test/ControlFlowAnchorDirectiveTest.java Thu Jun 04 11:08:12 2015 -0700 @@ -165,7 +165,6 @@ @Test public void testPeel() { - test("verifyPeelSnippet", 42); test("preventPeelSnippet", 42); } diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.api.runtime/src/com/oracle/graal/api/runtime/Graal.java --- a/graal/com.oracle.graal.api.runtime/src/com/oracle/graal/api/runtime/Graal.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.api.runtime/src/com/oracle/graal/api/runtime/Graal.java Thu Jun 04 11:08:12 2015 -0700 @@ -40,8 +40,8 @@ if (access != null) { GraalRuntime rt = access.getRuntime(); // The constant is patched in-situ by the build system - System.setProperty("graal.version", "@@graal.version@@".trim()); - assert !System.getProperty("graal.version").startsWith("@@") && !System.getProperty("graal.version").endsWith("@@") : "Graal version string constant was not patched by build system"; + System.setProperty("graal.version", "@@@@@@@@@@@@@@@@graal.version@@@@@@@@@@@@@@@@".trim()); + assert !System.getProperty("graal.version").startsWith("@@@@@@@@@@@@@@@@") && !System.getProperty("graal.version").endsWith("@@@@@@@@@@@@@@@@") : "Graal version string constant was not patched by build system"; return rt; } return new InvalidGraalRuntime(); diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.asm.amd64.test/src/com/oracle/graal/asm/amd64/test/BitOpsTest.java --- a/graal/com.oracle.graal.asm.amd64.test/src/com/oracle/graal/asm/amd64/test/BitOpsTest.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.asm.amd64.test/src/com/oracle/graal/asm/amd64/test/BitOpsTest.java Thu Jun 04 11:08:12 2015 -0700 @@ -23,15 +23,20 @@ package com.oracle.graal.asm.amd64.test; +import com.oracle.graal.asm.amd64.*; +import com.oracle.graal.asm.test.*; +import com.oracle.jvmci.amd64.*; +import com.oracle.jvmci.amd64.AMD64.*; import com.oracle.jvmci.code.RegisterConfig; import com.oracle.jvmci.code.TargetDescription; import com.oracle.jvmci.code.Register; import com.oracle.jvmci.code.CallingConvention; import com.oracle.jvmci.code.CompilationResult; import com.oracle.jvmci.meta.Kind; -import static com.oracle.jvmci.code.ValueUtil.*; + import static com.oracle.graal.asm.amd64.AMD64Assembler.AMD64RMOp.*; import static com.oracle.graal.asm.amd64.AMD64Assembler.OperandSize.*; +import static com.oracle.jvmci.code.ValueUtil.*; import static com.oracle.jvmci.common.UnsafeAccess.*; import static org.junit.Assume.*; @@ -40,11 +45,6 @@ import org.junit.*; -import com.oracle.graal.amd64.*; -import com.oracle.graal.amd64.AMD64.CPUFeature; -import com.oracle.graal.asm.amd64.*; -import com.oracle.graal.asm.test.*; - public class BitOpsTest extends AssemblerTest { private static boolean lzcntSupported; private static boolean tzcntSupported; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.asm.amd64.test/src/com/oracle/graal/asm/amd64/test/IncrementDecrementMacroTest.java --- a/graal/com.oracle.graal.asm.amd64.test/src/com/oracle/graal/asm/amd64/test/IncrementDecrementMacroTest.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.asm.amd64.test/src/com/oracle/graal/asm/amd64/test/IncrementDecrementMacroTest.java Thu Jun 04 11:08:12 2015 -0700 @@ -22,12 +22,16 @@ */ package com.oracle.graal.asm.amd64.test; +import com.oracle.graal.asm.amd64.*; +import com.oracle.graal.asm.test.*; +import com.oracle.jvmci.amd64.*; import com.oracle.jvmci.code.RegisterConfig; import com.oracle.jvmci.code.TargetDescription; import com.oracle.jvmci.code.Register; import com.oracle.jvmci.code.CallingConvention; import com.oracle.jvmci.code.CompilationResult; import com.oracle.jvmci.meta.Kind; + import static com.oracle.jvmci.code.ValueUtil.*; import static com.oracle.jvmci.common.UnsafeAccess.*; import static org.junit.Assume.*; @@ -36,10 +40,6 @@ import org.junit.*; -import com.oracle.graal.amd64.*; -import com.oracle.graal.asm.amd64.*; -import com.oracle.graal.asm.test.*; - public class IncrementDecrementMacroTest extends AssemblerTest { @Before diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.asm.amd64.test/src/com/oracle/graal/asm/amd64/test/SimpleAssemblerTest.java --- a/graal/com.oracle.graal.asm.amd64.test/src/com/oracle/graal/asm/amd64/test/SimpleAssemblerTest.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.asm.amd64.test/src/com/oracle/graal/asm/amd64/test/SimpleAssemblerTest.java Thu Jun 04 11:08:12 2015 -0700 @@ -22,6 +22,9 @@ */ package com.oracle.graal.asm.amd64.test; +import com.oracle.graal.asm.amd64.*; +import com.oracle.graal.asm.test.*; +import com.oracle.jvmci.amd64.*; import com.oracle.jvmci.code.RegisterConfig; import com.oracle.jvmci.code.TargetDescription; import com.oracle.jvmci.code.Register; @@ -29,18 +32,16 @@ import com.oracle.jvmci.code.CompilationResult; import com.oracle.jvmci.meta.JavaConstant; import com.oracle.jvmci.meta.Kind; + import static org.junit.Assume.*; import java.nio.*; import org.junit.*; -import com.oracle.graal.amd64.*; import com.oracle.jvmci.code.CompilationResult.DataSectionReference; import com.oracle.jvmci.code.DataSection.Data; import com.oracle.jvmci.code.DataSection.DataBuilder; -import com.oracle.graal.asm.amd64.*; -import com.oracle.graal.asm.test.*; public class SimpleAssemblerTest extends AssemblerTest { diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.asm.amd64/src/com/oracle/graal/asm/amd64/AMD64Address.java diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.asm.amd64/src/com/oracle/graal/asm/amd64/AMD64AsmOptions.java diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.asm.amd64/src/com/oracle/graal/asm/amd64/AMD64Assembler.java --- a/graal/com.oracle.graal.asm.amd64/src/com/oracle/graal/asm/amd64/AMD64Assembler.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.asm.amd64/src/com/oracle/graal/asm/amd64/AMD64Assembler.java Thu Jun 04 11:08:12 2015 -0700 @@ -22,21 +22,22 @@ */ package com.oracle.graal.asm.amd64; +import com.oracle.graal.asm.*; +import com.oracle.jvmci.amd64.*; +import com.oracle.jvmci.amd64.AMD64.*; import com.oracle.jvmci.code.Register; import com.oracle.jvmci.code.TargetDescription; import com.oracle.jvmci.code.RegisterConfig; -import static com.oracle.graal.amd64.AMD64.*; -import static com.oracle.jvmci.code.MemoryBarriers.*; + import static com.oracle.graal.asm.NumUtil.*; import static com.oracle.graal.asm.amd64.AMD64AsmOptions.*; import static com.oracle.graal.asm.amd64.AMD64Assembler.AMD64BinaryArithmetic.*; import static com.oracle.graal.asm.amd64.AMD64Assembler.AMD64MOp.*; import static com.oracle.graal.asm.amd64.AMD64Assembler.OperandSize.*; +import static com.oracle.jvmci.amd64.AMD64.*; +import static com.oracle.jvmci.code.MemoryBarriers.*; -import com.oracle.graal.amd64.*; -import com.oracle.graal.amd64.AMD64.CPUFeature; import com.oracle.jvmci.code.Register.RegisterCategory; -import com.oracle.graal.asm.*; /** * This class implements an assembler that can encode most X86 instructions. diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.asm.amd64/src/com/oracle/graal/asm/amd64/AMD64MacroAssembler.java --- a/graal/com.oracle.graal.asm.amd64/src/com/oracle/graal/asm/amd64/AMD64MacroAssembler.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.asm.amd64/src/com/oracle/graal/asm/amd64/AMD64MacroAssembler.java Thu Jun 04 11:08:12 2015 -0700 @@ -22,16 +22,16 @@ */ package com.oracle.graal.asm.amd64; +import com.oracle.graal.asm.*; +import com.oracle.jvmci.amd64.*; import com.oracle.jvmci.code.Register; import com.oracle.jvmci.code.CalleeSaveLayout; import com.oracle.jvmci.code.TargetDescription; import com.oracle.jvmci.code.RegisterConfig; import com.oracle.jvmci.meta.Kind; + import static com.oracle.graal.asm.amd64.AMD64AsmOptions.*; -import com.oracle.graal.amd64.*; -import com.oracle.graal.asm.*; - /** * This class implements commonly used X86 code patterns. */ diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.asm.sparc/src/com/oracle/graal/asm/sparc/SPARCAddress.java --- a/graal/com.oracle.graal.asm.sparc/src/com/oracle/graal/asm/sparc/SPARCAddress.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.asm.sparc/src/com/oracle/graal/asm/sparc/SPARCAddress.java Thu Jun 04 11:08:12 2015 -0700 @@ -22,12 +22,10 @@ */ package com.oracle.graal.asm.sparc; -import com.oracle.jvmci.code.AbstractAddress; -import com.oracle.jvmci.code.Register; -import static com.oracle.graal.sparc.SPARC.*; +import static com.oracle.jvmci.sparc.SPARC.*; -import com.oracle.graal.sparc.*; -import com.oracle.jvmci.common.*; +import com.oracle.jvmci.code.*; +import com.oracle.jvmci.sparc.*; public class SPARCAddress extends AbstractAddress { @@ -114,7 +112,7 @@ */ public int getDisplacement() { if (hasIndex()) { - throw JVMCIError.shouldNotReachHere("address has index register"); + throw new InternalError("address has index register"); } // TODO Should we also hide the register save area size here? if (getBase().equals(sp) || getBase().equals(fp)) { diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.asm.sparc/src/com/oracle/graal/asm/sparc/SPARCAssembler.java --- a/graal/com.oracle.graal.asm.sparc/src/com/oracle/graal/asm/sparc/SPARCAssembler.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.asm.sparc/src/com/oracle/graal/asm/sparc/SPARCAssembler.java Thu Jun 04 11:08:12 2015 -0700 @@ -22,25 +22,19 @@ */ package com.oracle.graal.asm.sparc; -import com.oracle.jvmci.code.TargetDescription; -import com.oracle.jvmci.code.RegisterConfig; -import com.oracle.jvmci.code.Register; -import com.oracle.jvmci.meta.Kind; -import com.oracle.jvmci.meta.JavaConstant; import static com.oracle.graal.asm.sparc.SPARCAssembler.CC.*; import static com.oracle.graal.asm.sparc.SPARCAssembler.ConditionFlag.*; import static com.oracle.graal.asm.sparc.SPARCAssembler.Op.*; import static com.oracle.graal.asm.sparc.SPARCAssembler.Op3s.*; import static com.oracle.graal.asm.sparc.SPARCAssembler.Opfs.*; -import static com.oracle.graal.hotspot.HotSpotGraalRuntime.*; -import static com.oracle.graal.sparc.SPARC.*; +import static com.oracle.jvmci.sparc.SPARC.*; import static java.lang.String.*; import com.oracle.graal.asm.*; -import com.oracle.graal.compiler.common.calc.*; -import com.oracle.graal.sparc.*; -import com.oracle.graal.sparc.SPARC.CPUFeature; -import com.oracle.jvmci.common.*; +import com.oracle.jvmci.code.*; +import com.oracle.jvmci.meta.*; +import com.oracle.jvmci.sparc.*; +import com.oracle.jvmci.sparc.SPARC.CPUFeature; /** * This class implements an assembler that can encode most SPARC instructions. @@ -545,7 +539,6 @@ * Condition is considered as 64bit operation condition. */ Xcc(0b10, "xcc", false), - Ptrcc(getHostWordKind() == Kind.Long ? Xcc.getValue() : Icc.getValue(), "ptrcc", false), Fcc0(0b00, "fcc0", true), Fcc1(0b01, "fcc1", true), Fcc2(0b10, "fcc2", true), @@ -583,7 +576,7 @@ } else if (isFloat) { return Fcc0; } else { - throw JVMCIError.shouldNotReachHere(); + throw new InternalError(); } } } @@ -699,10 +692,9 @@ case OverflowSet : return OverflowClear; case OverflowClear : return OverflowSet; default: - JVMCIError.unimplemented(); + throw new InternalError(); } //@formatter:on - return null; } public ConditionFlag mirror() { @@ -730,55 +722,6 @@ } } - public static ConditionFlag fromCondtition(CC conditionFlagsRegister, Condition cond, boolean unorderedIsTrue) { - switch (conditionFlagsRegister) { - case Xcc: - case Icc: - switch (cond) { - case EQ: - return Equal; - case NE: - return NotEqual; - case BT: - return LessUnsigned; - case LT: - return Less; - case BE: - return LessEqualUnsigned; - case LE: - return LessEqual; - case AE: - return GreaterEqualUnsigned; - case GE: - return GreaterEqual; - case AT: - return GreaterUnsigned; - case GT: - return Greater; - } - throw JVMCIError.shouldNotReachHere("Unimplemented for: " + cond); - case Fcc0: - case Fcc1: - case Fcc2: - case Fcc3: - switch (cond) { - case EQ: - return unorderedIsTrue ? F_UnorderedOrEqual : F_Equal; - case NE: - return ConditionFlag.F_NotEqual; - case LT: - return unorderedIsTrue ? F_UnorderedOrLess : F_Less; - case LE: - return unorderedIsTrue ? F_UnorderedOrLessOrEqual : F_LessOrEqual; - case GE: - return unorderedIsTrue ? F_UnorderedGreaterOrEqual : F_GreaterOrEqual; - case GT: - return unorderedIsTrue ? F_UnorderedOrGreater : F_Greater; - } - throw JVMCIError.shouldNotReachHere("Unkown condition: " + cond); - } - throw JVMCIError.shouldNotReachHere("Unknown condition flag register " + conditionFlagsRegister); - } } public enum RCondition { diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.asm.sparc/src/com/oracle/graal/asm/sparc/SPARCInstructionCounter.java --- a/graal/com.oracle.graal.asm.sparc/src/com/oracle/graal/asm/sparc/SPARCInstructionCounter.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.asm.sparc/src/com/oracle/graal/asm/sparc/SPARCInstructionCounter.java Thu Jun 04 11:08:12 2015 -0700 @@ -24,7 +24,7 @@ import java.util.*; -import com.oracle.graal.asm.Assembler.InstructionCounter; +import com.oracle.graal.asm.Assembler.*; public class SPARCInstructionCounter implements InstructionCounter { // Use a treemap to keep the order in the output diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.asm.sparc/src/com/oracle/graal/asm/sparc/SPARCMacroAssembler.java --- a/graal/com.oracle.graal.asm.sparc/src/com/oracle/graal/asm/sparc/SPARCMacroAssembler.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.asm.sparc/src/com/oracle/graal/asm/sparc/SPARCMacroAssembler.java Thu Jun 04 11:08:12 2015 -0700 @@ -22,18 +22,14 @@ */ package com.oracle.graal.asm.sparc; -import com.oracle.jvmci.code.AbstractAddress; -import com.oracle.jvmci.code.TargetDescription; -import com.oracle.jvmci.code.RegisterConfig; -import com.oracle.jvmci.code.Register; import static com.oracle.graal.asm.sparc.SPARCAssembler.Annul.*; import static com.oracle.graal.asm.sparc.SPARCAssembler.ConditionFlag.*; -import static com.oracle.graal.sparc.SPARC.*; +import static com.oracle.jvmci.sparc.SPARC.*; import java.util.function.*; import com.oracle.graal.asm.*; -import com.oracle.jvmci.common.*; +import com.oracle.jvmci.code.*; public class SPARCMacroAssembler extends SPARCAssembler { @@ -106,7 +102,7 @@ } break; default: - throw JVMCIError.shouldNotReachHere("Unknown op2 " + op2); + throw new InternalError("Unknown op2 " + op2); } int newInst = ~maskBits & inst; newInst |= setBits; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.asm.test/src/com/oracle/graal/asm/test/AssemblerTest.java --- a/graal/com.oracle.graal.asm.test/src/com/oracle/graal/asm/test/AssemblerTest.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.asm.test/src/com/oracle/graal/asm/test/AssemblerTest.java Thu Jun 04 11:08:12 2015 -0700 @@ -22,27 +22,18 @@ */ package com.oracle.graal.asm.test; -import com.oracle.jvmci.code.RegisterConfig; -import com.oracle.jvmci.code.CompilationResult; -import com.oracle.jvmci.code.CodeUtil; -import com.oracle.jvmci.code.InstalledCode; -import com.oracle.jvmci.code.CallingConvention; -import com.oracle.jvmci.code.DisassemblerProvider; -import com.oracle.jvmci.code.TargetDescription; -import com.oracle.jvmci.code.CodeCacheProvider; -import com.oracle.jvmci.code.InvalidInstalledCodeException; -import com.oracle.jvmci.meta.MetaAccessProvider; -import com.oracle.jvmci.meta.ResolvedJavaMethod; import java.lang.reflect.*; import org.junit.*; -import com.oracle.graal.api.runtime.*; -import com.oracle.graal.phases.util.*; -import com.oracle.graal.runtime.*; +import com.oracle.graal.code.*; import com.oracle.graal.test.*; +import com.oracle.jvmci.code.*; import com.oracle.jvmci.debug.*; import com.oracle.jvmci.debug.Debug.Scope; +import com.oracle.jvmci.meta.*; +import com.oracle.jvmci.runtime.*; +import com.oracle.jvmci.service.*; public abstract class AssemblerTest extends GraalTest { @@ -54,7 +45,7 @@ } public AssemblerTest() { - Providers providers = Graal.getRequiredCapability(RuntimeProvider.class).getHostBackend().getProviders(); + JVMCIBackend providers = JVMCI.getRuntime().getHostJVMCIBackend(); this.metaAccess = providers.getMetaAccess(); this.codeCache = providers.getCodeCache(); } @@ -76,10 +67,11 @@ InstalledCode code = codeCache.addMethod(method, compResult, null, null); - DisassemblerProvider dis = Graal.getRequiredCapability(RuntimeProvider.class).getHostBackend().getDisassembler(); - if (dis != null) { - String disasm = dis.disassemble(code); - Assert.assertTrue(code.toString(), disasm == null || disasm.length() > 0); + for (DisassemblerProvider dis : Services.load(DisassemblerProvider.class)) { + String disasm1 = dis.disassembleCompiledCode(codeCache, compResult); + Assert.assertTrue(compResult.toString(), disasm1 == null || disasm1.length() > 0); + String disasm2 = dis.disassembleInstalledCode(codeCache, compResult, code); + Assert.assertTrue(code.toString(), disasm2 == null || disasm2.length() > 0); } return code; } catch (Throwable e) { diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.asm/overview.html diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.asm/src/com/oracle/graal/asm/AsmOptions.java diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.asm/src/com/oracle/graal/asm/Assembler.java diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.asm/src/com/oracle/graal/asm/Buffer.java diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.asm/src/com/oracle/graal/asm/Label.java diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.asm/src/com/oracle/graal/asm/NumUtil.java diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.bytecode/overview.html diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.bytecode/src/com/oracle/graal/bytecode/BytecodeLookupSwitch.java diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.bytecode/src/com/oracle/graal/bytecode/BytecodeStream.java diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.bytecode/src/com/oracle/graal/bytecode/BytecodeSwitch.java diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.bytecode/src/com/oracle/graal/bytecode/BytecodeTableSwitch.java diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.bytecode/src/com/oracle/graal/bytecode/Bytecodes.java diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.bytecode/src/com/oracle/graal/bytecode/Bytes.java diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.code/src/com/oracle/graal/code/DisassemblerProvider.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.code/src/com/oracle/graal/code/DisassemblerProvider.java Thu Jun 04 11:08:12 2015 -0700 @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.graal.code; + +import com.oracle.jvmci.code.*; +import com.oracle.jvmci.service.*; + +/** + * Interface providing capability for disassembling machine code. + */ +public interface DisassemblerProvider extends Service { + + /** + * Gets a textual disassembly of a given compilation result. + * + * @param codeCache the object used for code {@link CodeCacheProvider#addMethod code + * installation} + * @param compResult a compilation result + * @return a non-zero length string containing a disassembly of {@code compResult} or null it + * could not be disassembled + */ + default String disassembleCompiledCode(CodeCacheProvider codeCache, CompilationResult compResult) { + return null; + } + + /** + * Gets a textual disassembly of a given installed code. + * + * @param codeCache the object used for code {@link CodeCacheProvider#addMethod code + * installation} + * @param compResult a compiled code that was installed to produce {@code installedCode}. This + * will be null if not available. + * @param installedCode + * @return a non-zero length string containing a disassembly of {@code code} or null if + * {@code code} is {@link InstalledCode#isValid() invalid} or it could not be + * disassembled for some other reason + */ + default String disassembleInstalledCode(CodeCacheProvider codeCache, CompilationResult compResult, InstalledCode installedCode) { + return null; + } + + /** + * Gets the name denoting the format of the disassmembly return by this object. + */ + String getName(); +} diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.code/src/com/oracle/graal/code/HexCodeFile.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.code/src/com/oracle/graal/code/HexCodeFile.java Thu Jun 04 11:08:12 2015 -0700 @@ -0,0 +1,431 @@ +/* + * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.graal.code; + +import java.io.*; +import java.util.*; +import java.util.regex.*; + +import com.oracle.jvmci.code.*; +import com.oracle.jvmci.code.CompilationResult.CodeAnnotation; +import com.oracle.jvmci.code.CompilationResult.CodeComment; +import com.oracle.jvmci.code.CompilationResult.JumpTable; + +/** + * A HexCodeFile is a textual format for representing a chunk of machine code along with extra + * information that can be used to enhance a disassembly of the code. + * + * A pseudo grammar for a HexCodeFile is given below. + * + *
+ *     HexCodeFile ::= Platform Delim HexCode Delim (OptionalSection Delim)*
+ *
+ *     OptionalSection ::= Comment | OperandComment | JumpTable | LookupTable
+ *
+ *     Platform ::= "Platform" ISA WordWidth
+ *
+ *     HexCode ::= "HexCode" StartAddress HexDigits
+ *
+ *     Comment ::= "Comment" Position String
+ *
+ *     OperandComment ::= "OperandComment" Position String
+ *
+ *     JumpTable ::= "JumpTable" Position EntrySize Low High
+ *
+ *     LookupTable ::= "LookupTable" Position NPairs KeySize OffsetSize
+ *
+ *     Position, EntrySize, Low, High, NPairs KeySize OffsetSize ::= int
+ *
+ *     Delim := "<||@"
+ * 
+ * + * There must be exactly one HexCode and Platform part in a HexCodeFile. The length of HexDigits + * must be even as each pair of digits represents a single byte. + *

+ * Below is an example of a valid Code input: + * + *

+ *
+ *  Platform AMD64 64  <||@
+ *  HexCode 0 e8000000009090904883ec084889842410d0ffff48893c24e800000000488b3c24488bf0e8000000004883c408c3  <||@
+ *  Comment 24 frame-ref-map: +0 {0}
+ *  at java.lang.String.toLowerCase(String.java:2496) [bci: 1]
+ *              |0
+ *     locals:  |stack:0:a
+ *     stack:   |stack:0:a
+ *    <||@
+ *  OperandComment 24 {java.util.Locale.getDefault()}  <||@
+ *  Comment 36 frame-ref-map: +0 {0}
+ *  at java.lang.String.toLowerCase(String.java:2496) [bci: 4]
+ *              |0
+ *     locals:  |stack:0:a
+ *    <||@
+ *  OperandComment 36 {java.lang.String.toLowerCase(Locale)}  lt;||@
+ *
+ * 
+ */ +public class HexCodeFile { + + public static final String NEW_LINE = CodeUtil.NEW_LINE; + public static final String SECTION_DELIM = " <||@"; + public static final String COLUMN_END = " <|@"; + public static final Pattern SECTION = Pattern.compile("(\\S+)\\s+(.*)", Pattern.DOTALL); + public static final Pattern COMMENT = Pattern.compile("(\\d+)\\s+(.*)", Pattern.DOTALL); + public static final Pattern OPERAND_COMMENT = COMMENT; + public static final Pattern JUMP_TABLE = Pattern.compile("(\\d+)\\s+(\\d+)\\s+(-{0,1}\\d+)\\s+(-{0,1}\\d+)\\s*"); + public static final Pattern LOOKUP_TABLE = Pattern.compile("(\\d+)\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)\\s*"); + public static final Pattern HEX_CODE = Pattern.compile("(\\p{XDigit}+)(?:\\s+(\\p{XDigit}*))?"); + public static final Pattern PLATFORM = Pattern.compile("(\\S+)\\s+(\\S+)", Pattern.DOTALL); + + /** + * Delimiter placed before a HexCodeFile when embedded in a string/stream. + */ + public static final String EMBEDDED_HCF_OPEN = "<<> comments = new TreeMap<>(); + + /** + * Map from a machine code position to a comment for the operands of the instruction at the + * position. + */ + public final Map operandComments = new TreeMap<>(); + + public final byte[] code; + + public final ArrayList jumpTables = new ArrayList<>(); + + public final String isa; + + public final int wordWidth; + + public final long startAddress; + + public HexCodeFile(byte[] code, long startAddress, String isa, int wordWidth) { + this.code = code; + this.startAddress = startAddress; + this.isa = isa; + this.wordWidth = wordWidth; + } + + /** + * Parses a string in the format produced by {@link #toString()} to produce a + * {@link HexCodeFile} object. + */ + public static HexCodeFile parse(String input, int sourceOffset, String source, String sourceName) { + return new Parser(input, sourceOffset, source, sourceName).hcf; + } + + /** + * Formats this HexCodeFile as a string that can be parsed with + * {@link #parse(String, int, String, String)}. + */ + @Override + public String toString() { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + writeTo(baos); + return baos.toString(); + } + + public String toEmbeddedString() { + return EMBEDDED_HCF_OPEN + NEW_LINE + toString() + EMBEDDED_HCF_CLOSE; + } + + public void writeTo(OutputStream out) { + PrintStream ps = out instanceof PrintStream ? (PrintStream) out : new PrintStream(out); + ps.printf("Platform %s %d %s%n", isa, wordWidth, SECTION_DELIM); + ps.printf("HexCode %x %s %s%n", startAddress, HexCodeFile.hexCodeString(code), SECTION_DELIM); + + for (JumpTable table : jumpTables) { + ps.printf("JumpTable %d %d %d %d %s%n", table.position, table.entrySize, table.low, table.high, SECTION_DELIM); + } + + for (Map.Entry> e : comments.entrySet()) { + int pos = e.getKey(); + for (String comment : e.getValue()) { + ps.printf("Comment %d %s %s%n", pos, comment, SECTION_DELIM); + } + } + + for (Map.Entry e : operandComments.entrySet()) { + ps.printf("OperandComment %d %s %s%n", e.getKey(), e.getValue(), SECTION_DELIM); + } + ps.flush(); + } + + /** + * Formats a byte array as a string of hex digits. + */ + public static String hexCodeString(byte[] code) { + if (code == null) { + return ""; + } else { + StringBuilder sb = new StringBuilder(code.length * 2); + for (int b : code) { + String hex = Integer.toHexString(b & 0xff); + if (hex.length() == 1) { + sb.append('0'); + } + sb.append(hex); + } + return sb.toString(); + } + } + + /** + * Adds a comment to the list of comments for a given position. + */ + public void addComment(int pos, String comment) { + List list = comments.get(pos); + if (list == null) { + list = new ArrayList<>(); + comments.put(pos, list); + } + list.add(encodeString(comment)); + } + + /** + * Sets an operand comment for a given position. + * + * @return the previous operand comment for {@code pos} + */ + public String addOperandComment(int pos, String comment) { + return operandComments.put(pos, encodeString(comment)); + } + + /** + * Adds any jump tables, lookup tables or code comments from a list of code annotations. + */ + public static void addAnnotations(HexCodeFile hcf, List annotations) { + if (annotations == null || annotations.isEmpty()) { + return; + } + for (CodeAnnotation a : annotations) { + if (a instanceof JumpTable) { + JumpTable table = (JumpTable) a; + hcf.jumpTables.add(table); + } else if (a instanceof CodeComment) { + CodeComment comment = (CodeComment) a; + hcf.addComment(comment.position, comment.value); + } + } + } + + /** + * Modifies a string to mangle any substrings matching {@link #SECTION_DELIM} and + * {@link #COLUMN_END}. + */ + public static String encodeString(String input) { + int index; + String s = input; + while ((index = s.indexOf(SECTION_DELIM)) != -1) { + s = s.substring(0, index) + " < |@" + s.substring(index + SECTION_DELIM.length()); + } + while ((index = s.indexOf(COLUMN_END)) != -1) { + s = s.substring(0, index) + " < @" + s.substring(index + COLUMN_END.length()); + } + return s; + } + + /** + * Helper class to parse a string in the format produced by {@link HexCodeFile#toString()} and + * produce a {@link HexCodeFile} object. + */ + static class Parser { + + final String input; + final String inputSource; + String isa; + int wordWidth; + byte[] code; + long startAddress; + HexCodeFile hcf; + + Parser(String input, int sourceOffset, String source, String sourceName) { + this.input = input; + this.inputSource = sourceName; + parseSections(sourceOffset, source); + } + + void makeHCF() { + if (hcf == null) { + if (isa != null && wordWidth != 0 && code != null) { + hcf = new HexCodeFile(code, startAddress, isa, wordWidth); + } + } + } + + void checkHCF(String section, int offset) { + check(hcf != null, offset, section + " section must be after Platform and HexCode section"); + } + + void check(boolean condition, int offset, String message) { + if (!condition) { + error(offset, message); + } + } + + Error error(int offset, String message) { + throw new Error(errorMessage(offset, message)); + } + + void warning(int offset, String message) { + PrintStream err = System.err; + err.println("Warning: " + errorMessage(offset, message)); + } + + String errorMessage(int offset, String message) { + assert offset < input.length(); + InputPos inputPos = filePos(offset); + int lineEnd = input.indexOf(HexCodeFile.NEW_LINE, offset); + int lineStart = offset - inputPos.col; + String line = lineEnd == -1 ? input.substring(lineStart) : input.substring(lineStart, lineEnd); + return String.format("%s:%d: %s%n%s%n%" + (inputPos.col + 1) + "s", inputSource, inputPos.line, message, line, "^"); + } + + static class InputPos { + + final int line; + final int col; + + public InputPos(int line, int col) { + this.line = line; + this.col = col; + } + } + + InputPos filePos(int index) { + assert input != null; + int lineStart = input.lastIndexOf(HexCodeFile.NEW_LINE, index) + 1; + + String l = input.substring(lineStart, lineStart + 10); + PrintStream out = System.out; + out.println("YYY" + input.substring(index, index + 10) + "..."); + out.println("XXX" + l + "..."); + + int pos = input.indexOf(HexCodeFile.NEW_LINE, 0); + int line = 1; + while (pos > 0 && pos < index) { + line++; + pos = input.indexOf(HexCodeFile.NEW_LINE, pos + 1); + } + return new InputPos(line, index - lineStart); + } + + void parseSections(int offset, String source) { + assert input.startsWith(source, offset); + int index = 0; + int endIndex = source.indexOf(SECTION_DELIM); + while (endIndex != -1) { + while (source.charAt(index) <= ' ') { + index++; + } + String section = source.substring(index, endIndex).trim(); + parseSection(offset + index, section); + index = endIndex + SECTION_DELIM.length(); + endIndex = source.indexOf(SECTION_DELIM, index); + } + } + + int parseInt(int offset, String value) { + try { + return Integer.parseInt(value); + } catch (NumberFormatException e) { + throw error(offset, "Not a valid integer: " + value); + } + } + + void parseSection(int offset, String section) { + if (section.isEmpty()) { + return; + } + assert input.startsWith(section, offset); + Matcher m = HexCodeFile.SECTION.matcher(section); + check(m.matches(), offset, "Section does not match pattern " + HexCodeFile.SECTION); + + String header = m.group(1); + String body = m.group(2); + int headerOffset = offset + m.start(1); + int bodyOffset = offset + m.start(2); + + if (header.equals("Platform")) { + check(isa == null, bodyOffset, "Duplicate Platform section found"); + m = HexCodeFile.PLATFORM.matcher(body); + check(m.matches(), bodyOffset, "Platform does not match pattern " + HexCodeFile.PLATFORM); + isa = m.group(1); + wordWidth = parseInt(bodyOffset + m.start(2), m.group(2)); + makeHCF(); + } else if (header.equals("HexCode")) { + check(code == null, bodyOffset, "Duplicate Code section found"); + m = HexCodeFile.HEX_CODE.matcher(body); + check(m.matches(), bodyOffset, "Code does not match pattern " + HexCodeFile.HEX_CODE); + String hexAddress = m.group(1); + startAddress = Long.valueOf(hexAddress, 16); + String hexCode = m.group(2); + if (hexCode == null) { + code = new byte[0]; + } else { + check((hexCode.length() % 2) == 0, bodyOffset, "Hex code length must be even"); + code = new byte[hexCode.length() / 2]; + for (int i = 0; i < code.length; i++) { + String hexByte = hexCode.substring(i * 2, (i + 1) * 2); + code[i] = (byte) Integer.parseInt(hexByte, 16); + } + } + makeHCF(); + } else if (header.equals("Comment")) { + checkHCF("Comment", headerOffset); + m = HexCodeFile.COMMENT.matcher(body); + check(m.matches(), bodyOffset, "Comment does not match pattern " + HexCodeFile.COMMENT); + int pos = parseInt(bodyOffset + m.start(1), m.group(1)); + String comment = m.group(2); + hcf.addComment(pos, comment); + } else if (header.equals("OperandComment")) { + checkHCF("OperandComment", headerOffset); + m = HexCodeFile.OPERAND_COMMENT.matcher(body); + check(m.matches(), bodyOffset, "OperandComment does not match pattern " + HexCodeFile.OPERAND_COMMENT); + int pos = parseInt(bodyOffset + m.start(1), m.group(1)); + String comment = m.group(2); + hcf.addOperandComment(pos, comment); + } else if (header.equals("JumpTable")) { + checkHCF("JumpTable", headerOffset); + m = HexCodeFile.JUMP_TABLE.matcher(body); + check(m.matches(), bodyOffset, "JumpTable does not match pattern " + HexCodeFile.JUMP_TABLE); + int pos = parseInt(bodyOffset + m.start(1), m.group(1)); + int entrySize = parseInt(bodyOffset + m.start(2), m.group(2)); + int low = parseInt(bodyOffset + m.start(3), m.group(3)); + int high = parseInt(bodyOffset + m.start(4), m.group(4)); + hcf.jumpTables.add(new JumpTable(pos, low, high, entrySize)); + } else { + error(offset, "Unknown section header: " + header); + } + } + } +} diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.code/src/com/oracle/graal/code/HexCodeFileDisassemblerProvider.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.code/src/com/oracle/graal/code/HexCodeFileDisassemblerProvider.java Thu Jun 04 11:08:12 2015 -0700 @@ -0,0 +1,147 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.graal.code; + +import java.lang.reflect.*; +import java.util.*; + +import com.oracle.jvmci.code.*; +import com.oracle.jvmci.code.CodeUtil.DefaultRefMapFormatter; +import com.oracle.jvmci.code.CodeUtil.RefMapFormatter; +import com.oracle.jvmci.code.CompilationResult.Call; +import com.oracle.jvmci.code.CompilationResult.DataPatch; +import com.oracle.jvmci.code.CompilationResult.Infopoint; +import com.oracle.jvmci.code.CompilationResult.Mark; +import com.oracle.jvmci.service.*; + +/** + * {@link HexCodeFile} based implementation of {@link DisassemblerProvider}. + */ +@ServiceProvider(DisassemblerProvider.class) +public class HexCodeFileDisassemblerProvider implements DisassemblerProvider { + + @Override + public String disassembleCompiledCode(CodeCacheProvider codeCache, CompilationResult compResult) { + assert compResult != null; + return disassemble(codeCache, compResult, null); + } + + public String getName() { + return "hcf"; + } + + @Override + public String disassembleInstalledCode(CodeCacheProvider codeCache, CompilationResult compResult, InstalledCode installedCode) { + assert installedCode != null; + return installedCode.isValid() ? disassemble(codeCache, compResult, installedCode) : null; + } + + private static String disassemble(CodeCacheProvider codeCache, CompilationResult compResult, InstalledCode installedCode) { + TargetDescription target = codeCache.getTarget(); + RegisterConfig regConfig = codeCache.getRegisterConfig(); + byte[] code = installedCode == null ? Arrays.copyOf(compResult.getTargetCode(), compResult.getTargetCodeSize()) : installedCode.getCode(); + if (code == null) { + // Method was deoptimized/invalidated + return ""; + } + long start = installedCode == null ? 0L : installedCode.getStart(); + HexCodeFile hcf = new HexCodeFile(code, start, target.arch.getName(), target.wordSize * 8); + if (compResult != null) { + HexCodeFile.addAnnotations(hcf, compResult.getAnnotations()); + addExceptionHandlersComment(compResult, hcf); + Register fp = regConfig.getFrameRegister(); + RefMapFormatter slotFormatter = new DefaultRefMapFormatter(target.arch, target.wordSize, fp, 0); + for (Infopoint infopoint : compResult.getInfopoints()) { + if (infopoint instanceof Call) { + Call call = (Call) infopoint; + if (call.debugInfo != null) { + hcf.addComment(call.pcOffset + call.size, CodeUtil.append(new StringBuilder(100), call.debugInfo, slotFormatter).toString()); + } + addOperandComment(hcf, call.pcOffset, "{" + codeCache.getTargetName(call) + "}"); + } else { + if (infopoint.debugInfo != null) { + hcf.addComment(infopoint.pcOffset, CodeUtil.append(new StringBuilder(100), infopoint.debugInfo, slotFormatter).toString()); + } + addOperandComment(hcf, infopoint.pcOffset, "{infopoint: " + infopoint.reason + "}"); + } + } + for (DataPatch site : compResult.getDataPatches()) { + hcf.addOperandComment(site.pcOffset, "{" + site.reference.toString() + "}"); + } + for (Mark mark : compResult.getMarks()) { + hcf.addComment(mark.pcOffset, codeCache.getMarkName(mark)); + } + } + String hcfEmbeddedString = hcf.toEmbeddedString(); + return HexCodeFileDisTool.tryDisassemble(hcfEmbeddedString); + } + + private static void addExceptionHandlersComment(CompilationResult compResult, HexCodeFile hcf) { + if (!compResult.getExceptionHandlers().isEmpty()) { + String nl = HexCodeFile.NEW_LINE; + StringBuilder buf = new StringBuilder("------ Exception Handlers ------").append(nl); + for (CompilationResult.ExceptionHandler e : compResult.getExceptionHandlers()) { + buf.append(" ").append(e.pcOffset).append(" -> ").append(e.handlerPos).append(nl); + hcf.addComment(e.pcOffset, "[exception -> " + e.handlerPos + "]"); + hcf.addComment(e.handlerPos, "[exception handler for " + e.pcOffset + "]"); + } + hcf.addComment(0, buf.toString()); + } + } + + private static void addOperandComment(HexCodeFile hcf, int pos, String comment) { + String oldValue = hcf.addOperandComment(pos, comment); + assert oldValue == null : "multiple comments for operand of instruction at " + pos + ": " + comment + ", " + oldValue; + } + + /** + * Interface to the tool for disassembling an {@link HexCodeFile#toEmbeddedString() embedded} + * {@link HexCodeFile}. + */ + static class HexCodeFileDisTool { + static final Method processMethod; + static { + Method toolMethod = null; + try { + Class toolClass = Class.forName("com.oracle.max.hcfdis.HexCodeFileDis", true, ClassLoader.getSystemClassLoader()); + toolMethod = toolClass.getDeclaredMethod("processEmbeddedString", String.class); + } catch (Exception e) { + // Tool not available on the class path + } + processMethod = toolMethod; + } + + public static String tryDisassemble(String hcfEmbeddedString) { + if (processMethod != null) { + try { + return (String) processMethod.invoke(null, hcfEmbeddedString); + } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { + // If the tool is available, for now let's be noisy when it fails + throw new InternalError(e); + } + } + return hcfEmbeddedString; + } + } + +} diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.compiler.amd64.test/src/com/oracle/graal/compiler/amd64/test/AMD64AllocatorTest.java --- a/graal/com.oracle.graal.compiler.amd64.test/src/com/oracle/graal/compiler/amd64/test/AMD64AllocatorTest.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.compiler.amd64.test/src/com/oracle/graal/compiler/amd64/test/AMD64AllocatorTest.java Thu Jun 04 11:08:12 2015 -0700 @@ -27,8 +27,8 @@ import org.junit.*; -import com.oracle.graal.amd64.*; import com.oracle.graal.compiler.test.backend.*; +import com.oracle.jvmci.amd64.*; public class AMD64AllocatorTest extends AllocatorTest { diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.compiler.amd64.test/src/com/oracle/graal/compiler/amd64/test/ConstantStackMoveTest.java --- a/graal/com.oracle.graal.compiler.amd64.test/src/com/oracle/graal/compiler/amd64/test/ConstantStackMoveTest.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.compiler.amd64.test/src/com/oracle/graal/compiler/amd64/test/ConstantStackMoveTest.java Thu Jun 04 11:08:12 2015 -0700 @@ -22,14 +22,15 @@ */ package com.oracle.graal.compiler.amd64.test; +import com.oracle.jvmci.amd64.*; import com.oracle.jvmci.code.StackSlotValue; import com.oracle.jvmci.meta.JavaConstant; import com.oracle.jvmci.meta.PrimitiveConstant; + import static org.junit.Assume.*; import org.junit.*; -import com.oracle.graal.amd64.*; import com.oracle.graal.lir.framemap.*; import com.oracle.graal.lir.gen.*; import com.oracle.graal.lir.jtt.*; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.compiler.amd64.test/src/com/oracle/graal/compiler/amd64/test/StackStoreTest.java --- a/graal/com.oracle.graal.compiler.amd64.test/src/com/oracle/graal/compiler/amd64/test/StackStoreTest.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.compiler.amd64.test/src/com/oracle/graal/compiler/amd64/test/StackStoreTest.java Thu Jun 04 11:08:12 2015 -0700 @@ -22,16 +22,17 @@ */ package com.oracle.graal.compiler.amd64.test; +import com.oracle.jvmci.amd64.*; import com.oracle.jvmci.code.StackSlotValue; import com.oracle.jvmci.meta.JavaConstant; import com.oracle.jvmci.meta.LIRKind; import com.oracle.jvmci.meta.Kind; import com.oracle.jvmci.meta.Value; + import static org.junit.Assume.*; import org.junit.*; -import com.oracle.graal.amd64.*; import com.oracle.graal.lir.framemap.*; import com.oracle.graal.lir.gen.*; import com.oracle.graal.lir.jtt.*; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.compiler.amd64/src/com/oracle/graal/compiler/amd64/AMD64LIRGenerator.java --- a/graal/com.oracle.graal.compiler.amd64/src/com/oracle/graal/compiler/amd64/AMD64LIRGenerator.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.compiler.amd64/src/com/oracle/graal/compiler/amd64/AMD64LIRGenerator.java Thu Jun 04 11:08:12 2015 -0700 @@ -23,6 +23,7 @@ package com.oracle.graal.compiler.amd64; +import com.oracle.jvmci.amd64.*; import com.oracle.jvmci.code.RegisterConfig; import com.oracle.jvmci.code.Register; import com.oracle.jvmci.code.ForeignCallLinkage; @@ -38,6 +39,7 @@ import com.oracle.jvmci.meta.Value; import com.oracle.jvmci.meta.AllocatableValue; import com.oracle.jvmci.meta.LIRKind; + import static com.oracle.jvmci.code.ValueUtil.*; import static com.oracle.graal.asm.amd64.AMD64Assembler.AMD64BinaryArithmetic.*; import static com.oracle.graal.asm.amd64.AMD64Assembler.AMD64MOp.*; @@ -49,19 +51,9 @@ import java.util.*; -import com.oracle.graal.amd64.*; import com.oracle.graal.asm.*; -import com.oracle.graal.asm.amd64.AMD64Address.Scale; -import com.oracle.graal.asm.amd64.AMD64Assembler.AMD64BinaryArithmetic; -import com.oracle.graal.asm.amd64.AMD64Assembler.AMD64MIOp; -import com.oracle.graal.asm.amd64.AMD64Assembler.AMD64MOp; -import com.oracle.graal.asm.amd64.AMD64Assembler.AMD64MROp; -import com.oracle.graal.asm.amd64.AMD64Assembler.AMD64RMIOp; -import com.oracle.graal.asm.amd64.AMD64Assembler.AMD64RMOp; -import com.oracle.graal.asm.amd64.AMD64Assembler.AMD64Shift; -import com.oracle.graal.asm.amd64.AMD64Assembler.ConditionFlag; -import com.oracle.graal.asm.amd64.AMD64Assembler.OperandSize; -import com.oracle.graal.asm.amd64.AMD64Assembler.SSEOp; +import com.oracle.graal.asm.amd64.AMD64Address.*; +import com.oracle.graal.asm.amd64.AMD64Assembler.*; import com.oracle.graal.compiler.common.calc.*; import com.oracle.graal.compiler.common.spi.*; import com.oracle.graal.compiler.common.util.*; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.compiler.amd64/src/com/oracle/graal/compiler/amd64/AMD64NodeLIRBuilder.java --- a/graal/com.oracle.graal.compiler.amd64/src/com/oracle/graal/compiler/amd64/AMD64NodeLIRBuilder.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.compiler.amd64/src/com/oracle/graal/compiler/amd64/AMD64NodeLIRBuilder.java Thu Jun 04 11:08:12 2015 -0700 @@ -23,6 +23,7 @@ package com.oracle.graal.compiler.amd64; +import com.oracle.jvmci.amd64.*; import com.oracle.jvmci.code.CallingConvention; import com.oracle.jvmci.meta.Kind; import com.oracle.jvmci.meta.JavaType; @@ -31,16 +32,13 @@ import com.oracle.jvmci.meta.Value; import com.oracle.jvmci.meta.AllocatableValue; import com.oracle.jvmci.meta.LIRKind; + import static com.oracle.graal.asm.amd64.AMD64Assembler.AMD64BinaryArithmetic.*; import static com.oracle.graal.asm.amd64.AMD64Assembler.AMD64RMOp.*; import static com.oracle.graal.asm.amd64.AMD64Assembler.OperandSize.*; -import com.oracle.graal.amd64.*; import com.oracle.graal.asm.*; -import com.oracle.graal.asm.amd64.AMD64Assembler.AMD64MIOp; -import com.oracle.graal.asm.amd64.AMD64Assembler.AMD64RMOp; -import com.oracle.graal.asm.amd64.AMD64Assembler.OperandSize; -import com.oracle.graal.asm.amd64.AMD64Assembler.SSEOp; +import com.oracle.graal.asm.amd64.AMD64Assembler.*; import com.oracle.graal.compiler.common.calc.*; import com.oracle.graal.compiler.gen.*; import com.oracle.graal.compiler.match.*; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/type/AbstractPointerStamp.java --- a/graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/type/AbstractPointerStamp.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/type/AbstractPointerStamp.java Thu Jun 04 11:08:12 2015 -0700 @@ -40,7 +40,7 @@ } public boolean nonNull() { - return nonNull; + return nonNull || this.isEmpty(); } public boolean alwaysNull() { diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.compiler.sparc.test/src/com/oracle/graal/compiler/sparc/test/SPARCAllocatorTest.java --- a/graal/com.oracle.graal.compiler.sparc.test/src/com/oracle/graal/compiler/sparc/test/SPARCAllocatorTest.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.compiler.sparc.test/src/com/oracle/graal/compiler/sparc/test/SPARCAllocatorTest.java Thu Jun 04 11:08:12 2015 -0700 @@ -28,7 +28,7 @@ import org.junit.*; import com.oracle.graal.compiler.test.backend.*; -import com.oracle.graal.sparc.*; +import com.oracle.jvmci.sparc.*; public class SPARCAllocatorTest extends AllocatorTest { diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.compiler.sparc/src/com/oracle/graal/compiler/sparc/SPARCLIRGenerator.java --- a/graal/com.oracle.graal.compiler.sparc/src/com/oracle/graal/compiler/sparc/SPARCLIRGenerator.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.compiler.sparc/src/com/oracle/graal/compiler/sparc/SPARCLIRGenerator.java Thu Jun 04 11:08:12 2015 -0700 @@ -23,25 +23,14 @@ package com.oracle.graal.compiler.sparc; -import com.oracle.jvmci.code.ForeignCallLinkage; -import com.oracle.jvmci.code.CodeUtil; -import com.oracle.jvmci.code.CallingConvention; -import com.oracle.jvmci.code.StackSlotValue; -import com.oracle.jvmci.meta.JavaConstant; -import com.oracle.jvmci.meta.Value; -import com.oracle.jvmci.meta.AllocatableValue; -import com.oracle.jvmci.meta.PlatformKind; -import com.oracle.jvmci.meta.Kind; -import com.oracle.jvmci.meta.LIRKind; -import static com.oracle.jvmci.code.ValueUtil.*; import static com.oracle.graal.lir.sparc.SPARCArithmetic.*; import static com.oracle.graal.lir.sparc.SPARCBitManipulationOp.IntrinsicOpcode.*; import static com.oracle.graal.lir.sparc.SPARCCompare.*; import static com.oracle.graal.lir.sparc.SPARCMathIntrinsicOp.IntrinsicOpcode.*; +import static com.oracle.jvmci.code.ValueUtil.*; import com.oracle.graal.asm.sparc.*; -import com.oracle.graal.asm.sparc.SPARCAssembler.CC; -import com.oracle.graal.asm.sparc.SPARCAssembler.ConditionFlag; +import com.oracle.graal.asm.sparc.SPARCAssembler.*; import com.oracle.graal.compiler.common.calc.*; import com.oracle.graal.compiler.common.spi.*; import com.oracle.graal.lir.*; @@ -71,9 +60,11 @@ import com.oracle.graal.lir.sparc.SPARCMove.SPARCStackMove; import com.oracle.graal.lir.sparc.SPARCMove.StackLoadAddressOp; import com.oracle.graal.phases.util.*; -import com.oracle.graal.sparc.*; -import com.oracle.graal.sparc.SPARC.CPUFeature; +import com.oracle.jvmci.code.*; import com.oracle.jvmci.common.*; +import com.oracle.jvmci.meta.*; +import com.oracle.jvmci.sparc.*; +import com.oracle.jvmci.sparc.SPARC.CPUFeature; /** * This class implements the SPARC specific portion of the LIR generator. @@ -355,7 +346,7 @@ throw JVMCIError.shouldNotReachHere(); } Variable result = newVariable(trueValue.getLIRKind()); - ConditionFlag finalCondition = ConditionFlag.fromCondtition(conditionFlags, mirrored ? cond.mirror() : cond, unorderedIsTrue); + ConditionFlag finalCondition = SPARCControlFlow.fromCondition(conditionFlags, mirrored ? cond.mirror() : cond, unorderedIsTrue); append(new CondMoveOp(result, conditionFlags, finalCondition, actualTrueValue, actualFalseValue)); return result; } @@ -431,7 +422,7 @@ default: throw JVMCIError.shouldNotReachHere(); } - ConditionFlag flag = ConditionFlag.fromCondtition(conditionCode, Condition.EQ, false); + ConditionFlag flag = SPARCControlFlow.fromCondition(conditionCode, Condition.EQ, false); append(new CondMoveOp(result, conditionCode, flag, loadSimm11(trueValue), loadSimm11(falseValue))); return result; } diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/CheckGraalInvariants.java --- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/CheckGraalInvariants.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/CheckGraalInvariants.java Thu Jun 04 11:08:12 2015 -0700 @@ -22,17 +22,6 @@ */ package com.oracle.graal.compiler.test; -import com.oracle.jvmci.code.BailoutException; -import com.oracle.jvmci.code.Register; -import com.oracle.jvmci.meta.ResolvedJavaMethod; -import com.oracle.jvmci.meta.JavaType; -import com.oracle.jvmci.meta.Value; -import com.oracle.jvmci.meta.JavaMethod; -import com.oracle.jvmci.meta.LocationIdentity; -import com.oracle.jvmci.meta.LIRKind; -import com.oracle.jvmci.meta.ExcludeFromIdentityComparisonVerification; -import com.oracle.jvmci.meta.MetaAccessProvider; -import com.oracle.jvmci.meta.JavaField; import static com.oracle.jvmci.debug.DelegatingDebugConfig.Feature.*; import java.io.*; @@ -43,7 +32,6 @@ import org.junit.*; -import com.oracle.jvmci.code.Register.RegisterCategory; import com.oracle.graal.api.runtime.*; import com.oracle.graal.compiler.*; import com.oracle.graal.compiler.CompilerThreadFactory.DebugConfigAccess; @@ -63,14 +51,37 @@ import com.oracle.graal.printer.*; import com.oracle.graal.runtime.*; import com.oracle.graal.test.*; +import com.oracle.jvmci.code.*; +import com.oracle.jvmci.code.Register.RegisterCategory; import com.oracle.jvmci.debug.*; +import com.oracle.jvmci.meta.*; /** - * Checks that all classes in graal*.jar from the boot classpath comply with global invariants such - * as using {@link Object#equals(Object)} to compare certain types instead of identity comparisons. + * Checks that all classes in *graal*.jar and *jvmci*.jar entries on the boot class path comply with + * global invariants such as using {@link Object#equals(Object)} to compare certain types instead of + * identity comparisons. */ public class CheckGraalInvariants extends GraalTest { + private static boolean shouldVerifyEquals(ResolvedJavaMethod m) { + if (m.getName().equals("identityEquals")) { + ResolvedJavaType c = m.getDeclaringClass(); + if (c.getName().equals("Lcom/oracle/jvmci/meta/AbstractValue;") || c.getName().equals("com/oracle/jvmci/meta/Value")) { + return false; + } + } + + return true; + } + + private static boolean shouldProcess(String classpathEntry) { + if (classpathEntry.endsWith(".jar")) { + String name = new File(classpathEntry).getName(); + return name.contains("jvmci") || name.contains("graal"); + } + return false; + } + @Test public void test() { RuntimeProvider rt = Graal.getRequiredCapability(RuntimeProvider.class); @@ -91,11 +102,9 @@ final List classNames = new ArrayList<>(); for (String path : bootclasspath.split(File.pathSeparator)) { - File file = new File(path); - String fileName = file.getName(); - if (fileName.startsWith("graal") && fileName.endsWith(".jar")) { + if (shouldProcess(path)) { try { - final ZipFile zipFile = new ZipFile(file); + final ZipFile zipFile = new ZipFile(new File(path)); for (final Enumeration entry = zipFile.entries(); entry.hasMoreElements();) { final ZipEntry zipEntry = entry.nextElement(); String name = zipEntry.getName(); @@ -140,7 +149,6 @@ // ignore } else { String methodName = className + "." + m.getName(); - boolean verifyEquals = !m.isAnnotationPresent(ExcludeFromIdentityComparisonVerification.class); if (matches(filters, methodName)) { executor.execute(() -> { ResolvedJavaMethod method = metaAccess.lookupJavaMethod(m); @@ -149,7 +157,7 @@ graphBuilderSuite.apply(graph, context); // update phi stamps graph.getNodes().filter(PhiNode.class).forEach(PhiNode::inferStamp); - checkGraph(context, graph, verifyEquals); + checkGraph(context, graph); } catch (VerificationError e) { errors.add(e.getMessage()); } catch (LinkageError e) { @@ -203,8 +211,8 @@ /** * Checks the invariants for a single graph. */ - private static void checkGraph(HighTierContext context, StructuredGraph graph, boolean verifyEquals) { - if (verifyEquals) { + private static void checkGraph(HighTierContext context, StructuredGraph graph) { + if (shouldVerifyEquals(graph.method())) { new VerifyUsageWithEquals(Value.class).apply(graph, context); new VerifyUsageWithEquals(Register.class).apply(graph, context); new VerifyUsageWithEquals(RegisterCategory.class).apply(graph, context); diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/GraalCompilerTest.java --- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/GraalCompilerTest.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/GraalCompilerTest.java Thu Jun 04 11:08:12 2015 -0700 @@ -22,18 +22,10 @@ */ package com.oracle.graal.compiler.test; -import com.oracle.jvmci.code.Architecture; -import com.oracle.jvmci.code.CompilationResult; -import com.oracle.jvmci.code.TargetDescription; -import com.oracle.jvmci.code.InstalledCode; -import com.oracle.jvmci.code.CallingConvention; -import com.oracle.jvmci.code.CodeCacheProvider; -import com.oracle.jvmci.meta.*; - -import static com.oracle.jvmci.code.CodeUtil.*; import static com.oracle.graal.compiler.GraalCompiler.*; import static com.oracle.graal.compiler.common.GraalOptions.*; import static com.oracle.graal.nodes.ConstantNode.*; +import static com.oracle.jvmci.code.CodeUtil.*; import java.lang.reflect.*; import java.util.*; @@ -43,7 +35,6 @@ import org.junit.*; import org.junit.internal.*; -import com.oracle.jvmci.code.CallingConvention.Type; import com.oracle.graal.api.directives.*; import com.oracle.graal.api.replacements.*; import com.oracle.graal.api.runtime.*; @@ -71,9 +62,12 @@ import com.oracle.graal.printer.*; import com.oracle.graal.runtime.*; import com.oracle.graal.test.*; +import com.oracle.jvmci.code.*; +import com.oracle.jvmci.code.CallingConvention.Type; import com.oracle.jvmci.common.*; import com.oracle.jvmci.debug.*; import com.oracle.jvmci.debug.Debug.Scope; +import com.oracle.jvmci.meta.*; import com.oracle.jvmci.options.*; /** diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/StaticInterfaceFieldTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/StaticInterfaceFieldTest.java Thu Jun 04 11:08:12 2015 -0700 @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2015, 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.graal.compiler.test; + +import static com.oracle.jvmci.debug.DelegatingDebugConfig.Feature.*; + +import java.lang.reflect.*; + +import org.junit.*; + +import com.oracle.graal.api.runtime.*; +import com.oracle.graal.graphbuilderconf.*; +import com.oracle.graal.graphbuilderconf.GraphBuilderConfiguration.Plugins; +import com.oracle.graal.java.*; +import com.oracle.graal.nodes.*; +import com.oracle.graal.nodes.StructuredGraph.AllowAssumptions; +import com.oracle.graal.phases.*; +import com.oracle.graal.phases.tiers.*; +import com.oracle.graal.phases.util.*; +import com.oracle.graal.runtime.*; +import com.oracle.graal.test.*; +import com.oracle.jvmci.debug.*; +import com.oracle.jvmci.meta.*; + +/** + * Test that interfaces are correctly initialized by a static field resolution during eager graph + * building. + */ +public class StaticInterfaceFieldTest extends GraalTest { + + private interface I { + Object CONST = new Object() { + }; + + } + + private static final class C implements I { + @SuppressWarnings({"static-method", "unused"}) + public Object test() { + return CONST; + } + } + + @Test + public void test() { + eagerlyParseMethod(C.class, "test"); + + } + + private void eagerlyParseMethod(Class clazz, String methodName) { + RuntimeProvider rt = Graal.getRequiredCapability(RuntimeProvider.class); + Providers providers = rt.getHostBackend().getProviders(); + MetaAccessProvider metaAccess = providers.getMetaAccess(); + + PhaseSuite graphBuilderSuite = new PhaseSuite<>(); + GraphBuilderConfiguration config = GraphBuilderConfiguration.getEagerDefault(new Plugins(new InvocationPlugins(metaAccess))); + graphBuilderSuite.appendPhase(new GraphBuilderPhase(config)); + HighTierContext context = new HighTierContext(providers, graphBuilderSuite, OptimisticOptimizations.NONE); + + Assume.assumeTrue(VerifyPhase.class.desiredAssertionStatus()); + + final Method m = getMethod(clazz, methodName); + ResolvedJavaMethod method = metaAccess.lookupJavaMethod(m); + StructuredGraph graph = new StructuredGraph(method, AllowAssumptions.NO); + try (DebugConfigScope s = Debug.setConfig(new DelegatingDebugConfig().disable(INTERCEPT)); Debug.Scope ds = Debug.scope("GraphBuilding", graph, method)) { + graphBuilderSuite.apply(graph, context); + } catch (Throwable e) { + throw Debug.handle(e); + } + } +} diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalCompiler.java --- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalCompiler.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalCompiler.java Thu Jun 04 11:08:12 2015 -0700 @@ -365,10 +365,6 @@ Debug.metric("ExceptionHandlersEmitted").add(compilationResult.getExceptionHandlers().size()); } - if (Debug.isLogEnabled()) { - Debug.log("%s", backend.getProviders().getCodeCache().disassemble(compilationResult, null)); - } - Debug.dump(compilationResult, "After code generation"); } } diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/target/Backend.java --- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/target/Backend.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/target/Backend.java Thu Jun 04 11:08:12 2015 -0700 @@ -79,8 +79,6 @@ public abstract SuitesProvider getSuites(); - public abstract DisassemblerProvider getDisassembler(); - public TargetDescription getTarget() { return providers.getCodeCache().getTarget(); } diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.graphbuilderconf/src/com/oracle/graal/graphbuilderconf/NodePlugin.java --- a/graal/com.oracle.graal.graphbuilderconf/src/com/oracle/graal/graphbuilderconf/NodePlugin.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.graphbuilderconf/src/com/oracle/graal/graphbuilderconf/NodePlugin.java Thu Jun 04 11:08:12 2015 -0700 @@ -152,4 +152,15 @@ default boolean handleInstanceOf(GraphBuilderContext b, ValueNode object, ResolvedJavaType type, JavaTypeProfile profile) { return false; } + + /** + * If the plugin {@link GraphBuilderContext#push pushes} a value with a different {@link Kind} + * than specified by the bytecode, it must override this method and return {@code true}. This + * disables assertion checking for value kinds. + * + * @param b the context + */ + default boolean canChangeStackKind(GraphBuilderContext b) { + return false; + } } diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.hotspot.amd64.test/src/com/oracle/graal/hotspot/amd64/test/AMD64HotSpotFrameOmissionTest.java --- a/graal/com.oracle.graal.hotspot.amd64.test/src/com/oracle/graal/hotspot/amd64/test/AMD64HotSpotFrameOmissionTest.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.hotspot.amd64.test/src/com/oracle/graal/hotspot/amd64/test/AMD64HotSpotFrameOmissionTest.java Thu Jun 04 11:08:12 2015 -0700 @@ -29,7 +29,8 @@ import com.oracle.jvmci.code.TargetDescription; import com.oracle.jvmci.meta.ResolvedJavaMethod; import com.oracle.jvmci.meta.Kind; -import static com.oracle.graal.amd64.AMD64.*; + +import static com.oracle.jvmci.amd64.AMD64.*; import java.util.*; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.hotspot.amd64.test/src/com/oracle/graal/hotspot/amd64/test/DataPatchInConstantsTest.java --- a/graal/com.oracle.graal.hotspot.amd64.test/src/com/oracle/graal/hotspot/amd64/test/DataPatchInConstantsTest.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.hotspot.amd64.test/src/com/oracle/graal/hotspot/amd64/test/DataPatchInConstantsTest.java Thu Jun 04 11:08:12 2015 -0700 @@ -25,12 +25,12 @@ import com.oracle.jvmci.meta.AllocatableValue; import com.oracle.jvmci.meta.Constant; + import static com.oracle.jvmci.code.ValueUtil.*; import static com.oracle.graal.lir.LIRInstruction.OperandFlag.*; import org.junit.*; -import com.oracle.graal.amd64.*; import com.oracle.graal.api.replacements.*; import com.oracle.graal.asm.amd64.*; import com.oracle.graal.graph.*; @@ -45,6 +45,7 @@ import com.oracle.graal.nodeinfo.*; import com.oracle.graal.nodes.*; import com.oracle.graal.nodes.spi.*; +import com.oracle.jvmci.amd64.*; import com.oracle.jvmci.hotspot.*; public class DataPatchInConstantsTest extends HotSpotGraalCompilerTest { diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64DeoptimizationStub.java --- a/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64DeoptimizationStub.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64DeoptimizationStub.java Thu Jun 04 11:08:12 2015 -0700 @@ -25,12 +25,14 @@ import com.oracle.jvmci.code.Register; import com.oracle.jvmci.code.RegisterConfig; import com.oracle.jvmci.code.TargetDescription; -import static com.oracle.graal.amd64.AMD64.*; + +import static com.oracle.jvmci.amd64.AMD64.*; import com.oracle.graal.hotspot.*; import com.oracle.graal.hotspot.meta.*; import com.oracle.graal.hotspot.stubs.*; import com.oracle.jvmci.hotspot.*; +import com.oracle.jvmci.hotspot.amd64.*; final class AMD64DeoptimizationStub extends DeoptimizationStub { diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64DeoptimizeOp.java diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotBackend.java --- a/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotBackend.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotBackend.java Thu Jun 04 11:08:12 2015 -0700 @@ -22,6 +22,7 @@ */ package com.oracle.graal.hotspot.amd64; +import com.oracle.jvmci.amd64.*; import com.oracle.jvmci.code.CompilationResult; import com.oracle.jvmci.code.Register; import com.oracle.jvmci.code.RegisterConfig; @@ -30,7 +31,8 @@ import com.oracle.jvmci.code.CalleeSaveLayout; import com.oracle.jvmci.meta.JavaType; import com.oracle.jvmci.meta.ResolvedJavaMethod; -import static com.oracle.graal.amd64.AMD64.*; + +import static com.oracle.jvmci.amd64.AMD64.*; import static com.oracle.jvmci.code.CallingConvention.Type.*; import static com.oracle.jvmci.code.ValueUtil.*; import static com.oracle.graal.compiler.common.GraalOptions.*; @@ -38,10 +40,9 @@ import java.util.*; -import com.oracle.graal.amd64.*; import com.oracle.graal.asm.*; import com.oracle.graal.asm.amd64.*; -import com.oracle.graal.asm.amd64.AMD64Assembler.ConditionFlag; +import com.oracle.graal.asm.amd64.AMD64Assembler.*; import com.oracle.graal.compiler.common.alloc.*; import com.oracle.graal.compiler.gen.*; import com.oracle.graal.compiler.target.*; @@ -121,7 +122,7 @@ } crb.blockComment("[stack overflow check]"); int pos = asm.position(); - asm.movq(new AMD64Address(rsp, -disp), AMD64.rax); + asm.movl(new AMD64Address(rsp, -disp), AMD64.rax); assert i > 0 || !isVerifiedEntryPoint || asm.position() - pos >= PATCHED_VERIFIED_ENTRY_POINT_INSTRUCTION_SIZE; } } diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotBackendFactory.java --- a/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotBackendFactory.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotBackendFactory.java Thu Jun 04 11:08:12 2015 -0700 @@ -26,7 +26,6 @@ import java.util.*; -import com.oracle.graal.amd64.*; import com.oracle.graal.api.replacements.*; import com.oracle.graal.graphbuilderconf.GraphBuilderConfiguration.Plugins; import com.oracle.graal.hotspot.*; @@ -34,6 +33,7 @@ import com.oracle.graal.hotspot.word.*; import com.oracle.graal.phases.util.*; import com.oracle.graal.replacements.amd64.*; +import com.oracle.jvmci.amd64.*; import com.oracle.jvmci.code.*; import com.oracle.jvmci.hotspot.*; import com.oracle.jvmci.meta.*; @@ -58,7 +58,6 @@ HotSpotLoweringProvider lowerer; HotSpotSnippetReflectionProvider snippetReflection; HotSpotReplacementsImpl replacements; - HotSpotDisassemblerProvider disassembler; HotSpotSuitesProvider suites; HotSpotWordTypes wordTypes; Plugins plugins; @@ -84,9 +83,6 @@ try (InitTimer rt = timer("create Replacements provider")) { replacements = createReplacements(runtime, p, snippetReflection); } - try (InitTimer rt = timer("create Disassembler provider")) { - disassembler = createDisassembler(runtime); - } try (InitTimer rt = timer("create WordTypes")) { wordTypes = new HotSpotWordTypes(metaAccess, target.wordKind); } @@ -97,7 +93,7 @@ try (InitTimer rt = timer("create Suites provider")) { suites = createSuites(runtime, plugins); } - providers = new HotSpotProviders(metaAccess, codeCache, constantReflection, foreignCalls, lowerer, replacements, disassembler, suites, registers, snippetReflection, wordTypes, plugins); + providers = new HotSpotProviders(metaAccess, codeCache, constantReflection, foreignCalls, lowerer, replacements, suites, registers, snippetReflection, wordTypes, plugins); } try (InitTimer rt = timer("instantiate backend")) { return createBackend(runtime, providers); @@ -120,10 +116,6 @@ return new HotSpotRegisters(AMD64.r15, AMD64.r12, AMD64.rsp); } - protected HotSpotDisassemblerProvider createDisassembler(HotSpotGraalRuntimeProvider runtime) { - return new HotSpotDisassemblerProvider(runtime); - } - protected HotSpotReplacementsImpl createReplacements(HotSpotGraalRuntimeProvider runtime, Providers p, SnippetReflectionProvider snippetReflection) { return new HotSpotReplacementsImpl(p, snippetReflection, runtime.getConfig(), p.getCodeCache().getTarget()); } @@ -172,15 +164,15 @@ } else { /* * System V Application Binary Interface, AMD64 Architecture Processor Supplement - * + * * Draft Version 0.96 - * + * * http://www.uclibc.org/docs/psABI-x86_64.pdf - * + * * 3.2.1 - * + * * ... - * + * * This subsection discusses usage of each register. Registers %rbp, %rbx and %r12 * through %r15 "belong" to the calling function and the called function is required to * preserve their values. In other words, a called function must preserve these diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotBinaryConsumer.java --- a/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotBinaryConsumer.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotBinaryConsumer.java Thu Jun 04 11:08:12 2015 -0700 @@ -23,10 +23,11 @@ package com.oracle.graal.hotspot.amd64; import com.oracle.jvmci.meta.AllocatableValue; + import static com.oracle.graal.asm.amd64.AMD64Assembler.OperandSize.*; -import com.oracle.graal.asm.amd64.AMD64Assembler.AMD64MIOp; import com.oracle.graal.asm.amd64.*; +import com.oracle.graal.asm.amd64.AMD64Assembler.*; import com.oracle.graal.lir.*; import com.oracle.graal.lir.amd64.*; import com.oracle.graal.lir.asm.*; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotBytecodeLIRBuilder.java --- a/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotBytecodeLIRBuilder.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotBytecodeLIRBuilder.java Thu Jun 04 11:08:12 2015 -0700 @@ -22,7 +22,7 @@ */ package com.oracle.graal.hotspot.amd64; -import static com.oracle.graal.amd64.AMD64.*; +import static com.oracle.jvmci.amd64.AMD64.*; import com.oracle.graal.compiler.gen.*; import com.oracle.graal.lir.gen.*; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotCRuntimeCallEpilogueOp.java diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotCRuntimeCallPrologueOp.java --- a/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotCRuntimeCallPrologueOp.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotCRuntimeCallPrologueOp.java Thu Jun 04 11:08:12 2015 -0700 @@ -23,7 +23,8 @@ package com.oracle.graal.hotspot.amd64; import com.oracle.jvmci.code.Register; -import static com.oracle.graal.amd64.AMD64.*; + +import static com.oracle.jvmci.amd64.AMD64.*; import com.oracle.graal.asm.amd64.*; import com.oracle.graal.lir.*; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotCardTableAddressOp.java diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotCardTableShiftOp.java diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotCounterOp.java --- a/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotCounterOp.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotCounterOp.java Thu Jun 04 11:08:12 2015 -0700 @@ -26,7 +26,8 @@ import com.oracle.jvmci.code.TargetDescription; import com.oracle.jvmci.code.StackSlotValue; import com.oracle.jvmci.meta.Value; -import static com.oracle.graal.amd64.AMD64.*; + +import static com.oracle.jvmci.amd64.AMD64.*; import static com.oracle.jvmci.code.ValueUtil.*; import static com.oracle.jvmci.common.JVMCIError.*; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotDeoptimizeCallerOp.java diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotEnterUnpackFramesStackFrameOp.java --- a/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotEnterUnpackFramesStackFrameOp.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotEnterUnpackFramesStackFrameOp.java Thu Jun 04 11:08:12 2015 -0700 @@ -27,7 +27,8 @@ import com.oracle.jvmci.code.RegisterSaveLayout; import com.oracle.jvmci.meta.AllocatableValue; import com.oracle.jvmci.meta.Kind; -import static com.oracle.graal.amd64.AMD64.*; + +import static com.oracle.jvmci.amd64.AMD64.*; import static com.oracle.jvmci.code.ValueUtil.*; import static com.oracle.graal.lir.LIRInstruction.OperandFlag.*; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotEpilogueOp.java --- a/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotEpilogueOp.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotEpilogueOp.java Thu Jun 04 11:08:12 2015 -0700 @@ -22,8 +22,8 @@ */ package com.oracle.graal.hotspot.amd64; -import static com.oracle.graal.amd64.AMD64.*; import static com.oracle.graal.lir.LIRInstruction.OperandFlag.*; +import static com.oracle.jvmci.amd64.AMD64.*; import static com.oracle.jvmci.code.ValueUtil.*; import com.oracle.graal.asm.amd64.*; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotForeignCallsProvider.java --- a/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotForeignCallsProvider.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotForeignCallsProvider.java Thu Jun 04 11:08:12 2015 -0700 @@ -30,7 +30,8 @@ import com.oracle.jvmci.meta.LIRKind; import com.oracle.jvmci.meta.MetaAccessProvider; import com.oracle.jvmci.meta.Kind; -import static com.oracle.graal.amd64.AMD64.*; + +import static com.oracle.jvmci.amd64.AMD64.*; import static com.oracle.jvmci.code.CallingConvention.Type.*; import static com.oracle.jvmci.meta.LocationIdentity.*; import static com.oracle.jvmci.meta.Value.*; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotJumpToExceptionHandlerInCallerOp.java --- a/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotJumpToExceptionHandlerInCallerOp.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotJumpToExceptionHandlerInCallerOp.java Thu Jun 04 11:08:12 2015 -0700 @@ -24,12 +24,13 @@ import com.oracle.jvmci.code.Register; import com.oracle.jvmci.meta.AllocatableValue; -import static com.oracle.graal.amd64.AMD64.*; + +import static com.oracle.jvmci.amd64.AMD64.*; import static com.oracle.jvmci.code.ValueUtil.*; import static com.oracle.graal.lir.LIRInstruction.OperandFlag.*; import com.oracle.graal.asm.amd64.*; -import com.oracle.graal.asm.amd64.AMD64Assembler.ConditionFlag; +import com.oracle.graal.asm.amd64.AMD64Assembler.*; import com.oracle.graal.lir.*; import com.oracle.graal.lir.StandardOp.BlockEndOp; import com.oracle.graal.lir.asm.*; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotLIRGenerator.java --- a/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotLIRGenerator.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotLIRGenerator.java Thu Jun 04 11:08:12 2015 -0700 @@ -22,17 +22,15 @@ */ package com.oracle.graal.hotspot.amd64; -import static com.oracle.graal.amd64.AMD64.*; import static com.oracle.graal.asm.amd64.AMD64Assembler.AMD64BinaryArithmetic.*; import static com.oracle.graal.asm.amd64.AMD64Assembler.AMD64RMOp.*; import static com.oracle.graal.asm.amd64.AMD64Assembler.OperandSize.*; import static com.oracle.graal.hotspot.HotSpotBackend.*; +import static com.oracle.jvmci.amd64.AMD64.*; import java.util.*; -import com.oracle.graal.amd64.*; -import com.oracle.graal.asm.amd64.AMD64Assembler.AMD64MIOp; -import com.oracle.graal.asm.amd64.AMD64Assembler.OperandSize; +import com.oracle.graal.asm.amd64.AMD64Assembler.*; import com.oracle.graal.compiler.amd64.*; import com.oracle.graal.compiler.common.*; import com.oracle.graal.compiler.common.spi.*; @@ -50,6 +48,7 @@ import com.oracle.graal.lir.asm.*; import com.oracle.graal.lir.framemap.*; import com.oracle.graal.lir.gen.*; +import com.oracle.jvmci.amd64.*; import com.oracle.jvmci.code.*; import com.oracle.jvmci.common.*; import com.oracle.jvmci.debug.*; @@ -335,7 +334,6 @@ } Variable result; - // TODO (je) check if we can remove this LIRFrameState deoptInfo = null; if (hotspotLinkage.canDeoptimize()) { deoptInfo = state; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotLeaveCurrentStackFrameOp.java --- a/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotLeaveCurrentStackFrameOp.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotLeaveCurrentStackFrameOp.java Thu Jun 04 11:08:12 2015 -0700 @@ -22,7 +22,7 @@ */ package com.oracle.graal.hotspot.amd64; -import static com.oracle.graal.amd64.AMD64.*; +import static com.oracle.jvmci.amd64.AMD64.*; import com.oracle.graal.asm.amd64.*; import com.oracle.graal.lir.*; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotLeaveDeoptimizedStackFrameOp.java --- a/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotLeaveDeoptimizedStackFrameOp.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotLeaveDeoptimizedStackFrameOp.java Thu Jun 04 11:08:12 2015 -0700 @@ -24,7 +24,8 @@ import com.oracle.jvmci.code.Register; import com.oracle.jvmci.meta.AllocatableValue; -import static com.oracle.graal.amd64.AMD64.*; + +import static com.oracle.jvmci.amd64.AMD64.*; import static com.oracle.jvmci.code.ValueUtil.*; import static com.oracle.graal.lir.LIRInstruction.OperandFlag.*; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotLeaveUnpackFramesStackFrameOp.java diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotMove.java --- a/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotMove.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotMove.java Thu Jun 04 11:08:12 2015 -0700 @@ -27,7 +27,7 @@ import com.oracle.graal.asm.*; import com.oracle.graal.asm.amd64.*; -import com.oracle.graal.asm.amd64.AMD64Assembler.ConditionFlag; +import com.oracle.graal.asm.amd64.AMD64Assembler.*; import com.oracle.graal.compiler.common.*; import com.oracle.graal.hotspot.*; import com.oracle.graal.lir.*; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotNodeLIRBuilder.java --- a/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotNodeLIRBuilder.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotNodeLIRBuilder.java Thu Jun 04 11:08:12 2015 -0700 @@ -22,16 +22,13 @@ */ package com.oracle.graal.hotspot.amd64; -import static com.oracle.graal.amd64.AMD64.*; import static com.oracle.graal.asm.amd64.AMD64Assembler.AMD64BinaryArithmetic.*; import static com.oracle.graal.hotspot.HotSpotBackend.*; +import static com.oracle.jvmci.amd64.AMD64.*; import static com.oracle.jvmci.code.ValueUtil.*; -import com.oracle.graal.amd64.*; import com.oracle.graal.asm.*; -import com.oracle.graal.asm.amd64.AMD64Assembler.AMD64RMOp; -import com.oracle.graal.asm.amd64.AMD64Assembler.OperandSize; -import com.oracle.graal.asm.amd64.AMD64Assembler.SSEOp; +import com.oracle.graal.asm.amd64.AMD64Assembler.*; import com.oracle.graal.compiler.amd64.*; import com.oracle.graal.compiler.common.calc.*; import com.oracle.graal.compiler.common.type.*; @@ -50,6 +47,7 @@ import com.oracle.graal.nodes.calc.*; import com.oracle.graal.nodes.extended.*; import com.oracle.graal.nodes.memory.*; +import com.oracle.jvmci.amd64.*; import com.oracle.jvmci.code.*; import com.oracle.jvmci.debug.*; import com.oracle.jvmci.hotspot.*; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotPatchReturnAddressOp.java --- a/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotPatchReturnAddressOp.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotPatchReturnAddressOp.java Thu Jun 04 11:08:12 2015 -0700 @@ -23,7 +23,8 @@ package com.oracle.graal.hotspot.amd64; import com.oracle.jvmci.meta.AllocatableValue; -import static com.oracle.graal.amd64.AMD64.*; + +import static com.oracle.jvmci.amd64.AMD64.*; import static com.oracle.jvmci.code.ValueUtil.*; import static com.oracle.graal.lir.LIRInstruction.OperandFlag.*; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotPushInterpreterFrameOp.java --- a/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotPushInterpreterFrameOp.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotPushInterpreterFrameOp.java Thu Jun 04 11:08:12 2015 -0700 @@ -24,7 +24,8 @@ import com.oracle.jvmci.code.Register; import com.oracle.jvmci.meta.AllocatableValue; -import static com.oracle.graal.amd64.AMD64.*; + +import static com.oracle.jvmci.amd64.AMD64.*; import static com.oracle.jvmci.code.ValueUtil.*; import static com.oracle.graal.lir.LIRInstruction.OperandFlag.*; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotRegisterAllocationConfig.java --- a/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotRegisterAllocationConfig.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotRegisterAllocationConfig.java Thu Jun 04 11:08:12 2015 -0700 @@ -22,7 +22,7 @@ */ package com.oracle.graal.hotspot.amd64; -import static com.oracle.graal.amd64.AMD64.*; +import static com.oracle.jvmci.amd64.AMD64.*; import java.util.*; @@ -55,12 +55,11 @@ @Override protected Register[] initAllocatable(Register[] registers) { BitSet regMap = new BitSet(registerConfig.getAllocatableRegisters().length); - Register[] regs = super.initAllocatable(registers); - for (Register reg : regs) { + for (Register reg : registers) { regMap.set(reg.number); } - Register[] allocatableRegisters = new Register[regs.length]; + Register[] allocatableRegisters = new Register[registers.length]; int i = 0; for (Register reg : registerAllocationOrder) { if (regMap.get(reg.number)) { @@ -69,7 +68,7 @@ } assert i == allocatableRegisters.length; - return allocatableRegisters; + return super.initAllocatable(allocatableRegisters); } @Override diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotRegisterConfig.java --- a/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotRegisterConfig.java Thu Jun 04 10:46:23 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,271 +0,0 @@ -/* - * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.hotspot.amd64; - -import com.oracle.jvmci.code.Register; -import com.oracle.jvmci.code.RegisterConfig; -import com.oracle.jvmci.code.TargetDescription; -import com.oracle.jvmci.code.CallingConvention; -import com.oracle.jvmci.code.StackSlot; -import com.oracle.jvmci.code.RegisterAttributes; -import com.oracle.jvmci.code.CalleeSaveLayout; -import com.oracle.jvmci.code.Architecture; -import com.oracle.jvmci.meta.JavaType; -import com.oracle.jvmci.meta.Value; -import com.oracle.jvmci.meta.PlatformKind; -import com.oracle.jvmci.meta.AllocatableValue; -import com.oracle.jvmci.meta.Kind; -import static com.oracle.graal.amd64.AMD64.*; -import static com.oracle.graal.compiler.common.GraalOptions.*; - -import java.util.*; - -import com.oracle.graal.amd64.*; -import com.oracle.jvmci.code.CallingConvention.Type; -import com.oracle.graal.compiler.common.*; -import com.oracle.jvmci.common.*; -import com.oracle.jvmci.hotspot.*; - -public class AMD64HotSpotRegisterConfig implements RegisterConfig { - - private final Architecture architecture; - - private final Register[] allocatable; - - private final int maxFrameSize; - - /** - * The same as {@link #allocatable}, except if parameter registers are removed with the - * {@link GraalOptions#RegisterPressure} option. The caller saved registers always include all - * parameter registers. - */ - private final Register[] callerSaved; - - private final boolean allAllocatableAreCallerSaved; - - private final RegisterAttributes[] attributesMap; - - public int getMaximumFrameSize() { - return maxFrameSize; - } - - @Override - public Register[] getAllocatableRegisters() { - return allocatable.clone(); - } - - public Register[] filterAllocatableRegisters(PlatformKind kind, Register[] registers) { - ArrayList list = new ArrayList<>(); - for (Register reg : registers) { - if (architecture.canStoreValue(reg.getRegisterCategory(), kind)) { - list.add(reg); - } - } - - Register[] ret = list.toArray(new Register[list.size()]); - return ret; - } - - @Override - public RegisterAttributes[] getAttributesMap() { - return attributesMap.clone(); - } - - private final Register[] javaGeneralParameterRegisters; - private final Register[] nativeGeneralParameterRegisters; - private final Register[] xmmParameterRegisters = {xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7}; - - /* - * Some ABIs (e.g. Windows) require a so-called "home space", that is a save area on the stack - * to store the argument registers - */ - private final boolean needsNativeStackHomeSpace; - - private final CalleeSaveLayout csl; - - private static Register[] initAllocatable(boolean reserveForHeapBase) { - Register[] registers = null; - // @formatter:off - if (reserveForHeapBase) { - registers = new Register[] { - rax, rbx, rcx, rdx, /*rsp,*/ rbp, rsi, rdi, r8, r9, r10, r11, /*r12,*/ r13, r14, /*r15, */ - xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, - xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15 - }; - } else { - registers = new Register[] { - rax, rbx, rcx, rdx, /*rsp,*/ rbp, rsi, rdi, r8, r9, r10, r11, r12, r13, r14, /*r15, */ - xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, - xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15 - }; - } - // @formatter:on - return registers; - } - - public AMD64HotSpotRegisterConfig(Architecture architecture, HotSpotVMConfig config) { - this(architecture, config, initAllocatable(config.useCompressedOops)); - assert callerSaved.length == allocatable.length || RegisterPressure.getValue() != null; - } - - public AMD64HotSpotRegisterConfig(Architecture architecture, HotSpotVMConfig config, Register[] allocatable) { - this.architecture = architecture; - this.maxFrameSize = config.maxFrameSize; - - if (config.windowsOs) { - javaGeneralParameterRegisters = new Register[]{rdx, r8, r9, rdi, rsi, rcx}; - nativeGeneralParameterRegisters = new Register[]{rcx, rdx, r8, r9}; - this.needsNativeStackHomeSpace = true; - } else { - javaGeneralParameterRegisters = new Register[]{rsi, rdx, rcx, r8, r9, rdi}; - nativeGeneralParameterRegisters = new Register[]{rdi, rsi, rdx, rcx, r8, r9}; - this.needsNativeStackHomeSpace = false; - } - - csl = null; - this.allocatable = allocatable.clone(); - Set callerSaveSet = new HashSet<>(); - Collections.addAll(callerSaveSet, allocatable); - Collections.addAll(callerSaveSet, xmmParameterRegisters); - Collections.addAll(callerSaveSet, javaGeneralParameterRegisters); - Collections.addAll(callerSaveSet, nativeGeneralParameterRegisters); - callerSaved = callerSaveSet.toArray(new Register[callerSaveSet.size()]); - - allAllocatableAreCallerSaved = true; - attributesMap = RegisterAttributes.createMap(this, AMD64.allRegisters); - } - - @Override - public Register[] getCallerSaveRegisters() { - return callerSaved; - } - - @Override - public boolean areAllAllocatableRegistersCallerSaved() { - return allAllocatableAreCallerSaved; - } - - @Override - public Register getRegisterForRole(int index) { - throw new UnsupportedOperationException(); - } - - @Override - public CallingConvention getCallingConvention(Type type, JavaType returnType, JavaType[] parameterTypes, TargetDescription target, boolean stackOnly) { - if (type == Type.NativeCall) { - return callingConvention(nativeGeneralParameterRegisters, returnType, parameterTypes, type, target, stackOnly); - } - // On x64, parameter locations are the same whether viewed - // from the caller or callee perspective - return callingConvention(javaGeneralParameterRegisters, returnType, parameterTypes, type, target, stackOnly); - } - - public Register[] getCallingConventionRegisters(Type type, Kind kind) { - if (architecture.canStoreValue(XMM, kind)) { - return xmmParameterRegisters; - } - assert architecture.canStoreValue(CPU, kind); - return type == Type.NativeCall ? nativeGeneralParameterRegisters : javaGeneralParameterRegisters; - } - - private CallingConvention callingConvention(Register[] generalParameterRegisters, JavaType returnType, JavaType[] parameterTypes, Type type, TargetDescription target, boolean stackOnly) { - AllocatableValue[] locations = new AllocatableValue[parameterTypes.length]; - - int currentGeneral = 0; - int currentXMM = 0; - int currentStackOffset = type == Type.NativeCall && needsNativeStackHomeSpace ? generalParameterRegisters.length * target.wordSize : 0; - - for (int i = 0; i < parameterTypes.length; i++) { - final Kind kind = parameterTypes[i].getKind(); - - switch (kind) { - case Byte: - case Boolean: - case Short: - case Char: - case Int: - case Long: - case Object: - if (!stackOnly && currentGeneral < generalParameterRegisters.length) { - Register register = generalParameterRegisters[currentGeneral++]; - locations[i] = register.asValue(target.getLIRKind(kind)); - } - break; - case Float: - case Double: - if (!stackOnly && currentXMM < xmmParameterRegisters.length) { - Register register = xmmParameterRegisters[currentXMM++]; - locations[i] = register.asValue(target.getLIRKind(kind)); - } - break; - default: - throw JVMCIError.shouldNotReachHere(); - } - - if (locations[i] == null) { - locations[i] = StackSlot.get(target.getLIRKind(kind.getStackKind()), currentStackOffset, !type.out); - currentStackOffset += Math.max(target.getSizeInBytes(kind), target.wordSize); - } - } - - Kind returnKind = returnType == null ? Kind.Void : returnType.getKind(); - AllocatableValue returnLocation = returnKind == Kind.Void ? Value.ILLEGAL : getReturnRegister(returnKind).asValue(target.getLIRKind(returnKind.getStackKind())); - return new CallingConvention(currentStackOffset, returnLocation, locations); - } - - @Override - public Register getReturnRegister(Kind kind) { - switch (kind) { - case Boolean: - case Byte: - case Char: - case Short: - case Int: - case Long: - case Object: - return rax; - case Float: - case Double: - return xmm0; - case Void: - case Illegal: - return null; - default: - throw new UnsupportedOperationException("no return register for type " + kind); - } - } - - @Override - public Register getFrameRegister() { - return rsp; - } - - public CalleeSaveLayout getCalleeSaveLayout() { - return csl; - } - - @Override - public String toString() { - return String.format("Allocatable: " + Arrays.toString(getAllocatableRegisters()) + "%n" + "CallerSave: " + Arrays.toString(getCallerSaveRegisters()) + "%n"); - } -} diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotReturnOp.java diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotSafepointOp.java --- a/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotSafepointOp.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotSafepointOp.java Thu Jun 04 11:08:12 2015 -0700 @@ -30,9 +30,10 @@ import com.oracle.jvmci.meta.JavaConstant; import com.oracle.jvmci.meta.AllocatableValue; import com.oracle.jvmci.meta.Kind; -import static com.oracle.graal.amd64.AMD64.*; + import static com.oracle.graal.asm.NumUtil.*; import static com.oracle.graal.compiler.common.GraalOptions.*; +import static com.oracle.jvmci.amd64.AMD64.*; import com.oracle.graal.asm.amd64.*; import com.oracle.graal.lir.*; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotUnwindOp.java --- a/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotUnwindOp.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotUnwindOp.java Thu Jun 04 11:08:12 2015 -0700 @@ -22,9 +22,9 @@ */ package com.oracle.graal.hotspot.amd64; -import static com.oracle.graal.amd64.AMD64.*; import static com.oracle.graal.hotspot.HotSpotBackend.*; import static com.oracle.graal.lir.LIRInstruction.OperandFlag.*; +import static com.oracle.jvmci.amd64.AMD64.*; import static com.oracle.jvmci.code.ValueUtil.*; import com.oracle.graal.asm.amd64.*; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotspotDirectStaticCallOp.java diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotspotDirectVirtualCallOp.java --- a/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotspotDirectVirtualCallOp.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotspotDirectVirtualCallOp.java Thu Jun 04 11:08:12 2015 -0700 @@ -24,12 +24,12 @@ import com.oracle.jvmci.meta.Value; import com.oracle.jvmci.meta.ResolvedJavaMethod; -import com.oracle.graal.amd64.*; import com.oracle.graal.asm.amd64.*; import com.oracle.graal.lir.*; import com.oracle.graal.lir.amd64.AMD64Call.DirectCallOp; import com.oracle.graal.lir.asm.*; import com.oracle.graal.nodes.CallTargetNode.InvokeKind; +import com.oracle.jvmci.amd64.*; import com.oracle.jvmci.hotspot.*; /** diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64IndirectCallOp.java --- a/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64IndirectCallOp.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64IndirectCallOp.java Thu Jun 04 11:08:12 2015 -0700 @@ -22,13 +22,14 @@ */ package com.oracle.graal.hotspot.amd64; +import com.oracle.jvmci.amd64.*; import com.oracle.jvmci.code.Register; import com.oracle.jvmci.meta.Value; import com.oracle.jvmci.meta.ResolvedJavaMethod; + import static com.oracle.jvmci.code.ValueUtil.*; import static com.oracle.graal.lir.LIRInstruction.OperandFlag.*; -import com.oracle.graal.amd64.*; import com.oracle.graal.asm.amd64.*; import com.oracle.graal.lir.*; import com.oracle.graal.lir.amd64.*; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64PrefetchOp.java diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64TailcallOp.java diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64UncommonTrapStub.java --- a/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64UncommonTrapStub.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64UncommonTrapStub.java Thu Jun 04 11:08:12 2015 -0700 @@ -25,12 +25,14 @@ import com.oracle.jvmci.code.Register; import com.oracle.jvmci.code.RegisterConfig; import com.oracle.jvmci.code.TargetDescription; -import static com.oracle.graal.amd64.AMD64.*; + +import static com.oracle.jvmci.amd64.AMD64.*; import com.oracle.graal.hotspot.*; import com.oracle.graal.hotspot.meta.*; import com.oracle.graal.hotspot.stubs.*; import com.oracle.jvmci.hotspot.*; +import com.oracle.jvmci.hotspot.amd64.*; final class AMD64UncommonTrapStub extends UncommonTrapStub { diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/jvmci/AMD64HotSpotJVMCIBackendFactory.java --- a/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/jvmci/AMD64HotSpotJVMCIBackendFactory.java Thu Jun 04 10:46:23 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,171 +0,0 @@ -/* - * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.hotspot.amd64.jvmci; - -import static com.oracle.jvmci.hotspot.InitTimer.*; - -import java.util.*; - -import com.oracle.graal.amd64.*; -import com.oracle.graal.hotspot.*; -import com.oracle.graal.hotspot.amd64.*; -import com.oracle.jvmci.code.*; -import com.oracle.jvmci.hotspot.*; -import com.oracle.jvmci.meta.*; -import com.oracle.jvmci.runtime.*; -import com.oracle.jvmci.service.*; - -@ServiceProvider(HotSpotJVMCIBackendFactory.class) -public class AMD64HotSpotJVMCIBackendFactory implements HotSpotJVMCIBackendFactory { - - protected Architecture createArchitecture(HotSpotVMConfig config) { - return new AMD64(computeFeatures(config), computeFlags(config)); - } - - protected EnumSet computeFeatures(HotSpotVMConfig config) { - // Configure the feature set using the HotSpot flag settings. - EnumSet features = EnumSet.noneOf(AMD64.CPUFeature.class); - assert config.useSSE >= 2 : "minimum config for x64"; - features.add(AMD64.CPUFeature.SSE); - features.add(AMD64.CPUFeature.SSE2); - if ((config.x86CPUFeatures & config.cpuSSE3) != 0) { - features.add(AMD64.CPUFeature.SSE3); - } - if ((config.x86CPUFeatures & config.cpuSSSE3) != 0) { - features.add(AMD64.CPUFeature.SSSE3); - } - if ((config.x86CPUFeatures & config.cpuSSE4A) != 0) { - features.add(AMD64.CPUFeature.SSE4a); - } - if ((config.x86CPUFeatures & config.cpuSSE41) != 0) { - features.add(AMD64.CPUFeature.SSE4_1); - } - if ((config.x86CPUFeatures & config.cpuSSE42) != 0) { - features.add(AMD64.CPUFeature.SSE4_2); - } - if ((config.x86CPUFeatures & config.cpuAVX) != 0) { - features.add(AMD64.CPUFeature.AVX); - } - if ((config.x86CPUFeatures & config.cpuAVX2) != 0) { - features.add(AMD64.CPUFeature.AVX2); - } - if ((config.x86CPUFeatures & config.cpuERMS) != 0) { - features.add(AMD64.CPUFeature.ERMS); - } - if ((config.x86CPUFeatures & config.cpuLZCNT) != 0) { - features.add(AMD64.CPUFeature.LZCNT); - } - if ((config.x86CPUFeatures & config.cpuPOPCNT) != 0) { - features.add(AMD64.CPUFeature.POPCNT); - } - if ((config.x86CPUFeatures & config.cpuAES) != 0) { - features.add(AMD64.CPUFeature.AES); - } - if ((config.x86CPUFeatures & config.cpu3DNOWPREFETCH) != 0) { - features.add(AMD64.CPUFeature.AMD_3DNOW_PREFETCH); - } - if ((config.x86CPUFeatures & config.cpuBMI1) != 0) { - features.add(AMD64.CPUFeature.BMI1); - } - return features; - } - - protected EnumSet computeFlags(HotSpotVMConfig config) { - EnumSet flags = EnumSet.noneOf(AMD64.Flag.class); - if (config.useCountLeadingZerosInstruction) { - flags.add(AMD64.Flag.UseCountLeadingZerosInstruction); - } - if (config.useCountTrailingZerosInstruction) { - flags.add(AMD64.Flag.UseCountTrailingZerosInstruction); - } - return flags; - } - - protected TargetDescription createTarget(HotSpotVMConfig config) { - final int stackFrameAlignment = 16; - final int implicitNullCheckLimit = 4096; - final boolean inlineObjects = true; - return new HotSpotTargetDescription(createArchitecture(config), true, stackFrameAlignment, implicitNullCheckLimit, inlineObjects); - } - - protected HotSpotConstantReflectionProvider createConstantReflection(HotSpotJVMCIRuntimeProvider runtime) { - return new HotSpotConstantReflectionProvider(runtime); - } - - protected RegisterConfig createRegisterConfig(HotSpotJVMCIRuntimeProvider runtime, TargetDescription target) { - return new AMD64HotSpotRegisterConfig(target.arch, runtime.getConfig()); - } - - protected HotSpotCodeCacheProvider createCodeCache(HotSpotJVMCIRuntimeProvider runtime, TargetDescription target, RegisterConfig regConfig) { - return new HotSpotCodeCacheProvider(runtime, runtime.getConfig(), target, regConfig); - } - - protected HotSpotMetaAccessProvider createMetaAccess(HotSpotJVMCIRuntimeProvider runtime) { - return new HotSpotMetaAccessProvider(runtime); - } - - public String getArchitecture() { - return "AMD64"; - } - - @Override - public String toString() { - return getJVMCIRuntimeName() + ":" + getArchitecture(); - } - - public JVMCIBackend createJVMCIBackend(HotSpotJVMCIRuntimeProvider runtime, JVMCIBackend host) { - - assert host == null; - TargetDescription target = createTarget(runtime.getConfig()); - - RegisterConfig regConfig; - HotSpotCodeCacheProvider codeCache; - ConstantReflectionProvider constantReflection; - HotSpotMetaAccessProvider metaAccess; - try (InitTimer t = timer("create providers")) { - try (InitTimer rt = timer("create MetaAccess provider")) { - metaAccess = createMetaAccess(runtime); - } - try (InitTimer rt = timer("create RegisterConfig")) { - regConfig = createRegisterConfig(runtime, target); - } - try (InitTimer rt = timer("create CodeCache provider")) { - codeCache = createCodeCache(runtime, target, regConfig); - } - try (InitTimer rt = timer("create ConstantReflection provider")) { - constantReflection = createConstantReflection(runtime); - } - } - try (InitTimer rt = timer("instantiate backend")) { - return createBackend(metaAccess, codeCache, constantReflection); - } - } - - protected JVMCIBackend createBackend(HotSpotMetaAccessProvider metaAccess, HotSpotCodeCacheProvider codeCache, ConstantReflectionProvider constantReflection) { - return new JVMCIBackend(metaAccess, codeCache, constantReflection); - } - - public String getJVMCIRuntimeName() { - return "basic"; - } -} diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCDeoptimizationStub.java --- a/graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCDeoptimizationStub.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCDeoptimizationStub.java Thu Jun 04 11:08:12 2015 -0700 @@ -25,7 +25,9 @@ import com.oracle.jvmci.code.TargetDescription; import com.oracle.jvmci.code.RegisterConfig; import com.oracle.jvmci.code.Register; -import static com.oracle.graal.sparc.SPARC.*; +import com.oracle.jvmci.hotspot.sparc.*; + +import static com.oracle.jvmci.sparc.SPARC.*; import com.oracle.graal.hotspot.*; import com.oracle.graal.hotspot.meta.*; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCDeoptimizeOp.java diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotBackend.java --- a/graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotBackend.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotBackend.java Thu Jun 04 11:08:12 2015 -0700 @@ -29,6 +29,7 @@ import com.oracle.jvmci.code.Register; import com.oracle.jvmci.meta.ResolvedJavaMethod; import com.oracle.jvmci.meta.JavaType; + import static com.oracle.jvmci.code.CallingConvention.Type.*; import static com.oracle.jvmci.code.ValueUtil.*; import static com.oracle.graal.asm.sparc.SPARCAssembler.Annul.*; @@ -36,15 +37,14 @@ import static com.oracle.graal.asm.sparc.SPARCAssembler.CC.*; import static com.oracle.graal.asm.sparc.SPARCAssembler.ConditionFlag.*; import static com.oracle.graal.compiler.common.GraalOptions.*; -import static com.oracle.graal.sparc.SPARC.*; import static com.oracle.jvmci.common.UnsafeAccess.*; +import static com.oracle.jvmci.sparc.SPARC.*; import java.util.*; import com.oracle.graal.asm.*; import com.oracle.graal.asm.sparc.*; -import com.oracle.graal.asm.sparc.SPARCMacroAssembler.ScratchRegister; -import com.oracle.graal.asm.sparc.SPARCMacroAssembler.Setx; +import com.oracle.graal.asm.sparc.SPARCMacroAssembler.*; import com.oracle.graal.compiler.common.alloc.*; import com.oracle.graal.compiler.common.cfg.*; import com.oracle.graal.hotspot.*; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotBackendFactory.java --- a/graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotBackendFactory.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotBackendFactory.java Thu Jun 04 11:08:12 2015 -0700 @@ -31,12 +31,12 @@ import com.oracle.graal.nodes.spi.*; import com.oracle.graal.phases.util.*; import com.oracle.graal.replacements.sparc.*; -import com.oracle.graal.sparc.*; import com.oracle.jvmci.code.*; import com.oracle.jvmci.hotspot.*; import com.oracle.jvmci.meta.*; import com.oracle.jvmci.runtime.*; import com.oracle.jvmci.service.*; +import com.oracle.jvmci.sparc.*; @ServiceProvider(HotSpotBackendFactory.class) public class SPARCHotSpotBackendFactory implements HotSpotBackendFactory { @@ -57,13 +57,11 @@ Providers p = new Providers(metaAccess, codeCache, constantReflection, foreignCalls, lowerer, null, stampProvider); HotSpotSnippetReflectionProvider snippetReflection = new HotSpotSnippetReflectionProvider(runtime); HotSpotReplacementsImpl replacements = new HotSpotReplacementsImpl(p, snippetReflection, runtime.getConfig(), target); - HotSpotDisassemblerProvider disassembler = new HotSpotDisassemblerProvider(runtime); HotSpotWordTypes wordTypes = new HotSpotWordTypes(metaAccess, target.wordKind); Plugins plugins = createGraphBuilderPlugins(runtime, metaAccess, constantReflection, foreignCalls, stampProvider, snippetReflection, replacements, wordTypes); replacements.setGraphBuilderPlugins(plugins); HotSpotSuitesProvider suites = createSuites(runtime, plugins); - HotSpotProviders providers = new HotSpotProviders(metaAccess, codeCache, constantReflection, foreignCalls, lowerer, replacements, disassembler, suites, registers, snippetReflection, - wordTypes, plugins); + HotSpotProviders providers = new HotSpotProviders(metaAccess, codeCache, constantReflection, foreignCalls, lowerer, replacements, suites, registers, snippetReflection, wordTypes, plugins); return createBackend(runtime, providers); } diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotCRuntimeCallEpilogueOp.java --- a/graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotCRuntimeCallEpilogueOp.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotCRuntimeCallEpilogueOp.java Thu Jun 04 11:08:12 2015 -0700 @@ -26,8 +26,9 @@ import com.oracle.jvmci.meta.Kind; import com.oracle.jvmci.meta.LIRKind; import com.oracle.jvmci.meta.Value; + import static com.oracle.graal.lir.LIRInstruction.OperandFlag.*; -import static com.oracle.graal.sparc.SPARC.*; +import static com.oracle.jvmci.sparc.SPARC.*; import com.oracle.graal.asm.sparc.*; import com.oracle.graal.lir.*; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotCRuntimeCallPrologueOp.java --- a/graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotCRuntimeCallPrologueOp.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotCRuntimeCallPrologueOp.java Thu Jun 04 11:08:12 2015 -0700 @@ -26,8 +26,9 @@ import com.oracle.jvmci.meta.Kind; import com.oracle.jvmci.meta.LIRKind; import com.oracle.jvmci.meta.Value; + import static com.oracle.graal.lir.LIRInstruction.OperandFlag.*; -import static com.oracle.graal.sparc.SPARC.*; +import static com.oracle.jvmci.sparc.SPARC.*; import com.oracle.graal.asm.sparc.*; import com.oracle.graal.lir.*; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotCounterOp.java --- a/graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotCounterOp.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotCounterOp.java Thu Jun 04 11:08:12 2015 -0700 @@ -25,13 +25,13 @@ import com.oracle.jvmci.code.TargetDescription; import com.oracle.jvmci.code.Register; import com.oracle.jvmci.meta.Value; + +import static com.oracle.graal.asm.sparc.SPARCAssembler.*; import static com.oracle.jvmci.code.ValueUtil.*; -import static com.oracle.graal.asm.sparc.SPARCAssembler.*; import com.oracle.graal.asm.*; import com.oracle.graal.asm.sparc.*; -import com.oracle.graal.asm.sparc.SPARCMacroAssembler.ScratchRegister; -import com.oracle.graal.asm.sparc.SPARCMacroAssembler.Setx; +import com.oracle.graal.asm.sparc.SPARCMacroAssembler.*; import com.oracle.graal.hotspot.*; import com.oracle.graal.hotspot.meta.*; import com.oracle.graal.lir.*; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotDeoptimizeCallerOp.java --- a/graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotDeoptimizeCallerOp.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotDeoptimizeCallerOp.java Thu Jun 04 11:08:12 2015 -0700 @@ -23,10 +23,11 @@ package com.oracle.graal.hotspot.sparc; import com.oracle.jvmci.code.Register; + import static com.oracle.graal.hotspot.HotSpotHostBackend.*; import com.oracle.graal.asm.sparc.*; -import com.oracle.graal.asm.sparc.SPARCMacroAssembler.ScratchRegister; +import com.oracle.graal.asm.sparc.SPARCMacroAssembler.*; import com.oracle.graal.lir.*; import com.oracle.graal.lir.asm.*; import com.oracle.graal.lir.sparc.*; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotEnterUnpackFramesStackFrameOp.java --- a/graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotEnterUnpackFramesStackFrameOp.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotEnterUnpackFramesStackFrameOp.java Thu Jun 04 11:08:12 2015 -0700 @@ -24,9 +24,10 @@ import com.oracle.jvmci.code.Register; import com.oracle.jvmci.meta.AllocatableValue; + import static com.oracle.jvmci.code.ValueUtil.*; +import static com.oracle.jvmci.sparc.SPARC.*; import static com.oracle.graal.lir.LIRInstruction.OperandFlag.*; -import static com.oracle.graal.sparc.SPARC.*; import com.oracle.graal.asm.sparc.*; import com.oracle.graal.hotspot.*; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotForeignCallsProvider.java --- a/graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotForeignCallsProvider.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotForeignCallsProvider.java Thu Jun 04 11:08:12 2015 -0700 @@ -30,15 +30,16 @@ import com.oracle.jvmci.meta.Kind; import com.oracle.jvmci.meta.LIRKind; import com.oracle.jvmci.meta.Value; + import static com.oracle.jvmci.meta.LocationIdentity.*; import static com.oracle.jvmci.meta.Value.*; +import static com.oracle.jvmci.sparc.SPARC.*; import static com.oracle.graal.hotspot.HotSpotBackend.*; import static com.oracle.graal.hotspot.HotSpotBackend.Options.*; import static com.oracle.graal.hotspot.HotSpotForeignCallLinkage.*; import static com.oracle.graal.hotspot.HotSpotForeignCallLinkage.RegisterEffect.*; import static com.oracle.graal.hotspot.HotSpotForeignCallLinkage.Transition.*; import static com.oracle.graal.hotspot.HotSpotHostBackend.*; -import static com.oracle.graal.sparc.SPARC.*; import com.oracle.graal.hotspot.*; import com.oracle.graal.hotspot.meta.*; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotJumpToExceptionHandlerInCallerOp.java --- a/graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotJumpToExceptionHandlerInCallerOp.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotJumpToExceptionHandlerInCallerOp.java Thu Jun 04 11:08:12 2015 -0700 @@ -24,14 +24,14 @@ import com.oracle.jvmci.code.Register; import com.oracle.jvmci.meta.AllocatableValue; + import static com.oracle.jvmci.code.ValueUtil.*; +import static com.oracle.jvmci.sparc.SPARC.*; import static com.oracle.graal.lir.LIRInstruction.OperandFlag.*; -import static com.oracle.graal.sparc.SPARC.*; import com.oracle.graal.asm.sparc.*; -import com.oracle.graal.asm.sparc.SPARCAssembler.CC; -import com.oracle.graal.asm.sparc.SPARCAssembler.ConditionFlag; -import com.oracle.graal.asm.sparc.SPARCMacroAssembler.ScratchRegister; +import com.oracle.graal.asm.sparc.SPARCAssembler.*; +import com.oracle.graal.asm.sparc.SPARCMacroAssembler.*; import com.oracle.graal.lir.*; import com.oracle.graal.lir.asm.*; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotJumpToExceptionHandlerOp.java --- a/graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotJumpToExceptionHandlerOp.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotJumpToExceptionHandlerOp.java Thu Jun 04 11:08:12 2015 -0700 @@ -24,6 +24,7 @@ import com.oracle.jvmci.code.Register; import com.oracle.jvmci.meta.AllocatableValue; + import static com.oracle.jvmci.code.ValueUtil.*; import static com.oracle.graal.lir.LIRInstruction.OperandFlag.*; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotLIRGenerator.java --- a/graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotLIRGenerator.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotLIRGenerator.java Thu Jun 04 11:08:12 2015 -0700 @@ -37,10 +37,12 @@ import com.oracle.jvmci.meta.LIRKind; import com.oracle.jvmci.meta.Value; import com.oracle.jvmci.meta.AllocatableValue; +import com.oracle.jvmci.sparc.*; + import static com.oracle.jvmci.code.ValueUtil.*; +import static com.oracle.jvmci.sparc.SPARC.*; import static com.oracle.graal.hotspot.HotSpotBackend.*; import static com.oracle.graal.hotspot.HotSpotGraalRuntime.*; -import static com.oracle.graal.sparc.SPARC.*; import java.util.*; @@ -60,7 +62,6 @@ import com.oracle.graal.lir.sparc.SPARCMove.NullCheckOp; import com.oracle.graal.lir.sparc.SPARCMove.StoreConstantOp; import com.oracle.graal.lir.sparc.SPARCMove.StoreOp; -import com.oracle.graal.sparc.*; import com.oracle.jvmci.common.*; import com.oracle.jvmci.hotspot.*; import com.oracle.jvmci.hotspot.HotSpotVMConfig.CompressEncoding; @@ -137,7 +138,6 @@ public Variable emitForeignCall(ForeignCallLinkage linkage, LIRFrameState state, Value... args) { HotSpotForeignCallLinkage hotspotLinkage = (HotSpotForeignCallLinkage) linkage; Variable result; - // TODO (je) check if this can be removed LIRFrameState deoptInfo = null; if (hotspotLinkage.canDeoptimize()) { deoptInfo = state; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotLeaveCurrentStackFrameOp.java --- a/graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotLeaveCurrentStackFrameOp.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotLeaveCurrentStackFrameOp.java Thu Jun 04 11:08:12 2015 -0700 @@ -22,7 +22,7 @@ */ package com.oracle.graal.hotspot.sparc; -import static com.oracle.graal.sparc.SPARC.*; +import static com.oracle.jvmci.sparc.SPARC.*; import com.oracle.graal.asm.sparc.*; import com.oracle.graal.lir.*; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotLeaveDeoptimizedStackFrameOp.java --- a/graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotLeaveDeoptimizedStackFrameOp.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotLeaveDeoptimizedStackFrameOp.java Thu Jun 04 11:08:12 2015 -0700 @@ -22,7 +22,7 @@ */ package com.oracle.graal.hotspot.sparc; -import static com.oracle.graal.sparc.SPARC.*; +import static com.oracle.jvmci.sparc.SPARC.*; import com.oracle.graal.asm.sparc.*; import com.oracle.graal.lir.*; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotLeaveUnpackFramesStackFrameOp.java --- a/graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotLeaveUnpackFramesStackFrameOp.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotLeaveUnpackFramesStackFrameOp.java Thu Jun 04 11:08:12 2015 -0700 @@ -23,7 +23,8 @@ package com.oracle.graal.hotspot.sparc; import com.oracle.jvmci.code.Register; -import static com.oracle.graal.sparc.SPARC.*; + +import static com.oracle.jvmci.sparc.SPARC.*; import com.oracle.graal.asm.sparc.*; import com.oracle.graal.hotspot.*; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotMove.java --- a/graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotMove.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotMove.java Thu Jun 04 11:08:12 2015 -0700 @@ -28,24 +28,21 @@ import com.oracle.jvmci.meta.Kind; import com.oracle.jvmci.meta.Value; import com.oracle.jvmci.meta.AllocatableValue; +import com.oracle.jvmci.sparc.*; + import static com.oracle.jvmci.code.ValueUtil.*; import static com.oracle.graal.lir.LIRInstruction.OperandFlag.*; import com.oracle.graal.asm.*; import com.oracle.graal.asm.sparc.*; -import com.oracle.graal.asm.sparc.SPARCAssembler.Annul; -import com.oracle.graal.asm.sparc.SPARCAssembler.BranchPredict; -import com.oracle.graal.asm.sparc.SPARCAssembler.CC; -import com.oracle.graal.asm.sparc.SPARCAssembler.ConditionFlag; -import com.oracle.graal.asm.sparc.SPARCAssembler.RCondition; -import com.oracle.graal.asm.sparc.SPARCMacroAssembler.ScratchRegister; +import com.oracle.graal.asm.sparc.SPARCAssembler.*; +import com.oracle.graal.asm.sparc.SPARCMacroAssembler.*; import com.oracle.graal.compiler.common.*; import com.oracle.graal.hotspot.*; import com.oracle.graal.lir.*; import com.oracle.graal.lir.StandardOp.MoveOp; import com.oracle.graal.lir.asm.*; import com.oracle.graal.lir.sparc.*; -import com.oracle.graal.sparc.*; import com.oracle.jvmci.common.*; import com.oracle.jvmci.hotspot.*; import com.oracle.jvmci.hotspot.HotSpotVMConfig.CompressEncoding; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotNodeLIRBuilder.java --- a/graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotNodeLIRBuilder.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotNodeLIRBuilder.java Thu Jun 04 11:08:12 2015 -0700 @@ -22,19 +22,9 @@ */ package com.oracle.graal.hotspot.sparc; -import com.oracle.jvmci.code.ForeignCallLinkage; -import com.oracle.jvmci.code.ValueUtil; -import com.oracle.jvmci.code.CallingConvention; -import com.oracle.jvmci.code.BytecodeFrame; -import com.oracle.jvmci.code.Register; -import com.oracle.jvmci.code.RegisterValue; -import com.oracle.jvmci.meta.Kind; -import com.oracle.jvmci.meta.LIRKind; -import com.oracle.jvmci.meta.Value; -import com.oracle.jvmci.meta.AllocatableValue; +import static com.oracle.graal.hotspot.HotSpotBackend.*; import static com.oracle.jvmci.code.ValueUtil.*; -import static com.oracle.graal.hotspot.HotSpotBackend.*; -import static com.oracle.graal.sparc.SPARC.*; +import static com.oracle.jvmci.sparc.SPARC.*; import com.oracle.graal.compiler.gen.*; import com.oracle.graal.compiler.sparc.*; @@ -47,8 +37,10 @@ import com.oracle.graal.lir.sparc.SPARCMove.CompareAndSwapOp; import com.oracle.graal.nodes.CallTargetNode.InvokeKind; import com.oracle.graal.nodes.*; +import com.oracle.jvmci.code.*; import com.oracle.jvmci.debug.*; import com.oracle.jvmci.hotspot.*; +import com.oracle.jvmci.meta.*; public class SPARCHotSpotNodeLIRBuilder extends SPARCNodeLIRBuilder implements HotSpotNodeLIRBuilder { diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotPatchReturnAddressOp.java --- a/graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotPatchReturnAddressOp.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotPatchReturnAddressOp.java Thu Jun 04 11:08:12 2015 -0700 @@ -24,9 +24,10 @@ import com.oracle.jvmci.code.Register; import com.oracle.jvmci.meta.AllocatableValue; + import static com.oracle.jvmci.code.ValueUtil.*; +import static com.oracle.jvmci.sparc.SPARC.*; import static com.oracle.graal.lir.LIRInstruction.OperandFlag.*; -import static com.oracle.graal.sparc.SPARC.*; import com.oracle.graal.asm.sparc.*; import com.oracle.graal.lir.*; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotPushInterpreterFrameOp.java --- a/graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotPushInterpreterFrameOp.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotPushInterpreterFrameOp.java Thu Jun 04 11:08:12 2015 -0700 @@ -24,9 +24,10 @@ import com.oracle.jvmci.code.Register; import com.oracle.jvmci.meta.AllocatableValue; + import static com.oracle.jvmci.code.ValueUtil.*; +import static com.oracle.jvmci.sparc.SPARC.*; import static com.oracle.graal.lir.LIRInstruction.OperandFlag.*; -import static com.oracle.graal.sparc.SPARC.*; import com.oracle.graal.asm.sparc.*; import com.oracle.graal.lir.*; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotRegisterConfig.java --- a/graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotRegisterConfig.java Thu Jun 04 10:46:23 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,301 +0,0 @@ -/* - * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.hotspot.sparc; - -import com.oracle.jvmci.code.Architecture; -import com.oracle.jvmci.code.TargetDescription; -import com.oracle.jvmci.code.CallingConvention; -import com.oracle.jvmci.code.CalleeSaveLayout; -import com.oracle.jvmci.code.RegisterAttributes; -import com.oracle.jvmci.code.StackSlot; -import com.oracle.jvmci.code.RegisterConfig; -import com.oracle.jvmci.code.Register; -import com.oracle.jvmci.meta.Kind; -import com.oracle.jvmci.meta.JavaType; -import com.oracle.jvmci.meta.PlatformKind; -import com.oracle.jvmci.meta.Value; -import com.oracle.jvmci.meta.AllocatableValue; -import static com.oracle.graal.sparc.SPARC.*; - -import java.util.*; - -import com.oracle.jvmci.code.CallingConvention.Type; -import com.oracle.graal.asm.*; -import com.oracle.graal.lir.framemap.*; -import com.oracle.graal.sparc.*; -import com.oracle.jvmci.common.*; -import com.oracle.jvmci.hotspot.*; - -public class SPARCHotSpotRegisterConfig implements RegisterConfig { - - private final Architecture architecture; - - private final Register[] allocatable; - - private final RegisterAttributes[] attributesMap; - - @Override - public Register[] getAllocatableRegisters() { - return allocatable.clone(); - } - - public Register[] filterAllocatableRegisters(PlatformKind kind, Register[] registers) { - ArrayList list = new ArrayList<>(); - for (Register reg : registers) { - if (architecture.canStoreValue(reg.getRegisterCategory(), kind)) { - // Special treatment for double precision - // TODO: This is wasteful it uses only half of the registers as float. - if (kind == Kind.Double) { - if (reg.name.startsWith("d")) { - list.add(reg); - } - } else if (kind == Kind.Float) { - if (reg.name.startsWith("f")) { - list.add(reg); - } - } else { - list.add(reg); - } - } - } - - Register[] ret = list.toArray(new Register[list.size()]); - return ret; - } - - @Override - public RegisterAttributes[] getAttributesMap() { - return attributesMap.clone(); - } - - private final Register[] cpuCallerParameterRegisters = {o0, o1, o2, o3, o4, o5}; - private final Register[] cpuCalleeParameterRegisters = {i0, i1, i2, i3, i4, i5}; - - private final Register[] fpuParameterRegisters = {f0, f1, f2, f3, f4, f5, f6, f7}; - private final Register[] fpuDoubleParameterRegisters = {d0, null, d2, null, d4, null, d6, null}; - // @formatter:off - private final Register[] callerSaveRegisters = - {g1, g2, g3, g4, g5, g6, g7, - o0, o1, o2, o3, o4, o5, o7, - f0, f1, f2, f3, f4, f5, f6, f7, - f8, f9, f10, f11, f12, f13, f14, f15, - f16, f17, f18, f19, f20, f21, f22, f23, - f24, f25, f26, f27, f28, f29, f30, f31, - d32, d34, d36, d38, d40, d42, d44, d46, - d48, d50, d52, d54, d56, d58, d60, d62}; - // @formatter:on - - /** - * Registers saved by the callee. This lists all L and I registers which are saved in the - * register window. {@link FrameMap} uses this array to calculate the spill area size. - */ - private final Register[] calleeSaveRegisters = {l0, l1, l2, l3, l4, l5, l6, l7, i0, i1, i2, i3, i4, i5, i6, i7}; - - private final CalleeSaveLayout csl; - - private static Register[] initAllocatable(boolean reserveForHeapBase) { - Register[] registers = null; - if (reserveForHeapBase) { - // @formatter:off - registers = new Register[]{ - // TODO this is not complete - // o7 cannot be used as register because it is always overwritten on call - // and the current register handler would ignore this fact if the called - // method still does not modify registers, in fact o7 is modified by the Call instruction - // There would be some extra handlin necessary to be able to handle the o7 properly for local usage - o0, o1, o2, o3, o4, o5, /*o6, o7,*/ - l0, l1, l2, l3, l4, l5, l6, l7, - i0, i1, i2, i3, i4, i5, /*i6,*/ /*i7,*/ - //f0, f1, f2, f3, f4, f5, f6, f7, - f8, f9, f10, f11, f12, f13, f14, f15, - f16, f17, f18, f19, f20, f21, f22, f23, - f24, f25, f26, f27, f28, f29, f30, f31, - d32, d34, d36, d38, d40, d42, d44, d46, - d48, d50, d52, d54, d56, d58, d60, d62 - }; - // @formatter:on - } else { - // @formatter:off - registers = new Register[]{ - // TODO this is not complete - o0, o1, o2, o3, o4, o5, /*o6, o7,*/ - l0, l1, l2, l3, l4, l5, l6, l7, - i0, i1, i2, i3, i4, i5, /*i6,*/ /*i7,*/ -// f0, f1, f2, f3, f4, f5, f6, f7 - f8, f9, f10, f11, f12, f13, f14, f15, - f16, f17, f18, f19, f20, f21, f22, f23, - f24, f25, f26, f27, f28, f29, f30, f31, - d32, d34, d36, d38, d40, d42, d44, d46, - d48, d50, d52, d54, d56, d58, d60, d62 - }; - // @formatter:on - } - - return registers; - } - - public SPARCHotSpotRegisterConfig(TargetDescription target, HotSpotVMConfig config) { - this(target, initAllocatable(config.useCompressedOops)); - } - - public SPARCHotSpotRegisterConfig(TargetDescription target, Register[] allocatable) { - this.architecture = target.arch; - - csl = new CalleeSaveLayout(target, -1, -1, target.arch.getWordSize(), calleeSaveRegisters); - this.allocatable = allocatable.clone(); - attributesMap = RegisterAttributes.createMap(this, SPARC.allRegisters); - } - - @Override - public Register[] getCallerSaveRegisters() { - return callerSaveRegisters; - } - - @Override - public boolean areAllAllocatableRegistersCallerSaved() { - return false; - } - - @Override - public Register getRegisterForRole(int index) { - throw new UnsupportedOperationException(); - } - - @Override - public CallingConvention getCallingConvention(Type type, JavaType returnType, JavaType[] parameterTypes, TargetDescription target, boolean stackOnly) { - if (type == Type.JavaCall || type == Type.NativeCall) { - return callingConvention(cpuCallerParameterRegisters, returnType, parameterTypes, type, target, stackOnly); - } - if (type == Type.JavaCallee) { - return callingConvention(cpuCalleeParameterRegisters, returnType, parameterTypes, type, target, stackOnly); - } - throw JVMCIError.shouldNotReachHere(); - } - - public Register[] getCallingConventionRegisters(Type type, Kind kind) { - if (architecture.canStoreValue(FPUs, kind) || architecture.canStoreValue(FPUd, kind)) { - return fpuParameterRegisters; - } - assert architecture.canStoreValue(CPU, kind); - return type == Type.JavaCallee ? cpuCalleeParameterRegisters : cpuCallerParameterRegisters; - } - - private CallingConvention callingConvention(Register[] generalParameterRegisters, JavaType returnType, JavaType[] parameterTypes, Type type, TargetDescription target, boolean stackOnly) { - AllocatableValue[] locations = new AllocatableValue[parameterTypes.length]; - - int currentGeneral = 0; - int currentFloating = 0; - int currentStackOffset = 0; - - for (int i = 0; i < parameterTypes.length; i++) { - final Kind kind = parameterTypes[i].getKind(); - - switch (kind) { - case Byte: - case Boolean: - case Short: - case Char: - case Int: - case Long: - case Object: - if (!stackOnly && currentGeneral < generalParameterRegisters.length) { - Register register = generalParameterRegisters[currentGeneral++]; - locations[i] = register.asValue(target.getLIRKind(kind)); - } - break; - case Double: - if (!stackOnly && currentFloating < fpuParameterRegisters.length) { - if (currentFloating % 2 != 0) { - // Make register number even to be a double reg - currentFloating++; - } - Register register = fpuDoubleParameterRegisters[currentFloating]; - currentFloating += 2; // Only every second is a double register - locations[i] = register.asValue(target.getLIRKind(kind)); - } - break; - case Float: - if (!stackOnly && currentFloating < fpuParameterRegisters.length) { - Register register = fpuParameterRegisters[currentFloating++]; - locations[i] = register.asValue(target.getLIRKind(kind)); - } - break; - default: - throw JVMCIError.shouldNotReachHere(); - } - - if (locations[i] == null) { - // Stack slot is always aligned to its size in bytes but minimum wordsize - int typeSize = SPARC.spillSlotSize(target, kind); - currentStackOffset = NumUtil.roundUp(currentStackOffset, typeSize); - locations[i] = StackSlot.get(target.getLIRKind(kind.getStackKind()), currentStackOffset, !type.out); - currentStackOffset += typeSize; - } - } - - Kind returnKind = returnType == null ? Kind.Void : returnType.getKind(); - AllocatableValue returnLocation = returnKind == Kind.Void ? Value.ILLEGAL : getReturnRegister(returnKind, type).asValue(target.getLIRKind(returnKind.getStackKind())); - return new CallingConvention(currentStackOffset, returnLocation, locations); - } - - @Override - public Register getReturnRegister(Kind kind) { - return getReturnRegister(kind, Type.JavaCallee); - } - - private static Register getReturnRegister(Kind kind, Type type) { - switch (kind) { - case Boolean: - case Byte: - case Char: - case Short: - case Int: - case Long: - case Object: - return type == Type.JavaCallee ? i0 : o0; - case Float: - return f0; - case Double: - return d0; - case Void: - case Illegal: - return null; - default: - throw new UnsupportedOperationException("no return register for type " + kind); - } - } - - @Override - public Register getFrameRegister() { - return sp; - } - - public CalleeSaveLayout getCalleeSaveLayout() { - return csl; - } - - @Override - public String toString() { - return String.format("Allocatable: " + Arrays.toString(getAllocatableRegisters()) + "%n" + "CallerSave: " + Arrays.toString(getCallerSaveRegisters()) + "%n"); - } -} diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotReturnOp.java --- a/graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotReturnOp.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotReturnOp.java Thu Jun 04 11:08:12 2015 -0700 @@ -23,13 +23,14 @@ package com.oracle.graal.hotspot.sparc; import com.oracle.jvmci.meta.Value; +import com.oracle.jvmci.sparc.*; + import static com.oracle.graal.lir.LIRInstruction.OperandFlag.*; import com.oracle.graal.asm.sparc.*; import com.oracle.graal.lir.*; import com.oracle.graal.lir.asm.*; import com.oracle.graal.lir.sparc.SPARCControlFlow.ReturnOp; -import com.oracle.graal.sparc.*; import com.oracle.jvmci.hotspot.*; /** diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotSafepointOp.java --- a/graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotSafepointOp.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotSafepointOp.java Thu Jun 04 11:08:12 2015 -0700 @@ -27,10 +27,11 @@ import com.oracle.jvmci.code.RegisterValue; import com.oracle.jvmci.meta.LIRKind; import com.oracle.jvmci.meta.AllocatableValue; -import static com.oracle.graal.sparc.SPARC.*; + +import static com.oracle.jvmci.sparc.SPARC.*; import com.oracle.graal.asm.sparc.*; -import com.oracle.graal.asm.sparc.SPARCMacroAssembler.Setx; +import com.oracle.graal.asm.sparc.SPARCMacroAssembler.*; import com.oracle.graal.lir.*; import com.oracle.graal.lir.asm.*; import com.oracle.graal.lir.gen.*; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotUnwindOp.java --- a/graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotUnwindOp.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotUnwindOp.java Thu Jun 04 11:08:12 2015 -0700 @@ -26,10 +26,11 @@ import com.oracle.jvmci.code.CallingConvention; import com.oracle.jvmci.code.Register; import com.oracle.jvmci.code.RegisterValue; + import static com.oracle.jvmci.code.ValueUtil.*; +import static com.oracle.jvmci.sparc.SPARC.*; import static com.oracle.graal.hotspot.HotSpotBackend.*; import static com.oracle.graal.lir.LIRInstruction.OperandFlag.*; -import static com.oracle.graal.sparc.SPARC.*; import com.oracle.graal.asm.sparc.*; import com.oracle.graal.hotspot.stubs.*; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotspotDirectStaticCallOp.java diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotspotDirectVirtualCallOp.java --- a/graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotspotDirectVirtualCallOp.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotspotDirectVirtualCallOp.java Thu Jun 04 11:08:12 2015 -0700 @@ -25,10 +25,11 @@ import com.oracle.jvmci.code.Register; import com.oracle.jvmci.meta.ResolvedJavaMethod; import com.oracle.jvmci.meta.Value; -import static com.oracle.graal.sparc.SPARC.*; + +import static com.oracle.jvmci.sparc.SPARC.*; import com.oracle.graal.asm.sparc.*; -import com.oracle.graal.asm.sparc.SPARCMacroAssembler.Setx; +import com.oracle.graal.asm.sparc.SPARCMacroAssembler.*; import com.oracle.graal.lir.*; import com.oracle.graal.lir.asm.*; import com.oracle.graal.lir.sparc.SPARCCall.DirectCallOp; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCIndirectCallOp.java --- a/graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCIndirectCallOp.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCIndirectCallOp.java Thu Jun 04 11:08:12 2015 -0700 @@ -25,9 +25,10 @@ import com.oracle.jvmci.code.Register; import com.oracle.jvmci.meta.ResolvedJavaMethod; import com.oracle.jvmci.meta.Value; + import static com.oracle.jvmci.code.ValueUtil.*; +import static com.oracle.jvmci.sparc.SPARC.*; import static com.oracle.graal.lir.LIRInstruction.OperandFlag.*; -import static com.oracle.graal.sparc.SPARC.*; import com.oracle.graal.asm.sparc.*; import com.oracle.graal.lir.*; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCPrefetchOp.java diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCUncommonTrapStub.java --- a/graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCUncommonTrapStub.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCUncommonTrapStub.java Thu Jun 04 11:08:12 2015 -0700 @@ -25,7 +25,9 @@ import com.oracle.jvmci.code.TargetDescription; import com.oracle.jvmci.code.RegisterConfig; import com.oracle.jvmci.code.Register; -import static com.oracle.graal.sparc.SPARC.*; +import com.oracle.jvmci.hotspot.sparc.*; + +import static com.oracle.jvmci.sparc.SPARC.*; import com.oracle.graal.hotspot.*; import com.oracle.graal.hotspot.meta.*; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/jvmci/SPARCHotSpotJVMCIBackendFactory.java --- a/graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/jvmci/SPARCHotSpotJVMCIBackendFactory.java Thu Jun 04 10:46:23 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,102 +0,0 @@ -/* - * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.hotspot.sparc.jvmci; - -import static com.oracle.jvmci.hotspot.InitTimer.*; - -import java.util.*; - -import com.oracle.graal.hotspot.*; -import com.oracle.graal.hotspot.sparc.*; -import com.oracle.graal.sparc.*; -import com.oracle.graal.sparc.SPARC.CPUFeature; -import com.oracle.jvmci.code.*; -import com.oracle.jvmci.hotspot.*; -import com.oracle.jvmci.runtime.*; -import com.oracle.jvmci.service.*; - -@ServiceProvider(HotSpotJVMCIBackendFactory.class) -public class SPARCHotSpotJVMCIBackendFactory implements HotSpotJVMCIBackendFactory { - - protected Architecture createArchitecture(HotSpotVMConfig config) { - return new SPARC(computeFeatures(config)); - } - - protected TargetDescription createTarget(HotSpotVMConfig config) { - final int stackFrameAlignment = 16; - final int implicitNullCheckLimit = 4096; - final boolean inlineObjects = true; - return new HotSpotTargetDescription(createArchitecture(config), true, stackFrameAlignment, implicitNullCheckLimit, inlineObjects); - } - - protected HotSpotCodeCacheProvider createCodeCache(HotSpotJVMCIRuntimeProvider runtime, TargetDescription target, RegisterConfig regConfig) { - return new HotSpotCodeCacheProvider(runtime, runtime.getConfig(), target, regConfig); - } - - protected EnumSet computeFeatures(HotSpotVMConfig config) { - EnumSet features = EnumSet.noneOf(CPUFeature.class); - if ((config.sparcFeatures & config.vis1Instructions) != 0) { - features.add(CPUFeature.VIS1); - } - if ((config.sparcFeatures & config.vis2Instructions) != 0) { - features.add(CPUFeature.VIS2); - } - if ((config.sparcFeatures & config.vis3Instructions) != 0) { - features.add(CPUFeature.VIS3); - } - if ((config.sparcFeatures & config.cbcondInstructions) != 0) { - features.add(CPUFeature.CBCOND); - } - return features; - } - - public String getArchitecture() { - return "SPARC"; - } - - @Override - public String toString() { - return getJVMCIRuntimeName() + ":" + getArchitecture(); - } - - public JVMCIBackend createJVMCIBackend(HotSpotJVMCIRuntimeProvider runtime, JVMCIBackend host) { - assert host == null; - TargetDescription target = createTarget(runtime.getConfig()); - - HotSpotMetaAccessProvider metaAccess = new HotSpotMetaAccessProvider(runtime); - RegisterConfig regConfig = new SPARCHotSpotRegisterConfig(target, runtime.getConfig()); - HotSpotCodeCacheProvider codeCache = createCodeCache(runtime, target, regConfig); - HotSpotConstantReflectionProvider constantReflection = new HotSpotConstantReflectionProvider(runtime); - try (InitTimer rt = timer("instantiate backend")) { - return createBackend(metaAccess, codeCache, constantReflection); - } - } - - protected JVMCIBackend createBackend(HotSpotMetaAccessProvider metaAccess, HotSpotCodeCacheProvider codeCache, HotSpotConstantReflectionProvider constantReflection) { - return new JVMCIBackend(metaAccess, codeCache, constantReflection); - } - - public String getJVMCIRuntimeName() { - return "basic"; - } -} diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompileTheWorld.java diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotBackend.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotBackend.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotBackend.java Thu Jun 04 11:08:12 2015 -0700 @@ -236,11 +236,6 @@ return getProviders().getSuites(); } - @Override - public DisassemblerProvider getDisassembler() { - return getProviders().getDisassembler(); - } - protected void profileInstructions(LIR lir, CompilationResultBuilder crb) { if (HotSpotBackend.Options.ASMInstructionProfiling.getValue() != null) { HotSpotInstructionProfiling.countInstructions(lir, crb.asm); diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotCounterOp.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotCounterOp.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotCounterOp.java Thu Jun 04 11:08:12 2015 -0700 @@ -27,6 +27,7 @@ import com.oracle.jvmci.meta.JavaConstant; import com.oracle.jvmci.meta.Value; import com.oracle.jvmci.meta.Kind; + import static com.oracle.jvmci.code.ValueUtil.*; import java.util.*; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotInstructionProfiling.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotInstructionProfiling.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotInstructionProfiling.java Thu Jun 04 11:08:12 2015 -0700 @@ -25,10 +25,11 @@ import com.oracle.jvmci.code.TargetDescription; import com.oracle.jvmci.meta.JavaConstant; import com.oracle.jvmci.meta.Value; + import java.util.*; import com.oracle.graal.asm.*; -import com.oracle.graal.asm.Assembler.InstructionCounter; +import com.oracle.graal.asm.Assembler.*; import com.oracle.graal.compiler.common.cfg.*; import com.oracle.graal.lir.*; import com.oracle.graal.lir.StandardOp.BlockEndOp; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotTargetDescription.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotTargetDescription.java Thu Jun 04 10:46:23 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.hotspot; - -import com.oracle.jvmci.code.TargetDescription; -import com.oracle.jvmci.code.Architecture; -import com.oracle.jvmci.code.ReferenceMap; -import com.oracle.jvmci.hotspot.*; - -public class HotSpotTargetDescription extends TargetDescription { - - public HotSpotTargetDescription(Architecture arch, boolean isMP, int stackAlignment, int implicitNullCheckLimit, boolean inlineObjects) { - super(arch, isMP, stackAlignment, implicitNullCheckLimit, inlineObjects); - } - - @Override - public ReferenceMap createReferenceMap(boolean hasRegisters, int stackSlotCount) { - return new HotSpotReferenceMap(this); - } -} diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/debug/BenchmarkCounters.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/debug/BenchmarkCounters.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/debug/BenchmarkCounters.java Thu Jun 04 11:08:12 2015 -0700 @@ -37,6 +37,8 @@ import edu.umd.cs.findbugs.annotations.*; +//JaCoCo Exclude + /** * This class contains infrastructure to maintain counters based on {@link DynamicCounterNode}s. The * infrastructure is enabled by specifying either the GenericDynamicCounters or diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/DefaultHotSpotLoweringProvider.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/DefaultHotSpotLoweringProvider.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/DefaultHotSpotLoweringProvider.java Thu Jun 04 11:08:12 2015 -0700 @@ -33,6 +33,7 @@ import com.oracle.jvmci.meta.ResolvedJavaType; import com.oracle.jvmci.meta.ForeignCallDescriptor; import com.oracle.jvmci.meta.Kind; + import static com.oracle.jvmci.meta.LocationIdentity.*; import static com.oracle.graal.compiler.common.GraalOptions.*; import static com.oracle.graal.hotspot.meta.HotSpotForeignCallsProviderImpl.*; @@ -108,7 +109,6 @@ @Override public void lower(Node n, LoweringTool tool) { StructuredGraph graph = (StructuredGraph) n.graph(); - if (n instanceof Invoke) { lowerInvoke((Invoke) n, tool, graph); } else if (n instanceof LoadMethodNode) { @@ -127,10 +127,6 @@ if (graph.getGuardsStage().areDeoptsFixed()) { instanceofSnippets.lower((InstanceOfNode) n, tool); } - } else if (n instanceof TypeCheckNode) { - if (graph.getGuardsStage().areDeoptsFixed()) { - instanceofSnippets.lower((TypeCheckNode) n, tool); - } } else if (n instanceof InstanceOfDynamicNode) { if (graph.getGuardsStage().areDeoptsFixed()) { instanceofSnippets.lower((InstanceOfDynamicNode) n, tool); diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotDisassemblerProvider.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotDisassemblerProvider.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotDisassemblerProvider.java Thu Jun 04 11:08:12 2015 -0700 @@ -22,27 +22,33 @@ */ package com.oracle.graal.hotspot.meta; -import com.oracle.jvmci.code.DisassemblerProvider; -import com.oracle.jvmci.code.InstalledCode; -import com.oracle.graal.hotspot.*; +import static com.oracle.graal.hotspot.HotSpotGraalRuntime.*; + +import com.oracle.graal.code.*; +import com.oracle.jvmci.code.*; import com.oracle.jvmci.hotspot.*; +import com.oracle.jvmci.service.*; /** * HotSpot implementation of {@link DisassemblerProvider}. */ +@ServiceProvider(DisassemblerProvider.class) public class HotSpotDisassemblerProvider implements DisassemblerProvider { - protected final HotSpotGraalRuntimeProvider runtime; - - public HotSpotDisassemblerProvider(HotSpotGraalRuntimeProvider runtime) { - this.runtime = runtime; + public String disassembleCompiledCode(CodeCacheProvider codeCache, CompilationResult compResult) { + return null; } - public String disassemble(InstalledCode code) { + @Override + public String disassembleInstalledCode(CodeCacheProvider codeCache, CompilationResult compResult, InstalledCode code) { if (code.isValid()) { long codeBlob = ((HotSpotInstalledCode) code).getAddress(); - return runtime.getCompilerToVM().disassembleCodeBlob(codeBlob); + return runtime().getCompilerToVM().disassembleCodeBlob(codeBlob); } return null; } + + public String getName() { + return "hsdis"; + } } diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotGraphBuilderPlugins.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotGraphBuilderPlugins.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotGraphBuilderPlugins.java Thu Jun 04 11:08:12 2015 -0700 @@ -78,7 +78,7 @@ NodeIntrinsificationPhase nodeIntrinsificationPhase = new NodeIntrinsificationPhase(metaAccess, constantReflection, snippetReflection, foreignCalls, stampProvider); NodeIntrinsificationPlugin nodeIntrinsificationPlugin = new NodeIntrinsificationPlugin(metaAccess, nodeIntrinsificationPhase, wordTypes, false); HotSpotWordOperationPlugin wordOperationPlugin = new HotSpotWordOperationPlugin(snippetReflection, wordTypes); - HotSpotNodePlugin nodePlugin = new HotSpotNodePlugin(metaAccess, constantReflection, wordOperationPlugin, nodeIntrinsificationPlugin); + HotSpotNodePlugin nodePlugin = new HotSpotNodePlugin(wordOperationPlugin, nodeIntrinsificationPlugin); plugins.appendParameterPlugin(nodePlugin); plugins.appendNodePlugin(nodePlugin); diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotNodePlugin.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotNodePlugin.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotNodePlugin.java Thu Jun 04 11:08:12 2015 -0700 @@ -51,21 +51,23 @@ * Constant folding of field loads. */ public final class HotSpotNodePlugin implements NodePlugin, ParameterPlugin { - private final MetaAccessProvider metaAccess; - private final ConstantReflectionProvider constantReflection; - protected final WordOperationPlugin wordOperationPlugin; protected final NodeIntrinsificationPlugin nodeIntrinsificationPlugin; - public HotSpotNodePlugin(MetaAccessProvider metaAccess, ConstantReflectionProvider constantReflection, WordOperationPlugin wordOperationPlugin, - NodeIntrinsificationPlugin nodeIntrinsificationPlugin) { - this.metaAccess = metaAccess; - this.constantReflection = constantReflection; + public HotSpotNodePlugin(WordOperationPlugin wordOperationPlugin, NodeIntrinsificationPlugin nodeIntrinsificationPlugin) { this.wordOperationPlugin = wordOperationPlugin; this.nodeIntrinsificationPlugin = nodeIntrinsificationPlugin; } @Override + public boolean canChangeStackKind(GraphBuilderContext b) { + if (b.parsingIntrinsic()) { + return wordOperationPlugin.canChangeStackKind(b) || nodeIntrinsificationPlugin.canChangeStackKind(b); + } + return false; + } + + @Override public FloatingNode interceptParameter(GraphBuilderContext b, int index, Stamp stamp) { if (b.parsingIntrinsic()) { return wordOperationPlugin.interceptParameter(b, index, stamp); @@ -113,7 +115,7 @@ return false; } - private boolean tryReadField(GraphBuilderContext b, ResolvedJavaField field, JavaConstant object) { + private static boolean tryReadField(GraphBuilderContext b, ResolvedJavaField field, JavaConstant object) { // FieldReadEnabledInImmutableCode is non null only if assertions are enabled if (FieldReadEnabledInImmutableCode != null && ImmutableCode.getValue()) { FieldReadEnabledInImmutableCode.set(Boolean.TRUE); @@ -127,10 +129,10 @@ } } - private boolean tryConstantFold(GraphBuilderContext b, ResolvedJavaField field, JavaConstant object) { - JavaConstant result = constantReflection.readConstantFieldValue(field, object); + private static boolean tryConstantFold(GraphBuilderContext b, ResolvedJavaField field, JavaConstant object) { + JavaConstant result = b.getConstantReflection().readConstantFieldValue(field, object); if (result != null) { - ConstantNode constantNode = ConstantNode.forConstant(result, metaAccess, b.getGraph()); + ConstantNode constantNode = ConstantNode.forConstant(result, b.getMetaAccess(), b.getGraph()); b.push(field.getKind(), constantNode); return true; } diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotProviders.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotProviders.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotProviders.java Thu Jun 04 11:08:12 2015 -0700 @@ -38,7 +38,6 @@ */ public class HotSpotProviders extends Providers { - private final HotSpotDisassemblerProvider disassembler; private final SuitesProvider suites; private final HotSpotRegistersProvider registers; private final SnippetReflectionProvider snippetReflection; @@ -46,10 +45,9 @@ private final Plugins graphBuilderPlugins; public HotSpotProviders(MetaAccessProvider metaAccess, HotSpotCodeCacheProvider codeCache, ConstantReflectionProvider constantReflection, HotSpotForeignCallsProvider foreignCalls, - LoweringProvider lowerer, Replacements replacements, HotSpotDisassemblerProvider disassembler, SuitesProvider suites, HotSpotRegistersProvider registers, - SnippetReflectionProvider snippetReflection, HotSpotWordTypes wordTypes, Plugins graphBuilderPlugins) { + LoweringProvider lowerer, Replacements replacements, SuitesProvider suites, HotSpotRegistersProvider registers, SnippetReflectionProvider snippetReflection, + HotSpotWordTypes wordTypes, Plugins graphBuilderPlugins) { super(metaAccess, codeCache, constantReflection, foreignCalls, lowerer, replacements, new HotSpotStampProvider()); - this.disassembler = disassembler; this.suites = suites; this.registers = registers; this.snippetReflection = snippetReflection; @@ -62,10 +60,6 @@ return (HotSpotCodeCacheProvider) super.getCodeCache(); } - public HotSpotDisassemblerProvider getDisassembler() { - return disassembler; - } - @Override public HotSpotForeignCallsProvider getForeignCalls() { return (HotSpotForeignCallsProvider) super.getForeignCalls(); diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/DimensionsNode.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/DimensionsNode.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/DimensionsNode.java Thu Jun 04 11:08:12 2015 -0700 @@ -24,6 +24,7 @@ import com.oracle.jvmci.code.VirtualStackSlot; import com.oracle.jvmci.meta.Value; + import static com.oracle.graal.asm.NumUtil.*; import java.util.*; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/CRC32Substitutions.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/CRC32Substitutions.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/CRC32Substitutions.java Thu Jun 04 11:08:12 2015 -0700 @@ -36,6 +36,8 @@ import com.oracle.graal.nodes.extended.*; import com.oracle.graal.word.*; +// JaCoCo Exclude + /** * Substitutions for {@link CRC32}. */ diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/HotSpotClassSubstitutions.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/HotSpotClassSubstitutions.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/HotSpotClassSubstitutions.java Thu Jun 04 11:08:12 2015 -0700 @@ -30,6 +30,8 @@ import com.oracle.graal.nodes.*; import com.oracle.graal.word.*; +// JaCoCo Exclude + /** * Substitutions for {@link java.lang.Class} methods. */ diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/arraycopy/UnsafeArrayCopySnippets.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/arraycopy/UnsafeArrayCopySnippets.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/arraycopy/UnsafeArrayCopySnippets.java Thu Jun 04 11:08:12 2015 -0700 @@ -26,6 +26,7 @@ import com.oracle.jvmci.meta.NamedLocationIdentity; import com.oracle.jvmci.meta.LocationIdentity; import com.oracle.jvmci.meta.Kind; + import static com.oracle.jvmci.meta.LocationIdentity.*; import static com.oracle.graal.hotspot.HotSpotGraalRuntime.*; import static com.oracle.graal.hotspot.replacements.HotSpotReplacementsUtil.*; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/DeoptimizationStub.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/DeoptimizationStub.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/DeoptimizationStub.java Thu Jun 04 11:08:12 2015 -0700 @@ -25,6 +25,7 @@ import com.oracle.jvmci.code.Register; import com.oracle.jvmci.code.TargetDescription; import com.oracle.jvmci.meta.ForeignCallDescriptor; + import static com.oracle.graal.hotspot.HotSpotBackend.*; import static com.oracle.graal.hotspot.HotSpotBackend.Options.*; import static com.oracle.graal.hotspot.nodes.DeoptimizationFetchUnrollInfoCallNode.*; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/UncommonTrapStub.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/UncommonTrapStub.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/UncommonTrapStub.java Thu Jun 04 11:08:12 2015 -0700 @@ -27,6 +27,7 @@ import com.oracle.jvmci.meta.NamedLocationIdentity; import com.oracle.jvmci.meta.LocationIdentity; import com.oracle.jvmci.meta.ForeignCallDescriptor; + import static com.oracle.graal.hotspot.HotSpotBackend.*; import static com.oracle.graal.hotspot.HotSpotBackend.Options.*; import static com.oracle.graal.hotspot.replacements.HotSpotReplacementsUtil.*; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.java.test/src/com/oracle/graal/java/test/ConstantTest.java --- a/graal/com.oracle.graal.java.test/src/com/oracle/graal/java/test/ConstantTest.java Thu Jun 04 10:46:23 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,67 +0,0 @@ -/* - * Copyright (c) 2014, 2014, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.java.test; - -import com.oracle.jvmci.meta.JavaConstant; -import com.oracle.jvmci.meta.Kind; -import org.junit.*; - -public class ConstantTest extends FieldUniverse { - - @Test - public void testNegativeZero() { - Assert.assertTrue("Constant for 0.0f must be different from -0.0f", JavaConstant.FLOAT_0 != JavaConstant.forFloat(-0.0F)); - Assert.assertTrue("Constant for 0.0d must be different from -0.0d", JavaConstant.DOUBLE_0 != JavaConstant.forDouble(-0.0d)); - } - - @Test - public void testNullIsNull() { - Assert.assertTrue(JavaConstant.NULL_POINTER.isNull()); - } - - @Test - public void testOne() { - for (Kind kind : Kind.values()) { - if (kind.isNumericInteger() || kind.isNumericFloat()) { - Assert.assertTrue(JavaConstant.one(kind).getKind() == kind); - } - } - Assert.assertEquals(1, JavaConstant.one(Kind.Int).asInt()); - Assert.assertEquals(1L, JavaConstant.one(Kind.Long).asLong()); - Assert.assertEquals(1, JavaConstant.one(Kind.Byte).asInt()); - Assert.assertEquals(1, JavaConstant.one(Kind.Short).asInt()); - Assert.assertEquals(1, JavaConstant.one(Kind.Char).asInt()); - Assert.assertTrue(1F == JavaConstant.one(Kind.Float).asFloat()); - Assert.assertTrue(1D == JavaConstant.one(Kind.Double).asDouble()); - } - - @Test(expected = IllegalArgumentException.class) - public void testIllegalOne() { - JavaConstant.one(Kind.Illegal); - } - - @Test(expected = IllegalArgumentException.class) - public void testVoidOne() { - JavaConstant.one(Kind.Void); - } -} diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.java.test/src/com/oracle/graal/java/test/FieldUniverse.java --- a/graal/com.oracle.graal.java.test/src/com/oracle/graal/java/test/FieldUniverse.java Thu Jun 04 10:46:23 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.java.test; - -import com.oracle.jvmci.meta.ResolvedJavaField; -import java.lang.reflect.*; -import java.util.*; - -/** - * Context for field related tests. - */ -public class FieldUniverse extends TypeUniverse { - - public final Map fields = new HashMap<>(); - - public FieldUniverse() { - for (Class c : classes) { - for (Field f : c.getDeclaredFields()) { - ResolvedJavaField field = metaAccess.lookupJavaField(f); - fields.put(f, field); - } - } - } -} diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.java.test/src/com/oracle/graal/java/test/MethodUniverse.java --- a/graal/com.oracle.graal.java.test/src/com/oracle/graal/java/test/MethodUniverse.java Thu Jun 04 10:46:23 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.java.test; - -import com.oracle.jvmci.meta.ResolvedJavaMethod; -import java.lang.reflect.*; -import java.util.*; - -/** - * Context for method related tests. - */ -public class MethodUniverse extends TypeUniverse { - - public final Map methods = new HashMap<>(); - public final Map, ResolvedJavaMethod> constructors = new HashMap<>(); - - public MethodUniverse() { - for (Class c : classes) { - for (Method m : c.getDeclaredMethods()) { - ResolvedJavaMethod method = metaAccess.lookupJavaMethod(m); - methods.put(m, method); - } - for (Constructor m : c.getDeclaredConstructors()) { - constructors.put(m, metaAccess.lookupJavaMethod(m)); - } - } - } -} diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.java.test/src/com/oracle/graal/java/test/NameAndSignature.java --- a/graal/com.oracle.graal.java.test/src/com/oracle/graal/java/test/NameAndSignature.java Thu Jun 04 10:46:23 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,91 +0,0 @@ -/* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.java.test; - -import com.oracle.jvmci.meta.ResolvedJavaMethod; -import com.oracle.jvmci.meta.Signature; -import com.oracle.jvmci.meta.ResolvedJavaType; -import com.oracle.jvmci.meta.MetaAccessProvider; -import java.lang.reflect.*; -import java.util.*; - -import com.oracle.graal.api.runtime.*; -import com.oracle.graal.runtime.*; - -class NameAndSignature { - - public static final MetaAccessProvider metaAccess = Graal.getRequiredCapability(RuntimeProvider.class).getHostBackend().getProviders().getMetaAccess(); - - final String name; - final Class returnType; - final Class[] parameterTypes; - - public NameAndSignature(Method m) { - this.name = m.getName(); - this.returnType = m.getReturnType(); - this.parameterTypes = m.getParameterTypes(); - } - - @Override - public boolean equals(Object obj) { - if (obj instanceof NameAndSignature) { - NameAndSignature s = (NameAndSignature) obj; - return s.returnType == returnType && name.equals(s.name) && Arrays.equals(s.parameterTypes, parameterTypes); - } - return false; - } - - @Override - public int hashCode() { - return name.hashCode(); - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(name + "("); - String sep = ""; - for (Class p : parameterTypes) { - sb.append(sep); - sep = ", "; - sb.append(p.getName()); - } - return sb.append(')').append(returnType.getName()).toString(); - } - - public boolean signatureEquals(ResolvedJavaMethod m) { - Signature s = m.getSignature(); - ResolvedJavaType declaringClass = m.getDeclaringClass(); - if (!s.getReturnType(declaringClass).resolve(declaringClass).equals(metaAccess.lookupJavaType(returnType))) { - return false; - } - if (s.getParameterCount(false) != parameterTypes.length) { - return false; - } - for (int i = 0; i < parameterTypes.length; i++) { - if (!s.getParameterType(i, declaringClass).resolve(declaringClass).equals(metaAccess.lookupJavaType(parameterTypes[i]))) { - return false; - } - } - return true; - } -} diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.java.test/src/com/oracle/graal/java/test/ResolvedJavaTypeResolveConcreteMethodTest.java --- a/graal/com.oracle.graal.java.test/src/com/oracle/graal/java/test/ResolvedJavaTypeResolveConcreteMethodTest.java Thu Jun 04 10:46:23 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,175 +0,0 @@ -/* - * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.java.test; - -import com.oracle.jvmci.meta.ResolvedJavaMethod; -import com.oracle.jvmci.meta.ResolvedJavaType; -import com.oracle.jvmci.meta.MetaAccessProvider; -import static org.junit.Assert.*; - -import org.junit.*; - -import com.oracle.graal.api.runtime.*; -import com.oracle.graal.phases.util.*; -import com.oracle.graal.runtime.*; - -public class ResolvedJavaTypeResolveConcreteMethodTest { - public final MetaAccessProvider metaAccess; - - public ResolvedJavaTypeResolveConcreteMethodTest() { - Providers providers = Graal.getRequiredCapability(RuntimeProvider.class).getHostBackend().getProviders(); - metaAccess = providers.getMetaAccess(); - } - - protected abstract static class A { - @SuppressWarnings("unused") - private void priv() { - } - - public void v1() { - } - - public void v2() { - } - - public abstract void abs(); - } - - protected static class B extends A implements I { - public void i() { - } - - @Override - public void v2() { - } - - @Override - public void abs() { - - } - } - - protected static class C extends B { - public void d() { - } - } - - protected abstract static class D extends A { - - } - - protected static class E extends D { - @Override - public void abs() { - } - } - - protected interface I { - void i(); - - default void d() { - } - } - - @Test - public void testDefaultMethod() { - ResolvedJavaType i = getType(I.class); - ResolvedJavaType b = getType(B.class); - ResolvedJavaType c = getType(C.class); - ResolvedJavaMethod di = getMethod(i, "d"); - ResolvedJavaMethod dc = getMethod(c, "d"); - - assertEquals(di, i.resolveConcreteMethod(di, c)); - assertEquals(di, b.resolveConcreteMethod(di, c)); - assertEquals(dc, c.resolveConcreteMethod(di, c)); - } - - @Test - public void testPrivateMethod() { - ResolvedJavaType a = getType(A.class); - ResolvedJavaType b = getType(B.class); - ResolvedJavaType c = getType(C.class); - ResolvedJavaMethod priv = getMethod(a, "priv"); - - assertNull(a.resolveConcreteMethod(priv, c)); - assertNull(b.resolveConcreteMethod(priv, c)); - } - - @Test - public void testAbstractMethod() { - ResolvedJavaType a = getType(A.class); - ResolvedJavaType b = getType(B.class); - ResolvedJavaType c = getType(C.class); - ResolvedJavaType d = getType(D.class); - ResolvedJavaType e = getType(E.class); - ResolvedJavaMethod absa = getMethod(a, "abs"); - ResolvedJavaMethod absb = getMethod(b, "abs"); - ResolvedJavaMethod abse = getMethod(e, "abs"); - - assertNull(a.resolveConcreteMethod(absa, c)); - assertNull(d.resolveConcreteMethod(absa, c)); - - assertEquals(absb, b.resolveConcreteMethod(absa, c)); - assertEquals(absb, b.resolveConcreteMethod(absb, c)); - assertEquals(absb, c.resolveConcreteMethod(absa, c)); - assertEquals(absb, c.resolveConcreteMethod(absb, c)); - assertEquals(abse, e.resolveConcreteMethod(absa, c)); - assertNull(e.resolveConcreteMethod(absb, c)); - assertEquals(abse, e.resolveConcreteMethod(abse, c)); - } - - @Test - public void testVirtualMethod() { - ResolvedJavaType a = getType(A.class); - ResolvedJavaType b = getType(B.class); - ResolvedJavaType c = getType(C.class); - ResolvedJavaMethod v1a = getMethod(a, "v1"); - ResolvedJavaMethod v2a = getMethod(a, "v2"); - ResolvedJavaMethod v2b = getMethod(b, "v2"); - - assertEquals(v1a, a.resolveConcreteMethod(v1a, c)); - assertEquals(v1a, b.resolveConcreteMethod(v1a, c)); - assertEquals(v1a, c.resolveConcreteMethod(v1a, c)); - assertEquals(v2a, a.resolveConcreteMethod(v2a, c)); - assertEquals(v2b, b.resolveConcreteMethod(v2a, c)); - assertEquals(v2b, b.resolveConcreteMethod(v2b, c)); - assertEquals(v2b, c.resolveConcreteMethod(v2a, c)); - assertEquals(v2b, c.resolveConcreteMethod(v2b, c)); - - } - - static ResolvedJavaMethod getMethod(ResolvedJavaType type, String methodName) { - for (ResolvedJavaMethod method : type.getDeclaredMethods()) { - if (method.getName().equals(methodName)) { - return method; - } - } - throw new IllegalArgumentException(); - } - - protected ResolvedJavaType getType(Class clazz) { - ResolvedJavaType type = metaAccess.lookupJavaType(clazz); - type.initialize(); - return type; - } -} diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.java.test/src/com/oracle/graal/java/test/ResolvedJavaTypeResolveMethodTest.java --- a/graal/com.oracle.graal.java.test/src/com/oracle/graal/java/test/ResolvedJavaTypeResolveMethodTest.java Thu Jun 04 10:46:23 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,175 +0,0 @@ -/* - * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.java.test; - -import com.oracle.jvmci.meta.ResolvedJavaMethod; -import com.oracle.jvmci.meta.ResolvedJavaType; -import com.oracle.jvmci.meta.MetaAccessProvider; -import static org.junit.Assert.*; - -import org.junit.*; - -import com.oracle.graal.api.runtime.*; -import com.oracle.graal.phases.util.*; -import com.oracle.graal.runtime.*; - -public class ResolvedJavaTypeResolveMethodTest { - public final MetaAccessProvider metaAccess; - - public ResolvedJavaTypeResolveMethodTest() { - Providers providers = Graal.getRequiredCapability(RuntimeProvider.class).getHostBackend().getProviders(); - metaAccess = providers.getMetaAccess(); - } - - protected abstract static class A { - @SuppressWarnings("unused") - private void priv() { - } - - public void v1() { - } - - public void v2() { - } - - public abstract void abs(); - } - - protected static class B extends A implements I { - public void i() { - } - - @Override - public void v2() { - } - - @Override - public void abs() { - - } - } - - protected static class C extends B { - public void d() { - } - } - - protected abstract static class D extends A { - - } - - protected static class E extends D { - @Override - public void abs() { - } - } - - protected interface I { - void i(); - - default void d() { - } - } - - @Test - public void testDefaultMethod() { - ResolvedJavaType i = getType(I.class); - ResolvedJavaType b = getType(B.class); - ResolvedJavaType c = getType(C.class); - ResolvedJavaMethod di = getMethod(i, "d"); - ResolvedJavaMethod dc = getMethod(c, "d"); - - assertEquals(di, i.resolveMethod(di, c, true)); - assertEquals(di, b.resolveMethod(di, c, true)); - assertEquals(dc, c.resolveMethod(di, c, true)); - } - - @Test - public void testPrivateMethod() { - ResolvedJavaType a = getType(A.class); - ResolvedJavaType b = getType(B.class); - ResolvedJavaType c = getType(C.class); - ResolvedJavaMethod priv = getMethod(a, "priv"); - - assertNull(a.resolveMethod(priv, c, true)); - assertNull(b.resolveMethod(priv, c, true)); - } - - @Test - public void testAbstractMethod() { - ResolvedJavaType a = getType(A.class); - ResolvedJavaType b = getType(B.class); - ResolvedJavaType c = getType(C.class); - ResolvedJavaType d = getType(D.class); - ResolvedJavaType e = getType(E.class); - ResolvedJavaMethod absa = getMethod(a, "abs"); - ResolvedJavaMethod absb = getMethod(b, "abs"); - ResolvedJavaMethod abse = getMethod(e, "abs"); - - assertEquals(absa, a.resolveMethod(absa, c, true)); - assertEquals(absa, d.resolveMethod(absa, c, true)); - - assertEquals(absb, b.resolveMethod(absa, c, true)); - assertEquals(absb, b.resolveMethod(absb, c, true)); - assertEquals(absb, c.resolveMethod(absa, c, true)); - assertEquals(absb, c.resolveMethod(absb, c, true)); - assertEquals(abse, e.resolveMethod(absa, c, true)); - assertNull(e.resolveMethod(absb, c, true)); - assertEquals(abse, e.resolveMethod(abse, c, true)); - } - - @Test - public void testVirtualMethod() { - ResolvedJavaType a = getType(A.class); - ResolvedJavaType b = getType(B.class); - ResolvedJavaType c = getType(C.class); - ResolvedJavaMethod v1a = getMethod(a, "v1"); - ResolvedJavaMethod v2a = getMethod(a, "v2"); - ResolvedJavaMethod v2b = getMethod(b, "v2"); - - assertEquals(v1a, a.resolveMethod(v1a, c, true)); - assertEquals(v1a, b.resolveMethod(v1a, c, true)); - assertEquals(v1a, c.resolveMethod(v1a, c, true)); - assertEquals(v2a, a.resolveMethod(v2a, c, true)); - assertEquals(v2b, b.resolveMethod(v2a, c, true)); - assertEquals(v2b, b.resolveMethod(v2b, c, true)); - assertEquals(v2b, c.resolveMethod(v2a, c, true)); - assertEquals(v2b, c.resolveMethod(v2b, c, true)); - - } - - static ResolvedJavaMethod getMethod(ResolvedJavaType type, String methodName) { - for (ResolvedJavaMethod method : type.getDeclaredMethods()) { - if (method.getName().equals(methodName)) { - return method; - } - } - throw new IllegalArgumentException(); - } - - protected ResolvedJavaType getType(Class clazz) { - ResolvedJavaType type = metaAccess.lookupJavaType(clazz); - type.initialize(); - return type; - } -} diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.java.test/src/com/oracle/graal/java/test/TestBytecodeDisassemblerProvider.java --- a/graal/com.oracle.graal.java.test/src/com/oracle/graal/java/test/TestBytecodeDisassemblerProvider.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.java.test/src/com/oracle/graal/java/test/TestBytecodeDisassemblerProvider.java Thu Jun 04 11:08:12 2015 -0700 @@ -24,6 +24,8 @@ import com.oracle.jvmci.meta.ResolvedJavaMethod; import com.oracle.jvmci.meta.BytecodeDisassemblerProvider; +import com.oracle.jvmci.runtime.test.*; + import org.junit.*; import com.oracle.graal.java.*; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.java.test/src/com/oracle/graal/java/test/TestConstantReflectionProvider.java --- a/graal/com.oracle.graal.java.test/src/com/oracle/graal/java/test/TestConstantReflectionProvider.java Thu Jun 04 10:46:23 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,103 +0,0 @@ -/* - * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.java.test; - -import static org.junit.Assert.*; - -import java.lang.reflect.*; - -import org.junit.*; - -import com.oracle.jvmci.meta.*; - -/** - * Tests for {@link ConstantReflectionProvider}. It assumes an implementation of the interface that - * actually returns non-null results for access operations that are possible, i.e., the tests will - * fail for an implementation that spuriously returns null (which is allowed by the specification). - */ -public class TestConstantReflectionProvider extends TypeUniverse { - - @Test - public void constantEqualsTest() { - for (JavaConstant c1 : constants) { - for (JavaConstant c2 : constants) { - // test symmetry - assertEquals(constantReflection.constantEquals(c1, c2), constantReflection.constantEquals(c2, c1)); - if (c1.getKind() != Kind.Object && c2.getKind() != Kind.Object) { - assertEquals(c1.equals(c2), constantReflection.constantEquals(c2, c1)); - } - } - } - } - - @Test - public void readArrayLengthTest() { - for (JavaConstant c : constants) { - Integer actual = constantReflection.readArrayLength(c); - if (c.getKind() != Kind.Object || c.isNull() || !snippetReflection.asObject(Object.class, c).getClass().isArray()) { - assertNull(actual); - } else { - assertNotNull(actual); - int actualInt = actual; - assertEquals(Array.getLength(snippetReflection.asObject(Object.class, c)), actualInt); - } - } - } - - @Test - public void boxTest() { - for (JavaConstant c : constants) { - JavaConstant boxed = constantReflection.boxPrimitive(c); - if (c.getKind().isPrimitive()) { - assertTrue(boxed.getKind().isObject()); - assertFalse(boxed.isNull()); - } - } - - assertEquals(Long.valueOf(42), snippetReflection.asObject(Long.class, constantReflection.boxPrimitive(JavaConstant.forLong(42)))); - assertEquals(Integer.valueOf(66), snippetReflection.asObject(Integer.class, constantReflection.boxPrimitive(JavaConstant.forInt(66)))); - assertEquals(Byte.valueOf((byte) 123), snippetReflection.asObject(Byte.class, constantReflection.boxPrimitive(JavaConstant.forByte((byte) 123)))); - assertSame(Boolean.TRUE, snippetReflection.asObject(Boolean.class, constantReflection.boxPrimitive(JavaConstant.forBoolean(true)))); - - assertNull(constantReflection.boxPrimitive(JavaConstant.NULL_POINTER)); - assertNull(constantReflection.boxPrimitive(snippetReflection.forObject("abc"))); - } - - @Test - public void unboxTest() { - for (JavaConstant c : constants) { - JavaConstant unboxed = c.isNull() ? null : constantReflection.unboxPrimitive(c); - if (unboxed != null) { - assertFalse(unboxed.getKind().isObject()); - } - } - - assertEquals(JavaConstant.forLong(42), constantReflection.unboxPrimitive(snippetReflection.forObject(Long.valueOf(42)))); - assertEquals(JavaConstant.forInt(66), constantReflection.unboxPrimitive(snippetReflection.forObject(Integer.valueOf(66)))); - assertEquals(JavaConstant.forByte((byte) 123), constantReflection.unboxPrimitive(snippetReflection.forObject(Byte.valueOf((byte) 123)))); - assertSame(JavaConstant.forBoolean(true), constantReflection.unboxPrimitive(snippetReflection.forObject(Boolean.TRUE))); - - assertNull(constantReflection.unboxPrimitive(JavaConstant.NULL_POINTER)); - assertNull(constantReflection.unboxPrimitive(snippetReflection.forObject("abc"))); - } -} diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.java.test/src/com/oracle/graal/java/test/TestJavaField.java --- a/graal/com.oracle.graal.java.test/src/com/oracle/graal/java/test/TestJavaField.java Thu Jun 04 10:46:23 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,76 +0,0 @@ -/* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.java.test; - -import static org.junit.Assert.*; - -import java.lang.reflect.*; -import java.util.*; - -import org.junit.*; - -import com.oracle.jvmci.meta.*; - -/** - * Tests for {@link JavaField}. - */ -public class TestJavaField extends FieldUniverse { - - @Test - public void getNameTest() { - for (Map.Entry e : fields.entrySet()) { - String expected = e.getKey().getName(); - String actual = e.getValue().getName(); - assertEquals(expected, actual); - } - } - - @Test - public void getTypeTest() { - for (Map.Entry e : fields.entrySet()) { - // Must resolve types first as a resolved types != unresolved types - ResolvedJavaField rf = e.getValue(); - JavaType expected = metaAccess.lookupJavaType(e.getKey().getType()).resolve(rf.getDeclaringClass()); - JavaType actual = rf.getType().resolve(rf.getDeclaringClass()); - assertEquals(expected, actual); - } - } - - @Test - public void getKindTest() { - for (Map.Entry e : fields.entrySet()) { - Kind expected = metaAccess.lookupJavaType(e.getKey().getType()).getKind(); - Kind actual = e.getValue().getKind(); - assertEquals(expected, actual); - } - } - - @Test - public void getDeclaringClassTest() { - for (Map.Entry e : fields.entrySet()) { - Class expected = e.getKey().getDeclaringClass(); - ResolvedJavaType actual = e.getValue().getDeclaringClass(); - assertTrue(actual.equals(metaAccess.lookupJavaType(expected))); - } - } -} diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.java.test/src/com/oracle/graal/java/test/TestJavaMethod.java --- a/graal/com.oracle.graal.java.test/src/com/oracle/graal/java/test/TestJavaMethod.java Thu Jun 04 10:46:23 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,63 +0,0 @@ -/* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.java.test; - -import static org.junit.Assert.*; - -import java.lang.reflect.*; -import java.util.*; - -import org.junit.*; - -import com.oracle.jvmci.meta.*; - -/** - * Tests for {@link JavaMethod}. - */ -public class TestJavaMethod extends MethodUniverse { - - @Test - public void getNameTest() { - for (Map.Entry e : methods.entrySet()) { - String expected = e.getKey().getName(); - String actual = e.getValue().getName(); - assertEquals(expected, actual); - } - } - - @Test - public void getDeclaringClassTest() { - for (Map.Entry e : methods.entrySet()) { - Class expected = e.getKey().getDeclaringClass(); - ResolvedJavaType actual = e.getValue().getDeclaringClass(); - assertTrue(actual.equals(metaAccess.lookupJavaType(expected))); - } - } - - @Test - public void getSignatureTest() { - for (Map.Entry e : methods.entrySet()) { - assertTrue(new NameAndSignature(e.getKey()).signatureEquals(e.getValue())); - } - } -} diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.java.test/src/com/oracle/graal/java/test/TestJavaType.java --- a/graal/com.oracle.graal.java.test/src/com/oracle/graal/java/test/TestJavaType.java Thu Jun 04 10:46:23 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.java.test; - -import com.oracle.jvmci.meta.JavaType; -import com.oracle.jvmci.meta.Kind; -import static org.junit.Assert.*; - -import org.junit.*; - -/** - * Tests for {@link JavaType}. - */ -public class TestJavaType extends TypeUniverse { - - public TestJavaType() { - } - - @Test - public void getKindTest() { - for (Class c : classes) { - JavaType type = metaAccess.lookupJavaType(c); - Kind expected = Kind.fromJavaClass(c); - Kind actual = type.getKind(); - assertEquals(expected, actual); - } - } -} diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.java.test/src/com/oracle/graal/java/test/TestMetaAccessProvider.java --- a/graal/com.oracle.graal.java.test/src/com/oracle/graal/java/test/TestMetaAccessProvider.java Thu Jun 04 10:46:23 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,93 +0,0 @@ -/* - * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.java.test; - -import static com.oracle.jvmci.meta.MetaUtil.*; -import static org.junit.Assert.*; - -import java.lang.reflect.*; - -import org.junit.*; - -import com.oracle.jvmci.meta.*; - -/** - * Tests for {@link MetaAccessProvider}. - */ -public class TestMetaAccessProvider extends TypeUniverse { - - @Test - public void lookupJavaTypeTest() { - for (Class c : classes) { - ResolvedJavaType type = metaAccess.lookupJavaType(c); - assertNotNull(type); - assertEquals(c.getModifiers(), type.getModifiers()); - if (!type.isArray()) { - assertEquals(type.getName(), toInternalName(c.getName())); - assertEquals(type.toJavaName(), c.getName()); - } - } - } - - @Test - public void lookupJavaMethodTest() { - for (Class c : classes) { - for (Method reflect : c.getDeclaredMethods()) { - ResolvedJavaMethod method = metaAccess.lookupJavaMethod(reflect); - assertNotNull(method); - int expected = reflect.getModifiers() & Modifier.methodModifiers(); - int actual = method.getModifiers(); - assertEquals(String.format("%s: 0x%x != 0x%x", reflect, expected, actual), expected, actual); - assertTrue(method.getDeclaringClass().equals(metaAccess.lookupJavaType(reflect.getDeclaringClass()))); - } - } - } - - @Test - public void lookupJavaFieldTest() { - for (Class c : classes) { - for (Field reflect : c.getDeclaredFields()) { - ResolvedJavaField field = metaAccess.lookupJavaField(reflect); - assertNotNull(field); - int expected = reflect.getModifiers(); - int actual = field.getModifiers(); - assertEquals(String.format("%s: 0x%x != 0x%x", reflect, expected, actual), expected, actual); - assertTrue(field.getDeclaringClass().equals(metaAccess.lookupJavaType(reflect.getDeclaringClass()))); - } - } - } - - @Test - public void lookupJavaTypeConstantTest() { - for (JavaConstant c : constants) { - if (c.getKind() == Kind.Object && !c.isNull()) { - Object o = snippetReflection.asObject(Object.class, c); - ResolvedJavaType type = metaAccess.lookupJavaType(c); - assertNotNull(type); - assertTrue(type.equals(metaAccess.lookupJavaType(o.getClass()))); - } else { - assertEquals(metaAccess.lookupJavaType(c), null); - } - } - } -} diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.java.test/src/com/oracle/graal/java/test/TestResolvedJavaField.java --- a/graal/com.oracle.graal.java.test/src/com/oracle/graal/java/test/TestResolvedJavaField.java Thu Jun 04 10:46:23 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,137 +0,0 @@ -/* - * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.java.test; - -import static org.junit.Assert.*; - -import java.lang.annotation.*; -import java.lang.reflect.*; -import java.util.*; - -import org.junit.*; - -import com.oracle.jvmci.meta.*; - -/** - * Tests for {@link ResolvedJavaField}. - */ -public class TestResolvedJavaField extends FieldUniverse { - - public TestResolvedJavaField() { - } - - @Test - public void getModifiersTest() { - for (Map.Entry e : fields.entrySet()) { - int expected = e.getKey().getModifiers(); - int actual = e.getValue().getModifiers(); - assertEquals(expected, actual); - } - } - - @Test - public void isSyntheticTest() { - for (Map.Entry e : fields.entrySet()) { - boolean expected = e.getKey().isSynthetic(); - boolean actual = e.getValue().isSynthetic(); - assertEquals(expected, actual); - } - } - - @Test - public void getAnnotationTest() { - for (Map.Entry e : fields.entrySet()) { - for (Annotation expected : e.getKey().getAnnotations()) { - if (expected != null) { - Annotation actual = e.getValue().getAnnotation(expected.annotationType()); - assertEquals(expected, actual); - } - } - } - } - - @Test - public void getLocationIdentityTest() { - for (Map.Entry e : fields.entrySet()) { - LocationIdentity identity = e.getValue().getLocationIdentity(); - assertTrue(identity != null); - } - } - - @Test - public void readConstantValueTest() throws NoSuchFieldException { - ResolvedJavaField field = metaAccess.lookupJavaField(getClass().getDeclaredField("stringField")); - for (Object receiver : new Object[]{this, null, new String()}) { - JavaConstant value = constantReflection.readConstantFieldValue(field, snippetReflection.forObject(receiver)); - assertNull(value); - } - - ResolvedJavaField constField = metaAccess.lookupJavaField(getClass().getDeclaredField("constantStringField")); - for (Object receiver : new Object[]{this, null, new String()}) { - JavaConstant value = constantReflection.readConstantFieldValue(constField, snippetReflection.forObject(receiver)); - if (value != null) { - Object expected = "constantField"; - assertTrue(snippetReflection.asObject(Object.class, value) == expected); - } - } - } - - String stringField = "field"; - final String constantStringField = "constantField"; - - private Method findTestMethod(Method apiMethod) { - String testName = apiMethod.getName() + "Test"; - for (Method m : getClass().getDeclaredMethods()) { - if (m.getName().equals(testName) && m.getAnnotation(Test.class) != null) { - return m; - } - } - return null; - } - - // @formatter:off - private static final String[] untestedApiMethods = { - "getDeclaringClass", - "isInternal" - }; - // @formatter:on - - /** - * Ensures that any new methods added to {@link ResolvedJavaMethod} either have a test written - * for them or are added to {@link #untestedApiMethods}. - */ - @Test - public void testCoverage() { - Set known = new HashSet<>(Arrays.asList(untestedApiMethods)); - for (Method m : ResolvedJavaField.class.getDeclaredMethods()) { - if (m.isSynthetic()) { - continue; - } - if (findTestMethod(m) == null) { - assertTrue("test missing for " + m, known.contains(m.getName())); - } else { - assertFalse("test should be removed from untestedApiMethods" + m, known.contains(m.getName())); - } - } - } -} diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.java.test/src/com/oracle/graal/java/test/TestResolvedJavaMethod.java --- a/graal/com.oracle.graal.java.test/src/com/oracle/graal/java/test/TestResolvedJavaMethod.java Thu Jun 04 10:46:23 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,381 +0,0 @@ -/* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.java.test; - -import com.oracle.jvmci.meta.ExceptionHandler; -import com.oracle.jvmci.meta.ResolvedJavaMethod; -import com.oracle.jvmci.meta.ConstantPool; -import static org.junit.Assert.*; - -import java.lang.annotation.*; -import java.lang.reflect.*; -import java.util.*; - -import org.junit.*; - -/** - * Tests for {@link ResolvedJavaMethod}. - */ -public class TestResolvedJavaMethod extends MethodUniverse { - - public TestResolvedJavaMethod() { - } - - /** - * @see ResolvedJavaMethod#getCode() - */ - @Test - public void getCodeTest() { - for (Map.Entry e : methods.entrySet()) { - ResolvedJavaMethod m = e.getValue(); - byte[] code = m.getCode(); - if (code == null) { - assertTrue(m.getCodeSize() == 0); - } else { - if (m.isAbstract()) { - assertTrue(code.length == 0); - } else if (!m.isNative()) { - assertTrue(code.length > 0); - } - } - } - } - - /** - * @see ResolvedJavaMethod#getCodeSize() - */ - @Test - public void getCodeSizeTest() { - for (Map.Entry e : methods.entrySet()) { - ResolvedJavaMethod m = e.getValue(); - int codeSize = m.getCodeSize(); - if (m.isAbstract()) { - assertTrue(codeSize == 0); - } else if (!m.isNative()) { - assertTrue(codeSize > 0); - } - } - } - - @Test - public void getModifiersTest() { - for (Map.Entry e : methods.entrySet()) { - ResolvedJavaMethod m = e.getValue(); - int expected = e.getKey().getModifiers() & Modifier.methodModifiers(); - int actual = m.getModifiers(); - assertEquals(expected, actual); - } - } - - /** - * @see ResolvedJavaMethod#isClassInitializer() - */ - @Test - public void isClassInitializerTest() { - for (Map.Entry e : methods.entrySet()) { - // Class initializers are hidden from reflection - ResolvedJavaMethod m = e.getValue(); - assertFalse(m.isClassInitializer()); - } - for (Map.Entry, ResolvedJavaMethod> e : constructors.entrySet()) { - ResolvedJavaMethod m = e.getValue(); - assertFalse(m.isClassInitializer()); - } - } - - @Test - public void isConstructorTest() { - for (Map.Entry e : methods.entrySet()) { - ResolvedJavaMethod m = e.getValue(); - assertFalse(m.isConstructor()); - } - for (Map.Entry, ResolvedJavaMethod> e : constructors.entrySet()) { - ResolvedJavaMethod m = e.getValue(); - assertTrue(m.isConstructor()); - } - } - - @Test - public void isSyntheticTest() { - for (Map.Entry e : methods.entrySet()) { - ResolvedJavaMethod m = e.getValue(); - assertEquals(e.getKey().isSynthetic(), m.isSynthetic()); - } - for (Map.Entry, ResolvedJavaMethod> e : constructors.entrySet()) { - ResolvedJavaMethod m = e.getValue(); - assertEquals(e.getKey().isSynthetic(), m.isSynthetic()); - } - } - - @Test - public void isSynchronizedTest() { - for (Map.Entry e : methods.entrySet()) { - ResolvedJavaMethod m = e.getValue(); - assertEquals(Modifier.isSynchronized(e.getKey().getModifiers()), m.isSynchronized()); - } - for (Map.Entry, ResolvedJavaMethod> e : constructors.entrySet()) { - ResolvedJavaMethod m = e.getValue(); - assertEquals(Modifier.isSynchronized(e.getKey().getModifiers()), m.isSynchronized()); - } - } - - @Test - public void canBeStaticallyBoundTest() { - for (Map.Entry e : methods.entrySet()) { - ResolvedJavaMethod m = e.getValue(); - assertEquals(m.canBeStaticallyBound(), canBeStaticallyBound(e.getKey())); - } - for (Map.Entry, ResolvedJavaMethod> e : constructors.entrySet()) { - ResolvedJavaMethod m = e.getValue(); - assertEquals(m.canBeStaticallyBound(), canBeStaticallyBound(e.getKey())); - } - } - - private static boolean canBeStaticallyBound(Member method) { - int modifiers = method.getModifiers(); - return (Modifier.isFinal(modifiers) || Modifier.isPrivate(modifiers) || Modifier.isStatic(modifiers) || Modifier.isFinal(method.getDeclaringClass().getModifiers())) && - !Modifier.isAbstract(modifiers); - } - - private static String methodWithExceptionHandlers(String p1, Object o2) { - try { - return p1.substring(100) + o2.toString(); - } catch (IndexOutOfBoundsException e) { - e.printStackTrace(); - } catch (NullPointerException e) { - e.printStackTrace(); - } catch (RuntimeException e) { - e.printStackTrace(); - } - return null; - } - - @Test - public void getExceptionHandlersTest() throws NoSuchMethodException { - ResolvedJavaMethod method = metaAccess.lookupJavaMethod(getClass().getDeclaredMethod("methodWithExceptionHandlers", String.class, Object.class)); - ExceptionHandler[] handlers = method.getExceptionHandlers(); - assertNotNull(handlers); - assertEquals(handlers.length, 3); - handlers[0].getCatchType().equals(metaAccess.lookupJavaType(IndexOutOfBoundsException.class)); - handlers[1].getCatchType().equals(metaAccess.lookupJavaType(NullPointerException.class)); - handlers[2].getCatchType().equals(metaAccess.lookupJavaType(RuntimeException.class)); - } - - private static String nullPointerExceptionOnFirstLine(Object o, String ignored) { - return o.toString() + ignored; - } - - @Test - public void asStackTraceElementTest() throws NoSuchMethodException { - try { - nullPointerExceptionOnFirstLine(null, "ignored"); - Assert.fail("should not reach here"); - } catch (NullPointerException e) { - StackTraceElement expected = e.getStackTrace()[0]; - ResolvedJavaMethod method = metaAccess.lookupJavaMethod(getClass().getDeclaredMethod("nullPointerExceptionOnFirstLine", Object.class, String.class)); - StackTraceElement actual = method.asStackTraceElement(0); - assertEquals(expected, actual); - } - } - - @Test - public void getConstantPoolTest() { - for (Map.Entry e : methods.entrySet()) { - ResolvedJavaMethod m = e.getValue(); - ConstantPool cp = m.getConstantPool(); - assertTrue(cp.length() > 0); - } - } - - @Test(timeout = 1000L) - public void getAnnotationTest() throws NoSuchMethodException { - ResolvedJavaMethod method = metaAccess.lookupJavaMethod(getClass().getDeclaredMethod("getAnnotationTest")); - Test annotation = method.getAnnotation(Test.class); - assertNotNull(annotation); - assertEquals(1000L, annotation.timeout()); - } - - @Test(timeout = 1000L) - public void getAnnotationsTest() throws NoSuchMethodException { - ResolvedJavaMethod method = metaAccess.lookupJavaMethod(getClass().getDeclaredMethod("getAnnotationsTest")); - Annotation[] annotations = method.getAnnotations(); - assertNotNull(annotations); - assertEquals(1, annotations.length); - assertEquals(1000L, ((Test) annotations[0]).timeout()); - } - - @Retention(RetentionPolicy.RUNTIME) - @Target(ElementType.PARAMETER) - @interface NonNull { - } - - @Retention(RetentionPolicy.RUNTIME) - @Target(ElementType.PARAMETER) - @interface Special { - } - - private static native void methodWithAnnotatedParameters(@NonNull HashMap p1, @Special @NonNull Class p2); - - @Test - public void getParameterAnnotationsTest() throws NoSuchMethodException { - ResolvedJavaMethod method = metaAccess.lookupJavaMethod(getClass().getDeclaredMethod("methodWithAnnotatedParameters", HashMap.class, Class.class)); - Annotation[][] annotations = method.getParameterAnnotations(); - assertEquals(2, annotations.length); - assertEquals(1, annotations[0].length); - assertEquals(NonNull.class, annotations[0][0].annotationType()); - assertEquals(2, annotations[1].length); - assertEquals(Special.class, annotations[1][0].annotationType()); - assertEquals(NonNull.class, annotations[1][1].annotationType()); - } - - @Test - public void getGenericParameterTypesTest() throws NoSuchMethodException { - ResolvedJavaMethod method = metaAccess.lookupJavaMethod(getClass().getDeclaredMethod("methodWithAnnotatedParameters", HashMap.class, Class.class)); - Type[] genericParameterTypes = method.getGenericParameterTypes(); - assertEquals(2, genericParameterTypes.length); - assertEquals("java.util.HashMap", genericParameterTypes[0].toString()); - assertEquals("java.lang.Class", genericParameterTypes[1].toString()); - } - - @Test - public void getMaxLocalsTest() throws NoSuchMethodException { - ResolvedJavaMethod method1 = metaAccess.lookupJavaMethod(getClass().getDeclaredMethod("methodWithAnnotatedParameters", HashMap.class, Class.class)); - ResolvedJavaMethod method2 = metaAccess.lookupJavaMethod(getClass().getDeclaredMethod("nullPointerExceptionOnFirstLine", Object.class, String.class)); - assertEquals(0, method1.getMaxLocals()); - assertEquals(2, method2.getMaxLocals()); - - } - - @Test - public void getMaxStackSizeTest() throws NoSuchMethodException { - ResolvedJavaMethod method1 = metaAccess.lookupJavaMethod(getClass().getDeclaredMethod("methodWithAnnotatedParameters", HashMap.class, Class.class)); - ResolvedJavaMethod method2 = metaAccess.lookupJavaMethod(getClass().getDeclaredMethod("nullPointerExceptionOnFirstLine", Object.class, String.class)); - assertEquals(0, method1.getMaxStackSize()); - // some versions of javac produce bytecode with a stacksize of 2 for this method - // JSR 292 also sometimes need one more stack slot - int method2StackSize = method2.getMaxStackSize(); - assertTrue(2 <= method2StackSize && method2StackSize <= 4); - } - - @Test - public void isDefaultTest() { - for (Map.Entry e : methods.entrySet()) { - ResolvedJavaMethod m = e.getValue(); - assertEquals(e.getKey().isDefault(), m.isDefault()); - } - for (Map.Entry, ResolvedJavaMethod> e : constructors.entrySet()) { - ResolvedJavaMethod m = e.getValue(); - assertFalse(m.isDefault()); - } - } - - @Test - public void hasReceiverTest() { - for (Map.Entry e : methods.entrySet()) { - ResolvedJavaMethod m = e.getValue(); - assertTrue(m.hasReceiver() != Modifier.isStatic(e.getKey().getModifiers())); - } - for (Map.Entry, ResolvedJavaMethod> e : constructors.entrySet()) { - ResolvedJavaMethod m = e.getValue(); - assertTrue(m.hasReceiver()); - } - } - - @Test - public void hasBytecodesTest() { - for (Map.Entry e : methods.entrySet()) { - ResolvedJavaMethod m = e.getValue(); - assertTrue(m.hasBytecodes() == (m.isConcrete() && !m.isNative())); - } - for (Map.Entry, ResolvedJavaMethod> e : constructors.entrySet()) { - ResolvedJavaMethod m = e.getValue(); - assertTrue(m.hasBytecodes()); - } - } - - @Test - public void isJavaLangObjectInitTest() throws NoSuchMethodException { - ResolvedJavaMethod method = metaAccess.lookupJavaMethod(Object.class.getConstructor()); - assertTrue(method.isJavaLangObjectInit()); - for (Map.Entry e : methods.entrySet()) { - ResolvedJavaMethod m = e.getValue(); - assertFalse(m.isJavaLangObjectInit()); - } - for (Map.Entry, ResolvedJavaMethod> e : constructors.entrySet()) { - ResolvedJavaMethod m = e.getValue(); - Constructor key = e.getKey(); - if (key.getDeclaringClass() == Object.class && key.getParameters().length == 0) { - assertTrue(m.isJavaLangObjectInit()); - } else { - assertFalse(m.isJavaLangObjectInit()); - } - } - } - - private Method findTestMethod(Method apiMethod) { - String testName = apiMethod.getName() + "Test"; - for (Method m : getClass().getDeclaredMethods()) { - if (m.getName().equals(testName) && m.getAnnotation(Test.class) != null) { - return m; - } - } - return null; - } - - // @formatter:off - private static final String[] untestedApiMethods = { - "invoke", - "newInstance", - "getDeclaringClass", - "getEncoding", - "getProfilingInfo", - "reprofile", - "getCompilerStorage", - "canBeInlined", - "shouldBeInlined", - "getLineNumberTable", - "getLocalVariableTable", - "isInVirtualMethodTable", - "toParameterTypes", - "getParameterAnnotation", - "getSpeculationLog", - "$jacocoInit" - }; - // @formatter:on - - /** - * Ensures that any new methods added to {@link ResolvedJavaMethod} either have a test written - * for them or are added to {@link #untestedApiMethods}. - */ - @Test - public void testCoverage() { - Set known = new HashSet<>(Arrays.asList(untestedApiMethods)); - for (Method m : ResolvedJavaMethod.class.getDeclaredMethods()) { - if (findTestMethod(m) == null) { - assertTrue("test missing for " + m, known.contains(m.getName())); - } else { - assertFalse("test should be removed from untestedApiMethods" + m, known.contains(m.getName())); - } - } - } -} diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.java.test/src/com/oracle/graal/java/test/TestResolvedJavaType.java --- a/graal/com.oracle.graal.java.test/src/com/oracle/graal/java/test/TestResolvedJavaType.java Thu Jun 04 10:46:23 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,879 +0,0 @@ -/* - * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.java.test; - -import com.oracle.jvmci.meta.JavaConstant; -import com.oracle.jvmci.meta.Kind; -import com.oracle.jvmci.meta.ResolvedJavaMethod; -import com.oracle.jvmci.meta.ResolvedJavaField; -import com.oracle.jvmci.meta.TrustedInterface; -import com.oracle.jvmci.meta.ResolvedJavaType; -import static java.lang.reflect.Modifier.*; -import static org.junit.Assert.*; - -import java.lang.annotation.*; -import java.lang.reflect.*; -import java.net.*; -import java.util.*; - -import org.junit.*; - -import sun.reflect.ConstantPool; - -import com.oracle.jvmci.meta.Assumptions.AssumptionResult; -import com.oracle.jvmci.common.*; - -/** - * Tests for {@link ResolvedJavaType}. - */ -public class TestResolvedJavaType extends TypeUniverse { - - public TestResolvedJavaType() { - } - - @Test - public void findInstanceFieldWithOffsetTest() { - for (Class c : classes) { - ResolvedJavaType type = metaAccess.lookupJavaType(c); - Set reflectionFields = getInstanceFields(c, true); - for (Field f : reflectionFields) { - ResolvedJavaField rf = lookupField(type.getInstanceFields(true), f); - assertNotNull(rf); - long offset = isStatic(f.getModifiers()) ? unsafe.staticFieldOffset(f) : unsafe.objectFieldOffset(f); - ResolvedJavaField result = type.findInstanceFieldWithOffset(offset, rf.getKind()); - assertNotNull(result); - assertTrue(fieldsEqual(f, result)); - } - } - } - - @Test - public void isInterfaceTest() { - for (Class c : classes) { - ResolvedJavaType type = metaAccess.lookupJavaType(c); - boolean expected = c.isInterface(); - boolean actual = type.isInterface(); - assertEquals(expected, actual); - } - } - - @Test - public void isInstanceClassTest() { - for (Class c : classes) { - ResolvedJavaType type = metaAccess.lookupJavaType(c); - boolean expected = !c.isArray() && !c.isPrimitive() && !c.isInterface(); - boolean actual = type.isInstanceClass(); - assertEquals(expected, actual); - } - } - - @Test - public void isArrayTest() { - for (Class c : classes) { - ResolvedJavaType type = metaAccess.lookupJavaType(c); - boolean expected = c.isArray(); - boolean actual = type.isArray(); - assertEquals(expected, actual); - } - } - - @Test - public void getModifiersTest() { - for (Class c : classes) { - ResolvedJavaType type = metaAccess.lookupJavaType(c); - int expected = c.getModifiers(); - int actual = type.getModifiers(); - assertEquals(expected, actual); - } - } - - @Test - public void isAssignableFromTest() { - Class[] all = classes.toArray(new Class[classes.size()]); - for (int i = 0; i < all.length; i++) { - Class c1 = all[i]; - for (int j = i; j < all.length; j++) { - Class c2 = all[j]; - ResolvedJavaType t1 = metaAccess.lookupJavaType(c1); - ResolvedJavaType t2 = metaAccess.lookupJavaType(c2); - boolean expected = c1.isAssignableFrom(c2); - boolean actual = t1.isAssignableFrom(t2); - assertEquals(expected, actual); - if (expected && t1 != t2) { - assertFalse(t2.isAssignableFrom(t1)); - } - } - } - } - - @Test - public void isInstanceTest() { - for (JavaConstant c : constants) { - if (c.getKind() == Kind.Object && !c.isNull()) { - Object o = snippetReflection.asObject(Object.class, c); - Class cls = o.getClass(); - while (cls != null) { - ResolvedJavaType type = metaAccess.lookupJavaType(cls); - boolean expected = cls.isInstance(o); - boolean actual = type.isInstance(c); - assertEquals(expected, actual); - cls = cls.getSuperclass(); - } - } - } - } - - private static Class asExactClass(Class c) { - if (c.isArray()) { - if (asExactClass(c.getComponentType()) != null) { - return c; - } - } else { - if (c.isPrimitive() || Modifier.isFinal(c.getModifiers())) { - return c; - } - } - return null; - } - - @Test - public void asExactTypeTest() { - for (Class c : classes) { - ResolvedJavaType type = metaAccess.lookupJavaType(c); - ResolvedJavaType exactType = type.asExactType(); - Class expected = asExactClass(c); - if (expected == null) { - assertTrue("exact(" + c.getName() + ") != null", exactType == null); - } else { - assertNotNull(exactType); - assertTrue(exactType.equals(metaAccess.lookupJavaType(expected))); - } - } - } - - @Test - public void getSuperclassTest() { - for (Class c : classes) { - ResolvedJavaType type = metaAccess.lookupJavaType(c); - Class expected = c.getSuperclass(); - ResolvedJavaType actual = type.getSuperclass(); - if (expected == null) { - assertTrue(actual == null); - } else { - assertNotNull(actual); - assertTrue(actual.equals(metaAccess.lookupJavaType(expected))); - } - } - } - - @Test - public void getInterfacesTest() { - for (Class c : classes) { - ResolvedJavaType type = metaAccess.lookupJavaType(c); - Class[] expected = c.getInterfaces(); - ResolvedJavaType[] actual = type.getInterfaces(); - assertEquals(expected.length, actual.length); - for (int i = 0; i < expected.length; i++) { - assertTrue(actual[i].equals(metaAccess.lookupJavaType(expected[i]))); - } - } - } - - public Class getSupertype(Class c) { - assert !c.isPrimitive(); - if (c.isArray()) { - Class componentType = c.getComponentType(); - if (componentType.isPrimitive() || componentType == Object.class) { - return Object.class; - } - return getArrayClass(getSupertype(componentType)); - } - if (c.isInterface()) { - return Object.class; - } - return c.getSuperclass(); - } - - public Class findLeastCommonAncestor(Class c1Initial, Class c2Initial) { - if (c1Initial.isPrimitive() || c2Initial.isPrimitive()) { - return null; - } else { - Class c1 = c1Initial; - Class c2 = c2Initial; - while (true) { - if (c1.isAssignableFrom(c2)) { - return c1; - } - if (c2.isAssignableFrom(c1)) { - return c2; - } - c1 = getSupertype(c1); - c2 = getSupertype(c2); - } - } - } - - @Test - public void findLeastCommonAncestorTest() { - Class[] all = classes.toArray(new Class[classes.size()]); - for (int i = 0; i < all.length; i++) { - Class c1 = all[i]; - for (int j = i; j < all.length; j++) { - Class c2 = all[j]; - ResolvedJavaType t1 = metaAccess.lookupJavaType(c1); - ResolvedJavaType t2 = metaAccess.lookupJavaType(c2); - Class expected = findLeastCommonAncestor(c1, c2); - ResolvedJavaType actual = t1.findLeastCommonAncestor(t2); - if (expected == null) { - assertTrue(actual == null); - } else { - assertNotNull(actual); - assertTrue(actual.equals(metaAccess.lookupJavaType(expected))); - } - } - } - } - - private static class Base { - } - - abstract static class Abstract1 extends Base { - } - - interface Interface1 { - } - - static class Concrete1 extends Abstract1 { - } - - static class Concrete2 extends Abstract1 implements Interface1 { - } - - static class Concrete3 extends Concrete2 { - } - - static final class Final1 extends Abstract1 { - } - - abstract static class Abstract4 extends Concrete3 { - } - - void checkConcreteSubtype(ResolvedJavaType type, ResolvedJavaType expected) { - AssumptionResult leafConcreteSubtype = type.findLeafConcreteSubtype(); - if (leafConcreteSubtype == null) { - // findLeafConcreteSubtype() is conservative - } else { - if (expected == null) { - assertNull(leafConcreteSubtype); - } else { - assertTrue(leafConcreteSubtype.getResult().equals(expected)); - } - } - - if (!type.isArray()) { - ResolvedJavaType arrayType = type.getArrayClass(); - AssumptionResult arraySubtype = arrayType.findLeafConcreteSubtype(); - if (arraySubtype != null) { - assertEquals(arraySubtype.getResult(), arrayType); - } else { - // findLeafConcreteSubtype() method is conservative - } - } - } - - @Test - public void findLeafConcreteSubtypeTest() { - ResolvedJavaType base = metaAccess.lookupJavaType(Base.class); - checkConcreteSubtype(base, base); - - ResolvedJavaType a1 = metaAccess.lookupJavaType(Abstract1.class); - ResolvedJavaType c1 = metaAccess.lookupJavaType(Concrete1.class); - - checkConcreteSubtype(base, null); - checkConcreteSubtype(a1, c1); - checkConcreteSubtype(c1, c1); - - ResolvedJavaType i1 = metaAccess.lookupJavaType(Interface1.class); - ResolvedJavaType c2 = metaAccess.lookupJavaType(Concrete2.class); - - checkConcreteSubtype(base, null); - checkConcreteSubtype(a1, null); - checkConcreteSubtype(c1, c1); - checkConcreteSubtype(i1, c2); - checkConcreteSubtype(c2, c2); - - ResolvedJavaType c3 = metaAccess.lookupJavaType(Concrete3.class); - checkConcreteSubtype(c2, null); - checkConcreteSubtype(c3, c3); - - ResolvedJavaType a4 = metaAccess.lookupJavaType(Abstract4.class); - checkConcreteSubtype(c3, null); - checkConcreteSubtype(a4, null); - - ResolvedJavaType a1a = metaAccess.lookupJavaType(Abstract1[].class); - checkConcreteSubtype(a1a, null); - ResolvedJavaType c1a = metaAccess.lookupJavaType(Concrete1[].class); - checkConcreteSubtype(c1a, null); - ResolvedJavaType f1a = metaAccess.lookupJavaType(Final1[].class); - checkConcreteSubtype(f1a, f1a); - - ResolvedJavaType obja = metaAccess.lookupJavaType(Object[].class); - checkConcreteSubtype(obja, null); - - ResolvedJavaType inta = metaAccess.lookupJavaType(int[].class); - checkConcreteSubtype(inta, inta); - } - - interface NoImplementor { - } - - interface SingleImplementorInterface { - } - - static class SingleConcreteImplementor implements SingleImplementorInterface { - } - - interface SingleAbstractImplementorInterface { - } - - abstract static class SingleAbstractImplementor implements SingleAbstractImplementorInterface { - } - - interface MultiImplementorInterface { - } - - static class ConcreteImplementor1 implements MultiImplementorInterface { - } - - static class ConcreteImplementor2 implements MultiImplementorInterface { - } - - interface MultipleAbstractImplementorInterface { - } - - abstract static class MultiAbstractImplementor1 implements MultipleAbstractImplementorInterface { - } - - abstract static class MultiAbstractImplementor2 implements MultipleAbstractImplementorInterface { - } - - interface SingleAbstractImplementorInterface2 { - } - - interface ExtendedSingleImplementorInterface { - } - - abstract static class SingleAbstractImplementor2 implements SingleAbstractImplementorInterface2 { - } - - static class ConcreteTransitiveImplementor1 extends SingleAbstractImplementor2 implements ExtendedSingleImplementorInterface { - } - - static class ConcreteTransitiveImplementor2 extends SingleAbstractImplementor2 implements ExtendedSingleImplementorInterface { - } - - @Test - public void getSingleImplementorTest() { - ResolvedJavaType iNi = metaAccess.lookupJavaType(NoImplementor.class); - assertNull(iNi.getSingleImplementor()); - - ResolvedJavaType iSi = metaAccess.lookupJavaType(SingleImplementorInterface.class); - ResolvedJavaType cSi = metaAccess.lookupJavaType(SingleConcreteImplementor.class); - assertEquals(cSi, iSi.getSingleImplementor()); - - ResolvedJavaType iSai = metaAccess.lookupJavaType(SingleAbstractImplementorInterface.class); - ResolvedJavaType aSai = metaAccess.lookupJavaType(SingleAbstractImplementor.class); - assertEquals(aSai, iSai.getSingleImplementor()); - - ResolvedJavaType iMi = metaAccess.lookupJavaType(MultiImplementorInterface.class); - metaAccess.lookupJavaType(ConcreteImplementor1.class); - metaAccess.lookupJavaType(ConcreteImplementor2.class); - assertEquals(iMi, iMi.getSingleImplementor()); - - ResolvedJavaType iMai = metaAccess.lookupJavaType(MultipleAbstractImplementorInterface.class); - metaAccess.lookupJavaType(MultiAbstractImplementor1.class); - metaAccess.lookupJavaType(MultiAbstractImplementor2.class); - assertEquals(iMai, iMai.getSingleImplementor()); - - ResolvedJavaType iSai2 = metaAccess.lookupJavaType(SingleAbstractImplementorInterface2.class); - ResolvedJavaType aSai2 = metaAccess.lookupJavaType(SingleAbstractImplementor2.class); - metaAccess.lookupJavaType(ConcreteTransitiveImplementor1.class); - metaAccess.lookupJavaType(ConcreteTransitiveImplementor2.class); - assertEquals(aSai2, iSai2.getSingleImplementor()); - } - - @Test(expected = JVMCIError.class) - public void getSingleImplementorTestClassReceiver() { - ResolvedJavaType base = metaAccess.lookupJavaType(Base.class); - base.getSingleImplementor(); - } - - @Test(expected = JVMCIError.class) - public void getSingleImplementorTestPrimitiveReceiver() { - ResolvedJavaType primitive = metaAccess.lookupJavaType(int.class); - primitive.getSingleImplementor(); - } - - @Test - public void getComponentTypeTest() { - for (Class c : classes) { - ResolvedJavaType type = metaAccess.lookupJavaType(c); - Class expected = c.getComponentType(); - ResolvedJavaType actual = type.getComponentType(); - if (expected == null) { - assertNull(actual); - } else { - assertTrue(actual.equals(metaAccess.lookupJavaType(expected))); - } - } - } - - @Test - public void getArrayClassTest() { - for (Class c : classes) { - if (c != void.class) { - ResolvedJavaType type = metaAccess.lookupJavaType(c); - Class expected = getArrayClass(c); - ResolvedJavaType actual = type.getArrayClass(); - assertTrue(actual.equals(metaAccess.lookupJavaType(expected))); - } - } - } - - static class Declarations { - - final Method implementation; - final Set declarations; - - public Declarations(Method impl) { - this.implementation = impl; - declarations = new HashSet<>(); - } - } - - /** - * See Method - * overriding. - */ - static boolean isOverriderOf(Method impl, Method m) { - if (!isPrivate(m.getModifiers()) && !isFinal(m.getModifiers())) { - if (m.getName().equals(impl.getName())) { - if (m.getReturnType() == impl.getReturnType()) { - if (Arrays.equals(m.getParameterTypes(), impl.getParameterTypes())) { - if (isPublic(m.getModifiers()) || isProtected(m.getModifiers())) { - // m is public or protected - return isPublic(impl.getModifiers()) || isProtected(impl.getModifiers()); - } else { - // m is package-private - return impl.getDeclaringClass().getPackage() == m.getDeclaringClass().getPackage(); - } - } - } - } - } - return false; - } - - static final Map, VTable> vtables = new HashMap<>(); - - static class VTable { - - final Map methods = new HashMap<>(); - } - - static synchronized VTable getVTable(Class c) { - VTable vtable = vtables.get(c); - if (vtable == null) { - vtable = new VTable(); - if (c != Object.class) { - VTable superVtable = getVTable(c.getSuperclass()); - vtable.methods.putAll(superVtable.methods); - } - for (Method m : c.getDeclaredMethods()) { - if (!isStatic(m.getModifiers()) && !isPrivate(m.getModifiers())) { - if (isAbstract(m.getModifiers())) { - // A subclass makes a concrete method in a superclass abstract - vtable.methods.remove(new NameAndSignature(m)); - } else { - vtable.methods.put(new NameAndSignature(m), m); - } - } - } - vtables.put(c, vtable); - } - return vtable; - } - - static Set findDeclarations(Method impl, Class c) { - Set declarations = new HashSet<>(); - NameAndSignature implSig = new NameAndSignature(impl); - if (c != null) { - for (Method m : c.getDeclaredMethods()) { - if (new NameAndSignature(m).equals(implSig)) { - declarations.add(m); - break; - } - } - if (!c.isInterface()) { - declarations.addAll(findDeclarations(impl, c.getSuperclass())); - } - for (Class i : c.getInterfaces()) { - declarations.addAll(findDeclarations(impl, i)); - } - } - return declarations; - } - - private static void checkResolveMethod(ResolvedJavaType type, ResolvedJavaType context, ResolvedJavaMethod decl, ResolvedJavaMethod expected) { - ResolvedJavaMethod impl = type.resolveConcreteMethod(decl, context); - assertEquals(expected, impl); - } - - @Test - public void resolveMethodTest() { - ResolvedJavaType context = metaAccess.lookupJavaType(TestResolvedJavaType.class); - for (Class c : classes) { - if (c.isInterface() || c.isPrimitive()) { - ResolvedJavaType type = metaAccess.lookupJavaType(c); - for (Method m : c.getDeclaredMethods()) { - if (JAVA_VERSION <= 1.7D || (!isStatic(m.getModifiers()) && !isPrivate(m.getModifiers()))) { - ResolvedJavaMethod resolved = metaAccess.lookupJavaMethod(m); - ResolvedJavaMethod impl = type.resolveMethod(resolved, context, true); - ResolvedJavaMethod expected = resolved.isDefault() || resolved.isAbstract() ? resolved : null; - assertEquals(m.toString(), expected, impl); - } else { - // As of JDK 8, interfaces can have static and private methods - } - } - } else { - ResolvedJavaType type = metaAccess.lookupJavaType(c); - VTable vtable = getVTable(c); - for (Method impl : vtable.methods.values()) { - Set decls = findDeclarations(impl, c); - for (Method decl : decls) { - ResolvedJavaMethod m = metaAccess.lookupJavaMethod(decl); - if (m.isPublic()) { - ResolvedJavaMethod i = metaAccess.lookupJavaMethod(impl); - checkResolveMethod(type, context, m, i); - } - } - } - } - } - } - - @Test - public void resolveConcreteMethodTest() { - ResolvedJavaType context = metaAccess.lookupJavaType(TestResolvedJavaType.class); - for (Class c : classes) { - if (c.isInterface() || c.isPrimitive()) { - ResolvedJavaType type = metaAccess.lookupJavaType(c); - for (Method m : c.getDeclaredMethods()) { - if (JAVA_VERSION <= 1.7D || (!isStatic(m.getModifiers()) && !isPrivate(m.getModifiers()))) { - ResolvedJavaMethod resolved = metaAccess.lookupJavaMethod(m); - ResolvedJavaMethod impl = type.resolveConcreteMethod(resolved, context); - ResolvedJavaMethod expected = resolved.isDefault() ? resolved : null; - assertEquals(m.toString(), expected, impl); - } else { - // As of JDK 8, interfaces can have static and private methods - } - } - } else { - ResolvedJavaType type = metaAccess.lookupJavaType(c); - VTable vtable = getVTable(c); - for (Method impl : vtable.methods.values()) { - Set decls = findDeclarations(impl, c); - for (Method decl : decls) { - ResolvedJavaMethod m = metaAccess.lookupJavaMethod(decl); - if (m.isPublic()) { - ResolvedJavaMethod i = metaAccess.lookupJavaMethod(impl); - checkResolveMethod(type, context, m, i); - } - } - } - for (Method m : c.getDeclaredMethods()) { - ResolvedJavaMethod impl = type.resolveConcreteMethod(metaAccess.lookupJavaMethod(m), context); - ResolvedJavaMethod expected = isAbstract(m.getModifiers()) ? null : impl; - assertEquals(type + " " + m.toString(), expected, impl); - } - } - } - } - - @Test - public void findUniqueConcreteMethodTest() throws NoSuchMethodException { - ResolvedJavaMethod thisMethod = metaAccess.lookupJavaMethod(getClass().getDeclaredMethod("findUniqueConcreteMethodTest")); - ResolvedJavaMethod ucm = metaAccess.lookupJavaType(getClass()).findUniqueConcreteMethod(thisMethod).getResult(); - assertEquals(thisMethod, ucm); - } - - public static Set getInstanceFields(Class c, boolean includeSuperclasses) { - if (c.isArray() || c.isPrimitive() || c.isInterface()) { - return Collections.emptySet(); - } - Set result = new HashSet<>(); - for (Field f : c.getDeclaredFields()) { - if (!Modifier.isStatic(f.getModifiers())) { - result.add(f); - } - } - if (includeSuperclasses && c != Object.class) { - result.addAll(getInstanceFields(c.getSuperclass(), true)); - } - return result; - } - - public static Set getStaticFields(Class c) { - Set result = new HashSet<>(); - for (Field f : c.getDeclaredFields()) { - if (Modifier.isStatic(f.getModifiers())) { - result.add(f); - } - } - return result; - } - - public boolean fieldsEqual(Field f, ResolvedJavaField rjf) { - return rjf.getDeclaringClass().equals(metaAccess.lookupJavaType(f.getDeclaringClass())) && rjf.getName().equals(f.getName()) && - rjf.getType().resolve(rjf.getDeclaringClass()).equals(metaAccess.lookupJavaType(f.getType())); - } - - public ResolvedJavaField lookupField(ResolvedJavaField[] fields, Field key) { - for (ResolvedJavaField rf : fields) { - if (fieldsEqual(key, rf)) { - return rf; - } - } - return null; - } - - public Field lookupField(Set fields, ResolvedJavaField key) { - for (Field f : fields) { - if (fieldsEqual(f, key)) { - return f; - } - } - return null; - } - - private boolean isHiddenFromReflection(ResolvedJavaField f) { - if (f.getDeclaringClass().equals(metaAccess.lookupJavaType(Throwable.class)) && f.getName().equals("backtrace")) { - return true; - } - if (f.getDeclaringClass().equals(metaAccess.lookupJavaType(ConstantPool.class)) && f.getName().equals("constantPoolOop")) { - return true; - } - if (f.getDeclaringClass().equals(metaAccess.lookupJavaType(Class.class)) && f.getName().equals("classLoader")) { - return true; - } - return false; - } - - @Test - public void getInstanceFieldsTest() { - for (Class c : classes) { - ResolvedJavaType type = metaAccess.lookupJavaType(c); - for (boolean includeSuperclasses : new boolean[]{true, false}) { - Set expected = getInstanceFields(c, includeSuperclasses); - ResolvedJavaField[] actual = type.getInstanceFields(includeSuperclasses); - for (Field f : expected) { - assertNotNull(lookupField(actual, f)); - } - for (ResolvedJavaField rf : actual) { - if (!isHiddenFromReflection(rf)) { - assertEquals(rf.toString(), lookupField(expected, rf) != null, !rf.isInternal()); - } - } - - // Test stability of getInstanceFields - ResolvedJavaField[] actual2 = type.getInstanceFields(includeSuperclasses); - assertArrayEquals(actual, actual2); - } - } - } - - @Test - public void getStaticFieldsTest() { - for (Class c : classes) { - ResolvedJavaType type = metaAccess.lookupJavaType(c); - Set expected = getStaticFields(c); - ResolvedJavaField[] actual = type.getStaticFields(); - for (Field f : expected) { - assertNotNull(lookupField(actual, f)); - } - for (ResolvedJavaField rf : actual) { - if (!isHiddenFromReflection(rf)) { - assertEquals(lookupField(expected, rf) != null, !rf.isInternal()); - } - } - - // Test stability of getStaticFields - ResolvedJavaField[] actual2 = type.getStaticFields(); - assertArrayEquals(actual, actual2); - } - } - - @Test - public void getDeclaredMethodsTest() { - for (Class c : classes) { - ResolvedJavaType type = metaAccess.lookupJavaType(c); - Method[] raw = c.getDeclaredMethods(); - Set expected = new HashSet<>(); - for (Method m : raw) { - ResolvedJavaMethod resolvedMethod = metaAccess.lookupJavaMethod(m); - assertNotNull(resolvedMethod); - expected.add(resolvedMethod); - } - Set actual = new HashSet<>(Arrays.asList(type.getDeclaredMethods())); - assertEquals(expected, actual); - } - } - - static class A { - static String name = "foo"; - } - - static class B extends A { - } - - static class C { - } - - static class D { - void foo() { - // use of assertions causes the class to have a - assert getClass() != null; - } - } - - @Test - public void getClassInitializerTest() { - assertNotNull(metaAccess.lookupJavaType(A.class).getClassInitializer()); - assertNotNull(metaAccess.lookupJavaType(D.class).getClassInitializer()); - assertNull(metaAccess.lookupJavaType(B.class).getClassInitializer()); - assertNull(metaAccess.lookupJavaType(C.class).getClassInitializer()); - assertNull(metaAccess.lookupJavaType(int.class).getClassInitializer()); - assertNull(metaAccess.lookupJavaType(void.class).getClassInitializer()); - } - - @Test - public void getAnnotationTest() { - for (Class c : classes) { - ResolvedJavaType type = metaAccess.lookupJavaType(c); - for (Annotation a : c.getAnnotations()) { - assertEquals(a, type.getAnnotation(a.annotationType())); - } - } - } - - @Test - public void memberClassesTest() { - for (Class c : classes) { - ResolvedJavaType type = metaAccess.lookupJavaType(c); - assertEquals(c.isLocalClass(), type.isLocal()); - assertEquals(c.isMemberClass(), type.isMember()); - Class enclc = c.getEnclosingClass(); - ResolvedJavaType enclt = type.getEnclosingType(); - assertFalse(enclc == null ^ enclt == null); - if (enclc != null) { - assertEquals(enclt, metaAccess.lookupJavaType(enclc)); - } - } - } - - @Test - public void classFilePathTest() { - for (Class c : classes) { - ResolvedJavaType type = metaAccess.lookupJavaType(c); - URL path = type.getClassFilePath(); - if (type.isPrimitive() || type.isArray()) { - assertEquals(null, path); - } else { - assertNotNull(path); - String pathString = path.getPath(); - if (type.isLocal() || type.isMember()) { - assertTrue(pathString.indexOf('$') > 0); - } - } - } - } - - @Test - public void isTrustedInterfaceTypeTest() { - for (Class c : classes) { - ResolvedJavaType type = metaAccess.lookupJavaType(c); - if (TrustedInterface.class.isAssignableFrom(c)) { - assertTrue(type.isTrustedInterfaceType()); - } - } - } - - private Method findTestMethod(Method apiMethod) { - String testName = apiMethod.getName() + "Test"; - for (Method m : getClass().getDeclaredMethods()) { - if (m.getName().equals(testName) && m.getAnnotation(Test.class) != null) { - return m; - } - } - return null; - } - - // @formatter:off - private static final String[] untestedApiMethods = { - "initialize", - "isPrimitive", - "newArray", - "getDeclaredConstructors", - "isInitialized", - "isLinked", - "getJavaClass", - "getObjectHub", - "hasFinalizableSubclass", - "hasFinalizer", - "getSourceFileName", - "getClassFilePath", - "isLocal", - "isJavaLangObject", - "isMember", - "getElementalType", - "getEnclosingType", - "$jacocoInit" - }; - // @formatter:on - - /** - * Ensures that any new methods added to {@link ResolvedJavaMethod} either have a test written - * for them or are added to {@link #untestedApiMethods}. - */ - @Test - public void testCoverage() { - Set known = new HashSet<>(Arrays.asList(untestedApiMethods)); - for (Method m : ResolvedJavaType.class.getDeclaredMethods()) { - if (findTestMethod(m) == null) { - assertTrue("test missing for " + m, known.contains(m.getName())); - } else { - assertFalse("test should be removed from untestedApiMethods" + m, known.contains(m.getName())); - } - } - } -} diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.java.test/src/com/oracle/graal/java/test/TypeUniverse.java --- a/graal/com.oracle.graal.java.test/src/com/oracle/graal/java/test/TypeUniverse.java Thu Jun 04 10:46:23 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,150 +0,0 @@ -/* - * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.java.test; - -import java.io.*; -import java.lang.reflect.*; -import java.util.*; -import java.util.Queue; - -import org.junit.*; - -import sun.misc.*; - -import com.oracle.graal.api.replacements.*; -import com.oracle.graal.api.runtime.*; -import com.oracle.graal.phases.util.*; -import com.oracle.graal.runtime.*; -import com.oracle.jvmci.meta.*; - -/** - * Context for type related tests. - */ -public class TypeUniverse { - - public final Unsafe unsafe; - public static final double JAVA_VERSION = Double.valueOf(System.getProperty("java.specification.version")); - - public final MetaAccessProvider metaAccess; - public final ConstantReflectionProvider constantReflection; - public final SnippetReflectionProvider snippetReflection; - public final Collection> classes = new HashSet<>(); - public final Map, Class> arrayClasses = new HashMap<>(); - public final List constants = new ArrayList<>(); - - public TypeUniverse() { - Providers providers = Graal.getRequiredCapability(RuntimeProvider.class).getHostBackend().getProviders(); - metaAccess = providers.getMetaAccess(); - constantReflection = providers.getConstantReflection(); - snippetReflection = Graal.getRequiredCapability(SnippetReflectionProvider.class); - Unsafe theUnsafe = null; - try { - theUnsafe = Unsafe.getUnsafe(); - } catch (Exception e) { - try { - Field theUnsafeField = Unsafe.class.getDeclaredField("theUnsafe"); - theUnsafeField.setAccessible(true); - theUnsafe = (Unsafe) theUnsafeField.get(null); - } catch (Exception e1) { - throw (InternalError) new InternalError("unable to initialize unsafe").initCause(e1); - } - } - unsafe = theUnsafe; - - Class[] initialClasses = {void.class, boolean.class, byte.class, short.class, char.class, int.class, float.class, long.class, double.class, Object.class, Class.class, ClassLoader.class, - String.class, Serializable.class, Cloneable.class, Test.class, TestMetaAccessProvider.class, List.class, Collection.class, Map.class, Queue.class, HashMap.class, - LinkedHashMap.class, IdentityHashMap.class, AbstractCollection.class, AbstractList.class, ArrayList.class, TrustedInterface.class}; - for (Class c : initialClasses) { - addClass(c); - } - for (Field f : JavaConstant.class.getDeclaredFields()) { - int mods = f.getModifiers(); - if (f.getType() == JavaConstant.class && Modifier.isPublic(mods) && Modifier.isStatic(mods) && Modifier.isFinal(mods)) { - try { - JavaConstant c = (JavaConstant) f.get(null); - if (c != null) { - constants.add(c); - } - } catch (Exception e) { - } - } - } - for (Class c : classes) { - if (c != void.class && !c.isArray()) { - constants.add(snippetReflection.forObject(Array.newInstance(c, 42))); - } - } - constants.add(snippetReflection.forObject(new ArrayList<>())); - constants.add(snippetReflection.forObject(new IdentityHashMap<>())); - constants.add(snippetReflection.forObject(new LinkedHashMap<>())); - constants.add(snippetReflection.forObject(new TreeMap<>())); - constants.add(snippetReflection.forObject(new ArrayDeque<>())); - constants.add(snippetReflection.forObject(new LinkedList<>())); - constants.add(snippetReflection.forObject("a string")); - constants.add(snippetReflection.forObject(42)); - constants.add(snippetReflection.forObject(String.class)); - constants.add(snippetReflection.forObject(String[].class)); - } - - public synchronized Class getArrayClass(Class componentType) { - Class arrayClass = arrayClasses.get(componentType); - if (arrayClass == null) { - arrayClass = Array.newInstance(componentType, 0).getClass(); - arrayClasses.put(componentType, arrayClass); - } - return arrayClass; - } - - public static int dimensions(Class c) { - if (c.getComponentType() != null) { - return 1 + dimensions(c.getComponentType()); - } - return 0; - } - - private void addClass(Class c) { - if (classes.add(c)) { - if (c.getSuperclass() != null) { - addClass(c.getSuperclass()); - } - for (Class sc : c.getInterfaces()) { - addClass(sc); - } - for (Class dc : c.getDeclaredClasses()) { - addClass(dc); - } - for (Method m : c.getDeclaredMethods()) { - addClass(m.getReturnType()); - for (Class p : m.getParameterTypes()) { - addClass(p); - } - } - - if (c != void.class && dimensions(c) < 2) { - Class arrayClass = Array.newInstance(c, 0).getClass(); - arrayClasses.put(c, arrayClass); - addClass(arrayClass); - } - } - } -} diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.java/src/com/oracle/graal/java/BciBlockMapping.java --- a/graal/com.oracle.graal.java/src/com/oracle/graal/java/BciBlockMapping.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.java/src/com/oracle/graal/java/BciBlockMapping.java Thu Jun 04 11:08:12 2015 -0700 @@ -22,10 +22,6 @@ */ package com.oracle.graal.java; -import com.oracle.jvmci.code.BailoutException; -import com.oracle.jvmci.code.BytecodeFrame; -import com.oracle.jvmci.meta.ResolvedJavaMethod; -import com.oracle.jvmci.meta.ExceptionHandler; import static com.oracle.graal.bytecode.Bytecodes.*; import static com.oracle.graal.compiler.common.GraalOptions.*; @@ -33,7 +29,9 @@ import com.oracle.graal.bytecode.*; import com.oracle.graal.compiler.common.*; +import com.oracle.jvmci.code.*; import com.oracle.jvmci.debug.*; +import com.oracle.jvmci.meta.*; /** * Builds a mapping between bytecodes and basic blocks and builds a conservative control flow graph @@ -540,10 +538,10 @@ case INVOKESTATIC: case INVOKEVIRTUAL: case INVOKEDYNAMIC: { + current = null; + addSuccessor(blockMap, bci, makeBlock(blockMap, stream.nextBCI())); ExceptionDispatchBlock handler = handleExceptions(blockMap, bci); if (handler != null) { - current = null; - addSuccessor(blockMap, bci, makeBlock(blockMap, stream.nextBCI())); addSuccessor(blockMap, bci, handler); } break; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.java/src/com/oracle/graal/java/BytecodeDisassembler.java --- a/graal/com.oracle.graal.java/src/com/oracle/graal/java/BytecodeDisassembler.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.java/src/com/oracle/graal/java/BytecodeDisassembler.java Thu Jun 04 11:08:12 2015 -0700 @@ -22,6 +22,7 @@ */ package com.oracle.graal.java; +import com.oracle.graal.bytecode.*; import com.oracle.jvmci.meta.JavaField; import com.oracle.jvmci.meta.ResolvedJavaMethod; import com.oracle.jvmci.meta.BytecodeDisassemblerProvider; @@ -29,10 +30,9 @@ import com.oracle.jvmci.meta.JavaType; import com.oracle.jvmci.meta.JavaMethod; import com.oracle.jvmci.meta.ConstantPool; + import static com.oracle.graal.bytecode.Bytecodes.*; -import com.oracle.graal.bytecode.*; - /** * Utility for producing a {@code javap}-like disassembly of bytecode. */ diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.java/src/com/oracle/graal/java/BytecodeParser.java --- a/graal/com.oracle.graal.java/src/com/oracle/graal/java/BytecodeParser.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.java/src/com/oracle/graal/java/BytecodeParser.java Thu Jun 04 11:08:12 2015 -0700 @@ -365,6 +365,12 @@ this.firstInstructionArray = new FixedWithNextNode[blockMap.getBlockCount()]; this.entryStateArray = new FrameStateBuilder[blockMap.getBlockCount()]; + /* + * Configure the assertion checking behavior of the FrameStateBuilder. This needs to be + * done only when assertions are enabled, so it is wrapped in an assertion itself. + */ + assert computeKindVerification(startFrameState); + try (Scope s = Debug.scope("LivenessAnalysis")) { int maxLocals = method.getMaxLocals(); liveness = LocalLiveness.compute(stream, blockMap.getBlocks(), maxLocals, blockMap.getLoopCount()); @@ -443,6 +449,28 @@ } } + private boolean computeKindVerification(FrameStateBuilder startFrameState) { + if (blockMap.hasJsrBytecodes) { + /* + * The JSR return address is an int value, but stored using the astore bytecode. Instead + * of weakening the kind assertion checking for all methods, we disable it completely + * for methods that contain a JSR bytecode. + */ + startFrameState.disableKindVerification(); + } + + for (NodePlugin plugin : graphBuilderConfig.getPlugins().getNodePlugins()) { + if (plugin.canChangeStackKind(this)) { + /* + * We have a plugin that can change the kind of values, so no kind assertion + * checking is possible. + */ + startFrameState.disableKindVerification(); + } + } + return true; + } + /** * Hook for subclasses to modify the graph start instruction or append new instructions to it. * @@ -524,12 +552,23 @@ ResolvedJavaMethod original = intrinsicContext.getOriginalMethod(); ValueNode[] locals; if (original.getMaxLocals() == frameState.localsSize() || original.isNative()) { + locals = new ValueNode[original.getMaxLocals()]; + for (int i = 0; i < locals.length; i++) { + ValueNode node = frameState.locals[i]; + if (node == FrameState.TWO_SLOT_MARKER) { + node = null; + } + locals[i] = node; + } locals = frameState.locals; } else { locals = new ValueNode[original.getMaxLocals()]; int parameterCount = original.getSignature().getParameterCount(!original.isStatic()); for (int i = 0; i < parameterCount; i++) { ValueNode param = frameState.locals[i]; + if (param == FrameState.TWO_SLOT_MARKER) { + param = null; + } locals[i] = param; assert param == null || param instanceof ParameterNode || param.isConstant(); } @@ -1249,9 +1288,9 @@ try { currentInvokeReturnType = returnType; currentInvokeKind = invokeKind; - if (tryGenericInvocationPlugin(args, targetMethod)) { + if (tryNodePluginForInvocation(args, targetMethod)) { if (TraceParserPlugins.getValue()) { - traceWithContext("used generic invocation plugin for %s", targetMethod.format("%h.%n(%p)")); + traceWithContext("used node plugin for %s", targetMethod.format("%h.%n(%p)")); } return; } @@ -1370,7 +1409,7 @@ return false; } - private boolean tryGenericInvocationPlugin(ValueNode[] args, ResolvedJavaMethod targetMethod) { + private boolean tryNodePluginForInvocation(ValueNode[] args, ResolvedJavaMethod targetMethod) { for (NodePlugin plugin : graphBuilderConfig.getPlugins().getNodePlugins()) { if (plugin.handleInvoke(this, targetMethod, args)) { return true; @@ -1437,11 +1476,11 @@ } if (inlinedMethod.hasBytecodes()) { for (InlineInvokePlugin plugin : graphBuilderConfig.getPlugins().getInlineInvokePlugins()) { - plugin.notifyBeforeInline(targetMethod); + plugin.notifyBeforeInline(inlinedMethod); } parseAndInlineCallee(inlinedMethod, args, intrinsic); for (InlineInvokePlugin plugin : graphBuilderConfig.getPlugins().getInlineInvokePlugins()) { - plugin.notifyAfterInline(targetMethod); + plugin.notifyAfterInline(inlinedMethod); } } else { return false; @@ -2861,6 +2900,14 @@ private JavaField lookupField(int cpi, int opcode) { maybeEagerlyResolve(cpi, opcode); JavaField result = constantPool.lookupField(cpi, opcode); + if (graphBuilderConfig.unresolvedIsError()) { + assert result instanceof ResolvedJavaField : "Not resolved: " + result; + ResolvedJavaType declaringClass = ((ResolvedJavaField) result).getDeclaringClass(); + if (!declaringClass.isInitialized()) { + assert declaringClass.isInterface() : "Declaring class not initialized but not an interface? " + declaringClass; + declaringClass.initialize(); + } + } assert !graphBuilderConfig.unresolvedIsError() || (result instanceof ResolvedJavaField && ((ResolvedJavaField) result).getDeclaringClass().isInitialized()) : result; return result; } @@ -2907,16 +2954,15 @@ ValueNode checkCastNode = null; if (profile != null) { if (profile.getNullSeen().isFalse()) { - object = append(GuardingPiNode.createNullCheck(object)); + object = appendNullCheck(object); ResolvedJavaType singleType = profile.asSingleType(); if (singleType != null) { LogicNode typeCheck = append(TypeCheckNode.create(singleType, object)); if (typeCheck.isTautology()) { checkCastNode = object; } else { - GuardingPiNode piNode = append(new GuardingPiNode(object, typeCheck, false, DeoptimizationReason.TypeCheckedInliningViolated, DeoptimizationAction.InvalidateReprofile, - StampFactory.exactNonNull(singleType))); - checkCastNode = piNode; + FixedGuardNode fixedGuard = append(new FixedGuardNode(typeCheck, DeoptimizationReason.TypeCheckedInliningViolated, DeoptimizationAction.InvalidateReprofile, false)); + checkCastNode = append(new PiNode(object, StampFactory.exactNonNull(singleType), fixedGuard)); } } } @@ -2927,6 +2973,12 @@ frameState.push(Kind.Object, checkCastNode); } + private ValueNode appendNullCheck(ValueNode object) { + IsNullNode isNull = append(new IsNullNode(object)); + FixedGuardNode fixedGuard = append(new FixedGuardNode(isNull, DeoptimizationReason.NullCheckException, DeoptimizationAction.InvalidateReprofile, true)); + return append(new PiNode(object, object.stamp().join(StampFactory.objectNonNull()), fixedGuard)); + } + private void genInstanceOf() { int cpi = getStream().readCPI(); JavaType type = lookupType(cpi, INSTANCEOF); @@ -2948,7 +3000,7 @@ ValueNode instanceOfNode = null; if (profile != null) { if (profile.getNullSeen().isFalse()) { - object = append(GuardingPiNode.createNullCheck(object)); + object = appendNullCheck(object); ResolvedJavaType singleType = profile.asSingleType(); if (singleType != null) { LogicNode typeCheck = append(TypeCheckNode.create(singleType, object)); diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.java/src/com/oracle/graal/java/FrameStateBuilder.java --- a/graal/com.oracle.graal.java/src/com/oracle/graal/java/FrameStateBuilder.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.java/src/com/oracle/graal/java/FrameStateBuilder.java Thu Jun 04 11:08:12 2015 -0700 @@ -25,6 +25,7 @@ import static com.oracle.graal.bytecode.Bytecodes.*; import static com.oracle.graal.graph.iterators.NodePredicates.*; import static com.oracle.graal.java.BytecodeParser.Options.*; +import static com.oracle.graal.nodes.FrameState.*; import static com.oracle.jvmci.common.JVMCIError.*; import java.util.*; @@ -54,6 +55,7 @@ protected final ValueNode[] locals; protected final ValueNode[] stack; private ValueNode[] lockedObjects; + private boolean canVerifyKind; /** * @see BytecodeFrame#rethrowException @@ -87,6 +89,11 @@ this.monitorIds = EMPTY_MONITOR_ARRAY; this.graph = graph; + this.canVerifyKind = true; + } + + public void disableKindVerification() { + canVerifyKind = false; } public void initializeFromArgumentsArray(ValueNode[] arguments) { @@ -104,7 +111,11 @@ for (int i = 0; i < max; i++) { Kind kind = sig.getParameterKind(i); locals[javaIndex] = arguments[index]; - javaIndex += kind.getSlotCount(); + javaIndex++; + if (kind.needsTwoSlots()) { + locals[javaIndex] = TWO_SLOT_MARKER; + javaIndex++; + } index++; } } @@ -156,7 +167,11 @@ param = new ParameterNode(index, stamp); } locals[javaIndex] = graph.unique(param); - javaIndex += kind.getSlotCount(); + javaIndex++; + if (kind.needsTwoSlots()) { + locals[javaIndex] = TWO_SLOT_MARKER; + javaIndex++; + } index++; } } @@ -169,6 +184,7 @@ this.stack = other.stack.clone(); this.lockedObjects = other.lockedObjects.length == 0 ? other.lockedObjects : other.lockedObjects.clone(); this.rethrowException = other.rethrowException; + this.canVerifyKind = other.canVerifyKind; assert locals.length == method.getMaxLocals(); assert stack.length == Math.max(1, method.getMaxStackSize()); @@ -195,11 +211,11 @@ StringBuilder sb = new StringBuilder(); sb.append("[locals: ["); for (int i = 0; i < locals.length; i++) { - sb.append(i == 0 ? "" : ",").append(locals[i] == null ? "_" : locals[i].toString(Verbosity.Id)); + sb.append(i == 0 ? "" : ",").append(locals[i] == null ? "_" : locals[i] == TWO_SLOT_MARKER ? "#" : locals[i].toString(Verbosity.Id)); } sb.append("] stack: ["); for (int i = 0; i < stackSize; i++) { - sb.append(i == 0 ? "" : ",").append(stack[i] == null ? "_" : stack[i].toString(Verbosity.Id)); + sb.append(i == 0 ? "" : ",").append(stack[i] == null ? "_" : stack[i] == TWO_SLOT_MARKER ? "#" : stack[i].toString(Verbosity.Id)); } sb.append("] locks: ["); for (int i = 0; i < lockedObjects.length; i++) { @@ -293,7 +309,8 @@ for (int i = 0; i < stackSize(); i++) { ValueNode x = stack[i]; ValueNode y = other.stack[i]; - if (x != y && (x == null || x.isDeleted() || y == null || y.isDeleted() || x.getKind() != y.getKind())) { + assert x != null && y != null; + if (x != y && (x == TWO_SLOT_MARKER || x.isDeleted() || y == TWO_SLOT_MARKER || y.isDeleted() || x.getKind() != y.getKind())) { return false; } } @@ -358,7 +375,7 @@ if (currentValue == null || currentValue.isDeleted()) { return null; } else if (block.isPhiAtMerge(currentValue)) { - if (otherValue == null || otherValue.isDeleted() || currentValue.getKind() != otherValue.getKind()) { + if (otherValue == null || otherValue == TWO_SLOT_MARKER || otherValue.isDeleted() || currentValue.getKind() != otherValue.getKind()) { propagateDelete((ValuePhiNode) currentValue); return null; } @@ -366,7 +383,9 @@ return currentValue; } else if (currentValue != otherValue) { assert !(block instanceof LoopBeginNode) : String.format("Phi functions for loop headers are create eagerly for changed locals and all stack slots: %s != %s", currentValue, otherValue); - if (otherValue == null || otherValue.isDeleted() || currentValue.getKind() != otherValue.getKind()) { + if (currentValue == TWO_SLOT_MARKER || otherValue == TWO_SLOT_MARKER) { + return null; + } else if (otherValue == null || otherValue.isDeleted() || currentValue.getKind() != otherValue.getKind()) { return null; } return createValuePhi(currentValue, otherValue, block); @@ -422,14 +441,14 @@ public void insertLoopProxies(LoopExitNode loopExit, FrameStateBuilder loopEntryState) { for (int i = 0; i < localsSize(); i++) { ValueNode value = locals[i]; - if (value != null && (!loopEntryState.contains(value) || loopExit.loopBegin().isPhiAtMerge(value))) { + if (value != null && value != TWO_SLOT_MARKER && (!loopEntryState.contains(value) || loopExit.loopBegin().isPhiAtMerge(value))) { Debug.log(" inserting proxy for %s", value); locals[i] = ProxyNode.forValue(value, loopExit, graph); } } for (int i = 0; i < stackSize(); i++) { ValueNode value = stack[i]; - if (value != null && (!loopEntryState.contains(value) || loopExit.loopBegin().isPhiAtMerge(value))) { + if (value != null && value != TWO_SLOT_MARKER && (!loopEntryState.contains(value) || loopExit.loopBegin().isPhiAtMerge(value))) { Debug.log(" inserting proxy for %s", value); stack[i] = ProxyNode.forValue(value, loopExit, graph); } @@ -446,14 +465,14 @@ public void insertProxies(Function proxyFunction) { for (int i = 0; i < localsSize(); i++) { ValueNode value = locals[i]; - if (value != null) { + if (value != null && value != TWO_SLOT_MARKER) { Debug.log(" inserting proxy for %s", value); locals[i] = proxyFunction.apply(value); } } for (int i = 0; i < stackSize(); i++) { ValueNode value = stack[i]; - if (value != null) { + if (value != null && value != TWO_SLOT_MARKER) { Debug.log(" inserting proxy for %s", value); stack[i] = proxyFunction.apply(value); } @@ -467,9 +486,9 @@ } } - private ValuePhiNode createLoopPhi(AbstractMergeNode block, ValueNode value, boolean stampFromValue) { - if (value == null) { - return null; + private ValueNode createLoopPhi(AbstractMergeNode block, ValueNode value, boolean stampFromValue) { + if (value == null || value == TWO_SLOT_MARKER) { + return value; } assert !block.isPhiAtMerge(value) : "phi function for this block already created"; @@ -552,12 +571,14 @@ if (liveIn) { for (int i = 0; i < locals.length; i++) { if (!liveness.localIsLiveIn(block, i)) { + assert locals[i] != TWO_SLOT_MARKER || locals[i - 1] == null : "Clearing of second slot must have cleared the first slot too"; locals[i] = null; } } } else { for (int i = 0; i < locals.length; i++) { if (!liveness.localIsLiveOut(block, i)) { + assert locals[i] != TWO_SLOT_MARKER || locals[i - 1] == null : "Clearing of second slot must have cleared the first slot too"; locals[i] = null; } } @@ -603,6 +624,17 @@ return stackSize; } + private boolean verifyKind(Kind slotKind, ValueNode x) { + assert x != null; + assert x != TWO_SLOT_MARKER; + assert slotKind.getSlotCount() > 0; + + if (canVerifyKind) { + assert x.getKind().getStackKind() == slotKind.getStackKind(); + } + return true; + } + /** * Loads the local variable at the specified index, checking that the returned value is non-null * and that two-stack values are properly handled. @@ -612,11 +644,9 @@ * @return the instruction that produced the specified local */ public ValueNode loadLocal(int i, Kind slotKind) { - assert slotKind.getSlotCount() > 0; - assert slotKind.getSlotCount() == 1 || locals[i + 1] == null; - ValueNode x = locals[i]; - assert x != null : i; + assert verifyKind(slotKind, x); + assert slotKind.needsTwoSlots() ? locals[i + 1] == TWO_SLOT_MARKER : (i == locals.length - 1 || locals[i + 1] != TWO_SLOT_MARKER); return x; } @@ -629,10 +659,21 @@ * @param x the instruction which produces the value for the local */ public void storeLocal(int i, Kind slotKind, ValueNode x) { - assert slotKind.getSlotCount() > 0; + assert verifyKind(slotKind, x); + if (locals[i] == TWO_SLOT_MARKER) { + /* Writing the second slot of a two-slot value invalidates the first slot. */ + locals[i - 1] = null; + } locals[i] = x; if (slotKind.needsTwoSlots()) { + /* Writing a two-slot value: mark the second slot. */ + locals[i + 1] = TWO_SLOT_MARKER; + } else if (i < locals.length - 1 && locals[i + 1] == TWO_SLOT_MARKER) { + /* + * Writing a one-slot value to an index previously occupied by a two-slot value: clear + * the old marker of the second slot. + */ locals[i + 1] = null; } } @@ -644,11 +685,11 @@ * @param x the instruction to push onto the stack */ public void push(Kind slotKind, ValueNode x) { - assert x != null; - assert slotKind.getSlotCount() > 0; + assert verifyKind(slotKind, x); + xpush(x); if (slotKind.needsTwoSlots()) { - xpush(null); + xpush(TWO_SLOT_MARKER); } } @@ -665,26 +706,30 @@ * @return the instruction on the top of the stack */ public ValueNode pop(Kind slotKind) { - assert slotKind.getSlotCount() > 0; if (slotKind.needsTwoSlots()) { ValueNode s = xpop(); - assert s == null; + assert s == TWO_SLOT_MARKER; } ValueNode x = xpop(); - assert x != null; + assert verifyKind(slotKind, x); return x; } private void xpush(ValueNode x) { + assert x != null; stack[stackSize++] = x; } private ValueNode xpop() { - return stack[--stackSize]; + ValueNode result = stack[--stackSize]; + assert result != null; + return result; } private ValueNode xpeek() { - return stack[stackSize - 1]; + ValueNode result = stack[stackSize - 1]; + assert result != null; + return result; } /** @@ -695,16 +740,15 @@ */ public ValueNode[] popArguments(int argSize) { ValueNode[] result = allocateArray(argSize); - int newStackSize = stackSize; for (int i = argSize - 1; i >= 0; i--) { - newStackSize--; - if (stack[newStackSize] == null) { - /* Two-slot value. */ - newStackSize--; + ValueNode x = xpop(); + if (x == TWO_SLOT_MARKER) { + /* Ignore second slot of two-slot value. */ + x = xpop(); } - result[i] = stack[newStackSize]; + assert x != null && x != TWO_SLOT_MARKER; + result[i] = x; } - stackSize = newStackSize; return result; } @@ -723,21 +767,26 @@ public void stackOp(int opcode) { switch (opcode) { case POP: { - xpop(); + ValueNode w1 = xpop(); + assert w1 != TWO_SLOT_MARKER; break; } case POP2: { xpop(); - xpop(); + ValueNode w2 = xpop(); + assert w2 != TWO_SLOT_MARKER; break; } case DUP: { - xpush(xpeek()); + ValueNode w1 = xpeek(); + assert w1 != TWO_SLOT_MARKER; + xpush(w1); break; } case DUP_X1: { ValueNode w1 = xpop(); ValueNode w2 = xpop(); + assert w1 != TWO_SLOT_MARKER; xpush(w1); xpush(w2); xpush(w1); @@ -747,6 +796,7 @@ ValueNode w1 = xpop(); ValueNode w2 = xpop(); ValueNode w3 = xpop(); + assert w1 != TWO_SLOT_MARKER; xpush(w1); xpush(w3); xpush(w2); @@ -789,6 +839,8 @@ case SWAP: { ValueNode w1 = xpop(); ValueNode w2 = xpop(); + assert w1 != TWO_SLOT_MARKER; + assert w2 != TWO_SLOT_MARKER; xpush(w1); xpush(w2); break; @@ -876,11 +928,11 @@ Debug.log(String.format("| state [nr locals = %d, stack depth = %d, method = %s]", localsSize(), stackSize(), method)); for (int i = 0; i < localsSize(); ++i) { ValueNode value = locals[i]; - Debug.log(String.format("| local[%d] = %-8s : %s", i, value == null ? "bogus" : value.getKind().getJavaName(), value)); + Debug.log(String.format("| local[%d] = %-8s : %s", i, value == null ? "bogus" : value == TWO_SLOT_MARKER ? "second" : value.getKind().getJavaName(), value)); } for (int i = 0; i < stackSize(); ++i) { ValueNode value = stack[i]; - Debug.log(String.format("| stack[%d] = %-8s : %s", i, value == null ? "bogus" : value.getKind().getJavaName(), value)); + Debug.log(String.format("| stack[%d] = %-8s : %s", i, value == null ? "bogus" : value == TWO_SLOT_MARKER ? "second" : value.getKind().getJavaName(), value)); } } } diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.java/src/com/oracle/graal/java/LocalLiveness.java diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64AddressValue.java --- a/graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64AddressValue.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64AddressValue.java Thu Jun 04 11:08:12 2015 -0700 @@ -27,13 +27,14 @@ import com.oracle.jvmci.meta.AllocatableValue; import com.oracle.jvmci.meta.LIRKind; import com.oracle.jvmci.meta.Value; + import static com.oracle.jvmci.code.ValueUtil.*; import static com.oracle.graal.lir.LIRInstruction.OperandFlag.*; import java.util.*; import com.oracle.graal.asm.amd64.*; -import com.oracle.graal.asm.amd64.AMD64Address.Scale; +import com.oracle.graal.asm.amd64.AMD64Address.*; import com.oracle.graal.lir.*; import com.oracle.graal.lir.LIRInstruction.OperandFlag; import com.oracle.graal.lir.LIRInstruction.OperandMode; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64Arithmetic.java --- a/graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64Arithmetic.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64Arithmetic.java Thu Jun 04 11:08:12 2015 -0700 @@ -22,15 +22,16 @@ */ package com.oracle.graal.lir.amd64; +import com.oracle.jvmci.amd64.*; import com.oracle.jvmci.meta.Kind; import com.oracle.jvmci.meta.AllocatableValue; import com.oracle.jvmci.meta.LIRKind; + import static com.oracle.jvmci.code.ValueUtil.*; -import com.oracle.graal.amd64.*; import com.oracle.graal.asm.*; import com.oracle.graal.asm.amd64.*; -import com.oracle.graal.asm.amd64.AMD64Assembler.ConditionFlag; +import com.oracle.graal.asm.amd64.AMD64Assembler.*; import com.oracle.graal.lir.*; import com.oracle.graal.lir.asm.*; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64ArrayEqualsOp.java --- a/graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64ArrayEqualsOp.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64ArrayEqualsOp.java Thu Jun 04 11:08:12 2015 -0700 @@ -22,23 +22,24 @@ */ package com.oracle.graal.lir.amd64; +import com.oracle.jvmci.amd64.*; +import com.oracle.jvmci.amd64.AMD64.*; import com.oracle.jvmci.code.Register; import com.oracle.jvmci.code.TargetDescription; import com.oracle.jvmci.meta.Kind; import com.oracle.jvmci.meta.LIRKind; import com.oracle.jvmci.meta.Value; + import static com.oracle.jvmci.code.ValueUtil.*; import static com.oracle.graal.lir.LIRInstruction.OperandFlag.*; import static com.oracle.jvmci.common.UnsafeAccess.*; import java.lang.reflect.*; -import com.oracle.graal.amd64.*; -import com.oracle.graal.amd64.AMD64.CPUFeature; import com.oracle.graal.asm.*; import com.oracle.graal.asm.amd64.*; -import com.oracle.graal.asm.amd64.AMD64Address.Scale; -import com.oracle.graal.asm.amd64.AMD64Assembler.ConditionFlag; +import com.oracle.graal.asm.amd64.AMD64Address.*; +import com.oracle.graal.asm.amd64.AMD64Assembler.*; import com.oracle.graal.lir.*; import com.oracle.graal.lir.asm.*; import com.oracle.graal.lir.gen.*; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64Binary.java --- a/graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64Binary.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64Binary.java Thu Jun 04 11:08:12 2015 -0700 @@ -25,17 +25,14 @@ import com.oracle.jvmci.meta.AllocatableValue; import com.oracle.jvmci.meta.Value; import com.oracle.jvmci.meta.JavaConstant; + import static com.oracle.jvmci.code.ValueUtil.*; import static com.oracle.graal.lir.LIRInstruction.OperandFlag.*; import com.oracle.jvmci.code.CompilationResult.DataSectionReference; import com.oracle.graal.asm.*; import com.oracle.graal.asm.amd64.*; -import com.oracle.graal.asm.amd64.AMD64Assembler.AMD64BinaryArithmetic; -import com.oracle.graal.asm.amd64.AMD64Assembler.AMD64MIOp; -import com.oracle.graal.asm.amd64.AMD64Assembler.AMD64RMIOp; -import com.oracle.graal.asm.amd64.AMD64Assembler.AMD64RMOp; -import com.oracle.graal.asm.amd64.AMD64Assembler.OperandSize; +import com.oracle.graal.asm.amd64.AMD64Assembler.*; import com.oracle.graal.lir.*; import com.oracle.graal.lir.StandardOp.ImplicitNullCheck; import com.oracle.graal.lir.asm.*; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64BinaryConsumer.java --- a/graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64BinaryConsumer.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64BinaryConsumer.java Thu Jun 04 11:08:12 2015 -0700 @@ -25,17 +25,14 @@ import com.oracle.jvmci.meta.Constant; import com.oracle.jvmci.meta.AllocatableValue; import com.oracle.jvmci.meta.Value; + import static com.oracle.jvmci.code.ValueUtil.*; import static com.oracle.graal.lir.LIRInstruction.OperandFlag.*; import com.oracle.jvmci.code.CompilationResult.DataSectionReference; import com.oracle.graal.asm.*; import com.oracle.graal.asm.amd64.*; -import com.oracle.graal.asm.amd64.AMD64Assembler.AMD64BinaryArithmetic; -import com.oracle.graal.asm.amd64.AMD64Assembler.AMD64MIOp; -import com.oracle.graal.asm.amd64.AMD64Assembler.AMD64MROp; -import com.oracle.graal.asm.amd64.AMD64Assembler.AMD64RMOp; -import com.oracle.graal.asm.amd64.AMD64Assembler.OperandSize; +import com.oracle.graal.asm.amd64.AMD64Assembler.*; import com.oracle.graal.lir.*; import com.oracle.graal.lir.StandardOp.ImplicitNullCheck; import com.oracle.graal.lir.asm.*; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64BreakpointOp.java --- a/graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64BreakpointOp.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64BreakpointOp.java Thu Jun 04 11:08:12 2015 -0700 @@ -23,6 +23,7 @@ package com.oracle.graal.lir.amd64; import com.oracle.jvmci.meta.Value; + import static com.oracle.graal.lir.LIRInstruction.OperandFlag.*; import com.oracle.graal.asm.amd64.*; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64ByteSwapOp.java diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64CCall.java --- a/graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64CCall.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64CCall.java Thu Jun 04 11:08:12 2015 -0700 @@ -25,6 +25,7 @@ import com.oracle.jvmci.code.Register; import com.oracle.jvmci.code.ValueUtil; import com.oracle.jvmci.meta.Value; + import static com.oracle.graal.lir.LIRInstruction.OperandFlag.*; import com.oracle.graal.asm.amd64.*; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64Call.java --- a/graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64Call.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64Call.java Thu Jun 04 11:08:12 2015 -0700 @@ -22,6 +22,7 @@ */ package com.oracle.graal.lir.amd64; +import com.oracle.jvmci.amd64.*; import com.oracle.jvmci.code.Register; import com.oracle.jvmci.code.RegisterValue; import com.oracle.jvmci.code.ValueUtil; @@ -32,12 +33,12 @@ import com.oracle.jvmci.meta.ResolvedJavaMethod; import com.oracle.jvmci.meta.Value; import com.oracle.jvmci.meta.InvokeTarget; + import static com.oracle.jvmci.code.ValueUtil.*; import static com.oracle.graal.lir.LIRInstruction.OperandFlag.*; -import com.oracle.graal.amd64.*; -import com.oracle.graal.asm.amd64.AMD64Assembler.ConditionFlag; import com.oracle.graal.asm.amd64.*; +import com.oracle.graal.asm.amd64.AMD64Assembler.*; import com.oracle.graal.lir.*; import com.oracle.graal.lir.asm.*; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64ClearRegisterOp.java --- a/graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64ClearRegisterOp.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64ClearRegisterOp.java Thu Jun 04 11:08:12 2015 -0700 @@ -23,13 +23,13 @@ package com.oracle.graal.lir.amd64; import com.oracle.jvmci.meta.AllocatableValue; + import static com.oracle.jvmci.code.ValueUtil.*; import static com.oracle.graal.asm.amd64.AMD64Assembler.AMD64BinaryArithmetic.*; import static com.oracle.graal.lir.LIRInstruction.OperandFlag.*; -import com.oracle.graal.asm.amd64.AMD64Assembler.AMD64RMOp; -import com.oracle.graal.asm.amd64.AMD64Assembler.OperandSize; import com.oracle.graal.asm.amd64.*; +import com.oracle.graal.asm.amd64.AMD64Assembler.*; import com.oracle.graal.lir.*; import com.oracle.graal.lir.asm.*; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64ControlFlow.java --- a/graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64ControlFlow.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64ControlFlow.java Thu Jun 04 11:08:12 2015 -0700 @@ -22,20 +22,21 @@ */ package com.oracle.graal.lir.amd64; +import com.oracle.jvmci.amd64.*; import com.oracle.jvmci.code.Register; import com.oracle.jvmci.meta.Kind; import com.oracle.jvmci.meta.AllocatableValue; import com.oracle.jvmci.meta.Value; import com.oracle.jvmci.meta.JavaConstant; + import static com.oracle.jvmci.code.ValueUtil.*; import static com.oracle.graal.lir.LIRInstruction.OperandFlag.*; -import com.oracle.graal.amd64.*; import com.oracle.jvmci.code.CompilationResult.JumpTable; import com.oracle.graal.asm.*; import com.oracle.graal.asm.amd64.*; -import com.oracle.graal.asm.amd64.AMD64Address.Scale; -import com.oracle.graal.asm.amd64.AMD64Assembler.ConditionFlag; +import com.oracle.graal.asm.amd64.AMD64Address.*; +import com.oracle.graal.asm.amd64.AMD64Assembler.*; import com.oracle.graal.compiler.common.calc.*; import com.oracle.graal.lir.*; import com.oracle.graal.lir.StandardOp.BlockEndOp; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64FrameMap.java --- a/graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64FrameMap.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64FrameMap.java Thu Jun 04 11:08:12 2015 -0700 @@ -27,7 +27,9 @@ import com.oracle.jvmci.code.RegisterConfig; import com.oracle.jvmci.meta.Kind; import com.oracle.jvmci.meta.LIRKind; + import static com.oracle.jvmci.code.ValueUtil.*; + import com.oracle.graal.asm.*; import com.oracle.graal.lir.framemap.*; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64LIRInstruction.java diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64MathIntrinsicOp.java --- a/graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64MathIntrinsicOp.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64MathIntrinsicOp.java Thu Jun 04 11:08:12 2015 -0700 @@ -23,6 +23,7 @@ package com.oracle.graal.lir.amd64; import com.oracle.jvmci.meta.Value; + import static com.oracle.jvmci.code.ValueUtil.*; import com.oracle.graal.asm.amd64.*; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64Move.java --- a/graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64Move.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64Move.java Thu Jun 04 11:08:12 2015 -0700 @@ -22,22 +22,22 @@ */ package com.oracle.graal.lir.amd64; +import com.oracle.jvmci.amd64.*; import com.oracle.jvmci.code.Register; import com.oracle.jvmci.code.StackSlotValue; import com.oracle.jvmci.meta.Kind; import com.oracle.jvmci.meta.AllocatableValue; import com.oracle.jvmci.meta.Value; import com.oracle.jvmci.meta.JavaConstant; + import static com.oracle.jvmci.code.ValueUtil.*; import static com.oracle.graal.lir.LIRInstruction.OperandFlag.*; import static java.lang.Double.*; import static java.lang.Float.*; -import com.oracle.graal.amd64.*; import com.oracle.graal.asm.*; import com.oracle.graal.asm.amd64.*; -import com.oracle.graal.asm.amd64.AMD64Assembler.AMD64MIOp; -import com.oracle.graal.asm.amd64.AMD64Assembler.OperandSize; +import com.oracle.graal.asm.amd64.AMD64Assembler.*; import com.oracle.graal.lir.*; import com.oracle.graal.lir.StandardOp.MoveOp; import com.oracle.graal.lir.StandardOp.NullCheck; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64MulDivOp.java --- a/graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64MulDivOp.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64MulDivOp.java Thu Jun 04 11:08:12 2015 -0700 @@ -22,17 +22,17 @@ */ package com.oracle.graal.lir.amd64; +import com.oracle.jvmci.amd64.*; import com.oracle.jvmci.meta.AllocatableValue; import com.oracle.jvmci.meta.LIRKind; import com.oracle.jvmci.meta.Value; + import static com.oracle.jvmci.code.ValueUtil.*; import static com.oracle.graal.asm.amd64.AMD64Assembler.AMD64MOp.*; import static com.oracle.graal.lir.LIRInstruction.OperandFlag.*; -import com.oracle.graal.amd64.*; import com.oracle.graal.asm.amd64.*; -import com.oracle.graal.asm.amd64.AMD64Assembler.AMD64MOp; -import com.oracle.graal.asm.amd64.AMD64Assembler.OperandSize; +import com.oracle.graal.asm.amd64.AMD64Assembler.*; import com.oracle.graal.lir.*; import com.oracle.graal.lir.asm.*; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64RestoreRegistersOp.java --- a/graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64RestoreRegistersOp.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64RestoreRegistersOp.java Thu Jun 04 11:08:12 2015 -0700 @@ -27,6 +27,7 @@ import com.oracle.jvmci.code.ValueUtil; import com.oracle.jvmci.code.StackSlotValue; import com.oracle.jvmci.code.StackSlot; + import static com.oracle.jvmci.code.ValueUtil.*; import static com.oracle.graal.lir.LIRInstruction.OperandFlag.*; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64SaveRegistersOp.java --- a/graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64SaveRegistersOp.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64SaveRegistersOp.java Thu Jun 04 11:08:12 2015 -0700 @@ -28,6 +28,7 @@ import com.oracle.jvmci.code.RegisterSaveLayout; import com.oracle.jvmci.code.StackSlotValue; import com.oracle.jvmci.code.StackSlot; + import static com.oracle.jvmci.code.ValueUtil.*; import static com.oracle.graal.lir.LIRInstruction.OperandFlag.*; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64ShiftOp.java --- a/graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64ShiftOp.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64ShiftOp.java Thu Jun 04 11:08:12 2015 -0700 @@ -22,14 +22,14 @@ */ package com.oracle.graal.lir.amd64; +import com.oracle.jvmci.amd64.*; import com.oracle.jvmci.meta.AllocatableValue; + import static com.oracle.jvmci.code.ValueUtil.*; import static com.oracle.graal.lir.LIRInstruction.OperandFlag.*; -import com.oracle.graal.amd64.*; -import com.oracle.graal.asm.amd64.AMD64Assembler.AMD64MOp; -import com.oracle.graal.asm.amd64.AMD64Assembler.OperandSize; import com.oracle.graal.asm.amd64.*; +import com.oracle.graal.asm.amd64.AMD64Assembler.*; import com.oracle.graal.lir.*; import com.oracle.graal.lir.asm.*; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64SignExtendOp.java --- a/graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64SignExtendOp.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64SignExtendOp.java Thu Jun 04 11:08:12 2015 -0700 @@ -22,15 +22,16 @@ */ package com.oracle.graal.lir.amd64; +import com.oracle.jvmci.amd64.*; import com.oracle.jvmci.meta.AllocatableValue; import com.oracle.jvmci.meta.LIRKind; + import static com.oracle.jvmci.code.ValueUtil.*; import static com.oracle.graal.asm.amd64.AMD64Assembler.OperandSize.*; import static com.oracle.graal.lir.LIRInstruction.OperandFlag.*; -import com.oracle.graal.amd64.*; -import com.oracle.graal.asm.amd64.AMD64Assembler.OperandSize; import com.oracle.graal.asm.amd64.*; +import com.oracle.graal.asm.amd64.AMD64Assembler.*; import com.oracle.graal.lir.*; import com.oracle.graal.lir.asm.*; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64Unary.java --- a/graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64Unary.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64Unary.java Thu Jun 04 11:08:12 2015 -0700 @@ -24,14 +24,12 @@ import com.oracle.jvmci.meta.AllocatableValue; import com.oracle.jvmci.meta.Value; + import static com.oracle.jvmci.code.ValueUtil.*; import static com.oracle.graal.lir.LIRInstruction.OperandFlag.*; import com.oracle.graal.asm.amd64.*; -import com.oracle.graal.asm.amd64.AMD64Assembler.AMD64MOp; -import com.oracle.graal.asm.amd64.AMD64Assembler.AMD64MROp; -import com.oracle.graal.asm.amd64.AMD64Assembler.AMD64RMOp; -import com.oracle.graal.asm.amd64.AMD64Assembler.OperandSize; +import com.oracle.graal.asm.amd64.AMD64Assembler.*; import com.oracle.graal.lir.*; import com.oracle.graal.lir.StandardOp.ImplicitNullCheck; import com.oracle.graal.lir.asm.*; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64ZapRegistersOp.java --- a/graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64ZapRegistersOp.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64ZapRegistersOp.java Thu Jun 04 11:08:12 2015 -0700 @@ -26,6 +26,7 @@ import com.oracle.jvmci.code.RegisterValue; import com.oracle.jvmci.code.RegisterSaveLayout; import com.oracle.jvmci.meta.JavaConstant; + import static com.oracle.graal.lir.LIRInstruction.OperandFlag.*; import static com.oracle.graal.lir.amd64.AMD64SaveRegistersOp.*; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCAddressValue.java --- a/graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCAddressValue.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCAddressValue.java Thu Jun 04 11:08:12 2015 -0700 @@ -27,6 +27,7 @@ import com.oracle.jvmci.meta.LIRKind; import com.oracle.jvmci.meta.Value; import com.oracle.jvmci.meta.AllocatableValue; + import static com.oracle.jvmci.code.ValueUtil.*; import static com.oracle.graal.lir.LIRInstruction.OperandFlag.*; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCArithmetic.java --- a/graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCArithmetic.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCArithmetic.java Thu Jun 04 11:08:12 2015 -0700 @@ -28,7 +28,11 @@ import com.oracle.jvmci.meta.Value; import com.oracle.jvmci.meta.AllocatableValue; import com.oracle.jvmci.meta.JavaConstant; +import com.oracle.jvmci.sparc.*; + import static com.oracle.jvmci.code.ValueUtil.*; +import static com.oracle.jvmci.sparc.SPARC.*; +import static com.oracle.jvmci.sparc.SPARC.CPUFeature.*; import static com.oracle.graal.asm.sparc.SPARCAssembler.*; import static com.oracle.graal.asm.sparc.SPARCAssembler.Annul.*; import static com.oracle.graal.asm.sparc.SPARCAssembler.BranchPredict.*; @@ -36,17 +40,13 @@ import static com.oracle.graal.asm.sparc.SPARCAssembler.ConditionFlag.*; import static com.oracle.graal.asm.sparc.SPARCAssembler.Opfs.*; import static com.oracle.graal.lir.LIRInstruction.OperandFlag.*; -import static com.oracle.graal.sparc.SPARC.*; -import static com.oracle.graal.sparc.SPARC.CPUFeature.*; import com.oracle.graal.asm.*; import com.oracle.graal.asm.sparc.*; -import com.oracle.graal.asm.sparc.SPARCMacroAssembler.ScratchRegister; -import com.oracle.graal.asm.sparc.SPARCMacroAssembler.Setx; +import com.oracle.graal.asm.sparc.SPARCMacroAssembler.*; import com.oracle.graal.lir.*; import com.oracle.graal.lir.asm.*; import com.oracle.graal.lir.gen.*; -import com.oracle.graal.sparc.*; import com.oracle.jvmci.common.*; public enum SPARCArithmetic { diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCArrayEqualsOp.java --- a/graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCArrayEqualsOp.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCArrayEqualsOp.java Thu Jun 04 11:08:12 2015 -0700 @@ -26,6 +26,8 @@ import com.oracle.jvmci.meta.LIRKind; import com.oracle.jvmci.meta.Value; import com.oracle.jvmci.meta.Kind; +import com.oracle.jvmci.sparc.SPARC.*; + import static com.oracle.jvmci.code.ValueUtil.*; import static com.oracle.graal.asm.sparc.SPARCAssembler.Annul.*; import static com.oracle.graal.asm.sparc.SPARCAssembler.BranchPredict.*; @@ -33,20 +35,18 @@ import static com.oracle.graal.asm.sparc.SPARCAssembler.ConditionFlag.*; import static com.oracle.graal.asm.sparc.SPARCAssembler.RCondition.*; import static com.oracle.graal.lir.LIRInstruction.OperandFlag.*; -import static com.oracle.graal.sparc.SPARC.*; -import static com.oracle.graal.sparc.SPARC.CPUFeature.*; import static com.oracle.jvmci.common.UnsafeAccess.*; +import static com.oracle.jvmci.sparc.SPARC.*; +import static com.oracle.jvmci.sparc.SPARC.CPUFeature.*; import java.lang.reflect.*; import com.oracle.graal.asm.*; import com.oracle.graal.asm.sparc.*; -import com.oracle.graal.asm.sparc.SPARCAssembler.CC; -import com.oracle.graal.asm.sparc.SPARCAssembler.ConditionFlag; +import com.oracle.graal.asm.sparc.SPARCAssembler.*; import com.oracle.graal.lir.*; import com.oracle.graal.lir.asm.*; import com.oracle.graal.lir.gen.*; -import com.oracle.graal.sparc.SPARC.CPUFeature; /** * Emits code which compares two arrays of the same length. diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCBitManipulationOp.java --- a/graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCBitManipulationOp.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCBitManipulationOp.java Thu Jun 04 11:08:12 2015 -0700 @@ -27,10 +27,11 @@ import com.oracle.jvmci.meta.Kind; import com.oracle.jvmci.meta.Value; import com.oracle.jvmci.meta.AllocatableValue; + import static com.oracle.jvmci.code.ValueUtil.*; +import static com.oracle.jvmci.sparc.SPARC.*; import static com.oracle.graal.asm.sparc.SPARCAssembler.*; import static com.oracle.graal.lir.LIRInstruction.OperandFlag.*; -import static com.oracle.graal.sparc.SPARC.*; import com.oracle.graal.asm.sparc.*; import com.oracle.graal.lir.*; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCBreakpointOp.java --- a/graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCBreakpointOp.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCBreakpointOp.java Thu Jun 04 11:08:12 2015 -0700 @@ -23,6 +23,7 @@ package com.oracle.graal.lir.sparc; import com.oracle.jvmci.meta.Value; + import static com.oracle.graal.lir.LIRInstruction.OperandFlag.*; import com.oracle.graal.asm.sparc.*; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCByteSwapOp.java --- a/graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCByteSwapOp.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCByteSwapOp.java Thu Jun 04 11:08:12 2015 -0700 @@ -28,11 +28,12 @@ import com.oracle.jvmci.meta.LIRKind; import com.oracle.jvmci.meta.Kind; import com.oracle.jvmci.meta.Value; + import static com.oracle.jvmci.code.ValueUtil.*; import static com.oracle.graal.lir.LIRInstruction.OperandFlag.*; import com.oracle.graal.asm.sparc.*; -import com.oracle.graal.asm.sparc.SPARCAssembler.Asi; +import com.oracle.graal.asm.sparc.SPARCAssembler.*; import com.oracle.graal.lir.*; import com.oracle.graal.lir.asm.*; import com.oracle.graal.lir.gen.*; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCCall.java --- a/graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCCall.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCCall.java Thu Jun 04 11:08:12 2015 -0700 @@ -27,12 +27,13 @@ import com.oracle.jvmci.meta.ResolvedJavaMethod; import com.oracle.jvmci.meta.InvokeTarget; import com.oracle.jvmci.meta.Value; + import static com.oracle.jvmci.code.ValueUtil.*; +import static com.oracle.jvmci.sparc.SPARC.*; import static com.oracle.graal.lir.LIRInstruction.OperandFlag.*; -import static com.oracle.graal.sparc.SPARC.*; import com.oracle.graal.asm.sparc.*; -import com.oracle.graal.asm.sparc.SPARCMacroAssembler.Sethix; +import com.oracle.graal.asm.sparc.SPARCMacroAssembler.*; import com.oracle.graal.lir.*; import com.oracle.graal.lir.asm.*; import com.oracle.jvmci.common.*; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCCompare.java --- a/graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCCompare.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCCompare.java Thu Jun 04 11:08:12 2015 -0700 @@ -25,6 +25,7 @@ import com.oracle.jvmci.meta.Kind; import com.oracle.jvmci.meta.Value; import com.oracle.jvmci.meta.JavaConstant; + import static com.oracle.jvmci.code.ValueUtil.*; import static com.oracle.graal.asm.sparc.SPARCAssembler.*; import static com.oracle.graal.asm.sparc.SPARCAssembler.CC.*; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCControlFlow.java --- a/graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCControlFlow.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCControlFlow.java Thu Jun 04 11:08:12 2015 -0700 @@ -22,18 +22,14 @@ */ package com.oracle.graal.lir.sparc; -import com.oracle.jvmci.code.Register; -import com.oracle.jvmci.meta.Kind; -import com.oracle.jvmci.meta.Value; -import com.oracle.jvmci.meta.JavaConstant; -import static com.oracle.jvmci.code.ValueUtil.*; import static com.oracle.graal.asm.sparc.SPARCAssembler.*; import static com.oracle.graal.asm.sparc.SPARCAssembler.Annul.*; import static com.oracle.graal.asm.sparc.SPARCAssembler.BranchPredict.*; import static com.oracle.graal.asm.sparc.SPARCAssembler.CC.*; import static com.oracle.graal.asm.sparc.SPARCAssembler.ConditionFlag.*; import static com.oracle.graal.lir.LIRInstruction.OperandFlag.*; -import static com.oracle.graal.sparc.SPARC.*; +import static com.oracle.jvmci.code.ValueUtil.*; +import static com.oracle.jvmci.sparc.SPARC.*; import java.util.*; @@ -50,8 +46,10 @@ import com.oracle.graal.lir.StandardOp.BlockEndOp; import com.oracle.graal.lir.SwitchStrategy.BaseSwitchClosure; import com.oracle.graal.lir.asm.*; -import com.oracle.graal.sparc.SPARC.CPUFeature; +import com.oracle.jvmci.code.*; import com.oracle.jvmci.common.*; +import com.oracle.jvmci.meta.*; +import com.oracle.jvmci.sparc.SPARC.CPUFeature; public class SPARCControlFlow { @@ -110,7 +108,7 @@ this.unorderedIsTrue = unorderedIsTrue; this.trueDestinationProbability = trueDestinationProbability; CC conditionCodeReg = CC.forKind(kind); - conditionFlag = ConditionFlag.fromCondtition(conditionCodeReg, condition, unorderedIsTrue); + conditionFlag = fromCondition(conditionCodeReg, condition, unorderedIsTrue); } @Override @@ -436,14 +434,14 @@ break; } case Object: { - conditionCode = CC.Ptrcc; + conditionCode = crb.codeCache.getTarget().wordKind == Kind.Long ? CC.Xcc : CC.Icc; scratchRegister = asObjectReg(scratch); break; } default: throw new JVMCIError("switch only supported for int, long and object"); } - ConditionFlag conditionFlag = ConditionFlag.fromCondtition(conditionCode, condition, false); + ConditionFlag conditionFlag = fromCondition(conditionCode, condition, false); masm.cmp(keyRegister, scratchRegister); masm.bpcc(conditionFlag, NOT_ANNUL, target, conditionCode, PREDICT_TAKEN); masm.nop(); // delay slot @@ -605,4 +603,54 @@ throw JVMCIError.shouldNotReachHere(); } } + + public static ConditionFlag fromCondition(CC conditionFlagsRegister, Condition cond, boolean unorderedIsTrue) { + switch (conditionFlagsRegister) { + case Xcc: + case Icc: + switch (cond) { + case EQ: + return Equal; + case NE: + return NotEqual; + case BT: + return LessUnsigned; + case LT: + return Less; + case BE: + return LessEqualUnsigned; + case LE: + return LessEqual; + case AE: + return GreaterEqualUnsigned; + case GE: + return GreaterEqual; + case AT: + return GreaterUnsigned; + case GT: + return Greater; + } + throw JVMCIError.shouldNotReachHere("Unimplemented for: " + cond); + case Fcc0: + case Fcc1: + case Fcc2: + case Fcc3: + switch (cond) { + case EQ: + return unorderedIsTrue ? F_UnorderedOrEqual : F_Equal; + case NE: + return ConditionFlag.F_NotEqual; + case LT: + return unorderedIsTrue ? F_UnorderedOrLess : F_Less; + case LE: + return unorderedIsTrue ? F_UnorderedOrLessOrEqual : F_LessOrEqual; + case GE: + return unorderedIsTrue ? F_UnorderedGreaterOrEqual : F_GreaterOrEqual; + case GT: + return unorderedIsTrue ? F_UnorderedOrGreater : F_Greater; + } + throw JVMCIError.shouldNotReachHere("Unkown condition: " + cond); + } + throw JVMCIError.shouldNotReachHere("Unknown condition flag register " + conditionFlagsRegister); + } } diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCDelayedControlTransfer.java diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCFrameMap.java --- a/graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCFrameMap.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCFrameMap.java Thu Jun 04 11:08:12 2015 -0700 @@ -27,9 +27,9 @@ import com.oracle.jvmci.code.StackSlot; import com.oracle.jvmci.meta.LIRKind; import com.oracle.jvmci.meta.Kind; +import com.oracle.jvmci.sparc.*; import com.oracle.graal.asm.*; import com.oracle.graal.lir.framemap.*; -import com.oracle.graal.sparc.*; /** * SPARC specific frame map. diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCJumpOp.java --- a/graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCJumpOp.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCJumpOp.java Thu Jun 04 11:08:12 2015 -0700 @@ -24,8 +24,8 @@ import static com.oracle.graal.asm.sparc.SPARCAssembler.Annul.*; -import com.oracle.graal.asm.sparc.SPARCAssembler.ConditionFlag; import com.oracle.graal.asm.sparc.*; +import com.oracle.graal.asm.sparc.SPARCAssembler.*; import com.oracle.graal.lir.*; import com.oracle.graal.lir.StandardOp.JumpOp; import com.oracle.graal.lir.asm.*; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCLIRInstruction.java diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCMathIntrinsicOp.java --- a/graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCMathIntrinsicOp.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCMathIntrinsicOp.java Thu Jun 04 11:08:12 2015 -0700 @@ -24,6 +24,7 @@ import com.oracle.jvmci.meta.Kind; import com.oracle.jvmci.meta.Value; + import static com.oracle.jvmci.code.ValueUtil.*; import com.oracle.graal.asm.sparc.*; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCMove.java --- a/graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCMove.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCMove.java Thu Jun 04 11:08:12 2015 -0700 @@ -31,22 +31,22 @@ import com.oracle.jvmci.meta.Value; import com.oracle.jvmci.meta.AllocatableValue; import com.oracle.jvmci.meta.JavaConstant; +import com.oracle.jvmci.sparc.*; +import com.oracle.jvmci.sparc.SPARC.*; + import static com.oracle.jvmci.code.ValueUtil.*; import static com.oracle.jvmci.meta.Kind.*; +import static com.oracle.jvmci.sparc.SPARC.*; import static com.oracle.graal.asm.sparc.SPARCAssembler.*; import static com.oracle.graal.lir.LIRInstruction.OperandFlag.*; -import static com.oracle.graal.sparc.SPARC.*; import com.oracle.graal.asm.sparc.*; -import com.oracle.graal.asm.sparc.SPARCMacroAssembler.ScratchRegister; -import com.oracle.graal.asm.sparc.SPARCMacroAssembler.Setx; +import com.oracle.graal.asm.sparc.SPARCMacroAssembler.*; import com.oracle.graal.lir.*; import com.oracle.graal.lir.StandardOp.ImplicitNullCheck; import com.oracle.graal.lir.StandardOp.MoveOp; import com.oracle.graal.lir.StandardOp.NullCheck; import com.oracle.graal.lir.asm.*; -import com.oracle.graal.sparc.*; -import com.oracle.graal.sparc.SPARC.CPUFeature; import com.oracle.jvmci.common.*; public class SPARCMove { diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCSaveRegistersOp.java --- a/graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCSaveRegistersOp.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCSaveRegistersOp.java Thu Jun 04 11:08:12 2015 -0700 @@ -28,6 +28,8 @@ import com.oracle.jvmci.code.StackSlotValue; import com.oracle.jvmci.code.StackSlot; import com.oracle.jvmci.code.RegisterValue; +import com.oracle.jvmci.sparc.*; + import static com.oracle.jvmci.code.ValueUtil.*; import static com.oracle.graal.lir.LIRInstruction.OperandFlag.*; @@ -38,7 +40,6 @@ import com.oracle.graal.lir.StandardOp.SaveRegistersOp; import com.oracle.graal.lir.asm.*; import com.oracle.graal.lir.framemap.*; -import com.oracle.graal.sparc.*; /** * Saves registers to stack slots. diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCTailDelayedLIRInstruction.java --- a/graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCTailDelayedLIRInstruction.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCTailDelayedLIRInstruction.java Thu Jun 04 11:08:12 2015 -0700 @@ -22,6 +22,7 @@ */ package com.oracle.graal.lir.sparc; +import com.oracle.graal.asm.sparc.*; import com.oracle.graal.lir.*; /** @@ -33,14 +34,14 @@ *
    *
  1. Emit everything up to the second last instruction.
  2. *
  3. Call - * {@link SPARCDelayedControlTransfer#emitControlTransfer(com.oracle.graal.lir.asm.CompilationResultBuilder, com.oracle.graal.asm.sparc.SPARCMacroAssembler)} + * {@link SPARCDelayedControlTransfer#emitControlTransfer(com.oracle.graal.lir.asm.CompilationResultBuilder, SPARCMacroAssembler)} * to let the DelayedControlTransfer instruction emit its own code (But must not stuff the delay * slot with Nop)
  4. *
  5. emit the last instruction for this {@link LIRInstruction}
  6. *
* * Note: If this instruction decides not to use the delay slot, it can skip the call of - * {@link SPARCDelayedControlTransfer#emitControlTransfer(com.oracle.graal.lir.asm.CompilationResultBuilder, com.oracle.graal.asm.sparc.SPARCMacroAssembler)} + * {@link SPARCDelayedControlTransfer#emitControlTransfer(com.oracle.graal.lir.asm.CompilationResultBuilder, SPARCMacroAssembler)} * . The DelayedControlTransfer instruction will emit the code just with Nop in the delay slot. */ public interface SPARCTailDelayedLIRInstruction { diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCTestOp.java --- a/graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCTestOp.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCTestOp.java Thu Jun 04 11:08:12 2015 -0700 @@ -23,9 +23,10 @@ package com.oracle.graal.lir.sparc; import com.oracle.jvmci.meta.Value; + import static com.oracle.jvmci.code.ValueUtil.*; +import static com.oracle.jvmci.sparc.SPARC.*; import static com.oracle.graal.lir.LIRInstruction.OperandFlag.*; -import static com.oracle.graal.sparc.SPARC.*; import com.oracle.graal.asm.sparc.*; import com.oracle.graal.lir.*; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.lir/src/com/oracle/graal/lir/LabelRef.java diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.lir/src/com/oracle/graal/lir/StandardOp.java --- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/StandardOp.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/StandardOp.java Thu Jun 04 11:08:12 2015 -0700 @@ -223,7 +223,7 @@ } /** - * An operation that takes one input and stores it in a stack slot as well as on an ordinary + * An operation that takes one input and stores it in a stack slot as well as to an ordinary * variable. */ public interface StackStoreOp { diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.lir/src/com/oracle/graal/lir/SwitchStrategy.java diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.lir/src/com/oracle/graal/lir/asm/CompilationResultBuilder.java --- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/asm/CompilationResultBuilder.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/asm/CompilationResultBuilder.java Thu Jun 04 11:08:12 2015 -0700 @@ -36,6 +36,7 @@ import com.oracle.jvmci.meta.JavaConstant; import com.oracle.jvmci.meta.Value; import com.oracle.jvmci.meta.InvokeTarget; + import static com.oracle.jvmci.code.ValueUtil.*; import java.util.*; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.lir/src/com/oracle/graal/lir/asm/CompilationResultBuilderFactory.java diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.lir/src/com/oracle/graal/lir/framemap/FrameMap.java diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.lir/src/com/oracle/graal/lir/gen/LIRGenerator.java --- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/gen/LIRGenerator.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/gen/LIRGenerator.java Thu Jun 04 11:08:12 2015 -0700 @@ -38,6 +38,7 @@ import com.oracle.jvmci.meta.LIRKind; import com.oracle.jvmci.meta.AllocatableValue; import com.oracle.jvmci.meta.MetaAccessProvider; + import static com.oracle.jvmci.code.ValueUtil.*; import static com.oracle.graal.lir.LIRValueUtil.*; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.nodes.test/src/com/oracle/graal/nodes/test/ObjectStampJoinTest.java --- a/graal/com.oracle.graal.nodes.test/src/com/oracle/graal/nodes/test/ObjectStampJoinTest.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.nodes.test/src/com/oracle/graal/nodes/test/ObjectStampJoinTest.java Thu Jun 04 11:08:12 2015 -0700 @@ -89,7 +89,6 @@ Stamp alwaysNull = StampFactory.alwaysNull(); Stamp join = join(alwaysNull, dExactNonNull); Assert.assertFalse(join.hasValues()); - Assert.assertFalse(StampTool.isPointerNonNull(join)); Assert.assertFalse(StampTool.isPointerAlwaysNull(join)); } diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/FrameState.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/FrameState.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/FrameState.java Thu Jun 04 11:08:12 2015 -0700 @@ -27,6 +27,7 @@ import java.util.*; import com.oracle.graal.bytecode.*; +import com.oracle.graal.compiler.common.type.*; import com.oracle.graal.graph.*; import com.oracle.graal.graph.iterators.*; import com.oracle.graal.nodeinfo.*; @@ -48,6 +49,22 @@ private static final DebugMetric METRIC_FRAMESTATE_COUNT = Debug.metric("FrameStateCount"); + /** + * Marker value for the second slot of values that occupy two local variable or expression stack + * slots. The marker value is used by the bytecode parser, but replaced with {@code null} in the + * {@link #values} of the {@link FrameState}. + */ + public static final ValueNode TWO_SLOT_MARKER = new TwoSlotMarker(); + + @NodeInfo + private static final class TwoSlotMarker extends ValueNode { + public static final NodeClass TYPE = NodeClass.create(TwoSlotMarker.class); + + protected TwoSlotMarker() { + super(TYPE, StampFactory.forKind(Kind.Illegal)); + } + } + protected final int localsSize; protected final int stackSize; @@ -139,13 +156,23 @@ private void createValues(ValueNode[] locals, ValueNode[] stack, ValueNode[] locks) { int index = 0; for (int i = 0; i < locals.length; ++i) { - this.values.initialize(index++, locals[i]); + ValueNode value = locals[i]; + if (value == TWO_SLOT_MARKER) { + value = null; + } + this.values.initialize(index++, value); } for (int i = 0; i < stackSize; ++i) { - this.values.initialize(index++, stack[i]); + ValueNode value = stack[i]; + if (value == TWO_SLOT_MARKER) { + value = null; + } + this.values.initialize(index++, value); } for (int i = 0; i < locks.length; ++i) { - this.values.initialize(index++, locks[i]); + ValueNode value = locks[i]; + assert value != TWO_SLOT_MARKER; + this.values.initialize(index++, value); } } diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/GuardingPiNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/GuardingPiNode.java Thu Jun 04 10:46:23 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,153 +0,0 @@ -/* - * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.nodes; - -import com.oracle.graal.compiler.common.type.*; -import com.oracle.graal.graph.*; -import com.oracle.graal.graph.spi.*; -import com.oracle.graal.nodeinfo.*; -import com.oracle.graal.nodes.calc.*; -import com.oracle.graal.nodes.extended.*; -import com.oracle.graal.nodes.spi.*; -import com.oracle.graal.nodes.type.*; -import com.oracle.jvmci.meta.*; - -/** - * A node that changes the stamp of its input based on some condition being true. - */ -@NodeInfo(nameTemplate = "GuardingPi(!={p#negated}) {p#reason/s}") -public final class GuardingPiNode extends FixedWithNextNode implements Lowerable, Virtualizable, Canonicalizable, ValueProxy { - - public static final NodeClass TYPE = NodeClass.create(GuardingPiNode.class); - @Input ValueNode object; - @Input(InputType.Condition) LogicNode condition; - protected final DeoptimizationReason reason; - protected final DeoptimizationAction action; - protected final Stamp piStamp; - protected boolean negated; - - public ValueNode object() { - return object; - } - - public LogicNode condition() { - return condition; - } - - public boolean isNegated() { - return negated; - } - - public DeoptimizationReason getReason() { - return reason; - } - - public DeoptimizationAction getAction() { - return action; - } - - public GuardingPiNode(ValueNode object) { - this(object, object.graph().unique(new IsNullNode(object)), true, DeoptimizationReason.NullCheckException, DeoptimizationAction.None, object.stamp().join(StampFactory.objectNonNull())); - } - - public GuardingPiNode(ValueNode object, ValueNode condition, boolean negateCondition, DeoptimizationReason reason, DeoptimizationAction action, Stamp stamp) { - super(TYPE, stamp); - assert stamp != null; - this.piStamp = stamp; - this.object = object; - this.condition = (LogicNode) condition; - this.reason = reason; - this.action = action; - this.negated = negateCondition; - } - - public static ValueNode createNullCheck(ValueNode object) { - ObjectStamp objectStamp = (ObjectStamp) object.stamp(); - if (objectStamp.nonNull()) { - return object; - } else { - return new GuardingPiNode(object); - } - } - - @Override - public void lower(LoweringTool tool) { - GuardingNode guard = tool.createGuard(next(), condition, reason, action, negated); - ValueAnchorNode anchor = graph().add(new ValueAnchorNode((ValueNode) guard)); - if (usages().isNotEmpty()) { - PiNode pi = graph().unique(new PiNode(object, stamp(), (ValueNode) guard)); - replaceAtUsages(pi); - } - graph().replaceFixedWithFixed(this, anchor); - } - - @Override - public void virtualize(VirtualizerTool tool) { - State state = tool.getObjectState(object); - if (state != null && state.getState() == EscapeState.Virtual && StampTool.typeOrNull(this) != null && StampTool.typeOrNull(this).isAssignableFrom(state.getVirtualObject().type())) { - tool.replaceWithVirtual(state.getVirtualObject()); - } - } - - @Override - public boolean inferStamp() { - return updateStamp(piStamp.join(object().stamp())); - } - - @Override - public Node canonical(CanonicalizerTool tool) { - if (stamp().isEmpty()) { - // The guard always fails - return new DeoptimizeNode(action, reason); - } - if (condition instanceof LogicConstantNode) { - LogicConstantNode c = (LogicConstantNode) condition; - if (c.getValue() == negated) { - // The guard always fails - return new DeoptimizeNode(action, reason); - } else if (stamp().equals(object().stamp())) { - // The guard always succeeds, and does not provide new type information - return object; - } else { - // The guard always succeeds, and provides new type information - return new PiNode(object, stamp()); - } - } - return this; - } - - @NodeIntrinsic - public static native Object guardingNonNull(Object object); - - @Override - public ValueNode getOriginalNode() { - return object; - } - - /** - * Casts a value to have an exact, non-null stamp representing {@link Class} that is guarded by - * a null check. - */ - @NodeIntrinsic(GuardingPiNode.class) - public static native Class asNonNullClass(Class c); -} diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/CompareNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/CompareNode.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/CompareNode.java Thu Jun 04 11:08:12 2015 -0700 @@ -182,7 +182,7 @@ if (x.stamp() instanceof AbstractObjectStamp) { comparison = ObjectEqualsNode.create(x, y, constantReflection); } else if (x.stamp() instanceof AbstractPointerStamp) { - comparison = new PointerEqualsNode(x, y); + comparison = PointerEqualsNode.create(x, y); } else { assert x.getKind().isNumericInteger(); comparison = IntegerEqualsNode.create(x, y, constantReflection); diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/PointerEqualsNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/PointerEqualsNode.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/PointerEqualsNode.java Thu Jun 04 11:08:12 2015 -0700 @@ -41,6 +41,14 @@ this(TYPE, x, y); } + public static LogicNode create(ValueNode x, ValueNode y) { + LogicNode result = findSynonym(x, y); + if (result != null) { + return result; + } + return new PointerEqualsNode(x, y); + } + protected PointerEqualsNode(NodeClass c, ValueNode x, ValueNode y) { super(c, Condition.EQ, false, x, y); assert x.stamp() instanceof AbstractPointerStamp; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/BoxNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/BoxNode.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/BoxNode.java Thu Jun 04 11:08:12 2015 -0700 @@ -29,7 +29,6 @@ import com.oracle.graal.graph.spi.*; import com.oracle.graal.nodeinfo.*; import com.oracle.graal.nodes.*; -import com.oracle.graal.nodes.calc.*; import com.oracle.graal.nodes.java.*; import com.oracle.graal.nodes.spi.*; import com.oracle.graal.nodes.type.*; @@ -41,13 +40,15 @@ * methods in Integer, Long, etc. */ @NodeInfo -public final class BoxNode extends UnaryNode implements VirtualizableAllocation, Lowerable { +public final class BoxNode extends FixedWithNextNode implements VirtualizableAllocation, Lowerable, Canonicalizable.Unary { public static final NodeClass TYPE = NodeClass.create(BoxNode.class); - protected final Kind boxingKind; + @Input private ValueNode value; + private final Kind boxingKind; public BoxNode(ValueNode value, ResolvedJavaType resultType, Kind boxingKind) { - super(TYPE, StampFactory.exactNonNull(resultType), value); + super(TYPE, StampFactory.exactNonNull(resultType)); + this.value = value; this.boxingKind = boxingKind; } @@ -55,6 +56,10 @@ return boxingKind; } + public ValueNode getValue() { + return value; + } + @Override public void lower(LoweringTool tool) { tool.getLowerer().lower(this, tool); @@ -62,10 +67,9 @@ @Override public ValueNode canonical(CanonicalizerTool tool, ValueNode forValue) { - /* - * Constant values are not canonicalized into their constant boxing objects because this - * would mean that the information that they came from a valueOf is lost. - */ + if (tool.allUsagesAvailable() && hasNoUsages()) { + return null; + } return this; } diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/GetClassNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/GetClassNode.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/GetClassNode.java Thu Jun 04 11:08:12 2015 -0700 @@ -48,6 +48,7 @@ public GetClassNode(Stamp stamp, ValueNode object) { super(TYPE, stamp); this.object = object; + assert ((ObjectStamp) object.stamp()).nonNull(); } @Override diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/CheckCastNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/CheckCastNode.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/CheckCastNode.java Thu Jun 04 11:08:12 2015 -0700 @@ -32,6 +32,7 @@ import com.oracle.graal.nodeinfo.*; import com.oracle.graal.nodes.*; import com.oracle.graal.nodes.calc.*; +import com.oracle.graal.nodes.extended.*; import com.oracle.graal.nodes.spi.*; import com.oracle.graal.nodes.type.*; import com.oracle.jvmci.meta.*; @@ -59,8 +60,8 @@ } protected CheckCastNode(NodeClass c, ResolvedJavaType type, ValueNode object, JavaTypeProfile profile, boolean forStoreCheck) { - super(c, StampFactory.declaredTrusted(type)); - assert object.stamp() instanceof ObjectStamp : object + ":" + object.stamp(); + super(c, StampFactory.declaredTrusted(type).improveWith(object.stamp())); + assert object.stamp() instanceof ObjectStamp : object; assert type != null; this.type = type; this.object = object; @@ -74,7 +75,7 @@ if (synonym != null) { return synonym; } - assert object.stamp() instanceof ObjectStamp : object + ":" + object.stamp(); + assert object.stamp() instanceof ObjectStamp : object; if (assumptions != null) { AssumptionResult leafConcreteSubtype = type.findLeafConcreteSubtype(); if (leafConcreteSubtype != null && !leafConcreteSubtype.getResult().equals(type)) { @@ -90,7 +91,7 @@ } /** - * Lowers a {@link CheckCastNode} to a {@link GuardingPiNode}. That is: + * Lowers a {@link CheckCastNode}. That is: * *
      * 1: A a = ...
@@ -118,7 +119,7 @@
     @Override
     public void lower(LoweringTool tool) {
         Stamp newStamp = StampFactory.declaredTrusted(type).improveWith(object().stamp());
-        ValueNode condition;
+        LogicNode condition;
         ValueNode theValue = object;
         if (newStamp.isEmpty()) {
             // This is a check cast that will always fail
@@ -148,9 +149,11 @@
                 condition = LogicNode.or(graph().unique(new IsNullNode(object)), typeTest, shortCircuitProbability);
             }
         }
-        GuardingPiNode checkedObject = graph().add(new GuardingPiNode(theValue, condition, false, forStoreCheck ? ArrayStoreException : ClassCastException, InvalidateReprofile, newStamp));
-        graph().replaceFixedWithFixed(this, checkedObject);
-        checkedObject.lower(tool);
+        GuardingNode guard = tool.createGuard(next(), condition, forStoreCheck ? ArrayStoreException : ClassCastException, InvalidateReprofile, false);
+        ValueAnchorNode valueAnchor = graph().add(new ValueAnchorNode((ValueNode) guard));
+        PiNode piNode = graph().unique(new PiNode(theValue, newStamp, valueAnchor));
+        this.replaceAtUsages(piNode);
+        graph().replaceFixedWithFixed(this, valueAnchor);
     }
 
     @Override
diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/TypeCheckNode.java
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/TypeCheckNode.java	Thu Jun 04 10:46:23 2015 -0700
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/TypeCheckNode.java	Thu Jun 04 11:08:12 2015 -0700
@@ -27,13 +27,13 @@
 import com.oracle.graal.graph.spi.*;
 import com.oracle.graal.nodeinfo.*;
 import com.oracle.graal.nodes.*;
-import com.oracle.graal.nodes.calc.*;
 import com.oracle.graal.nodes.spi.*;
 import com.oracle.jvmci.meta.*;
 import com.oracle.jvmci.meta.Assumptions.AssumptionResult;
 
 /**
- * The {@code TypeCheckNode} represents a test equivalent to (o != null && o.getClass() == type).
+ * The {@code TypeCheckNode} represents a test equivalent to {@code o.getClass() == type}. The node
+ * may only be used if {@code o != null} is known to be true as indicated by the object's stamp.
  */
 @NodeInfo
 public final class TypeCheckNode extends UnaryOpLogicNode implements Lowerable, Virtualizable {
@@ -41,7 +41,7 @@
 
     protected final ResolvedJavaType type;
 
-    public TypeCheckNode(ResolvedJavaType type, ValueNode object) {
+    protected TypeCheckNode(ResolvedJavaType type, ValueNode object) {
         super(TYPE, object);
         this.type = type;
         assert type != null;
@@ -50,7 +50,8 @@
 
     public static LogicNode create(ResolvedJavaType type, ValueNode object) {
         ObjectStamp objectStamp = (ObjectStamp) object.stamp();
-        LogicNode constantValue = findSynonym(type, objectStamp.type(), objectStamp.nonNull(), objectStamp.isExactType());
+        assert objectStamp.nonNull() : object;
+        LogicNode constantValue = findSynonym(type, objectStamp.type(), true, objectStamp.isExactType());
         if (constantValue != null) {
             return constantValue;
         } else {
@@ -69,13 +70,11 @@
             return this;
         }
         ObjectStamp objectStamp = (ObjectStamp) forValue.stamp();
-        if (objectStamp.alwaysNull()) {
-            return LogicConstantNode.contradiction();
-        }
+        assert objectStamp.nonNull();
 
         ResolvedJavaType stampType = objectStamp.type();
         if (stampType != null) {
-            ValueNode result = check(forValue, stampType, objectStamp.nonNull(), objectStamp.isExactType());
+            ValueNode result = findSynonym(type(), stampType, true, objectStamp.isExactType());
             if (result != null) {
                 return result;
             }
@@ -83,7 +82,7 @@
             if (assumptions != null) {
                 AssumptionResult leafConcreteSubtype = stampType.findLeafConcreteSubtype();
                 if (leafConcreteSubtype != null) {
-                    result = check(forValue, leafConcreteSubtype.getResult(), objectStamp.nonNull(), true);
+                    result = findSynonym(type(), leafConcreteSubtype.getResult(), true, true);
                     if (result != null) {
                         assumptions.record(leafConcreteSubtype);
                         return result;
@@ -94,22 +93,6 @@
         return this;
     }
 
-    private ValueNode check(ValueNode forValue, ResolvedJavaType inputType, boolean nonNull, boolean exactType) {
-        ValueNode result = findSynonym(type(), inputType, nonNull, exactType);
-        if (result != null) {
-            return result;
-        }
-        if (type().equals(inputType)) {
-            boolean mightBeNull = !nonNull;
-            if (exactType && mightBeNull) {
-                // the instanceof matches if the object is non-null, so return true
-                // depending on the null-ness.
-                return LogicNegationNode.create(new IsNullNode(forValue));
-            }
-        }
-        return null;
-    }
-
     public static LogicNode findSynonym(ResolvedJavaType type, ResolvedJavaType inputType, boolean nonNull, boolean exactType) {
         if (inputType == null) {
             return null;
diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/type/StampTool.java
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/type/StampTool.java	Thu Jun 04 10:46:23 2015 -0700
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/type/StampTool.java	Thu Jun 04 11:08:12 2015 -0700
@@ -129,7 +129,7 @@
      *         always null
      */
     public static boolean isPointerNonNull(Stamp stamp) {
-        if (stamp instanceof AbstractPointerStamp && stamp.hasValues()) {
+        if (stamp instanceof AbstractPointerStamp) {
             return ((AbstractPointerStamp) stamp).nonNull();
         }
         return false;
diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/GuardLoweringPhase.java
--- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/GuardLoweringPhase.java	Thu Jun 04 10:46:23 2015 -0700
+++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/GuardLoweringPhase.java	Thu Jun 04 11:08:12 2015 -0700
@@ -23,6 +23,7 @@
 package com.oracle.graal.phases.common;
 
 import com.oracle.jvmci.meta.JavaConstant;
+
 import static com.oracle.graal.compiler.common.GraalOptions.*;
 
 import java.util.*;
@@ -62,7 +63,7 @@
 
     private static class UseImplicitNullChecks extends ScheduledNodeIterator {
 
-        private final Map nullGuarded = Node.newIdentityMap();
+        private final Map nullGuarded = Node.newIdentityMap();
         private final int implicitNullCheckLimit;
 
         UseImplicitNullChecks(int implicitNullCheckLimit) {
@@ -75,48 +76,85 @@
                 processGuard(node);
             } else if (node instanceof Access) {
                 processAccess((Access) node);
+            } else if (node instanceof PiNode) {
+                processPi((PiNode) node);
             }
             if (node instanceof StateSplit && ((StateSplit) node).stateAfter() != null) {
                 nullGuarded.clear();
             } else {
-                Iterator> it = nullGuarded.entrySet().iterator();
+                Iterator> it = nullGuarded.entrySet().iterator();
                 while (it.hasNext()) {
-                    Entry entry = it.next();
-                    GuardNode guard = entry.getValue();
+                    Entry entry = it.next();
+                    ValueNode guard = entry.getValue();
                     if (guard.usages().contains(node)) {
                         it.remove();
+                    } else if (guard instanceof PiNode && guard != node) {
+                        PiNode piNode = (PiNode) guard;
+                        if (piNode.getGuard().asNode().usages().contains(node)) {
+                            it.remove();
+                        }
                     }
                 }
             }
         }
 
+        private boolean processPi(PiNode node) {
+            ValueNode guardNode = nullGuarded.get(node.object());
+            if (guardNode != null && node.getGuard() == guardNode) {
+                nullGuarded.put(node, node);
+                return true;
+            }
+            return false;
+        }
+
         private void processAccess(Access access) {
             if (access.canNullCheck()) {
-                GuardNode guard = nullGuarded.get(access.object());
-                if (guard != null && isImplicitNullCheck(access.accessLocation())) {
-                    metricImplicitNullCheck.increment();
-                    access.setGuard(null);
-                    FixedAccessNode fixedAccess;
-                    if (access instanceof FloatingAccessNode) {
-                        FloatingAccessNode floatingAccessNode = (FloatingAccessNode) access;
-                        MemoryNode lastLocationAccess = floatingAccessNode.getLastLocationAccess();
-                        fixedAccess = floatingAccessNode.asFixedNode();
-                        replaceCurrent(fixedAccess);
-                        if (lastLocationAccess != null) {
-                            // fixed accesses are not currently part of the memory graph
-                            GraphUtil.tryKillUnused(lastLocationAccess.asNode());
-                        }
-                    } else {
-                        fixedAccess = (FixedAccessNode) access;
+                ValueNode object = access.object();
+                check(access, object);
+            }
+        }
+
+        private void check(Access access, ValueNode object) {
+            ValueNode guard = nullGuarded.get(object);
+            if (guard != null && isImplicitNullCheck(access.accessLocation())) {
+                if (object instanceof PiNode) {
+                    PiNode piNode = (PiNode) object;
+                    if (access.object() == object) {
+                        access.asNode().replaceFirstInput(object, piNode.getOriginalNode());
+                    }
+                    if (!(piNode.getGuard() instanceof GuardNode)) {
+                        return;
                     }
-                    fixedAccess.setNullCheck(true);
-                    LogicNode condition = guard.condition();
-                    guard.replaceAndDelete(fixedAccess);
-                    if (condition.hasNoUsages()) {
-                        GraphUtil.killWithUnusedFloatingInputs(condition);
+                }
+                metricImplicitNullCheck.increment();
+                access.setGuard(null);
+                FixedAccessNode fixedAccess;
+                if (access instanceof FloatingAccessNode) {
+                    FloatingAccessNode floatingAccessNode = (FloatingAccessNode) access;
+                    MemoryNode lastLocationAccess = floatingAccessNode.getLastLocationAccess();
+                    fixedAccess = floatingAccessNode.asFixedNode();
+                    replaceCurrent(fixedAccess);
+                    if (lastLocationAccess != null) {
+                        // fixed accesses are not currently part of the memory graph
+                        GraphUtil.tryKillUnused(lastLocationAccess.asNode());
                     }
-                    nullGuarded.remove(fixedAccess.object());
+                } else {
+                    fixedAccess = (FixedAccessNode) access;
                 }
+                fixedAccess.setNullCheck(true);
+                GuardNode guardNode = null;
+                if (guard instanceof GuardNode) {
+                    guardNode = (GuardNode) guard;
+                } else {
+                    PiNode piNode = (PiNode) guard;
+                    guardNode = (GuardNode) piNode.getGuard();
+                }
+                LogicNode condition = guardNode.condition();
+                guardNode.replaceAndDelete(fixedAccess);
+                if (condition.hasNoUsages()) {
+                    GraphUtil.killWithUnusedFloatingInputs(condition);
+                }
+                nullGuarded.remove(fixedAccess.object());
             }
         }
 
diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/inlining/InliningUtil.java
--- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/inlining/InliningUtil.java	Thu Jun 04 10:46:23 2015 -0700
+++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/inlining/InliningUtil.java	Thu Jun 04 11:08:12 2015 -0700
@@ -628,6 +628,7 @@
 
         if (returnValuePhi != null) {
             assert returnValuePhi.verify();
+            returnValuePhi.inferStamp();
             return returnValuePhi;
         } else {
             return singleReturnValue;
@@ -655,8 +656,9 @@
         if (firstParam.getKind() == Kind.Object && !StampTool.isPointerNonNull(firstParam)) {
             IsNullNode condition = graph.unique(new IsNullNode(firstParam));
             Stamp stamp = firstParam.stamp().join(objectNonNull());
-            GuardingPiNode nonNullReceiver = graph.add(new GuardingPiNode(firstParam, condition, true, NullCheckException, InvalidateReprofile, stamp));
-            graph.addBeforeFixed(invoke.asNode(), nonNullReceiver);
+            FixedGuardNode fixedGuard = graph.add(new FixedGuardNode(condition, NullCheckException, InvalidateReprofile, true));
+            PiNode nonNullReceiver = graph.unique(new PiNode(firstParam, stamp, fixedGuard));
+            graph.addBeforeFixed(invoke.asNode(), fixedGuard);
             callTarget.replaceFirstInput(firstParam, nonNullReceiver);
             return nonNullReceiver;
         }
diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.printer/src/com/oracle/graal/printer/CFGPrinterObserver.java
--- a/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/CFGPrinterObserver.java	Thu Jun 04 10:46:23 2015 -0700
+++ b/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/CFGPrinterObserver.java	Thu Jun 04 11:08:12 2015 -0700
@@ -22,15 +22,11 @@
  */
 package com.oracle.graal.printer;
 
-import com.oracle.jvmci.code.CompilationResult;
-import com.oracle.jvmci.code.CodeCacheProvider;
-import com.oracle.jvmci.code.InstalledCode;
-import com.oracle.jvmci.meta.ResolvedJavaMethod;
-import com.oracle.jvmci.meta.JavaMethod;
 import java.io.*;
 import java.util.*;
 import java.util.concurrent.atomic.*;
 
+import com.oracle.graal.code.*;
 import com.oracle.graal.compiler.gen.*;
 import com.oracle.graal.graph.*;
 import com.oracle.graal.java.*;
@@ -40,8 +36,11 @@
 import com.oracle.graal.nodes.*;
 import com.oracle.graal.nodes.cfg.*;
 import com.oracle.graal.phases.schedule.*;
+import com.oracle.jvmci.code.*;
 import com.oracle.jvmci.common.*;
 import com.oracle.jvmci.debug.*;
+import com.oracle.jvmci.meta.*;
+import com.oracle.jvmci.service.*;
 
 /**
  * Observes compilation events and uses {@link CFGPrinter} to produce a control flow graph for the
@@ -179,10 +178,10 @@
 
         } else if (object instanceof CompilationResult) {
             final CompilationResult compResult = (CompilationResult) object;
-            cfgPrinter.printMachineCode(codeCache.disassemble(compResult, null), message);
+            cfgPrinter.printMachineCode(disassemble(codeCache, compResult, null), message);
         } else if (isCompilationResultAndInstalledCode(object)) {
             Object[] tuple = (Object[]) object;
-            cfgPrinter.printMachineCode(codeCache.disassemble((CompilationResult) tuple[0], (InstalledCode) tuple[1]), message);
+            cfgPrinter.printMachineCode(disassemble(codeCache, (CompilationResult) tuple[0], (InstalledCode) tuple[1]), message);
         } else if (object instanceof Interval[]) {
             cfgPrinter.printIntervals(message, (Interval[]) object);
         } else if (object instanceof StackInterval[]) {
@@ -197,6 +196,37 @@
 
     }
 
+    private static DisassemblerProvider disassembler;
+
+    private static final DisassemblerProvider NOP_DISASSEMBLER = new DisassemblerProvider() {
+        public String getName() {
+            return null;
+        }
+    };
+
+    private static DisassemblerProvider getDisassembler() {
+        if (disassembler == null) {
+            DisassemblerProvider selected = NOP_DISASSEMBLER;
+            for (DisassemblerProvider d : Services.load(DisassemblerProvider.class)) {
+                String name = d.getName().toLowerCase();
+                if (name.contains("hcf") || name.contains("hexcodefile")) {
+                    selected = d;
+                    break;
+                }
+            }
+            disassembler = selected;
+        }
+        return disassembler;
+    }
+
+    private static String disassemble(CodeCacheProvider codeCache, CompilationResult compResult, InstalledCode installedCode) {
+        DisassemblerProvider dis = getDisassembler();
+        if (installedCode != null) {
+            return dis.disassembleInstalledCode(codeCache, compResult, installedCode);
+        }
+        return dis.disassembleCompiledCode(codeCache, compResult);
+    }
+
     private static boolean isCompilationResultAndInstalledCode(Object object) {
         if (object instanceof Object[]) {
             Object[] tuple = (Object[]) object;
diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.printer/src/com/oracle/graal/printer/GraphPrinterDumpHandler.java
--- a/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/GraphPrinterDumpHandler.java	Thu Jun 04 10:46:23 2015 -0700
+++ b/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/GraphPrinterDumpHandler.java	Thu Jun 04 11:08:12 2015 -0700
@@ -39,6 +39,8 @@
 import com.oracle.jvmci.debug.*;
 import com.oracle.jvmci.debug.Debug.Scope;
 
+//JaCoCo Exclude
+
 /**
  * Observes compilation events and uses {@link IdealGraphPrinter} to generate a graph representation
  * that can be inspected with the Ideal Graph
diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.replacements.amd64/src/com/oracle/graal/replacements/amd64/AMD64GraphBuilderPlugins.java
--- a/graal/com.oracle.graal.replacements.amd64/src/com/oracle/graal/replacements/amd64/AMD64GraphBuilderPlugins.java	Thu Jun 04 10:46:23 2015 -0700
+++ b/graal/com.oracle.graal.replacements.amd64/src/com/oracle/graal/replacements/amd64/AMD64GraphBuilderPlugins.java	Thu Jun 04 11:08:12 2015 -0700
@@ -22,15 +22,16 @@
  */
 package com.oracle.graal.replacements.amd64;
 
+import com.oracle.jvmci.amd64.*;
 import com.oracle.jvmci.code.ForeignCallsProvider;
 import com.oracle.jvmci.meta.ResolvedJavaMethod;
 import com.oracle.jvmci.meta.Kind;
 import com.oracle.jvmci.meta.LocationIdentity;
+
 import static com.oracle.graal.compiler.target.Backend.*;
 import static com.oracle.graal.replacements.amd64.AMD64MathIntrinsicNode.Operation.*;
 import sun.misc.*;
 
-import com.oracle.graal.amd64.*;
 import com.oracle.graal.graphbuilderconf.*;
 import com.oracle.graal.graphbuilderconf.GraphBuilderConfiguration.Plugins;
 import com.oracle.graal.graphbuilderconf.InvocationPlugin.Receiver;
diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/BoxingSnippets.java
--- a/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/BoxingSnippets.java	Thu Jun 04 10:46:23 2015 -0700
+++ b/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/BoxingSnippets.java	Thu Jun 04 11:08:12 2015 -0700
@@ -33,7 +33,6 @@
 import com.oracle.graal.nodes.calc.*;
 import com.oracle.graal.nodes.extended.*;
 import com.oracle.graal.nodes.spi.*;
-import com.oracle.graal.nodes.util.*;
 import com.oracle.graal.phases.util.*;
 import com.oracle.graal.replacements.SnippetTemplate.AbstractTemplates;
 import com.oracle.graal.replacements.SnippetTemplate.Arguments;
@@ -185,15 +184,14 @@
             FloatingNode canonical = canonicalizeBoxing(box, providers.getMetaAccess(), providers.getConstantReflection());
             // if in AOT mode, we don't want to embed boxed constants.
             if (canonical != null && !ImmutableCode.getValue()) {
-                box.graph().replaceFloating(box, canonical);
+                box.graph().replaceFixedWithFloating(box, canonical);
             } else {
                 Arguments args = new Arguments(boxSnippets.get(box.getBoxingKind()), box.graph().getGuardsStage(), tool.getLoweringStage());
                 args.add("value", box.getValue());
 
                 SnippetTemplate template = template(args);
                 Debug.log("Lowering integerValueOf in %s: node=%s, template=%s, arguments=%s", box.graph(), box, template, args);
-                template.instantiate(providers.getMetaAccess(), box, DEFAULT_REPLACER, tool, args);
-                GraphUtil.killWithUnusedFloatingInputs(box);
+                template.instantiate(providers.getMetaAccess(), box, DEFAULT_REPLACER, args);
             }
         }
 
diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/DefaultJavaLoweringProvider.java
--- a/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/DefaultJavaLoweringProvider.java	Thu Jun 04 10:46:23 2015 -0700
+++ b/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/DefaultJavaLoweringProvider.java	Thu Jun 04 11:08:12 2015 -0700
@@ -73,6 +73,7 @@
 
     @Override
     public void lower(Node n, LoweringTool tool) {
+        StructuredGraph graph = (StructuredGraph) n.graph();
         if (n instanceof LoadFieldNode) {
             lowerLoadFieldNode((LoadFieldNode) n, tool);
         } else if (n instanceof StoreFieldNode) {
@@ -103,6 +104,10 @@
             boxingSnippets.lower((BoxNode) n, tool);
         } else if (n instanceof UnboxNode) {
             boxingSnippets.lower((UnboxNode) n, tool);
+        } else if (n instanceof TypeCheckNode) {
+            if (graph.getGuardsStage().areDeoptsFixed()) {
+                lowerTypeCheckNode((TypeCheckNode) n, tool, graph);
+            }
         } else if (n instanceof VerifyHeapNode) {
             lowerVerifyHeap((VerifyHeapNode) n);
         } else {
@@ -110,6 +115,13 @@
         }
     }
 
+    private void lowerTypeCheckNode(TypeCheckNode n, LoweringTool tool, StructuredGraph graph) {
+        ValueNode hub = createReadHub(graph, n.getValue(), null);
+        ValueNode clazz = graph.unique(ConstantNode.forConstant(tool.getStampProvider().createHubStamp((ObjectStamp) n.getValue().stamp()), n.type().getObjectHub(), tool.getMetaAccess()));
+        LogicNode objectEquals = graph.unique(PointerEqualsNode.create(hub, clazz));
+        n.replaceAndDelete(objectEquals);
+    }
+
     protected void lowerVerifyHeap(VerifyHeapNode n) {
         GraphUtil.removeFixedWithUnusedInputs(n);
     }
diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/InstanceOfSnippetsTemplates.java
--- a/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/InstanceOfSnippetsTemplates.java	Thu Jun 04 10:46:23 2015 -0700
+++ b/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/InstanceOfSnippetsTemplates.java	Thu Jun 04 11:08:12 2015 -0700
@@ -95,7 +95,7 @@
      */
     protected InstanceOfUsageReplacer createReplacer(FloatingNode instanceOf, Instantiation instantiation, Node usage, final StructuredGraph graph) {
         InstanceOfUsageReplacer replacer;
-        if (usage instanceof IfNode || usage instanceof FixedGuardNode || usage instanceof ShortCircuitOrNode || usage instanceof GuardingPiNode || usage instanceof ConditionAnchorNode) {
+        if (usage instanceof IfNode || usage instanceof FixedGuardNode || usage instanceof ShortCircuitOrNode || usage instanceof ConditionAnchorNode) {
             ValueNode trueValue = ConstantNode.forInt(1, graph);
             ValueNode falseValue = ConstantNode.forInt(0, graph);
             if (instantiation.isInitialized() && (trueValue != instantiation.trueValue || falseValue != instantiation.falseValue)) {
diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/NodeIntrinsificationPhase.java
--- a/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/NodeIntrinsificationPhase.java	Thu Jun 04 10:46:23 2015 -0700
+++ b/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/NodeIntrinsificationPhase.java	Thu Jun 04 11:08:12 2015 -0700
@@ -489,12 +489,6 @@
             for (Node piUsage : usage.usages().snapshot()) {
                 checkCheckCastUsage(graph, intrinsifiedNode, usage, piUsage);
             }
-        } else if (usage instanceof GuardingPiNode) {
-            GuardingPiNode pi = (GuardingPiNode) usage;
-            for (Node piUsage : pi.usages().snapshot()) {
-                checkCheckCastUsage(graph, intrinsifiedNode, usage, piUsage);
-            }
-            graph.removeFixed(pi);
         } else {
             DebugScope.forceDump(graph, "exception");
             assert false : sourceLocation(usage) + " has unexpected usage " + usage + " of checkcast " + input + " at " + sourceLocation(input);
diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/WordOperationPlugin.java
--- a/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/WordOperationPlugin.java	Thu Jun 04 10:46:23 2015 -0700
+++ b/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/WordOperationPlugin.java	Thu Jun 04 11:08:12 2015 -0700
@@ -59,6 +59,11 @@
         this.wordKind = wordTypes.getWordKind();
     }
 
+    @Override
+    public boolean canChangeStackKind(GraphBuilderContext b) {
+        return true;
+    }
+
     /**
      * Processes a call to a method if it is annotated with {@link Operation} by adding nodes to the
      * graph being built that implement the denoted operation.
diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.sparc/src/com/oracle/graal/sparc/SPARC.java
--- a/graal/com.oracle.graal.sparc/src/com/oracle/graal/sparc/SPARC.java	Thu Jun 04 10:46:23 2015 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,337 +0,0 @@
-/*
- * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-package com.oracle.graal.sparc;
-
-import com.oracle.jvmci.code.Architecture;
-import com.oracle.jvmci.code.Register;
-import com.oracle.jvmci.code.TargetDescription;
-import com.oracle.jvmci.meta.Kind;
-import com.oracle.jvmci.meta.PlatformKind;
-import static com.oracle.jvmci.code.MemoryBarriers.*;
-
-import java.nio.*;
-import java.util.*;
-
-import com.oracle.jvmci.code.Register.RegisterCategory;
-
-/**
- * Represents the SPARC architecture.
- */
-public class SPARC extends Architecture {
-
-    public static final RegisterCategory CPU = new RegisterCategory("CPU");
-
-    // General purpose registers
-    public static final Register r0 = new Register(0, 0, "g0", CPU);
-    public static final Register r1 = new Register(1, 1, "g1", CPU);
-    public static final Register r2 = new Register(2, 2, "g2", CPU);
-    public static final Register r3 = new Register(3, 3, "g3", CPU);
-    public static final Register r4 = new Register(4, 4, "g4", CPU);
-    public static final Register r5 = new Register(5, 5, "g5", CPU);
-    public static final Register r6 = new Register(6, 6, "g6", CPU);
-    public static final Register r7 = new Register(7, 7, "g7", CPU);
-
-    public static final Register r8 = new Register(8, 8, "o0", CPU);
-    public static final Register r9 = new Register(9, 9, "o1", CPU);
-    public static final Register r10 = new Register(10, 10, "o2", CPU);
-    public static final Register r11 = new Register(11, 11, "o3", CPU);
-    public static final Register r12 = new Register(12, 12, "o4", CPU);
-    public static final Register r13 = new Register(13, 13, "o5", CPU);
-    public static final Register r14 = new Register(14, 14, "o6", CPU);
-    public static final Register r15 = new Register(15, 15, "o7", CPU);
-
-    public static final Register r16 = new Register(16, 16, "l0", CPU);
-    public static final Register r17 = new Register(17, 17, "l1", CPU);
-    public static final Register r18 = new Register(18, 18, "l2", CPU);
-    public static final Register r19 = new Register(19, 19, "l3", CPU);
-    public static final Register r20 = new Register(20, 20, "l4", CPU);
-    public static final Register r21 = new Register(21, 21, "l5", CPU);
-    public static final Register r22 = new Register(22, 22, "l6", CPU);
-    public static final Register r23 = new Register(23, 23, "l7", CPU);
-
-    public static final Register r24 = new Register(24, 24, "i0", CPU);
-    public static final Register r25 = new Register(25, 25, "i1", CPU);
-    public static final Register r26 = new Register(26, 26, "i2", CPU);
-    public static final Register r27 = new Register(27, 27, "i3", CPU);
-    public static final Register r28 = new Register(28, 28, "i4", CPU);
-    public static final Register r29 = new Register(29, 29, "i5", CPU);
-    public static final Register r30 = new Register(30, 30, "i6", CPU);
-    public static final Register r31 = new Register(31, 31, "i7", CPU);
-
-    public static final Register g0 = r0;
-    public static final Register g1 = r1;
-    public static final Register g2 = r2;
-    public static final Register g3 = r3;
-    public static final Register g4 = r4;
-    public static final Register g5 = r5;
-    public static final Register g6 = r6;
-    public static final Register g7 = r7;
-
-    public static final Register o0 = r8;
-    public static final Register o1 = r9;
-    public static final Register o2 = r10;
-    public static final Register o3 = r11;
-    public static final Register o4 = r12;
-    public static final Register o5 = r13;
-    public static final Register o6 = r14;
-    public static final Register o7 = r15;
-
-    public static final Register l0 = r16;
-    public static final Register l1 = r17;
-    public static final Register l2 = r18;
-    public static final Register l3 = r19;
-    public static final Register l4 = r20;
-    public static final Register l5 = r21;
-    public static final Register l6 = r22;
-    public static final Register l7 = r23;
-
-    public static final Register i0 = r24;
-    public static final Register i1 = r25;
-    public static final Register i2 = r26;
-    public static final Register i3 = r27;
-    public static final Register i4 = r28;
-    public static final Register i5 = r29;
-    public static final Register i6 = r30;
-    public static final Register i7 = r31;
-
-    public static final Register sp = o6;
-    public static final Register fp = i6;
-
-    // @formatter:off
-    public static final Register[] cpuRegisters = {
-        r0,  r1,  r2,  r3,  r4,  r5,  r6,  r7,
-        r8,  r9,  r10, r11, r12, r13, r14, r15,
-        r16, r17, r18, r19, r20, r21, r22, r23,
-        r24, r25, r26, r27, r28, r29, r30, r31
-    };
-    // @formatter:on
-
-    public static final RegisterCategory FPUs = new RegisterCategory("FPUs", cpuRegisters.length);
-    public static final RegisterCategory FPUd = new RegisterCategory("FPUd", cpuRegisters.length + 32);
-
-    // Floating point registers
-    public static final Register f0 = new Register(32, 0, "f0", FPUs);
-    public static final Register f1 = new Register(33, 1, "f1", FPUs);
-    public static final Register f2 = new Register(34, 2, "f2", FPUs);
-    public static final Register f3 = new Register(35, 3, "f3", FPUs);
-    public static final Register f4 = new Register(36, 4, "f4", FPUs);
-    public static final Register f5 = new Register(37, 5, "f5", FPUs);
-    public static final Register f6 = new Register(38, 6, "f6", FPUs);
-    public static final Register f7 = new Register(39, 7, "f7", FPUs);
-
-    public static final Register f8 = new Register(40, 8, "f8", FPUs);
-    public static final Register f9 = new Register(41, 9, "f9", FPUs);
-    public static final Register f10 = new Register(42, 10, "f10", FPUs);
-    public static final Register f11 = new Register(43, 11, "f11", FPUs);
-    public static final Register f12 = new Register(44, 12, "f12", FPUs);
-    public static final Register f13 = new Register(45, 13, "f13", FPUs);
-    public static final Register f14 = new Register(46, 14, "f14", FPUs);
-    public static final Register f15 = new Register(47, 15, "f15", FPUs);
-
-    public static final Register f16 = new Register(48, 16, "f16", FPUs);
-    public static final Register f17 = new Register(49, 17, "f17", FPUs);
-    public static final Register f18 = new Register(50, 18, "f18", FPUs);
-    public static final Register f19 = new Register(51, 19, "f19", FPUs);
-    public static final Register f20 = new Register(52, 20, "f20", FPUs);
-    public static final Register f21 = new Register(53, 21, "f21", FPUs);
-    public static final Register f22 = new Register(54, 22, "f22", FPUs);
-    public static final Register f23 = new Register(55, 23, "f23", FPUs);
-
-    public static final Register f24 = new Register(56, 24, "f24", FPUs);
-    public static final Register f25 = new Register(57, 25, "f25", FPUs);
-    public static final Register f26 = new Register(58, 26, "f26", FPUs);
-    public static final Register f27 = new Register(59, 27, "f27", FPUs);
-    public static final Register f28 = new Register(60, 28, "f28", FPUs);
-    public static final Register f29 = new Register(61, 29, "f29", FPUs);
-    public static final Register f30 = new Register(62, 30, "f30", FPUs);
-    public static final Register f31 = new Register(63, 31, "f31", FPUs);
-
-    public static final Register d0 = new Register(32, getDoubleEncoding(0), "d0", FPUs);
-    public static final Register d2 = new Register(34, getDoubleEncoding(2), "d2", FPUs);
-    public static final Register d4 = new Register(36, getDoubleEncoding(4), "d4", FPUs);
-    public static final Register d6 = new Register(38, getDoubleEncoding(6), "d6", FPUs);
-    public static final Register d8 = new Register(40, getDoubleEncoding(8), "d8", FPUs);
-    public static final Register d10 = new Register(42, getDoubleEncoding(10), "d10", FPUs);
-    public static final Register d12 = new Register(44, getDoubleEncoding(12), "d12", FPUs);
-    public static final Register d14 = new Register(46, getDoubleEncoding(14), "d14", FPUs);
-
-    public static final Register d16 = new Register(48, getDoubleEncoding(16), "d16", FPUs);
-    public static final Register d18 = new Register(50, getDoubleEncoding(18), "d18", FPUs);
-    public static final Register d20 = new Register(52, getDoubleEncoding(20), "d20", FPUs);
-    public static final Register d22 = new Register(54, getDoubleEncoding(22), "d22", FPUs);
-    public static final Register d24 = new Register(56, getDoubleEncoding(24), "d24", FPUs);
-    public static final Register d26 = new Register(58, getDoubleEncoding(26), "d26", FPUs);
-    public static final Register d28 = new Register(60, getDoubleEncoding(28), "d28", FPUs);
-    public static final Register d30 = new Register(62, getDoubleEncoding(28), "d28", FPUs);
-
-    public static final Register d32 = new Register(64, getDoubleEncoding(32), "d32", FPUd);
-    public static final Register d34 = new Register(65, getDoubleEncoding(34), "d34", FPUd);
-    public static final Register d36 = new Register(66, getDoubleEncoding(36), "d36", FPUd);
-    public static final Register d38 = new Register(67, getDoubleEncoding(38), "d38", FPUd);
-    public static final Register d40 = new Register(68, getDoubleEncoding(40), "d40", FPUd);
-    public static final Register d42 = new Register(69, getDoubleEncoding(42), "d42", FPUd);
-    public static final Register d44 = new Register(70, getDoubleEncoding(44), "d44", FPUd);
-    public static final Register d46 = new Register(71, getDoubleEncoding(46), "d46", FPUd);
-
-    public static final Register d48 = new Register(72, getDoubleEncoding(48), "d48", FPUd);
-    public static final Register d50 = new Register(73, getDoubleEncoding(50), "d50", FPUd);
-    public static final Register d52 = new Register(74, getDoubleEncoding(52), "d52", FPUd);
-    public static final Register d54 = new Register(75, getDoubleEncoding(54), "d54", FPUd);
-    public static final Register d56 = new Register(76, getDoubleEncoding(56), "d56", FPUd);
-    public static final Register d58 = new Register(77, getDoubleEncoding(58), "d58", FPUd);
-    public static final Register d60 = new Register(78, getDoubleEncoding(60), "d60", FPUd);
-    public static final Register d62 = new Register(79, getDoubleEncoding(62), "d62", FPUd);
-
-    // @formatter:off
-    public static final Register[] fpuRegisters = {
-        f0,  f1,  f2,  f3,  f4,  f5,  f6,  f7,
-        f8,  f9,  f10, f11, f12, f13, f14, f15,
-        f16, f17, f18, f19, f20, f21, f22, f23,
-        f24, f25, f26, f27, f28, f29, f30, f31,
-        d32, d34, d36, d38, d40, d42, d44, d46,
-        d48, d50, d52, d54, d56, d58, d60, d62
-    };
-    // @formatter:on
-
-    // @formatter:off
-    public static final Register[] allRegisters = {
-        // CPU
-        r0,  r1,  r2,  r3,  r4,  r5,  r6,  r7,
-        r8,  r9,  r10, r11, r12, r13, r14, r15,
-        r16, r17, r18, r19, r20, r21, r22, r23,
-        r24, r25, r26, r27, r28, r29, r30, r31,
-        // FPU
-        f0,  f1,  f2,  f3,  f4,  f5,  f6,  f7,
-        f8,  f9,  f10, f11, f12, f13, f14, f15,
-        f16, f17, f18, f19, f20, f21, f22, f23,
-        f24, f25, f26, f27, f28, f29, f30, f31,
-        d32, d34, d36, d38, d40, d42, d44, d46,
-        d48, d50, d52, d54, d56, d58, d60, d62
-    };
-    // @formatter:on
-
-    /**
-     * Stack bias for stack and frame pointer loads.
-     */
-    public static final int STACK_BIAS = 0x7ff;
-    /**
-     * In fact there are 64 single floating point registers, 32 of them could be accessed. TODO:
-     * Improve handling of these float registers
-     */
-    public static final int FLOAT_REGISTER_COUNT = 64;
-
-    /**
-     * Alignment for valid memory access.
-     */
-    public static final int MEMORY_ACCESS_ALIGN = 4;
-
-    public final Set features;
-
-    public SPARC(Set features) {
-        super("SPARC", 8, ByteOrder.BIG_ENDIAN, false, allRegisters, LOAD_STORE | STORE_STORE, 1, r31.encoding + FLOAT_REGISTER_COUNT + 1, 8);
-        this.features = features;
-    }
-
-    @Override
-    public boolean canStoreValue(RegisterCategory category, PlatformKind lirKind) {
-        if (!(lirKind instanceof Kind)) {
-            return false;
-        }
-
-        Kind kind = (Kind) lirKind;
-        if (category.equals(CPU)) {
-            switch (kind) {
-                case Boolean:
-                case Byte:
-                case Char:
-                case Short:
-                case Int:
-                case Long:
-                case Object:
-                    return true;
-            }
-        } else if (category.equals(FPUs) && kind.equals(Kind.Float)) {
-            return true;
-        } else if (category.equals(FPUd) && kind.equals(Kind.Double)) {
-            return true;
-        }
-        return false;
-    }
-
-    @Override
-    public PlatformKind getLargestStorableKind(RegisterCategory category) {
-        if (category.equals(CPU)) {
-            return Kind.Long;
-        } else if (category.equals(FPUs)) {
-            return Kind.Double;
-        } else {
-            return Kind.Illegal;
-        }
-    }
-
-    public static int spillSlotSize(TargetDescription td, PlatformKind kind) {
-        return Math.max(td.getSizeInBytes(kind), MEMORY_ACCESS_ALIGN);
-    }
-
-    public static int getDoubleEncoding(int reg) {
-        assert reg < 64 && ((reg & 1) == 0);
-        // ignore v8 assertion for now
-        return (reg & 0x1e) | ((reg & 0x20) >> 5);
-    }
-
-    public static boolean isCPURegister(Register r) {
-        return r.getRegisterCategory().equals(CPU);
-    }
-
-    public static boolean isCPURegister(Register... regs) {
-        for (Register reg : regs) {
-            if (!isCPURegister(reg)) {
-                return false;
-            }
-        }
-        return true;
-    }
-
-    public static boolean isSingleFloatRegister(Register r) {
-        return r.name.startsWith("f");
-    }
-
-    public static boolean isDoubleFloatRegister(Register r) {
-        return r.name.startsWith("d");
-    }
-
-    public Set getFeatures() {
-        return features;
-    }
-
-    public boolean hasFeature(CPUFeature feature) {
-        return features.contains(feature);
-    }
-
-    public enum CPUFeature {
-        VIS1,
-        VIS2,
-        VIS3,
-        CBCOND
-    }
-}
diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.test/src/com/oracle/graal/test/GraalJUnitCore.java
--- a/graal/com.oracle.graal.test/src/com/oracle/graal/test/GraalJUnitCore.java	Thu Jun 04 10:46:23 2015 -0700
+++ b/graal/com.oracle.graal.test/src/com/oracle/graal/test/GraalJUnitCore.java	Thu Jun 04 11:08:12 2015 -0700
@@ -23,6 +23,7 @@
 package com.oracle.graal.test;
 
 import java.io.*;
+import java.lang.reflect.Modifier;
 import java.nio.file.*;
 import java.util.*;
 
@@ -104,7 +105,10 @@
                     }
                 }
                 try {
-                    classes.add(Class.forName(each, false, GraalJUnitCore.class.getClassLoader()));
+                    Class cls = Class.forName(each, false, GraalJUnitCore.class.getClassLoader());
+                    if ((cls.getModifiers() & Modifier.ABSTRACT) == 0) {
+                        classes.add(cls);
+                    }
                 } catch (ClassNotFoundException e) {
                     system.out().println("Could not find class: " + each);
                     Description description = Description.createSuiteDescription(each);
diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.test/src/com/oracle/graal/test/GraalTest.java
--- a/graal/com.oracle.graal.test/src/com/oracle/graal/test/GraalTest.java	Thu Jun 04 10:46:23 2015 -0700
+++ b/graal/com.oracle.graal.test/src/com/oracle/graal/test/GraalTest.java	Thu Jun 04 11:08:12 2015 -0700
@@ -30,9 +30,7 @@
 import org.junit.internal.*;
 
 /**
- * Base class for Graal tests.
- * 

- * This contains common utility methods and classes that are used in tests. + * Base class that contains common utility methods and classes useful in unit tests. */ public class GraalTest { diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.truffle.hotspot.amd64/src/com/oracle/graal/truffle/hotspot/amd64/AMD64OptimizedCallTargetInstrumentationFactory.java --- a/graal/com.oracle.graal.truffle.hotspot.amd64/src/com/oracle/graal/truffle/hotspot/amd64/AMD64OptimizedCallTargetInstrumentationFactory.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.truffle.hotspot.amd64/src/com/oracle/graal/truffle/hotspot/amd64/AMD64OptimizedCallTargetInstrumentationFactory.java Thu Jun 04 11:08:12 2015 -0700 @@ -22,15 +22,15 @@ */ package com.oracle.graal.truffle.hotspot.amd64; -import com.oracle.graal.amd64.*; import com.oracle.graal.asm.*; import com.oracle.graal.asm.amd64.*; -import com.oracle.graal.asm.amd64.AMD64Assembler.ConditionFlag; +import com.oracle.graal.asm.amd64.AMD64Assembler.*; import com.oracle.graal.hotspot.meta.*; import com.oracle.graal.lir.asm.*; import com.oracle.graal.lir.framemap.*; import com.oracle.graal.truffle.*; import com.oracle.graal.truffle.hotspot.*; +import com.oracle.jvmci.amd64.*; import com.oracle.jvmci.code.CallingConvention.Type; import com.oracle.jvmci.code.*; import com.oracle.jvmci.hotspot.*; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.truffle.hotspot.sparc/src/com/oracle/graal/truffle/hotspot/sparc/SPARCOptimizedCallTargetInstumentationFactory.java --- a/graal/com.oracle.graal.truffle.hotspot.sparc/src/com/oracle/graal/truffle/hotspot/sparc/SPARCOptimizedCallTargetInstumentationFactory.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.truffle.hotspot.sparc/src/com/oracle/graal/truffle/hotspot/sparc/SPARCOptimizedCallTargetInstumentationFactory.java Thu Jun 04 11:08:12 2015 -0700 @@ -26,13 +26,13 @@ import static com.oracle.graal.asm.sparc.SPARCAssembler.BranchPredict.*; import static com.oracle.graal.asm.sparc.SPARCAssembler.CC.*; import static com.oracle.graal.asm.sparc.SPARCAssembler.ConditionFlag.*; -import static com.oracle.graal.sparc.SPARC.CPUFeature.*; import static com.oracle.jvmci.code.CallingConvention.Type.*; import static com.oracle.jvmci.meta.Kind.*; +import static com.oracle.jvmci.sparc.SPARC.CPUFeature.*; import com.oracle.graal.asm.*; import com.oracle.graal.asm.sparc.*; -import com.oracle.graal.asm.sparc.SPARCMacroAssembler.ScratchRegister; +import com.oracle.graal.asm.sparc.SPARCMacroAssembler.*; import com.oracle.graal.hotspot.meta.*; import com.oracle.graal.lir.asm.*; import com.oracle.graal.lir.framemap.*; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.truffle.hotspot/src/com/oracle/graal/truffle/hotspot/OptimizedCallTargetInstrumentation.java --- a/graal/com.oracle.graal.truffle.hotspot/src/com/oracle/graal/truffle/hotspot/OptimizedCallTargetInstrumentation.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.truffle.hotspot/src/com/oracle/graal/truffle/hotspot/OptimizedCallTargetInstrumentation.java Thu Jun 04 11:08:12 2015 -0700 @@ -25,6 +25,7 @@ import com.oracle.jvmci.code.CodeCacheProvider; import com.oracle.jvmci.code.CompilationResult; import com.oracle.jvmci.code.ForeignCallsProvider; + import java.lang.reflect.*; import com.oracle.jvmci.code.CompilationResult.Mark; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.truffle.hotspot/src/com/oracle/graal/truffle/hotspot/nfi/NativeCallStubGraphBuilder.java --- a/graal/com.oracle.graal.truffle.hotspot/src/com/oracle/graal/truffle/hotspot/nfi/NativeCallStubGraphBuilder.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.truffle.hotspot/src/com/oracle/graal/truffle/hotspot/nfi/NativeCallStubGraphBuilder.java Thu Jun 04 11:08:12 2015 -0700 @@ -90,13 +90,14 @@ throw new IllegalArgumentException("Return type not supported: " + returnType.getName()); } ResolvedJavaType type = providers.getMetaAccess().lookupJavaType(callNode.getKind().toBoxedJavaClass()); - boxedResult = g.unique(new BoxNode(callNode, type, callNode.getKind())); + boxedResult = g.add(new BoxNode(callNode, type, callNode.getKind())); } else { - boxedResult = g.unique(new BoxNode(ConstantNode.forLong(0, g), providers.getMetaAccess().lookupJavaType(Long.class), Kind.Long)); + boxedResult = g.add(new BoxNode(ConstantNode.forLong(0, g), providers.getMetaAccess().lookupJavaType(Long.class), Kind.Long)); } + callNode.setNext(boxedResult); ReturnNode returnNode = g.add(new ReturnNode(boxedResult)); - callNode.setNext(returnNode); + boxedResult.setNext(returnNode); return g; } catch (NoSuchMethodException e) { throw JVMCIError.shouldNotReachHere("Call Stub method not found"); diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/LoopNodeFactory.java --- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/LoopNodeFactory.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/LoopNodeFactory.java Thu Jun 04 11:08:12 2015 -0700 @@ -22,9 +22,10 @@ */ package com.oracle.graal.truffle; +import com.oracle.jvmci.service.*; import com.oracle.truffle.api.nodes.*; -public interface LoopNodeFactory extends PrioritizedServiceProvider { +public interface LoopNodeFactory extends PrioritizedServiceProvider, Service { LoopNode create(RepeatingNode repeatingNode); diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/PartialEvaluator.java diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCompiler.java --- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCompiler.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCompiler.java Thu Jun 04 11:08:12 2015 -0700 @@ -198,9 +198,6 @@ a.getAssumption().registerInstalledCode(installedCode); } - if (Debug.isLogEnabled()) { - Debug.log(providers.getCodeCache().disassemble(result, installedCode)); - } return result; } diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.jvmci.amd64/src/com/oracle/jvmci/amd64/AMD64.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.jvmci.amd64/src/com/oracle/jvmci/amd64/AMD64.java Thu Jun 04 11:08:12 2015 -0700 @@ -0,0 +1,207 @@ +/* + * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.jvmci.amd64; + +import com.oracle.jvmci.code.Architecture; +import com.oracle.jvmci.code.Register; +import com.oracle.jvmci.meta.Kind; +import com.oracle.jvmci.meta.PlatformKind; +import static com.oracle.jvmci.code.MemoryBarriers.*; +import static com.oracle.jvmci.code.Register.*; + +import java.nio.*; +import java.util.*; + +import com.oracle.jvmci.code.Register.RegisterCategory; + +/** + * Represents the AMD64 architecture. + */ +public class AMD64 extends Architecture { + + public static final RegisterCategory CPU = new RegisterCategory("CPU"); + + // @formatter:off + + // General purpose CPU registers + public static final Register rax = new Register(0, 0, "rax", CPU); + public static final Register rcx = new Register(1, 1, "rcx", CPU); + public static final Register rdx = new Register(2, 2, "rdx", CPU); + public static final Register rbx = new Register(3, 3, "rbx", CPU); + public static final Register rsp = new Register(4, 4, "rsp", CPU); + public static final Register rbp = new Register(5, 5, "rbp", CPU); + public static final Register rsi = new Register(6, 6, "rsi", CPU); + public static final Register rdi = new Register(7, 7, "rdi", CPU); + + public static final Register r8 = new Register(8, 8, "r8", CPU); + public static final Register r9 = new Register(9, 9, "r9", CPU); + public static final Register r10 = new Register(10, 10, "r10", CPU); + public static final Register r11 = new Register(11, 11, "r11", CPU); + public static final Register r12 = new Register(12, 12, "r12", CPU); + public static final Register r13 = new Register(13, 13, "r13", CPU); + public static final Register r14 = new Register(14, 14, "r14", CPU); + public static final Register r15 = new Register(15, 15, "r15", CPU); + + public static final Register[] cpuRegisters = { + rax, rcx, rdx, rbx, rsp, rbp, rsi, rdi, + r8, r9, r10, r11, r12, r13, r14, r15 + }; + + private static final int XMM_REFERENCE_MAP_SHIFT = 2; + + public static final RegisterCategory XMM = new RegisterCategory("XMM", cpuRegisters.length, XMM_REFERENCE_MAP_SHIFT); + + // XMM registers + public static final Register xmm0 = new Register(16, 0, "xmm0", XMM); + public static final Register xmm1 = new Register(17, 1, "xmm1", XMM); + public static final Register xmm2 = new Register(18, 2, "xmm2", XMM); + public static final Register xmm3 = new Register(19, 3, "xmm3", XMM); + public static final Register xmm4 = new Register(20, 4, "xmm4", XMM); + public static final Register xmm5 = new Register(21, 5, "xmm5", XMM); + public static final Register xmm6 = new Register(22, 6, "xmm6", XMM); + public static final Register xmm7 = new Register(23, 7, "xmm7", XMM); + + public static final Register xmm8 = new Register(24, 8, "xmm8", XMM); + public static final Register xmm9 = new Register(25, 9, "xmm9", XMM); + public static final Register xmm10 = new Register(26, 10, "xmm10", XMM); + public static final Register xmm11 = new Register(27, 11, "xmm11", XMM); + public static final Register xmm12 = new Register(28, 12, "xmm12", XMM); + public static final Register xmm13 = new Register(29, 13, "xmm13", XMM); + public static final Register xmm14 = new Register(30, 14, "xmm14", XMM); + public static final Register xmm15 = new Register(31, 15, "xmm15", XMM); + + public static final Register[] xmmRegisters = { + xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, + xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15 + }; + + public static final Register[] cpuxmmRegisters = { + rax, rcx, rdx, rbx, rsp, rbp, rsi, rdi, + r8, r9, r10, r11, r12, r13, r14, r15, + xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, + xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15 + }; + + /** + * Register used to construct an instruction-relative address. + */ + public static final Register rip = new Register(32, -1, "rip", SPECIAL); + + public static final Register[] allRegisters = { + rax, rcx, rdx, rbx, rsp, rbp, rsi, rdi, + r8, r9, r10, r11, r12, r13, r14, r15, + xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, + xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15, + rip + }; + + // @formatter:on + + /** + * Basic set of CPU features mirroring what is returned from the cpuid instruction. + */ + public static enum CPUFeature { + SSE, + SSE2, + SSE3, + SSE4a, + SSE4_1, + SSE4_2, + SSSE3, + POPCNT, + LZCNT, + AVX, + AVX2, + ERMS, + AMD_3DNOW_PREFETCH, + AES, + BMI1 + } + + private final EnumSet features; + + /** + * Set of flags to control code emission. + */ + public static enum Flag { + UseCountLeadingZerosInstruction, + UseCountTrailingZerosInstruction + } + + private final EnumSet flags; + + public AMD64(EnumSet features, EnumSet flags) { + super("AMD64", 8, ByteOrder.LITTLE_ENDIAN, true, allRegisters, LOAD_STORE | STORE_STORE, 1, cpuRegisters.length + (xmmRegisters.length << XMM_REFERENCE_MAP_SHIFT), 8); + this.features = features; + this.flags = flags; + assert features.contains(CPUFeature.SSE2) : "minimum config for x64"; + } + + public EnumSet getFeatures() { + return features; + } + + public EnumSet getFlags() { + return flags; + } + + @Override + public boolean canStoreValue(RegisterCategory category, PlatformKind platformKind) { + if (!(platformKind instanceof Kind)) { + return false; + } + + Kind kind = (Kind) platformKind; + if (category.equals(CPU)) { + switch (kind) { + case Boolean: + case Byte: + case Char: + case Short: + case Int: + case Long: + case Object: + return true; + } + } else if (category.equals(XMM)) { + switch (kind) { + case Float: + case Double: + return true; + } + } + + return false; + } + + @Override + public PlatformKind getLargestStorableKind(RegisterCategory category) { + if (category.equals(CPU)) { + return Kind.Long; + } else if (category.equals(XMM)) { + return Kind.Double; + } else { + return Kind.Illegal; + } + } +} diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.jvmci.code/src/com/oracle/jvmci/code/CodeCacheProvider.java --- a/graal/com.oracle.jvmci.code/src/com/oracle/jvmci/code/CodeCacheProvider.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.jvmci.code/src/com/oracle/jvmci/code/CodeCacheProvider.java Thu Jun 04 11:08:12 2015 -0700 @@ -22,9 +22,11 @@ */ package com.oracle.jvmci.code; -import com.oracle.jvmci.meta.*; +import com.oracle.jvmci.code.CompilationResult.Call; import com.oracle.jvmci.code.CompilationResult.DataPatch; +import com.oracle.jvmci.code.CompilationResult.Mark; import com.oracle.jvmci.code.DataSection.Data; +import com.oracle.jvmci.meta.*; /** * Access to code cache related details and requirements. @@ -54,16 +56,18 @@ InstalledCode setDefaultMethod(ResolvedJavaMethod method, CompilationResult compResult); /** - * Returns a disassembly of some compiled code. - * - * @param compResult some compiled code - * @param installedCode the result of installing the code in {@code compResult} or null if the - * code has not yet been installed - * - * @return a disassembly. This will be of length 0 if the runtime does not support - * disassembling. + * Gets a name for a {@link Mark} mark. */ - String disassemble(CompilationResult compResult, InstalledCode installedCode); + default String getMarkName(Mark mark) { + return String.valueOf(mark.id); + } + + /** + * Gets a name for the {@linkplain Call#target target} of a {@link Call}. + */ + default String getTargetName(Call call) { + return String.valueOf(call.target); + } /** * Gets the register configuration to use when compiling a given method. diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.jvmci.code/src/com/oracle/jvmci/code/DisassemblerProvider.java --- a/graal/com.oracle.jvmci.code/src/com/oracle/jvmci/code/DisassemblerProvider.java Thu Jun 04 10:46:23 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.jvmci.code; - -/** - * Interface providing capability for disassembling machine code. - */ -public interface DisassemblerProvider { - - /** - * Gets a textual disassembly of some given installed code. - * - * @return a non-zero length string containing a disassembly of {@code code} or null if - * {@code code} is {@link InstalledCode#isValid() invalid} or it could not be - * disassembled for some other reason - */ - String disassemble(InstalledCode code); -} diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.jvmci.hotspot.amd64/src/com/oracle/jvmci/hotspot/amd64/AMD64HotSpotJVMCIBackendFactory.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.jvmci.hotspot.amd64/src/com/oracle/jvmci/hotspot/amd64/AMD64HotSpotJVMCIBackendFactory.java Thu Jun 04 11:08:12 2015 -0700 @@ -0,0 +1,169 @@ +/* + * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.jvmci.hotspot.amd64; + +import static com.oracle.jvmci.hotspot.InitTimer.*; + +import java.util.*; + +import com.oracle.jvmci.amd64.*; +import com.oracle.jvmci.code.*; +import com.oracle.jvmci.hotspot.*; +import com.oracle.jvmci.meta.*; +import com.oracle.jvmci.runtime.*; +import com.oracle.jvmci.service.*; + +@ServiceProvider(HotSpotJVMCIBackendFactory.class) +public class AMD64HotSpotJVMCIBackendFactory implements HotSpotJVMCIBackendFactory { + + protected Architecture createArchitecture(HotSpotVMConfig config) { + return new AMD64(computeFeatures(config), computeFlags(config)); + } + + protected EnumSet computeFeatures(HotSpotVMConfig config) { + // Configure the feature set using the HotSpot flag settings. + EnumSet features = EnumSet.noneOf(AMD64.CPUFeature.class); + assert config.useSSE >= 2 : "minimum config for x64"; + features.add(AMD64.CPUFeature.SSE); + features.add(AMD64.CPUFeature.SSE2); + if ((config.x86CPUFeatures & config.cpuSSE3) != 0) { + features.add(AMD64.CPUFeature.SSE3); + } + if ((config.x86CPUFeatures & config.cpuSSSE3) != 0) { + features.add(AMD64.CPUFeature.SSSE3); + } + if ((config.x86CPUFeatures & config.cpuSSE4A) != 0) { + features.add(AMD64.CPUFeature.SSE4a); + } + if ((config.x86CPUFeatures & config.cpuSSE41) != 0) { + features.add(AMD64.CPUFeature.SSE4_1); + } + if ((config.x86CPUFeatures & config.cpuSSE42) != 0) { + features.add(AMD64.CPUFeature.SSE4_2); + } + if ((config.x86CPUFeatures & config.cpuAVX) != 0) { + features.add(AMD64.CPUFeature.AVX); + } + if ((config.x86CPUFeatures & config.cpuAVX2) != 0) { + features.add(AMD64.CPUFeature.AVX2); + } + if ((config.x86CPUFeatures & config.cpuERMS) != 0) { + features.add(AMD64.CPUFeature.ERMS); + } + if ((config.x86CPUFeatures & config.cpuLZCNT) != 0) { + features.add(AMD64.CPUFeature.LZCNT); + } + if ((config.x86CPUFeatures & config.cpuPOPCNT) != 0) { + features.add(AMD64.CPUFeature.POPCNT); + } + if ((config.x86CPUFeatures & config.cpuAES) != 0) { + features.add(AMD64.CPUFeature.AES); + } + if ((config.x86CPUFeatures & config.cpu3DNOWPREFETCH) != 0) { + features.add(AMD64.CPUFeature.AMD_3DNOW_PREFETCH); + } + if ((config.x86CPUFeatures & config.cpuBMI1) != 0) { + features.add(AMD64.CPUFeature.BMI1); + } + return features; + } + + protected EnumSet computeFlags(HotSpotVMConfig config) { + EnumSet flags = EnumSet.noneOf(AMD64.Flag.class); + if (config.useCountLeadingZerosInstruction) { + flags.add(AMD64.Flag.UseCountLeadingZerosInstruction); + } + if (config.useCountTrailingZerosInstruction) { + flags.add(AMD64.Flag.UseCountTrailingZerosInstruction); + } + return flags; + } + + protected TargetDescription createTarget(HotSpotVMConfig config) { + final int stackFrameAlignment = 16; + final int implicitNullCheckLimit = 4096; + final boolean inlineObjects = true; + return new HotSpotTargetDescription(createArchitecture(config), true, stackFrameAlignment, implicitNullCheckLimit, inlineObjects); + } + + protected HotSpotConstantReflectionProvider createConstantReflection(HotSpotJVMCIRuntimeProvider runtime) { + return new HotSpotConstantReflectionProvider(runtime); + } + + protected RegisterConfig createRegisterConfig(HotSpotJVMCIRuntimeProvider runtime, TargetDescription target) { + return new AMD64HotSpotRegisterConfig(target.arch, runtime.getConfig()); + } + + protected HotSpotCodeCacheProvider createCodeCache(HotSpotJVMCIRuntimeProvider runtime, TargetDescription target, RegisterConfig regConfig) { + return new HotSpotCodeCacheProvider(runtime, runtime.getConfig(), target, regConfig); + } + + protected HotSpotMetaAccessProvider createMetaAccess(HotSpotJVMCIRuntimeProvider runtime) { + return new HotSpotMetaAccessProvider(runtime); + } + + public String getArchitecture() { + return "AMD64"; + } + + @Override + public String toString() { + return getJVMCIRuntimeName() + ":" + getArchitecture(); + } + + public JVMCIBackend createJVMCIBackend(HotSpotJVMCIRuntimeProvider runtime, JVMCIBackend host) { + + assert host == null; + TargetDescription target = createTarget(runtime.getConfig()); + + RegisterConfig regConfig; + HotSpotCodeCacheProvider codeCache; + ConstantReflectionProvider constantReflection; + HotSpotMetaAccessProvider metaAccess; + try (InitTimer t = timer("create providers")) { + try (InitTimer rt = timer("create MetaAccess provider")) { + metaAccess = createMetaAccess(runtime); + } + try (InitTimer rt = timer("create RegisterConfig")) { + regConfig = createRegisterConfig(runtime, target); + } + try (InitTimer rt = timer("create CodeCache provider")) { + codeCache = createCodeCache(runtime, target, regConfig); + } + try (InitTimer rt = timer("create ConstantReflection provider")) { + constantReflection = createConstantReflection(runtime); + } + } + try (InitTimer rt = timer("instantiate backend")) { + return createBackend(metaAccess, codeCache, constantReflection); + } + } + + protected JVMCIBackend createBackend(HotSpotMetaAccessProvider metaAccess, HotSpotCodeCacheProvider codeCache, ConstantReflectionProvider constantReflection) { + return new JVMCIBackend(metaAccess, codeCache, constantReflection); + } + + public String getJVMCIRuntimeName() { + return "basic"; + } +} diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.jvmci.hotspot.amd64/src/com/oracle/jvmci/hotspot/amd64/AMD64HotSpotRegisterConfig.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.jvmci.hotspot.amd64/src/com/oracle/jvmci/hotspot/amd64/AMD64HotSpotRegisterConfig.java Thu Jun 04 11:08:12 2015 -0700 @@ -0,0 +1,268 @@ +/* + * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.jvmci.hotspot.amd64; + +import com.oracle.jvmci.amd64.*; +import com.oracle.jvmci.code.Register; +import com.oracle.jvmci.code.RegisterConfig; +import com.oracle.jvmci.code.TargetDescription; +import com.oracle.jvmci.code.CallingConvention; +import com.oracle.jvmci.code.StackSlot; +import com.oracle.jvmci.code.RegisterAttributes; +import com.oracle.jvmci.code.CalleeSaveLayout; +import com.oracle.jvmci.code.Architecture; +import com.oracle.jvmci.meta.JavaType; +import com.oracle.jvmci.meta.Value; +import com.oracle.jvmci.meta.PlatformKind; +import com.oracle.jvmci.meta.AllocatableValue; +import com.oracle.jvmci.meta.Kind; + +import static com.oracle.jvmci.amd64.AMD64.*; + +import java.util.*; + +import com.oracle.jvmci.code.CallingConvention.Type; +import com.oracle.jvmci.common.*; +import com.oracle.jvmci.hotspot.*; + +public class AMD64HotSpotRegisterConfig implements RegisterConfig { + + private final Architecture architecture; + + private final Register[] allocatable; + + private final int maxFrameSize; + + /** + * The caller saved registers always include all parameter registers. + */ + private final Register[] callerSaved; + + private final boolean allAllocatableAreCallerSaved; + + private final RegisterAttributes[] attributesMap; + + public int getMaximumFrameSize() { + return maxFrameSize; + } + + @Override + public Register[] getAllocatableRegisters() { + return allocatable.clone(); + } + + public Register[] filterAllocatableRegisters(PlatformKind kind, Register[] registers) { + ArrayList list = new ArrayList<>(); + for (Register reg : registers) { + if (architecture.canStoreValue(reg.getRegisterCategory(), kind)) { + list.add(reg); + } + } + + Register[] ret = list.toArray(new Register[list.size()]); + return ret; + } + + @Override + public RegisterAttributes[] getAttributesMap() { + return attributesMap.clone(); + } + + private final Register[] javaGeneralParameterRegisters; + private final Register[] nativeGeneralParameterRegisters; + private final Register[] xmmParameterRegisters = {xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7}; + + /* + * Some ABIs (e.g. Windows) require a so-called "home space", that is a save area on the stack + * to store the argument registers + */ + private final boolean needsNativeStackHomeSpace; + + private final CalleeSaveLayout csl; + + private static Register[] initAllocatable(boolean reserveForHeapBase) { + Register[] registers = null; + // @formatter:off + if (reserveForHeapBase) { + registers = new Register[] { + rax, rbx, rcx, rdx, /*rsp,*/ rbp, rsi, rdi, r8, r9, r10, r11, /*r12,*/ r13, r14, /*r15, */ + xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, + xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15 + }; + } else { + registers = new Register[] { + rax, rbx, rcx, rdx, /*rsp,*/ rbp, rsi, rdi, r8, r9, r10, r11, r12, r13, r14, /*r15, */ + xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, + xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15 + }; + } + // @formatter:on + return registers; + } + + public AMD64HotSpotRegisterConfig(Architecture architecture, HotSpotVMConfig config) { + this(architecture, config, initAllocatable(config.useCompressedOops)); + assert callerSaved.length >= allocatable.length; + } + + public AMD64HotSpotRegisterConfig(Architecture architecture, HotSpotVMConfig config, Register[] allocatable) { + this.architecture = architecture; + this.maxFrameSize = config.maxFrameSize; + + if (config.windowsOs) { + javaGeneralParameterRegisters = new Register[]{rdx, r8, r9, rdi, rsi, rcx}; + nativeGeneralParameterRegisters = new Register[]{rcx, rdx, r8, r9}; + this.needsNativeStackHomeSpace = true; + } else { + javaGeneralParameterRegisters = new Register[]{rsi, rdx, rcx, r8, r9, rdi}; + nativeGeneralParameterRegisters = new Register[]{rdi, rsi, rdx, rcx, r8, r9}; + this.needsNativeStackHomeSpace = false; + } + + csl = null; + this.allocatable = allocatable.clone(); + Set callerSaveSet = new HashSet<>(); + Collections.addAll(callerSaveSet, allocatable); + Collections.addAll(callerSaveSet, xmmParameterRegisters); + Collections.addAll(callerSaveSet, javaGeneralParameterRegisters); + Collections.addAll(callerSaveSet, nativeGeneralParameterRegisters); + callerSaved = callerSaveSet.toArray(new Register[callerSaveSet.size()]); + + allAllocatableAreCallerSaved = true; + attributesMap = RegisterAttributes.createMap(this, AMD64.allRegisters); + } + + @Override + public Register[] getCallerSaveRegisters() { + return callerSaved; + } + + @Override + public boolean areAllAllocatableRegistersCallerSaved() { + return allAllocatableAreCallerSaved; + } + + @Override + public Register getRegisterForRole(int index) { + throw new UnsupportedOperationException(); + } + + @Override + public CallingConvention getCallingConvention(Type type, JavaType returnType, JavaType[] parameterTypes, TargetDescription target, boolean stackOnly) { + if (type == Type.NativeCall) { + return callingConvention(nativeGeneralParameterRegisters, returnType, parameterTypes, type, target, stackOnly); + } + // On x64, parameter locations are the same whether viewed + // from the caller or callee perspective + return callingConvention(javaGeneralParameterRegisters, returnType, parameterTypes, type, target, stackOnly); + } + + public Register[] getCallingConventionRegisters(Type type, Kind kind) { + if (architecture.canStoreValue(XMM, kind)) { + return xmmParameterRegisters; + } + assert architecture.canStoreValue(CPU, kind); + return type == Type.NativeCall ? nativeGeneralParameterRegisters : javaGeneralParameterRegisters; + } + + private CallingConvention callingConvention(Register[] generalParameterRegisters, JavaType returnType, JavaType[] parameterTypes, Type type, TargetDescription target, boolean stackOnly) { + AllocatableValue[] locations = new AllocatableValue[parameterTypes.length]; + + int currentGeneral = 0; + int currentXMM = 0; + int currentStackOffset = type == Type.NativeCall && needsNativeStackHomeSpace ? generalParameterRegisters.length * target.wordSize : 0; + + for (int i = 0; i < parameterTypes.length; i++) { + final Kind kind = parameterTypes[i].getKind(); + + switch (kind) { + case Byte: + case Boolean: + case Short: + case Char: + case Int: + case Long: + case Object: + if (!stackOnly && currentGeneral < generalParameterRegisters.length) { + Register register = generalParameterRegisters[currentGeneral++]; + locations[i] = register.asValue(target.getLIRKind(kind)); + } + break; + case Float: + case Double: + if (!stackOnly && currentXMM < xmmParameterRegisters.length) { + Register register = xmmParameterRegisters[currentXMM++]; + locations[i] = register.asValue(target.getLIRKind(kind)); + } + break; + default: + throw JVMCIError.shouldNotReachHere(); + } + + if (locations[i] == null) { + locations[i] = StackSlot.get(target.getLIRKind(kind.getStackKind()), currentStackOffset, !type.out); + currentStackOffset += Math.max(target.getSizeInBytes(kind), target.wordSize); + } + } + + Kind returnKind = returnType == null ? Kind.Void : returnType.getKind(); + AllocatableValue returnLocation = returnKind == Kind.Void ? Value.ILLEGAL : getReturnRegister(returnKind).asValue(target.getLIRKind(returnKind.getStackKind())); + return new CallingConvention(currentStackOffset, returnLocation, locations); + } + + @Override + public Register getReturnRegister(Kind kind) { + switch (kind) { + case Boolean: + case Byte: + case Char: + case Short: + case Int: + case Long: + case Object: + return rax; + case Float: + case Double: + return xmm0; + case Void: + case Illegal: + return null; + default: + throw new UnsupportedOperationException("no return register for type " + kind); + } + } + + @Override + public Register getFrameRegister() { + return rsp; + } + + public CalleeSaveLayout getCalleeSaveLayout() { + return csl; + } + + @Override + public String toString() { + return String.format("Allocatable: " + Arrays.toString(getAllocatableRegisters()) + "%n" + "CallerSave: " + Arrays.toString(getCallerSaveRegisters()) + "%n"); + } +} diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.jvmci.hotspot.sparc/src/com/oracle/jvmci/hotspot/sparc/SPARCHotSpotJVMCIBackendFactory.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.jvmci.hotspot.sparc/src/com/oracle/jvmci/hotspot/sparc/SPARCHotSpotJVMCIBackendFactory.java Thu Jun 04 11:08:12 2015 -0700 @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.jvmci.hotspot.sparc; + +import static com.oracle.jvmci.hotspot.InitTimer.*; + +import java.util.*; + +import com.oracle.jvmci.code.*; +import com.oracle.jvmci.hotspot.*; +import com.oracle.jvmci.runtime.*; +import com.oracle.jvmci.service.*; +import com.oracle.jvmci.sparc.*; +import com.oracle.jvmci.sparc.SPARC.CPUFeature; + +@ServiceProvider(HotSpotJVMCIBackendFactory.class) +public class SPARCHotSpotJVMCIBackendFactory implements HotSpotJVMCIBackendFactory { + + protected Architecture createArchitecture(HotSpotVMConfig config) { + return new SPARC(computeFeatures(config)); + } + + protected TargetDescription createTarget(HotSpotVMConfig config) { + final int stackFrameAlignment = 16; + final int implicitNullCheckLimit = 4096; + final boolean inlineObjects = true; + return new HotSpotTargetDescription(createArchitecture(config), true, stackFrameAlignment, implicitNullCheckLimit, inlineObjects); + } + + protected HotSpotCodeCacheProvider createCodeCache(HotSpotJVMCIRuntimeProvider runtime, TargetDescription target, RegisterConfig regConfig) { + return new HotSpotCodeCacheProvider(runtime, runtime.getConfig(), target, regConfig); + } + + protected EnumSet computeFeatures(HotSpotVMConfig config) { + EnumSet features = EnumSet.noneOf(CPUFeature.class); + if ((config.sparcFeatures & config.vis1Instructions) != 0) { + features.add(CPUFeature.VIS1); + } + if ((config.sparcFeatures & config.vis2Instructions) != 0) { + features.add(CPUFeature.VIS2); + } + if ((config.sparcFeatures & config.vis3Instructions) != 0) { + features.add(CPUFeature.VIS3); + } + if ((config.sparcFeatures & config.cbcondInstructions) != 0) { + features.add(CPUFeature.CBCOND); + } + return features; + } + + public String getArchitecture() { + return "SPARC"; + } + + @Override + public String toString() { + return getJVMCIRuntimeName() + ":" + getArchitecture(); + } + + public JVMCIBackend createJVMCIBackend(HotSpotJVMCIRuntimeProvider runtime, JVMCIBackend host) { + assert host == null; + TargetDescription target = createTarget(runtime.getConfig()); + + HotSpotMetaAccessProvider metaAccess = new HotSpotMetaAccessProvider(runtime); + RegisterConfig regConfig = new SPARCHotSpotRegisterConfig(target, runtime.getConfig()); + HotSpotCodeCacheProvider codeCache = createCodeCache(runtime, target, regConfig); + HotSpotConstantReflectionProvider constantReflection = new HotSpotConstantReflectionProvider(runtime); + try (InitTimer rt = timer("instantiate backend")) { + return createBackend(metaAccess, codeCache, constantReflection); + } + } + + protected JVMCIBackend createBackend(HotSpotMetaAccessProvider metaAccess, HotSpotCodeCacheProvider codeCache, HotSpotConstantReflectionProvider constantReflection) { + return new JVMCIBackend(metaAccess, codeCache, constantReflection); + } + + public String getJVMCIRuntimeName() { + return "basic"; + } +} diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.jvmci.hotspot.sparc/src/com/oracle/jvmci/hotspot/sparc/SPARCHotSpotRegisterConfig.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.jvmci.hotspot.sparc/src/com/oracle/jvmci/hotspot/sparc/SPARCHotSpotRegisterConfig.java Thu Jun 04 11:08:12 2015 -0700 @@ -0,0 +1,304 @@ +/* + * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.jvmci.hotspot.sparc; + +import com.oracle.jvmci.code.Architecture; +import com.oracle.jvmci.code.TargetDescription; +import com.oracle.jvmci.code.CallingConvention; +import com.oracle.jvmci.code.CalleeSaveLayout; +import com.oracle.jvmci.code.RegisterAttributes; +import com.oracle.jvmci.code.StackSlot; +import com.oracle.jvmci.code.RegisterConfig; +import com.oracle.jvmci.code.Register; +import com.oracle.jvmci.meta.Kind; +import com.oracle.jvmci.meta.JavaType; +import com.oracle.jvmci.meta.PlatformKind; +import com.oracle.jvmci.meta.Value; +import com.oracle.jvmci.meta.AllocatableValue; +import com.oracle.jvmci.sparc.*; + +import static com.oracle.jvmci.sparc.SPARC.*; + +import java.util.*; + +import com.oracle.jvmci.code.CallingConvention.Type; +import com.oracle.jvmci.common.*; +import com.oracle.jvmci.hotspot.*; + +public class SPARCHotSpotRegisterConfig implements RegisterConfig { + + private final Architecture architecture; + + private final Register[] allocatable; + + private final RegisterAttributes[] attributesMap; + + @Override + public Register[] getAllocatableRegisters() { + return allocatable.clone(); + } + + public Register[] filterAllocatableRegisters(PlatformKind kind, Register[] registers) { + ArrayList list = new ArrayList<>(); + for (Register reg : registers) { + if (architecture.canStoreValue(reg.getRegisterCategory(), kind)) { + // Special treatment for double precision + // TODO: This is wasteful it uses only half of the registers as float. + if (kind == Kind.Double) { + if (reg.name.startsWith("d")) { + list.add(reg); + } + } else if (kind == Kind.Float) { + if (reg.name.startsWith("f")) { + list.add(reg); + } + } else { + list.add(reg); + } + } + } + + Register[] ret = list.toArray(new Register[list.size()]); + return ret; + } + + @Override + public RegisterAttributes[] getAttributesMap() { + return attributesMap.clone(); + } + + private final Register[] cpuCallerParameterRegisters = {o0, o1, o2, o3, o4, o5}; + private final Register[] cpuCalleeParameterRegisters = {i0, i1, i2, i3, i4, i5}; + + private final Register[] fpuParameterRegisters = {f0, f1, f2, f3, f4, f5, f6, f7}; + private final Register[] fpuDoubleParameterRegisters = {d0, null, d2, null, d4, null, d6, null}; + // @formatter:off + private final Register[] callerSaveRegisters = + {g1, g2, g3, g4, g5, g6, g7, + o0, o1, o2, o3, o4, o5, o7, + f0, f1, f2, f3, f4, f5, f6, f7, + f8, f9, f10, f11, f12, f13, f14, f15, + f16, f17, f18, f19, f20, f21, f22, f23, + f24, f25, f26, f27, f28, f29, f30, f31, + d32, d34, d36, d38, d40, d42, d44, d46, + d48, d50, d52, d54, d56, d58, d60, d62}; + // @formatter:on + + /** + * Registers saved by the callee. This lists all L and I registers which are saved in the + * register window. + */ + private final Register[] calleeSaveRegisters = {l0, l1, l2, l3, l4, l5, l6, l7, i0, i1, i2, i3, i4, i5, i6, i7}; + + private final CalleeSaveLayout csl; + + private static Register[] initAllocatable(boolean reserveForHeapBase) { + Register[] registers = null; + if (reserveForHeapBase) { + // @formatter:off + registers = new Register[]{ + // TODO this is not complete + // o7 cannot be used as register because it is always overwritten on call + // and the current register handler would ignore this fact if the called + // method still does not modify registers, in fact o7 is modified by the Call instruction + // There would be some extra handlin necessary to be able to handle the o7 properly for local usage + o0, o1, o2, o3, o4, o5, /*o6, o7,*/ + l0, l1, l2, l3, l4, l5, l6, l7, + i0, i1, i2, i3, i4, i5, /*i6,*/ /*i7,*/ + //f0, f1, f2, f3, f4, f5, f6, f7, + f8, f9, f10, f11, f12, f13, f14, f15, + f16, f17, f18, f19, f20, f21, f22, f23, + f24, f25, f26, f27, f28, f29, f30, f31, + d32, d34, d36, d38, d40, d42, d44, d46, + d48, d50, d52, d54, d56, d58, d60, d62 + }; + // @formatter:on + } else { + // @formatter:off + registers = new Register[]{ + // TODO this is not complete + o0, o1, o2, o3, o4, o5, /*o6, o7,*/ + l0, l1, l2, l3, l4, l5, l6, l7, + i0, i1, i2, i3, i4, i5, /*i6,*/ /*i7,*/ +// f0, f1, f2, f3, f4, f5, f6, f7 + f8, f9, f10, f11, f12, f13, f14, f15, + f16, f17, f18, f19, f20, f21, f22, f23, + f24, f25, f26, f27, f28, f29, f30, f31, + d32, d34, d36, d38, d40, d42, d44, d46, + d48, d50, d52, d54, d56, d58, d60, d62 + }; + // @formatter:on + } + + return registers; + } + + public SPARCHotSpotRegisterConfig(TargetDescription target, HotSpotVMConfig config) { + this(target, initAllocatable(config.useCompressedOops)); + } + + public SPARCHotSpotRegisterConfig(TargetDescription target, Register[] allocatable) { + this.architecture = target.arch; + + csl = new CalleeSaveLayout(target, -1, -1, target.arch.getWordSize(), calleeSaveRegisters); + this.allocatable = allocatable.clone(); + attributesMap = RegisterAttributes.createMap(this, SPARC.allRegisters); + } + + @Override + public Register[] getCallerSaveRegisters() { + return callerSaveRegisters; + } + + @Override + public boolean areAllAllocatableRegistersCallerSaved() { + return false; + } + + @Override + public Register getRegisterForRole(int index) { + throw new UnsupportedOperationException(); + } + + @Override + public CallingConvention getCallingConvention(Type type, JavaType returnType, JavaType[] parameterTypes, TargetDescription target, boolean stackOnly) { + if (type == Type.JavaCall || type == Type.NativeCall) { + return callingConvention(cpuCallerParameterRegisters, returnType, parameterTypes, type, target, stackOnly); + } + if (type == Type.JavaCallee) { + return callingConvention(cpuCalleeParameterRegisters, returnType, parameterTypes, type, target, stackOnly); + } + throw JVMCIError.shouldNotReachHere(); + } + + public Register[] getCallingConventionRegisters(Type type, Kind kind) { + if (architecture.canStoreValue(FPUs, kind) || architecture.canStoreValue(FPUd, kind)) { + return fpuParameterRegisters; + } + assert architecture.canStoreValue(CPU, kind); + return type == Type.JavaCallee ? cpuCalleeParameterRegisters : cpuCallerParameterRegisters; + } + + private CallingConvention callingConvention(Register[] generalParameterRegisters, JavaType returnType, JavaType[] parameterTypes, Type type, TargetDescription target, boolean stackOnly) { + AllocatableValue[] locations = new AllocatableValue[parameterTypes.length]; + + int currentGeneral = 0; + int currentFloating = 0; + int currentStackOffset = 0; + + for (int i = 0; i < parameterTypes.length; i++) { + final Kind kind = parameterTypes[i].getKind(); + + switch (kind) { + case Byte: + case Boolean: + case Short: + case Char: + case Int: + case Long: + case Object: + if (!stackOnly && currentGeneral < generalParameterRegisters.length) { + Register register = generalParameterRegisters[currentGeneral++]; + locations[i] = register.asValue(target.getLIRKind(kind)); + } + break; + case Double: + if (!stackOnly && currentFloating < fpuParameterRegisters.length) { + if (currentFloating % 2 != 0) { + // Make register number even to be a double reg + currentFloating++; + } + Register register = fpuDoubleParameterRegisters[currentFloating]; + currentFloating += 2; // Only every second is a double register + locations[i] = register.asValue(target.getLIRKind(kind)); + } + break; + case Float: + if (!stackOnly && currentFloating < fpuParameterRegisters.length) { + Register register = fpuParameterRegisters[currentFloating++]; + locations[i] = register.asValue(target.getLIRKind(kind)); + } + break; + default: + throw JVMCIError.shouldNotReachHere(); + } + + if (locations[i] == null) { + // Stack slot is always aligned to its size in bytes but minimum wordsize + int typeSize = SPARC.spillSlotSize(target, kind); + currentStackOffset = roundUp(currentStackOffset, typeSize); + locations[i] = StackSlot.get(target.getLIRKind(kind.getStackKind()), currentStackOffset, !type.out); + currentStackOffset += typeSize; + } + } + + Kind returnKind = returnType == null ? Kind.Void : returnType.getKind(); + AllocatableValue returnLocation = returnKind == Kind.Void ? Value.ILLEGAL : getReturnRegister(returnKind, type).asValue(target.getLIRKind(returnKind.getStackKind())); + return new CallingConvention(currentStackOffset, returnLocation, locations); + } + + private static int roundUp(int number, int mod) { + return ((number + mod - 1) / mod) * mod; + } + + @Override + public Register getReturnRegister(Kind kind) { + return getReturnRegister(kind, Type.JavaCallee); + } + + private static Register getReturnRegister(Kind kind, Type type) { + switch (kind) { + case Boolean: + case Byte: + case Char: + case Short: + case Int: + case Long: + case Object: + return type == Type.JavaCallee ? i0 : o0; + case Float: + return f0; + case Double: + return d0; + case Void: + case Illegal: + return null; + default: + throw new UnsupportedOperationException("no return register for type " + kind); + } + } + + @Override + public Register getFrameRegister() { + return sp; + } + + public CalleeSaveLayout getCalleeSaveLayout() { + return csl; + } + + @Override + public String toString() { + return String.format("Allocatable: " + Arrays.toString(getAllocatableRegisters()) + "%n" + "CallerSave: " + Arrays.toString(getCallerSaveRegisters()) + "%n"); + } +} diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HexCodeFile.java --- a/graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HexCodeFile.java Thu Jun 04 10:46:23 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,431 +0,0 @@ -/* - * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.jvmci.hotspot; - -import java.io.*; -import java.util.*; -import java.util.regex.*; - -import com.oracle.jvmci.code.*; -import com.oracle.jvmci.code.CompilationResult.CodeAnnotation; -import com.oracle.jvmci.code.CompilationResult.CodeComment; -import com.oracle.jvmci.code.CompilationResult.JumpTable; - -/** - * A HexCodeFile is a textual format for representing a chunk of machine code along with extra - * information that can be used to enhance a disassembly of the code. - * - * A pseudo grammar for a HexCodeFile is given below. - * - *

- *     HexCodeFile ::= Platform Delim HexCode Delim (OptionalSection Delim)*
- *
- *     OptionalSection ::= Comment | OperandComment | JumpTable | LookupTable
- *
- *     Platform ::= "Platform" ISA WordWidth
- *
- *     HexCode ::= "HexCode" StartAddress HexDigits
- *
- *     Comment ::= "Comment" Position String
- *
- *     OperandComment ::= "OperandComment" Position String
- *
- *     JumpTable ::= "JumpTable" Position EntrySize Low High
- *
- *     LookupTable ::= "LookupTable" Position NPairs KeySize OffsetSize
- *
- *     Position, EntrySize, Low, High, NPairs KeySize OffsetSize ::= int
- *
- *     Delim := "<||@"
- * 
- * - * There must be exactly one HexCode and Platform part in a HexCodeFile. The length of HexDigits - * must be even as each pair of digits represents a single byte. - *

- * Below is an example of a valid Code input: - * - *

- *
- *  Platform AMD64 64  <||@
- *  HexCode 0 e8000000009090904883ec084889842410d0ffff48893c24e800000000488b3c24488bf0e8000000004883c408c3  <||@
- *  Comment 24 frame-ref-map: +0 {0}
- *  at java.lang.String.toLowerCase(String.java:2496) [bci: 1]
- *              |0
- *     locals:  |stack:0:a
- *     stack:   |stack:0:a
- *    <||@
- *  OperandComment 24 {java.util.Locale.getDefault()}  <||@
- *  Comment 36 frame-ref-map: +0 {0}
- *  at java.lang.String.toLowerCase(String.java:2496) [bci: 4]
- *              |0
- *     locals:  |stack:0:a
- *    <||@
- *  OperandComment 36 {java.lang.String.toLowerCase(Locale)}  lt;||@
- *
- * 
- */ -public class HexCodeFile { - - public static final String NEW_LINE = CodeUtil.NEW_LINE; - public static final String SECTION_DELIM = " <||@"; - public static final String COLUMN_END = " <|@"; - public static final Pattern SECTION = Pattern.compile("(\\S+)\\s+(.*)", Pattern.DOTALL); - public static final Pattern COMMENT = Pattern.compile("(\\d+)\\s+(.*)", Pattern.DOTALL); - public static final Pattern OPERAND_COMMENT = COMMENT; - public static final Pattern JUMP_TABLE = Pattern.compile("(\\d+)\\s+(\\d+)\\s+(-{0,1}\\d+)\\s+(-{0,1}\\d+)\\s*"); - public static final Pattern LOOKUP_TABLE = Pattern.compile("(\\d+)\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)\\s*"); - public static final Pattern HEX_CODE = Pattern.compile("(\\p{XDigit}+)(?:\\s+(\\p{XDigit}*))?"); - public static final Pattern PLATFORM = Pattern.compile("(\\S+)\\s+(\\S+)", Pattern.DOTALL); - - /** - * Delimiter placed before a HexCodeFile when embedded in a string/stream. - */ - public static final String EMBEDDED_HCF_OPEN = "<<> comments = new TreeMap<>(); - - /** - * Map from a machine code position to a comment for the operands of the instruction at the - * position. - */ - public final Map operandComments = new TreeMap<>(); - - public final byte[] code; - - public final ArrayList jumpTables = new ArrayList<>(); - - public final String isa; - - public final int wordWidth; - - public final long startAddress; - - public HexCodeFile(byte[] code, long startAddress, String isa, int wordWidth) { - this.code = code; - this.startAddress = startAddress; - this.isa = isa; - this.wordWidth = wordWidth; - } - - /** - * Parses a string in the format produced by {@link #toString()} to produce a - * {@link HexCodeFile} object. - */ - public static HexCodeFile parse(String input, int sourceOffset, String source, String sourceName) { - return new Parser(input, sourceOffset, source, sourceName).hcf; - } - - /** - * Formats this HexCodeFile as a string that can be parsed with - * {@link #parse(String, int, String, String)}. - */ - @Override - public String toString() { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - writeTo(baos); - return baos.toString(); - } - - public String toEmbeddedString() { - return EMBEDDED_HCF_OPEN + NEW_LINE + toString() + EMBEDDED_HCF_CLOSE; - } - - public void writeTo(OutputStream out) { - PrintStream ps = out instanceof PrintStream ? (PrintStream) out : new PrintStream(out); - ps.printf("Platform %s %d %s%n", isa, wordWidth, SECTION_DELIM); - ps.printf("HexCode %x %s %s%n", startAddress, HexCodeFile.hexCodeString(code), SECTION_DELIM); - - for (JumpTable table : jumpTables) { - ps.printf("JumpTable %d %d %d %d %s%n", table.position, table.entrySize, table.low, table.high, SECTION_DELIM); - } - - for (Map.Entry> e : comments.entrySet()) { - int pos = e.getKey(); - for (String comment : e.getValue()) { - ps.printf("Comment %d %s %s%n", pos, comment, SECTION_DELIM); - } - } - - for (Map.Entry e : operandComments.entrySet()) { - ps.printf("OperandComment %d %s %s%n", e.getKey(), e.getValue(), SECTION_DELIM); - } - ps.flush(); - } - - /** - * Formats a byte array as a string of hex digits. - */ - public static String hexCodeString(byte[] code) { - if (code == null) { - return ""; - } else { - StringBuilder sb = new StringBuilder(code.length * 2); - for (int b : code) { - String hex = Integer.toHexString(b & 0xff); - if (hex.length() == 1) { - sb.append('0'); - } - sb.append(hex); - } - return sb.toString(); - } - } - - /** - * Adds a comment to the list of comments for a given position. - */ - public void addComment(int pos, String comment) { - List list = comments.get(pos); - if (list == null) { - list = new ArrayList<>(); - comments.put(pos, list); - } - list.add(encodeString(comment)); - } - - /** - * Sets an operand comment for a given position. - * - * @return the previous operand comment for {@code pos} - */ - public String addOperandComment(int pos, String comment) { - return operandComments.put(pos, encodeString(comment)); - } - - /** - * Adds any jump tables, lookup tables or code comments from a list of code annotations. - */ - public static void addAnnotations(HexCodeFile hcf, List annotations) { - if (annotations == null || annotations.isEmpty()) { - return; - } - for (CodeAnnotation a : annotations) { - if (a instanceof JumpTable) { - JumpTable table = (JumpTable) a; - hcf.jumpTables.add(table); - } else if (a instanceof CodeComment) { - CodeComment comment = (CodeComment) a; - hcf.addComment(comment.position, comment.value); - } - } - } - - /** - * Modifies a string to mangle any substrings matching {@link #SECTION_DELIM} and - * {@link #COLUMN_END}. - */ - public static String encodeString(String input) { - int index; - String s = input; - while ((index = s.indexOf(SECTION_DELIM)) != -1) { - s = s.substring(0, index) + " < |@" + s.substring(index + SECTION_DELIM.length()); - } - while ((index = s.indexOf(COLUMN_END)) != -1) { - s = s.substring(0, index) + " < @" + s.substring(index + COLUMN_END.length()); - } - return s; - } - - /** - * Helper class to parse a string in the format produced by {@link HexCodeFile#toString()} and - * produce a {@link HexCodeFile} object. - */ - static class Parser { - - final String input; - final String inputSource; - String isa; - int wordWidth; - byte[] code; - long startAddress; - HexCodeFile hcf; - - Parser(String input, int sourceOffset, String source, String sourceName) { - this.input = input; - this.inputSource = sourceName; - parseSections(sourceOffset, source); - } - - void makeHCF() { - if (hcf == null) { - if (isa != null && wordWidth != 0 && code != null) { - hcf = new HexCodeFile(code, startAddress, isa, wordWidth); - } - } - } - - void checkHCF(String section, int offset) { - check(hcf != null, offset, section + " section must be after Platform and HexCode section"); - } - - void check(boolean condition, int offset, String message) { - if (!condition) { - error(offset, message); - } - } - - Error error(int offset, String message) { - throw new Error(errorMessage(offset, message)); - } - - void warning(int offset, String message) { - PrintStream err = System.err; - err.println("Warning: " + errorMessage(offset, message)); - } - - String errorMessage(int offset, String message) { - assert offset < input.length(); - InputPos inputPos = filePos(offset); - int lineEnd = input.indexOf(HexCodeFile.NEW_LINE, offset); - int lineStart = offset - inputPos.col; - String line = lineEnd == -1 ? input.substring(lineStart) : input.substring(lineStart, lineEnd); - return String.format("%s:%d: %s%n%s%n%" + (inputPos.col + 1) + "s", inputSource, inputPos.line, message, line, "^"); - } - - static class InputPos { - - final int line; - final int col; - - public InputPos(int line, int col) { - this.line = line; - this.col = col; - } - } - - InputPos filePos(int index) { - assert input != null; - int lineStart = input.lastIndexOf(HexCodeFile.NEW_LINE, index) + 1; - - String l = input.substring(lineStart, lineStart + 10); - PrintStream out = System.out; - out.println("YYY" + input.substring(index, index + 10) + "..."); - out.println("XXX" + l + "..."); - - int pos = input.indexOf(HexCodeFile.NEW_LINE, 0); - int line = 1; - while (pos > 0 && pos < index) { - line++; - pos = input.indexOf(HexCodeFile.NEW_LINE, pos + 1); - } - return new InputPos(line, index - lineStart); - } - - void parseSections(int offset, String source) { - assert input.startsWith(source, offset); - int index = 0; - int endIndex = source.indexOf(SECTION_DELIM); - while (endIndex != -1) { - while (source.charAt(index) <= ' ') { - index++; - } - String section = source.substring(index, endIndex).trim(); - parseSection(offset + index, section); - index = endIndex + SECTION_DELIM.length(); - endIndex = source.indexOf(SECTION_DELIM, index); - } - } - - int parseInt(int offset, String value) { - try { - return Integer.parseInt(value); - } catch (NumberFormatException e) { - throw error(offset, "Not a valid integer: " + value); - } - } - - void parseSection(int offset, String section) { - if (section.isEmpty()) { - return; - } - assert input.startsWith(section, offset); - Matcher m = HexCodeFile.SECTION.matcher(section); - check(m.matches(), offset, "Section does not match pattern " + HexCodeFile.SECTION); - - String header = m.group(1); - String body = m.group(2); - int headerOffset = offset + m.start(1); - int bodyOffset = offset + m.start(2); - - if (header.equals("Platform")) { - check(isa == null, bodyOffset, "Duplicate Platform section found"); - m = HexCodeFile.PLATFORM.matcher(body); - check(m.matches(), bodyOffset, "Platform does not match pattern " + HexCodeFile.PLATFORM); - isa = m.group(1); - wordWidth = parseInt(bodyOffset + m.start(2), m.group(2)); - makeHCF(); - } else if (header.equals("HexCode")) { - check(code == null, bodyOffset, "Duplicate Code section found"); - m = HexCodeFile.HEX_CODE.matcher(body); - check(m.matches(), bodyOffset, "Code does not match pattern " + HexCodeFile.HEX_CODE); - String hexAddress = m.group(1); - startAddress = Long.valueOf(hexAddress, 16); - String hexCode = m.group(2); - if (hexCode == null) { - code = new byte[0]; - } else { - check((hexCode.length() % 2) == 0, bodyOffset, "Hex code length must be even"); - code = new byte[hexCode.length() / 2]; - for (int i = 0; i < code.length; i++) { - String hexByte = hexCode.substring(i * 2, (i + 1) * 2); - code[i] = (byte) Integer.parseInt(hexByte, 16); - } - } - makeHCF(); - } else if (header.equals("Comment")) { - checkHCF("Comment", headerOffset); - m = HexCodeFile.COMMENT.matcher(body); - check(m.matches(), bodyOffset, "Comment does not match pattern " + HexCodeFile.COMMENT); - int pos = parseInt(bodyOffset + m.start(1), m.group(1)); - String comment = m.group(2); - hcf.addComment(pos, comment); - } else if (header.equals("OperandComment")) { - checkHCF("OperandComment", headerOffset); - m = HexCodeFile.OPERAND_COMMENT.matcher(body); - check(m.matches(), bodyOffset, "OperandComment does not match pattern " + HexCodeFile.OPERAND_COMMENT); - int pos = parseInt(bodyOffset + m.start(1), m.group(1)); - String comment = m.group(2); - hcf.addOperandComment(pos, comment); - } else if (header.equals("JumpTable")) { - checkHCF("JumpTable", headerOffset); - m = HexCodeFile.JUMP_TABLE.matcher(body); - check(m.matches(), bodyOffset, "JumpTable does not match pattern " + HexCodeFile.JUMP_TABLE); - int pos = parseInt(bodyOffset + m.start(1), m.group(1)); - int entrySize = parseInt(bodyOffset + m.start(2), m.group(2)); - int low = parseInt(bodyOffset + m.start(3), m.group(3)); - int high = parseInt(bodyOffset + m.start(4), m.group(4)); - hcf.jumpTables.add(new JumpTable(pos, low, high, entrySize)); - } else { - error(offset, "Unknown section header: " + header); - } - } - } -} diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotCodeCacheProvider.java --- a/graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotCodeCacheProvider.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotCodeCacheProvider.java Thu Jun 04 11:08:12 2015 -0700 @@ -25,15 +25,11 @@ import static com.oracle.jvmci.hotspot.HotSpotCompressedNullConstant.*; import java.lang.reflect.*; -import java.util.*; import com.oracle.jvmci.code.*; -import com.oracle.jvmci.code.CodeUtil.DefaultRefMapFormatter; -import com.oracle.jvmci.code.CodeUtil.RefMapFormatter; import com.oracle.jvmci.code.CompilationResult.Call; import com.oracle.jvmci.code.CompilationResult.ConstantReference; import com.oracle.jvmci.code.CompilationResult.DataPatch; -import com.oracle.jvmci.code.CompilationResult.Infopoint; import com.oracle.jvmci.code.CompilationResult.Mark; import com.oracle.jvmci.code.DataSection.Data; import com.oracle.jvmci.code.DataSection.DataBuilder; @@ -59,75 +55,8 @@ } @Override - public String disassemble(CompilationResult compResult, InstalledCode installedCode) { - byte[] code = installedCode == null ? Arrays.copyOf(compResult.getTargetCode(), compResult.getTargetCodeSize()) : installedCode.getCode(); - if (code == null) { - // Method was deoptimized/invalidated - return ""; - } - long start = installedCode == null ? 0L : installedCode.getStart(); - HexCodeFile hcf = new HexCodeFile(code, start, target.arch.getName(), target.wordSize * 8); - if (compResult != null) { - HexCodeFile.addAnnotations(hcf, compResult.getAnnotations()); - addExceptionHandlersComment(compResult, hcf); - Register fp = regConfig.getFrameRegister(); - RefMapFormatter slotFormatter = new DefaultRefMapFormatter(target.arch, target.wordSize, fp, 0); - for (Infopoint infopoint : compResult.getInfopoints()) { - if (infopoint instanceof Call) { - Call call = (Call) infopoint; - if (call.debugInfo != null) { - hcf.addComment(call.pcOffset + call.size, CodeUtil.append(new StringBuilder(100), call.debugInfo, slotFormatter).toString()); - } - addOperandComment(hcf, call.pcOffset, "{" + getTargetName(call) + "}"); - } else { - if (infopoint.debugInfo != null) { - hcf.addComment(infopoint.pcOffset, CodeUtil.append(new StringBuilder(100), infopoint.debugInfo, slotFormatter).toString()); - } - addOperandComment(hcf, infopoint.pcOffset, "{infopoint: " + infopoint.reason + "}"); - } - } - for (DataPatch site : compResult.getDataPatches()) { - hcf.addOperandComment(site.pcOffset, "{" + site.reference.toString() + "}"); - } - for (Mark mark : compResult.getMarks()) { - hcf.addComment(mark.pcOffset, getMarkIdName((int) mark.id)); - } - } - String hcfEmbeddedString = hcf.toEmbeddedString(); - return HexCodeFileDisTool.tryDisassemble(hcfEmbeddedString); - } - - /** - * Interface to the tool for disassembling an {@link HexCodeFile#toEmbeddedString() embedded} - * {@link HexCodeFile}. - */ - static class HexCodeFileDisTool { - static final Method processMethod; - static { - Method toolMethod = null; - try { - Class toolClass = Class.forName("com.oracle.max.hcfdis.HexCodeFileDis", true, ClassLoader.getSystemClassLoader()); - toolMethod = toolClass.getDeclaredMethod("processEmbeddedString", String.class); - } catch (Exception e) { - // Tool not available on the class path - } - processMethod = toolMethod; - } - - public static String tryDisassemble(String hcfEmbeddedString) { - if (processMethod != null) { - try { - return (String) processMethod.invoke(null, hcfEmbeddedString); - } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { - // If the tool is available, for now let's be noisy when it fails - throw new JVMCIError(e); - } - } - return hcfEmbeddedString; - } - } - - private String getMarkIdName(int markId) { + public String getMarkName(Mark mark) { + int markId = (int) mark.id; Field[] fields = runtime.getConfig().getClass().getDeclaredFields(); for (Field f : fields) { if (f.getName().startsWith("MARKID_")) { @@ -140,13 +69,14 @@ } } } - return String.valueOf(markId); + return CodeCacheProvider.super.getMarkName(mark); } /** * Decodes a call target to a mnemonic if possible. */ - private String getTargetName(Call call) { + @Override + public String getTargetName(Call call) { Field[] fields = runtime.getConfig().getClass().getDeclaredFields(); for (Field f : fields) { if (f.getName().endsWith("Stub")) { @@ -160,25 +90,7 @@ } } } - return String.valueOf(call.target); - } - - private static void addExceptionHandlersComment(CompilationResult compResult, HexCodeFile hcf) { - if (!compResult.getExceptionHandlers().isEmpty()) { - String nl = HexCodeFile.NEW_LINE; - StringBuilder buf = new StringBuilder("------ Exception Handlers ------").append(nl); - for (CompilationResult.ExceptionHandler e : compResult.getExceptionHandlers()) { - buf.append(" ").append(e.pcOffset).append(" -> ").append(e.handlerPos).append(nl); - hcf.addComment(e.pcOffset, "[exception -> " + e.handlerPos + "]"); - hcf.addComment(e.handlerPos, "[exception handler for " + e.pcOffset + "]"); - } - hcf.addComment(0, buf.toString()); - } - } - - private static void addOperandComment(HexCodeFile hcf, int pos, String comment) { - String oldValue = hcf.addOperandComment(pos, comment); - assert oldValue == null : "multiple comments for operand of instruction at " + pos + ": " + comment + ", " + oldValue; + return CodeCacheProvider.super.getTargetName(call); } @Override diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotConstantPool.java diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotJVMCIRuntime.java --- a/graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotJVMCIRuntime.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotJVMCIRuntime.java Thu Jun 04 11:08:12 2015 -0700 @@ -220,7 +220,12 @@ hostBackend = registerBackend(factory.createJVMCIBackend(this, null)); } - vmEventListener = Services.loadSingle(HotSpotVMEventListener.class, true); + HotSpotVMEventListener listener = Services.loadSingle(HotSpotVMEventListener.class, false); + if (listener == null) { + listener = new HotSpotVMEventListener() { + }; + } + vmEventListener = listener; } private JVMCIBackend registerBackend(JVMCIBackend backend) { diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotMetaAccessProvider.java --- a/graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotMetaAccessProvider.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotMetaAccessProvider.java Thu Jun 04 11:08:12 2015 -0700 @@ -32,6 +32,8 @@ import com.oracle.jvmci.common.*; import com.oracle.jvmci.meta.*; +// JaCoCo Exclude + /** * HotSpot implementation of {@link MetaAccessProvider}. */ diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotTargetDescription.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotTargetDescription.java Thu Jun 04 11:08:12 2015 -0700 @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.jvmci.hotspot; + +import com.oracle.jvmci.code.*; + +public class HotSpotTargetDescription extends TargetDescription { + + public HotSpotTargetDescription(Architecture arch, boolean isMP, int stackAlignment, int implicitNullCheckLimit, boolean inlineObjects) { + super(arch, isMP, stackAlignment, implicitNullCheckLimit, inlineObjects); + } + + @Override + public ReferenceMap createReferenceMap(boolean hasRegisters, int stackSlotCount) { + return new HotSpotReferenceMap(this); + } +} diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotVMEventListener.java --- a/graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotVMEventListener.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotVMEventListener.java Thu Jun 04 11:08:12 2015 -0700 @@ -29,17 +29,25 @@ /** * Notifies this client that HotSpot is running in CompileTheWorld mode and the JVMCI compiler * should now perform its version of CompileTheWorld. + * + * @param metaspaceMethod + * @param entryBCI + * @param jvmciEnv + * @param id */ - void compileMetaspaceMethod(long metaspaceMethod, int entryBCI, long jvmciEnv, int id); + default void compileMetaspaceMethod(long metaspaceMethod, int entryBCI, long jvmciEnv, int id) { + } /** * Notifies this client that HotSpot is running in CompileTheWorld mode and the JVMCI compiler * should now perform its version of CompileTheWorld. */ - void notifyCompileTheWorld() throws Throwable; + default void notifyCompileTheWorld() throws Throwable { + } /** * Notifies this client that the VM is shutting down. */ - void notifyShutdown(); + default void notifyShutdown() { + } } diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/AbstractValue.java --- a/graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/AbstractValue.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/AbstractValue.java Thu Jun 04 11:08:12 2015 -0700 @@ -92,7 +92,6 @@ * Warning: Use with caution! Usually equivalence {@link #equals(Object)} is sufficient and * should be used. */ - @ExcludeFromIdentityComparisonVerification public final boolean identityEquals(AbstractValue other) { return this == other; } diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/ExcludeFromIdentityComparisonVerification.java --- a/graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/ExcludeFromIdentityComparisonVerification.java Thu Jun 04 10:46:23 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2014, 2014, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.jvmci.meta; - -import java.lang.annotation.*; - -/** - * This annotation denotes methods which are allowed to use identity checks (==/!=) on restricted - * types. - * - * @see CheckGraalInvariants - */ -@SuppressWarnings("javadoc") -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.METHOD) -public @interface ExcludeFromIdentityComparisonVerification { - -} diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/Value.java --- a/graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/Value.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/Value.java Thu Jun 04 11:08:12 2015 -0700 @@ -63,7 +63,6 @@ * Warning: Use with caution! Usually equivalence {@link #equals(Object)} is sufficient and * should be used. */ - @ExcludeFromIdentityComparisonVerification default boolean identityEquals(Value other) { return this == other; } diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/ConstantTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/ConstantTest.java Thu Jun 04 11:08:12 2015 -0700 @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2014, 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.jvmci.runtime.test; + +import com.oracle.jvmci.meta.JavaConstant; +import com.oracle.jvmci.meta.Kind; +import org.junit.*; + +public class ConstantTest extends FieldUniverse { + + @Test + public void testNegativeZero() { + Assert.assertTrue("Constant for 0.0f must be different from -0.0f", JavaConstant.FLOAT_0 != JavaConstant.forFloat(-0.0F)); + Assert.assertTrue("Constant for 0.0d must be different from -0.0d", JavaConstant.DOUBLE_0 != JavaConstant.forDouble(-0.0d)); + } + + @Test + public void testNullIsNull() { + Assert.assertTrue(JavaConstant.NULL_POINTER.isNull()); + } + + @Test + public void testOne() { + for (Kind kind : Kind.values()) { + if (kind.isNumericInteger() || kind.isNumericFloat()) { + Assert.assertTrue(JavaConstant.one(kind).getKind() == kind); + } + } + Assert.assertEquals(1, JavaConstant.one(Kind.Int).asInt()); + Assert.assertEquals(1L, JavaConstant.one(Kind.Long).asLong()); + Assert.assertEquals(1, JavaConstant.one(Kind.Byte).asInt()); + Assert.assertEquals(1, JavaConstant.one(Kind.Short).asInt()); + Assert.assertEquals(1, JavaConstant.one(Kind.Char).asInt()); + Assert.assertTrue(1F == JavaConstant.one(Kind.Float).asFloat()); + Assert.assertTrue(1D == JavaConstant.one(Kind.Double).asDouble()); + } + + @Test(expected = IllegalArgumentException.class) + public void testIllegalOne() { + JavaConstant.one(Kind.Illegal); + } + + @Test(expected = IllegalArgumentException.class) + public void testVoidOne() { + JavaConstant.one(Kind.Void); + } +} diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/FieldUniverse.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/FieldUniverse.java Thu Jun 04 11:08:12 2015 -0700 @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.jvmci.runtime.test; + +import com.oracle.jvmci.meta.ResolvedJavaField; + +import java.lang.reflect.*; +import java.util.*; + +/** + * Context for field related tests. + */ +public class FieldUniverse extends TypeUniverse { + + public static final Map fields = new HashMap<>(); + + { + for (Class c : classes) { + for (Field f : c.getDeclaredFields()) { + ResolvedJavaField field = metaAccess.lookupJavaField(f); + fields.put(f, field); + } + } + } +} diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/MethodUniverse.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/MethodUniverse.java Thu Jun 04 11:08:12 2015 -0700 @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.jvmci.runtime.test; + +import com.oracle.jvmci.meta.ResolvedJavaMethod; +import java.lang.reflect.*; +import java.util.*; + +/** + * Context for method related tests. + */ +public class MethodUniverse extends TypeUniverse { + + public static final Map methods = new HashMap<>(); + public static final Map, ResolvedJavaMethod> constructors = new HashMap<>(); + + { + for (Class c : classes) { + for (Method m : c.getDeclaredMethods()) { + ResolvedJavaMethod method = metaAccess.lookupJavaMethod(m); + methods.put(m, method); + } + for (Constructor m : c.getDeclaredConstructors()) { + constructors.put(m, metaAccess.lookupJavaMethod(m)); + } + } + } +} diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/NameAndSignature.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/NameAndSignature.java Thu Jun 04 11:08:12 2015 -0700 @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.jvmci.runtime.test; + +import java.lang.reflect.*; +import java.util.*; + +import com.oracle.jvmci.meta.*; +import com.oracle.jvmci.runtime.*; + +class NameAndSignature { + + public static final MetaAccessProvider metaAccess = JVMCI.getRuntime().getHostJVMCIBackend().getMetaAccess(); + + final String name; + final Class returnType; + final Class[] parameterTypes; + + public NameAndSignature(Method m) { + this.name = m.getName(); + this.returnType = m.getReturnType(); + this.parameterTypes = m.getParameterTypes(); + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof NameAndSignature) { + NameAndSignature s = (NameAndSignature) obj; + return s.returnType == returnType && name.equals(s.name) && Arrays.equals(s.parameterTypes, parameterTypes); + } + return false; + } + + @Override + public int hashCode() { + return name.hashCode(); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(name + "("); + String sep = ""; + for (Class p : parameterTypes) { + sb.append(sep); + sep = ", "; + sb.append(p.getName()); + } + return sb.append(')').append(returnType.getName()).toString(); + } + + public boolean signatureEquals(ResolvedJavaMethod m) { + Signature s = m.getSignature(); + ResolvedJavaType declaringClass = m.getDeclaringClass(); + if (!s.getReturnType(declaringClass).resolve(declaringClass).equals(metaAccess.lookupJavaType(returnType))) { + return false; + } + if (s.getParameterCount(false) != parameterTypes.length) { + return false; + } + for (int i = 0; i < parameterTypes.length; i++) { + if (!s.getParameterType(i, declaringClass).resolve(declaringClass).equals(metaAccess.lookupJavaType(parameterTypes[i]))) { + return false; + } + } + return true; + } +} diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/ResolvedJavaTypeResolveConcreteMethodTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/ResolvedJavaTypeResolveConcreteMethodTest.java Thu Jun 04 11:08:12 2015 -0700 @@ -0,0 +1,170 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.jvmci.runtime.test; + +import static org.junit.Assert.*; + +import org.junit.*; + +import com.oracle.jvmci.meta.*; +import com.oracle.jvmci.runtime.*; + +public class ResolvedJavaTypeResolveConcreteMethodTest { + public final MetaAccessProvider metaAccess; + + public ResolvedJavaTypeResolveConcreteMethodTest() { + metaAccess = JVMCI.getRuntime().getHostJVMCIBackend().getMetaAccess(); + } + + protected abstract static class A { + @SuppressWarnings("unused") + private void priv() { + } + + public void v1() { + } + + public void v2() { + } + + public abstract void abs(); + } + + protected static class B extends A implements I { + public void i() { + } + + @Override + public void v2() { + } + + @Override + public void abs() { + + } + } + + protected static class C extends B { + public void d() { + } + } + + protected abstract static class D extends A { + + } + + protected static class E extends D { + @Override + public void abs() { + } + } + + protected interface I { + void i(); + + default void d() { + } + } + + @Test + public void testDefaultMethod() { + ResolvedJavaType i = getType(I.class); + ResolvedJavaType b = getType(B.class); + ResolvedJavaType c = getType(C.class); + ResolvedJavaMethod di = getMethod(i, "d"); + ResolvedJavaMethod dc = getMethod(c, "d"); + + assertEquals(di, i.resolveConcreteMethod(di, c)); + assertEquals(di, b.resolveConcreteMethod(di, c)); + assertEquals(dc, c.resolveConcreteMethod(di, c)); + } + + @Test + public void testPrivateMethod() { + ResolvedJavaType a = getType(A.class); + ResolvedJavaType b = getType(B.class); + ResolvedJavaType c = getType(C.class); + ResolvedJavaMethod priv = getMethod(a, "priv"); + + assertNull(a.resolveConcreteMethod(priv, c)); + assertNull(b.resolveConcreteMethod(priv, c)); + } + + @Test + public void testAbstractMethod() { + ResolvedJavaType a = getType(A.class); + ResolvedJavaType b = getType(B.class); + ResolvedJavaType c = getType(C.class); + ResolvedJavaType d = getType(D.class); + ResolvedJavaType e = getType(E.class); + ResolvedJavaMethod absa = getMethod(a, "abs"); + ResolvedJavaMethod absb = getMethod(b, "abs"); + ResolvedJavaMethod abse = getMethod(e, "abs"); + + assertNull(a.resolveConcreteMethod(absa, c)); + assertNull(d.resolveConcreteMethod(absa, c)); + + assertEquals(absb, b.resolveConcreteMethod(absa, c)); + assertEquals(absb, b.resolveConcreteMethod(absb, c)); + assertEquals(absb, c.resolveConcreteMethod(absa, c)); + assertEquals(absb, c.resolveConcreteMethod(absb, c)); + assertEquals(abse, e.resolveConcreteMethod(absa, c)); + assertNull(e.resolveConcreteMethod(absb, c)); + assertEquals(abse, e.resolveConcreteMethod(abse, c)); + } + + @Test + public void testVirtualMethod() { + ResolvedJavaType a = getType(A.class); + ResolvedJavaType b = getType(B.class); + ResolvedJavaType c = getType(C.class); + ResolvedJavaMethod v1a = getMethod(a, "v1"); + ResolvedJavaMethod v2a = getMethod(a, "v2"); + ResolvedJavaMethod v2b = getMethod(b, "v2"); + + assertEquals(v1a, a.resolveConcreteMethod(v1a, c)); + assertEquals(v1a, b.resolveConcreteMethod(v1a, c)); + assertEquals(v1a, c.resolveConcreteMethod(v1a, c)); + assertEquals(v2a, a.resolveConcreteMethod(v2a, c)); + assertEquals(v2b, b.resolveConcreteMethod(v2a, c)); + assertEquals(v2b, b.resolveConcreteMethod(v2b, c)); + assertEquals(v2b, c.resolveConcreteMethod(v2a, c)); + assertEquals(v2b, c.resolveConcreteMethod(v2b, c)); + + } + + static ResolvedJavaMethod getMethod(ResolvedJavaType type, String methodName) { + for (ResolvedJavaMethod method : type.getDeclaredMethods()) { + if (method.getName().equals(methodName)) { + return method; + } + } + throw new IllegalArgumentException(); + } + + protected ResolvedJavaType getType(Class clazz) { + ResolvedJavaType type = metaAccess.lookupJavaType(clazz); + type.initialize(); + return type; + } +} diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/ResolvedJavaTypeResolveMethodTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/ResolvedJavaTypeResolveMethodTest.java Thu Jun 04 11:08:12 2015 -0700 @@ -0,0 +1,170 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.jvmci.runtime.test; + +import static org.junit.Assert.*; + +import org.junit.*; + +import com.oracle.jvmci.meta.*; +import com.oracle.jvmci.runtime.*; + +public class ResolvedJavaTypeResolveMethodTest { + public final MetaAccessProvider metaAccess; + + public ResolvedJavaTypeResolveMethodTest() { + metaAccess = JVMCI.getRuntime().getHostJVMCIBackend().getMetaAccess(); + } + + protected abstract static class A { + @SuppressWarnings("unused") + private void priv() { + } + + public void v1() { + } + + public void v2() { + } + + public abstract void abs(); + } + + protected static class B extends A implements I { + public void i() { + } + + @Override + public void v2() { + } + + @Override + public void abs() { + + } + } + + protected static class C extends B { + public void d() { + } + } + + protected abstract static class D extends A { + + } + + protected static class E extends D { + @Override + public void abs() { + } + } + + protected interface I { + void i(); + + default void d() { + } + } + + @Test + public void testDefaultMethod() { + ResolvedJavaType i = getType(I.class); + ResolvedJavaType b = getType(B.class); + ResolvedJavaType c = getType(C.class); + ResolvedJavaMethod di = getMethod(i, "d"); + ResolvedJavaMethod dc = getMethod(c, "d"); + + assertEquals(di, i.resolveMethod(di, c, true)); + assertEquals(di, b.resolveMethod(di, c, true)); + assertEquals(dc, c.resolveMethod(di, c, true)); + } + + @Test + public void testPrivateMethod() { + ResolvedJavaType a = getType(A.class); + ResolvedJavaType b = getType(B.class); + ResolvedJavaType c = getType(C.class); + ResolvedJavaMethod priv = getMethod(a, "priv"); + + assertNull(a.resolveMethod(priv, c, true)); + assertNull(b.resolveMethod(priv, c, true)); + } + + @Test + public void testAbstractMethod() { + ResolvedJavaType a = getType(A.class); + ResolvedJavaType b = getType(B.class); + ResolvedJavaType c = getType(C.class); + ResolvedJavaType d = getType(D.class); + ResolvedJavaType e = getType(E.class); + ResolvedJavaMethod absa = getMethod(a, "abs"); + ResolvedJavaMethod absb = getMethod(b, "abs"); + ResolvedJavaMethod abse = getMethod(e, "abs"); + + assertEquals(absa, a.resolveMethod(absa, c, true)); + assertEquals(absa, d.resolveMethod(absa, c, true)); + + assertEquals(absb, b.resolveMethod(absa, c, true)); + assertEquals(absb, b.resolveMethod(absb, c, true)); + assertEquals(absb, c.resolveMethod(absa, c, true)); + assertEquals(absb, c.resolveMethod(absb, c, true)); + assertEquals(abse, e.resolveMethod(absa, c, true)); + assertNull(e.resolveMethod(absb, c, true)); + assertEquals(abse, e.resolveMethod(abse, c, true)); + } + + @Test + public void testVirtualMethod() { + ResolvedJavaType a = getType(A.class); + ResolvedJavaType b = getType(B.class); + ResolvedJavaType c = getType(C.class); + ResolvedJavaMethod v1a = getMethod(a, "v1"); + ResolvedJavaMethod v2a = getMethod(a, "v2"); + ResolvedJavaMethod v2b = getMethod(b, "v2"); + + assertEquals(v1a, a.resolveMethod(v1a, c, true)); + assertEquals(v1a, b.resolveMethod(v1a, c, true)); + assertEquals(v1a, c.resolveMethod(v1a, c, true)); + assertEquals(v2a, a.resolveMethod(v2a, c, true)); + assertEquals(v2b, b.resolveMethod(v2a, c, true)); + assertEquals(v2b, b.resolveMethod(v2b, c, true)); + assertEquals(v2b, c.resolveMethod(v2a, c, true)); + assertEquals(v2b, c.resolveMethod(v2b, c, true)); + + } + + static ResolvedJavaMethod getMethod(ResolvedJavaType type, String methodName) { + for (ResolvedJavaMethod method : type.getDeclaredMethods()) { + if (method.getName().equals(methodName)) { + return method; + } + } + throw new IllegalArgumentException(); + } + + protected ResolvedJavaType getType(Class clazz) { + ResolvedJavaType type = metaAccess.lookupJavaType(clazz); + type.initialize(); + return type; + } +} diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/TestConstantReflectionProvider.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/TestConstantReflectionProvider.java Thu Jun 04 11:08:12 2015 -0700 @@ -0,0 +1,125 @@ +/* + * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.jvmci.runtime.test; + +import static org.junit.Assert.*; + +import java.lang.reflect.*; +import java.util.*; + +import org.junit.*; + +import com.oracle.jvmci.meta.*; + +/** + * Tests for {@link ConstantReflectionProvider}. It assumes an implementation of the interface that + * actually returns non-null results for access operations that are possible, i.e., the tests will + * fail for an implementation that spuriously returns null (which is allowed by the specification). + */ +public class TestConstantReflectionProvider extends TypeUniverse { + + @Test + public void constantEqualsTest() { + for (ConstantValue c1 : constants()) { + for (ConstantValue c2 : constants()) { + // test symmetry + assertEquals(constantReflection.constantEquals(c1.value, c2.value), constantReflection.constantEquals(c2.value, c1.value)); + if (c1.value.getKind() != Kind.Object && c2.value.getKind() != Kind.Object) { + assertEquals(c1.value.equals(c2.value), constantReflection.constantEquals(c2.value, c1.value)); + } + } + } + } + + @Test + public void readArrayLengthTest() { + for (ConstantValue cv : constants()) { + JavaConstant c = cv.value; + Integer actual = constantReflection.readArrayLength(c); + if (c.getKind() != Kind.Object || c.isNull() || !cv.boxed.getClass().isArray()) { + assertNull(actual); + } else { + assertNotNull(actual); + int actualInt = actual; + assertEquals(Array.getLength(cv.boxed), actualInt); + } + } + } + + static class PrimitiveConstants { + static final long LONG_CONST = 42; + static final int INT_CONST = 66; + static final byte BYTE_CONST = 123; + static final boolean BOOL_CONST = true; + } + + static class BoxedConstants { + static final Long LONG_CONST = 42L; + static final Integer INT_CONST = 66; + static final Byte BYTE_CONST = 123; + static final Boolean BOOL_CONST = true; + } + + @Test + public void boxTest() { + for (ConstantValue cv : constants()) { + JavaConstant c = cv.value; + JavaConstant boxed = constantReflection.boxPrimitive(c); + if (boxed != null && c.getKind().isPrimitive()) { + assertTrue(boxed.getKind().isObject()); + assertFalse(boxed.isNull()); + } + } + + List primitiveConstants = readConstants(PrimitiveConstants.class); + List boxedConstants = readConstants(BoxedConstants.class); + for (int i = 0; i < primitiveConstants.size(); i++) { + ConstantValue prim = primitiveConstants.get(i); + ConstantValue box = boxedConstants.get(i); + assertEquals(box.value, constantReflection.boxPrimitive(prim.value)); + } + + assertNull(constantReflection.boxPrimitive(JavaConstant.NULL_POINTER)); + } + + @Test + public void unboxTest() { + for (ConstantValue cv : constants()) { + JavaConstant c = cv.value; + JavaConstant unboxed = c.isNull() ? null : constantReflection.unboxPrimitive(c); + if (unboxed != null) { + assertFalse(unboxed.getKind().isObject()); + } + } + List primitiveConstants = readConstants(PrimitiveConstants.class); + List boxedConstants = readConstants(BoxedConstants.class); + for (int i = 0; i < primitiveConstants.size(); i++) { + ConstantValue prim = primitiveConstants.get(i); + ConstantValue box = boxedConstants.get(i); + assert prim.getSimpleName().equals(box.getSimpleName()); + assertEquals(prim.value, constantReflection.unboxPrimitive(box.value)); + } + + assertNull(constantReflection.unboxPrimitive(JavaConstant.NULL_POINTER)); + } +} diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/TestJavaField.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/TestJavaField.java Thu Jun 04 11:08:12 2015 -0700 @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.jvmci.runtime.test; + +import static org.junit.Assert.*; + +import java.lang.reflect.*; +import java.util.*; + +import org.junit.*; + +import com.oracle.jvmci.meta.*; + +/** + * Tests for {@link JavaField}. + */ +public class TestJavaField extends FieldUniverse { + + @Test + public void getNameTest() { + for (Map.Entry e : fields.entrySet()) { + String expected = e.getKey().getName(); + String actual = e.getValue().getName(); + assertEquals(expected, actual); + } + } + + @Test + public void getTypeTest() { + for (Map.Entry e : fields.entrySet()) { + // Must resolve types first as a resolved types != unresolved types + ResolvedJavaField rf = e.getValue(); + JavaType expected = metaAccess.lookupJavaType(e.getKey().getType()).resolve(rf.getDeclaringClass()); + JavaType actual = rf.getType().resolve(rf.getDeclaringClass()); + assertEquals(expected, actual); + } + } + + @Test + public void getKindTest() { + for (Map.Entry e : fields.entrySet()) { + Kind expected = metaAccess.lookupJavaType(e.getKey().getType()).getKind(); + Kind actual = e.getValue().getKind(); + assertEquals(expected, actual); + } + } + + @Test + public void getDeclaringClassTest() { + for (Map.Entry e : fields.entrySet()) { + Class expected = e.getKey().getDeclaringClass(); + ResolvedJavaType actual = e.getValue().getDeclaringClass(); + assertTrue(actual.equals(metaAccess.lookupJavaType(expected))); + } + } +} diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/TestJavaMethod.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/TestJavaMethod.java Thu Jun 04 11:08:12 2015 -0700 @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.jvmci.runtime.test; + +import static org.junit.Assert.*; + +import java.lang.reflect.*; +import java.util.*; + +import org.junit.*; + +import com.oracle.jvmci.meta.*; + +/** + * Tests for {@link JavaMethod}. + */ +public class TestJavaMethod extends MethodUniverse { + + @Test + public void getNameTest() { + for (Map.Entry e : methods.entrySet()) { + String expected = e.getKey().getName(); + String actual = e.getValue().getName(); + assertEquals(expected, actual); + } + } + + @Test + public void getDeclaringClassTest() { + for (Map.Entry e : methods.entrySet()) { + Class expected = e.getKey().getDeclaringClass(); + ResolvedJavaType actual = e.getValue().getDeclaringClass(); + assertTrue(actual.equals(metaAccess.lookupJavaType(expected))); + } + } + + @Test + public void getSignatureTest() { + for (Map.Entry e : methods.entrySet()) { + assertTrue(new NameAndSignature(e.getKey()).signatureEquals(e.getValue())); + } + } +} diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/TestJavaType.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/TestJavaType.java Thu Jun 04 11:08:12 2015 -0700 @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.jvmci.runtime.test; + +import com.oracle.jvmci.meta.JavaType; +import com.oracle.jvmci.meta.Kind; +import static org.junit.Assert.*; + +import org.junit.*; + +/** + * Tests for {@link JavaType}. + */ +public class TestJavaType extends TypeUniverse { + + public TestJavaType() { + } + + @Test + public void getKindTest() { + for (Class c : classes) { + JavaType type = metaAccess.lookupJavaType(c); + Kind expected = Kind.fromJavaClass(c); + Kind actual = type.getKind(); + assertEquals(expected, actual); + } + } +} diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/TestMetaAccessProvider.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/TestMetaAccessProvider.java Thu Jun 04 11:08:12 2015 -0700 @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.jvmci.runtime.test; + +import static com.oracle.jvmci.meta.MetaUtil.*; +import static org.junit.Assert.*; + +import java.lang.reflect.*; + +import org.junit.*; + +import com.oracle.jvmci.meta.*; + +/** + * Tests for {@link MetaAccessProvider}. + */ +public class TestMetaAccessProvider extends TypeUniverse { + + @Test + public void lookupJavaTypeTest() { + for (Class c : classes) { + ResolvedJavaType type = metaAccess.lookupJavaType(c); + assertNotNull(type); + assertEquals(c.getModifiers(), type.getModifiers()); + if (!type.isArray()) { + assertEquals(type.getName(), toInternalName(c.getName())); + assertEquals(type.toJavaName(), c.getName()); + } + } + } + + @Test + public void lookupJavaMethodTest() { + for (Class c : classes) { + for (Method reflect : c.getDeclaredMethods()) { + ResolvedJavaMethod method = metaAccess.lookupJavaMethod(reflect); + assertNotNull(method); + int expected = reflect.getModifiers() & Modifier.methodModifiers(); + int actual = method.getModifiers(); + assertEquals(String.format("%s: 0x%x != 0x%x", reflect, expected, actual), expected, actual); + assertTrue(method.getDeclaringClass().equals(metaAccess.lookupJavaType(reflect.getDeclaringClass()))); + } + } + } + + @Test + public void lookupJavaFieldTest() { + for (Class c : classes) { + for (Field reflect : c.getDeclaredFields()) { + ResolvedJavaField field = metaAccess.lookupJavaField(reflect); + assertNotNull(field); + int expected = reflect.getModifiers(); + int actual = field.getModifiers(); + assertEquals(String.format("%s: 0x%x != 0x%x", reflect, expected, actual), expected, actual); + assertTrue(field.getDeclaringClass().equals(metaAccess.lookupJavaType(reflect.getDeclaringClass()))); + } + } + } + + @Test + public void lookupJavaTypeConstantTest() { + for (ConstantValue cv : constants()) { + JavaConstant c = cv.value; + if (c.getKind() == Kind.Object && !c.isNull()) { + Object o = cv.boxed; + ResolvedJavaType type = metaAccess.lookupJavaType(c); + assertNotNull(type); + assertTrue(type.equals(metaAccess.lookupJavaType(o.getClass()))); + } else { + assertEquals(metaAccess.lookupJavaType(c), null); + } + } + } +} diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/TestResolvedJavaField.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/TestResolvedJavaField.java Thu Jun 04 11:08:12 2015 -0700 @@ -0,0 +1,145 @@ +/* + * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.jvmci.runtime.test; + +import static org.junit.Assert.*; + +import java.lang.annotation.*; +import java.lang.reflect.*; +import java.util.*; + +import org.junit.*; + +import com.oracle.jvmci.meta.*; + +/** + * Tests for {@link ResolvedJavaField}. + */ +public class TestResolvedJavaField extends FieldUniverse { + + public TestResolvedJavaField() { + } + + @Test + public void getModifiersTest() { + for (Map.Entry e : fields.entrySet()) { + int expected = e.getKey().getModifiers(); + int actual = e.getValue().getModifiers(); + assertEquals(expected, actual); + } + } + + @Test + public void isSyntheticTest() { + for (Map.Entry e : fields.entrySet()) { + boolean expected = e.getKey().isSynthetic(); + boolean actual = e.getValue().isSynthetic(); + assertEquals(expected, actual); + } + } + + @Test + public void getAnnotationTest() { + for (Map.Entry e : fields.entrySet()) { + for (Annotation expected : e.getKey().getAnnotations()) { + if (expected != null) { + Annotation actual = e.getValue().getAnnotation(expected.annotationType()); + assertEquals(expected, actual); + } + } + } + } + + @Test + public void getLocationIdentityTest() { + for (Map.Entry e : fields.entrySet()) { + LocationIdentity identity = e.getValue().getLocationIdentity(); + assertTrue(identity != null); + } + } + + static class ReadConstantValueTestConstants { + String stringField = "field"; + final String constantStringField = "constantField"; + + static final Object CONST1 = new ReadConstantValueTestConstants(); + static final Object CONST2 = null; + static final Object CONST3 = new String(); + } + + @Test + public void readConstantValueTest() throws NoSuchFieldException { + ResolvedJavaField field = metaAccess.lookupJavaField(ReadConstantValueTestConstants.class.getDeclaredField("stringField")); + List receiverConstants = readConstants(ReadConstantValueTestConstants.class); + for (ConstantValue receiver : receiverConstants) { + JavaConstant value = constantReflection.readConstantFieldValue(field, receiver.value); + assertNull(value); + } + + ResolvedJavaField constField = metaAccess.lookupJavaField(ReadConstantValueTestConstants.class.getDeclaredField("constantStringField")); + for (ConstantValue receiver : receiverConstants) { + JavaConstant value = constantReflection.readConstantFieldValue(constField, receiver.value); + if (value != null) { + Object expected = "constantField"; + String actual = ((ReadConstantValueTestConstants) receiver.boxed).constantStringField; + assertTrue(actual + " != " + expected, actual == expected); + } + } + } + + private Method findTestMethod(Method apiMethod) { + String testName = apiMethod.getName() + "Test"; + for (Method m : getClass().getDeclaredMethods()) { + if (m.getName().equals(testName) && m.getAnnotation(Test.class) != null) { + return m; + } + } + return null; + } + + // @formatter:off + private static final String[] untestedApiMethods = { + "getDeclaringClass", + "isInternal" + }; + // @formatter:on + + /** + * Ensures that any new methods added to {@link ResolvedJavaMethod} either have a test written + * for them or are added to {@link #untestedApiMethods}. + */ + @Test + public void testCoverage() { + Set known = new HashSet<>(Arrays.asList(untestedApiMethods)); + for (Method m : ResolvedJavaField.class.getDeclaredMethods()) { + if (m.isSynthetic()) { + continue; + } + if (findTestMethod(m) == null) { + assertTrue("test missing for " + m, known.contains(m.getName())); + } else { + assertFalse("test should be removed from untestedApiMethods" + m, known.contains(m.getName())); + } + } + } +} diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/TestResolvedJavaMethod.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/TestResolvedJavaMethod.java Thu Jun 04 11:08:12 2015 -0700 @@ -0,0 +1,381 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.jvmci.runtime.test; + +import com.oracle.jvmci.meta.ExceptionHandler; +import com.oracle.jvmci.meta.ResolvedJavaMethod; +import com.oracle.jvmci.meta.ConstantPool; +import static org.junit.Assert.*; + +import java.lang.annotation.*; +import java.lang.reflect.*; +import java.util.*; + +import org.junit.*; + +/** + * Tests for {@link ResolvedJavaMethod}. + */ +public class TestResolvedJavaMethod extends MethodUniverse { + + public TestResolvedJavaMethod() { + } + + /** + * @see ResolvedJavaMethod#getCode() + */ + @Test + public void getCodeTest() { + for (Map.Entry e : methods.entrySet()) { + ResolvedJavaMethod m = e.getValue(); + byte[] code = m.getCode(); + if (code == null) { + assertTrue(m.getCodeSize() == 0); + } else { + if (m.isAbstract()) { + assertTrue(code.length == 0); + } else if (!m.isNative()) { + assertTrue(code.length > 0); + } + } + } + } + + /** + * @see ResolvedJavaMethod#getCodeSize() + */ + @Test + public void getCodeSizeTest() { + for (Map.Entry e : methods.entrySet()) { + ResolvedJavaMethod m = e.getValue(); + int codeSize = m.getCodeSize(); + if (m.isAbstract()) { + assertTrue(codeSize == 0); + } else if (!m.isNative()) { + assertTrue(codeSize > 0); + } + } + } + + @Test + public void getModifiersTest() { + for (Map.Entry e : methods.entrySet()) { + ResolvedJavaMethod m = e.getValue(); + int expected = e.getKey().getModifiers() & Modifier.methodModifiers(); + int actual = m.getModifiers(); + assertEquals(expected, actual); + } + } + + /** + * @see ResolvedJavaMethod#isClassInitializer() + */ + @Test + public void isClassInitializerTest() { + for (Map.Entry e : methods.entrySet()) { + // Class initializers are hidden from reflection + ResolvedJavaMethod m = e.getValue(); + assertFalse(m.isClassInitializer()); + } + for (Map.Entry, ResolvedJavaMethod> e : constructors.entrySet()) { + ResolvedJavaMethod m = e.getValue(); + assertFalse(m.isClassInitializer()); + } + } + + @Test + public void isConstructorTest() { + for (Map.Entry e : methods.entrySet()) { + ResolvedJavaMethod m = e.getValue(); + assertFalse(m.isConstructor()); + } + for (Map.Entry, ResolvedJavaMethod> e : constructors.entrySet()) { + ResolvedJavaMethod m = e.getValue(); + assertTrue(m.isConstructor()); + } + } + + @Test + public void isSyntheticTest() { + for (Map.Entry e : methods.entrySet()) { + ResolvedJavaMethod m = e.getValue(); + assertEquals(e.getKey().isSynthetic(), m.isSynthetic()); + } + for (Map.Entry, ResolvedJavaMethod> e : constructors.entrySet()) { + ResolvedJavaMethod m = e.getValue(); + assertEquals(e.getKey().isSynthetic(), m.isSynthetic()); + } + } + + @Test + public void isSynchronizedTest() { + for (Map.Entry e : methods.entrySet()) { + ResolvedJavaMethod m = e.getValue(); + assertEquals(Modifier.isSynchronized(e.getKey().getModifiers()), m.isSynchronized()); + } + for (Map.Entry, ResolvedJavaMethod> e : constructors.entrySet()) { + ResolvedJavaMethod m = e.getValue(); + assertEquals(Modifier.isSynchronized(e.getKey().getModifiers()), m.isSynchronized()); + } + } + + @Test + public void canBeStaticallyBoundTest() { + for (Map.Entry e : methods.entrySet()) { + ResolvedJavaMethod m = e.getValue(); + assertEquals(m.canBeStaticallyBound(), canBeStaticallyBound(e.getKey())); + } + for (Map.Entry, ResolvedJavaMethod> e : constructors.entrySet()) { + ResolvedJavaMethod m = e.getValue(); + assertEquals(m.canBeStaticallyBound(), canBeStaticallyBound(e.getKey())); + } + } + + private static boolean canBeStaticallyBound(Member method) { + int modifiers = method.getModifiers(); + return (Modifier.isFinal(modifiers) || Modifier.isPrivate(modifiers) || Modifier.isStatic(modifiers) || Modifier.isFinal(method.getDeclaringClass().getModifiers())) && + !Modifier.isAbstract(modifiers); + } + + private static String methodWithExceptionHandlers(String p1, Object o2) { + try { + return p1.substring(100) + o2.toString(); + } catch (IndexOutOfBoundsException e) { + e.printStackTrace(); + } catch (NullPointerException e) { + e.printStackTrace(); + } catch (RuntimeException e) { + e.printStackTrace(); + } + return null; + } + + @Test + public void getExceptionHandlersTest() throws NoSuchMethodException { + ResolvedJavaMethod method = metaAccess.lookupJavaMethod(getClass().getDeclaredMethod("methodWithExceptionHandlers", String.class, Object.class)); + ExceptionHandler[] handlers = method.getExceptionHandlers(); + assertNotNull(handlers); + assertEquals(handlers.length, 3); + handlers[0].getCatchType().equals(metaAccess.lookupJavaType(IndexOutOfBoundsException.class)); + handlers[1].getCatchType().equals(metaAccess.lookupJavaType(NullPointerException.class)); + handlers[2].getCatchType().equals(metaAccess.lookupJavaType(RuntimeException.class)); + } + + private static String nullPointerExceptionOnFirstLine(Object o, String ignored) { + return o.toString() + ignored; + } + + @Test + public void asStackTraceElementTest() throws NoSuchMethodException { + try { + nullPointerExceptionOnFirstLine(null, "ignored"); + Assert.fail("should not reach here"); + } catch (NullPointerException e) { + StackTraceElement expected = e.getStackTrace()[0]; + ResolvedJavaMethod method = metaAccess.lookupJavaMethod(getClass().getDeclaredMethod("nullPointerExceptionOnFirstLine", Object.class, String.class)); + StackTraceElement actual = method.asStackTraceElement(0); + assertEquals(expected, actual); + } + } + + @Test + public void getConstantPoolTest() { + for (Map.Entry e : methods.entrySet()) { + ResolvedJavaMethod m = e.getValue(); + ConstantPool cp = m.getConstantPool(); + assertTrue(cp.length() > 0); + } + } + + @Test(timeout = 1000L) + public void getAnnotationTest() throws NoSuchMethodException { + ResolvedJavaMethod method = metaAccess.lookupJavaMethod(getClass().getDeclaredMethod("getAnnotationTest")); + Test annotation = method.getAnnotation(Test.class); + assertNotNull(annotation); + assertEquals(1000L, annotation.timeout()); + } + + @Test(timeout = 1000L) + public void getAnnotationsTest() throws NoSuchMethodException { + ResolvedJavaMethod method = metaAccess.lookupJavaMethod(getClass().getDeclaredMethod("getAnnotationsTest")); + Annotation[] annotations = method.getAnnotations(); + assertNotNull(annotations); + assertEquals(1, annotations.length); + assertEquals(1000L, ((Test) annotations[0]).timeout()); + } + + @Retention(RetentionPolicy.RUNTIME) + @Target(ElementType.PARAMETER) + @interface NonNull { + } + + @Retention(RetentionPolicy.RUNTIME) + @Target(ElementType.PARAMETER) + @interface Special { + } + + private static native void methodWithAnnotatedParameters(@NonNull HashMap p1, @Special @NonNull Class p2); + + @Test + public void getParameterAnnotationsTest() throws NoSuchMethodException { + ResolvedJavaMethod method = metaAccess.lookupJavaMethod(getClass().getDeclaredMethod("methodWithAnnotatedParameters", HashMap.class, Class.class)); + Annotation[][] annotations = method.getParameterAnnotations(); + assertEquals(2, annotations.length); + assertEquals(1, annotations[0].length); + assertEquals(NonNull.class, annotations[0][0].annotationType()); + assertEquals(2, annotations[1].length); + assertEquals(Special.class, annotations[1][0].annotationType()); + assertEquals(NonNull.class, annotations[1][1].annotationType()); + } + + @Test + public void getGenericParameterTypesTest() throws NoSuchMethodException { + ResolvedJavaMethod method = metaAccess.lookupJavaMethod(getClass().getDeclaredMethod("methodWithAnnotatedParameters", HashMap.class, Class.class)); + Type[] genericParameterTypes = method.getGenericParameterTypes(); + assertEquals(2, genericParameterTypes.length); + assertEquals("java.util.HashMap", genericParameterTypes[0].toString()); + assertEquals("java.lang.Class", genericParameterTypes[1].toString()); + } + + @Test + public void getMaxLocalsTest() throws NoSuchMethodException { + ResolvedJavaMethod method1 = metaAccess.lookupJavaMethod(getClass().getDeclaredMethod("methodWithAnnotatedParameters", HashMap.class, Class.class)); + ResolvedJavaMethod method2 = metaAccess.lookupJavaMethod(getClass().getDeclaredMethod("nullPointerExceptionOnFirstLine", Object.class, String.class)); + assertEquals(0, method1.getMaxLocals()); + assertEquals(2, method2.getMaxLocals()); + + } + + @Test + public void getMaxStackSizeTest() throws NoSuchMethodException { + ResolvedJavaMethod method1 = metaAccess.lookupJavaMethod(getClass().getDeclaredMethod("methodWithAnnotatedParameters", HashMap.class, Class.class)); + ResolvedJavaMethod method2 = metaAccess.lookupJavaMethod(getClass().getDeclaredMethod("nullPointerExceptionOnFirstLine", Object.class, String.class)); + assertEquals(0, method1.getMaxStackSize()); + // some versions of javac produce bytecode with a stacksize of 2 for this method + // JSR 292 also sometimes need one more stack slot + int method2StackSize = method2.getMaxStackSize(); + assertTrue(2 <= method2StackSize && method2StackSize <= 4); + } + + @Test + public void isDefaultTest() { + for (Map.Entry e : methods.entrySet()) { + ResolvedJavaMethod m = e.getValue(); + assertEquals(e.getKey().isDefault(), m.isDefault()); + } + for (Map.Entry, ResolvedJavaMethod> e : constructors.entrySet()) { + ResolvedJavaMethod m = e.getValue(); + assertFalse(m.isDefault()); + } + } + + @Test + public void hasReceiverTest() { + for (Map.Entry e : methods.entrySet()) { + ResolvedJavaMethod m = e.getValue(); + assertTrue(m.hasReceiver() != Modifier.isStatic(e.getKey().getModifiers())); + } + for (Map.Entry, ResolvedJavaMethod> e : constructors.entrySet()) { + ResolvedJavaMethod m = e.getValue(); + assertTrue(m.hasReceiver()); + } + } + + @Test + public void hasBytecodesTest() { + for (Map.Entry e : methods.entrySet()) { + ResolvedJavaMethod m = e.getValue(); + assertTrue(m.hasBytecodes() == (m.isConcrete() && !m.isNative())); + } + for (Map.Entry, ResolvedJavaMethod> e : constructors.entrySet()) { + ResolvedJavaMethod m = e.getValue(); + assertTrue(m.hasBytecodes()); + } + } + + @Test + public void isJavaLangObjectInitTest() throws NoSuchMethodException { + ResolvedJavaMethod method = metaAccess.lookupJavaMethod(Object.class.getConstructor()); + assertTrue(method.isJavaLangObjectInit()); + for (Map.Entry e : methods.entrySet()) { + ResolvedJavaMethod m = e.getValue(); + assertFalse(m.isJavaLangObjectInit()); + } + for (Map.Entry, ResolvedJavaMethod> e : constructors.entrySet()) { + ResolvedJavaMethod m = e.getValue(); + Constructor key = e.getKey(); + if (key.getDeclaringClass() == Object.class && key.getParameters().length == 0) { + assertTrue(m.isJavaLangObjectInit()); + } else { + assertFalse(m.isJavaLangObjectInit()); + } + } + } + + private Method findTestMethod(Method apiMethod) { + String testName = apiMethod.getName() + "Test"; + for (Method m : getClass().getDeclaredMethods()) { + if (m.getName().equals(testName) && m.getAnnotation(Test.class) != null) { + return m; + } + } + return null; + } + + // @formatter:off + private static final String[] untestedApiMethods = { + "invoke", + "newInstance", + "getDeclaringClass", + "getEncoding", + "getProfilingInfo", + "reprofile", + "getCompilerStorage", + "canBeInlined", + "shouldBeInlined", + "getLineNumberTable", + "getLocalVariableTable", + "isInVirtualMethodTable", + "toParameterTypes", + "getParameterAnnotation", + "getSpeculationLog", + "$jacocoInit" + }; + // @formatter:on + + /** + * Ensures that any new methods added to {@link ResolvedJavaMethod} either have a test written + * for them or are added to {@link #untestedApiMethods}. + */ + @Test + public void testCoverage() { + Set known = new HashSet<>(Arrays.asList(untestedApiMethods)); + for (Method m : ResolvedJavaMethod.class.getDeclaredMethods()) { + if (findTestMethod(m) == null) { + assertTrue("test missing for " + m, known.contains(m.getName())); + } else { + assertFalse("test should be removed from untestedApiMethods" + m, known.contains(m.getName())); + } + } + } +} diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/TestResolvedJavaType.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/TestResolvedJavaType.java Thu Jun 04 11:08:12 2015 -0700 @@ -0,0 +1,874 @@ +/* + * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.jvmci.runtime.test; + +import static java.lang.reflect.Modifier.*; +import static org.junit.Assert.*; + +import java.lang.annotation.*; +import java.lang.reflect.*; +import java.net.*; +import java.util.*; + +import org.junit.*; + +import sun.reflect.ConstantPool; + +import com.oracle.jvmci.common.*; +import com.oracle.jvmci.meta.Assumptions.AssumptionResult; +import com.oracle.jvmci.meta.*; + +/** + * Tests for {@link ResolvedJavaType}. + */ +public class TestResolvedJavaType extends TypeUniverse { + + public TestResolvedJavaType() { + } + + @Test + public void findInstanceFieldWithOffsetTest() { + for (Class c : classes) { + ResolvedJavaType type = metaAccess.lookupJavaType(c); + Set reflectionFields = getInstanceFields(c, true); + for (Field f : reflectionFields) { + ResolvedJavaField rf = lookupField(type.getInstanceFields(true), f); + assertNotNull(rf); + long offset = isStatic(f.getModifiers()) ? unsafe.staticFieldOffset(f) : unsafe.objectFieldOffset(f); + ResolvedJavaField result = type.findInstanceFieldWithOffset(offset, rf.getKind()); + assertNotNull(result); + assertTrue(fieldsEqual(f, result)); + } + } + } + + @Test + public void isInterfaceTest() { + for (Class c : classes) { + ResolvedJavaType type = metaAccess.lookupJavaType(c); + boolean expected = c.isInterface(); + boolean actual = type.isInterface(); + assertEquals(expected, actual); + } + } + + @Test + public void isInstanceClassTest() { + for (Class c : classes) { + ResolvedJavaType type = metaAccess.lookupJavaType(c); + boolean expected = !c.isArray() && !c.isPrimitive() && !c.isInterface(); + boolean actual = type.isInstanceClass(); + assertEquals(expected, actual); + } + } + + @Test + public void isArrayTest() { + for (Class c : classes) { + ResolvedJavaType type = metaAccess.lookupJavaType(c); + boolean expected = c.isArray(); + boolean actual = type.isArray(); + assertEquals(expected, actual); + } + } + + @Test + public void getModifiersTest() { + for (Class c : classes) { + ResolvedJavaType type = metaAccess.lookupJavaType(c); + int expected = c.getModifiers(); + int actual = type.getModifiers(); + assertEquals(expected, actual); + } + } + + @Test + public void isAssignableFromTest() { + Class[] all = classes.toArray(new Class[classes.size()]); + for (int i = 0; i < all.length; i++) { + Class c1 = all[i]; + for (int j = i; j < all.length; j++) { + Class c2 = all[j]; + ResolvedJavaType t1 = metaAccess.lookupJavaType(c1); + ResolvedJavaType t2 = metaAccess.lookupJavaType(c2); + boolean expected = c1.isAssignableFrom(c2); + boolean actual = t1.isAssignableFrom(t2); + assertEquals(expected, actual); + if (expected && t1 != t2) { + assertFalse(t2.isAssignableFrom(t1)); + } + } + } + } + + @Test + public void isInstanceTest() { + for (ConstantValue cv : constants()) { + JavaConstant c = cv.value; + if (c.getKind() == Kind.Object && !c.isNull()) { + ResolvedJavaType cType = metaAccess.lookupJavaType(c); + for (ResolvedJavaType t : javaTypes) { + if (t.isAssignableFrom(cType)) { + assertTrue(t.isInstance(c)); + } else { + assertFalse(t.isInstance(c)); + } + } + } + } + } + + private static Class asExactClass(Class c) { + if (c.isArray()) { + if (asExactClass(c.getComponentType()) != null) { + return c; + } + } else { + if (c.isPrimitive() || Modifier.isFinal(c.getModifiers())) { + return c; + } + } + return null; + } + + @Test + public void asExactTypeTest() { + for (Class c : classes) { + ResolvedJavaType type = metaAccess.lookupJavaType(c); + ResolvedJavaType exactType = type.asExactType(); + Class expected = asExactClass(c); + if (expected == null) { + assertTrue("exact(" + c.getName() + ") != null", exactType == null); + } else { + assertNotNull(exactType); + assertTrue(exactType.equals(metaAccess.lookupJavaType(expected))); + } + } + } + + @Test + public void getSuperclassTest() { + for (Class c : classes) { + ResolvedJavaType type = metaAccess.lookupJavaType(c); + Class expected = c.getSuperclass(); + ResolvedJavaType actual = type.getSuperclass(); + if (expected == null) { + assertTrue(actual == null); + } else { + assertNotNull(actual); + assertTrue(actual.equals(metaAccess.lookupJavaType(expected))); + } + } + } + + @Test + public void getInterfacesTest() { + for (Class c : classes) { + ResolvedJavaType type = metaAccess.lookupJavaType(c); + Class[] expected = c.getInterfaces(); + ResolvedJavaType[] actual = type.getInterfaces(); + assertEquals(expected.length, actual.length); + for (int i = 0; i < expected.length; i++) { + assertTrue(actual[i].equals(metaAccess.lookupJavaType(expected[i]))); + } + } + } + + public Class getSupertype(Class c) { + assert !c.isPrimitive(); + if (c.isArray()) { + Class componentType = c.getComponentType(); + if (componentType.isPrimitive() || componentType == Object.class) { + return Object.class; + } + return getArrayClass(getSupertype(componentType)); + } + if (c.isInterface()) { + return Object.class; + } + return c.getSuperclass(); + } + + public Class findLeastCommonAncestor(Class c1Initial, Class c2Initial) { + if (c1Initial.isPrimitive() || c2Initial.isPrimitive()) { + return null; + } else { + Class c1 = c1Initial; + Class c2 = c2Initial; + while (true) { + if (c1.isAssignableFrom(c2)) { + return c1; + } + if (c2.isAssignableFrom(c1)) { + return c2; + } + c1 = getSupertype(c1); + c2 = getSupertype(c2); + } + } + } + + @Test + public void findLeastCommonAncestorTest() { + Class[] all = classes.toArray(new Class[classes.size()]); + for (int i = 0; i < all.length; i++) { + Class c1 = all[i]; + for (int j = i; j < all.length; j++) { + Class c2 = all[j]; + ResolvedJavaType t1 = metaAccess.lookupJavaType(c1); + ResolvedJavaType t2 = metaAccess.lookupJavaType(c2); + Class expected = findLeastCommonAncestor(c1, c2); + ResolvedJavaType actual = t1.findLeastCommonAncestor(t2); + if (expected == null) { + assertTrue(actual == null); + } else { + assertNotNull(actual); + assertTrue(actual.equals(metaAccess.lookupJavaType(expected))); + } + } + } + } + + private static class Base { + } + + abstract static class Abstract1 extends Base { + } + + interface Interface1 { + } + + static class Concrete1 extends Abstract1 { + } + + static class Concrete2 extends Abstract1 implements Interface1 { + } + + static class Concrete3 extends Concrete2 { + } + + static final class Final1 extends Abstract1 { + } + + abstract static class Abstract4 extends Concrete3 { + } + + void checkConcreteSubtype(ResolvedJavaType type, ResolvedJavaType expected) { + AssumptionResult leafConcreteSubtype = type.findLeafConcreteSubtype(); + if (leafConcreteSubtype == null) { + // findLeafConcreteSubtype() is conservative + } else { + if (expected == null) { + assertNull(leafConcreteSubtype); + } else { + assertTrue(leafConcreteSubtype.getResult().equals(expected)); + } + } + + if (!type.isArray()) { + ResolvedJavaType arrayType = type.getArrayClass(); + AssumptionResult arraySubtype = arrayType.findLeafConcreteSubtype(); + if (arraySubtype != null) { + assertEquals(arraySubtype.getResult(), arrayType); + } else { + // findLeafConcreteSubtype() method is conservative + } + } + } + + @Test + public void findLeafConcreteSubtypeTest() { + ResolvedJavaType base = metaAccess.lookupJavaType(Base.class); + checkConcreteSubtype(base, base); + + ResolvedJavaType a1 = metaAccess.lookupJavaType(Abstract1.class); + ResolvedJavaType c1 = metaAccess.lookupJavaType(Concrete1.class); + + checkConcreteSubtype(base, null); + checkConcreteSubtype(a1, c1); + checkConcreteSubtype(c1, c1); + + ResolvedJavaType i1 = metaAccess.lookupJavaType(Interface1.class); + ResolvedJavaType c2 = metaAccess.lookupJavaType(Concrete2.class); + + checkConcreteSubtype(base, null); + checkConcreteSubtype(a1, null); + checkConcreteSubtype(c1, c1); + checkConcreteSubtype(i1, c2); + checkConcreteSubtype(c2, c2); + + ResolvedJavaType c3 = metaAccess.lookupJavaType(Concrete3.class); + checkConcreteSubtype(c2, null); + checkConcreteSubtype(c3, c3); + + ResolvedJavaType a4 = metaAccess.lookupJavaType(Abstract4.class); + checkConcreteSubtype(c3, null); + checkConcreteSubtype(a4, null); + + ResolvedJavaType a1a = metaAccess.lookupJavaType(Abstract1[].class); + checkConcreteSubtype(a1a, null); + ResolvedJavaType c1a = metaAccess.lookupJavaType(Concrete1[].class); + checkConcreteSubtype(c1a, null); + ResolvedJavaType f1a = metaAccess.lookupJavaType(Final1[].class); + checkConcreteSubtype(f1a, f1a); + + ResolvedJavaType obja = metaAccess.lookupJavaType(Object[].class); + checkConcreteSubtype(obja, null); + + ResolvedJavaType inta = metaAccess.lookupJavaType(int[].class); + checkConcreteSubtype(inta, inta); + } + + interface NoImplementor { + } + + interface SingleImplementorInterface { + } + + static class SingleConcreteImplementor implements SingleImplementorInterface { + } + + interface SingleAbstractImplementorInterface { + } + + abstract static class SingleAbstractImplementor implements SingleAbstractImplementorInterface { + } + + interface MultiImplementorInterface { + } + + static class ConcreteImplementor1 implements MultiImplementorInterface { + } + + static class ConcreteImplementor2 implements MultiImplementorInterface { + } + + interface MultipleAbstractImplementorInterface { + } + + abstract static class MultiAbstractImplementor1 implements MultipleAbstractImplementorInterface { + } + + abstract static class MultiAbstractImplementor2 implements MultipleAbstractImplementorInterface { + } + + interface SingleAbstractImplementorInterface2 { + } + + interface ExtendedSingleImplementorInterface { + } + + abstract static class SingleAbstractImplementor2 implements SingleAbstractImplementorInterface2 { + } + + static class ConcreteTransitiveImplementor1 extends SingleAbstractImplementor2 implements ExtendedSingleImplementorInterface { + } + + static class ConcreteTransitiveImplementor2 extends SingleAbstractImplementor2 implements ExtendedSingleImplementorInterface { + } + + @Test + public void getSingleImplementorTest() { + ResolvedJavaType iNi = metaAccess.lookupJavaType(NoImplementor.class); + assertNull(iNi.getSingleImplementor()); + + ResolvedJavaType iSi = metaAccess.lookupJavaType(SingleImplementorInterface.class); + ResolvedJavaType cSi = metaAccess.lookupJavaType(SingleConcreteImplementor.class); + assertEquals(cSi, iSi.getSingleImplementor()); + + ResolvedJavaType iSai = metaAccess.lookupJavaType(SingleAbstractImplementorInterface.class); + ResolvedJavaType aSai = metaAccess.lookupJavaType(SingleAbstractImplementor.class); + assertEquals(aSai, iSai.getSingleImplementor()); + + ResolvedJavaType iMi = metaAccess.lookupJavaType(MultiImplementorInterface.class); + metaAccess.lookupJavaType(ConcreteImplementor1.class); + metaAccess.lookupJavaType(ConcreteImplementor2.class); + assertEquals(iMi, iMi.getSingleImplementor()); + + ResolvedJavaType iMai = metaAccess.lookupJavaType(MultipleAbstractImplementorInterface.class); + metaAccess.lookupJavaType(MultiAbstractImplementor1.class); + metaAccess.lookupJavaType(MultiAbstractImplementor2.class); + assertEquals(iMai, iMai.getSingleImplementor()); + + ResolvedJavaType iSai2 = metaAccess.lookupJavaType(SingleAbstractImplementorInterface2.class); + ResolvedJavaType aSai2 = metaAccess.lookupJavaType(SingleAbstractImplementor2.class); + metaAccess.lookupJavaType(ConcreteTransitiveImplementor1.class); + metaAccess.lookupJavaType(ConcreteTransitiveImplementor2.class); + assertEquals(aSai2, iSai2.getSingleImplementor()); + } + + @Test(expected = JVMCIError.class) + public void getSingleImplementorTestClassReceiver() { + ResolvedJavaType base = metaAccess.lookupJavaType(Base.class); + base.getSingleImplementor(); + } + + @Test(expected = JVMCIError.class) + public void getSingleImplementorTestPrimitiveReceiver() { + ResolvedJavaType primitive = metaAccess.lookupJavaType(int.class); + primitive.getSingleImplementor(); + } + + @Test + public void getComponentTypeTest() { + for (Class c : classes) { + ResolvedJavaType type = metaAccess.lookupJavaType(c); + Class expected = c.getComponentType(); + ResolvedJavaType actual = type.getComponentType(); + if (expected == null) { + assertNull(actual); + } else { + assertTrue(actual.equals(metaAccess.lookupJavaType(expected))); + } + } + } + + @Test + public void getArrayClassTest() { + for (Class c : classes) { + if (c != void.class) { + ResolvedJavaType type = metaAccess.lookupJavaType(c); + Class expected = getArrayClass(c); + ResolvedJavaType actual = type.getArrayClass(); + assertTrue(actual.equals(metaAccess.lookupJavaType(expected))); + } + } + } + + static class Declarations { + + final Method implementation; + final Set declarations; + + public Declarations(Method impl) { + this.implementation = impl; + declarations = new HashSet<>(); + } + } + + /** + * See
Method + * overriding. + */ + static boolean isOverriderOf(Method impl, Method m) { + if (!isPrivate(m.getModifiers()) && !isFinal(m.getModifiers())) { + if (m.getName().equals(impl.getName())) { + if (m.getReturnType() == impl.getReturnType()) { + if (Arrays.equals(m.getParameterTypes(), impl.getParameterTypes())) { + if (isPublic(m.getModifiers()) || isProtected(m.getModifiers())) { + // m is public or protected + return isPublic(impl.getModifiers()) || isProtected(impl.getModifiers()); + } else { + // m is package-private + return impl.getDeclaringClass().getPackage() == m.getDeclaringClass().getPackage(); + } + } + } + } + } + return false; + } + + static final Map, VTable> vtables = new HashMap<>(); + + static class VTable { + + final Map methods = new HashMap<>(); + } + + static synchronized VTable getVTable(Class c) { + VTable vtable = vtables.get(c); + if (vtable == null) { + vtable = new VTable(); + if (c != Object.class) { + VTable superVtable = getVTable(c.getSuperclass()); + vtable.methods.putAll(superVtable.methods); + } + for (Method m : c.getDeclaredMethods()) { + if (!isStatic(m.getModifiers()) && !isPrivate(m.getModifiers())) { + if (isAbstract(m.getModifiers())) { + // A subclass makes a concrete method in a superclass abstract + vtable.methods.remove(new NameAndSignature(m)); + } else { + vtable.methods.put(new NameAndSignature(m), m); + } + } + } + vtables.put(c, vtable); + } + return vtable; + } + + static Set findDeclarations(Method impl, Class c) { + Set declarations = new HashSet<>(); + NameAndSignature implSig = new NameAndSignature(impl); + if (c != null) { + for (Method m : c.getDeclaredMethods()) { + if (new NameAndSignature(m).equals(implSig)) { + declarations.add(m); + break; + } + } + if (!c.isInterface()) { + declarations.addAll(findDeclarations(impl, c.getSuperclass())); + } + for (Class i : c.getInterfaces()) { + declarations.addAll(findDeclarations(impl, i)); + } + } + return declarations; + } + + private static void checkResolveMethod(ResolvedJavaType type, ResolvedJavaType context, ResolvedJavaMethod decl, ResolvedJavaMethod expected) { + ResolvedJavaMethod impl = type.resolveConcreteMethod(decl, context); + assertEquals(expected, impl); + } + + @Test + public void resolveMethodTest() { + ResolvedJavaType context = metaAccess.lookupJavaType(TestResolvedJavaType.class); + for (Class c : classes) { + if (c.isInterface() || c.isPrimitive()) { + ResolvedJavaType type = metaAccess.lookupJavaType(c); + for (Method m : c.getDeclaredMethods()) { + if (JAVA_VERSION <= 1.7D || (!isStatic(m.getModifiers()) && !isPrivate(m.getModifiers()))) { + ResolvedJavaMethod resolved = metaAccess.lookupJavaMethod(m); + ResolvedJavaMethod impl = type.resolveMethod(resolved, context, true); + ResolvedJavaMethod expected = resolved.isDefault() || resolved.isAbstract() ? resolved : null; + assertEquals(m.toString(), expected, impl); + } else { + // As of JDK 8, interfaces can have static and private methods + } + } + } else { + ResolvedJavaType type = metaAccess.lookupJavaType(c); + VTable vtable = getVTable(c); + for (Method impl : vtable.methods.values()) { + Set decls = findDeclarations(impl, c); + for (Method decl : decls) { + ResolvedJavaMethod m = metaAccess.lookupJavaMethod(decl); + if (m.isPublic()) { + ResolvedJavaMethod i = metaAccess.lookupJavaMethod(impl); + checkResolveMethod(type, context, m, i); + } + } + } + } + } + } + + @Test + public void resolveConcreteMethodTest() { + ResolvedJavaType context = metaAccess.lookupJavaType(TestResolvedJavaType.class); + for (Class c : classes) { + if (c.isInterface() || c.isPrimitive()) { + ResolvedJavaType type = metaAccess.lookupJavaType(c); + for (Method m : c.getDeclaredMethods()) { + if (JAVA_VERSION <= 1.7D || (!isStatic(m.getModifiers()) && !isPrivate(m.getModifiers()))) { + ResolvedJavaMethod resolved = metaAccess.lookupJavaMethod(m); + ResolvedJavaMethod impl = type.resolveConcreteMethod(resolved, context); + ResolvedJavaMethod expected = resolved.isDefault() ? resolved : null; + assertEquals(m.toString(), expected, impl); + } else { + // As of JDK 8, interfaces can have static and private methods + } + } + } else { + ResolvedJavaType type = metaAccess.lookupJavaType(c); + VTable vtable = getVTable(c); + for (Method impl : vtable.methods.values()) { + Set decls = findDeclarations(impl, c); + for (Method decl : decls) { + ResolvedJavaMethod m = metaAccess.lookupJavaMethod(decl); + if (m.isPublic()) { + ResolvedJavaMethod i = metaAccess.lookupJavaMethod(impl); + checkResolveMethod(type, context, m, i); + } + } + } + for (Method m : c.getDeclaredMethods()) { + ResolvedJavaMethod impl = type.resolveConcreteMethod(metaAccess.lookupJavaMethod(m), context); + ResolvedJavaMethod expected = isAbstract(m.getModifiers()) ? null : impl; + assertEquals(type + " " + m.toString(), expected, impl); + } + } + } + } + + @Test + public void findUniqueConcreteMethodTest() throws NoSuchMethodException { + ResolvedJavaMethod thisMethod = metaAccess.lookupJavaMethod(getClass().getDeclaredMethod("findUniqueConcreteMethodTest")); + ResolvedJavaMethod ucm = metaAccess.lookupJavaType(getClass()).findUniqueConcreteMethod(thisMethod).getResult(); + assertEquals(thisMethod, ucm); + } + + public static Set getInstanceFields(Class c, boolean includeSuperclasses) { + if (c.isArray() || c.isPrimitive() || c.isInterface()) { + return Collections.emptySet(); + } + Set result = new HashSet<>(); + for (Field f : c.getDeclaredFields()) { + if (!Modifier.isStatic(f.getModifiers())) { + result.add(f); + } + } + if (includeSuperclasses && c != Object.class) { + result.addAll(getInstanceFields(c.getSuperclass(), true)); + } + return result; + } + + public static Set getStaticFields(Class c) { + Set result = new HashSet<>(); + for (Field f : c.getDeclaredFields()) { + if (Modifier.isStatic(f.getModifiers())) { + result.add(f); + } + } + return result; + } + + public boolean fieldsEqual(Field f, ResolvedJavaField rjf) { + return rjf.getDeclaringClass().equals(metaAccess.lookupJavaType(f.getDeclaringClass())) && rjf.getName().equals(f.getName()) && + rjf.getType().resolve(rjf.getDeclaringClass()).equals(metaAccess.lookupJavaType(f.getType())); + } + + public ResolvedJavaField lookupField(ResolvedJavaField[] fields, Field key) { + for (ResolvedJavaField rf : fields) { + if (fieldsEqual(key, rf)) { + return rf; + } + } + return null; + } + + public Field lookupField(Set fields, ResolvedJavaField key) { + for (Field f : fields) { + if (fieldsEqual(f, key)) { + return f; + } + } + return null; + } + + private static boolean isHiddenFromReflection(ResolvedJavaField f) { + if (f.getDeclaringClass().equals(metaAccess.lookupJavaType(Throwable.class)) && f.getName().equals("backtrace")) { + return true; + } + if (f.getDeclaringClass().equals(metaAccess.lookupJavaType(ConstantPool.class)) && f.getName().equals("constantPoolOop")) { + return true; + } + if (f.getDeclaringClass().equals(metaAccess.lookupJavaType(Class.class)) && f.getName().equals("classLoader")) { + return true; + } + return false; + } + + @Test + public void getInstanceFieldsTest() { + for (Class c : classes) { + ResolvedJavaType type = metaAccess.lookupJavaType(c); + for (boolean includeSuperclasses : new boolean[]{true, false}) { + Set expected = getInstanceFields(c, includeSuperclasses); + ResolvedJavaField[] actual = type.getInstanceFields(includeSuperclasses); + for (Field f : expected) { + assertNotNull(lookupField(actual, f)); + } + for (ResolvedJavaField rf : actual) { + if (!isHiddenFromReflection(rf)) { + assertEquals(rf.toString(), lookupField(expected, rf) != null, !rf.isInternal()); + } + } + + // Test stability of getInstanceFields + ResolvedJavaField[] actual2 = type.getInstanceFields(includeSuperclasses); + assertArrayEquals(actual, actual2); + } + } + } + + @Test + public void getStaticFieldsTest() { + for (Class c : classes) { + ResolvedJavaType type = metaAccess.lookupJavaType(c); + Set expected = getStaticFields(c); + ResolvedJavaField[] actual = type.getStaticFields(); + for (Field f : expected) { + assertNotNull(lookupField(actual, f)); + } + for (ResolvedJavaField rf : actual) { + if (!isHiddenFromReflection(rf)) { + assertEquals(lookupField(expected, rf) != null, !rf.isInternal()); + } + } + + // Test stability of getStaticFields + ResolvedJavaField[] actual2 = type.getStaticFields(); + assertArrayEquals(actual, actual2); + } + } + + @Test + public void getDeclaredMethodsTest() { + for (Class c : classes) { + ResolvedJavaType type = metaAccess.lookupJavaType(c); + Method[] raw = c.getDeclaredMethods(); + Set expected = new HashSet<>(); + for (Method m : raw) { + ResolvedJavaMethod resolvedMethod = metaAccess.lookupJavaMethod(m); + assertNotNull(resolvedMethod); + expected.add(resolvedMethod); + } + Set actual = new HashSet<>(Arrays.asList(type.getDeclaredMethods())); + assertEquals(expected, actual); + } + } + + static class A { + static String name = "foo"; + } + + static class B extends A { + } + + static class C { + } + + static class D { + void foo() { + // use of assertions causes the class to have a + assert getClass() != null; + } + } + + @Test + public void getClassInitializerTest() { + assertNotNull(metaAccess.lookupJavaType(A.class).getClassInitializer()); + assertNotNull(metaAccess.lookupJavaType(D.class).getClassInitializer()); + assertNull(metaAccess.lookupJavaType(B.class).getClassInitializer()); + assertNull(metaAccess.lookupJavaType(C.class).getClassInitializer()); + assertNull(metaAccess.lookupJavaType(int.class).getClassInitializer()); + assertNull(metaAccess.lookupJavaType(void.class).getClassInitializer()); + } + + @Test + public void getAnnotationTest() { + for (Class c : classes) { + ResolvedJavaType type = metaAccess.lookupJavaType(c); + for (Annotation a : c.getAnnotations()) { + assertEquals(a, type.getAnnotation(a.annotationType())); + } + } + } + + @Test + public void memberClassesTest() { + for (Class c : classes) { + ResolvedJavaType type = metaAccess.lookupJavaType(c); + assertEquals(c.isLocalClass(), type.isLocal()); + assertEquals(c.isMemberClass(), type.isMember()); + Class enclc = c.getEnclosingClass(); + ResolvedJavaType enclt = type.getEnclosingType(); + assertFalse(enclc == null ^ enclt == null); + if (enclc != null) { + assertEquals(enclt, metaAccess.lookupJavaType(enclc)); + } + } + } + + @Test + public void classFilePathTest() { + for (Class c : classes) { + ResolvedJavaType type = metaAccess.lookupJavaType(c); + URL path = type.getClassFilePath(); + if (type.isPrimitive() || type.isArray()) { + assertEquals(null, path); + } else { + assertNotNull(path); + String pathString = path.getPath(); + if (type.isLocal() || type.isMember()) { + assertTrue(pathString.indexOf('$') > 0); + } + } + } + } + + @Test + public void isTrustedInterfaceTypeTest() { + for (Class c : classes) { + ResolvedJavaType type = metaAccess.lookupJavaType(c); + if (TrustedInterface.class.isAssignableFrom(c)) { + assertTrue(type.isTrustedInterfaceType()); + } + } + } + + private Method findTestMethod(Method apiMethod) { + String testName = apiMethod.getName() + "Test"; + for (Method m : getClass().getDeclaredMethods()) { + if (m.getName().equals(testName) && m.getAnnotation(Test.class) != null) { + return m; + } + } + return null; + } + + // @formatter:off + private static final String[] untestedApiMethods = { + "initialize", + "isPrimitive", + "newArray", + "getDeclaredConstructors", + "isInitialized", + "isLinked", + "getJavaClass", + "getObjectHub", + "hasFinalizableSubclass", + "hasFinalizer", + "getSourceFileName", + "getClassFilePath", + "isLocal", + "isJavaLangObject", + "isMember", + "getElementalType", + "getEnclosingType", + "$jacocoInit" + }; + // @formatter:on + + /** + * Ensures that any new methods added to {@link ResolvedJavaMethod} either have a test written + * for them or are added to {@link #untestedApiMethods}. + */ + @Test + public void testCoverage() { + Set known = new HashSet<>(Arrays.asList(untestedApiMethods)); + for (Method m : ResolvedJavaType.class.getDeclaredMethods()) { + if (findTestMethod(m) == null) { + assertTrue("test missing for " + m, known.contains(m.getName())); + } else { + assertFalse("test should be removed from untestedApiMethods" + m, known.contains(m.getName())); + } + } + } +} diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/TypeUniverse.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/TypeUniverse.java Thu Jun 04 11:08:12 2015 -0700 @@ -0,0 +1,205 @@ +/* + * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.jvmci.runtime.test; + +import static java.lang.reflect.Modifier.*; + +import java.io.*; +import java.lang.reflect.*; +import java.util.*; +import java.util.Queue; +import java.util.stream.*; + +import org.junit.*; + +import sun.misc.*; + +import com.oracle.jvmci.meta.*; +import com.oracle.jvmci.runtime.*; + +//JaCoCo Exclude + +/** + * Context for type related tests. + */ +public class TypeUniverse { + + public static final Unsafe unsafe; + public static final double JAVA_VERSION = Double.valueOf(System.getProperty("java.specification.version")); + + public static final MetaAccessProvider metaAccess = JVMCI.getRuntime().getHostJVMCIBackend().getMetaAccess(); + public static final ConstantReflectionProvider constantReflection = JVMCI.getRuntime().getHostJVMCIBackend().getConstantReflection(); + public static final Collection> classes = new HashSet<>(); + public static final Set javaTypes; + public static final Map, Class> arrayClasses = new HashMap<>(); + + private static List constants; + + static { + Unsafe theUnsafe = null; + try { + theUnsafe = Unsafe.getUnsafe(); + } catch (Exception e) { + try { + Field theUnsafeField = Unsafe.class.getDeclaredField("theUnsafe"); + theUnsafeField.setAccessible(true); + theUnsafe = (Unsafe) theUnsafeField.get(null); + } catch (Exception e1) { + throw (InternalError) new InternalError("unable to initialize unsafe").initCause(e1); + } + } + unsafe = theUnsafe; + + Class[] initialClasses = {void.class, boolean.class, byte.class, short.class, char.class, int.class, float.class, long.class, double.class, Object.class, Class.class, ClassLoader.class, + String.class, Serializable.class, Cloneable.class, Test.class, TestMetaAccessProvider.class, List.class, Collection.class, Map.class, Queue.class, HashMap.class, + LinkedHashMap.class, IdentityHashMap.class, AbstractCollection.class, AbstractList.class, ArrayList.class, TrustedInterface.class}; + for (Class c : initialClasses) { + addClass(c); + } + + javaTypes = Collections.unmodifiableSet(classes.stream().map(c -> metaAccess.lookupJavaType(c)).collect(Collectors.toSet())); + } + + static class ConstantsUniverse { + static final Object[] ARRAYS = classes.stream().map(c -> c != void.class && !c.isArray() ? Array.newInstance(c, 42) : null).filter(o -> o != null).collect(Collectors.toList()).toArray(); + static final Object CONST1 = new ArrayList<>(); + static final Object CONST2 = new ArrayList<>(); + static final Object CONST3 = new IdentityHashMap<>(); + static final Object CONST4 = new LinkedHashMap<>(); + static final Object CONST5 = new TreeMap<>(); + static final Object CONST6 = new ArrayDeque<>(); + static final Object CONST7 = new LinkedList<>(); + static final Object CONST8 = "a string"; + static final Object CONST9 = 42; + static final Object CONST10 = String.class; + static final Object CONST11 = String[].class; + } + + public static List constants() { + if (constants == null) { + List res = readConstants(JavaConstant.class); + res.addAll(readConstants(ConstantsUniverse.class)); + constants = res; + } + return constants; + } + + public static class ConstantValue { + public final String name; + public final JavaConstant value; + public final Object boxed; + + public ConstantValue(String name, JavaConstant value, Object boxed) { + this.name = name; + this.value = value; + this.boxed = boxed; + } + + @Override + public String toString() { + return name + "=" + value; + } + + public String getSimpleName() { + return name.substring(name.lastIndexOf('.') + 1); + } + } + + /** + * Reads the value of all {@code static final} fields from a given class into an array of + * {@link ConstantValue}s. + */ + public static List readConstants(Class fromClass) { + try { + List res = new ArrayList<>(); + for (Field field : fromClass.getDeclaredFields()) { + if (isStatic(field.getModifiers()) && isFinal(field.getModifiers())) { + JavaField javaField = metaAccess.lookupJavaField(field); + Object boxed = field.get(null); + if (boxed instanceof JavaConstant) { + res.add(new ConstantValue(javaField.format("%H.%n"), (JavaConstant) boxed, boxed)); + } else { + JavaConstant value = constantReflection.readConstantFieldValue(javaField, null); + if (value != null) { + res.add(new ConstantValue(javaField.format("%H.%n"), value, boxed)); + if (boxed instanceof Object[]) { + Object[] arr = (Object[]) boxed; + for (int i = 0; i < arr.length; i++) { + JavaConstant element = constantReflection.readArrayElement(value, i); + if (element != null) { + res.add(new ConstantValue(javaField.format("%H.%n[" + i + "]"), element, arr[i])); + } + } + } + } + } + } + } + return res; + } catch (Exception e) { + throw new AssertionError(e); + } + } + + public synchronized Class getArrayClass(Class componentType) { + Class arrayClass = arrayClasses.get(componentType); + if (arrayClass == null) { + arrayClass = Array.newInstance(componentType, 0).getClass(); + arrayClasses.put(componentType, arrayClass); + } + return arrayClass; + } + + public static int dimensions(Class c) { + if (c.getComponentType() != null) { + return 1 + dimensions(c.getComponentType()); + } + return 0; + } + + private static void addClass(Class c) { + if (classes.add(c)) { + if (c.getSuperclass() != null) { + addClass(c.getSuperclass()); + } + for (Class sc : c.getInterfaces()) { + addClass(sc); + } + for (Class dc : c.getDeclaredClasses()) { + addClass(dc); + } + for (Method m : c.getDeclaredMethods()) { + addClass(m.getReturnType()); + for (Class p : m.getParameterTypes()) { + addClass(p); + } + } + + if (c != void.class && dimensions(c) < 2) { + Class arrayClass = Array.newInstance(c, 0).getClass(); + arrayClasses.put(c, arrayClass); + addClass(arrayClass); + } + } + } +} diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.jvmci.service.processor/src/com/oracle/jvmci/service/processor/ServiceProviderProcessor.java --- a/graal/com.oracle.jvmci.service.processor/src/com/oracle/jvmci/service/processor/ServiceProviderProcessor.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.jvmci.service.processor/src/com/oracle/jvmci/service/processor/ServiceProviderProcessor.java Thu Jun 04 11:08:12 2015 -0700 @@ -38,6 +38,7 @@ public class ServiceProviderProcessor extends AbstractProcessor { private final Set processed = new HashSet<>(); + private TypeElement baseJVMCIServiceInterface; @Override public SourceVersion getSupportedSourceVersion() { @@ -45,6 +46,11 @@ } private boolean verifyAnnotation(TypeMirror serviceInterface, TypeElement serviceProvider) { + if (!processingEnv.getTypeUtils().isSubtype(serviceInterface, baseJVMCIServiceInterface.asType())) { + String msg = String.format("Service interface class %s doesn't extend JVMCI service interface %s", serviceInterface, baseJVMCIServiceInterface); + processingEnv.getMessager().printMessage(Kind.ERROR, msg, serviceProvider); + return false; + } if (!processingEnv.getTypeUtils().isSubtype(serviceProvider.asType(), serviceInterface)) { String msg = String.format("Service provider class %s doesn't implement service interface %s", serviceProvider.getSimpleName(), serviceInterface); processingEnv.getMessager().printMessage(Kind.ERROR, msg, serviceProvider); @@ -101,6 +107,8 @@ return true; } + baseJVMCIServiceInterface = processingEnv.getElementUtils().getTypeElement("com.oracle.jvmci.service.Service"); + for (Element element : roundEnv.getElementsAnnotatedWith(ServiceProvider.class)) { assert element.getKind().isClass(); processElement((TypeElement) element); diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.jvmci.service/src/com/oracle/jvmci/service/Services.java --- a/graal/com.oracle.jvmci.service/src/com/oracle/jvmci/service/Services.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.jvmci.service/src/com/oracle/jvmci/service/Services.java Thu Jun 04 11:08:12 2015 -0700 @@ -34,10 +34,23 @@ */ public class Services { + /** + * Determines whether to suppress the {@link NoClassDefFoundError} raised if a service + * implementation class specified in a {@code /jvmci/services/*} file is missing. + */ + private static final boolean SuppressNoClassDefFoundError = Boolean.getBoolean("jvmci.service.suppressNoClassDefFoundError"); + private static final ClassValue> cache = new ClassValue>() { @Override protected List computeValue(Class type) { - return Arrays.asList(getServiceImpls(type)); + try { + return Arrays.asList(getServiceImpls(type)); + } catch (NoClassDefFoundError e) { + if (SuppressNoClassDefFoundError) { + return Collections.emptyList(); + } + throw e; + } } }; @@ -84,13 +97,16 @@ if (sm != null) { sm.checkPermission(new RuntimePermission("jvmciServices")); } - Iterable impls = null; + Iterable impls; if (Service.class.isAssignableFrom(service)) { try { impls = (Iterable) cache.get(service); } catch (UnsatisfiedLinkError e) { // Fall back to standard ServiceLoader + impls = null; } + } else { + impls = null; } if (impls == null) { diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.jvmci.sparc/src/com/oracle/jvmci/sparc/SPARC.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.jvmci.sparc/src/com/oracle/jvmci/sparc/SPARC.java Thu Jun 04 11:08:12 2015 -0700 @@ -0,0 +1,337 @@ +/* + * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.jvmci.sparc; + +import com.oracle.jvmci.code.Architecture; +import com.oracle.jvmci.code.Register; +import com.oracle.jvmci.code.TargetDescription; +import com.oracle.jvmci.meta.Kind; +import com.oracle.jvmci.meta.PlatformKind; +import static com.oracle.jvmci.code.MemoryBarriers.*; + +import java.nio.*; +import java.util.*; + +import com.oracle.jvmci.code.Register.RegisterCategory; + +/** + * Represents the SPARC architecture. + */ +public class SPARC extends Architecture { + + public static final RegisterCategory CPU = new RegisterCategory("CPU"); + + // General purpose registers + public static final Register r0 = new Register(0, 0, "g0", CPU); + public static final Register r1 = new Register(1, 1, "g1", CPU); + public static final Register r2 = new Register(2, 2, "g2", CPU); + public static final Register r3 = new Register(3, 3, "g3", CPU); + public static final Register r4 = new Register(4, 4, "g4", CPU); + public static final Register r5 = new Register(5, 5, "g5", CPU); + public static final Register r6 = new Register(6, 6, "g6", CPU); + public static final Register r7 = new Register(7, 7, "g7", CPU); + + public static final Register r8 = new Register(8, 8, "o0", CPU); + public static final Register r9 = new Register(9, 9, "o1", CPU); + public static final Register r10 = new Register(10, 10, "o2", CPU); + public static final Register r11 = new Register(11, 11, "o3", CPU); + public static final Register r12 = new Register(12, 12, "o4", CPU); + public static final Register r13 = new Register(13, 13, "o5", CPU); + public static final Register r14 = new Register(14, 14, "o6", CPU); + public static final Register r15 = new Register(15, 15, "o7", CPU); + + public static final Register r16 = new Register(16, 16, "l0", CPU); + public static final Register r17 = new Register(17, 17, "l1", CPU); + public static final Register r18 = new Register(18, 18, "l2", CPU); + public static final Register r19 = new Register(19, 19, "l3", CPU); + public static final Register r20 = new Register(20, 20, "l4", CPU); + public static final Register r21 = new Register(21, 21, "l5", CPU); + public static final Register r22 = new Register(22, 22, "l6", CPU); + public static final Register r23 = new Register(23, 23, "l7", CPU); + + public static final Register r24 = new Register(24, 24, "i0", CPU); + public static final Register r25 = new Register(25, 25, "i1", CPU); + public static final Register r26 = new Register(26, 26, "i2", CPU); + public static final Register r27 = new Register(27, 27, "i3", CPU); + public static final Register r28 = new Register(28, 28, "i4", CPU); + public static final Register r29 = new Register(29, 29, "i5", CPU); + public static final Register r30 = new Register(30, 30, "i6", CPU); + public static final Register r31 = new Register(31, 31, "i7", CPU); + + public static final Register g0 = r0; + public static final Register g1 = r1; + public static final Register g2 = r2; + public static final Register g3 = r3; + public static final Register g4 = r4; + public static final Register g5 = r5; + public static final Register g6 = r6; + public static final Register g7 = r7; + + public static final Register o0 = r8; + public static final Register o1 = r9; + public static final Register o2 = r10; + public static final Register o3 = r11; + public static final Register o4 = r12; + public static final Register o5 = r13; + public static final Register o6 = r14; + public static final Register o7 = r15; + + public static final Register l0 = r16; + public static final Register l1 = r17; + public static final Register l2 = r18; + public static final Register l3 = r19; + public static final Register l4 = r20; + public static final Register l5 = r21; + public static final Register l6 = r22; + public static final Register l7 = r23; + + public static final Register i0 = r24; + public static final Register i1 = r25; + public static final Register i2 = r26; + public static final Register i3 = r27; + public static final Register i4 = r28; + public static final Register i5 = r29; + public static final Register i6 = r30; + public static final Register i7 = r31; + + public static final Register sp = o6; + public static final Register fp = i6; + + // @formatter:off + public static final Register[] cpuRegisters = { + r0, r1, r2, r3, r4, r5, r6, r7, + r8, r9, r10, r11, r12, r13, r14, r15, + r16, r17, r18, r19, r20, r21, r22, r23, + r24, r25, r26, r27, r28, r29, r30, r31 + }; + // @formatter:on + + public static final RegisterCategory FPUs = new RegisterCategory("FPUs", cpuRegisters.length); + public static final RegisterCategory FPUd = new RegisterCategory("FPUd", cpuRegisters.length + 32); + + // Floating point registers + public static final Register f0 = new Register(32, 0, "f0", FPUs); + public static final Register f1 = new Register(33, 1, "f1", FPUs); + public static final Register f2 = new Register(34, 2, "f2", FPUs); + public static final Register f3 = new Register(35, 3, "f3", FPUs); + public static final Register f4 = new Register(36, 4, "f4", FPUs); + public static final Register f5 = new Register(37, 5, "f5", FPUs); + public static final Register f6 = new Register(38, 6, "f6", FPUs); + public static final Register f7 = new Register(39, 7, "f7", FPUs); + + public static final Register f8 = new Register(40, 8, "f8", FPUs); + public static final Register f9 = new Register(41, 9, "f9", FPUs); + public static final Register f10 = new Register(42, 10, "f10", FPUs); + public static final Register f11 = new Register(43, 11, "f11", FPUs); + public static final Register f12 = new Register(44, 12, "f12", FPUs); + public static final Register f13 = new Register(45, 13, "f13", FPUs); + public static final Register f14 = new Register(46, 14, "f14", FPUs); + public static final Register f15 = new Register(47, 15, "f15", FPUs); + + public static final Register f16 = new Register(48, 16, "f16", FPUs); + public static final Register f17 = new Register(49, 17, "f17", FPUs); + public static final Register f18 = new Register(50, 18, "f18", FPUs); + public static final Register f19 = new Register(51, 19, "f19", FPUs); + public static final Register f20 = new Register(52, 20, "f20", FPUs); + public static final Register f21 = new Register(53, 21, "f21", FPUs); + public static final Register f22 = new Register(54, 22, "f22", FPUs); + public static final Register f23 = new Register(55, 23, "f23", FPUs); + + public static final Register f24 = new Register(56, 24, "f24", FPUs); + public static final Register f25 = new Register(57, 25, "f25", FPUs); + public static final Register f26 = new Register(58, 26, "f26", FPUs); + public static final Register f27 = new Register(59, 27, "f27", FPUs); + public static final Register f28 = new Register(60, 28, "f28", FPUs); + public static final Register f29 = new Register(61, 29, "f29", FPUs); + public static final Register f30 = new Register(62, 30, "f30", FPUs); + public static final Register f31 = new Register(63, 31, "f31", FPUs); + + public static final Register d0 = new Register(32, getDoubleEncoding(0), "d0", FPUs); + public static final Register d2 = new Register(34, getDoubleEncoding(2), "d2", FPUs); + public static final Register d4 = new Register(36, getDoubleEncoding(4), "d4", FPUs); + public static final Register d6 = new Register(38, getDoubleEncoding(6), "d6", FPUs); + public static final Register d8 = new Register(40, getDoubleEncoding(8), "d8", FPUs); + public static final Register d10 = new Register(42, getDoubleEncoding(10), "d10", FPUs); + public static final Register d12 = new Register(44, getDoubleEncoding(12), "d12", FPUs); + public static final Register d14 = new Register(46, getDoubleEncoding(14), "d14", FPUs); + + public static final Register d16 = new Register(48, getDoubleEncoding(16), "d16", FPUs); + public static final Register d18 = new Register(50, getDoubleEncoding(18), "d18", FPUs); + public static final Register d20 = new Register(52, getDoubleEncoding(20), "d20", FPUs); + public static final Register d22 = new Register(54, getDoubleEncoding(22), "d22", FPUs); + public static final Register d24 = new Register(56, getDoubleEncoding(24), "d24", FPUs); + public static final Register d26 = new Register(58, getDoubleEncoding(26), "d26", FPUs); + public static final Register d28 = new Register(60, getDoubleEncoding(28), "d28", FPUs); + public static final Register d30 = new Register(62, getDoubleEncoding(28), "d28", FPUs); + + public static final Register d32 = new Register(64, getDoubleEncoding(32), "d32", FPUd); + public static final Register d34 = new Register(65, getDoubleEncoding(34), "d34", FPUd); + public static final Register d36 = new Register(66, getDoubleEncoding(36), "d36", FPUd); + public static final Register d38 = new Register(67, getDoubleEncoding(38), "d38", FPUd); + public static final Register d40 = new Register(68, getDoubleEncoding(40), "d40", FPUd); + public static final Register d42 = new Register(69, getDoubleEncoding(42), "d42", FPUd); + public static final Register d44 = new Register(70, getDoubleEncoding(44), "d44", FPUd); + public static final Register d46 = new Register(71, getDoubleEncoding(46), "d46", FPUd); + + public static final Register d48 = new Register(72, getDoubleEncoding(48), "d48", FPUd); + public static final Register d50 = new Register(73, getDoubleEncoding(50), "d50", FPUd); + public static final Register d52 = new Register(74, getDoubleEncoding(52), "d52", FPUd); + public static final Register d54 = new Register(75, getDoubleEncoding(54), "d54", FPUd); + public static final Register d56 = new Register(76, getDoubleEncoding(56), "d56", FPUd); + public static final Register d58 = new Register(77, getDoubleEncoding(58), "d58", FPUd); + public static final Register d60 = new Register(78, getDoubleEncoding(60), "d60", FPUd); + public static final Register d62 = new Register(79, getDoubleEncoding(62), "d62", FPUd); + + // @formatter:off + public static final Register[] fpuRegisters = { + f0, f1, f2, f3, f4, f5, f6, f7, + f8, f9, f10, f11, f12, f13, f14, f15, + f16, f17, f18, f19, f20, f21, f22, f23, + f24, f25, f26, f27, f28, f29, f30, f31, + d32, d34, d36, d38, d40, d42, d44, d46, + d48, d50, d52, d54, d56, d58, d60, d62 + }; + // @formatter:on + + // @formatter:off + public static final Register[] allRegisters = { + // CPU + r0, r1, r2, r3, r4, r5, r6, r7, + r8, r9, r10, r11, r12, r13, r14, r15, + r16, r17, r18, r19, r20, r21, r22, r23, + r24, r25, r26, r27, r28, r29, r30, r31, + // FPU + f0, f1, f2, f3, f4, f5, f6, f7, + f8, f9, f10, f11, f12, f13, f14, f15, + f16, f17, f18, f19, f20, f21, f22, f23, + f24, f25, f26, f27, f28, f29, f30, f31, + d32, d34, d36, d38, d40, d42, d44, d46, + d48, d50, d52, d54, d56, d58, d60, d62 + }; + // @formatter:on + + /** + * Stack bias for stack and frame pointer loads. + */ + public static final int STACK_BIAS = 0x7ff; + /** + * In fact there are 64 single floating point registers, 32 of them could be accessed. TODO: + * Improve handling of these float registers + */ + public static final int FLOAT_REGISTER_COUNT = 64; + + /** + * Alignment for valid memory access. + */ + public static final int MEMORY_ACCESS_ALIGN = 4; + + public final Set features; + + public SPARC(Set features) { + super("SPARC", 8, ByteOrder.BIG_ENDIAN, false, allRegisters, LOAD_STORE | STORE_STORE, 1, r31.encoding + FLOAT_REGISTER_COUNT + 1, 8); + this.features = features; + } + + @Override + public boolean canStoreValue(RegisterCategory category, PlatformKind lirKind) { + if (!(lirKind instanceof Kind)) { + return false; + } + + Kind kind = (Kind) lirKind; + if (category.equals(CPU)) { + switch (kind) { + case Boolean: + case Byte: + case Char: + case Short: + case Int: + case Long: + case Object: + return true; + } + } else if (category.equals(FPUs) && kind.equals(Kind.Float)) { + return true; + } else if (category.equals(FPUd) && kind.equals(Kind.Double)) { + return true; + } + return false; + } + + @Override + public PlatformKind getLargestStorableKind(RegisterCategory category) { + if (category.equals(CPU)) { + return Kind.Long; + } else if (category.equals(FPUs)) { + return Kind.Double; + } else { + return Kind.Illegal; + } + } + + public static int spillSlotSize(TargetDescription td, PlatformKind kind) { + return Math.max(td.getSizeInBytes(kind), MEMORY_ACCESS_ALIGN); + } + + public static int getDoubleEncoding(int reg) { + assert reg < 64 && ((reg & 1) == 0); + // ignore v8 assertion for now + return (reg & 0x1e) | ((reg & 0x20) >> 5); + } + + public static boolean isCPURegister(Register r) { + return r.getRegisterCategory().equals(CPU); + } + + public static boolean isCPURegister(Register... regs) { + for (Register reg : regs) { + if (!isCPURegister(reg)) { + return false; + } + } + return true; + } + + public static boolean isSingleFloatRegister(Register r) { + return r.name.startsWith("f"); + } + + public static boolean isDoubleFloatRegister(Register r) { + return r.name.startsWith("d"); + } + + public Set getFeatures() { + return features; + } + + public boolean hasFeature(CPUFeature feature) { + return features.contains(feature); + } + + public enum CPUFeature { + VIS1, + VIS2, + VIS3, + CBCOND + } +} diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/processor/LanguageRegistrationTest.java --- a/graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/processor/LanguageRegistrationTest.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/processor/LanguageRegistrationTest.java Thu Jun 04 11:08:12 2015 -0700 @@ -58,7 +58,7 @@ } @Override - protected Object findExportedSymbol(String globalName) { + protected Object findExportedSymbol(String globalName, boolean onlyExplicit) { return null; } @@ -86,7 +86,7 @@ } @Override - protected Object findExportedSymbol(String globalName) { + protected Object findExportedSymbol(String globalName, boolean onlyExplicit) { return null; } @@ -113,7 +113,7 @@ } @Override - protected Object findExportedSymbol(String globalName) { + protected Object findExportedSymbol(String globalName, boolean onlyExplicit) { return null; } diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.truffle.api.object/src/com/oracle/truffle/api/object/DynamicObject.java --- a/graal/com.oracle.truffle.api.object/src/com/oracle/truffle/api/object/DynamicObject.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.truffle.api.object/src/com/oracle/truffle/api/object/DynamicObject.java Thu Jun 04 11:08:12 2015 -0700 @@ -52,6 +52,23 @@ public abstract boolean set(Object key, Object value); /** + * Returns {@code true} if this object contains a property with the given key. + */ + public final boolean containsKey(Object key) { + return getShape().getProperty(key) != null; + } + + /** + * Define new property or redefine existing property. + * + * @param key property identifier + * @param value value to be set + */ + public final void define(Object key, Object value) { + define(key, value, 0); + } + + /** * Define new property or redefine existing property. * * @param key property identifier diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.truffle.api.object/src/com/oracle/truffle/api/object/LayoutFactory.java --- a/graal/com.oracle.truffle.api.object/src/com/oracle/truffle/api/object/LayoutFactory.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.truffle.api.object/src/com/oracle/truffle/api/object/LayoutFactory.java Thu Jun 04 11:08:12 2015 -0700 @@ -27,6 +27,8 @@ public interface LayoutFactory { Layout createLayout(LayoutBuilder layoutBuilder); + Property createProperty(Object id, Location location); + Property createProperty(Object id, Location location, int flags); int getPriority(); diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/source/SourceSectionTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/source/SourceSectionTest.java Thu Jun 04 11:08:12 2015 -0700 @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.truffle.api.test.source; + +import static org.junit.Assert.*; + +import org.junit.*; + +import com.oracle.truffle.api.source.*; + +public class SourceSectionTest { + + private final Source emptySource = Source.fromText("", null); + + private final Source emptyLineSource = Source.fromText("\n", null); + + private final Source shortSource = Source.fromText("01", null); + + private final Source longSource = Source.fromText("01234\n67\n9\n", null); + + public void emptySourceTest0() { + SourceSection section = emptySource.createSection("test", 0, 0); + assertNotNull(section); + assertEquals(section.getCode(), ""); + } + + @Test + public void emptyLineTest0() { + SourceSection section = emptyLineSource.createSection("test", 0, 0); + assertNotNull(section); + assertEquals(section.getCode(), ""); + assertEquals(section.getCharIndex(), 0); + assertEquals(section.getCharLength(), 0); + assertEquals(section.getStartLine(), 1); + assertEquals(section.getStartColumn(), 1); + } + + @Ignore + @Test + public void emptyLineTest0a() { + SourceSection section = emptyLineSource.createSection("test", 0, 0); + assertEquals(section.getEndLine(), 1); + assertEquals(section.getEndColumn(), 1); + } + + @Test + public void emptyLineTest1() { + SourceSection section = emptyLineSource.createSection("test", 0, 1); + assertNotNull(section); + assertEquals(section.getCode(), "\n"); + assertEquals(section.getCharIndex(), 0); + assertEquals(section.getCharLength(), 1); + assertEquals(section.getStartLine(), 1); + assertEquals(section.getStartColumn(), 1); + assertEquals(section.getEndLine(), 1); + assertEquals(section.getEndColumn(), 1); + } + + @Ignore + @Test + public void emptyLineTest2() { + SourceSection section = emptyLineSource.createSection("test", 1, 0); + assertNotNull(section); + assertEquals(section.getCode(), ""); + assertEquals(section.getCharIndex(), 1); + assertEquals(section.getCharLength(), 0); + assertEquals(section.getStartLine(), 1); + assertEquals(section.getStartColumn(), 1); + assertEquals(section.getEndLine(), 1); + assertEquals(section.getEndColumn(), 1); + } + + @Test + public void emptySectionTest2() { + SourceSection section = shortSource.createSection("test", 0, 0); + assertNotNull(section); + assertEquals(section.getCode(), ""); + } + + @Test + public void emptySectionTest3() { + SourceSection section = longSource.createSection("test", 0, 0); + assertNotNull(section); + assertEquals(section.getCode(), ""); + } + +} diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/source/SourceTagTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/source/SourceTagTest.java Thu Jun 04 11:08:12 2015 -0700 @@ -0,0 +1,162 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.truffle.api.test.source; + +import static org.junit.Assert.*; + +import org.junit.*; + +import com.oracle.truffle.api.source.*; + +public class SourceTagTest { + + @Test + public void sourceTagTest() { + + // Private tag + final SourceTag testTag = new SourceTag() { + + public String name() { + return null; + } + + public String getDescription() { + return null; + } + }; + + // No sources exist with the private tag + assertEquals(Source.findSourcesTaggedAs(testTag).size(), 0); + + // Create a new source + final Source source = Source.fromText("test1 source", "test1 source"); + + // Initially has only the default tag + assertEquals(source.getSourceTags().size(), 1); + + assertTrue(source.getSourceTags().contains(Source.Tags.FROM_LITERAL)); + assertTrue(source.isTaggedAs(Source.Tags.FROM_LITERAL)); + assertTrue(Source.findSourcesTaggedAs(Source.Tags.FROM_LITERAL).contains(source)); + + assertFalse(source.isTaggedAs(testTag)); + assertEquals(Source.findSourcesTaggedAs(testTag).size(), 0); + + // Add a private tag + source.tagAs(testTag); + + // Now there are exactly two tags + assertEquals(source.getSourceTags().size(), 2); + + assertTrue(source.getSourceTags().contains(Source.Tags.FROM_LITERAL)); + assertTrue(source.isTaggedAs(Source.Tags.FROM_LITERAL)); + assertTrue(Source.findSourcesTaggedAs(Source.Tags.FROM_LITERAL).contains(source)); + + assertTrue(source.getSourceTags().contains(testTag)); + assertTrue(source.isTaggedAs(testTag)); + assertEquals(Source.findSourcesTaggedAs(testTag).size(), 1); + assertTrue(Source.findSourcesTaggedAs(testTag).contains(source)); + + // Add the private tag again + source.tagAs(testTag); + + // Nothing has changed + assertEquals(source.getSourceTags().size(), 2); + + assertTrue(source.getSourceTags().contains(Source.Tags.FROM_LITERAL)); + assertTrue(source.isTaggedAs(Source.Tags.FROM_LITERAL)); + assertTrue(Source.findSourcesTaggedAs(Source.Tags.FROM_LITERAL).contains(source)); + + assertTrue(source.getSourceTags().contains(testTag)); + assertTrue(source.isTaggedAs(testTag)); + assertEquals(Source.findSourcesTaggedAs(testTag).size(), 1); + assertTrue(Source.findSourcesTaggedAs(testTag).contains(source)); + } + + @Test + public void sourceListenerTest() { + + // Private tag + final SourceTag testTag = new SourceTag() { + + public String name() { + return null; + } + + public String getDescription() { + return null; + } + }; + + final int[] newSourceEvents = {0}; + final Source[] newSource = {null}; + + final int[] newTagEvents = {0}; + final Source[] taggedSource = {null}; + final SourceTag[] newTag = {null}; + + Source.addSourceListener(new SourceListener() { + + public void sourceCreated(Source source) { + newSourceEvents[0] = newSourceEvents[0] + 1; + newSource[0] = source; + } + + public void sourceTaggedAs(Source source, SourceTag tag) { + newTagEvents[0] = newTagEvents[0] + 1; + taggedSource[0] = source; + newTag[0] = tag; + } + }); + + // New source has a default tag applied. + // Get one event for the new source, another one when it gets tagged + final Source source = Source.fromText("testSource", "testSource"); + assertEquals(newSourceEvents[0], 1); + assertEquals(newSource[0], source); + assertEquals(newTagEvents[0], 1); + assertEquals(taggedSource[0], source); + assertEquals(newTag[0], Source.Tags.FROM_LITERAL); + + // reset + newSource[0] = null; + taggedSource[0] = null; + newTag[0] = null; + + // Add a tag; only get one event (the new tag) + source.tagAs(testTag); + assertEquals(newSourceEvents[0], 1); + assertEquals(newSource[0], null); + assertEquals(newTagEvents[0], 2); + assertEquals(taggedSource[0], source); + assertEquals(newTag[0], testTag); + + // Add the same tag; no events, and nothing changes. + source.tagAs(testTag); + assertEquals(newSourceEvents[0], 1); + assertEquals(newSource[0], null); + assertEquals(newTagEvents[0], 2); + assertEquals(taggedSource[0], source); + assertEquals(newTag[0], testTag); + + } +} diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/source/SourceTest.java --- a/graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/source/SourceTest.java Thu Jun 04 10:46:23 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,162 +0,0 @@ -/* - * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.truffle.api.test.source; - -import static org.junit.Assert.*; - -import org.junit.*; - -import com.oracle.truffle.api.source.*; - -public class SourceTest { - - @Test - public void sourceTagTest() { - - // Private tag - final SourceTag testTag = new SourceTag() { - - public String name() { - return null; - } - - public String getDescription() { - return null; - } - }; - - // No sources exist with the private tag - assertEquals(Source.findSourcesTaggedAs(testTag).size(), 0); - - // Create a new source - final Source source = Source.fromText("test1 source", "test1 source"); - - // Initially has only the default tag - assertEquals(source.getSourceTags().size(), 1); - - assertTrue(source.getSourceTags().contains(Source.Tags.FROM_LITERAL)); - assertTrue(source.isTaggedAs(Source.Tags.FROM_LITERAL)); - assertTrue(Source.findSourcesTaggedAs(Source.Tags.FROM_LITERAL).contains(source)); - - assertFalse(source.isTaggedAs(testTag)); - assertEquals(Source.findSourcesTaggedAs(testTag).size(), 0); - - // Add a private tag - source.tagAs(testTag); - - // Now there are exactly two tags - assertEquals(source.getSourceTags().size(), 2); - - assertTrue(source.getSourceTags().contains(Source.Tags.FROM_LITERAL)); - assertTrue(source.isTaggedAs(Source.Tags.FROM_LITERAL)); - assertTrue(Source.findSourcesTaggedAs(Source.Tags.FROM_LITERAL).contains(source)); - - assertTrue(source.getSourceTags().contains(testTag)); - assertTrue(source.isTaggedAs(testTag)); - assertEquals(Source.findSourcesTaggedAs(testTag).size(), 1); - assertTrue(Source.findSourcesTaggedAs(testTag).contains(source)); - - // Add the private tag again - source.tagAs(testTag); - - // Nothing has changed - assertEquals(source.getSourceTags().size(), 2); - - assertTrue(source.getSourceTags().contains(Source.Tags.FROM_LITERAL)); - assertTrue(source.isTaggedAs(Source.Tags.FROM_LITERAL)); - assertTrue(Source.findSourcesTaggedAs(Source.Tags.FROM_LITERAL).contains(source)); - - assertTrue(source.getSourceTags().contains(testTag)); - assertTrue(source.isTaggedAs(testTag)); - assertEquals(Source.findSourcesTaggedAs(testTag).size(), 1); - assertTrue(Source.findSourcesTaggedAs(testTag).contains(source)); - } - - @Test - public void sourceListenerTest() { - - // Private tag - final SourceTag testTag = new SourceTag() { - - public String name() { - return null; - } - - public String getDescription() { - return null; - } - }; - - final int[] newSourceEvents = {0}; - final Source[] newSource = {null}; - - final int[] newTagEvents = {0}; - final Source[] taggedSource = {null}; - final SourceTag[] newTag = {null}; - - Source.addSourceListener(new SourceListener() { - - public void sourceCreated(Source source) { - newSourceEvents[0] = newSourceEvents[0] + 1; - newSource[0] = source; - } - - public void sourceTaggedAs(Source source, SourceTag tag) { - newTagEvents[0] = newTagEvents[0] + 1; - taggedSource[0] = source; - newTag[0] = tag; - } - }); - - // New source has a default tag applied. - // Get one event for the new source, another one when it gets tagged - final Source source = Source.fromText("testSource", "testSource"); - assertEquals(newSourceEvents[0], 1); - assertEquals(newSource[0], source); - assertEquals(newTagEvents[0], 1); - assertEquals(taggedSource[0], source); - assertEquals(newTag[0], Source.Tags.FROM_LITERAL); - - // reset - newSource[0] = null; - taggedSource[0] = null; - newTag[0] = null; - - // Add a tag; only get one event (the new tag) - source.tagAs(testTag); - assertEquals(newSourceEvents[0], 1); - assertEquals(newSource[0], null); - assertEquals(newTagEvents[0], 2); - assertEquals(taggedSource[0], source); - assertEquals(newTag[0], testTag); - - // Add the same tag; no events, and nothing changes. - source.tagAs(testTag); - assertEquals(newSourceEvents[0], 1); - assertEquals(newSource[0], null); - assertEquals(newTagEvents[0], 2); - assertEquals(taggedSource[0], source); - assertEquals(newTag[0], testTag); - - } -} diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/vm/ImplicitExplicitExportTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/vm/ImplicitExplicitExportTest.java Thu Jun 04 11:08:12 2015 -0700 @@ -0,0 +1,189 @@ +/* + * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.truffle.api.test.vm; + +import com.oracle.truffle.api.TruffleLanguage; +import com.oracle.truffle.api.source.Source; +import com.oracle.truffle.api.vm.TruffleVM; +import java.io.IOException; +import java.io.Reader; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.Map; +import java.util.Properties; +import static org.junit.Assert.*; +import org.junit.Before; +import org.junit.Test; + +public class ImplicitExplicitExportTest { + private TruffleVM vm; + + @Before + public void initializeVM() { + vm = TruffleVM.newVM().build(); + assertTrue("Found " + L1 + " language", vm.getLanguages().containsKey(L1)); + assertTrue("Found " + L2 + " language", vm.getLanguages().containsKey(L2)); + assertTrue("Found " + L3 + " language", vm.getLanguages().containsKey(L3)); + } + + @Test + public void explicitExportFound() throws IOException { + // @formatter:off + vm.eval(L1, + "explicit.ahoj=42" + ); + Object ret = vm.eval(L3, + "return=ahoj" + ); + // @formatter:on + assertEquals("42", ret); + } + + @Test + public void implicitExportFound() throws IOException { + // @formatter:off + vm.eval(L1, + "implicit.ahoj=42" + ); + Object ret = vm.eval(L3, + "return=ahoj" + ); + // @formatter:on + assertEquals("42", ret); + } + + @Test + public void explicitExportPreferred2() throws IOException { + // @formatter:off + vm.eval(L1, + "implicit.ahoj=42" + ); + vm.eval(L2, + "explicit.ahoj=43" + ); + Object ret = vm.eval(L3, + "return=ahoj" + ); + // @formatter:on + assertEquals("Explicit import from L2 is used", "43", ret); + assertEquals("Global symbol is also 43", "43", vm.findGlobalSymbol("ahoj").invoke(null)); + } + + @Test + public void explicitExportPreferred1() throws IOException { + // @formatter:off + vm.eval(L1, + "explicit.ahoj=43" + ); + vm.eval(L2, + "implicit.ahoj=42" + ); + Object ret = vm.eval(L3, + "return=ahoj" + ); + // @formatter:on + assertEquals("Explicit import from L2 is used", "43", ret); + assertEquals("Global symbol is also 43", "43", vm.findGlobalSymbol("ahoj").invoke(null)); + } + + private abstract static class AbstractExportImportLanguage extends TruffleLanguage { + protected AbstractExportImportLanguage(Env env) { + super(env); + } + + private final Map explicit = new HashMap<>(); + private final Map implicit = new HashMap<>(); + + @Override + protected Object eval(Source code) throws IOException { + Properties p = new Properties(); + try (Reader r = code.getReader()) { + p.load(r); + } + Enumeration en = p.keys(); + while (en.hasMoreElements()) { + Object n = en.nextElement(); + if (n instanceof String) { + String k = (String) n; + if (k.startsWith("explicit.")) { + explicit.put(k.substring(9), p.getProperty(k)); + } + if (k.startsWith("implicit.")) { + implicit.put(k.substring(9), p.getProperty(k)); + } + if (k.equals("return")) { + return env().importSymbol(p.getProperty(k)); + } + } + } + return null; + } + + @Override + protected Object findExportedSymbol(String globalName, boolean onlyExplicit) { + if (explicit.containsKey(globalName)) { + return explicit.get(globalName); + } + if (!onlyExplicit && implicit.containsKey(globalName)) { + return implicit.get(globalName); + } + return null; + } + + @Override + protected Object getLanguageGlobal() { + return null; + } + + @Override + protected boolean isObjectOfLanguage(Object object) { + return false; + } + } + + private static final String L1 = "application/x-test-import-export-1"; + private static final String L2 = "application/x-test-import-export-2"; + private static final String L3 = "application/x-test-import-export-3"; + + @TruffleLanguage.Registration(mimeType = L1, name = "ImportExport1") + public static final class ExportImportLanguage1 extends AbstractExportImportLanguage { + public ExportImportLanguage1(Env env) { + super(env); + } + } + + @TruffleLanguage.Registration(mimeType = L2, name = "ImportExport2") + public static final class ExportImportLanguage2 extends AbstractExportImportLanguage { + public ExportImportLanguage2(Env env) { + super(env); + } + } + + @TruffleLanguage.Registration(mimeType = L3, name = "ImportExport3") + public static final class ExportImportLanguage3 extends AbstractExportImportLanguage { + public ExportImportLanguage3(Env env) { + super(env); + } + } + +} diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/vm/TruffleTCK.java --- a/graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/vm/TruffleTCK.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/vm/TruffleTCK.java Thu Jun 04 11:08:12 2015 -0700 @@ -22,21 +22,21 @@ */ package com.oracle.truffle.api.test.vm; -import java.util.*; - -import org.junit.*; - -import com.oracle.truffle.api.vm.*; +import com.oracle.truffle.api.vm.TruffleVM; +import java.io.IOException; +import java.util.Random; +import static org.junit.Assert.*; +import org.junit.Test; /** * A collection of tests that can certify language implementaiton to be complient with most recent * requirements of the Truffle infrastructure and tooling. Subclass, implement abstract methods and * include in your test suite. */ -public class TruffleTCK { // abstract +public abstract class TruffleTCK { private TruffleVM tckVM; - public TruffleTCK() { // protected + protected TruffleTCK() { } /** @@ -44,15 +44,22 @@ * your language up, so it is ready for testing. * {@link TruffleVM#eval(java.lang.String, java.lang.String) Execute} any scripts you need, and * prepare global symbols with proper names. The symbols will then be looked up by the - * infastructure (using the names provided by you from methods like {@link #plusInt()}) and used - * for internal testing. + * infrastructure (using the names provided by you from methods like {@link #plusInt()}) and + * used for internal testing. * * @return initialized Truffle virtual machine * @throws java.lang.Exception thrown when the VM preparation fails */ - protected TruffleVM prepareVM() throws Exception { // abstract - return null; - } + protected abstract TruffleVM prepareVM() throws Exception; + + /** + * Mimetype associated with your language. The mimetype will be passed to + * {@link TruffleVM#eval(java.lang.String, java.lang.String)} method of the {@link #prepareVM() + * created TruffleVM}. + * + * @return mime type of the tested language + */ + protected abstract String mimeType(); /** * Name of function which will return value 42 as a number. The return value of the method @@ -61,9 +68,17 @@ * * @return name of globally exported symbol */ - protected String fourtyTwo() { // abstract - return null; - } + protected abstract String fourtyTwo(); + + /** + * Name of a function that returns null. Truffle languages are encouraged to have + * their own type representing null, but when such value is returned from + * {@link TruffleVM#eval}, it needs to be converted to real Java null by sending a + * foreign access isNull message. There is a test to verify it is really true. + * + * @return name of globally exported symbol + */ + protected abstract String returnsNull(); /** * Name of function to add two integer values together. The symbol will be invoked with two @@ -72,9 +87,16 @@ * * @return name of globally exported symbol */ - protected String plusInt() { // abstract - return null; - } + protected abstract String plusInt(); + + /** + * Return a code snippet that is invalid in your language. Its + * {@link TruffleVM#eval(java.lang.String, java.lang.String) evaluation} should fail and yield + * an exception. + * + * @return code snippet invalid in the tested language + */ + protected abstract String invalidCode(); private TruffleVM vm() throws Exception { if (tckVM == null) { @@ -89,9 +111,6 @@ @Test public void testFortyTwo() throws Exception { - if (getClass() == TruffleTCK.class) { - return; - } TruffleVM.Symbol fourtyTwo = findGlobalSymbol(fourtyTwo()); Object res = fourtyTwo.invoke(null); @@ -104,10 +123,19 @@ } @Test - public void testPlusWithInts() throws Exception { + public void testNull() throws Exception { if (getClass() == TruffleTCK.class) { return; } + TruffleVM.Symbol retNull = findGlobalSymbol(returnsNull()); + + Object res = retNull.invoke(null); + + assertNull("Should yield real Java null", res); + } + + @Test + public void testPlusWithInts() throws Exception { Random r = new Random(); int a = r.nextInt(100); int b = r.nextInt(100); @@ -123,6 +151,14 @@ assert a + b == n.intValue() : "The value is correct: (" + a + " + " + b + ") = " + n.intValue(); } + @Test(expected = IOException.class) + public void testInvalidTestMethod() throws Exception { + String mime = mimeType(); + String code = invalidCode(); + Object ret = vm().eval(mime, code); + fail("Should yield IOException, but returned " + ret); + } + private TruffleVM.Symbol findGlobalSymbol(String name) throws Exception { TruffleVM.Symbol s = vm().findGlobalSymbol(name); assert s != null : "Symbol " + name + " is not found!"; diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.truffle.api/src/com/oracle/truffle/api/Truffle.java --- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/Truffle.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/Truffle.java Thu Jun 04 11:08:12 2015 -0700 @@ -54,7 +54,12 @@ return AccessController.doPrivileged(new PrivilegedAction() { public TruffleRuntime run() { - TruffleRuntimeAccess access = Services.loadSingle(TruffleRuntimeAccess.class, false); + TruffleRuntimeAccess access = null; + try { + access = Services.loadSingle(TruffleRuntimeAccess.class, false); + } catch (NoClassDefFoundError e) { + // JVMCI is unavailable + } if (access != null) { return access.getRuntime(); } diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.truffle.api/src/com/oracle/truffle/api/TruffleLanguage.java --- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/TruffleLanguage.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/TruffleLanguage.java Thu Jun 04 11:08:12 2015 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -38,7 +38,7 @@ * implementation of this type and registering it using {@link Registration} annotation, your * language becomes accessible to users of the {@link TruffleVM Truffle virtual machine} - all they * will need to do is to include your JAR into their application and all the Truffle goodies (multi - * language support, multi tennat hosting, debugging, etc.) will be made available to them. + * language support, multitenant hosting, debugging, etc.) will be made available to them. */ public abstract class TruffleLanguage { private final Env env; @@ -56,7 +56,7 @@ /** * The annotation to use to register your language to the {@link TruffleVM Truffle} system. By * annotating your implementation of {@link TruffleLanguage} by this annotation you are just a - * one JAR drop to the classpath away from your users. Once they include your JAR in + * one JAR drop to the class path away from your users. Once they include your JAR in * their application, your language will be available to the {@link TruffleVM Truffle virtual * machine}. */ @@ -72,11 +72,11 @@ String name(); /** - * List of mimetypes associated with your language. Users will use them (directly or - * inderectly) when {@link TruffleVM#eval(java.lang.String, java.lang.String) executing} + * List of MIME types associated with your language. Users will use them (directly or + * indirectly) when {@link TruffleVM#eval(java.lang.String, java.lang.String) executing} * their code snippets or their {@link TruffleVM#eval(java.net.URI) files}. * - * @return array of mime types assigned to your language files + * @return array of MIME types assigned to your language files */ String[] mimeType(); } @@ -96,14 +96,25 @@ * somebody asks for it (by calling this method). *

* The exported object can either be TruffleObject (e.g. a native object from the - * other language) to support interoperability between languages or one of Java primitive - * wrappers ( {@link Integer}, {@link Double}, {@link Short}, etc.). + * other language) to support inter-operability between languages, {@link String} or one of Java + * primitive wrappers ( {@link Integer}, {@link Double}, {@link Short}, {@link Boolean}, etc.). + *

+ * The way a symbol becomes exported is language dependant. In general it is preferred + * to make the export explicit - e.g. call some function or method to register an object under + * specific name. Some languages may however decide to support implicit export of symbols (for + * example from global scope, if they have one). However explicit exports should always be + * preferred. Implicitly exported object of some name should only be used when there is no + * explicit export under such globalName. To ensure so the infrastructure first + * asks all known languages for onlyExplicit symbols and only when none is found, + * it does one more round with onlyExplicit set to false. * * @param globalName the name of the global symbol to find + * @param onlyExplicit should the language seek for implicitly exported object or only consider + * the explicitly exported ones? * @return an exported object or null, if the symbol does not represent anything * meaningful in this language */ - protected abstract Object findExportedSymbol(String globalName); + protected abstract Object findExportedSymbol(String globalName, boolean onlyExplicit); /** * Returns global object for the language. @@ -210,8 +221,8 @@ } @Override - protected Object findExportedSymbol(TruffleLanguage l, String globalName) { - return l.findExportedSymbol(globalName); + protected Object findExportedSymbol(TruffleLanguage l, String globalName, boolean onlyExplicit) { + return l.findExportedSymbol(globalName, onlyExplicit); } @Override diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/Accessor.java --- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/Accessor.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/Accessor.java Thu Jun 04 11:08:12 2015 -0700 @@ -46,7 +46,7 @@ } @Override - protected Object findExportedSymbol(String globalName) { + protected Object findExportedSymbol(String globalName, boolean onlyExplicit) { return null; } @@ -89,8 +89,8 @@ return SPI.importSymbol(vm, queryingLang, globalName); } - protected Object findExportedSymbol(TruffleLanguage l, String globalName) { - return API.findExportedSymbol(l, globalName); + protected Object findExportedSymbol(TruffleLanguage l, String globalName, boolean onlyExplicit) { + return API.findExportedSymbol(l, globalName, onlyExplicit); } protected Object languageGlobal(TruffleLanguage l) { diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.truffle.api/src/com/oracle/truffle/api/instrument/Probe.java --- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/instrument/Probe.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/instrument/Probe.java Thu Jun 04 11:08:12 2015 -0700 @@ -24,6 +24,7 @@ */ package com.oracle.truffle.api.instrument; +import java.io.*; import java.lang.ref.*; import java.util.*; @@ -100,6 +101,16 @@ */ public final class Probe { + private static final boolean TRACE = false; + private static final String TRACE_PREFIX = "PROBE: "; + private static final PrintStream OUT = System.out; + + private static void trace(String format, Object... args) { + if (TRACE) { + OUT.println(TRACE_PREFIX + String.format(format, args)); + } + } + private static final List astProbers = new ArrayList<>(); private static final List probeListeners = new ArrayList<>(); @@ -162,8 +173,17 @@ */ public static void applyASTProbers(Node node) { + String name = ""; final Source source = findSource(node); - + if (source != null) { + name = source.getShortName(); + } else { + final SourceSection sourceSection = node.getEncapsulatingSourceSection(); + if (sourceSection != null) { + name = sourceSection.getShortDescription(); + } + } + trace("START %s", name); for (ProbeListener listener : probeListeners) { listener.startASTProbing(source); } @@ -173,6 +193,7 @@ for (ProbeListener listener : probeListeners) { listener.endASTProbing(source); } + trace("FINISHED %s", name); } /** @@ -286,6 +307,10 @@ this.sourceSection = sourceSection; probes.add(new WeakReference<>(this)); registerProbeNodeClone(probeNode); + if (TRACE) { + final String location = this.sourceSection == null ? "" : sourceSection.getShortDescription(); + trace("ADDED %s %s %s", "Probe@", location, getTagsDescription()); + } for (ProbeListener listener : probeListeners) { listener.newProbeInserted(this); } @@ -332,6 +357,9 @@ if (tagTrapsChanged) { invalidateProbeUnchanged(); } + if (TRACE) { + trace("TAGGED as %s: %s", tag, getShortDescription()); + } } } diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/Node.java --- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/Node.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/Node.java Thu Jun 04 11:08:12 2015 -0700 @@ -352,7 +352,7 @@ public final Iterable getChildren() { return new Iterable() { public Iterator iterator() { - return nodeClass.makeIterator(Node.this); + return getNodeClass().makeIterator(Node.this); } }; } diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/NodeUtil.java --- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/NodeUtil.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/NodeUtil.java Thu Jun 04 11:08:12 2015 -0700 @@ -454,14 +454,13 @@ } public static T findFirstNodeInstance(Node root, Class clazz) { - for (Node childNode : findNodeChildren(root)) { - if (clazz.isInstance(childNode)) { - return clazz.cast(childNode); - } else { - T node = findFirstNodeInstance(childNode, clazz); - if (node != null) { - return node; - } + if (clazz.isInstance(root)) { + return clazz.cast(root); + } + for (Node child : root.getChildren()) { + T node = findFirstNodeInstance(child, clazz); + if (node != null) { + return node; } } return null; @@ -480,23 +479,6 @@ return nodeList; } - /** - * Like {@link #findAllNodeInstances(Node, Class)} but do not visit children of found nodes. - */ - public static List findNodeInstancesShallow(final Node root, final Class clazz) { - final List nodeList = new ArrayList<>(); - root.accept(new NodeVisitor() { - public boolean visit(Node node) { - if (clazz.isInstance(node)) { - nodeList.add(clazz.cast(node)); - return false; - } - return true; - } - }); - return nodeList; - } - public static int countNodes(Node root) { return countNodes(root, NodeCountFilter.NO_FILTER); } diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.truffle.api/src/com/oracle/truffle/api/vm/TruffleVM.java --- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/vm/TruffleVM.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/vm/TruffleVM.java Thu Jun 04 11:08:12 2015 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -40,12 +40,12 @@ /** * Virtual machine for Truffle based languages. Use {@link #newVM()} to create new isolated virtual * machine ready for execution of various languages. All the languages in a single virtual machine - * see each other exported global symbols and can co-operate. Use {@link #newVM()} multiple times to + * see each other exported global symbols and can cooperate. Use {@link #newVM()} multiple times to * create different, isolated virtual machines completely separated from each other. *

* Once instantiated use {@link #eval(java.net.URI)} with a reference to a file or URL or directly * pass code snippet into the virtual machine via {@link #eval(java.lang.String, java.lang.String)}. - * Support for individual languages is initialized on demand - e.g. once a file of certain mime type + * Support for individual languages is initialized on demand - e.g. once a file of certain MIME type * is about to be processed, its appropriate engine (if found), is initialized. Once an engine gets * initialized, it remains so, until the virtual machine isn't garbage collected. *

@@ -104,9 +104,15 @@ LOG.log(Level.CONFIG, "Cannot process " + u + " as language definition", ex); continue; } - Language l = new Language(p); - for (String mimeType : l.getMimeTypes()) { - langs.put(mimeType, l); + for (int cnt = 1;; cnt++) { + String prefix = "language" + cnt + "."; + if (p.getProperty(prefix + "name") == null) { + break; + } + Language l = new Language(prefix, p); + for (String mimeType : l.getMimeTypes()) { + langs.put(mimeType, l); + } } } } @@ -190,7 +196,7 @@ } /** - * Changes the defaut input for languages running in to be created + * Changes the default input for languages running in to be created * {@link TruffleVM virtual machine}. The default is to use {@link System#out}. * * @param r the reader to use as input @@ -224,7 +230,7 @@ /** * Descriptions of languages supported in this Truffle virtual machine. * - * @return an immutable map with keys being mimetypes and values the {@link Language + * @return an immutable map with keys being MIME types and values the {@link Language * descriptions} of associated languages */ public Map getLanguages() { @@ -233,7 +239,7 @@ /** * Evaluates file located on a given URL. Is equivalent to loading the content of a file and - * executing it via {@link #eval(java.lang.String, java.lang.String)} with a mime type guess + * executing it via {@link #eval(java.lang.String, java.lang.String)} with a MIME type guess * based on the file's extension and/or content. * * @param location the location of a file to execute @@ -263,43 +269,43 @@ } TruffleLanguage l = getTruffleLang(mimeType); if (l == null) { - throw new IOException("No language for " + location + " with mime type " + mimeType + " found. Supported types: " + langs.keySet()); + throw new IOException("No language for " + location + " with MIME type " + mimeType + " found. Supported types: " + langs.keySet()); } return SPI.eval(l, s); } /** - * Evaluates code snippet. Chooses a language registered for a given mime type (throws + * Evaluates code snippet. Chooses a language registered for a given MIME type (throws * {@link IOException} if there is none). And passes the specified code to it for execution. * - * @param mimeType mime type of the code snippet - chooses the right language + * @param mimeType MIME type of the code snippet - chooses the right language * @param reader the source of code snippet to execute - * @return result of an exceution, possibly null + * @return result of an execution, possibly null * @throws IOException thrown to signal errors while processing the code */ public Object eval(String mimeType, Reader reader) throws IOException { checkThread(); TruffleLanguage l = getTruffleLang(mimeType); if (l == null) { - throw new IOException("No language for mime type " + mimeType + " found. Supported types: " + langs.keySet()); + throw new IOException("No language for MIME type " + mimeType + " found. Supported types: " + langs.keySet()); } return SPI.eval(l, Source.fromReader(reader, mimeType)); } /** - * Evaluates code snippet. Chooses a language registered for a given mime type (throws + * Evaluates code snippet. Chooses a language registered for a given MIME type (throws * {@link IOException} if there is none). And passes the specified code to it for execution. * - * @param mimeType mime type of the code snippet - chooses the right language + * @param mimeType MIME type of the code snippet - chooses the right language * @param code the code snippet to execute - * @return result of an exceution, possibly null + * @return result of an execution, possibly null * @throws IOException thrown to signal errors while processing the code */ public Object eval(String mimeType, String code) throws IOException { checkThread(); TruffleLanguage l = getTruffleLang(mimeType); if (l == null) { - throw new IOException("No language for mime type " + mimeType + " found. Supported types: " + langs.keySet()); + throw new IOException("No language for MIME type " + mimeType + " found. Supported types: " + langs.keySet()); } return SPI.eval(l, Source.fromText(code, mimeType)); } @@ -309,13 +315,13 @@ * program via one of your {@link #eval(java.lang.String, java.lang.String)} and then look * expected symbol up using this method. *

- * The names of the symbols are language dependant, but for example the Java language bindings + * The names of the symbols are language dependent, but for example the Java language bindings * follow the specification for method references: *

    *
  • "java.lang.Exception::new" is a reference to constructor of {@link Exception} *
  • "java.lang.Integer::valueOf" is a reference to static method in {@link Integer} class *
- * Once an symbol is obtained, it remembers values for fast acces and is ready for being + * Once an symbol is obtained, it remembers values for fast access and is ready for being * invoked. * * @param globalName the name of the symbol to find @@ -327,12 +333,22 @@ Object global = null; for (Language dl : langs.values()) { TruffleLanguage l = dl.getImpl(); - obj = SPI.findExportedSymbol(l, globalName); + obj = SPI.findExportedSymbol(l, globalName, true); if (obj != null) { global = SPI.languageGlobal(l); break; } } + if (obj == null) { + for (Language dl : langs.values()) { + TruffleLanguage l = dl.getImpl(); + obj = SPI.findExportedSymbol(l, globalName, false); + if (obj != null) { + global = SPI.languageGlobal(l); + break; + } + } + } return obj == null ? null : new Symbol(obj, global); } @@ -391,28 +407,30 @@ * Description of a language registered in {@link TruffleVM Truffle virtual machine}. Languages * are registered by {@link Registration} annotation which stores necessary information into a * descriptor inside of the language's JAR file. When a new {@link TruffleVM} is created, it - * reads all available descritors and creates {@link Language} objects to represent them. One - * can obtain a {@link #getName() name} or list of supported {@link #getMimeTypes() mimetypes} + * reads all available descriptors and creates {@link Language} objects to represent them. One + * can obtain a {@link #getName() name} or list of supported {@link #getMimeTypes() MIME types} * for each language. The actual language implementation is not initialized until * {@link TruffleVM#eval(java.lang.String, java.lang.String) a code is evaluated} in it. */ public final class Language { private final Properties props; private TruffleLanguage impl; + private final String prefix; - Language(Properties props) { + Language(String prefix, Properties props) { + this.prefix = prefix; this.props = props; } /** - * Mimetypes recognized by the language. + * MIME types recognized by the language. * - * @return returns immutable set of recognized mimetypes + * @return returns immutable set of recognized MIME types */ public Set getMimeTypes() { TreeSet ts = new TreeSet<>(); for (int i = 0;; i++) { - String mt = props.getProperty("mimeType." + i); + String mt = props.getProperty(prefix + "mimeType." + i); if (mt == null) { break; } @@ -427,12 +445,12 @@ * @return string giving the language a name */ public String getName() { - return props.getProperty("name"); + return props.getProperty(prefix + "name"); } TruffleLanguage getImpl() { if (impl == null) { - String n = props.getProperty("className"); + String n = props.getProperty(prefix + "className"); try { Class langClazz = Class.forName(n, true, loader()); Constructor constructor = langClazz.getConstructor(Env.class); @@ -459,7 +477,17 @@ if (l == ownLang) { continue; } - Object obj = SPI.findExportedSymbol(l, globalName); + Object obj = SPI.findExportedSymbol(l, globalName, true); + if (obj != null) { + return obj; + } + } + for (Language dl : uniqueLang) { + TruffleLanguage l = dl.getImpl(); + if (l == ownLang) { + continue; + } + Object obj = SPI.findExportedSymbol(l, globalName, false); if (obj != null) { return obj; } @@ -478,8 +506,8 @@ } @Override - public Object findExportedSymbol(TruffleLanguage l, String globalName) { - return super.findExportedSymbol(l, globalName); + public Object findExportedSymbol(TruffleLanguage l, String globalName, boolean onlyExplicit) { + return super.findExportedSymbol(l, globalName, onlyExplicit); } @Override diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/LanguageRegistrationProcessor.java --- a/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/LanguageRegistrationProcessor.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/LanguageRegistrationProcessor.java Thu Jun 04 11:08:12 2015 -0700 @@ -37,33 +37,50 @@ @SupportedAnnotationTypes("com.oracle.truffle.api.*") public final class LanguageRegistrationProcessor extends AbstractProcessor { + private final List registrations = new ArrayList<>(); + @Override public SourceVersion getSupportedSourceVersion() { return SourceVersion.latest(); } - private void createProviderFile(TypeElement language, Registration annotation) { + private void generateFile(List languages) { String filename = "META-INF/truffle/language"; - try { - FileObject file = processingEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT, "", filename, language); - Properties p = new Properties(); - String className = processingEnv.getElementUtils().getBinaryName(language).toString(); - p.setProperty("name", annotation.name()); - p.setProperty("className", className); + Properties p = new Properties(); + int cnt = 0; + for (TypeElement l : languages) { + Registration annotation = l.getAnnotation(Registration.class); + if (annotation == null) { + continue; + } + String prefix = "language" + ++cnt + "."; + String className = processingEnv.getElementUtils().getBinaryName(l).toString(); + p.setProperty(prefix + "name", annotation.name()); + p.setProperty(prefix + "className", className); String[] mimes = annotation.mimeType(); for (int i = 0; i < mimes.length; i++) { - p.setProperty("mimeType." + i, mimes[i]); + p.setProperty(prefix + "mimeType." + i, mimes[i]); } - try (OutputStream os = file.openOutputStream()) { - p.store(os, "Generated by " + LanguageRegistrationProcessor.class.getName()); + } + if (cnt > 0) { + try { + FileObject file = processingEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT, "", filename, languages.toArray(new Element[0])); + try (OutputStream os = file.openOutputStream()) { + p.store(os, "Generated by " + LanguageRegistrationProcessor.class.getName()); + } + } catch (IOException e) { + processingEnv.getMessager().printMessage(Kind.ERROR, e.getMessage(), languages.get(0)); } - } catch (IOException e) { - processingEnv.getMessager().printMessage(Kind.ERROR, e.getMessage(), language); } } @Override public boolean process(Set annotations, RoundEnvironment roundEnv) { + if (roundEnv.processingOver()) { + generateFile(registrations); + registrations.clear(); + return true; + } for (Element e : roundEnv.getElementsAnnotatedWith(Registration.class)) { Registration annotation = e.getAnnotation(Registration.class); if (annotation != null && e.getKind() == ElementKind.CLASS) { @@ -103,7 +120,7 @@ continue; } assertNoErrorExpected(e); - createProviderFile((TypeElement) e, annotation); + registrations.add((TypeElement) e); } } diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/TruffleProcessor.java --- a/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/TruffleProcessor.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/TruffleProcessor.java Thu Jun 04 11:08:12 2015 -0700 @@ -40,12 +40,16 @@ */ // @SupportedAnnotationTypes({"com.oracle.truffle.codegen.Operation", // "com.oracle.truffle.codegen.TypeLattice"}) -@SupportedSourceVersion(SourceVersion.RELEASE_7) public class TruffleProcessor extends AbstractProcessor implements ProcessCallback { private List> generators; @Override + public SourceVersion getSupportedSourceVersion() { + return SourceVersion.latest(); + } + + @Override public boolean process(Set annotations, RoundEnvironment roundEnv) { if (!roundEnv.processingOver()) { processImpl(roundEnv); diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.truffle.interop/src/com/oracle/truffle/interop/SymbolInvokerImpl.java --- a/graal/com.oracle.truffle.interop/src/com/oracle/truffle/interop/SymbolInvokerImpl.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.truffle.interop/src/com/oracle/truffle/interop/SymbolInvokerImpl.java Thu Jun 04 11:08:12 2015 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -29,8 +29,8 @@ import com.oracle.truffle.api.*; import com.oracle.truffle.api.frame.*; import com.oracle.truffle.api.impl.*; -import com.oracle.truffle.api.instrument.*; import com.oracle.truffle.api.interop.*; +import com.oracle.truffle.api.interop.exception.UnsupportedMessageException; import com.oracle.truffle.api.nodes.*; import com.oracle.truffle.interop.messages.*; import com.oracle.truffle.interop.node.*; @@ -40,10 +40,48 @@ @Override protected Object invoke(Object symbol, Object... arr) throws IOException { - ForeignObjectAccessNode executeMain = ForeignObjectAccessNode.getAccess(Execute.create(Receiver.create(), arr.length)); - CallTarget callTarget = Truffle.getRuntime().createCallTarget(new TemporaryRoot(executeMain, (TruffleObject) symbol, arr)); + if (symbol instanceof String) { + return symbol; + } + if (symbol instanceof Number) { + return symbol; + } + if (symbol instanceof Boolean) { + return symbol; + } + ForeignObjectAccessNode callMain = ForeignObjectAccessNode.getAccess(Execute.create(Receiver.create(), arr.length)); + CallTarget callMainTarget = Truffle.getRuntime().createCallTarget(new TemporaryRoot(callMain, (TruffleObject) symbol, arr)); VirtualFrame frame = Truffle.getRuntime().createVirtualFrame(arr, UNUSED_FRAMEDESCRIPTOR); - return callTarget.call(frame); + Object ret = callMainTarget.call(frame); + if (ret instanceof TruffleObject) { + TruffleObject tret = (TruffleObject) ret; + Object isBoxedResult; + try { + ForeignObjectAccessNode isBoxed = ForeignObjectAccessNode.getAccess(IsBoxed.create(Receiver.create())); + CallTarget isBoxedTarget = Truffle.getRuntime().createCallTarget(new TemporaryRoot(isBoxed, tret)); + isBoxedResult = isBoxedTarget.call(frame); + } catch (UnsupportedMessageException ex) { + isBoxedResult = false; + } + if (Boolean.TRUE.equals(isBoxedResult)) { + ForeignObjectAccessNode unbox = ForeignObjectAccessNode.getAccess(Unbox.create(Receiver.create())); + CallTarget unboxTarget = Truffle.getRuntime().createCallTarget(new TemporaryRoot(unbox, tret)); + Object unboxResult = unboxTarget.call(frame); + return unboxResult; + } else { + try { + ForeignObjectAccessNode isNull = ForeignObjectAccessNode.getAccess(IsNull.create(Receiver.create())); + CallTarget isNullTarget = Truffle.getRuntime().createCallTarget(new TemporaryRoot(isNull, tret)); + Object isNullResult = isNullTarget.call(frame); + if (Boolean.TRUE.equals(isNullResult)) { + return null; + } + } catch (UnsupportedMessageException ex) { + // fallthrough + } + } + } + return ret; } private static class TemporaryRoot extends RootNode { @@ -58,11 +96,6 @@ } @Override - public void applyInstrumentation() { - Probe.applyASTProbers(foreignAccess); - } - - @Override public Object execute(VirtualFrame frame) { return foreignAccess.executeForeign(frame, function, args); } diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.truffle.object.basic/src/com/oracle/truffle/object/basic/DefaultLayoutFactory.java --- a/graal/com.oracle.truffle.object.basic/src/com/oracle/truffle/object/basic/DefaultLayoutFactory.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.truffle.object.basic/src/com/oracle/truffle/object/basic/DefaultLayoutFactory.java Thu Jun 04 11:08:12 2015 -0700 @@ -30,6 +30,10 @@ return BasicLayout.createLayoutImpl(layoutBuilder.getAllowedImplicitCasts(), new DefaultStrategy()); } + public Property createProperty(Object id, Location location) { + return createProperty(id, location, 0); + } + public Property createProperty(Object id, Location location, int flags) { return new PropertyImpl(id, location, flags); } diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.truffle.object/src/com/oracle/truffle/object/DynamicObjectImpl.java --- a/graal/com.oracle.truffle.object/src/com/oracle/truffle/object/DynamicObjectImpl.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.truffle.object/src/com/oracle/truffle/object/DynamicObjectImpl.java Thu Jun 04 11:08:12 2015 -0700 @@ -209,8 +209,8 @@ Shape oldShape = getShape(); Property existing = oldShape.getProperty(id); if (existing != null) { - Integer newFlags = updateFunction.apply(existing.getFlags()); - if (newFlags != null && existing.getFlags() != newFlags.intValue()) { + int newFlags = updateFunction.apply(existing.getFlags()); + if (existing.getFlags() != newFlags) { Property newProperty = existing.copyWithFlags(newFlags); Shape newShape = oldShape.replaceProperty(existing, newProperty); this.setShape(newShape); diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.truffle.object/src/com/oracle/truffle/object/PropertyImpl.java --- a/graal/com.oracle.truffle.object/src/com/oracle/truffle/object/PropertyImpl.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.truffle.object/src/com/oracle/truffle/object/PropertyImpl.java Thu Jun 04 11:08:12 2015 -0700 @@ -42,6 +42,8 @@ * Generic, usual-case constructor for properties storing at least a name. * * @param key the name of the property + * @param location the storage location used to access the property + * @param flags property flags (optional) */ protected PropertyImpl(Object key, Location location, int flags, boolean shadow, boolean relocatable) { this.key = Objects.requireNonNull(key); @@ -67,8 +69,8 @@ @Override public Property relocate(Location newLocation) { - if ((getLocation() == null || !getLocation().equals(newLocation)) && relocatable) { - return construct(getKey(), newLocation, getFlags()); + if (!getLocation().equals(newLocation) && relocatable) { + return construct(key, newLocation, flags); } return this; } @@ -163,8 +165,7 @@ } PropertyImpl other = (PropertyImpl) obj; - return key.equals(other.key) && ((location == null && other.location == null) || (location != null && location.equals(other.location))) && flags == other.flags && shadow == other.shadow && - relocatable == other.relocatable; + return key.equals(other.key) && location.equals(other.location) && flags == other.flags && shadow == other.shadow && relocatable == other.relocatable; } @Override @@ -189,7 +190,7 @@ int result = 1; result = prime * result + getClass().hashCode(); result = prime * result + key.hashCode(); - result = prime * result + (location != null ? location.hashCode() : 0); + result = prime * result + location.hashCode(); result = prime * result + flags; return result; } @@ -240,7 +241,7 @@ private Property relocateShadow(Location newLocation) { assert !isShadow() && getLocation() instanceof DeclaredLocation && relocatable; - return new PropertyImpl(getKey(), newLocation, flags, true, relocatable); + return new PropertyImpl(key, newLocation, flags, true, relocatable); } @SuppressWarnings("hiding") diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/SLTckTest.java --- a/graal/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/SLTckTest.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/SLTckTest.java Thu Jun 04 11:08:12 2015 -0700 @@ -41,18 +41,27 @@ @Override protected TruffleVM prepareVM() throws Exception { TruffleVM vm = TruffleVM.newVM().build(); - vm.eval("application/x-sl", // your langage - "function fourtyTwo() {\n" + // your script - " return 42;\n" + // - "}\n" + // - "function plus(a, b) {\n" + // - " return a + b;\n" + // - "}\n" // + // @formatter:off + vm.eval("application/x-sl", + "function fourtyTwo() {\n" + + " return 42;\n" + // + "}\n" + + "function plus(a, b) {\n" + + " return a + b;\n" + + "}\n" + + "function null() {\n" + + "}\n" ); + // @formatter:on return vm; } @Override + protected String mimeType() { + return "application/x-sl"; + } + + @Override protected String fourtyTwo() { return "fourtyTwo"; } @@ -61,4 +70,19 @@ protected String plusInt() { return "plus"; } + + @Override + protected String returnsNull() { + return "null"; + } + + @Override + protected String invalidCode() { + // @formatter:off + return + "f unction main() {\n" + + " retu rn 42;\n" + + "}\n"; + // @formatter:on + } } diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/SLMain.java --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/SLMain.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/SLMain.java Thu Jun 04 11:08:12 2015 -0700 @@ -148,13 +148,18 @@ } } - /* Demonstrate per-type tabulation of node execution counts */ + /* Enables demonstration of per-type tabulation of node execution counts */ private static boolean nodeExecCounts = false; - /* Demonstrate per-line tabulation of STATEMENT node execution counts */ + /* Enables demonstration of per-line tabulation of STATEMENT node execution counts */ private static boolean statementCounts = false; - /* Demonstrate per-line tabulation of STATEMENT coverage */ + /* Enables demonstration of er-line tabulation of STATEMENT coverage */ private static boolean coverage = false; + /* Small tools that can be installed for demonstration */ + private static NodeExecCounter nodeExecCounter = null; + private static NodeExecCounter statementExecCounter = null; + private static CoverageTracker coverageTracker = null; + /** * The main entry point. Use the mx command "mx sl" to run it with the correct class path setup. */ @@ -162,6 +167,8 @@ TruffleVM vm = TruffleVM.newVM().build(); assert vm.getLanguages().containsKey("application/x-sl"); + setupToolDemos(); + int repeats = 1; if (args.length >= 2) { repeats = Integer.parseInt(args[1]); @@ -179,8 +186,12 @@ while (repeats-- > 0) { main.invoke(null); } + reportToolDemos(); } + /** + * Temporary method during API evolution, supports debugger integration. + */ public static void run(Source source) throws IOException { TruffleVM vm = TruffleVM.newVM().build(); assert vm.getLanguages().containsKey("application/x-sl"); @@ -204,28 +215,6 @@ // logOutput.println("Source = " + source.getCode()); } - if (statementCounts || coverage) { - Probe.registerASTProber(new SLStandardASTProber()); - } - - NodeExecCounter nodeExecCounter = null; - if (nodeExecCounts) { - nodeExecCounter = new NodeExecCounter(); - nodeExecCounter.install(); - } - - NodeExecCounter statementExecCounter = null; - if (statementCounts) { - statementExecCounter = new NodeExecCounter(StandardSyntaxTag.STATEMENT); - statementExecCounter.install(); - } - - CoverageTracker coverageTracker = null; - if (coverage) { - coverageTracker = new CoverageTracker(); - coverageTracker.install(); - } - /* Parse the SL source file. */ Object result = context.eval(source); if (result != null) { @@ -253,7 +242,7 @@ /* Call the main entry point, without any arguments. */ try { result = main.invoke(null); - if (result != SLNull.SINGLETON) { + if (result != null) { out.println(result); } } catch (UnsupportedSpecializationException ex) { @@ -272,18 +261,6 @@ } finally { printScript("after execution", LAST.context, logOutput, printASTToLog, printSourceAttributionToLog, dumpASTToIGV); } - if (nodeExecCounter != null) { - nodeExecCounter.print(System.out); - nodeExecCounter.dispose(); - } - if (statementExecCounter != null) { - statementExecCounter.print(System.out); - statementExecCounter.dispose(); - } - if (coverageTracker != null) { - coverageTracker.print(System.out); - coverageTracker.dispose(); - } return totalRuntime; } @@ -382,12 +359,16 @@ @Override protected Object eval(Source code) throws IOException { - context.executeMain(code); + try { + context.executeMain(code); + } catch (Exception e) { + throw new IOException(e); + } return null; } @Override - protected Object findExportedSymbol(String globalName) { + protected Object findExportedSymbol(String globalName, boolean onlyExplicit) { for (SLFunction f : context.getFunctionRegistry().getFunctions()) { if (globalName.equals(f.getName())) { return f; @@ -406,4 +387,39 @@ return object instanceof SLFunction; } + private static void setupToolDemos() { + if (statementCounts || coverage) { + Probe.registerASTProber(new SLStandardASTProber()); + } + if (nodeExecCounts) { + nodeExecCounter = new NodeExecCounter(); + nodeExecCounter.install(); + } + + if (statementCounts) { + statementExecCounter = new NodeExecCounter(StandardSyntaxTag.STATEMENT); + statementExecCounter.install(); + } + + if (coverage) { + coverageTracker = new CoverageTracker(); + coverageTracker.install(); + } + } + + private static void reportToolDemos() { + if (nodeExecCounter != null) { + nodeExecCounter.print(System.out); + nodeExecCounter.dispose(); + } + if (statementExecCounter != null) { + statementExecCounter.print(System.out); + statementExecCounter.dispose(); + } + if (coverageTracker != null) { + coverageTracker.print(System.out); + coverageTracker.dispose(); + } + } + } diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/runtime/SLFunctionForeignAccess.java --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/runtime/SLFunctionForeignAccess.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/runtime/SLFunctionForeignAccess.java Thu Jun 04 11:08:12 2015 -0700 @@ -32,6 +32,7 @@ import com.oracle.truffle.api.nodes.RootNode; import com.oracle.truffle.interop.ForeignAccessArguments; import com.oracle.truffle.interop.messages.Execute; +import com.oracle.truffle.interop.messages.IsNull; import com.oracle.truffle.interop.messages.Receiver; import com.oracle.truffle.sl.nodes.call.SLDispatchNode; import com.oracle.truffle.sl.nodes.call.SLDispatchNodeGen; @@ -55,6 +56,8 @@ public CallTarget getAccess(Message tree) { if (Execute.create(Receiver.create(), 0).matchStructure(tree)) { return Truffle.getRuntime().createCallTarget(new SLForeignCallerRootNode()); + } else if (IsNull.create(Receiver.create()).matchStructure(tree)) { + return Truffle.getRuntime().createCallTarget(new SLForeignNullCheckNode()); } else { throw new UnsupportedMessageException(tree.toString() + " not supported"); } @@ -87,4 +90,11 @@ } + private static class SLForeignNullCheckNode extends RootNode { + @Override + public Object execute(VirtualFrame frame) { + Object receiver = ForeignAccessArguments.getReceiver(frame.getArguments()); + return SLNull.SINGLETON == receiver; + } + } } diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/runtime/SLNull.java --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/runtime/SLNull.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/runtime/SLNull.java Thu Jun 04 11:08:12 2015 -0700 @@ -22,6 +22,9 @@ */ package com.oracle.truffle.sl.runtime; +import com.oracle.truffle.api.interop.ForeignAccessFactory; +import com.oracle.truffle.api.interop.TruffleObject; + /** * The SL type for a {@code null} (i.e., undefined) value. In Truffle, it is generally discouraged * to use the Java {@code null} value to represent the guest language {@code null} value. It is not @@ -30,7 +33,7 @@ * language {@code null} as a singleton, as in {@link #SINGLETON this class}, is the recommended * practice. */ -public final class SLNull { +public final class SLNull implements TruffleObject { /** * The canonical value to represent {@code null} in SL. @@ -52,4 +55,9 @@ public String toString() { return "null"; } + + @Override + public ForeignAccessFactory getForeignAccessFactory() { + return SLFunctionForeignAccess.INSTANCE; + } } diff -r bc2ec35a7189 -r 27943aac2e3c graal/com.oracle.truffle.tools.debug.engine/src/com/oracle/truffle/tools/debug/engine/DebugEngine.java --- a/graal/com.oracle.truffle.tools.debug.engine/src/com/oracle/truffle/tools/debug/engine/DebugEngine.java Thu Jun 04 10:46:23 2015 -0700 +++ b/graal/com.oracle.truffle.tools.debug.engine/src/com/oracle/truffle/tools/debug/engine/DebugEngine.java Thu Jun 04 11:08:12 2015 -0700 @@ -41,7 +41,6 @@ public final class DebugEngine { private static final boolean TRACE = false; - private static final boolean TRACE_PROBES = false; private static final String TRACE_PREFIX = "DEBUG ENGINE: "; private static final PrintStream OUT = System.out; @@ -49,9 +48,8 @@ private static final SyntaxTag STEPPING_TAG = StandardSyntaxTag.STATEMENT; private static final SyntaxTag CALL_TAG = StandardSyntaxTag.CALL; - @SuppressWarnings("unused") private static void trace(String format, Object... args) { - if (TRACE || TRACE_PROBES) { + if (TRACE) { OUT.println(TRACE_PREFIX + String.format(format, args)); } } @@ -151,38 +149,6 @@ this.lineBreaks = new LineBreakpointFactory(sourceExecutionProvider, breakpointCallback, warningLog); this.tagBreaks = new TagBreakpointFactory(sourceExecutionProvider, breakpointCallback, warningLog); - - if (TRACE_PROBES) { - Probe.addProbeListener(new ProbeListener() { - - private Source beingProbed = null; - - @Override - public void startASTProbing(Source source) { - final String sourceName = source == null ? "" : source.getShortName(); - trace("START PROBING %s", sourceName); - beingProbed = source; - } - - @Override - public void newProbeInserted(Probe probe) { - trace("PROBE ADDED %s", probe.getShortDescription()); - } - - @Override - public void probeTaggedAs(Probe probe, SyntaxTag tag, Object tagValue) { - trace("PROBE TAGGED as %s: %s", tag, probe.getShortDescription()); - } - - @Override - public void endASTProbing(Source source) { - final String sourceName = source == null ? "" : source.getShortName(); - trace("FINISHED PROBING %s", sourceName); - assert source == beingProbed; - beingProbed = null; - } - }); - } } public static DebugEngine create(DebugClient debugClient, SourceExecutionProvider sourceExecutionProvider) { diff -r bc2ec35a7189 -r 27943aac2e3c make/Makefile --- a/make/Makefile Thu Jun 04 10:46:23 2015 -0700 +++ b/make/Makefile Thu Jun 04 11:08:12 2015 -0700 @@ -323,6 +323,7 @@ # Builds code that can be shared among different build flavors buildshared: $(PYTHON) -u $(GAMMADIR)/mxtool/mx.py build --no-native --export-dir $(SHARED_DIR) + #cd .. && $(MAKE) -f make/jvmci.make TARGET=build/make MX_TARGET=. HS_COMMON_SRC=$(HS_COMMON_SRC) JDK=$(ABS_BOOTDIR) EXPORT_DIR=$(SHARED_DIR) VERBOSE=0 export # Export file rule generic_export: $(EXPORT_LIST) diff -r bc2ec35a7189 -r 27943aac2e3c make/defs.make --- a/make/defs.make Thu Jun 04 10:46:23 2015 -0700 +++ b/make/defs.make Thu Jun 04 11:08:12 2015 -0700 @@ -375,12 +375,14 @@ endif EXPORT_LIST += $(EXPORT_JRE_LIB_JVMCI_SERVICES_DIR)/com.oracle.graal.api.runtime.GraalRuntimeAccess +EXPORT_LIST += $(EXPORT_JRE_LIB_JVMCI_SERVICES_DIR)/com.oracle.graal.code.DisassemblerProvider EXPORT_LIST += $(EXPORT_JRE_LIB_JVMCI_SERVICES_DIR)/com.oracle.graal.compiler.match.MatchStatementSet EXPORT_LIST += $(EXPORT_JRE_LIB_JVMCI_SERVICES_DIR)/com.oracle.graal.hotspot.HotSpotBackendFactory EXPORT_LIST += $(EXPORT_JRE_LIB_JVMCI_SERVICES_DIR)/com.oracle.graal.nodes.spi.ReplacementsProvider EXPORT_LIST += $(EXPORT_JRE_LIB_JVMCI_SERVICES_DIR)/com.oracle.graal.phases.tiers.CompilerConfiguration EXPORT_LIST += $(EXPORT_JRE_LIB_JVMCI_SERVICES_DIR)/com.oracle.graal.truffle.hotspot.nfi.RawNativeCallNodeFactory EXPORT_LIST += $(EXPORT_JRE_LIB_JVMCI_SERVICES_DIR)/com.oracle.graal.truffle.OptimizedCallTargetInstrumentationFactory +EXPORT_LIST += $(EXPORT_JRE_LIB_JVMCI_SERVICES_DIR)/com.oracle.graal.truffle.LoopNodeFactory EXPORT_LIST += $(EXPORT_JRE_LIB_JVMCI_SERVICES_DIR)/com.oracle.truffle.api.TruffleRuntimeAccess EXPORT_LIST += $(EXPORT_JRE_LIB_JVMCI_SERVICES_DIR)/com.oracle.nfi.api.NativeFunctionInterfaceAccess diff -r bc2ec35a7189 -r 27943aac2e3c make/jvmci.make --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/make/jvmci.make Thu Jun 04 11:08:12 2015 -0700 @@ -0,0 +1,196 @@ +[?1034hVERBOSE= +TARGET=. +JDK= + +WGET=wget +JAVAC=$(JDK)/bin/javac -g -target 1.8 +JAR=$(JDK)/bin/jar + +EXPORT_DIR=export +EXPORTED_FILES_ADDITIONAL=$(TARGET)/options $(TARGET)/services +HS_COMMON_SRC=. +# where all other stuff built by mx (graal.jar) resides +MX_TARGET=. +PROVIDERS_INF=/META-INF/providers/ +SERVICES_INF=/META-INF/services/ +OPTIONS_INF=/META-INF/options/ + +ifeq ($(JDK),) + $(error Variable JDK must be set to a JDK installation.) + endif + ifneq ($(VERBOSE),) + SHELL=sh -x +endif + +define process_options = + $(eval providers=$(1)/$(PROVIDERS_INF)) + $(eval services=$(1)/$(SERVICES_INF)) + $(eval options=$(1)/$(OPTIONS_INF)) + test -d $(services) || mkdir -p $(services) + test ! -d $(providers) || (cd $(providers) && for i in $$(ls $(providers)); do c=$$(cat $$i); echo $$i >> $(services)$$c; rm $$i; done) + + # We're building all projects together with one javac call; thus we cannot determine, from which project the generated file is thus we hardcode it for now + $(eval vmconfig=$(1)/hotspot/HotSpotVMConfig.inline.hpp) + $(eval vmconfigDest=$(HS_COMMON_SRC)/../graal/com.oracle.jvmci.hotspot/src_gen/hotspot) + test ! -f $(vmconfig) || (mkdir -p $(vmconfigDest) && cp $(vmconfig) $(vmconfigDest)) +endef + +define extract = + $(eval TMP := $(shell mktemp -d)) + mkdir -p $(2); + cd $(TMP) && $(JAR) xf $(abspath $(1)) && ((test ! -d .$(SERVICES_INF) || cp -r .$(SERVICES_INF) $(abspath $(2))) && (test ! -d .$(OPTIONS_INF) || cp -r .$(OPTIONS_INF) $(abspath $(2)))) + rm -r $(TMP) + cp $(1) $(2) +endef + + +all: default + +export: all + mkdir -p $(EXPORT_DIR) + $(foreach export,$(EXPORTED_FILES),$(call extract,$(export),$(EXPORT_DIR))) +.PHONY: export + + + +EXPORTED_FILES += $(MX_TARGET)/build/truffle.jar + +EXPORTED_FILES += $(MX_TARGET)/build/graal.jar + +EXPORTED_FILES += $(MX_TARGET)/build/graal-truffle.jar + +JDK_BOOTCLASSPATH = $(JDK)/jre/lib/resources.jar:$(JDK)/jre/lib/rt.jar:$(JDK)/jre/lib/jsse.jar:$(JDK)/jre/lib/jce.jar:$(JDK)/jre/lib/charsets.jar:$(JDK)/jre/lib/jfr.jar + +COM_ORACLE_JVMCI_HOTSPOTVMCONFIG_PROCESSOR_SRC = $(shell find graal/com.oracle.jvmci.hotspotvmconfig/src -type f -name *.java 2> /dev/null) +COM_ORACLE_JVMCI_HOTSPOTVMCONFIG_PROCESSOR_SRC += $(shell find graal/com.oracle.jvmci.common/src -type f -name *.java 2> /dev/null) +COM_ORACLE_JVMCI_HOTSPOTVMCONFIG_PROCESSOR_SRC += $(shell find graal/com.oracle.jvmci.hotspotvmconfig.processor/src -type f -name *.java 2> /dev/null) + +COM_ORACLE_JVMCI_HOTSPOTVMCONFIG_PROCESSOR_JAR = $(TARGET)/graal/com.oracle.jvmci.hotspotvmconfig.processor/ap/com.oracle.jvmci.hotspotvmconfig.processor.jar + +COM_ORACLE_JVMCI_SERVICE_PROCESSOR_SRC = $(shell find graal/com.oracle.jvmci.service/src -type f -name *.java 2> /dev/null) +COM_ORACLE_JVMCI_SERVICE_PROCESSOR_SRC += $(shell find graal/com.oracle.jvmci.service.processor/src -type f -name *.java 2> /dev/null) + +COM_ORACLE_JVMCI_SERVICE_PROCESSOR_JAR = $(TARGET)/graal/com.oracle.jvmci.service.processor/ap/com.oracle.jvmci.service.processor.jar + +COM_ORACLE_JVMCI_OPTIONS_PROCESSOR_SRC = $(shell find graal/com.oracle.jvmci.service/src -type f -name *.java 2> /dev/null) +COM_ORACLE_JVMCI_OPTIONS_PROCESSOR_SRC += $(shell find graal/com.oracle.jvmci.options/src -type f -name *.java 2> /dev/null) +COM_ORACLE_JVMCI_OPTIONS_PROCESSOR_SRC += $(shell find graal/com.oracle.jvmci.options.processor/src -type f -name *.java 2> /dev/null) + +COM_ORACLE_JVMCI_OPTIONS_PROCESSOR_JAR = $(TARGET)/graal/com.oracle.jvmci.options.processor/ap/com.oracle.jvmci.options.processor.jar + +JVMCI_UTIL_SRC = $(shell find graal/com.oracle.jvmci.bytecode/src -type f -name *.java 2> /dev/null) +JVMCI_UTIL_SRC += $(shell find graal/com.oracle.jvmci.asm/src -type f -name *.java 2> /dev/null) +JVMCI_UTIL_SRC += $(shell find graal/com.oracle.jvmci.amd64/src -type f -name *.java 2> /dev/null) +JVMCI_UTIL_SRC += $(shell find graal/com.oracle.jvmci.asm.amd64/src -type f -name *.java 2> /dev/null) +JVMCI_UTIL_SRC += $(shell find graal/com.oracle.jvmci.sparc/src -type f -name *.java 2> /dev/null) +JVMCI_UTIL_SRC += $(shell find graal/com.oracle.jvmci.asm.sparc/src -type f -name *.java 2> /dev/null) + +JVMCI_UTIL_JAR = $(TARGET)/build/jvmci-util.jar + +JVMCI_UTIL_DEP_JARS = $(TARGET)/build/jvmci-service.jar $(TARGET)/build/jvmci-api.jar + +EXPORTED_FILES += $(JVMCI_UTIL_JAR) + +JVMCI_SERVICE_SRC = $(shell find graal/com.oracle.jvmci.service/src -type f -name *.java 2> /dev/null) + +JVMCI_SERVICE_JAR = $(TARGET)/build/jvmci-service.jar + +JVMCI_SERVICE_DEP_JARS = graal/findbugs-SuppressFBWarnings.jar + +EXPORTED_FILES += $(JVMCI_SERVICE_JAR) + +JVMCI_HOTSPOT_SRC = $(shell find graal/com.oracle.jvmci.hotspotvmconfig/src -type f -name *.java 2> /dev/null) +JVMCI_HOTSPOT_SRC += $(shell find graal/com.oracle.jvmci.hotspotvmconfig/graal/com.oracle.jvmci.hotspotvmconfig/src_gen -type f -name *.java 2> /dev/null) +JVMCI_HOTSPOT_SRC += $(shell find graal/com.oracle.jvmci.hotspot/src -type f -name *.java 2> /dev/null) +JVMCI_HOTSPOT_SRC += $(shell find graal/com.oracle.jvmci.hotspot/graal/com.oracle.jvmci.hotspot/src_gen -type f -name *.java 2> /dev/null) +JVMCI_HOTSPOT_SRC += $(shell find graal/com.oracle.jvmci.hotspot.amd64/src -type f -name *.java 2> /dev/null) +JVMCI_HOTSPOT_SRC += $(shell find graal/com.oracle.jvmci.hotspot.amd64/graal/com.oracle.jvmci.hotspot.amd64/src_gen -type f -name *.java 2> /dev/null) +JVMCI_HOTSPOT_SRC += $(shell find graal/com.oracle.jvmci.hotspot.sparc/src -type f -name *.java 2> /dev/null) +JVMCI_HOTSPOT_SRC += $(shell find graal/com.oracle.jvmci.hotspot.sparc/graal/com.oracle.jvmci.hotspot.sparc/src_gen -type f -name *.java 2> /dev/null) +JVMCI_HOTSPOT_SRC += $(shell find graal/com.oracle.jvmci.hotspot.jfr/src -type f -name *.java 2> /dev/null) +JVMCI_HOTSPOT_SRC += $(shell find graal/com.oracle.jvmci.hotspot.jfr/graal/com.oracle.jvmci.hotspot.jfr/src_gen -type f -name *.java 2> /dev/null) + +JVMCI_HOTSPOT_JAR = $(TARGET)/build/jvmci-hotspot.jar + +JVMCI_HOTSPOT_DEP_JARS = $(TARGET)/build/jvmci-util.jar $(TARGET)/build/jvmci-service.jar $(TARGET)/build/jvmci-api.jar graal/findbugs-SuppressFBWarnings.jar + +EXPORTED_FILES += $(JVMCI_HOTSPOT_JAR) + +JVMCI_API_SRC = $(shell find graal/com.oracle.jvmci.meta/src -type f -name *.java 2> /dev/null) +JVMCI_API_SRC += $(shell find graal/com.oracle.jvmci.code/src -type f -name *.java 2> /dev/null) +JVMCI_API_SRC += $(shell find graal/com.oracle.jvmci.runtime/src -type f -name *.java 2> /dev/null) +JVMCI_API_SRC += $(shell find graal/com.oracle.jvmci.options/src -type f -name *.java 2> /dev/null) +JVMCI_API_SRC += $(shell find graal/com.oracle.jvmci.common/src -type f -name *.java 2> /dev/null) +JVMCI_API_SRC += $(shell find graal/com.oracle.jvmci.debug/src -type f -name *.java 2> /dev/null) + +JVMCI_API_JAR = $(TARGET)/build/jvmci-api.jar + +JVMCI_API_DEP_JARS = $(TARGET)/build/jvmci-service.jar graal/findbugs-SuppressFBWarnings.jar + +EXPORTED_FILES += $(JVMCI_API_JAR) + +$(COM_ORACLE_JVMCI_HOTSPOTVMCONFIG_PROCESSOR_JAR): $(COM_ORACLE_JVMCI_HOTSPOTVMCONFIG_PROCESSOR_SRC) + $(eval TMP := $(shell mktemp -d)) + $(JAVAC) -d $(TMP) -bootclasspath $(JDK_BOOTCLASSPATH) $(COM_ORACLE_JVMCI_HOTSPOTVMCONFIG_PROCESSOR_SRC) + cp -r graal/com.oracle.jvmci.hotspotvmconfig.processor/src/META-INF $(TMP) + $(call process_options,$(TMP),False) + mkdir -p $$(dirname $(COM_ORACLE_JVMCI_HOTSPOTVMCONFIG_PROCESSOR_JAR)) + $(JAR) cf $(COM_ORACLE_JVMCI_HOTSPOTVMCONFIG_PROCESSOR_JAR) -C $(TMP) . + rm -r $(TMP) + +$(COM_ORACLE_JVMCI_SERVICE_PROCESSOR_JAR): $(COM_ORACLE_JVMCI_SERVICE_PROCESSOR_SRC) + $(eval TMP := $(shell mktemp -d)) + $(JAVAC) -d $(TMP) -bootclasspath $(JDK_BOOTCLASSPATH) $(COM_ORACLE_JVMCI_SERVICE_PROCESSOR_SRC) + cp -r graal/com.oracle.jvmci.service.processor/src/META-INF $(TMP) + $(call process_options,$(TMP),False) + mkdir -p $$(dirname $(COM_ORACLE_JVMCI_SERVICE_PROCESSOR_JAR)) + $(JAR) cf $(COM_ORACLE_JVMCI_SERVICE_PROCESSOR_JAR) -C $(TMP) . + rm -r $(TMP) + +$(COM_ORACLE_JVMCI_OPTIONS_PROCESSOR_JAR): $(COM_ORACLE_JVMCI_OPTIONS_PROCESSOR_SRC) + $(eval TMP := $(shell mktemp -d)) + $(JAVAC) -d $(TMP) -bootclasspath $(JDK_BOOTCLASSPATH) $(COM_ORACLE_JVMCI_OPTIONS_PROCESSOR_SRC) + cp -r graal/com.oracle.jvmci.options.processor/src/META-INF $(TMP) + $(call process_options,$(TMP),False) + mkdir -p $$(dirname $(COM_ORACLE_JVMCI_OPTIONS_PROCESSOR_JAR)) + $(JAR) cf $(COM_ORACLE_JVMCI_OPTIONS_PROCESSOR_JAR) -C $(TMP) . + rm -r $(TMP) + +$(JVMCI_UTIL_JAR): $(JVMCI_UTIL_SRC) $(JVMCI_UTIL_DEP_JARS) + $(eval TMP := $(shell mktemp -d)) + $(JAVAC) -d $(TMP) -bootclasspath $(JDK_BOOTCLASSPATH) -cp $(TARGET)/build/jvmci-service.jar:$(TARGET)/build/jvmci-api.jar $(JVMCI_UTIL_SRC) + + $(call process_options,$(TMP),True) + mkdir -p $$(dirname $(JVMCI_UTIL_JAR)) + $(JAR) cf $(JVMCI_UTIL_JAR) -C $(TMP) . + rm -r $(TMP) + +$(JVMCI_SERVICE_JAR): $(JVMCI_SERVICE_SRC) $(JVMCI_SERVICE_DEP_JARS) + $(eval TMP := $(shell mktemp -d)) + $(JAVAC) -d $(TMP) -bootclasspath $(JDK_BOOTCLASSPATH) -cp graal/findbugs-SuppressFBWarnings.jar $(JVMCI_SERVICE_SRC) + + $(call process_options,$(TMP),True) + mkdir -p $$(dirname $(JVMCI_SERVICE_JAR)) + $(JAR) cf $(JVMCI_SERVICE_JAR) -C $(TMP) . + rm -r $(TMP) + +$(JVMCI_HOTSPOT_JAR): $(JVMCI_HOTSPOT_SRC) $(COM_ORACLE_JVMCI_HOTSPOTVMCONFIG_PROCESSOR_JAR) $(COM_ORACLE_JVMCI_SERVICE_PROCESSOR_JAR) $(COM_ORACLE_JVMCI_OPTIONS_PROCESSOR_JAR) $(JVMCI_HOTSPOT_DEP_JARS) + $(eval TMP := $(shell mktemp -d)) + $(JAVAC) -d $(TMP) -processorpath $(COM_ORACLE_JVMCI_HOTSPOTVMCONFIG_PROCESSOR_JAR):$(COM_ORACLE_JVMCI_SERVICE_PROCESSOR_JAR):$(COM_ORACLE_JVMCI_OPTIONS_PROCESSOR_JAR) -bootclasspath $(JDK_BOOTCLASSPATH) -cp $(TARGET)/build/jvmci-util.jar:$(TARGET)/build/jvmci-service.jar:$(TARGET)/build/jvmci-api.jar:graal/findbugs-SuppressFBWarnings.jar $(JVMCI_HOTSPOT_SRC) + + $(call process_options,$(TMP),True) + mkdir -p $$(dirname $(JVMCI_HOTSPOT_JAR)) + $(JAR) cf $(JVMCI_HOTSPOT_JAR) -C $(TMP) . + rm -r $(TMP) + +$(JVMCI_API_JAR): $(JVMCI_API_SRC) $(JVMCI_API_DEP_JARS) + $(eval TMP := $(shell mktemp -d)) + $(JAVAC) -d $(TMP) -bootclasspath $(JDK_BOOTCLASSPATH) -cp $(TARGET)/build/jvmci-service.jar:graal/findbugs-SuppressFBWarnings.jar $(JVMCI_API_SRC) + + $(call process_options,$(TMP),True) + mkdir -p $$(dirname $(JVMCI_API_JAR)) + $(JAR) cf $(JVMCI_API_JAR) -C $(TMP) . + rm -r $(TMP) + +default: $(JVMCI_UTIL_JAR) $(JVMCI_SERVICE_JAR) $(JVMCI_HOTSPOT_JAR) $(JVMCI_API_JAR) +.PHONY: default diff -r bc2ec35a7189 -r 27943aac2e3c make/solaris/makefiles/defs.make --- a/make/solaris/makefiles/defs.make Thu Jun 04 10:46:23 2015 -0700 +++ b/make/solaris/makefiles/defs.make Thu Jun 04 11:08:12 2015 -0700 @@ -304,3 +304,4 @@ endif endif EXPORT_LIST += $(EXPORT_LIB_DIR)/sa-jdi.jar +EXPORT_LIST += $(EXPORT_JRE_LIB_JVMCI_SERVICES_DIR)/com.oracle.jvmci.debug.DebugInitializationPropertyProvider diff -r bc2ec35a7189 -r 27943aac2e3c mx/mx_graal.py --- a/mx/mx_graal.py Thu Jun 04 10:46:23 2015 -0700 +++ b/mx/mx_graal.py Thu Jun 04 11:08:12 2015 -0700 @@ -578,8 +578,10 @@ if os.path.isfile(jar): with zipfile.ZipFile(jar) as zf: for member in zf.namelist(): - if member.startswith('META-INF/services'): + if member.startswith('META-INF/services') and member: serviceName = basename(member) + if serviceName == "": + continue # Zip files may contain empty entries for directories (jar -cf ... creates such) # we don't handle directories assert serviceName and member == 'META-INF/services/' + serviceName with zf.open(member) as serviceFile: @@ -590,6 +592,8 @@ serviceImpls.append(line) elif member.startswith('META-INF/options'): filename = basename(member) + if filename == "": + continue # Zip files may contain empty entries for directories (jar -cf ... creates such) # we don't handle directories assert filename and member == 'META-INF/options/' + filename targetpath = join(optionsDir, filename) @@ -614,22 +618,33 @@ def _updateJVMCIFiles(jdkDir): jreJVMCIDir = join(jdkDir, 'jre', 'lib', 'jvmci') jvmciJars = [join(jreJVMCIDir, e) for e in os.listdir(jreJVMCIDir) if e.endswith('.jar')] - jreGraalServicesDir = join(jreJVMCIDir, 'services') - jreGraalOptionsDir = join(jreJVMCIDir, 'options') - _extractJVMCIFiles(_getJdkDeployedJars(jdkDir), jvmciJars, jreGraalServicesDir, jreGraalOptionsDir) + jreJVMCIServicesDir = join(jreJVMCIDir, 'services') + jreJVMCIOptionsDir = join(jreJVMCIDir, 'options') + _extractJVMCIFiles(_getJdkDeployedJars(jdkDir), jvmciJars, jreJVMCIServicesDir, jreJVMCIOptionsDir) def _patchGraalVersionConstant(dist): """ - Patches the constant "@@graal.version@@" in the constant pool of Graal.class + Patches the constant "@@@@@@@@@@@@@@@@graal.version@@@@@@@@@@@@@@@@" in the constant pool of Graal.class with the computed Graal version string. """ zf = zipfile.ZipFile(dist.path, 'r') graalClassfilePath = 'com/oracle/graal/api/runtime/Graal.class' - graalClassfile = zf.read(graalClassfilePath) - versionSpec = '{:' + str(len('@@graal.version@@')) + '}' + try: + graalClassfile = zf.read(graalClassfilePath) + except KeyError: + mx.log(graalClassfilePath + ' is not present in ' + dist.path) + return + placeholder = '@@@@@@@@@@@@@@@@graal.version@@@@@@@@@@@@@@@@' + placeholderLen = len(placeholder) + versionSpec = '{:' + str(placeholderLen) + '}' versionStr = versionSpec.format(graal_version()) - if '@@graal.version@@' not in graalClassfile: - assert versionStr in graalClassfile, 'could not find "@@graal.version@@" or "' + versionStr + '" constant in ' + dist.path + '!' + graalClassfilePath + + if len(versionStr) > placeholderLen: + # Truncate the version string if necessary + assert versionStr.startswith('unknown'), versionStr + versionStr = versionStr[:placeholderLen] + if placeholder not in graalClassfile: + assert versionStr in graalClassfile, 'could not find "' + placeholder + '" or "' + versionStr + '" constant in ' + dist.path + '!' + graalClassfilePath zf.close() return False @@ -637,7 +652,7 @@ zfOut = zipfile.ZipFile(zfOutPath, 'w') for zi in zf.infolist(): if zi.filename == graalClassfilePath: - data = graalClassfile.replace('@@graal.version@@', versionStr) + data = graalClassfile.replace(placeholder, versionStr) else: data = zf.read(zi) zfOut.writestr(zi, data) diff -r bc2ec35a7189 -r 27943aac2e3c mx/mx_graal_makefile.py --- a/mx/mx_graal_makefile.py Thu Jun 04 10:46:23 2015 -0700 +++ b/mx/mx_graal_makefile.py Thu Jun 04 11:08:12 2015 -0700 @@ -1,4 +1,3 @@ -import mx, os, sys # # ---------------------------------------------------------------------------------------------------- # @@ -25,160 +24,226 @@ # # ---------------------------------------------------------------------------------------------------- # +import mx, mx_graal, os +from argparse import ArgumentParser, REMAINDER + + +class Makefile: + def __init__(self): + self.rules = [] + self.definitions = [] + + def add_rule(self, s): + self.rules.append(s) + + def add_definition(self, s): + self.definitions.append(s) + + def generate(self): + return "\n\n".join(self.definitions + self.rules) def build_makefile(args): - """Build a Makefile from the suitte.py to build graa.jar without python""" - if len(args) == 0 or args[0] == "-": - do_build_makefile(lambda l: sys.stdout.write(l + os.linesep)) - elif args[0] == "-o": - with open(args[1], "w") as f: - do_build_makefile(lambda l: f.write(l + os.linesep)) + """Creates a Makefile which is able to build distributions without mx""" + parser = ArgumentParser(prog='mx makefile') + parser.add_argument('-o', action='store', dest='output', help='Write contents to this file.') + parser.add_argument('selectedDists', help="Selected distribution names which are going to be built with make.", nargs=REMAINDER) + args = parser.parse_args(args) -def relative_dep_path(d): - if isinstance(d, str): d = mx.dependency(d) - return os.path.basename(d.get_path(False)) - -def createMakeRule(p, bootClasspath): - def filterDeps(deps, t): - def typeFilter(project): # filters - if isinstance(project, str): - project = mx.dependency(project, True) - return isinstance(project, t) - return [d for d in deps if typeFilter(d)] + if args.selectedDists == None or len(args.selectedDists) == 0: + parser.print_help() + return + mf = Makefile() + if do_build_makefile(mf, args.selectedDists): + contents = mf.generate() + if args.output == None: + print contents + else: + with open(args.output, "w") as f: + f.write(contents) - canonicalDeps = p.canonical_deps() - canonicalProjectDep = filterDeps(canonicalDeps, mx.Project) - canonicalProjectDepDirs = ['$(TARGET)/' +i for i in canonicalProjectDep] - canonicalLibDep = filterDeps(canonicalDeps, mx.Library) - canonicalLibDepJars = ["$(LIB)/" + relative_dep_path(d) for d in canonicalLibDep] - - allDep = p.all_deps([], True, False, includeAnnotationProcessors=True) - allProcessorDistNames = [x.definedAnnotationProcessorsDist.name for x in filterDeps(allDep, mx.Project) if x.definedAnnotationProcessors != None] - allProjectDep = filterDeps(allDep, mx.Project) - allProjectDepDir = ['$(TARGET)/' +i.name for i in allProjectDep] - allLibDep = filterDeps(allDep, mx.Library) - allLibDepJar = ["$(LIB)/" + relative_dep_path(d) for d in allLibDep] - - processor = p.annotation_processors_path() - if processor != None: processor = processor.replace(p.suite.dir, "$(TARGET)") +def filter_projects(deps, t): + def typeFilter(project): # filters + if isinstance(project, str): + project = mx.dependency(project, True) + return isinstance(project, t) + return [d for d in deps if typeFilter(d)] - cp = allLibDepJar +allProjectDepDir - props = { - 'name': p.name, - 'project_deps': ' '.join(canonicalProjectDepDirs + canonicalLibDepJars + allProcessorDistNames), - 'cp_deps': ('-cp ' + ':'.join(cp)) if len(cp) > 0 else '', - 'cp_boot': ('-bootclasspath ' + bootClasspath) if len(bootClasspath) > 0 else '', - 'processor': ('-processorpath ' + processor) if processor != None else '' - } - return """$(TARGET)/{name}: $(shell find graal/{name}/src/ -type f -name *.java) {project_deps} -\t$(eval TMP := $(shell mktemp -d)) -\ttest ! -d $(TARGET)/{name} || cp -Rp $(TARGET)/{name} $(TMP) -\t$(JAVAC) -d $(TMP) {cp_boot} {processor} {cp_deps} $(shell find graal/{name}/src/ -type f -name *.java) -\ttest ! -d graal/{name}/src/META-INF || (mkdir -p $(TARGET)/{name}/META-INF/ && cp -r graal/{name}/src/META-INF/ $(TARGET)/{name}/) -\tmkdir -p $(TARGET)/{name} -\tcp -r $(TMP)/* $(TARGET)/{name} -\ttouch $(TARGET)/{name} -\trm -r $(TMP) -""".format(**props) +def get_jdk_deployed_dists(): + return [d.name for d in mx_graal._jdkDeployedDists] -def createDistributionRule(dist): - sorted_deps = set(dist.sorted_deps(False, True)) - depDirs = ' '.join(['$(TARGET)/' + i.name for i in sorted_deps]) - depDirsStar = ' '.join(['$(TARGET)/' + i.name + '/*' for i in sorted_deps]) - jarPath = os.path.relpath(dist.path, dist.suite.dir) - jarDir = os.path.dirname(jarPath) - props = { - 'dist_name': dist.name, - 'depDirs': depDirs, - 'depDirsStar': depDirsStar, - 'jar_path': jarPath, - 'jar_dir': jarDir, - 'providers_dir': '$(TMP)/META-INF/providers/ ', - 'services_dir': '$(TMP)/META-INF/services/' - } - return """{dist_name}: {depDirs} -\t$(eval TMP := $(shell mktemp -d)) -\tmkdir -p $(TARGET){jar_dir} -\ttouch $(TARGET)/{jar_path} -\tcp -r {depDirsStar} $(TMP) -\ttest -d {services_dir} || mkdir -p {services_dir} -\ttest ! -d {providers_dir} || (cd {providers_dir} && for i in $$(ls); do c=$$(cat $$i); echo $$i >> {services_dir}$$c; done) -\ttest ! -d {providers_dir} || rm -r {providers_dir} -\t$(JAR) cvf $(TARGET){jar_path} -C $(TMP) . -\trm -r $(TMP) -""".format(**props) +def make_dist_rule(dist, mf, bootClassPath=None): + def path_dist_relative(p): + return os.path.relpath(p, dist.suite.dir) + jdkDeployedDists = get_jdk_deployed_dists() + jarPath = path_dist_relative(dist.path) + sourcesVariableName = dist.name + "_SRC" + depJarVariableName = dist.name + "_DEP_JARS" + sources = [] + resources = [] + sortedDeps = dist.sorted_deps(True, transitive=False, includeAnnotationProcessors=True) + projects = filter_projects(sortedDeps, mx.Project) + targetPathPrefix = "$(TARGET)" + os.path.sep + libraryDeps = [path_dist_relative(l.get_path(False)) for l in filter_projects(sortedDeps, mx.Library)] -def createDownloadRule(lib): - http_urls = [u for u in lib.urls if u.startswith("http")] - if len(http_urls) == 0: http_urls = [u for u in lib.urls if u.startswith("jar")] - if len(http_urls) == 0: raise BaseException("No http url specified for downloading library %s: available urls: %s" % (lib.name, lib.urls)) - url = http_urls[0] - tofile = '$(LIB)/' + relative_dep_path(lib) - if url.startswith("jar"): - props = { - 'url': url[url.find(":")+1:url.rfind("!")], - 'archive_file': url[url.rfind("!")+1:], - 'dest': tofile - } - dl = """\t$(eval TMP := $(shell mktemp -d)) -\tcd $(TMP) && $(WGET) -O dl.zip {url} && $(JAR) xf dl.zip -\tmv $(TMP)/{archive_file} {dest} -\trm -rf $(TMP)""".format(**props) - else: - dl = "\t$(WGET) -O {} {}".format(tofile, url) - return """{}:\n{}""".format(tofile, dl) + annotationProcessorDeps = set() + distDeps = dist.get_dist_deps(includeSelf=False, transitive=True) + distDepProjects = set() + for d in distDeps: + distDepProjects.update(d.sorted_deps(includeLibs=False, transitive=True)) + + classPath = [targetPathPrefix + path_dist_relative(d.path) for d in distDeps] + libraryDeps \ + + [path_dist_relative(mx.dependency(name).path) for name in dist.excludedDependencies] + for p in projects: + if p.definedAnnotationProcessors != None and p.definedAnnotationProcessorsDist != dist: + annotationProcessorDeps.add(p) + for p in projects: + projectDir = path_dist_relative(p.dir) + if p not in distDepProjects and p not in annotationProcessorDeps: + generatedSource = [path_dist_relative(p.source_gen_dir())] if len(annotationProcessorDeps) > 0 else [] + + for d in p.srcDirs + generatedSource: + src = projectDir + os.path.sep + d + sources.append("$(shell find {} -type f -name *.java 2> /dev/null)".format(src)) + metaInf = src + os.path.sep + "META-INF" + if os.path.exists(metaInf): + resources.append(metaInf) -def create_suite_build(suite, out): - for p in suite.projects: - java = mx.java(p.javaCompliance) - bootClassPath = java.bootclasspath() - bootClassPath = bootClassPath.replace(java.jdk, "$(JDK)") - out(createMakeRule(p, bootClassPath)) - for l in suite.libs: - out(createDownloadRule(l)) + sourceLines = sourcesVariableName + " = " + ("\n" + sourcesVariableName + " += ").join(sources) + apPaths = [] + apDistNames = [] + apDistVariableNames = [] + for p in annotationProcessorDeps: + apPaths.append(path_dist_relative(p.definedAnnotationProcessorsDist.path)) + name = p.definedAnnotationProcessorsDist.name + apDistNames.append(name) + apDistVariableNames.append("$(" + name + "_JAR)") + shouldExport = dist.name in jdkDeployedDists + props = { + "name": dist.name, + "jarPath": targetPathPrefix + jarPath, + "depends": "", + "depJarsVariableAccess": "$(" + depJarVariableName + ")" if len(classPath) > 0 else "", + "depJarsVariable": depJarVariableName, + "sourceLines": sourceLines, + "sourcesVariableName": sourcesVariableName, + "annotationProcessors": " ".join(apDistVariableNames), + "cpAnnotationProcessors": "-processorpath " + ":".join(apDistVariableNames) if len(apDistVariableNames) > 0 else "", + "bootCp": ("-bootclasspath " + bootClassPath) if bootClassPath != None else "", + "cpDeps": ("-cp " + ":".join(classPath)) if len(classPath) > 0 else "", + "jarDeps": " ".join(classPath), + "copyResources": "cp -r {} $(TMP)".format(" ".join(resources)) if len(resources) > 0 else "", + "targetPathPrefix": targetPathPrefix, + "shouldExport": shouldExport, + } - distributionNames = [] - for d in suite.dists: - distributionNames.append(d.name) - out(createDistributionRule(d)) - out("{0}: {1}\n.PHONY: {1}".format(suite.name, " ".join(distributionNames))) + mf.add_definition(sourceLines) + mf.add_definition("{name}_JAR = {jarPath}".format(**props)) + if len(classPath) > 0: mf.add_definition("{depJarsVariable} = {jarDeps}".format(**props)) + if shouldExport: mf.add_definition("EXPORTED_FILES += $({name}_JAR)".format(**props)) + mf.add_rule("""$({name}_JAR): $({sourcesVariableName}) {annotationProcessors} {depJarsVariableAccess} +\t$(eval TMP := $(shell mktemp -d)) +\t$(JAVAC) -d $(TMP) {cpAnnotationProcessors} {bootCp} {cpDeps} $({sourcesVariableName}) +\t{copyResources} +\t$(call process_options,$(TMP),{shouldExport}) +\tmkdir -p $$(dirname $({name}_JAR)) +\t$(JAR) cf $({name}_JAR) -C $(TMP) . +\trm -r $(TMP)""".format(**props)) + return -def do_build_makefile(out): - out("""VERBOSE= -TARGET=build/ -LIB=$(TARGET)/lib + +def do_build_makefile(mf, selectedDists): + java = mx.java() + bootClassPath = java.bootclasspath() + bootClassPath = bootClassPath.replace(java.jdk, "$(JDK)") + jdkBootClassPathVariableName = "JDK_BOOTCLASSPATH" + + mf.add_definition("""VERBOSE= +TARGET=. JDK= WGET=wget -JAVAC=$(JDK)/bin/javac +JAVAC=$(JDK)/bin/javac -g -target """ + str(java.javaCompliance) + """ JAR=$(JDK)/bin/jar +EXPORT_DIR=export +EXPORTED_FILES_ADDITIONAL=$(TARGET)/options $(TARGET)/services +HS_COMMON_SRC=. +# where all other stuff built by mx (graal.jar) resides +MX_TARGET=. +PROVIDERS_INF=/META-INF/providers/ +SERVICES_INF=/META-INF/services/ +OPTIONS_INF=/META-INF/options/ ifeq ($(JDK),) -$(error Variable JDK must be set to a JDK installation.) + $(error Variable JDK must be set to a JDK installation.) + endif + ifneq ($(VERBOSE),) + SHELL=sh -x endif -ifneq ($(VERBOSE),) -SHELL=sh -x -endif + +define process_options = + $(eval providers=$(1)/$(PROVIDERS_INF)) + $(eval services=$(1)/$(SERVICES_INF)) + $(eval options=$(1)/$(OPTIONS_INF)) + test -d $(services) || mkdir -p $(services) + test ! -d $(providers) || (cd $(providers) && for i in $$(ls $(providers)); do c=$$(cat $$i); echo $$i >> $(services)$$c; rm $$i; done) + + # We're building all projects together with one javac call; thus we cannot determine, from which project the generated file is thus we hardcode it for now + $(eval vmconfig=$(1)/hotspot/HotSpotVMConfig.inline.hpp) + $(eval vmconfigDest=$(HS_COMMON_SRC)/../graal/com.oracle.jvmci.hotspot/src_gen/hotspot) + test ! -f $(vmconfig) || (mkdir -p $(vmconfigDest) && cp $(vmconfig) $(vmconfigDest)) +endef + +define extract = + $(eval TMP := $(shell mktemp -d)) + mkdir -p $(2); + cd $(TMP) && $(JAR) xf $(abspath $(1)) && \ + ((test ! -d .$(SERVICES_INF) || cp -r .$(SERVICES_INF) $(abspath $(2))) && (test ! -d .$(OPTIONS_INF) || cp -r .$(OPTIONS_INF) $(abspath $(2)))) + rm -r $(TMP) + cp $(1) $(2) +endef + all: default -$(TARGET): -\tmkdir -p $(TARGET) +export: all +\tmkdir -p $(EXPORT_DIR) +\t$(foreach export,$(EXPORTED_FILES),$(call extract,$(export),$(EXPORT_DIR))) +.PHONY: export -$(LIB): -\tmkdir -p $(LIB) """) - suiteNames = [] - for s in mx.suites(): - suiteNames.append(s.name) - create_suite_build(s, out) + s = mx.suite("graal") + dists = set() + ap = set() + projects = set() + for d in s.dists: + if d.name in selectedDists: + dists.update(d.get_dist_deps(True, True)) + projects.update(d.sorted_deps(includeLibs=False, transitive=True)) + for p in projects: + deps = p.all_deps([], False, includeSelf=True, includeJreLibs=False, includeAnnotationProcessors=True) + for d in deps: + if d.definedAnnotationProcessorsDist != None: + apd = d.definedAnnotationProcessorsDist + ap.add(apd) - out("""default: $(TARGET) $(LIB) {0} -.PHONY: {0} - """.format(" ".join(suiteNames))) + for d in mx_graal._jdkDeployedDists: + dist = mx.distribution(d.name) + if dist not in dists: # this sould go away + mf.add_definition("EXPORTED_FILES += $(MX_TARGET)/{}".format(os.path.relpath(dist.path, dist.suite.dir))) + if len(dists) > 0: + mf.add_definition(jdkBootClassPathVariableName + " = " + bootClassPath) + bootClassPathVarAccess = "$(" + jdkBootClassPathVariableName + ")" + for d in ap: make_dist_rule(d, mf, bootClassPathVarAccess) + for d in dists: make_dist_rule(d, mf, bootClassPathVarAccess) + mf.add_rule("default: $({}_JAR)\n.PHONY: default".format("_JAR) $(".join([d.name for d in dists]))) + return True + else: + for d in dists: + selectedDists.remove(d.name) + print "Distribution(s) '" + "', '".join(selectedDists) + "' does not exist." diff -r bc2ec35a7189 -r 27943aac2e3c mx/suite.py --- a/mx/suite.py Thu Jun 04 10:46:23 2015 -0700 +++ b/mx/suite.py Thu Jun 04 11:08:12 2015 -0700 @@ -3,6 +3,8 @@ "name" : "graal", "libraries" : { + # ------------- Libraries ------------- + "JLINE" : { "path" : "lib/jline-2.11.jar", "urls" : [ @@ -153,14 +155,28 @@ }, "projects" : { + + # ------------- JVMCI:Service ------------- + "com.oracle.jvmci.service" : { "subDir" : "graal", "sourceDirs" : ["src"], "checkstyle" : "com.oracle.graal.graph", "javaCompliance" : "1.8", - "workingSets" : "API,Graal", + "workingSets" : "API,JVMCI", }, + "com.oracle.jvmci.service.processor" : { + "subDir" : "graal", + "sourceDirs" : ["src"], + "dependencies" : ["com.oracle.jvmci.service"], + "checkstyle" : "com.oracle.graal.graph", + "javaCompliance" : "1.8", + "workingSets" : "JVMCI,Codegen,HotSpot", + }, + + # ------------- JVMCI:API ------------- + "com.oracle.jvmci.common" : { "subDir" : "graal", "sourceDirs" : ["src"], @@ -169,6 +185,23 @@ "workingSets" : "API,JVMCI", }, + "com.oracle.jvmci.meta" : { + "subDir" : "graal", + "sourceDirs" : ["src"], + "checkstyle" : "com.oracle.graal.graph", + "javaCompliance" : "1.8", + "workingSets" : "API,JVMCI", + }, + + "com.oracle.jvmci.code" : { + "subDir" : "graal", + "sourceDirs" : ["src"], + "dependencies" : ["com.oracle.jvmci.meta"], + "checkstyle" : "com.oracle.graal.graph", + "javaCompliance" : "1.8", + "workingSets" : "API,JVMCI", + }, + "com.oracle.jvmci.runtime" : { "subDir" : "graal", "sourceDirs" : ["src"], @@ -180,6 +213,97 @@ "workingSets" : "API,JVMCI", }, + "com.oracle.jvmci.runtime.test" : { + "subDir" : "graal", + "sourceDirs" : ["src"], + "dependencies" : [ + "JUNIT", + "com.oracle.jvmci.common", + "com.oracle.jvmci.runtime", + ], + "checkstyle" : "com.oracle.graal.graph", + "javaCompliance" : "1.8", + "workingSets" : "API,JVMCI", + }, + + "com.oracle.jvmci.debug" : { + "subDir" : "graal", + "sourceDirs" : ["src"], + "checkstyle" : "com.oracle.graal.graph", + "dependencies" : [ + "com.oracle.jvmci.service", + ], + "javaCompliance" : "1.8", + "workingSets" : "JVMCI,Debug", + }, + + "com.oracle.jvmci.debug.test" : { + "subDir" : "graal", + "sourceDirs" : ["src"], + "dependencies" : [ + "JUNIT", + "com.oracle.jvmci.debug", + ], + "checkstyle" : "com.oracle.graal.graph", + "javaCompliance" : "1.8", + "workingSets" : "JVMCI,Debug,Test", + }, + + "com.oracle.jvmci.options" : { + "subDir" : "graal", + "sourceDirs" : ["src"], + "dependencies" : [ + "com.oracle.jvmci.service", + ], + "checkstyle" : "com.oracle.graal.graph", + "javaCompliance" : "1.8", + "workingSets" : "JVMCI", + }, + + "com.oracle.jvmci.options.processor" : { + "subDir" : "graal", + "sourceDirs" : ["src"], + "dependencies" : [ + "com.oracle.jvmci.options", + ], + "checkstyle" : "com.oracle.graal.graph", + "javaCompliance" : "1.8", + "workingSets" : "JVMCI,Codegen", + }, + + "com.oracle.jvmci.options.test" : { + "subDir" : "graal", + "sourceDirs" : ["src"], + "dependencies" : [ + "com.oracle.jvmci.options", + "JUNIT", + ], + "checkstyle" : "com.oracle.graal.graph", + "annotationProcessors" : ["com.oracle.jvmci.options.processor"], + "javaCompliance" : "1.8", + "workingSets" : "JVMCI", + }, + + # ------------- JVMCI:HotSpot ------------- + + "com.oracle.jvmci.amd64" : { + "subDir" : "graal", + "sourceDirs" : ["src"], + "dependencies" : ["com.oracle.jvmci.code"], + "checkstyle" : "com.oracle.graal.graph", + "javaCompliance" : "1.8", + "workingSets" : "JVMCI,AMD64", + }, + + "com.oracle.jvmci.sparc" : { + "subDir" : "graal", + "sourceDirs" : ["src"], + "dependencies" : ["com.oracle.jvmci.code"], + "checkstyle" : "com.oracle.graal.graph", + "javaCompliance" : "1.8", + "workingSets" : "JVMCI,SPARC", + }, + "com.oracle.jvmci.hotspot" : { "subDir" : "graal", "sourceDirs" : ["src"], @@ -200,6 +324,65 @@ "workingSets" : "JVMCI", }, + "com.oracle.jvmci.hotspotvmconfig" : { + "subDir" : "graal", + "sourceDirs" : ["src"], + "checkstyle" : "com.oracle.graal.graph", + "javaCompliance" : "1.8", + "workingSets" : "JVMCI,HotSpot", + }, + + "com.oracle.jvmci.hotspotvmconfig.processor" : { + "subDir" : "graal", + "sourceDirs" : ["src"], + "dependencies" : ["com.oracle.jvmci.hotspotvmconfig", "com.oracle.jvmci.common"], + "checkstyle" : "com.oracle.graal.graph", + "javaCompliance" : "1.8", + "workingSets" : "JVMCI,HotSpot,Codegen", + }, + + "com.oracle.jvmci.hotspot.amd64" : { + "subDir" : "graal", + "sourceDirs" : ["src"], + "dependencies" : [ + "com.oracle.jvmci.amd64", + "com.oracle.jvmci.hotspot", + ], + "checkstyle" : "com.oracle.graal.graph", + "annotationProcessors" : ["com.oracle.jvmci.service.processor"], + "javaCompliance" : "1.8", + "workingSets" : "JVMCI,HotSpot,AMD64", + }, + + "com.oracle.jvmci.hotspot.sparc" : { + "subDir" : "graal", + "sourceDirs" : ["src"], + "dependencies" : [ + "com.oracle.jvmci.sparc", + "com.oracle.jvmci.hotspot", + ], + "checkstyle" : "com.oracle.graal.graph", + "annotationProcessors" : ["com.oracle.jvmci.service.processor"], + "javaCompliance" : "1.8", + "workingSets" : "JVMCI,HotSpot,SPARC", + }, + + "com.oracle.jvmci.hotspot.jfr" : { + "subDir" : "graal", + "sourceDirs" : ["src"], + "dependencies" : [ + "com.oracle.jvmci.hotspot", + "JFR", + ], + "checkstyle" : "com.oracle.graal.graph", + "annotationProcessors" : ["com.oracle.jvmci.service.processor"], + "javaCompliance" : "1.8", + "profile" : "", + "workingSets" : "JVMCI,HotSpot", + }, + + # ------------- NFI ------------- + "com.oracle.nfi" : { "subDir" : "graal", "sourceDirs" : ["src"], @@ -220,6 +403,21 @@ "javaCompliance" : "1.7", }, + # ------------- Graal ------------- + + "com.oracle.graal.code" : { + "subDir" : "graal", + "sourceDirs" : ["src"], + "dependencies" : [ + "com.oracle.jvmci.service", + "com.oracle.jvmci.code", + ], + "annotationProcessors" : ["com.oracle.jvmci.service.processor"], + "checkstyle" : "com.oracle.graal.graph", + "javaCompliance" : "1.8", + "workingSets" : "Graal", + }, + "com.oracle.graal.api.collections" : { "subDir" : "graal", "sourceDirs" : ["src"], @@ -270,23 +468,6 @@ "workingSets" : "API,Graal,Test", }, - "com.oracle.jvmci.meta" : { - "subDir" : "graal", - "sourceDirs" : ["src"], - "checkstyle" : "com.oracle.graal.graph", - "javaCompliance" : "1.8", - "workingSets" : "API,JVMCI", - }, - - "com.oracle.jvmci.code" : { - "subDir" : "graal", - "sourceDirs" : ["src"], - "dependencies" : ["com.oracle.jvmci.meta"], - "checkstyle" : "com.oracle.graal.graph", - "javaCompliance" : "1.8", - "workingSets" : "API,JVMCI", - }, - "com.oracle.graal.api.replacements" : { "subDir" : "graal", "sourceDirs" : ["src"], @@ -296,50 +477,6 @@ "workingSets" : "API,Graal,Replacements", }, - "com.oracle.jvmci.service.processor" : { - "subDir" : "graal", - "sourceDirs" : ["src"], - "dependencies" : ["com.oracle.jvmci.service"], - "checkstyle" : "com.oracle.graal.graph", - "javaCompliance" : "1.8", - "workingSets" : "Codegen,HotSpot", - }, - - "com.oracle.graal.amd64" : { - "subDir" : "graal", - "sourceDirs" : ["src"], - "dependencies" : ["com.oracle.jvmci.code"], - "checkstyle" : "com.oracle.graal.graph", - "javaCompliance" : "1.8", - "workingSets" : "Graal,AMD64", - }, - - "com.oracle.graal.sparc" : { - "subDir" : "graal", - "sourceDirs" : ["src"], - "dependencies" : ["com.oracle.jvmci.code"], - "checkstyle" : "com.oracle.graal.graph", - "javaCompliance" : "1.8", - "workingSets" : "Graal,SPARC", - }, - - "com.oracle.jvmci.hotspotvmconfig" : { - "subDir" : "graal", - "sourceDirs" : ["src"], - "checkstyle" : "com.oracle.graal.graph", - "javaCompliance" : "1.8", - "workingSets" : "JVMCI,HotSpot", - }, - - "com.oracle.jvmci.hotspotvmconfig.processor" : { - "subDir" : "graal", - "sourceDirs" : ["src"], - "dependencies" : ["com.oracle.jvmci.hotspotvmconfig", "com.oracle.jvmci.common"], - "checkstyle" : "com.oracle.graal.graph", - "javaCompliance" : "1.8", - "workingSets" : "Graal,HotSpot,Codegen", - }, - "com.oracle.graal.hotspot" : { "subDir" : "graal", "sourceDirs" : ["src"], @@ -358,24 +495,11 @@ "workingSets" : "Graal,HotSpot", }, - "com.oracle.jvmci.hotspot.jfr" : { - "subDir" : "graal", - "sourceDirs" : ["src"], - "dependencies" : [ - "com.oracle.jvmci.hotspot", - "JFR", - ], - "checkstyle" : "com.oracle.graal.graph", - "annotationProcessors" : ["com.oracle.jvmci.service.processor"], - "javaCompliance" : "1.8", - "profile" : "", - "workingSets" : "JVMCI,HotSpot", - }, - "com.oracle.graal.hotspot.amd64" : { "subDir" : "graal", "sourceDirs" : ["src"], "dependencies" : [ + "com.oracle.jvmci.hotspot.amd64", "com.oracle.graal.compiler.amd64", "com.oracle.graal.hotspot", "com.oracle.graal.replacements.amd64", @@ -390,6 +514,8 @@ "subDir" : "graal", "sourceDirs" : ["src"], "dependencies" : [ + "com.oracle.graal.hotspot", + "com.oracle.jvmci.hotspot.sparc", "com.oracle.graal.compiler.sparc", "com.oracle.graal.replacements.sparc", ], @@ -423,41 +549,6 @@ "workingSets" : "Graal,HotSpot,AMD64,Test", }, - "com.oracle.jvmci.options" : { - "subDir" : "graal", - "sourceDirs" : ["src"], - "dependencies" : [ - "com.oracle.jvmci.service", - ], - "checkstyle" : "com.oracle.graal.graph", - "javaCompliance" : "1.8", - "workingSets" : "JVMCI", - }, - - "com.oracle.jvmci.options.processor" : { - "subDir" : "graal", - "sourceDirs" : ["src"], - "dependencies" : [ - "com.oracle.jvmci.options", - ], - "checkstyle" : "com.oracle.graal.graph", - "javaCompliance" : "1.8", - "workingSets" : "JVMCI,Codegen", - }, - - "com.oracle.jvmci.options.test" : { - "subDir" : "graal", - "sourceDirs" : ["src"], - "dependencies" : [ - "com.oracle.jvmci.options", - "JUNIT", - ], - "checkstyle" : "com.oracle.graal.graph", - "annotationProcessors" : ["com.oracle.jvmci.options.processor"], - "javaCompliance" : "1.8", - "workingSets" : "JVMCI", - }, - "com.oracle.graal.nodeinfo" : { "subDir" : "graal", "sourceDirs" : ["src"], @@ -504,27 +595,71 @@ "workingSets" : "Graal,Graph,Test", }, - "com.oracle.jvmci.debug" : { + "com.oracle.graal.asm" : { + "subDir" : "graal", + "sourceDirs" : ["src"], + "dependencies" : ["com.oracle.jvmci.code"], + "checkstyle" : "com.oracle.graal.graph", + "javaCompliance" : "1.8", + "workingSets" : "Graal,Assembler", + }, + + "com.oracle.graal.asm.amd64" : { + "subDir" : "graal", + "sourceDirs" : ["src"], + "dependencies" : [ + "com.oracle.graal.asm", + "com.oracle.jvmci.amd64", + ], + "checkstyle" : "com.oracle.graal.graph", + "javaCompliance" : "1.8", + "workingSets" : "Graal,Assembler,AMD64", + }, + + "com.oracle.graal.asm.sparc" : { + "subDir" : "graal", + "sourceDirs" : ["src"], + "dependencies" : [ + "com.oracle.graal.asm", + "com.oracle.jvmci.sparc", + ], + "checkstyle" : "com.oracle.graal.graph", + "javaCompliance" : "1.8", + "workingSets" : "Graal,Assembler,SPARC", + }, + + "com.oracle.graal.bytecode" : { "subDir" : "graal", "sourceDirs" : ["src"], "checkstyle" : "com.oracle.graal.graph", - "dependencies" : [ - "com.oracle.jvmci.service", - ], "javaCompliance" : "1.8", - "workingSets" : "JVMCI,Debug", + "workingSets" : "Graal,Java", }, - "com.oracle.jvmci.debug.test" : { + "com.oracle.graal.asm.test" : { "subDir" : "graal", "sourceDirs" : ["src"], "dependencies" : [ - "JUNIT", - "com.oracle.jvmci.debug", + "com.oracle.graal.code", + "com.oracle.graal.test", + "com.oracle.jvmci.runtime", ], "checkstyle" : "com.oracle.graal.graph", "javaCompliance" : "1.8", - "workingSets" : "JVMCI,Debug,Test", + "workingSets" : "Graal,Assembler,Test", + }, + + "com.oracle.graal.asm.amd64.test" : { + "subDir" : "graal", + "sourceDirs" : ["src"], + "dependencies" : [ + "com.oracle.graal.asm.test", + "com.oracle.jvmci.common", + "com.oracle.graal.asm.amd64", + ], + "checkstyle" : "com.oracle.graal.graph", + "javaCompliance" : "1.8", + "workingSets" : "Graal,Assembler,AMD64,Test", }, "com.oracle.graal.lir" : { @@ -577,7 +712,10 @@ "com.oracle.graal.lir.sparc" : { "subDir" : "graal", "sourceDirs" : ["src"], - "dependencies" : ["com.oracle.graal.asm.sparc"], + "dependencies" : [ + "com.oracle.graal.asm.sparc", + "com.oracle.graal.lir", + ], "checkstyle" : "com.oracle.graal.graph", "javaCompliance" : "1.8", "workingSets" : "Graal,LIR,SPARC", @@ -781,7 +919,7 @@ "subDir" : "graal", "sourceDirs" : ["src"], "dependencies" : [ - "com.oracle.graal.amd64", + "com.oracle.jvmci.amd64", "com.oracle.graal.lir.jtt", ], "checkstyle" : "com.oracle.graal.graph", @@ -792,7 +930,10 @@ "com.oracle.graal.compiler.sparc" : { "subDir" : "graal", "sourceDirs" : ["src"], - "dependencies" : ["com.oracle.graal.lir.sparc"], + "dependencies" : [ + "com.oracle.graal.compiler", + "com.oracle.graal.lir.sparc" + ], "checkstyle" : "com.oracle.graal.graph", "javaCompliance" : "1.8", "workingSets" : "Graal,SPARC", @@ -802,7 +943,7 @@ "subDir" : "graal", "sourceDirs" : ["src"], "dependencies" : [ - "com.oracle.graal.sparc", + "com.oracle.jvmci.sparc", "com.oracle.graal.compiler.test", ], "checkstyle" : "com.oracle.graal.graph", @@ -819,14 +960,6 @@ "workingSets" : "Graal", }, - "com.oracle.graal.bytecode" : { - "subDir" : "graal", - "sourceDirs" : ["src"], - "checkstyle" : "com.oracle.graal.graph", - "javaCompliance" : "1.8", - "workingSets" : "Graal,Java", - }, - "com.oracle.graal.java" : { "subDir" : "graal", "sourceDirs" : ["src"], @@ -844,8 +977,7 @@ "subDir" : "graal", "sourceDirs" : ["src"], "dependencies" : [ - "JUNIT", - "com.oracle.graal.runtime", + "com.oracle.jvmci.runtime.test", "com.oracle.graal.java", ], "checkstyle" : "com.oracle.graal.graph", @@ -884,6 +1016,7 @@ "subDir" : "graal", "sourceDirs" : ["src"], "dependencies" : [ + "com.oracle.graal.code", "com.oracle.graal.java", "com.oracle.graal.compiler", ], @@ -896,8 +1029,8 @@ "subDir" : "graal", "sourceDirs" : ["src"], "dependencies" : [ + "com.oracle.jvmci.debug", "JUNIT", - "com.oracle.jvmci.debug", ], "checkstyle" : "com.oracle.graal.graph", "javaCompliance" : "1.8", @@ -908,8 +1041,8 @@ "subDir" : "graal", "sourceDirs" : ["src"], "dependencies" : [ + "com.oracle.graal.test", "com.oracle.graal.api.directives", - "com.oracle.graal.test", "com.oracle.graal.printer", "com.oracle.graal.runtime", "JAVA_ALLOCATION_INSTRUMENTER", @@ -932,62 +1065,7 @@ "jacoco" : "exclude", }, - "com.oracle.graal.asm" : { - "subDir" : "graal", - "sourceDirs" : ["src"], - "dependencies" : ["com.oracle.jvmci.code"], - "checkstyle" : "com.oracle.graal.graph", - "javaCompliance" : "1.8", - "workingSets" : "Graal,Assembler", - }, - - "com.oracle.graal.asm.test" : { - "subDir" : "graal", - "sourceDirs" : ["src"], - "dependencies" : [ - "com.oracle.graal.test", - "com.oracle.graal.runtime", - ], - "checkstyle" : "com.oracle.graal.graph", - "javaCompliance" : "1.8", - "workingSets" : "Graal,Assembler,Test", - }, - - "com.oracle.graal.asm.amd64" : { - "subDir" : "graal", - "sourceDirs" : ["src"], - "dependencies" : [ - "com.oracle.graal.asm", - "com.oracle.graal.amd64", - ], - "checkstyle" : "com.oracle.graal.graph", - "javaCompliance" : "1.8", - "workingSets" : "Graal,Assembler,AMD64", - }, - - "com.oracle.graal.asm.amd64.test" : { - "subDir" : "graal", - "sourceDirs" : ["src"], - "dependencies" : [ - "com.oracle.graal.asm.test", - "com.oracle.graal.asm.amd64", - ], - "checkstyle" : "com.oracle.graal.graph", - "javaCompliance" : "1.8", - "workingSets" : "Graal,Assembler,AMD64,Test", - }, - - "com.oracle.graal.asm.sparc" : { - "subDir" : "graal", - "sourceDirs" : ["src"], - "dependencies" : [ - "com.oracle.graal.hotspot", - "com.oracle.graal.sparc", - ], - "checkstyle" : "com.oracle.graal.graph", - "javaCompliance" : "1.8", - "workingSets" : "Graal,Assembler,SPARC", - }, + # ------------- Truffle ------------- "com.oracle.truffle.api" : { "subDir" : "graal", @@ -1006,6 +1084,7 @@ ], "checkstyle" : "com.oracle.graal.graph", "javaCompliance" : "1.7", + "annotationProcessors" : ["com.oracle.truffle.dsl.processor"], "workingSets" : "API,Truffle,Test", "jacoco" : "exclude", }, @@ -1092,7 +1171,7 @@ "sourceDirs" : ["src"], "dependencies" : ["com.oracle.truffle.api"], "checkstyle" : "com.oracle.truffle.api", - "javaCompliance" : "1.8", + "javaCompliance" : "1.7", "workingSets" : "Truffle,Tools", }, @@ -1167,6 +1246,8 @@ "workingSets" : "Truffle,SimpleLanguage,Tools", }, + # ------------- GraalTruffle ------------- + "com.oracle.graal.truffle" : { "subDir" : "graal", "sourceDirs" : ["src"], @@ -1240,6 +1321,8 @@ "distributions" : { + # ------------- Distributions ------------- + "JVMCI_SERVICE" : { "path" : "build/jvmci-service.jar", "subDir" : "graal", @@ -1269,7 +1352,8 @@ "subDir" : "graal", "sourcesPath" : "build/jvmci-hotspot.src.zip", "dependencies" : [ - "com.oracle.jvmci.hotspot", + "com.oracle.jvmci.hotspot.amd64", + "com.oracle.jvmci.hotspot.sparc", "com.oracle.jvmci.hotspot.jfr", ], "distDependencies" : [ @@ -1303,6 +1387,7 @@ "com.oracle.nfi", "com.oracle.truffle.interop", "com.oracle.truffle.object.basic", + "com.oracle.truffle.tools" ], "distDependencies" : [ "JVMCI_SERVICE", diff -r bc2ec35a7189 -r 27943aac2e3c mxtool/mx.py --- a/mxtool/mx.py Thu Jun 04 10:46:23 2015 -0700 +++ b/mxtool/mx.py Thu Jun 04 11:08:12 2015 -0700 @@ -124,7 +124,7 @@ self.javaCompliance = JavaCompliance(javaCompliance) if javaCompliance else None self.isProcessorDistribution = isProcessorDistribution - def sorted_deps(self, includeLibs=False, transitive=False): + def sorted_deps(self, includeLibs=False, transitive=False, includeAnnotationProcessors=False): deps = [] if transitive: for depDist in [distribution(name) for name in self.distDependencies]: @@ -135,7 +135,7 @@ excl = [dependency(d) for d in self.excludedDependencies] except SystemExit as e: abort('invalid excluded dependency for {0} distribution: {1}'.format(self.name, e)) - return deps + [d for d in sorted_deps(self.deps, includeLibs=includeLibs) if d not in excl] + return deps + [d for d in sorted_deps(self.deps, includeLibs=includeLibs, includeAnnotationProcessors=includeAnnotationProcessors) if d not in excl] def __str__(self): return self.name @@ -143,6 +143,16 @@ def add_update_listener(self, listener): self.update_listeners.add(listener) + def get_dist_deps(self, includeSelf=True, transitive=False): + deps = set() + if includeSelf: + deps.add(self) + deps.update([distribution(name) for name in self.distDependencies]) + if transitive: + for depName in self.distDependencies: + deps.update(distribution(depName).get_dist_deps(False, False)) + return list(deps) + """ Gets the directory in which the IDE project configuration for this distribution is generated. If this is a distribution @@ -167,6 +177,9 @@ srcArc = arc if unified else srcArcRaw services = {} def overwriteCheck(zf, arcname, source): + if os.path.basename(arcname).startswith('.'): + logv('Excluding dotfile: ' + source) + return True if not hasattr(zf, '_provenance'): zf._provenance = {} existingSource = zf._provenance.get(arcname, None) @@ -633,6 +646,7 @@ if canSymlink and 'symlink' in dir(os): if exists(path): os.unlink(path) + print 'Path ' + cachePath + ' path: ' + path os.symlink(cachePath, path) else: shutil.copy(cachePath, path) @@ -4429,7 +4443,7 @@ out.close('target') out.open('target', {'name' : 'compile'}) - out.open('exec', {'executable' : sys.executable}) + out.open('exec', {'executable' : sys.executable, 'failonerror' : 'true'}) out.element('env', {'key' : 'JAVA_HOME', 'value' : jdk.jdk}) out.element('arg', {'value' : os.path.abspath(__file__)}) out.element('arg', {'value' : 'build'}) @@ -4904,8 +4918,8 @@ distIdeDirs = [d.get_ide_project_dir() for d in suite.dists if d.get_ide_project_dir() is not None] for dirpath, dirnames, files in os.walk(suite.dir): if dirpath == suite.dir: - # no point in traversing .hg or lib/ - dirnames[:] = [d for d in dirnames if d not in ['.hg', 'lib']] + # no point in traversing .hg, lib, or .workspace + dirnames[:] = [d for d in dirnames if d not in ['.hg', 'lib', '.workspace']] elif dirpath in projectDirs: # don't traverse subdirs of an existing project in this suite dirnames[:] = [] diff -r bc2ec35a7189 -r 27943aac2e3c src/share/vm/jvmci/jvmciOptions.cpp --- a/src/share/vm/jvmci/jvmciOptions.cpp Thu Jun 04 10:46:23 2015 -0700 +++ b/src/share/vm/jvmci/jvmciOptions.cpp Thu Jun 04 11:08:12 2015 -0700 @@ -90,7 +90,7 @@ type = _boolean; break; default: - warn_and_abort("unkown type"); + warn_and_abort("unknown type"); return; } char* name2 = NEW_C_HEAP_ARRAY(char, (strlen(name) + 1 + strlen(help) + 1 + strlen(declaringClass) + 1 + strlen(fieldClass) + 1), mtCompiler);