# HG changeset patch # User Doug Simon # Date 1433802169 -7200 # Node ID 395ac43a857803090cef1bed11c711e846d74076 # Parent 42452d2dfbec3a53796219f6e7aeafb98e62440f moved JVMCI sources from graal/ to jvmci/ directory diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.amd64/src/com/oracle/jvmci/amd64/AMD64.java --- a/graal/com.oracle.jvmci.amd64/src/com/oracle/jvmci/amd64/AMD64.java Mon Jun 08 23:40:08 2015 +0200 +++ /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.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 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.code/overview.html --- a/graal/com.oracle.jvmci.code/overview.html Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,37 +0,0 @@ - - - - - - - - -The com.oracle.jvmci.code project provides an API to the runtime's native code cache. -It allows installation and execution of native code. - - - diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.code/src/com/oracle/jvmci/code/AbstractAddress.java --- a/graal/com.oracle.jvmci.code/src/com/oracle/jvmci/code/AbstractAddress.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,29 +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; - -/** - * Abstract base class that represents a platform specific address. - */ -public abstract class AbstractAddress { -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.code/src/com/oracle/jvmci/code/Architecture.java --- a/graal/com.oracle.jvmci.code/src/com/oracle/jvmci/code/Architecture.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,250 +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.code; - -import com.oracle.jvmci.meta.Kind; -import com.oracle.jvmci.meta.PlatformKind; -import java.nio.*; -import java.util.*; - -import com.oracle.jvmci.code.Register.RegisterCategory; - -/** - * Represents a CPU architecture, including information such as its endianness, CPU registers, word - * width, etc. - */ -public abstract class Architecture { - - /** - * The number of entries required in a {@link ReferenceMap} covering all the registers that may - * store references. The index of a register in the reference map is given by - * {@link Register#getReferenceMapIndex()}. - */ - private final int registerReferenceMapSize; - - /** - * Represents the natural size of words (typically registers and pointers) of this architecture, - * in bytes. - */ - private final int wordSize; - - /** - * The name of this architecture (e.g. "AMD64", "SPARCv9"). - */ - private final String name; - - /** - * Array of all available registers on this architecture. The index of each register in this - * array is equal to its {@linkplain Register#number number}. - */ - private final Register[] registers; - - /** - * The byte ordering can be either little or big endian. - */ - private final ByteOrder byteOrder; - - /** - * Whether the architecture supports unaligned memory accesses. - */ - private final boolean unalignedMemoryAccess; - - /** - * Mask of the barrier constants denoting the barriers that are not required to be explicitly - * inserted under this architecture. - */ - private final int implicitMemoryBarriers; - - /** - * Offset in bytes from the beginning of a call instruction to the displacement. - */ - private final int machineCodeCallDisplacementOffset; - - /** - * The size of the return address pushed to the stack by a call instruction. A value of 0 - * denotes that call linkage uses registers instead (e.g. SPARC). - */ - private final int returnAddressSize; - - protected Architecture(String name, int wordSize, ByteOrder byteOrder, boolean unalignedMemoryAccess, Register[] registers, int implicitMemoryBarriers, int nativeCallDisplacementOffset, - int registerReferenceMapSize, int returnAddressSize) { - this.name = name; - this.registers = registers; - this.wordSize = wordSize; - this.byteOrder = byteOrder; - this.unalignedMemoryAccess = unalignedMemoryAccess; - this.implicitMemoryBarriers = implicitMemoryBarriers; - this.machineCodeCallDisplacementOffset = nativeCallDisplacementOffset; - this.registerReferenceMapSize = registerReferenceMapSize; - this.returnAddressSize = returnAddressSize; - } - - /** - * Converts this architecture to a string. - * - * @return the string representation of this architecture - */ - @Override - public final String toString() { - return getName().toLowerCase(); - } - - public int getRegisterReferenceMapSize() { - return registerReferenceMapSize; - } - - /** - * Gets the natural size of words (typically registers and pointers) of this architecture, in - * bytes. - */ - public int getWordSize() { - return wordSize; - } - - /** - * Gets the name of this architecture. - */ - public String getName() { - return name; - } - - /** - * Gets an array of all available registers on this architecture. The index of each register in - * this array is equal to its {@linkplain Register#number number}. - */ - public Register[] getRegisters() { - return registers.clone(); - } - - public ByteOrder getByteOrder() { - return byteOrder; - } - - /** - * @return true if the architecture supports unaligned memory accesses. - */ - public boolean supportsUnalignedMemoryAccess() { - return unalignedMemoryAccess; - } - - /** - * Gets the size of the return address pushed to the stack by a call instruction. A value of 0 - * denotes that call linkage uses registers instead. - */ - public int getReturnAddressSize() { - return returnAddressSize; - } - - /** - * Gets the offset in bytes from the beginning of a call instruction to the displacement. - */ - public int getMachineCodeCallDisplacementOffset() { - return machineCodeCallDisplacementOffset; - } - - /** - * Determines the barriers in a given barrier mask that are explicitly required on this - * architecture. - * - * @param barriers a mask of the barrier constants - * @return the value of {@code barriers} minus the barriers unnecessary on this architecture - */ - public final int requiredBarriers(int barriers) { - return barriers & ~implicitMemoryBarriers; - } - - /** - * Gets the size in bytes of the specified kind for this target. - * - * @param kind the kind for which to get the size - * - * @return the size in bytes of {@code kind} - */ - public int getSizeInBytes(PlatformKind kind) { - switch ((Kind) kind) { - case Boolean: - return 1; - case Byte: - return 1; - case Char: - return 2; - case Short: - return 2; - case Int: - return 4; - case Long: - return 8; - case Float: - return 4; - case Double: - return 8; - case Object: - return wordSize; - default: - return 0; - } - } - - /** - * Determine whether a kind can be stored in a register of a given category. - * - * @param category the category of the register - * @param kind the kind that should be stored in the register - */ - public abstract boolean canStoreValue(RegisterCategory category, PlatformKind kind); - - /** - * Return the largest kind that can be stored in a register of a given category. - * - * @param category the category of the register - * @return the largest kind that can be stored in a register {@code category} - */ - public abstract PlatformKind getLargestStorableKind(RegisterCategory category); - - @Override - public final boolean equals(Object obj) { - if (obj == this) { - return true; - } - if (obj instanceof Architecture) { - Architecture that = (Architecture) obj; - if (this.name.equals(that.name)) { - assert this.byteOrder.equals(that.byteOrder); - assert this.implicitMemoryBarriers == that.implicitMemoryBarriers; - assert this.machineCodeCallDisplacementOffset == that.machineCodeCallDisplacementOffset; - assert this.registerReferenceMapSize == that.registerReferenceMapSize; - assert Arrays.equals(this.registers, that.registers); - assert this.returnAddressSize == that.returnAddressSize; - assert this.unalignedMemoryAccess == that.unalignedMemoryAccess; - assert this.wordSize == that.wordSize; - return true; - } - } - return false; - } - - @Override - public final int hashCode() { - return name.hashCode(); - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.code/src/com/oracle/jvmci/code/ArithmeticOperation.java --- a/graal/com.oracle.jvmci.code/src/com/oracle/jvmci/code/ArithmeticOperation.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,30 +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.jvmci.code; - -/** - * An {@code ArithmeticOperation} is an operation that does primitive value arithmetic without side - * effect. - */ -public interface ArithmeticOperation { -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.code/src/com/oracle/jvmci/code/BailoutException.java --- a/graal/com.oracle.jvmci.code/src/com/oracle/jvmci/code/BailoutException.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,76 +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.code; - -import java.util.*; - -/** - * Exception thrown when the compiler refuses to compile a method because of problems with the - * method. e.g. bytecode wouldn't verify, too big, JSR/ret too complicated, etc. This exception is - * not meant to indicate problems with the compiler itself. - */ -public class BailoutException extends RuntimeException { - - public static final long serialVersionUID = 8974598793458772L; - private final boolean permanent; - - /** - * Creates a new {@link BailoutException}. - * - * - * @param args parameters to the formatter - */ - public BailoutException(String format, Object... args) { - super(String.format(Locale.ENGLISH, format, args)); - this.permanent = true; - } - - /** - * Creates a new {@link BailoutException}. - * - * - * @param args parameters to the formatter - */ - public BailoutException(Throwable cause, String format, Object... args) { - super(String.format(Locale.ENGLISH, format, args), cause); - this.permanent = true; - } - - /** - * Creates a new {@link BailoutException}. - * - * @param permanent specifies whether this exception will occur again if compilation is retried - * @param args parameters to the formatter - */ - public BailoutException(boolean permanent, String format, Object... args) { - super(String.format(Locale.ENGLISH, format, args)); - this.permanent = permanent; - } - - /** - * @return whether this exception will occur again if compilation is retried - */ - public boolean isPermanent() { - return permanent; - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.code/src/com/oracle/jvmci/code/BytecodeFrame.java --- a/graal/com.oracle.jvmci.code/src/com/oracle/jvmci/code/BytecodeFrame.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,272 +0,0 @@ -/* - * Copyright (c) 2009, 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.code; - -import com.oracle.jvmci.meta.Kind; -import com.oracle.jvmci.meta.ResolvedJavaMethod; -import com.oracle.jvmci.meta.Value; -import java.util.*; - -/** - * Represents the Java bytecode frame state(s) at a given position including {@link Value locations} - * where to find the local variables, operand stack values and locked objects of the bytecode - * frame(s). - */ -public class BytecodeFrame extends BytecodePosition { - - /** - * An array of values representing how to reconstruct the state of the Java frame. This is array - * is partitioned as follows: - *

- * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - *
Start index (inclusive)End index (exclusive)Description
0numLocalsLocal variables
numLocalsnumLocals + numStackOperand stack
numLocals + numStackvalues.lengthLocked objects
- *

- * Note that the number of locals and the number of stack slots may be smaller than the maximum - * number of locals and stack slots as specified in the compiled method. - */ - public final Value[] values; - - /** - * The number of locals in the values array. - */ - public final int numLocals; - - /** - * The number of stack slots in the values array. - */ - public final int numStack; - - /** - * The number of locks in the values array. - */ - public final int numLocks; - - /** - * True if this is a position inside an exception handler before the exception object has been - * consumed. In this case, {@link #numStack} {@code == 1} and {@link #getStackValue(int) - * getStackValue(0)} is the location of the exception object. If deoptimization happens at this - * position, the interpreter will rethrow the exception instead of executing the bytecode - * instruction at this position. - */ - public final boolean rethrowException; - - public final boolean duringCall; - - /** - * This BCI should be used for frame states that are built for code with no meaningful BCI. - */ - public static final int UNKNOWN_BCI = -5; - - /** - * The BCI for exception unwind. This is synthetic code and has no representation in bytecode. - * In contrast with {@link #AFTER_EXCEPTION_BCI}, at this point, if the method is synchronized, - * the monitor is still held. - */ - public static final int UNWIND_BCI = -1; - - /** - * The BCI for the state before starting to execute a method. Note that if the method is - * synchronized, the monitor is not yet held. - */ - public static final int BEFORE_BCI = -2; - - /** - * The BCI for the state after finishing the execution of a method and returning normally. Note - * that if the method was synchronized the monitor is already released. - */ - public static final int AFTER_BCI = -3; - - /** - * The BCI for exception unwind. This is synthetic code and has no representation in bytecode. - * In contrast with {@link #UNWIND_BCI}, at this point, if the method is synchronized, the - * monitor is already released. - */ - public static final int AFTER_EXCEPTION_BCI = -4; - - /** - * This BCI should be used for states that cannot be the target of a deoptimization, like - * snippet frame states. - */ - public static final int INVALID_FRAMESTATE_BCI = -6; - - /** - * Determines if a given BCI matches one of the placeholder BCI constants defined in this class. - */ - public static boolean isPlaceholderBci(int bci) { - return bci < 0; - } - - /** - * Gets the name of a given placeholder BCI. - */ - public static String getPlaceholderBciName(int bci) { - assert isPlaceholderBci(bci); - if (bci == BytecodeFrame.AFTER_BCI) { - return "AFTER_BCI"; - } else if (bci == BytecodeFrame.AFTER_EXCEPTION_BCI) { - return "AFTER_EXCEPTION_BCI"; - } else if (bci == BytecodeFrame.INVALID_FRAMESTATE_BCI) { - return "INVALID_FRAMESTATE_BCI"; - } else if (bci == BytecodeFrame.BEFORE_BCI) { - return "BEFORE_BCI"; - } else if (bci == BytecodeFrame.UNKNOWN_BCI) { - return "UNKNOWN_BCI"; - } else { - assert bci == BytecodeFrame.UNWIND_BCI; - return "UNWIND_BCI"; - } - } - - /** - * Creates a new frame object. - * - * @param caller the caller frame (which may be {@code null}) - * @param method the method - * @param bci a BCI within the method - * @param rethrowException specifies if the VM should re-throw the pending exception when - * deopt'ing using this frame - * @param values the frame state {@link #values} - * @param numLocals the number of local variables - * @param numStack the depth of the stack - * @param numLocks the number of locked objects - */ - public BytecodeFrame(BytecodeFrame caller, ResolvedJavaMethod method, int bci, boolean rethrowException, boolean duringCall, Value[] values, int numLocals, int numStack, int numLocks) { - super(caller, method, bci); - assert values != null; - this.rethrowException = rethrowException; - this.duringCall = duringCall; - this.values = values; - this.numLocals = numLocals; - this.numStack = numStack; - this.numLocks = numLocks; - assert !rethrowException || numStack == 1 : "must have exception on top of the stack"; - } - - /** - * Ensure that the frame state is formatted as expected by the JVM, with null or Illegal in the - * slot following a double word item. This should really be checked in FrameState itself but - * because of Word type rewriting and alternative backends that can't be done. - */ - public boolean validateFormat(boolean derivedOk) { - if (caller() != null) { - caller().validateFormat(derivedOk); - } - for (int i = 0; i < numLocals + numStack; i++) { - if (values[i] != null) { - Kind kind = values[i].getKind(); - if (kind.needsTwoSlots()) { - assert values.length > i + 1 : String.format("missing second word %s", this); - assert values[i + 1] == null || values[i + 1].getKind() == Kind.Illegal : this; - } - assert derivedOk || ValueUtil.isIllegal(values[i]) || !values[i].getLIRKind().isDerivedReference() : "Unexpected derived value: " + values[i]; - } - } - return true; - } - - /** - * Gets the value representing the specified local variable. - * - * @param i the local variable index - * @return the value that can be used to reconstruct the local's current value - */ - public Value getLocalValue(int i) { - return values[i]; - } - - /** - * Gets the value representing the specified stack slot. - * - * @param i the stack index - * @return the value that can be used to reconstruct the stack slot's current value - */ - public Value getStackValue(int i) { - return values[i + numLocals]; - } - - /** - * Gets the value representing the specified lock. - * - * @param i the lock index - * @return the value that can be used to reconstruct the lock's current value - */ - public Value getLockValue(int i) { - return values[i + numLocals + numStack]; - } - - /** - * Gets the caller of this frame. - * - * @return {@code null} if this frame has no caller - */ - public BytecodeFrame caller() { - return (BytecodeFrame) getCaller(); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj instanceof BytecodeFrame && super.equals(obj)) { - BytecodeFrame that = (BytecodeFrame) obj; - // @formatter:off - if (this.duringCall == that.duringCall && - this.rethrowException == that.rethrowException && - this.numLocals == that.numLocals && - this.numLocks == that.numLocks && - this.numStack == that.numStack && - Arrays.equals(this.values, that.values)) { - return true; - } - // @formatter:off - return true; - } - return false; - } - - @Override - public String toString() { - return CodeUtil.append(new StringBuilder(100), this).toString(); - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.code/src/com/oracle/jvmci/code/BytecodePosition.java --- a/graal/com.oracle.jvmci.code/src/com/oracle/jvmci/code/BytecodePosition.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,119 +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.code; - -import com.oracle.jvmci.meta.ResolvedJavaMethod; -import java.util.*; - -/** - * Represents a code position, that is, a chain of inlined methods with bytecode locations, that is - * communicated from the compiler to the runtime system. A code position can be used by the runtime - * system to reconstruct a source-level stack trace for exceptions and to create - * {@linkplain BytecodeFrame frames} for deoptimization. - */ -public class BytecodePosition { - - private final BytecodePosition caller; - private final ResolvedJavaMethod method; - private final int bci; - - /** - * Constructs a new object representing a given parent/caller, a given method, and a given BCI. - * - * @param caller the parent position - * @param method the method - * @param bci a BCI within the method - */ - public BytecodePosition(BytecodePosition caller, ResolvedJavaMethod method, int bci) { - assert method != null; - this.caller = caller; - this.method = method; - this.bci = bci; - } - - /** - * Converts this code position to a string representation. - * - * @return a string representation of this code position - */ - @Override - public String toString() { - return CodeUtil.append(new StringBuilder(100), this).toString(); - } - - /** - * Deep equality test. - */ - @Override - public boolean equals(Object obj) { - if (obj == this) { - return true; - } - if (obj != null && getClass() == obj.getClass()) { - BytecodePosition that = (BytecodePosition) obj; - if (this.bci == that.bci && Objects.equals(this.getMethod(), that.getMethod()) && Objects.equals(this.caller, that.caller)) { - return true; - } - } - return false; - } - - @Override - public int hashCode() { - return getBCI(); - } - - /** - * @return The location within the method, as a bytecode index. The constant {@code -1} may be - * used to indicate the location is unknown, for example within code synthesized by the - * compiler. - */ - public int getBCI() { - return bci; - } - - /** - * @return The runtime interface method for this position. - */ - public ResolvedJavaMethod getMethod() { - return method; - } - - /** - * The position where this position has been called, {@code null} if none. - */ - public BytecodePosition getCaller() { - return caller; - } - - /** - * Adds a caller to the current position returning the new position. - */ - public BytecodePosition addCaller(BytecodePosition link) { - if (getCaller() == null) { - return new BytecodePosition(link, getMethod(), getBCI()); - } else { - return new BytecodePosition(getCaller().addCaller(link), getMethod(), getBCI()); - } - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.code/src/com/oracle/jvmci/code/CalleeSaveLayout.java --- a/graal/com.oracle.jvmci.code/src/com/oracle/jvmci/code/CalleeSaveLayout.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,181 +0,0 @@ -/* - * Copyright (c) 2010, 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.code; - -import com.oracle.jvmci.meta.PlatformKind; -import java.util.*; - -/** - * The callee save area (CSA) is a contiguous space in a stack frame used to save (and restore) the - * values of the caller's registers. This class describes the layout of a CSA in terms of its - * {@linkplain #size size}, {@linkplain #slotSize slot size} and the {@linkplain #registers callee - * save registers} covered by the CSA. - */ -public class CalleeSaveLayout { - - /** - * The size (in bytes) of the CSA. - */ - public final int size; - - /** - * The size (in bytes) of an {@linkplain #registerAt(int) indexable} slot in the CSA. - */ - public final int slotSize; - - /** - * Map from {@linkplain Register#number register numbers} to slot indexes in the CSA. - */ - private final int[] regNumToIndex; - - private final Register[] indexToReg; - - /** - * The list of registers {@linkplain #contains(int) contained} by this CSA. - */ - public final Register[] registers; - - /** - * The offset from the frame pointer to the CSA. If this is not known, then this field will have - * the value {@link Integer#MAX_VALUE}. - */ - public final int frameOffsetToCSA; - - /** - * Creates a CSA layout. - * - * @param size size (in bytes) of the CSA. If this is {@code -1}, then the CSA size will be - * computed from {@code registers}. - * @param slotSize the size (in bytes) of an {@linkplain #registerAt(int) indexable} slot in the - * CSA - * @param registers the registers that can be saved in the CSA - */ - public CalleeSaveLayout(TargetDescription target, int frameOffsetToCSA, int size, int slotSize, Register... registers) { - this.frameOffsetToCSA = frameOffsetToCSA; - assert slotSize == 0 || CodeUtil.isPowerOf2(slotSize); - this.slotSize = slotSize; - int maxRegNum = -1; - int maxOffset = 0; - this.registers = registers; - int offset = 0; - for (Register reg : registers) { - assert offset % slotSize == 0; - assert reg.number >= 0; - if (reg.number > maxRegNum) { - maxRegNum = reg.number; - } - if (offset > maxOffset) { - maxOffset = offset; - } - PlatformKind kind = target.arch.getLargestStorableKind(reg.getRegisterCategory()); - offset += target.getSizeInBytes(kind); - } - if (size == -1) { - this.size = offset; - } else { - assert offset <= size; - this.size = size; - } - - this.regNumToIndex = new int[maxRegNum + 1]; - this.indexToReg = offset == 0 ? new Register[0] : new Register[offset / slotSize]; - Arrays.fill(regNumToIndex, -1); - offset = 0; - for (Register reg : registers) { - int index = offset / slotSize; - regNumToIndex[reg.number] = index; - indexToReg[index] = reg; - PlatformKind kind = target.arch.getLargestStorableKind(reg.getRegisterCategory()); - offset += target.getSizeInBytes(kind); - } - } - - /** - * Gets the offset of a given register in the CSA. - * - * @return the offset (in bytes) of {@code reg} in the CSA - * @throws IllegalArgumentException if {@code reg} does not have a slot in the CSA - */ - public int offsetOf(int reg) { - return indexOf(reg) * slotSize; - } - - /** - * Gets the index of a given register in the CSA. - * - * @return the index of {@code reg} in the CSA - * @throws IllegalArgumentException if {@code reg} does not have a slot in the CSA - */ - public int indexOf(int reg) { - if (!contains(reg)) { - throw new IllegalArgumentException(String.valueOf(reg)); - } - return regNumToIndex[reg]; - } - - /** - * Gets the offset of a given register in the CSA. - * - * @return the offset (in bytes) of {@code reg} in the CSA - * @throws IllegalArgumentException if {@code reg} does not have a slot in the CSA - */ - public int offsetOf(Register reg) { - return offsetOf(reg.number); - } - - /** - * Determines if the CSA includes a slot for a given register. - * - * @param reg the register to test - * @return true if the CSA contains a slot for {@code reg} - */ - public boolean contains(int reg) { - return reg >= 0 && reg < regNumToIndex.length && regNumToIndex[reg] != -1; - } - - /** - * Gets the register whose slot in the CSA is at a given index. - * - * @param index an index of a slot in the CSA - * @return the register whose slot in the CSA is at {@code index} or {@code null} if - * {@code index} does not denote a slot in the CSA aligned with a register - */ - public Register registerAt(int index) { - if (index < 0 || index >= indexToReg.length) { - return null; - } - return indexToReg[index]; - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder("["); - for (Register reg : registers) { - if (sb.length() != 1) { - sb.append(", "); - } - sb.append(reg).append("{+").append(offsetOf(reg)).append('}'); - } - return sb.append("] size=").append(size).toString(); - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.code/src/com/oracle/jvmci/code/CallingConvention.java --- a/graal/com.oracle.jvmci.code/src/com/oracle/jvmci/code/CallingConvention.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,158 +0,0 @@ -/* - * Copyright (c) 2009, 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.code; - -import com.oracle.jvmci.meta.Value; -import com.oracle.jvmci.meta.AllocatableValue; -import static com.oracle.jvmci.code.ValueUtil.*; - -/** - * A calling convention describes the locations in which the arguments for a call are placed and the - * location in which the return value is placed if the call is not void. - */ -public class CallingConvention { - - /** - * Constants denoting the type of a call for which a calling convention is requested. - */ - public enum Type { - /** - * A request for the outgoing argument locations at a call site to Java code. - */ - JavaCall(true), - - /** - * A request for the incoming argument locations. - */ - JavaCallee(false), - - /** - * A request for the outgoing argument locations at a call site to external native code that - * complies with the platform ABI. - */ - NativeCall(true); - - /** - * Determines if this is a request for the outgoing argument locations at a call site. - */ - public final boolean out; - - public static final Type[] VALUES = values(); - - private Type(boolean out) { - this.out = out; - } - } - - /** - * The amount of stack space (in bytes) required for the stack-based arguments of the call. - */ - private final int stackSize; - - private final AllocatableValue returnLocation; - - /** - * The ordered locations in which the arguments are placed. - */ - private final AllocatableValue[] argumentLocations; - - /** - * Creates a description of the registers and stack locations used by a call. - * - * @param stackSize amount of stack space (in bytes) required for the stack-based arguments of - * the call - * @param returnLocation the location for the return value or {@link Value#ILLEGAL} if a void - * call - * @param argumentLocations the ordered locations in which the arguments are placed - */ - public CallingConvention(int stackSize, AllocatableValue returnLocation, AllocatableValue... argumentLocations) { - assert argumentLocations != null; - assert returnLocation != null; - this.argumentLocations = argumentLocations; - this.stackSize = stackSize; - this.returnLocation = returnLocation; - assert verify(); - } - - /** - * Gets the location for the return value or {@link Value#ILLEGAL} if a void call. - */ - public AllocatableValue getReturn() { - return returnLocation; - } - - /** - * Gets the location for the {@code index}'th argument. - */ - public AllocatableValue getArgument(int index) { - return argumentLocations[index]; - } - - /** - * Gets the amount of stack space (in bytes) required for the stack-based arguments of the call. - */ - public int getStackSize() { - return stackSize; - } - - /** - * Gets the number of locations required for the arguments. - */ - public int getArgumentCount() { - return argumentLocations.length; - } - - /** - * Gets the locations required for the arguments. - */ - public AllocatableValue[] getArguments() { - if (argumentLocations.length == 0) { - return argumentLocations; - } - return argumentLocations.clone(); - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("CallingConvention["); - String sep = ""; - for (Value op : argumentLocations) { - sb.append(sep).append(op); - sep = ", "; - } - if (!returnLocation.equals(Value.ILLEGAL)) { - sb.append(" -> ").append(returnLocation); - } - sb.append("]"); - return sb.toString(); - } - - private boolean verify() { - for (int i = 0; i < argumentLocations.length; i++) { - Value location = argumentLocations[i]; - assert isStackSlot(location) || isAllocatableValue(location); - } - return true; - } -} diff -r 42452d2dfbec -r 395ac43a8578 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 Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,105 +0,0 @@ -/* - * Copyright (c) 2009, 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.code; - -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. - */ -public interface CodeCacheProvider { - - /** - * Adds the given compilation result as an implementation of the given method without making it - * the default implementation. - * - * @param method a method to which the executable code is begin added - * @param compResult the compilation result to be added - * @param speculationLog the speculation log to be used - * @return a reference to the compiled and ready-to-run code or throws a - * {@link BailoutException} if the code installation failed - */ - InstalledCode addMethod(ResolvedJavaMethod method, CompilationResult compResult, SpeculationLog speculationLog, InstalledCode predefinedInstalledCode); - - /** - * Sets the given compilation result as the default implementation of the given method. - * - * @param method a method to which the executable code is begin added - * @param compResult the compilation result to be added - * @return a reference to the compiled and ready-to-run code or null if the code installation - * failed - */ - InstalledCode setDefaultMethod(ResolvedJavaMethod method, CompilationResult compResult); - - /** - * Gets a name for a {@link Mark} mark. - */ - 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. - */ - RegisterConfig getRegisterConfig(); - - /** - * Minimum size of the stack area reserved for outgoing parameters. This area is reserved in all - * cases, even when the compiled method has no regular call instructions. - * - * @return the minimum size of the outgoing parameter area in bytes - */ - int getMinimumOutgoingSize(); - - /** - * Determines if a {@link DataPatch} should be created for a given primitive constant that is - * part of a {@link CompilationResult}. A data patch is always created for an object constant. - */ - boolean needsDataPatch(JavaConstant constant); - - /** - * Create a {@link Data} item for a {@link Constant}, that can be used in a {@link DataPatch}. - */ - Data createDataItem(Constant constant); - - /** - * Gets a description of the target architecture. - */ - TargetDescription getTarget(); - - /** - * Create a new speculation log for the target runtime. - */ - SpeculationLog createSpeculationLog(); -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.code/src/com/oracle/jvmci/code/CodeUtil.java --- a/graal/com.oracle.jvmci.code/src/com/oracle/jvmci/code/CodeUtil.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,474 +0,0 @@ -/* - * Copyright (c) 2010, 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; - -import com.oracle.jvmci.meta.Signature; -import com.oracle.jvmci.meta.ResolvedJavaMethod; -import com.oracle.jvmci.meta.JavaType; -import com.oracle.jvmci.meta.MetaUtil; -import java.util.*; - -/** - * Miscellaneous collection of utility methods used by {@code com.oracle.jvmci.code} and its - * clients. - */ -public class CodeUtil { - - public static final String NEW_LINE = String.format("%n"); - - public static final int K = 1024; - public static final int M = 1024 * 1024; - - public static boolean isOdd(int n) { - return (n & 1) == 1; - } - - public static boolean isEven(int n) { - return (n & 1) == 0; - } - - /** - * Checks whether the specified integer is a power of two. - * - * @param val the value to check - * @return {@code true} if the value is a power of two; {@code false} otherwise - */ - public static boolean isPowerOf2(int val) { - return val > 0 && (val & val - 1) == 0; - } - - /** - * Checks whether the specified long is a power of two. - * - * @param val the value to check - * @return {@code true} if the value is a power of two; {@code false} otherwise - */ - public static boolean isPowerOf2(long val) { - return val > 0 && (val & val - 1) == 0; - } - - /** - * Computes the log (base 2) of the specified integer, rounding down. (E.g {@code log2(8) = 3}, - * {@code log2(21) = 4} ) - * - * @param val the value - * @return the log base 2 of the value - */ - public static int log2(int val) { - assert val > 0; - return (Integer.SIZE - 1) - Integer.numberOfLeadingZeros(val); - } - - /** - * Computes the log (base 2) of the specified long, rounding down. (E.g {@code log2(8) = 3}, - * {@code log2(21) = 4}) - * - * @param val the value - * @return the log base 2 of the value - */ - public static int log2(long val) { - assert val > 0; - return (Long.SIZE - 1) - Long.numberOfLeadingZeros(val); - } - - /** - * Narrow an integer value to a given bit width, and return the result as a signed long. - * - * @param value the value - * @param resultBits the result bit width - * @return {@code value} interpreted as {@code resultBits} bit number, encoded as signed long - */ - public static long narrow(long value, int resultBits) { - long ret = value & mask(resultBits); - return signExtend(ret, resultBits); - } - - /** - * Sign extend an integer. - * - * @param value the input value - * @param inputBits the bit width of the input value - * @return a signed long with the same value as the signed {@code inputBits}-bit number - * {@code value} - */ - public static long signExtend(long value, int inputBits) { - if (inputBits < 64) { - if ((value >>> (inputBits - 1) & 1) == 1) { - return value | (-1L << inputBits); - } else { - return value & ~(-1L << inputBits); - } - } else { - return value; - } - } - - /** - * Zero extend an integer. - * - * @param value the input value - * @param inputBits the bit width of the input value - * @return an unsigned long with the same value as the unsigned {@code inputBits}-bit number - * {@code value} - */ - public static long zeroExtend(long value, int inputBits) { - if (inputBits < 64) { - return value & ~(-1L << inputBits); - } else { - return value; - } - } - - /** - * Convert an integer to long. - * - * @param value the input value - * @param inputBits the bit width of the input value - * @param unsigned whether the values should be interpreted as signed or unsigned - * @return a long with the same value as the {@code inputBits}-bit number {@code value} - */ - public static long convert(long value, int inputBits, boolean unsigned) { - if (unsigned) { - return zeroExtend(value, inputBits); - } else { - return signExtend(value, inputBits); - } - } - - /** - * Get a bitmask with the low {@code bits} bit set and the high {@code 64 - bits} bit clear. - */ - public static long mask(int bits) { - assert 0 <= bits && bits <= 64; - if (bits == 64) { - return 0xffffffffffffffffL; - } else { - return (1L << bits) - 1; - } - } - - /** - * Get the minimum value representable in a {@code bits} bit signed integer. - */ - public static long minValue(int bits) { - assert 0 < bits && bits <= 64; - return -1L << (bits - 1); - } - - /** - * Get the maximum value representable in a {@code bits} bit signed integer. - */ - public static long maxValue(int bits) { - assert 0 < bits && bits <= 64; - return mask(bits - 1); - } - - /** - * Formats the values in a frame as a tabulated string. - * - * @param frame - * @return the values in {@code frame} as a tabulated string - */ - public static String tabulateValues(BytecodeFrame frame) { - int cols = Math.max(frame.numLocals, Math.max(frame.numStack, frame.numLocks)); - assert cols > 0; - ArrayList cells = new ArrayList<>(); - cells.add(""); - for (int i = 0; i < cols; i++) { - cells.add(i); - } - cols++; - if (frame.numLocals != 0) { - cells.add("locals:"); - cells.addAll(Arrays.asList(frame.values).subList(0, frame.numLocals)); - cells.addAll(Collections.nCopies(cols - frame.numLocals - 1, "")); - } - if (frame.numStack != 0) { - cells.add("stack:"); - cells.addAll(Arrays.asList(frame.values).subList(frame.numLocals, frame.numLocals + frame.numStack)); - cells.addAll(Collections.nCopies(cols - frame.numStack - 1, "")); - } - if (frame.numLocks != 0) { - cells.add("locks:"); - cells.addAll(Arrays.asList(frame.values).subList(frame.numLocals + frame.numStack, frame.values.length)); - cells.addAll(Collections.nCopies(cols - frame.numLocks - 1, "")); - } - Object[] cellArray = cells.toArray(); - for (int i = 0; i < cellArray.length; i++) { - if ((i % cols) != 0) { - cellArray[i] = "|" + cellArray[i]; - } - } - return CodeUtil.tabulate(cellArray, cols, 1, 1); - } - - /** - * Formats a given table as a string. The value of each cell is produced by - * {@link String#valueOf(Object)}. - * - * @param cells the cells of the table in row-major order - * @param cols the number of columns per row - * @param lpad the number of space padding inserted before each formatted cell value - * @param rpad the number of space padding inserted after each formatted cell value - * @return a string with one line per row and each column left-aligned - */ - public static String tabulate(Object[] cells, int cols, int lpad, int rpad) { - int rows = (cells.length + (cols - 1)) / cols; - int[] colWidths = new int[cols]; - for (int col = 0; col < cols; col++) { - for (int row = 0; row < rows; row++) { - int index = col + (row * cols); - if (index < cells.length) { - Object cell = cells[index]; - colWidths[col] = Math.max(colWidths[col], String.valueOf(cell).length()); - } - } - } - StringBuilder sb = new StringBuilder(); - String nl = NEW_LINE; - for (int row = 0; row < rows; row++) { - for (int col = 0; col < cols; col++) { - int index = col + (row * cols); - if (index < cells.length) { - for (int i = 0; i < lpad; i++) { - sb.append(' '); - } - Object cell = cells[index]; - String s = String.valueOf(cell); - int w = s.length(); - sb.append(s); - while (w < colWidths[col]) { - sb.append(' '); - w++; - } - for (int i = 0; i < rpad; i++) { - sb.append(' '); - } - } - } - sb.append(nl); - } - return sb.toString(); - } - - /** - * Appends a formatted code position to a {@link StringBuilder}. - * - * @param sb the {@link StringBuilder} to append to - * @param pos the code position to format and append to {@code sb} - * @return the value of {@code sb} - */ - public static StringBuilder append(StringBuilder sb, BytecodePosition pos) { - MetaUtil.appendLocation(sb.append("at "), pos.getMethod(), pos.getBCI()); - if (pos.getCaller() != null) { - sb.append(NEW_LINE); - append(sb, pos.getCaller()); - } - return sb; - } - - /** - * Appends a formatted frame to a {@link StringBuilder}. - * - * @param sb the {@link StringBuilder} to append to - * @param frame the frame to format and append to {@code sb} - * @return the value of {@code sb} - */ - public static StringBuilder append(StringBuilder sb, BytecodeFrame frame) { - MetaUtil.appendLocation(sb.append("at "), frame.getMethod(), frame.getBCI()); - assert sb.charAt(sb.length() - 1) == ']'; - sb.deleteCharAt(sb.length() - 1); - sb.append(", duringCall: ").append(frame.duringCall).append(", rethrow: ").append(frame.rethrowException).append(']'); - if (frame.values != null && frame.values.length > 0) { - sb.append(NEW_LINE); - String table = tabulateValues(frame); - String[] rows = table.split(NEW_LINE); - for (int i = 0; i < rows.length; i++) { - String row = rows[i]; - if (!row.trim().isEmpty()) { - sb.append(" ").append(row); - if (i != rows.length - 1) { - sb.append(NEW_LINE); - } - } - } - } - if (frame.caller() != null) { - sb.append(NEW_LINE); - append(sb, frame.caller()); - } else if (frame.getCaller() != null) { - sb.append(NEW_LINE); - append(sb, frame.getCaller()); - } - return sb; - } - - public interface RefMapFormatter { - - String formatStackSlot(int frameRefMapIndex); - - String formatRegister(int regRefMapIndex); - } - - /** - * Formats a location in a register reference map. - */ - public static class DefaultRegFormatter implements RefMapFormatter { - - private final Register[] registers; - - public DefaultRegFormatter(Architecture arch) { - registers = new Register[arch.getRegisterReferenceMapSize()]; - for (Register r : arch.getRegisters()) { - if (r.getReferenceMapIndex() >= 0) { - registers[r.getReferenceMapIndex()] = r; - } - } - } - - public String formatStackSlot(int frameRefMapIndex) { - return null; - } - - public String formatRegister(int regRefMapIndex) { - int i = regRefMapIndex; - int idx = 0; - while (registers[i] == null) { - i--; - idx++; - } - if (idx == 0) { - return registers[i].toString(); - } else { - return String.format("%s+%d", registers[i].toString(), idx); - } - } - } - - /** - * Formats a location present in a register or frame reference map. - */ - public static class DefaultRefMapFormatter extends DefaultRegFormatter { - - /** - * The size of a stack slot. - */ - public final int slotSize; - - /** - * The register used as the frame pointer. - */ - public final Register fp; - - /** - * The offset (in bytes) from the slot pointed to by {@link #fp} to the slot corresponding - * to bit 0 in the frame reference map. - */ - public final int refMapToFPOffset; - - public DefaultRefMapFormatter(Architecture arch, int slotSize, Register fp, int refMapToFPOffset) { - super(arch); - this.slotSize = slotSize; - this.fp = fp; - this.refMapToFPOffset = refMapToFPOffset; - } - - @Override - public String formatStackSlot(int frameRefMapIndex) { - int refMapOffset = frameRefMapIndex * slotSize; - int fpOffset = refMapOffset + refMapToFPOffset; - if (fpOffset >= 0) { - return fp + "+" + fpOffset; - } - return fp.name + fpOffset; - } - } - - public static class NumberedRefMapFormatter implements RefMapFormatter { - - public String formatStackSlot(int frameRefMapIndex) { - return "s" + frameRefMapIndex; - } - - public String formatRegister(int regRefMapIndex) { - return "r" + regRefMapIndex; - } - } - - /** - * Appends a formatted debug info to a {@link StringBuilder}. - * - * @param sb the {@link StringBuilder} to append to - * @param info the debug info to format and append to {@code sb} - * @return the value of {@code sb} - */ - public static StringBuilder append(StringBuilder sb, DebugInfo info, RefMapFormatter formatterArg) { - RefMapFormatter formatter = formatterArg; - if (formatter == null) { - formatter = new NumberedRefMapFormatter(); - } - String nl = NEW_LINE; - ReferenceMap refMap = info.getReferenceMap(); - if (refMap != null) { - sb.append(refMap.toString()); - } - RegisterSaveLayout calleeSaveInfo = info.getCalleeSaveInfo(); - if (calleeSaveInfo != null) { - sb.append("callee-save-info:").append(nl); - Map map = calleeSaveInfo.slotsToRegisters(true); - for (Map.Entry e : map.entrySet()) { - sb.append(" ").append(e.getValue()).append(" -> ").append(formatter.formatStackSlot(e.getKey())).append(nl); - } - } - BytecodeFrame frame = info.frame(); - if (frame != null) { - append(sb, frame); - } else if (info.getBytecodePosition() != null) { - append(sb, info.getBytecodePosition()); - } - return sb; - } - - /** - * Create a calling convention from a {@link ResolvedJavaMethod}. - */ - public static CallingConvention getCallingConvention(CodeCacheProvider codeCache, CallingConvention.Type type, ResolvedJavaMethod method, boolean stackOnly) { - Signature sig = method.getSignature(); - JavaType retType = sig.getReturnType(null); - int sigCount = sig.getParameterCount(false); - JavaType[] argTypes; - int argIndex = 0; - if (!method.isStatic()) { - argTypes = new JavaType[sigCount + 1]; - argTypes[argIndex++] = method.getDeclaringClass(); - } else { - argTypes = new JavaType[sigCount]; - } - for (int i = 0; i < sigCount; i++) { - argTypes[argIndex++] = sig.getParameterType(i, null); - } - - RegisterConfig registerConfig = codeCache.getRegisterConfig(); - return registerConfig.getCallingConvention(type, retType, argTypes, codeCache.getTarget(), stackOnly); - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.code/src/com/oracle/jvmci/code/CompilationResult.java --- a/graal/com.oracle.jvmci.code/src/com/oracle/jvmci/code/CompilationResult.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,949 +0,0 @@ -/* - * Copyright (c) 2009, 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.code; - -import static com.oracle.jvmci.meta.MetaUtil.*; -import static java.util.Collections.*; - -import java.util.*; - -import com.oracle.jvmci.meta.Assumptions.Assumption; -import com.oracle.jvmci.meta.*; - -/** - * Represents the output from compiling a method, including the compiled machine code, associated - * data and references, relocation information, deoptimization information, etc. - */ -public class CompilationResult { - - /** - * Represents a code position with associated additional information. - */ - public abstract static class Site { - - /** - * The position (or offset) of this site with respect to the start of the target method. - */ - public final int pcOffset; - - public Site(int pos) { - this.pcOffset = pos; - } - - @Override - public final int hashCode() { - throw new UnsupportedOperationException("hashCode"); - } - - @Override - public String toString() { - return identityHashCodeString(this); - } - - @Override - public abstract boolean equals(Object obj); - } - - /** - * Represents an infopoint with associated debug info. Note that safepoints are also infopoints. - */ - public static class Infopoint extends Site implements Comparable { - - public final DebugInfo debugInfo; - - public final InfopointReason reason; - - public Infopoint(int pcOffset, DebugInfo debugInfo, InfopointReason reason) { - super(pcOffset); - this.debugInfo = debugInfo; - this.reason = reason; - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append(pcOffset); - sb.append("[]"); - appendDebugInfo(sb, debugInfo); - return sb.toString(); - } - - @Override - public int compareTo(Infopoint o) { - if (pcOffset < o.pcOffset) { - return -1; - } else if (pcOffset > o.pcOffset) { - return 1; - } - return this.reason.compareTo(o.reason); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj != null && obj.getClass() == getClass()) { - Infopoint that = (Infopoint) obj; - if (this.pcOffset == that.pcOffset && Objects.equals(this.debugInfo, that.debugInfo) && Objects.equals(this.reason, that.reason)) { - return true; - } - } - return false; - } - } - - /** - * Represents a call in the code. - */ - public static final class Call extends Infopoint { - - /** - * The target of the call. - */ - public final InvokeTarget target; - - /** - * The size of the call instruction. - */ - public final int size; - - /** - * Specifies if this call is direct or indirect. A direct call has an immediate operand - * encoding the absolute or relative (to the call itself) address of the target. An indirect - * call has a register or memory operand specifying the target address of the call. - */ - public final boolean direct; - - public Call(InvokeTarget target, int pcOffset, int size, boolean direct, DebugInfo debugInfo) { - super(pcOffset, debugInfo, InfopointReason.CALL); - this.size = size; - this.target = target; - this.direct = direct; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj instanceof Call && super.equals(obj)) { - Call that = (Call) obj; - if (this.size == that.size && this.direct == that.direct && Objects.equals(this.target, that.target)) { - return true; - } - } - return false; - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append(pcOffset); - sb.append('['); - sb.append(target); - sb.append(']'); - - if (debugInfo != null) { - appendDebugInfo(sb, debugInfo); - } - - return sb.toString(); - } - } - - /** - * Represents some external data that is referenced by the code. - */ - public abstract static class Reference { - - @Override - public abstract int hashCode(); - - @Override - public abstract boolean equals(Object obj); - } - - public static final class ConstantReference extends Reference { - - private final VMConstant constant; - - public ConstantReference(VMConstant constant) { - this.constant = constant; - } - - public VMConstant getConstant() { - return constant; - } - - @Override - public String toString() { - return constant.toString(); - } - - @Override - public int hashCode() { - return constant.hashCode(); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj instanceof ConstantReference) { - ConstantReference that = (ConstantReference) obj; - return Objects.equals(this.constant, that.constant); - } - return false; - } - } - - public static final class DataSectionReference extends Reference { - - private boolean initialized; - private int offset; - - public DataSectionReference() { - // will be set after the data section layout is fixed - offset = 0xDEADDEAD; - } - - public int getOffset() { - assert initialized; - - return offset; - } - - public void setOffset(int offset) { - assert !initialized; - initialized = true; - - this.offset = offset; - } - - @Override - public int hashCode() { - return offset; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj instanceof DataSectionReference) { - DataSectionReference that = (DataSectionReference) obj; - return this.offset == that.offset; - } - return false; - } - } - - /** - * Represents a code site that references some data. The associated data can be either a - * {@link DataSectionReference reference} to the data section, or it may be an inlined - * {@link JavaConstant} that needs to be patched. - */ - public static final class DataPatch extends Site { - - public Reference reference; - - public DataPatch(int pcOffset, Reference reference) { - super(pcOffset); - this.reference = reference; - } - - @Override - public String toString() { - return String.format("%d[]", pcOffset, reference.toString()); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj instanceof DataPatch) { - DataPatch that = (DataPatch) obj; - if (this.pcOffset == that.pcOffset && Objects.equals(this.reference, that.reference)) { - return true; - } - } - return false; - } - } - - /** - * Provides extra information about instructions or data at specific positions in - * {@link CompilationResult#getTargetCode()}. This is optional information that can be used to - * enhance a disassembly of the code. - */ - public abstract static class CodeAnnotation { - - public final int position; - - public CodeAnnotation(int position) { - this.position = position; - } - - @Override - public final int hashCode() { - throw new UnsupportedOperationException("hashCode"); - } - - @Override - public String toString() { - return identityHashCodeString(this); - } - - @Override - public abstract boolean equals(Object obj); - } - - /** - * A string comment about one or more instructions at a specific position in the code. - */ - public static final class CodeComment extends CodeAnnotation { - - public final String value; - - public CodeComment(int position, String comment) { - super(position); - this.value = comment; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj instanceof CodeComment) { - CodeComment that = (CodeComment) obj; - if (this.position == that.position && this.value.equals(that.value)) { - return true; - } - } - return false; - } - - @Override - public String toString() { - return getClass().getSimpleName() + "@" + position + ": " + value; - } - } - - /** - * Describes a table of signed offsets embedded in the code. The offsets are relative to the - * starting address of the table. This type of table maybe generated when translating a - * multi-way branch based on a key value from a dense value set (e.g. the {@code tableswitch} - * JVM instruction). - * - * The table is indexed by the contiguous range of integers from {@link #low} to {@link #high} - * inclusive. - */ - public static final class JumpTable extends CodeAnnotation { - - /** - * The low value in the key range (inclusive). - */ - public final int low; - - /** - * The high value in the key range (inclusive). - */ - public final int high; - - /** - * The size (in bytes) of each table entry. - */ - public final int entrySize; - - public JumpTable(int position, int low, int high, int entrySize) { - super(position); - this.low = low; - this.high = high; - this.entrySize = entrySize; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj instanceof JumpTable) { - JumpTable that = (JumpTable) obj; - if (this.position == that.position && this.entrySize == that.entrySize && this.low == that.low && this.high == that.high) { - return true; - } - } - return false; - } - - @Override - public String toString() { - return getClass().getSimpleName() + "@" + position + ": [" + low + " .. " + high + "]"; - } - } - - /** - * Represents exception handler information for a specific code position. It includes the catch - * code position as well as the caught exception type. - */ - public static final class ExceptionHandler extends Site { - - public final int handlerPos; - - ExceptionHandler(int pcOffset, int handlerPos) { - super(pcOffset); - this.handlerPos = handlerPos; - } - - @Override - public String toString() { - return String.format("%d[]", pcOffset, handlerPos); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj instanceof ExceptionHandler) { - ExceptionHandler that = (ExceptionHandler) obj; - if (this.pcOffset == that.pcOffset && this.handlerPos == that.handlerPos) { - return true; - } - } - return false; - } - } - - /** - * Represents a mark in the machine code that can be used by the runtime for its own purposes. A - * mark can reference other marks. - */ - public static final class Mark extends Site { - - public final Object id; - - public Mark(int pcOffset, Object id) { - super(pcOffset); - this.id = id; - } - - @Override - public String toString() { - if (id == null) { - return String.format("%d[]", pcOffset); - } else if (id instanceof Integer) { - return String.format("%d[]", pcOffset, Integer.toHexString((Integer) id)); - } else { - return String.format("%d[]", pcOffset, id.toString()); - } - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj instanceof Mark) { - Mark that = (Mark) obj; - if (this.pcOffset == that.pcOffset && Objects.equals(this.id, that.id)) { - return true; - } - } - return false; - } - } - - private int id = -1; - private int entryBCI = -1; - - private final DataSection dataSection = new DataSection(); - - private final List infopoints = new ArrayList<>(); - private final List dataPatches = new ArrayList<>(); - private final List exceptionHandlers = new ArrayList<>(); - private final List marks = new ArrayList<>(); - - private int totalFrameSize = -1; - private int customStackAreaOffset = -1; - - private final String name; - - /** - * The buffer containing the emitted machine code. - */ - private byte[] targetCode; - - /** - * The leading number of bytes in {@link #targetCode} containing the emitted machine code. - */ - private int targetCodeSize; - - private ArrayList annotations; - - private Assumption[] assumptions; - - /** - * The list of the methods whose bytecodes were used as input to the compilation. If - * {@code null}, then the compilation did not record method dependencies. Otherwise, the first - * element of this array is the root method of the compilation. - */ - private ResolvedJavaMethod[] methods; - - private int bytecodeSize; - - public CompilationResult() { - this(null); - } - - public CompilationResult(String name) { - this.name = name; - } - - @Override - public int hashCode() { - // CompilationResult instances should not be used as hash map keys - throw new UnsupportedOperationException("hashCode"); - } - - @Override - public String toString() { - if (methods != null) { - return getClass().getName() + "[" + methods[0].format("%H.%n(%p)%r") + "]"; - } - return identityHashCodeString(this); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj != null && obj.getClass() == getClass()) { - CompilationResult that = (CompilationResult) obj; - // @formatter:off - if (this.entryBCI == that.entryBCI && - this.id == that.id && - this.customStackAreaOffset == that.customStackAreaOffset && - this.totalFrameSize == that.totalFrameSize && - this.targetCodeSize == that.targetCodeSize && - Objects.equals(this.name, that.name) && - Objects.equals(this.annotations, that.annotations) && - Objects.equals(this.dataSection, that.dataSection) && - Objects.equals(this.exceptionHandlers, that.exceptionHandlers) && - Objects.equals(this.dataPatches, that.dataPatches) && - Objects.equals(this.infopoints, that.infopoints) && - Objects.equals(this.marks, that.marks) && - Arrays.equals(this.assumptions, that.assumptions) && - Arrays.equals(targetCode, that.targetCode)) { - return true; - } - // @formatter:on - } - return false; - } - - /** - * @return the compile id - */ - public int getId() { - return id; - } - - /** - * @param id the compile id to set - */ - public void setId(int id) { - this.id = id; - } - - /** - * @return the entryBCI - */ - public int getEntryBCI() { - return entryBCI; - } - - /** - * @param entryBCI the entryBCI to set - */ - public void setEntryBCI(int entryBCI) { - this.entryBCI = entryBCI; - } - - /** - * Sets the assumptions made during compilation. - */ - public void setAssumptions(Assumption[] assumptions) { - this.assumptions = assumptions; - } - - /** - * Gets the assumptions made during compilation. - */ - public Assumption[] getAssumptions() { - return assumptions; - } - - /** - * Sets the methods whose bytecodes were used as input to the compilation. - * - * @param rootMethod the root method of the compilation - * @param inlinedMethods the methods inlined during compilation - */ - public void setMethods(ResolvedJavaMethod rootMethod, Collection inlinedMethods) { - assert rootMethod != null; - assert inlinedMethods != null; - if (inlinedMethods.contains(rootMethod)) { - methods = inlinedMethods.toArray(new ResolvedJavaMethod[inlinedMethods.size()]); - for (int i = 0; i < methods.length; i++) { - if (methods[i].equals(rootMethod)) { - if (i != 0) { - ResolvedJavaMethod tmp = methods[0]; - methods[0] = methods[i]; - methods[i] = tmp; - } - break; - } - } - } else { - methods = new ResolvedJavaMethod[1 + inlinedMethods.size()]; - methods[0] = rootMethod; - int i = 1; - for (ResolvedJavaMethod m : inlinedMethods) { - methods[i++] = m; - } - } - } - - /** - * Gets the methods whose bytecodes were used as input to the compilation. - * - * @return {@code null} if the compilation did not record method dependencies otherwise the - * methods whose bytecodes were used as input to the compilation with the first element - * being the root method of the compilation - */ - public ResolvedJavaMethod[] getMethods() { - return methods; - } - - public void setBytecodeSize(int bytecodeSize) { - this.bytecodeSize = bytecodeSize; - } - - public int getBytecodeSize() { - return bytecodeSize; - } - - public DataSection getDataSection() { - return dataSection; - } - - /** - * The total frame size of the method in bytes. This includes the return address pushed onto the - * stack, if any. - * - * @return the frame size - */ - public int getTotalFrameSize() { - assert totalFrameSize != -1 : "frame size not yet initialized!"; - return totalFrameSize; - } - - /** - * Sets the total frame size in bytes. This includes the return address pushed onto the stack, - * if any. - * - * @param size the size of the frame in bytes - */ - public void setTotalFrameSize(int size) { - totalFrameSize = size; - } - - /** - * Sets the machine that has been generated by the compiler. - * - * @param code the machine code generated - * @param size the size of the machine code - */ - public void setTargetCode(byte[] code, int size) { - targetCode = code; - targetCodeSize = size; - } - - /** - * Records a data patch in the code section. The data patch can refer to something in the - * {@link DataSectionReference data section} or directly to an {@link ConstantReference inlined - * constant}. - * - * @param codePos The position in the code that needs to be patched. - * @param ref The reference that should be inserted in the code. - */ - public void recordDataPatch(int codePos, Reference ref) { - assert codePos >= 0 && ref != null; - dataPatches.add(new DataPatch(codePos, ref)); - } - - /** - * Records a call in the code array. - * - * @param codePos the position of the call in the code array - * @param size the size of the call instruction - * @param target the being called - * @param debugInfo the debug info for the call - * @param direct specifies if this is a {@linkplain Call#direct direct} call - */ - public void recordCall(int codePos, int size, InvokeTarget target, DebugInfo debugInfo, boolean direct) { - final Call call = new Call(target, codePos, size, direct, debugInfo); - addInfopoint(call); - } - - /** - * Records an exception handler for this method. - * - * @param codePos the position in the code that is covered by the handler - * @param handlerPos the position of the handler - */ - public void recordExceptionHandler(int codePos, int handlerPos) { - assert validateExceptionHandlerAdd(codePos, handlerPos) : String.format("Duplicate exception handler for pc 0x%x handlerPos 0x%x", codePos, handlerPos); - exceptionHandlers.add(new ExceptionHandler(codePos, handlerPos)); - } - - /** - * Validate if the exception handler for codePos already exists and handlerPos is different. - * - * @param codePos - * @param handlerPos - * @return true if the validation is successful - */ - private boolean validateExceptionHandlerAdd(int codePos, int handlerPos) { - ExceptionHandler exHandler = getExceptionHandlerForCodePos(codePos); - return exHandler == null || exHandler.handlerPos == handlerPos; - } - - /** - * Returns the first ExceptionHandler which matches codePos. - * - * @param codePos position to search for - * @return first matching ExceptionHandler - */ - private ExceptionHandler getExceptionHandlerForCodePos(int codePos) { - for (ExceptionHandler h : exceptionHandlers) { - if (h.pcOffset == codePos) { - return h; - } - } - return null; - } - - /** - * Records an infopoint in the code array. - * - * @param codePos the position of the infopoint in the code array - * @param debugInfo the debug info for the infopoint - */ - public void recordInfopoint(int codePos, DebugInfo debugInfo, InfopointReason reason) { - addInfopoint(new Infopoint(codePos, debugInfo, reason)); - } - - /** - * Records a custom infopoint in the code section. - * - * Compiler implementations can use this method to record non-standard infopoints, which are not - * handled by the dedicated methods like {@link #recordCall}. - * - * @param infopoint the infopoint to record, usually a derived class from {@link Infopoint} - */ - public void addInfopoint(Infopoint infopoint) { - // The infopoints list must always be sorted - if (!infopoints.isEmpty()) { - Infopoint previousInfopoint = infopoints.get(infopoints.size() - 1); - if (previousInfopoint.pcOffset > infopoint.pcOffset) { - // This re-sorting should be very rare - Collections.sort(infopoints); - previousInfopoint = infopoints.get(infopoints.size() - 1); - } - if (previousInfopoint.pcOffset == infopoint.pcOffset) { - if (infopoint.reason.canBeOmitted()) { - return; - } - if (previousInfopoint.reason.canBeOmitted()) { - Infopoint removed = infopoints.remove(infopoints.size() - 1); - assert removed == previousInfopoint; - } else { - throw new RuntimeException("Infopoints that can not be omited should have distinct PCs"); - } - } - } - infopoints.add(infopoint); - } - - /** - * Records an instruction mark within this method. - * - * @param codePos the position in the code that is covered by the handler - * @param markId the identifier for this mark - */ - public Mark recordMark(int codePos, Object markId) { - Mark mark = new Mark(codePos, markId); - marks.add(mark); - return mark; - } - - /** - * Offset in bytes for the custom stack area (relative to sp). - * - * @return the offset in bytes - */ - public int getCustomStackAreaOffset() { - return customStackAreaOffset; - } - - /** - * @see #getCustomStackAreaOffset() - * @param offset - */ - public void setCustomStackAreaOffset(int offset) { - customStackAreaOffset = offset; - } - - /** - * @return the machine code generated for this method - */ - public byte[] getTargetCode() { - return targetCode; - } - - /** - * @return the size of the machine code generated for this method - */ - public int getTargetCodeSize() { - return targetCodeSize; - } - - /** - * @return the code annotations or {@code null} if there are none - */ - public List getAnnotations() { - if (annotations == null) { - return Collections.emptyList(); - } - return annotations; - } - - public void addAnnotation(CodeAnnotation annotation) { - assert annotation != null; - if (annotations == null) { - annotations = new ArrayList<>(); - } - annotations.add(annotation); - } - - private static void appendDebugInfo(StringBuilder sb, DebugInfo info) { - if (info != null) { - ReferenceMap refMap = info.getReferenceMap(); - if (refMap != null) { - sb.append(refMap.toString()); - sb.append(']'); - } - RegisterSaveLayout calleeSaveInfo = info.getCalleeSaveInfo(); - if (calleeSaveInfo != null) { - sb.append(" callee-save-info["); - String sep = ""; - for (Map.Entry e : calleeSaveInfo.registersToSlots(true).entrySet()) { - sb.append(sep).append(e.getKey()).append("->").append(e.getValue()); - sep = ", "; - } - sb.append(']'); - } - BytecodePosition codePos = info.getBytecodePosition(); - if (codePos != null) { - MetaUtil.appendLocation(sb.append(" "), codePos.getMethod(), codePos.getBCI()); - if (info.hasFrame()) { - sb.append(" #locals=").append(info.frame().numLocals).append(" #expr=").append(info.frame().numStack); - if (info.frame().numLocks > 0) { - sb.append(" #locks=").append(info.frame().numLocks); - } - } - } - } - } - - /** - * @return the list of infopoints, sorted by {@link Site#pcOffset} - */ - public List getInfopoints() { - if (infopoints.isEmpty()) { - return emptyList(); - } - return unmodifiableList(infopoints); - } - - /** - * @return the list of data references - */ - public List getDataPatches() { - if (dataPatches.isEmpty()) { - return emptyList(); - } - return unmodifiableList(dataPatches); - } - - /** - * @return the list of exception handlers - */ - public List getExceptionHandlers() { - if (exceptionHandlers.isEmpty()) { - return emptyList(); - } - return unmodifiableList(exceptionHandlers); - } - - /** - * @return the list of marks - */ - public List getMarks() { - if (marks.isEmpty()) { - return emptyList(); - } - return unmodifiableList(marks); - } - - public String getName() { - return name; - } - - public void reset() { - infopoints.clear(); - dataPatches.clear(); - exceptionHandlers.clear(); - marks.clear(); - if (annotations != null) { - annotations.clear(); - } - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.code/src/com/oracle/jvmci/code/DataSection.java --- a/graal/com.oracle.jvmci.code/src/com/oracle/jvmci/code/DataSection.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,278 +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.code; - -import com.oracle.jvmci.meta.SerializableConstant; -import static com.oracle.jvmci.meta.MetaUtil.*; - -import java.nio.*; -import java.util.*; -import java.util.function.*; - -import com.oracle.jvmci.code.CompilationResult.DataPatch; -import com.oracle.jvmci.code.CompilationResult.DataSectionReference; -import com.oracle.jvmci.code.DataSection.Data; - -public final class DataSection implements Iterable { - - @FunctionalInterface - public interface DataBuilder { - - void emit(ByteBuffer buffer, Consumer patch); - - static DataBuilder raw(byte[] data) { - return (buffer, patch) -> buffer.put(data); - } - - static DataBuilder serializable(SerializableConstant c) { - return (buffer, patch) -> c.serialize(buffer); - } - - static DataBuilder zero(int size) { - switch (size) { - case 1: - return (buffer, patch) -> buffer.put((byte) 0); - case 2: - return (buffer, patch) -> buffer.putShort((short) 0); - case 4: - return (buffer, patch) -> buffer.putInt(0); - case 8: - return (buffer, patch) -> buffer.putLong(0L); - default: - return (buffer, patch) -> { - int rest = size; - while (rest > 8) { - buffer.putLong(0L); - rest -= 8; - } - while (rest > 0) { - buffer.put((byte) 0); - rest--; - } - }; - } - } - } - - public static final class Data { - - private int alignment; - private final int size; - private final DataBuilder builder; - - private DataSectionReference ref; - - public Data(int alignment, int size, DataBuilder builder) { - this.alignment = alignment; - this.size = size; - this.builder = builder; - - // initialized in DataSection.insertData(Data) - ref = null; - } - - public void updateAlignment(int newAlignment) { - if (newAlignment == alignment) { - return; - } - alignment = lcm(alignment, newAlignment); - } - - public int getAlignment() { - return alignment; - } - - public int getSize() { - return size; - } - - public DataBuilder getBuilder() { - return builder; - } - - @Override - public int hashCode() { - // Data instances should not be used as hash map keys - throw new UnsupportedOperationException("hashCode"); - } - - @Override - public String toString() { - return identityHashCodeString(this); - } - - @Override - public boolean equals(Object obj) { - assert ref != null; - if (obj == this) { - return true; - } - if (obj instanceof Data) { - Data that = (Data) obj; - if (this.alignment == that.alignment && this.size == that.size && this.ref.equals(that.ref)) { - return true; - } - } - return false; - } - } - - private final ArrayList dataItems = new ArrayList<>(); - - private boolean finalLayout; - private int sectionAlignment; - private int sectionSize; - - @Override - public int hashCode() { - // DataSection instances should not be used as hash map keys - throw new UnsupportedOperationException("hashCode"); - } - - @Override - public String toString() { - return identityHashCodeString(this); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj instanceof DataSection) { - DataSection that = (DataSection) obj; - if (this.finalLayout == that.finalLayout && this.sectionAlignment == that.sectionAlignment && this.sectionSize == that.sectionSize && Objects.equals(this.dataItems, that.dataItems)) { - return true; - } - } - return false; - } - - /** - * Insert a {@link Data} item into the data section. If the item is already in the data section, - * the same {@link DataSectionReference} is returned. - * - * @param data the {@link Data} item to be inserted - * @return a unique {@link DataSectionReference} identifying the {@link Data} item - */ - public DataSectionReference insertData(Data data) { - assert !finalLayout; - if (data.ref == null) { - data.ref = new DataSectionReference(); - dataItems.add(data); - } - return data.ref; - } - - /** - * Compute the layout of the data section. This can be called only once, and after it has been - * called, the data section can no longer be modified. - */ - public void finalizeLayout() { - assert !finalLayout; - finalLayout = true; - - // simple heuristic: put items with larger alignment requirement first - dataItems.sort((a, b) -> a.alignment - b.alignment); - - int position = 0; - for (Data d : dataItems) { - sectionAlignment = lcm(sectionAlignment, d.alignment); - position = align(position, d.alignment); - - d.ref.setOffset(position); - position += d.size; - } - - sectionSize = position; - } - - /** - * Get the size of the data section. Can only be called after {@link #finalizeLayout}. - */ - public int getSectionSize() { - assert finalLayout; - return sectionSize; - } - - /** - * Get the minimum alignment requirement of the data section. Can only be called after - * {@link #finalizeLayout}. - */ - public int getSectionAlignment() { - assert finalLayout; - return sectionAlignment; - } - - /** - * Build the data section. Can only be called after {@link #finalizeLayout}. - * - * @param buffer The {@link ByteBuffer} where the data section should be built. The buffer must - * hold at least {@link #getSectionSize()} bytes. - * @param patch A {@link Consumer} to receive {@link DataPatch data patches} for relocations in - * the data section. - */ - public void buildDataSection(ByteBuffer buffer, Consumer patch) { - assert finalLayout; - for (Data d : dataItems) { - buffer.position(d.ref.getOffset()); - d.builder.emit(buffer, patch); - } - } - - public Data findData(DataSectionReference ref) { - for (Data d : dataItems) { - if (d.ref == ref) { - return d; - } - } - return null; - } - - public Iterator iterator() { - return dataItems.iterator(); - } - - private static int lcm(int x, int y) { - if (x == 0) { - return y; - } else if (y == 0) { - return x; - } - - int a = Math.max(x, y); - int b = Math.min(x, y); - while (b > 0) { - int tmp = a % b; - a = b; - b = tmp; - } - - int gcd = a; - return x * y / gcd; - } - - private static int align(int position, int alignment) { - return ((position + alignment - 1) / alignment) * alignment; - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.code/src/com/oracle/jvmci/code/DebugInfo.java --- a/graal/com.oracle.jvmci.code/src/com/oracle/jvmci/code/DebugInfo.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,136 +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.code; - -import com.oracle.jvmci.meta.Value; -import java.util.*; - -/** - * Represents the debugging information for a particular point of execution. This information - * includes: - *
    - *
  • a {@linkplain #getBytecodePosition() bytecode position}
  • - *
  • a reference map for registers and stack slots in the current frame
  • - *
  • a map from bytecode locals and operand stack slots to their values or locations from which - * their values can be read
  • - *
  • a map from the registers (in the caller's frame) to the slots where they are saved in the - * current frame
  • - *
- */ -public final class DebugInfo { - - private final BytecodePosition bytecodePosition; - private final ReferenceMap referenceMap; - @SuppressWarnings("unused") private final Value[] virtualObjectMapping; - private RegisterSaveLayout calleeSaveInfo; - - /** - * Creates a new {@link DebugInfo} from the given values. - * - * @param codePos the {@linkplain BytecodePosition code position} or {@linkplain BytecodeFrame - * frame} info - * @param referenceMap the reference map - * @param virtualObjectMapping the mapping of {@link VirtualObject}s to their real values - */ - public DebugInfo(BytecodePosition codePos, ReferenceMap referenceMap, Value[] virtualObjectMapping) { - this.bytecodePosition = codePos; - this.referenceMap = referenceMap; - this.virtualObjectMapping = virtualObjectMapping; - } - - public DebugInfo(BytecodePosition codePos) { - this(codePos, null, null); - } - - /** - * @return {@code true} if this debug information has a frame - */ - public boolean hasFrame() { - return getBytecodePosition() instanceof BytecodeFrame; - } - - /** - * Gets the deoptimization information for each inlined frame (if available). - * - * @return {@code null} if no frame de-opt info is {@linkplain #hasFrame() available} - */ - public BytecodeFrame frame() { - if (hasFrame()) { - return (BytecodeFrame) getBytecodePosition(); - } - return null; - } - - @Override - public String toString() { - return CodeUtil.append(new StringBuilder(100), this, null).toString(); - } - - /** - * @return The code position (including all inlined methods) of this debug info. If this is a - * {@link BytecodeFrame} instance, then it is also the deoptimization information for - * each inlined frame. - */ - public BytecodePosition getBytecodePosition() { - return bytecodePosition; - } - - public ReferenceMap getReferenceMap() { - return referenceMap; - } - - /** - * Sets the map from the registers (in the caller's frame) to the slots where they are saved in - * the current frame. - */ - public void setCalleeSaveInfo(RegisterSaveLayout calleeSaveInfo) { - this.calleeSaveInfo = calleeSaveInfo; - } - - /** - * Gets the map from the registers (in the caller's frame) to the slots where they are saved in - * the current frame. If no such information is available, {@code null} is returned. - */ - public RegisterSaveLayout getCalleeSaveInfo() { - return calleeSaveInfo; - } - - @Override - public int hashCode() { - throw new UnsupportedOperationException("hashCode"); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj instanceof DebugInfo) { - DebugInfo that = (DebugInfo) obj; - if (Objects.equals(this.bytecodePosition, that.bytecodePosition) && Objects.equals(this.calleeSaveInfo, that.calleeSaveInfo) && Objects.equals(this.referenceMap, that.referenceMap)) { - return true; - } - } - return false; - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.code/src/com/oracle/jvmci/code/ForeignCallLinkage.java --- a/graal/com.oracle.jvmci.code/src/com/oracle/jvmci/code/ForeignCallLinkage.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,74 +0,0 @@ -/* - * Copyright (c) 2009, 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.code; - -import com.oracle.jvmci.meta.InvokeTarget; -import com.oracle.jvmci.meta.Value; -import com.oracle.jvmci.meta.ForeignCallDescriptor; - -/** - * The runtime specific details of a {@linkplain ForeignCallDescriptor foreign} call. - */ -public interface ForeignCallLinkage extends InvokeTarget { - - /** - * Gets the details of where parameters are passed and value(s) are returned from the caller's - * perspective. - */ - CallingConvention getOutgoingCallingConvention(); - - /** - * Gets the details of where parameters are passed and value(s) are returned from the callee's - * perspective. - */ - CallingConvention getIncomingCallingConvention(); - - /** - * Returns the maximum absolute offset of PC relative call to this stub from any position in the - * code cache or -1 when not applicable. Intended for determining the required size of - * address/offset fields. - */ - long getMaxCallTargetOffset(); - - ForeignCallDescriptor getDescriptor(); - - /** - * Gets the values used/killed by this foreign call. - */ - Value[] getTemporaries(); - - /** - * Determines if the foreign call target destroys all registers. - * - * @return {@code true} if the register allocator must save all live registers around a call to - * this target - */ - boolean destroysRegisters(); - - /** - * Determines if this is call to a function that does not deoptimize, and therefore also does - * not lock, GC or throw exceptions. That is, the thread's execution state during the call is - * never inspected by another thread. - */ - boolean canDeoptimize(); -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.code/src/com/oracle/jvmci/code/ForeignCallsProvider.java --- a/graal/com.oracle.jvmci.code/src/com/oracle/jvmci/code/ForeignCallsProvider.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,55 +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; - -import com.oracle.jvmci.meta.LocationIdentity; -import com.oracle.jvmci.meta.ForeignCallDescriptor; - -/** - * Details about a set of supported {@link ForeignCallDescriptor foreign calls}. - */ -public interface ForeignCallsProvider { - - /** - * Determines if a given foreign call is side-effect free. Deoptimization cannot return - * execution to a point before a foreign call that has a side effect. - */ - boolean isReexecutable(ForeignCallDescriptor descriptor); - - /** - * Gets the set of memory locations killed by a given foreign call. Returning the special value - * {@link LocationIdentity#any()} denotes that the call kills all memory locations. Returning - * any empty array denotes that the call does not kill any memory locations. - */ - LocationIdentity[] getKilledLocations(ForeignCallDescriptor descriptor); - - /** - * Determines if deoptimization can occur during a given foreign call. - */ - boolean canDeoptimize(ForeignCallDescriptor descriptor); - - /** - * Gets the linkage for a foreign call. - */ - ForeignCallLinkage lookupForeignCall(ForeignCallDescriptor descriptor); -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.code/src/com/oracle/jvmci/code/InfopointReason.java --- a/graal/com.oracle.jvmci.code/src/com/oracle/jvmci/code/InfopointReason.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,46 +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; - -/** - * A reason for infopoint insertion. - */ -public enum InfopointReason { - UNKNOWN(false), - SAFEPOINT(false), - CALL(false), - IMPLICIT_EXCEPTION(false), - METHOD_START(true), - METHOD_END(true), - LINE_NUMBER(true); - - private InfopointReason(boolean canBeOmitted) { - this.canBeOmitted = canBeOmitted; - } - - private final boolean canBeOmitted; - - public boolean canBeOmitted() { - return canBeOmitted; - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.code/src/com/oracle/jvmci/code/InstalledCode.java --- a/graal/com.oracle.jvmci.code/src/com/oracle/jvmci/code/InstalledCode.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,121 +0,0 @@ -/* - * Copyright (c) 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.code; - -/** - * Represents a compiled instance of a method. It may have been invalidated or removed in the - * meantime. - */ -public class InstalledCode { - - /** - * Raw address of this code blob. - */ - private long address; - - /** - * Counts how often the address field was reassigned. - */ - private long version; - - protected final String name; - - public InstalledCode(String name) { - this.name = name; - } - - public final void setAddress(long address) { - this.address = address; - version++; - } - - /** - * @return the address of this code blob - */ - public final long getAddress() { - return address; - } - - /** - * @return the address of this code blob - */ - public final long getVersion() { - return version; - } - - /** - * Returns the name of this code blob. - */ - public String getName() { - return name; - } - - /** - * Returns the start address of this installed code if it is {@linkplain #isValid() valid}, 0 - * otherwise. - */ - public long getStart() { - return 0; - } - - /** - * Returns the number of instruction bytes for this code. - */ - public long getCodeSize() { - return 0; - } - - /** - * Returns a copy of this installed code if it is {@linkplain #isValid() valid}, null otherwise. - */ - public byte[] getCode() { - return null; - } - - /** - * @return true if the code represented by this object is still valid, false otherwise (may - * happen due to deopt, etc.) - */ - public boolean isValid() { - return address != 0; - } - - /** - * Invalidates this installed code such that any subsequent invocation will throw an - * {@link InvalidInstalledCodeException}. - */ - public void invalidate() { - throw new UnsupportedOperationException(); - } - - /** - * Executes the installed code with a variable number of arguments. - * - * @param args the array of object arguments - * @return the value returned by the executed code - */ - @SuppressWarnings("unused") - public Object executeVarargs(Object... args) throws InvalidInstalledCodeException { - throw new UnsupportedOperationException(); - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.code/src/com/oracle/jvmci/code/InvalidInstalledCodeException.java --- a/graal/com.oracle.jvmci.code/src/com/oracle/jvmci/code/InvalidInstalledCodeException.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,31 +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; - -/** - * Exception thrown by the runtime in case an invalidated machine code is called. - */ -public final class InvalidInstalledCodeException extends Exception { - - private static final long serialVersionUID = -3540232440794244844L; -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.code/src/com/oracle/jvmci/code/MemoryBarriers.java --- a/graal/com.oracle.jvmci.code/src/com/oracle/jvmci/code/MemoryBarriers.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,121 +0,0 @@ -/* - * Copyright (c) 2011, 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.code; - -/** - * Constants and intrinsic definition for memory barriers. - * - * The documentation for each constant is taken from Doug Lea's The JSR-133 Cookbook for Compiler - * Writers. - *

- * The {@code JMM_*} constants capture the memory barriers necessary to implement the Java Memory - * Model with respect to volatile field accesses. Their values are explained by this comment from - * templateTable_i486.cpp in the HotSpot source code: - * - *

- * Volatile variables demand their effects be made known to all CPU's in
- * order.  Store buffers on most chips allow reads & writes to reorder; the
- * JMM's ReadAfterWrite.java test fails in -Xint mode without some kind of
- * memory barrier (i.e., it's not sufficient that the interpreter does not
- * reorder volatile references, the hardware also must not reorder them).
- *
- * According to the new Java Memory Model (JMM):
- * (1) All volatiles are serialized wrt to each other.
- * ALSO reads & writes act as acquire & release, so:
- * (2) A read cannot let unrelated NON-volatile memory refs that happen after
- * the read float up to before the read.  It's OK for non-volatile memory refs
- * that happen before the volatile read to float down below it.
- * (3) Similarly, a volatile write cannot let unrelated NON-volatile memory refs
- * that happen BEFORE the write float down to after the write.  It's OK for
- * non-volatile memory refs that happen after the volatile write to float up
- * before it.
- *
- * We only put in barriers around volatile refs (they are expensive), not
- * _between_ memory refs (which would require us to track the flavor of the
- * previous memory refs).  Requirements (2) and (3) require some barriers
- * before volatile stores and after volatile loads.  These nearly cover
- * requirement (1) but miss the volatile-store-volatile-load case.  This final
- * case is placed after volatile-stores although it could just as well go
- * before volatile-loads.
- * 
- */ -public class MemoryBarriers { - - /** - * The sequence {@code Load1; LoadLoad; Load2} ensures that {@code Load1}'s data are loaded - * before data accessed by {@code Load2} and all subsequent load instructions are loaded. In - * general, explicit {@code LoadLoad} barriers are needed on processors that perform speculative - * loads and/or out-of-order processing in which waiting load instructions can bypass waiting - * stores. On processors that guarantee to always preserve load ordering, these barriers amount - * to no-ops. - */ - public static final int LOAD_LOAD = 0x0001; - - /** - * The sequence {@code Load1; LoadStore; Store2} ensures that {@code Load1}'s data are loaded - * before all data associated with {@code Store2} and subsequent store instructions are flushed. - * {@code LoadStore} barriers are needed only on those out-of-order processors in which waiting - * store instructions can bypass loads. - */ - public static final int LOAD_STORE = 0x0002; - - /** - * The sequence {@code Store1; StoreLoad; Load2} ensures that {@code Store1}'s data are made - * visible to other processors (i.e., flushed to main memory) before data accessed by - * {@code Load2} and all subsequent load instructions are loaded. {@code StoreLoad} barriers - * protect against a subsequent load incorrectly using {@code Store1}'s data value rather than - * that from a more recent store to the same location performed by a different processor. - * Because of this, on the processors discussed below, a {@code StoreLoad} is strictly necessary - * only for separating stores from subsequent loads of the same location(s) as were stored - * before the barrier. {@code StoreLoad} barriers are needed on nearly all recent - * multiprocessors, and are usually the most expensive kind. Part of the reason they are - * expensive is that they must disable mechanisms that ordinarily bypass cache to satisfy loads - * from write-buffers. This might be implemented by letting the buffer fully flush, among other - * possible stalls. - */ - public static final int STORE_LOAD = 0x0004; - - /** - * The sequence {@code Store1; StoreStore; Store2} ensures that {@code Store1}'s data are - * visible to other processors (i.e., flushed to memory) before the data associated with - * {@code Store2} and all subsequent store instructions. In general, {@code StoreStore} barriers - * are needed on processors that do not otherwise guarantee strict ordering of flushes from - * write buffers and/or caches to other processors or main memory. - */ - public static final int STORE_STORE = 0x0008; - - public static final int JMM_PRE_VOLATILE_WRITE = LOAD_STORE | STORE_STORE; - public static final int JMM_POST_VOLATILE_WRITE = STORE_LOAD | STORE_STORE; - public static final int JMM_PRE_VOLATILE_READ = 0; - public static final int JMM_POST_VOLATILE_READ = LOAD_LOAD | LOAD_STORE; - - public static String barriersString(int barriers) { - StringBuilder sb = new StringBuilder(); - sb.append((barriers & LOAD_LOAD) != 0 ? "LOAD_LOAD " : ""); - sb.append((barriers & LOAD_STORE) != 0 ? "LOAD_STORE " : ""); - sb.append((barriers & STORE_LOAD) != 0 ? "STORE_LOAD " : ""); - sb.append((barriers & STORE_STORE) != 0 ? "STORE_STORE " : ""); - return sb.toString().trim(); - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.code/src/com/oracle/jvmci/code/ReferenceMap.java --- a/graal/com.oracle.jvmci.code/src/com/oracle/jvmci/code/ReferenceMap.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2009, 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.code; - -import com.oracle.jvmci.meta.*; - -public abstract class ReferenceMap { - - /** - * Empty out the reference map. - */ - public abstract void reset(); - - /** - * Add {@code value} to the current set of reference values. - * - * @param v - */ - public abstract void addLiveValue(Value v); - - /** - * Perform any final encoding needed before use. - */ - public abstract void finish(); -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.code/src/com/oracle/jvmci/code/Register.java --- a/graal/com.oracle.jvmci.code/src/com/oracle/jvmci/code/Register.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,241 +0,0 @@ -/* - * Copyright (c) 2009, 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.code; - -import com.oracle.jvmci.meta.*; - -/** - * Represents a target machine register. - */ -public final class Register implements Comparable { - - public static final RegisterCategory SPECIAL = new RegisterCategory("SPECIAL"); - - /** - * Invalid register. - */ - public static final Register None = new Register(-1, -1, "noreg", SPECIAL); - - /** - * Frame pointer of the current method. All spill slots and outgoing stack-based arguments are - * addressed relative to this register. - */ - public static final Register Frame = new Register(-2, -2, "framereg", SPECIAL); - - public static final Register CallerFrame = new Register(-3, -3, "callerframereg", SPECIAL); - - /** - * The identifier for this register that is unique across all the registers in a - * {@link Architecture}. A valid register has {@code number > 0}. - */ - public final int number; - - /** - * The mnemonic of this register. - */ - public final String name; - - /** - * The actual encoding in a target machine instruction for this register, which may or may not - * be the same as {@link #number}. - */ - public final int encoding; - - /** - * The assembler calls this method to get the register's encoding. - */ - public int encoding() { - return encoding; - } - - /** - * A platform specific register category that describes which values can be stored in a - * register. - */ - private final RegisterCategory registerCategory; - - /** - * A platform specific register type that describes which values can be stored in a register. - */ - public static class RegisterCategory { - - private final String name; - - private final int referenceMapOffset; - private final int referenceMapShift; - - public RegisterCategory(String name) { - this(name, 0, 0); - } - - public RegisterCategory(String name, int referenceMapOffset) { - this(name, referenceMapOffset, 0); - } - - public RegisterCategory(String name, int referenceMapOffset, int referenceMapShift) { - this.name = name; - this.referenceMapOffset = referenceMapOffset; - this.referenceMapShift = referenceMapShift; - } - - @Override - public String toString() { - return name; - } - - @Override - public int hashCode() { - return 23 + name.hashCode(); - } - - @Override - public boolean equals(Object obj) { - if (obj instanceof RegisterCategory) { - RegisterCategory that = (RegisterCategory) obj; - return this.referenceMapOffset == that.referenceMapOffset && this.referenceMapShift == that.referenceMapShift && this.name.equals(that.name); - } - return false; - } - } - - /** - * Creates a {@link Register} instance. - * - * @param number unique identifier for the register - * @param encoding the target machine encoding for the register - * @param name the mnemonic name for the register - * @param registerCategory the register category - */ - public Register(int number, int encoding, String name, RegisterCategory registerCategory) { - this.number = number; - this.name = name; - this.registerCategory = registerCategory; - this.encoding = encoding; - } - - public RegisterCategory getRegisterCategory() { - return registerCategory; - } - - /** - * Get the start index of this register in the {@link ReferenceMap}. - */ - public int getReferenceMapIndex() { - return (encoding << registerCategory.referenceMapShift) + registerCategory.referenceMapOffset; - } - - /** - * Gets this register as a {@linkplain RegisterValue value} with a specified kind. - * - * @param kind the specified kind - * @return the {@link RegisterValue} - */ - public RegisterValue asValue(LIRKind kind) { - return new RegisterValue(kind, this); - } - - /** - * Gets this register as a {@linkplain RegisterValue value} with no particular kind. - * - * @return a {@link RegisterValue} with {@link Kind#Illegal} kind. - */ - public RegisterValue asValue() { - return asValue(LIRKind.Illegal); - } - - /** - * Determines if this is a valid register. - * - * @return {@code true} iff this register is valid - */ - public boolean isValid() { - return number >= 0; - } - - /** - * Gets the maximum register {@linkplain #number number} in a given set of registers. - * - * @param registers the set of registers to process - * @return the maximum register number for any register in {@code registers} - */ - public static int maxRegisterNumber(Register[] registers) { - int max = Integer.MIN_VALUE; - for (Register r : registers) { - if (r.number > max) { - max = r.number; - } - } - return max; - } - - /** - * Gets the maximum register {@linkplain #encoding encoding} in a given set of registers. - * - * @param registers the set of registers to process - * @return the maximum register encoding for any register in {@code registers} - */ - public static int maxRegisterEncoding(Register[] registers) { - int max = Integer.MIN_VALUE; - for (Register r : registers) { - if (r.encoding > max) { - max = r.encoding; - } - } - return max; - } - - @Override - public String toString() { - return name; - } - - @Override - public int compareTo(Register o) { - if (number < o.number) { - return -1; - } - if (number > o.number) { - return 1; - } - return 0; - } - - @Override - public int hashCode() { - return 17 + name.hashCode(); - } - - @Override - public boolean equals(Object obj) { - if (obj instanceof Register) { - Register other = (Register) obj; - if (number == other.number) { - assert name.equals(other.name); - assert encoding == other.encoding; - assert registerCategory.equals(other.registerCategory); - return true; - } - } - return false; - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.code/src/com/oracle/jvmci/code/RegisterAttributes.java --- a/graal/com.oracle.jvmci.code/src/com/oracle/jvmci/code/RegisterAttributes.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,99 +0,0 @@ -/* - * Copyright (c) 2010, 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.code; - -import java.util.*; - -/** - * A collection of register attributes. The specific attribute values for a register may be local to - * a compilation context. For example, a {@link RegisterConfig} in use during a compilation will - * determine which registers are callee saved. - */ -public class RegisterAttributes { - - private final boolean callerSave; - private final boolean calleeSave; - private final boolean allocatable; - - public RegisterAttributes(boolean isCallerSave, boolean isCalleeSave, boolean isAllocatable) { - this.callerSave = isCallerSave; - this.calleeSave = isCalleeSave; - this.allocatable = isAllocatable; - } - - public static final RegisterAttributes NONE = new RegisterAttributes(false, false, false); - - /** - * Creates a map from register {@linkplain Register#number numbers} to register - * {@linkplain RegisterAttributes attributes} for a given register configuration and set of - * registers. - * - * @param registerConfig a register configuration - * @param registers a set of registers - * @return an array whose length is the max register number in {@code registers} plus 1. An - * element at index i holds the attributes of the register whose number is i. - */ - public static RegisterAttributes[] createMap(RegisterConfig registerConfig, Register[] registers) { - RegisterAttributes[] map = new RegisterAttributes[registers.length]; - for (Register reg : registers) { - if (reg != null) { - CalleeSaveLayout csl = registerConfig.getCalleeSaveLayout(); - RegisterAttributes attr = new RegisterAttributes(Arrays.asList(registerConfig.getCallerSaveRegisters()).contains(reg), - csl == null ? false : Arrays.asList(csl.registers).contains(reg), Arrays.asList(registerConfig.getAllocatableRegisters()).contains(reg)); - if (map.length <= reg.number) { - map = Arrays.copyOf(map, reg.number + 1); - } - map[reg.number] = attr; - } - } - for (int i = 0; i < map.length; i++) { - if (map[i] == null) { - map[i] = NONE; - } - } - return map; - } - - /** - * @return Denotes a register that is available for use by a register allocator. - */ - public boolean isAllocatable() { - return allocatable; - } - - /** - * @return Denotes a register whose value preservation (if required) across a call is the - * responsibility of the callee. - */ - public boolean isCalleeSave() { - return calleeSave; - } - - /** - * @return Denotes a register whose value preservation (if required) across a call is the - * responsibility of the caller. - */ - public boolean isCallerSave() { - return callerSave; - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.code/src/com/oracle/jvmci/code/RegisterConfig.java --- a/graal/com.oracle.jvmci.code/src/com/oracle/jvmci/code/RegisterConfig.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,124 +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.code; - -import com.oracle.jvmci.meta.Kind; -import com.oracle.jvmci.meta.JavaType; -import com.oracle.jvmci.meta.PlatformKind; -import com.oracle.jvmci.code.CallingConvention.Type; - -/** - * A register configuration binds roles and {@linkplain RegisterAttributes attributes} to physical - * registers. - */ -public interface RegisterConfig { - - /** - * Gets the register to be used for returning a value of a given kind. - */ - Register getReturnRegister(Kind kind); - - /** - * Gets the maximum allowed size of the frame. - */ - default int getMaximumFrameSize() { - return Integer.MAX_VALUE; - } - - /** - * Gets the register to which {@link Register#Frame} and {@link Register#CallerFrame} are bound. - */ - Register getFrameRegister(); - - /** - * Gets the calling convention describing how arguments are passed. - * - * @param type the type of calling convention being requested - * @param returnType the return type (can be null for methods returning {@code void}) - * @param parameterTypes the types of the arguments of the call - * @param target the target platform - * @param stackOnly ignore registers - */ - CallingConvention getCallingConvention(Type type, JavaType returnType, JavaType[] parameterTypes, TargetDescription target, boolean stackOnly); - - /** - * Gets the ordered set of registers that are can be used to pass parameters according to a - * given calling convention. - * - * @param type the type of calling convention - * @param kind specifies what kind of registers is being requested - * @return the ordered set of registers that may be used to pass parameters in a call conforming - * to {@code type} - */ - Register[] getCallingConventionRegisters(Type type, Kind kind); - - /** - * Gets the set of all registers that might be used by the register allocator. - * - * To get the set of registers the register allocator is allowed to use see - * {@link RegisterAllocationConfig#getAllocatableRegisters()} - */ - @SuppressWarnings("javadoc") - Register[] getAllocatableRegisters(); - - /** - * Filters a set of registers and returns only those that can be used by the register allocator - * for a value of a particular kind. - */ - Register[] filterAllocatableRegisters(PlatformKind kind, Register[] registers); - - /** - * Gets the registers whose values must be preserved by a method across any call it makes. - */ - Register[] getCallerSaveRegisters(); - - /** - * Gets the layout of the callee save area of this register configuration. - * - * @return {@code null} if there is no callee save area - */ - CalleeSaveLayout getCalleeSaveLayout(); - - /** - * Gets a map from register {@linkplain Register#number numbers} to register - * {@linkplain RegisterAttributes attributes} for this register configuration. - * - * @return an array where an element at index i holds the attributes of the register whose - * number is i - */ - RegisterAttributes[] getAttributesMap(); - - /** - * Gets the register corresponding to a runtime-defined role. - * - * @param id the identifier of a runtime-defined register role - * @return the register playing the role specified by {@code id} - */ - Register getRegisterForRole(int id); - - /** - * Determines if all {@link #getAllocatableRegisters() allocatable} registers are - * {@link #getCallerSaveRegisters() caller saved}. - */ - boolean areAllAllocatableRegistersCallerSaved(); -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.code/src/com/oracle/jvmci/code/RegisterSaveLayout.java --- a/graal/com.oracle.jvmci.code/src/com/oracle/jvmci/code/RegisterSaveLayout.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,127 +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.jvmci.code; - -import java.util.*; - -/** - * A map from registers to frame slots. This can be used to describe where callee saved registers - * are saved in a callee's frame. - */ -public final class RegisterSaveLayout { - - /** - * Keys. - */ - private final Register[] registers; - - /** - * Slot indexes relative to stack pointer. - */ - private final int[] slots; - - /** - * Creates a map from registers to frame slots. - * - * @param registers the keys in the map - * @param slots frame slot index for each register in {@code registers} - */ - public RegisterSaveLayout(Register[] registers, int[] slots) { - assert registers.length == slots.length; - this.registers = registers; - this.slots = slots; - assert registersToSlots(false).size() == registers.length : "non-unique registers"; - assert new HashSet<>(registersToSlots(false).values()).size() == slots.length : "non-unqiue slots"; - } - - /** - * Gets the frame slot index for a given register. - * - * @param register register to get the frame slot index for - * @return frame slot index - */ - public int registerToSlot(Register register) { - for (int i = 0; i < registers.length; i++) { - if (register.equals(registers[i])) { - return slots[i]; - } - } - throw new IllegalArgumentException(register + " not saved by this layout: " + this); - } - - /** - * Gets this layout information as a {@link Map} from registers to slots. - */ - public Map registersToSlots(boolean sorted) { - Map result; - if (sorted) { - result = new TreeMap<>(); - } else { - result = new HashMap<>(); - } - for (int i = 0; i < registers.length; i++) { - result.put(registers[i], slots[i]); - } - return result; - } - - /** - * Gets this layout information as a {@link Map} from slots to registers. - */ - public Map slotsToRegisters(boolean sorted) { - Map result; - if (sorted) { - result = new TreeMap<>(); - } else { - result = new HashMap<>(); - } - for (int i = 0; i < registers.length; i++) { - result.put(slots[i], registers[i]); - } - return result; - } - - @Override - public int hashCode() { - throw new UnsupportedOperationException(); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj instanceof RegisterSaveLayout) { - RegisterSaveLayout that = (RegisterSaveLayout) obj; - if (Arrays.equals(registers, that.registers) && Arrays.equals(slots, that.slots)) { - return true; - } - } - return false; - } - - @Override - public String toString() { - return registersToSlots(true).toString(); - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.code/src/com/oracle/jvmci/code/RegisterValue.java --- a/graal/com.oracle.jvmci.code/src/com/oracle/jvmci/code/RegisterValue.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,70 +0,0 @@ -/* - * Copyright (c) 2009, 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.code; - -import com.oracle.jvmci.meta.*; - -/** - * Denotes a register that stores a value of a fixed kind. There is exactly one (canonical) instance - * of {@link RegisterValue} for each ({@link Register}, {@link Kind}) pair. Use - * {@link Register#asValue(LIRKind)} to retrieve the canonical {@link RegisterValue} instance for a - * given (register,kind) pair. - */ -public final class RegisterValue extends AllocatableValue { - - private final Register reg; - - /** - * Should only be called from {@link Register#Register} to ensure canonicalization. - */ - protected RegisterValue(LIRKind kind, Register register) { - super(kind); - this.reg = register; - } - - @Override - public String toString() { - return getRegister().name + getKindSuffix(); - } - - /** - * @return the register that contains the value - */ - public Register getRegister() { - return reg; - } - - @Override - public int hashCode() { - return 29 * super.hashCode() + reg.hashCode(); - } - - @Override - public boolean equals(Object obj) { - if (obj instanceof RegisterValue) { - RegisterValue other = (RegisterValue) obj; - return super.equals(obj) && reg.equals(other.reg); - } - return false; - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.code/src/com/oracle/jvmci/code/SourceStackTrace.java --- a/graal/com.oracle.jvmci.code/src/com/oracle/jvmci/code/SourceStackTrace.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,50 +0,0 @@ -/* - * 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.jvmci.code; - -/** - * Class representing a exception with a stack trace of the currently processed position in the - * compiled Java program instead of the stack trace of the compiler. The exception of the compiler - * is saved as the cause of this exception. - */ -public abstract class SourceStackTrace extends BailoutException { - private static final long serialVersionUID = 2144811793442316776L; - - public static SourceStackTrace create(Throwable cause, String format, StackTraceElement[] elements) { - return new SourceStackTrace(cause, format) { - - private static final long serialVersionUID = 6279381376051787907L; - - @Override - public final synchronized Throwable fillInStackTrace() { - assert elements != null; - setStackTrace(elements); - return this; - } - }; - } - - private SourceStackTrace(Throwable cause, String format) { - super(cause, format); - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.code/src/com/oracle/jvmci/code/StackLockValue.java --- a/graal/com.oracle.jvmci.code/src/com/oracle/jvmci/code/StackLockValue.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,91 +0,0 @@ -/* - * Copyright (c) 2011, 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.code; - -import com.oracle.jvmci.meta.JavaValue; -import com.oracle.jvmci.meta.AbstractValue; -import com.oracle.jvmci.meta.Value; -import com.oracle.jvmci.meta.LIRKind; -import static com.oracle.jvmci.code.ValueUtil.*; - -/** - * Represents lock information in the debug information. - */ -public final class StackLockValue extends AbstractValue implements JavaValue { - - private Value owner; - private StackSlotValue slot; - private final boolean eliminated; - - public StackLockValue(Value object, StackSlotValue slot, boolean eliminated) { - super(LIRKind.Illegal); - this.owner = object; - this.slot = slot; - this.eliminated = eliminated; - } - - public Value getOwner() { - return owner; - } - - public void setOwner(Value newOwner) { - this.owner = newOwner; - } - - public Value getSlot() { - return slot; - } - - public boolean isEliminated() { - return eliminated; - } - - @Override - public String toString() { - return "monitor[" + owner + (slot != null ? ", " + slot : "") + (eliminated ? ", eliminated" : "") + "]"; - } - - @Override - public int hashCode() { - final int prime = 43; - int result = super.hashCode(); - result = prime * result + (eliminated ? 1231 : 1237); - result = prime * result + owner.hashCode(); - result = prime * result + slot.hashCode(); - return result; - } - - @Override - public boolean equals(Object obj) { - if (obj instanceof StackLockValue) { - StackLockValue other = (StackLockValue) obj; - return super.equals(obj) && eliminated == other.eliminated && owner.equals(other.owner) && slot.equals(other.slot); - } - return false; - } - - public void setSlot(StackSlotValue stackSlot) { - assert slot == null || (isVirtualStackSlot(slot) && (slot.equals(stackSlot) || isStackSlot(stackSlot))) : String.format("Can not set slot for %s to %s", this, stackSlot); - slot = stackSlot; - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.code/src/com/oracle/jvmci/code/StackSlot.java --- a/graal/com.oracle.jvmci.code/src/com/oracle/jvmci/code/StackSlot.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,134 +0,0 @@ -/* - * Copyright (c) 2010, 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.code; - -import com.oracle.jvmci.meta.LIRKind; - -/** - * Represents a compiler spill slot or an outgoing stack-based argument in a method's frame or an - * incoming stack-based argument in a method's {@linkplain #isInCallerFrame() caller's frame}. - */ -public final class StackSlot extends StackSlotValue { - - private final int offset; - private final boolean addFrameSize; - - /** - * Gets a {@link StackSlot} instance representing a stack slot at a given index holding a value - * of a given kind. - * - * @param kind The kind of the value stored in the stack slot. - * @param offset The offset of the stack slot (in bytes) - * @param addFrameSize Specifies if the offset is relative to the stack pointer, or the - * beginning of the frame (stack pointer + total frame size). - */ - public static StackSlot get(LIRKind kind, int offset, boolean addFrameSize) { - assert addFrameSize || offset >= 0; - return new StackSlot(kind, offset, addFrameSize); - } - - /** - * Private constructor to enforce use of {@link #get(LIRKind, int, boolean)} so that a cache can - * be used. - */ - private StackSlot(LIRKind kind, int offset, boolean addFrameSize) { - super(kind); - this.offset = offset; - this.addFrameSize = addFrameSize; - } - - /** - * Gets the offset of this stack slot, relative to the stack pointer. - * - * @return The offset of this slot (in bytes). - */ - public int getOffset(int totalFrameSize) { - assert totalFrameSize > 0 || !addFrameSize; - int result = offset + (addFrameSize ? totalFrameSize : 0); - assert result >= 0; - return result; - } - - public boolean isInCallerFrame() { - return addFrameSize && offset >= 0; - } - - public int getRawOffset() { - return offset; - } - - public boolean getRawAddFrameSize() { - return addFrameSize; - } - - @Override - public String toString() { - if (!addFrameSize) { - return "out:" + offset + getKindSuffix(); - } else if (offset >= 0) { - return "in:" + offset + getKindSuffix(); - } else { - return "stack:" + (-offset) + getKindSuffix(); - } - } - - /** - * Gets this stack slot used to pass an argument from the perspective of a caller. - */ - public StackSlot asOutArg() { - assert offset >= 0; - if (addFrameSize) { - return get(getLIRKind(), offset, false); - } - return this; - } - - /** - * Gets this stack slot used to pass an argument from the perspective of a callee. - */ - public StackSlot asInArg() { - assert offset >= 0; - if (!addFrameSize) { - return get(getLIRKind(), offset, true); - } - return this; - } - - @Override - public int hashCode() { - final int prime = 37; - int result = super.hashCode(); - result = prime * result + (addFrameSize ? 1231 : 1237); - result = prime * result + offset; - return result; - } - - @Override - public boolean equals(Object obj) { - if (obj instanceof StackSlot) { - StackSlot other = (StackSlot) obj; - return super.equals(obj) && addFrameSize == other.addFrameSize && offset == other.offset; - } - return false; - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.code/src/com/oracle/jvmci/code/StackSlotValue.java --- a/graal/com.oracle.jvmci.code/src/com/oracle/jvmci/code/StackSlotValue.java Mon Jun 08 23:40:08 2015 +0200 +++ /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.code; - -import com.oracle.jvmci.meta.AllocatableValue; -import com.oracle.jvmci.meta.LIRKind; - -/** - * Common base class for {@linkplain StackSlot real} and {@linkplain VirtualStackSlot virtual} stack - * slots. - */ -public abstract class StackSlotValue extends AllocatableValue { - - public StackSlotValue(LIRKind lirKind) { - super(lirKind); - } - -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.code/src/com/oracle/jvmci/code/TargetDescription.java --- a/graal/com.oracle.jvmci.code/src/com/oracle/jvmci/code/TargetDescription.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,143 +0,0 @@ -/* - * Copyright (c) 2009, 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.code; - -import com.oracle.jvmci.meta.Kind; -import com.oracle.jvmci.meta.PlatformKind; -import com.oracle.jvmci.meta.LIRKind; -import static com.oracle.jvmci.meta.MetaUtil.*; - -/** - * Represents the target machine for a compiler, including the CPU architecture, the size of - * pointers and references, alignment of stacks, caches, etc. - */ -public abstract class TargetDescription { - - public final Architecture arch; - - /** - * Specifies if this is a multi-processor system. - */ - public final boolean isMP; - - /** - * Specifies if this target supports encoding objects inline in the machine code. - */ - public final boolean inlineObjects; - - /** - * The machine word size on this target. - */ - public final int wordSize; - - /** - * The kind to be used for representing raw pointers and CPU registers. - */ - public final Kind wordKind; - - /** - * The stack alignment requirement of the platform. For example, from Appendix D of Intel 64 and IA-32 Architectures - * Optimization Reference Manual: - * - *
-     *     "It is important to ensure that the stack frame is aligned to a
-     *      16-byte boundary upon function entry to keep local __m128 data,
-     *      parameters, and XMM register spill locations aligned throughout
-     *      a function invocation."
-     * 
- */ - public final int stackAlignment; - - /** - * Maximum constant displacement at which a memory access can no longer be an implicit null - * check. - */ - public final int implicitNullCheckLimit; - - public TargetDescription(Architecture arch, boolean isMP, int stackAlignment, int implicitNullCheckLimit, boolean inlineObjects) { - this.arch = arch; - this.isMP = isMP; - this.wordSize = arch.getWordSize(); - this.wordKind = Kind.fromWordSize(wordSize); - this.stackAlignment = stackAlignment; - this.implicitNullCheckLimit = implicitNullCheckLimit; - this.inlineObjects = inlineObjects; - } - - @Override - public final int hashCode() { - throw new UnsupportedOperationException(); - } - - @Override - public final boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj instanceof TargetDescription) { - TargetDescription that = (TargetDescription) obj; - // @formatter:off - if (this.implicitNullCheckLimit == that.implicitNullCheckLimit && - this.inlineObjects == that.inlineObjects && - this.isMP == that.isMP && - this.stackAlignment == that.stackAlignment && - this.wordKind.equals(that.wordKind) && - this.wordSize == that.wordSize && - this.arch.equals(that.arch)) { - return true; - } - // @formatter:on - } - return false; - } - - @Override - public String toString() { - return identityHashCodeString(this); - } - - public int getSizeInBytes(PlatformKind kind) { - return arch.getSizeInBytes(kind); - } - - public LIRKind getLIRKind(Kind javaKind) { - switch (javaKind) { - case Boolean: - case Byte: - case Short: - case Char: - case Int: - case Long: - case Float: - case Double: - return LIRKind.value(javaKind); - case Object: - return LIRKind.reference(javaKind); - default: - return LIRKind.Illegal; - } - } - - public abstract ReferenceMap createReferenceMap(boolean hasRegisters, int stackSlotCount); -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.code/src/com/oracle/jvmci/code/TypeCheckHints.java --- a/graal/com.oracle.jvmci.code/src/com/oracle/jvmci/code/TypeCheckHints.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,160 +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.jvmci.code; - -import com.oracle.jvmci.meta.JavaTypeProfile; -import com.oracle.jvmci.meta.ResolvedJavaType; -import com.oracle.jvmci.meta.Assumptions; -import java.util.*; - -import com.oracle.jvmci.meta.Assumptions.AssumptionResult; -import com.oracle.jvmci.meta.JavaTypeProfile.ProfiledType; - -/** - * Utility for deriving hint types for a type check instruction (e.g. checkcast or instanceof) based - * on the target type of the check and any profiling information available for the instruction. - */ -public class TypeCheckHints { - - /** - * A receiver type profiled in a type check instruction. - */ - public static class Hint { - - /** - * A type seen while profiling a type check instruction. - */ - public final ResolvedJavaType type; - - /** - * Specifies if {@link #type} is a sub-type of the checked type. - */ - public final boolean positive; - - Hint(ResolvedJavaType type, boolean positive) { - this.type = type; - this.positive = positive; - } - } - - private static final Hint[] NO_HINTS = {}; - - /** - * If non-null, then this is the only type that could pass the type check because the target of - * the type check is a final class or has been speculated to be a final class and this value is - * the only concrete subclass of the target type. - */ - public final ResolvedJavaType exact; - - /** - * The most likely types that the type check instruction will see. - */ - public final Hint[] hints; - - /** - * The profile from which this information was derived. - */ - public final JavaTypeProfile profile; - - /** - * The total probability that the type check will hit one of the types in {@link #hints}. - */ - public final double hintHitProbability; - - /** - * Derives hint information for use when generating the code for a type check instruction. - * - * @param targetType the target type of the type check - * @param profile the profiling information available for the instruction (if any) - * @param assumptions the object in which speculations are recorded. This is null if - * speculations are not supported. - * @param minHintHitProbability if the probability that the type check will hit one of the - * profiled types (up to {@code maxHints}) is below this value, then {@link #hints} - * will be null - * @param maxHints the maximum length of {@link #hints} - */ - public TypeCheckHints(ResolvedJavaType targetType, JavaTypeProfile profile, Assumptions assumptions, double minHintHitProbability, int maxHints) { - this.profile = profile; - if (targetType != null && !canHaveSubtype(targetType)) { - exact = targetType; - } else { - if (assumptions != null) { - AssumptionResult leafConcreteSubtype = targetType == null ? null : targetType.findLeafConcreteSubtype(); - if (leafConcreteSubtype != null) { - assumptions.record(leafConcreteSubtype); - exact = leafConcreteSubtype.getResult(); - } else { - exact = null; - } - } else { - exact = null; - } - } - Double[] hitProbability = {null}; - this.hints = makeHints(targetType, profile, minHintHitProbability, maxHints, hitProbability); - this.hintHitProbability = hitProbability[0]; - } - - private static Hint[] makeHints(ResolvedJavaType targetType, JavaTypeProfile profile, double minHintHitProbability, int maxHints, Double[] hitProbability) { - double hitProb = 0.0d; - Hint[] hintsBuf = NO_HINTS; - if (profile != null) { - double notRecordedTypes = profile.getNotRecordedProbability(); - ProfiledType[] ptypes = profile.getTypes(); - if (notRecordedTypes < (1D - minHintHitProbability) && ptypes != null && ptypes.length > 0) { - hintsBuf = new Hint[ptypes.length]; - int hintCount = 0; - for (ProfiledType ptype : ptypes) { - if (targetType != null) { - ResolvedJavaType hintType = ptype.getType(); - hintsBuf[hintCount++] = new Hint(hintType, targetType.isAssignableFrom(hintType)); - hitProb += ptype.getProbability(); - } - if (hintCount == maxHints) { - break; - } - } - if (hitProb >= minHintHitProbability) { - if (hintsBuf.length != hintCount || hintCount > maxHints) { - hintsBuf = Arrays.copyOf(hintsBuf, Math.min(maxHints, hintCount)); - } - } else { - hintsBuf = NO_HINTS; - hitProb = 0.0d; - } - } - } - hitProbability[0] = hitProb; - return hintsBuf; - } - - /** - * Determines if a given type can have subtypes other than itself. This analysis is purely - * static; no assumptions are made. - * - * @return true if {@code type} can have subtypes - */ - public static boolean canHaveSubtype(ResolvedJavaType type) { - return !type.getElementalType().isFinal(); - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.code/src/com/oracle/jvmci/code/UnsignedMath.java --- a/graal/com.oracle.jvmci.code/src/com/oracle/jvmci/code/UnsignedMath.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,124 +0,0 @@ -/* - * Copyright (c) 2011, 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.code; - -import java.math.*; - -//JaCoCo Exclude - -/** - * Utilities for unsigned comparisons. All methods have correct, but slow, standard Java - * implementations so that they can be used with compilers not supporting the intrinsics. - */ -public class UnsignedMath { - - private static final long MASK = 0xffffffffL; - - /** - * Unsigned comparison aboveThan for two numbers. - */ - public static boolean aboveThan(int a, int b) { - return (a & MASK) > (b & MASK); - } - - /** - * Unsigned comparison aboveOrEqual for two numbers. - */ - public static boolean aboveOrEqual(int a, int b) { - return (a & MASK) >= (b & MASK); - } - - /** - * Unsigned comparison belowThan for two numbers. - */ - public static boolean belowThan(int a, int b) { - return (a & MASK) < (b & MASK); - } - - /** - * Unsigned comparison belowOrEqual for two numbers. - */ - public static boolean belowOrEqual(int a, int b) { - return (a & MASK) <= (b & MASK); - } - - /** - * Unsigned comparison aboveThan for two numbers. - */ - public static boolean aboveThan(long a, long b) { - return (a > b) ^ ((a < 0) != (b < 0)); - } - - /** - * Unsigned comparison aboveOrEqual for two numbers. - */ - public static boolean aboveOrEqual(long a, long b) { - return (a >= b) ^ ((a < 0) != (b < 0)); - } - - /** - * Unsigned comparison belowThan for two numbers. - */ - public static boolean belowThan(long a, long b) { - return (a < b) ^ ((a < 0) != (b < 0)); - } - - /** - * Unsigned comparison belowOrEqual for two numbers. - */ - public static boolean belowOrEqual(long a, long b) { - return (a <= b) ^ ((a < 0) != (b < 0)); - } - - /** - * Unsigned division for two numbers. - */ - public static int divide(int a, int b) { - return (int) ((a & MASK) / (b & MASK)); - } - - /** - * Unsigned remainder for two numbers. - */ - public static int remainder(int a, int b) { - return (int) ((a & MASK) % (b & MASK)); - } - - /** - * Unsigned division for two numbers. - */ - public static long divide(long a, long b) { - return bi(a).divide(bi(b)).longValue(); - } - - /** - * Unsigned remainder for two numbers. - */ - public static long remainder(long a, long b) { - return bi(a).remainder(bi(b)).longValue(); - } - - private static BigInteger bi(long unsigned) { - return unsigned >= 0 ? BigInteger.valueOf(unsigned) : BigInteger.valueOf(unsigned & 0x7fffffffffffffffL).setBit(63); - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.code/src/com/oracle/jvmci/code/ValueUtil.java --- a/graal/com.oracle.jvmci.code/src/com/oracle/jvmci/code/ValueUtil.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,189 +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.jvmci.code; - -import com.oracle.jvmci.meta.Kind; -import com.oracle.jvmci.meta.Value; -import com.oracle.jvmci.meta.AllocatableValue; -import com.oracle.jvmci.meta.JavaConstant; -import java.util.*; - -/** - * Utility class for working with the {@link Value} class and its subclasses. - */ -public final class ValueUtil { - - public static boolean isIllegal(Value value) { - assert value != null; - return Value.ILLEGAL.equals(value); - } - - public static boolean isLegal(Value value) { - return !isIllegal(value); - } - - public static boolean isVirtualObject(Value value) { - assert value != null; - return value instanceof VirtualObject; - } - - public static VirtualObject asVirtualObject(Value value) { - assert value != null; - return (VirtualObject) value; - } - - public static boolean isConstant(Value value) { - assert value != null; - return value instanceof JavaConstant; - } - - public static JavaConstant asConstant(Value value) { - assert value != null; - return (JavaConstant) value; - } - - public static boolean isAllocatableValue(Value value) { - assert value != null; - return value instanceof AllocatableValue; - } - - public static AllocatableValue asAllocatableValue(Value value) { - assert value != null; - return (AllocatableValue) value; - } - - public static boolean isStackSlot(Value value) { - assert value != null; - return value instanceof StackSlot; - } - - public static StackSlot asStackSlot(Value value) { - assert value != null; - return (StackSlot) value; - } - - public static boolean isStackSlotValue(Value value) { - assert value != null; - return value instanceof StackSlotValue; - } - - public static StackSlotValue asStackSlotValue(Value value) { - assert value != null; - return (StackSlotValue) value; - } - - public static boolean isVirtualStackSlot(Value value) { - assert value != null; - return value instanceof VirtualStackSlot; - } - - public static VirtualStackSlot asVirtualStackSlot(Value value) { - assert value != null; - return (VirtualStackSlot) value; - } - - public static boolean isRegister(Value value) { - assert value != null; - return value instanceof RegisterValue; - } - - public static Register asRegister(Value value) { - assert value != null; - return ((RegisterValue) value).getRegister(); - } - - public static Register asIntReg(Value value) { - if (value.getKind().getStackKind() != Kind.Int) { - throw new InternalError("needed Int got: " + value.getKind()); - } else { - return asRegister(value); - } - } - - public static Register asLongReg(Value value) { - if (value.getKind() != Kind.Long) { - throw new InternalError("needed Long got: " + value.getKind()); - } else { - return asRegister(value); - } - } - - public static Register asObjectReg(Value value) { - assert value.getKind() == Kind.Object : value.getKind(); - return asRegister(value); - } - - public static Register asFloatReg(Value value) { - assert value.getKind() == Kind.Float : value.getKind(); - return asRegister(value); - } - - public static Register asDoubleReg(Value value) { - assert value.getKind() == Kind.Double : value.getKind(); - return asRegister(value); - } - - public static boolean sameRegister(Value v1, Value v2) { - return isRegister(v1) && isRegister(v2) && asRegister(v1).equals(asRegister(v2)); - } - - public static boolean sameRegister(Value v1, Value v2, Value v3) { - return sameRegister(v1, v2) && sameRegister(v1, v3); - } - - /** - * Checks if all the provided values are different physical registers. The parameters can be - * either {@link Register registers}, {@link Value values} or arrays of them. All values that - * are not {@link RegisterValue registers} are ignored. - */ - public static boolean differentRegisters(Object... values) { - List registers = collectRegisters(values, new ArrayList()); - for (int i = 1; i < registers.size(); i++) { - Register r1 = registers.get(i); - for (int j = 0; j < i; j++) { - Register r2 = registers.get(j); - if (r1.equals(r2)) { - return false; - } - } - } - return true; - } - - private static List collectRegisters(Object[] values, List registers) { - for (Object o : values) { - if (o instanceof Register) { - registers.add((Register) o); - } else if (o instanceof Value) { - if (isRegister((Value) o)) { - registers.add(asRegister((Value) o)); - } - } else if (o instanceof Object[]) { - collectRegisters((Object[]) o, registers); - } else { - throw new IllegalArgumentException("Not a Register or Value: " + o); - } - } - return registers; - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.code/src/com/oracle/jvmci/code/VirtualObject.java --- a/graal/com.oracle.jvmci.code/src/com/oracle/jvmci/code/VirtualObject.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,218 +0,0 @@ -/* - * Copyright (c) 2010, 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.code; - -import com.oracle.jvmci.meta.ResolvedJavaField; -import com.oracle.jvmci.meta.JavaValue; -import com.oracle.jvmci.meta.Kind; -import com.oracle.jvmci.meta.AbstractValue; -import com.oracle.jvmci.meta.Value; -import com.oracle.jvmci.meta.ResolvedJavaType; -import com.oracle.jvmci.meta.LIRKind; -import java.util.*; - -/** - * An instance of this class represents an object whose allocation was removed by escape analysis. - * The information stored in the {@link VirtualObject} is used during deoptimization to recreate the - * object. - */ -public final class VirtualObject extends AbstractValue implements JavaValue { - - private final ResolvedJavaType type; - private Value[] values; - private final int id; - - /** - * Creates a new {@link VirtualObject} for the given type, with the given fields. If - * {@code type} is an instance class then {@code values} provides the values for the fields - * returned by {@link ResolvedJavaType#getInstanceFields(boolean) getInstanceFields(true)}. If - * {@code type} is an array then the length of the values array determines the reallocated array - * length. - * - * @param type the type of the object whose allocation was removed during compilation. This can - * be either an instance of an array type. - * @param values an array containing all the values to be stored into the object when it is - * recreated - * @param id a unique id that identifies the object within the debug information for one - * position in the compiled code. - * @return a new {@link VirtualObject} instance. - */ - public static VirtualObject get(ResolvedJavaType type, Value[] values, int id) { - return new VirtualObject(type, values, id); - } - - private VirtualObject(ResolvedJavaType type, Value[] values, int id) { - super(LIRKind.reference(Kind.Object)); - this.type = type; - this.values = values; - this.id = id; - } - - private static StringBuilder appendValue(StringBuilder buf, Value value, Set visited) { - if (value instanceof VirtualObject) { - VirtualObject vo = (VirtualObject) value; - buf.append("vobject:").append(vo.type.toJavaName(false)).append(':').append(vo.id); - if (!visited.contains(vo)) { - visited.add(vo); - buf.append('{'); - if (vo.values == null) { - buf.append(""); - } else { - if (vo.type.isArray()) { - for (int i = 0; i < vo.values.length; i++) { - if (i != 0) { - buf.append(','); - } - buf.append(i).append('='); - appendValue(buf, vo.values[i], visited); - } - } else { - ResolvedJavaField[] fields = vo.type.getInstanceFields(true); - assert fields.length == vo.values.length : vo.type + ", fields=" + Arrays.toString(fields) + ", values=" + Arrays.toString(vo.values); - for (int i = 0; i < vo.values.length; i++) { - if (i != 0) { - buf.append(','); - } - buf.append(fields[i].getName()).append('='); - appendValue(buf, vo.values[i], visited); - } - } - } - buf.append('}'); - } - } else { - buf.append(value); - } - return buf; - } - - @Override - public String toString() { - Set visited = Collections.newSetFromMap(new IdentityHashMap()); - return appendValue(new StringBuilder(), this, visited).toString(); - } - - /** - * Returns the type of the object whose allocation was removed during compilation. This can be - * either an instance of an array type. - */ - public ResolvedJavaType getType() { - return type; - } - - /** - * Returns an array containing all the values to be stored into the object when it is recreated. - */ - public Value[] getValues() { - return values; - } - - /** - * Returns the unique id that identifies the object within the debug information for one - * position in the compiled code. - */ - public int getId() { - return id; - } - - private static boolean checkValues(ResolvedJavaType type, Value[] values) { - if (values != null) { - if (!type.isArray()) { - ResolvedJavaField[] fields = type.getInstanceFields(true); - int fieldIndex = 0; - for (int i = 0; i < values.length; i++) { - ResolvedJavaField field = fields[fieldIndex++]; - Kind valKind = values[i].getKind().getStackKind(); - if (field.getKind() == Kind.Object) { - assert values[i].getLIRKind().isReference(0) : field + ": " + valKind + " != " + field.getKind(); - } else { - if ((valKind == Kind.Double || valKind == Kind.Long) && field.getKind() == Kind.Int) { - assert fields[fieldIndex].getKind() == Kind.Int; - fieldIndex++; - } else { - assert valKind == field.getKind().getStackKind() : field + ": " + valKind + " != " + field.getKind(); - } - } - } - assert fields.length == fieldIndex : type + ": fields=" + Arrays.toString(fields) + ", field values=" + Arrays.toString(values); - } else { - Kind componentKind = type.getComponentType().getKind().getStackKind(); - if (componentKind == Kind.Object) { - for (int i = 0; i < values.length; i++) { - assert values[i].getLIRKind().isReference(0) : values[i].getKind() + " != " + componentKind; - } - } else { - for (int i = 0; i < values.length; i++) { - assert values[i].getKind() == componentKind || componentKind.getBitCount() >= values[i].getKind().getBitCount() || - (componentKind == Kind.Int && values[i].getKind().getBitCount() >= Kind.Int.getBitCount()) : values[i].getKind() + " != " + componentKind; - } - } - } - } - return true; - } - - /** - * Overwrites the current set of values with a new one. - * - * @param values an array containing all the values to be stored into the object when it is - * recreated. - */ - public void setValues(Value[] values) { - assert checkValues(type, values); - this.values = values; - } - - @Override - public int hashCode() { - return getLIRKind().hashCode() + type.hashCode(); - } - - @Override - public boolean equals(Object o) { - if (o == this) { - return true; - } - if (o instanceof VirtualObject) { - VirtualObject l = (VirtualObject) o; - if (!l.type.equals(type) || l.values.length != values.length) { - return false; - } - for (int i = 0; i < values.length; i++) { - /* - * Virtual objects can form cycles. Calling equals() could therefore lead to - * infinite recursion. - */ - if (!same(values[i], l.values[i])) { - return false; - } - } - return true; - } - return false; - } - - private static boolean same(Object o1, Object o2) { - return o1 == o2; - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.code/src/com/oracle/jvmci/code/VirtualStackSlot.java --- a/graal/com.oracle.jvmci.code/src/com/oracle/jvmci/code/VirtualStackSlot.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,75 +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.code; - -import com.oracle.jvmci.meta.LIRKind; - -/** - * {@link VirtualStackSlot}s are stack slots that are not yet fixed to specific frame offset. They - * are replaced by real {@link StackSlot}s with a fixed position in the frame before code emission. - */ -public abstract class VirtualStackSlot extends StackSlotValue { - - private final int id; - - public VirtualStackSlot(int id, LIRKind lirKind) { - super(lirKind); - this.id = id; - } - - public int getId() { - return id; - } - - @Override - public String toString() { - return "vstack:" + id + getKindSuffix(); - } - - @Override - public int hashCode() { - final int prime = 31; - int result = super.hashCode(); - result = prime * result + id; - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (!super.equals(obj)) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - VirtualStackSlot other = (VirtualStackSlot) obj; - if (id != other.id) { - return false; - } - return true; - } - -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.code/src/com/oracle/jvmci/code/package-info.java --- a/graal/com.oracle.jvmci.code/src/com/oracle/jvmci/code/package-info.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,30 +0,0 @@ -/* - * Copyright (c) 2010, 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 that defines the interface between a Java application that wants to install code and the runtime. - * The runtime provides in implementation of the {@link com.oracle.jvmci.code.CodeCacheProvider} interface. - * The method {@link com.oracle.jvmci.code.CodeCacheProvider#addMethod(com.oracle.jvmci.meta.ResolvedJavaMethod, CompilationResult, com.oracle.jvmci.meta.SpeculationLog, InstalledCode)} - * can be used to install code for a given method. - */ -package com.oracle.jvmci.code; - diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.code/src/com/oracle/jvmci/code/stack/InspectedFrame.java --- a/graal/com.oracle.jvmci.code/src/com/oracle/jvmci/code/stack/InspectedFrame.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,69 +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.jvmci.code.stack; - -import com.oracle.jvmci.meta.ResolvedJavaMethod; - -public interface InspectedFrame { - - /** - * Returns the value of the local at the given index. Currently only works for object values. - * This value is a copy iff {@link #isVirtual(int)} is true. - */ - Object getLocal(int index); - - /** - * Returns whether the local at the given index is a virtual object, and therefore the object - * returned by {@link #getLocal(int)} is a copy. - */ - boolean isVirtual(int index); - - /** - * Returns true if the stack frame is a compiled stack frame and there are virtual objects - * anywhere in the current state of the compiled method. This can return true even if - * {@link #isVirtual(int)} return false for all locals. - */ - boolean hasVirtualObjects(); - - /** - * This method will materialize all virtual objects, deoptimize the stack frame and make sure - * that subsequent execution of the deoptimized frame uses the materialized values. - */ - void materializeVirtualObjects(boolean invalidateCode); - - /** - * @return the current bytecode index - */ - int getBytecodeIndex(); - - /** - * @return the current method - */ - ResolvedJavaMethod getMethod(); - - /** - * Checks if the current method is equal to the given method. This is semantically equivalent to - * {@code method.equals(getMethod())}, but can be implemented more efficiently. - */ - boolean isMethod(ResolvedJavaMethod method); -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.code/src/com/oracle/jvmci/code/stack/InspectedFrameVisitor.java --- a/graal/com.oracle.jvmci.code/src/com/oracle/jvmci/code/stack/InspectedFrameVisitor.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,34 +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.jvmci.code.stack; - -/** - * Callback interface for {@link StackIntrospection#iterateFrames}. Implementations of - * {@link #visitFrame} return null to indicate that frame iteration should continue and the next - * caller frame should be visited; and return any non-null value to indicate that frame iteration - * should stop. - */ -public interface InspectedFrameVisitor { - - T visitFrame(InspectedFrame frame); -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.code/src/com/oracle/jvmci/code/stack/StackIntrospection.java --- a/graal/com.oracle.jvmci.code/src/com/oracle/jvmci/code/stack/StackIntrospection.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,45 +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.jvmci.code.stack; - -import com.oracle.jvmci.meta.ResolvedJavaMethod; - -public interface StackIntrospection { - - /** - * Accesses the current stack, providing {@link InspectedFrame}s to the visitor that can be used - * to inspect the stack frames' contents. Iteration continues as long as - * {@link InspectedFrameVisitor#visitFrame}, which is invoked for every {@link InspectedFrame}, - * returns null. Any non-null result of the visitor indicates that frame iteration should stop. - * - * @param initialMethods if this is non-{@code null}, then the stack trace will start at these - * methods - * @param matchingMethods if this is non-{@code null}, then only matching stack frames are - * returned - * @param initialSkip the number of matching methods to skip (including the initial method) - * @param visitor the visitor that is called for every matching method - * @return the last result returned by the visitor (which is non-null to indicate that iteration - * should stop), or null if the whole stack was iterated. - */ - T iterateFrames(ResolvedJavaMethod[] initialMethods, ResolvedJavaMethod[] matchingMethods, int initialSkip, InspectedFrameVisitor visitor); -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.common/src/com/oracle/jvmci/common/JVMCIError.java --- a/graal/com.oracle.jvmci.common/src/com/oracle/jvmci/common/JVMCIError.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,139 +0,0 @@ -/* - * Copyright (c) 2011, 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.common; - -import java.util.*; - -/** - * Indicates a condition in JVMCI related code that should never occur during normal operation. - */ -public class JVMCIError extends Error { - - private static final long serialVersionUID = 531632331813456233L; - private final ArrayList context = new ArrayList<>(); - - public static RuntimeException unimplemented() { - throw new JVMCIError("unimplemented"); - } - - public static RuntimeException unimplemented(String msg) { - throw new JVMCIError("unimplemented: %s", msg); - } - - public static RuntimeException shouldNotReachHere() { - throw new JVMCIError("should not reach here"); - } - - public static RuntimeException shouldNotReachHere(String msg) { - throw new JVMCIError("should not reach here: %s", msg); - } - - public static RuntimeException shouldNotReachHere(Throwable cause) { - throw new JVMCIError(cause); - } - - /** - * Checks a given condition and throws a {@link JVMCIError} if it is false. Guarantees are - * stronger than assertions in that they are always checked. Error messages for guarantee - * violations should clearly indicate the nature of the problem as well as a suggested solution - * if possible. - * - * @param condition the condition to check - * @param msg the message that will be associated with the error, in - * {@link String#format(String, Object...)} syntax - * @param args arguments to the format string - */ - public static void guarantee(boolean condition, String msg, Object... args) { - if (!condition) { - throw new JVMCIError("failed guarantee: " + msg, args); - } - } - - /** - * This constructor creates a {@link JVMCIError} with a message assembled via - * {@link String#format(String, Object...)}. It always uses the ENGLISH locale in order to - * always generate the same output. - * - * @param msg the message that will be associated with the error, in String.format syntax - * @param args parameters to String.format - parameters that implement {@link Iterable} will be - * expanded into a [x, x, ...] representation. - */ - public JVMCIError(String msg, Object... args) { - super(format(msg, args)); - } - - /** - * This constructor creates a {@link JVMCIError} for a given causing Throwable instance. - * - * @param cause the original exception that contains additional information on this error - */ - public JVMCIError(Throwable cause) { - super(cause); - } - - /** - * This constructor creates a {@link JVMCIError} and adds all the - * {@linkplain #addContext(String) context} of another {@link JVMCIError}. - * - * @param e the original {@link JVMCIError} - */ - public JVMCIError(JVMCIError e) { - super(e); - context.addAll(e.context); - } - - @Override - public String toString() { - StringBuilder str = new StringBuilder(); - str.append(super.toString()); - for (String s : context) { - str.append("\n\tat ").append(s); - } - return str.toString(); - } - - private static String format(String msg, Object... args) { - if (args != null) { - // expand Iterable parameters into a list representation - for (int i = 0; i < args.length; i++) { - if (args[i] instanceof Iterable) { - ArrayList list = new ArrayList<>(); - for (Object o : (Iterable) args[i]) { - list.add(o); - } - args[i] = list.toString(); - } - } - } - return String.format(Locale.ENGLISH, msg, args); - } - - public JVMCIError addContext(String newContext) { - this.context.add(newContext); - return this; - } - - public JVMCIError addContext(String name, Object obj) { - return addContext(format("%s: %s", name, obj)); - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.common/src/com/oracle/jvmci/common/UnsafeAccess.java --- a/graal/com.oracle.jvmci.common/src/com/oracle/jvmci/common/UnsafeAccess.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,95 +0,0 @@ -/* - * Copyright (c) 2012, 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.common; - -import java.lang.reflect.*; - -import sun.misc.*; - -public class UnsafeAccess { - - /** - * An instance of {@link Unsafe} for use within JVMCI. - */ - public static final Unsafe unsafe; - - static { - try { - Field theUnsafeInstance = Unsafe.class.getDeclaredField("theUnsafe"); - theUnsafeInstance.setAccessible(true); - unsafe = (Unsafe) theUnsafeInstance.get(Unsafe.class); - } catch (Exception e) { - throw new RuntimeException("exception while trying to get Unsafe", e); - } - } - - /** - * Copies the contents of a {@link String} to a native memory buffer as a {@code '\0'} - * terminated C string. The native memory buffer is allocated via - * {@link Unsafe#allocateMemory(long)}. The caller is responsible for releasing the buffer when - * it is no longer needed via {@link Unsafe#freeMemory(long)}. - * - * @return the native memory pointer of the C string created from {@code s} - */ - public static long createCString(String s) { - return writeCString(s, unsafe.allocateMemory(s.length() + 1)); - } - - /** - * Reads a {@code '\0'} terminated C string from native memory and converts it to a - * {@link String}. - * - * @return a Java string - */ - public static String readCString(long address) { - if (address == 0) { - return null; - } - StringBuilder sb = new StringBuilder(); - for (int i = 0;; i++) { - char c = (char) unsafe.getByte(address + i); - if (c == 0) { - break; - } - sb.append(c); - } - return sb.toString(); - } - - /** - * Writes the contents of a {@link String} to a native memory buffer as a {@code '\0'} - * terminated C string. The caller is responsible for ensuring the buffer is at least - * {@code s.length() + 1} bytes long. The caller is also responsible for releasing the buffer - * when it is no longer. - * - * @return the value of {@code buf} - */ - public static long writeCString(String s, long buf) { - int size = s.length(); - for (int i = 0; i < size; i++) { - unsafe.putByte(buf + i, (byte) s.charAt(i)); - } - unsafe.putByte(buf + size, (byte) '\0'); - return buf; - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.compiler/src/com/oracle/jvmci/compiler/Compiler.java --- a/graal/com.oracle.jvmci.compiler/src/com/oracle/jvmci/compiler/Compiler.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,42 +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.jvmci.compiler; - -import com.oracle.jvmci.code.*; -import com.oracle.jvmci.meta.*; -import com.oracle.jvmci.options.*; -import com.oracle.jvmci.service.*; - -public interface Compiler extends Service { - int INVOCATION_ENTRY_BCI = -1; - - @Option(help = "", type = OptionType.Debug) OptionValue PrintFilter = new OptionValue<>(null); - @Option(help = "", type = OptionType.Debug) OptionValue PrintCompilation = new OptionValue<>(false); - @Option(help = "", type = OptionType.Debug) OptionValue PrintAfterCompilation = new OptionValue<>(false); - @Option(help = "", type = OptionType.Debug) OptionValue PrintBailout = new OptionValue<>(false); - @Option(help = "", type = OptionType.Debug) OptionValue ExitVMOnBailout = new OptionValue<>(false); - @Option(help = "", type = OptionType.Debug) OptionValue ExitVMOnException = new OptionValue<>(true); - @Option(help = "", type = OptionType.Debug) OptionValue PrintStackTraceOnException = new OptionValue<>(false); - - CompilationResult compile(ResolvedJavaMethod method, int entryBCI, boolean mustRecordMethodInlining); -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.compiler/src/com/oracle/jvmci/compiler/CompilerThread.java --- a/graal/com.oracle.jvmci.compiler/src/com/oracle/jvmci/compiler/CompilerThread.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,61 +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.jvmci.compiler; - -import com.oracle.jvmci.compiler.CompilerThreadFactory.*; -import com.oracle.jvmci.debug.*; - -/** - * A compiler thread is a daemon thread that runs at {@link Thread#MAX_PRIORITY} and executes in the - * context of a thread-local {@linkplain JVMCIDebugConfig debug configuration}. - */ -public class CompilerThread extends Thread { - - private final DebugConfigAccess debugConfigAccess; - - public CompilerThread(Runnable r, String namePrefix, DebugConfigAccess debugConfigAccess) { - super(r); - this.setName(namePrefix + "-" + this.getId()); - this.setPriority(Thread.MAX_PRIORITY); - this.setDaemon(true); - this.debugConfigAccess = debugConfigAccess; - } - - @Override - public void run() { - JVMCIDebugConfig debugConfig = debugConfigAccess.getDebugConfig(); - setContextClassLoader(getClass().getClassLoader()); - try { - super.run(); - } finally { - if (debugConfig != null) { - for (DebugDumpHandler dumpHandler : debugConfig.dumpHandlers()) { - try { - dumpHandler.close(); - } catch (Throwable t) { - } - } - } - } - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.compiler/src/com/oracle/jvmci/compiler/CompilerThreadFactory.java --- a/graal/com.oracle.jvmci.compiler/src/com/oracle/jvmci/compiler/CompilerThreadFactory.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,56 +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.jvmci.compiler; - -import java.util.concurrent.*; - -import com.oracle.jvmci.debug.*; - -/** - * Facility for creating {@linkplain CompilerThread compiler threads}. - */ -public class CompilerThreadFactory implements ThreadFactory { - - /** - * Capability to get a thread-local debug configuration for the current thread. - */ - public interface DebugConfigAccess { - /** - * Get a thread-local debug configuration for the current thread. This will be null if - * debugging is {@linkplain Debug#isEnabled() disabled}. - */ - JVMCIDebugConfig getDebugConfig(); - } - - protected final String threadNamePrefix; - protected final DebugConfigAccess debugConfigAccess; - - public CompilerThreadFactory(String threadNamePrefix, DebugConfigAccess debugConfigAccess) { - this.threadNamePrefix = threadNamePrefix; - this.debugConfigAccess = debugConfigAccess; - } - - public Thread newThread(Runnable r) { - return new CompilerThread(r, threadNamePrefix, debugConfigAccess); - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.debug.test/src/com/oracle/jvmci/debug/test/DebugHistogramTest.java --- a/graal/com.oracle.jvmci.debug.test/src/com/oracle/jvmci/debug/test/DebugHistogramTest.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,123 +0,0 @@ -/* - * Copyright (c) 2013, 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.debug.test; - -import java.io.*; - -import org.junit.*; - -import com.oracle.jvmci.debug.*; -import com.oracle.jvmci.debug.internal.*; - -public class DebugHistogramTest { - - @Test - public void testEmptyHistogram() { - DebugHistogram histogram = Debug.createHistogram("TestHistogram"); - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - - new DebugHistogramAsciiPrinter(new PrintStream(outputStream)).print(histogram); - String line = outputStream.toString().split("\r?\n")[0]; - Assert.assertEquals("TestHistogram is empty.", line); - - outputStream.reset(); - new DebugHistogramRPrinter(new PrintStream(outputStream)).print(histogram); - Assert.assertEquals("", outputStream.toString()); - } - - @Test - public void testSingleEntryHistogram() { - DebugHistogram histogram = Debug.createHistogram("TestHistogram"); - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - histogram.add(new Integer(1)); - histogram.add(new Integer(1)); - new DebugHistogramAsciiPrinter(new PrintStream(outputStream)).print(histogram); - String[] lines = outputStream.toString().split("\r?\n"); - // @formatter:off - String[] expected = { - "TestHistogram has 1 unique elements and 2 total elements:", - "--------------------------------------------------------------------------------------------------------------------------------------------------------------------------", - "| 1 | 2 | ==================================================================================================== |", - "--------------------------------------------------------------------------------------------------------------------------------------------------------------------------" - }; - // @formatter:on - Assert.assertArrayEquals(expected, lines); - - outputStream.reset(); - new DebugHistogramRPrinter(new PrintStream(outputStream)).print(histogram); - lines = outputStream.toString().split("\r?\n"); - // @formatter:off - expected = new String[] { - "TestHistogram <- c(2);", - "names(TestHistogram) <- c(\"1\");" - }; - // @formatter:on - Assert.assertArrayEquals(expected, lines); - } - - @Test - public void testMultipleEntryHistogram() { - DebugHistogram histogram = Debug.createHistogram("TestHistogram"); - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - histogram.add(new Integer(1)); - histogram.add(new Integer(2)); - histogram.add(new Integer(2)); - new DebugHistogramAsciiPrinter(new PrintStream(outputStream)).print(histogram); - String[] lines = outputStream.toString().split("\r?\n"); - // @formatter:off - String[] expected = new String[] { - "TestHistogram has 2 unique elements and 3 total elements:", - "--------------------------------------------------------------------------------------------------------------------------------------------------------------------------", - "| 2 | 2 | ==================================================================================================== |", - "| 1 | 1 | ================================================== |", - "--------------------------------------------------------------------------------------------------------------------------------------------------------------------------" - }; - // @formatter:on - Assert.assertArrayEquals(expected, lines); - - outputStream.reset(); - new DebugHistogramRPrinter(new PrintStream(outputStream)).print(histogram); - lines = outputStream.toString().split("\r?\n"); - // @formatter:off - expected = new String[] { - "TestHistogram <- c(2, 1);", - "names(TestHistogram) <- c(\"2\", \"1\");" - }; - // @formatter:on - Assert.assertArrayEquals(expected, lines); - } - - @Test - public void testTooLongValueString() { - DebugHistogram histogram = Debug.createHistogram("TestHistogram"); - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - histogram.add("MyCustomValue"); - new DebugHistogramAsciiPrinter(new PrintStream(outputStream), Integer.MAX_VALUE, 10, 10, 1).print(histogram); - String[] lines = outputStream.toString().split("\r?\n"); - Assert.assertEquals(4, lines.length); - Assert.assertEquals("TestHistogram has 1 unique elements and 1 total elements:", lines[0]); - Assert.assertEquals("----------------------------------------", lines[1]); - Assert.assertEquals("| MyCusto... | 1 | ========== |", lines[2]); - Assert.assertEquals("----------------------------------------", lines[3]); - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.debug.test/src/com/oracle/jvmci/debug/test/DebugTimerTest.java --- a/graal/com.oracle.jvmci.debug.test/src/com/oracle/jvmci/debug/test/DebugTimerTest.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,137 +0,0 @@ -/* - * Copyright (c) 2013, 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.debug.test; - -import static org.junit.Assert.*; - -import java.lang.management.*; - -import org.junit.*; - -import com.oracle.jvmci.debug.*; - -public class DebugTimerTest { - - private static final ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean(); - - /** - * Actively spins the current thread for at least a given number of milliseconds in such a way - * that timers for the current thread keep ticking over. - * - * @return the number of milliseconds actually spent spinning which is guaranteed to be >= - * {@code ms} - */ - private static long spin(long ms) { - long start = threadMXBean.getCurrentThreadCpuTime(); - do { - long durationMS = (threadMXBean.getCurrentThreadCpuTime() - start) / 1000; - if (durationMS >= ms) { - return durationMS; - } - } while (true); - } - - @Test - public void test1() { - DebugConfig debugConfig = Debug.fixedConfig(0, 0, false, false, true, false, null, null, System.out); - try (DebugConfigScope dcs = new DebugConfigScope(debugConfig); Debug.Scope s = Debug.scope("DebugTimerTest")) { - - DebugTimer timerA = Debug.timer("TimerA"); - DebugTimer timerB = Debug.timer("TimerB"); - - long spinA; - long spinB; - - try (DebugCloseable a1 = timerA.start()) { - spinA = spin(50); - try (DebugCloseable b1 = timerB.start()) { - spinB = spin(50); - } - } - - Assert.assertTrue(timerB.getCurrentValue() < timerA.getCurrentValue()); - if (timerA.getFlat() != null && timerB.getFlat() != null) { - assertTrue(spinB >= spinA || timerB.getFlat().getCurrentValue() < timerA.getFlat().getCurrentValue()); - assertEquals(timerA.getFlat().getCurrentValue(), timerA.getCurrentValue() - timerB.getFlat().getCurrentValue(), 10D); - } - } - } - - @Test - public void test2() { - DebugConfig debugConfig = Debug.fixedConfig(0, 0, false, false, true, false, null, null, System.out); - try (DebugConfigScope dcs = new DebugConfigScope(debugConfig); Debug.Scope s = Debug.scope("DebugTimerTest")) { - DebugTimer timerC = Debug.timer("TimerC"); - try (DebugCloseable c1 = timerC.start()) { - spin(50); - try (DebugCloseable c2 = timerC.start()) { - spin(50); - try (DebugCloseable c3 = timerC.start()) { - spin(50); - try (DebugCloseable c4 = timerC.start()) { - spin(50); - try (DebugCloseable c5 = timerC.start()) { - spin(50); - } - } - } - } - } - if (timerC.getFlat() != null) { - assertEquals(timerC.getFlat().getCurrentValue(), timerC.getCurrentValue()); - } - } - } - - @Test - public void test3() { - DebugConfig debugConfig = Debug.fixedConfig(0, 0, false, false, true, false, null, null, System.out); - try (DebugConfigScope dcs = new DebugConfigScope(debugConfig); Debug.Scope s = Debug.scope("DebugTimerTest")) { - - DebugTimer timerD = Debug.timer("TimerD"); - DebugTimer timerE = Debug.timer("TimerE"); - - long spinD1; - long spinE; - - try (DebugCloseable d1 = timerD.start()) { - spinD1 = spin(50); - try (DebugCloseable e1 = timerE.start()) { - spinE = spin(50); - try (DebugCloseable d2 = timerD.start()) { - spin(50); - try (DebugCloseable d3 = timerD.start()) { - spin(50); - } - } - } - } - - Assert.assertTrue(timerE.getCurrentValue() < timerD.getCurrentValue()); - if (timerD.getFlat() != null && timerE.getFlat() != null) { - assertTrue(spinE >= spinD1 || timerE.getFlat().getCurrentValue() < timerD.getFlat().getCurrentValue()); - assertEquals(timerD.getFlat().getCurrentValue(), timerD.getCurrentValue() - timerE.getFlat().getCurrentValue(), 10D); - } - } - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.debug/overview.html --- a/graal/com.oracle.jvmci.debug/overview.html Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,36 +0,0 @@ - - - - - - - - -Documentation for the com.oracle.jvmci.debug project. - - - diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/AnsiColor.java --- a/graal/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/AnsiColor.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,88 +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.debug; - -/** - * Ansi terminal color escape codes. - */ -public final class AnsiColor { - /** Foreground black. */ - public static final String BLACK = "\u001b[30m"; - /** Foreground red. */ - public static final String RED = "\u001b[31m"; - /** Foreground green. */ - public static final String GREEN = "\u001b[32m"; - /** Foreground yellow. */ - public static final String YELLOW = "\u001b[33m"; - /** Foreground blue. */ - public static final String BLUE = "\u001b[34m"; - /** Foreground magenta. */ - public static final String MAGENTA = "\u001b[35m"; - /** Foreground cyan. */ - public static final String CYAN = "\u001b[36m"; - /** Foreground white. */ - public static final String WHITE = "\u001b[37m"; - - /** Foreground bold black. */ - public static final String BOLD_BLACK = "\u001b[30;1m"; - /** Foreground bold red. */ - public static final String BOLD_RED = "\u001b[31;1m"; - /** Foreground bold green. */ - public static final String BOLD_GREEN = "\u001b[32;1m"; - /** Foreground bold yellow. */ - public static final String BOLD_YELLOW = "\u001b[33;1m"; - /** Foreground bold blue. */ - public static final String BOLD_BLUE = "\u001b[34;1m"; - /** Foreground bold magenta. */ - public static final String BOLD_MAGENTA = "\u001b[35;1m"; - /** Foreground bold cyan. */ - public static final String BOLD_CYAN = "\u001b[36;1m"; - /** Foreground bold white. */ - public static final String BOLD_WHITE = "\u001b[37;1m"; - - /** Background black. */ - public static final String BG_BLACK = "\u001b[40m"; - /** Background red. */ - public static final String BG_RED = "\u001b[41m"; - /** Background green. */ - public static final String BG_GREEN = "\u001b[42m"; - /** Background yellow. */ - public static final String BG_YELLOW = "\u001b[43m"; - /** Background blue. */ - public static final String BG_BLUE = "\u001b[44m"; - /** Background magenta. */ - public static final String BG_MAGENTA = "\u001b[45m"; - /** Background cyan. */ - public static final String BG_CYAN = "\u001b[46m"; - /** Background white. */ - public static final String BG_WHITE = "\u001b[47m"; - - /** Reset. */ - public static final String RESET = "\u001b[0m"; - /** Underline. */ - public static final String UNDERLINED = "\u001b[4m"; - - /** Prevent instantiation. */ - private AnsiColor() { - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/Debug.java --- a/graal/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/Debug.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1551 +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.jvmci.debug; - -import static com.oracle.jvmci.debug.Debug.Initialization.*; -import static com.oracle.jvmci.debug.DelegatingDebugConfig.Feature.*; -import static java.util.FormattableFlags.*; - -import java.io.*; -import java.util.*; -import java.util.concurrent.*; - -import com.oracle.jvmci.debug.DelegatingDebugConfig.Level; -import com.oracle.jvmci.debug.internal.*; -import com.oracle.jvmci.service.*; - -/** - * Scope based debugging facility. This facility is {@link #isEnabled()} if assertions are enabled - * for the {@link Debug} class or the {@value Initialization#INITIALIZER_PROPERTY_NAME} system - * property is {@code "true"} when {@link Debug} is initialized. - */ -public class Debug { - - static { - for (DebugInitializationPropertyProvider p : Services.load(DebugInitializationPropertyProvider.class)) { - p.apply(); - } - } - - /** - * Class to assist with initialization of {@link Debug}. - */ - public static class Initialization { - - public static final String INITIALIZER_PROPERTY_NAME = "jvmci.debug.enable"; - - private static boolean initialized; - - /** - * Determines if {@link Debug} has been initialized. - */ - public static boolean isDebugInitialized() { - return initialized; - } - - } - - @SuppressWarnings("all") - private static boolean initialize() { - boolean assertionsEnabled = false; - assert assertionsEnabled = true; - Initialization.initialized = true; - return assertionsEnabled || Boolean.getBoolean(INITIALIZER_PROPERTY_NAME); - } - - private static final boolean ENABLED = initialize(); - - public static boolean isEnabled() { - return ENABLED; - } - - public static boolean isDumpEnabledForMethod() { - if (!ENABLED) { - return false; - } - DebugConfig config = DebugScope.getConfig(); - if (config == null) { - return false; - } - return config.isDumpEnabledForMethod(); - } - - public static final int DEFAULT_LOG_LEVEL = 2; - - public static boolean isDumpEnabled() { - return isDumpEnabled(DEFAULT_LOG_LEVEL); - } - - public static boolean isDumpEnabled(int dumpLevel) { - return ENABLED && DebugScope.getInstance().isDumpEnabled(dumpLevel); - } - - /** - * Determines if verification is enabled in the current method, regardless of the - * {@linkplain Debug#currentScope() current debug scope}. - * - * @see Debug#verify(Object, String) - */ - public static boolean isVerifyEnabledForMethod() { - if (!ENABLED) { - return false; - } - DebugConfig config = DebugScope.getConfig(); - if (config == null) { - return false; - } - return config.isVerifyEnabledForMethod(); - } - - /** - * Determines if verification is enabled in the {@linkplain Debug#currentScope() current debug - * scope}. - * - * @see Debug#verify(Object, String) - */ - public static boolean isVerifyEnabled() { - return ENABLED && DebugScope.getInstance().isVerifyEnabled(); - } - - public static boolean isMeterEnabled() { - return ENABLED && DebugScope.getInstance().isMeterEnabled(); - } - - public static boolean isTimeEnabled() { - return ENABLED && DebugScope.getInstance().isTimeEnabled(); - } - - public static boolean isMemUseTrackingEnabled() { - return ENABLED && DebugScope.getInstance().isMemUseTrackingEnabled(); - } - - public static boolean isLogEnabledForMethod() { - if (!ENABLED) { - return false; - } - DebugConfig config = DebugScope.getConfig(); - if (config == null) { - return false; - } - return config.isLogEnabledForMethod(); - } - - public static boolean isLogEnabled() { - return isLogEnabled(DEFAULT_LOG_LEVEL); - } - - public static boolean isLogEnabled(int logLevel) { - return ENABLED && DebugScope.getInstance().isLogEnabled(logLevel); - } - - @SuppressWarnings("unused") - public static Runnable decorateDebugRoot(Runnable runnable, String name, DebugConfig config) { - return runnable; - } - - @SuppressWarnings("unused") - public static Callable decorateDebugRoot(Callable callable, String name, DebugConfig config) { - return callable; - } - - @SuppressWarnings("unused") - public static Runnable decorateScope(Runnable runnable, String name, Object... context) { - return runnable; - } - - @SuppressWarnings("unused") - public static Callable decorateScope(Callable callable, String name, Object... context) { - return callable; - } - - /** - * Gets a string composed of the names in the current nesting of debug - * {@linkplain #scope(Object) scopes} separated by {@code '.'}. - */ - public static String currentScope() { - if (ENABLED) { - return DebugScope.getInstance().getQualifiedName(); - } else { - return ""; - } - } - - /** - * Represents a debug scope entered by {@link Debug#scope(Object)} or - * {@link Debug#sandbox(CharSequence, DebugConfig, Object...)}. Leaving the scope is achieved - * via {@link #close()}. - */ - public interface Scope extends AutoCloseable { - void close(); - } - - /** - * Creates and enters a new debug scope which will be a child of the current debug scope. - *

- * It is recommended to use the try-with-resource statement for managing entering and leaving - * debug scopes. For example: - * - *

-     * try (Scope s = Debug.scope("InliningGraph", inlineeGraph)) {
-     *     ...
-     * } catch (Throwable e) {
-     *     throw Debug.handle(e);
-     * }
-     * 
- * - * The {@code name} argument is subject to the following type based conversion before having - * {@link Object#toString()} called on it: - * - *
-     *     Type          | Conversion
-     * ------------------+-----------------
-     *  java.lang.Class  | arg.getSimpleName()
-     *                   |
-     * 
- * - * @param name the name of the new scope - * @param contextObjects an array of object to be appended to the {@linkplain #context() - * current} debug context - * @throws Throwable used to enforce a catch block. - * @return the scope entered by this method which will be exited when its {@link Scope#close()} - * method is called - */ - public static Scope scope(Object name, Object[] contextObjects) throws Throwable { - if (ENABLED) { - return DebugScope.getInstance().scope(convertFormatArg(name).toString(), null, contextObjects); - } else { - return null; - } - } - - /** - * Similar to {@link #scope(Object, Object[])} but without context objects. Therefore the catch - * block can be omitted. - * - * @see #scope(Object, Object[]) - */ - public static Scope scope(Object name) { - if (ENABLED) { - return DebugScope.getInstance().scope(convertFormatArg(name).toString(), null); - } else { - return null; - } - } - - /** - * @see #scope(Object, Object[]) - * @param context an object to be appended to the {@linkplain #context() current} debug context - */ - public static Scope scope(Object name, Object context) throws Throwable { - if (ENABLED) { - return DebugScope.getInstance().scope(convertFormatArg(name).toString(), null, context); - } else { - return null; - } - } - - /** - * @see #scope(Object, Object[]) - * @param context1 first object to be appended to the {@linkplain #context() current} debug - * context - * @param context2 second object to be appended to the {@linkplain #context() current} debug - * context - */ - public static Scope scope(Object name, Object context1, Object context2) throws Throwable { - if (ENABLED) { - return DebugScope.getInstance().scope(convertFormatArg(name).toString(), null, context1, context2); - } else { - return null; - } - } - - /** - * @see #scope(Object, Object[]) - * @param context1 first object to be appended to the {@linkplain #context() current} debug - * context - * @param context2 second object to be appended to the {@linkplain #context() current} debug - * context - * @param context3 third object to be appended to the {@linkplain #context() current} debug - * context - */ - public static Scope scope(Object name, Object context1, Object context2, Object context3) throws Throwable { - if (ENABLED) { - return DebugScope.getInstance().scope(convertFormatArg(name).toString(), null, context1, context2, context3); - } else { - return null; - } - } - - /** - * Creates and enters a new debug scope which will be disjoint from the current debug scope. - *

- * It is recommended to use the try-with-resource statement for managing entering and leaving - * debug scopes. For example: - * - *

-     * try (Scope s = Debug.sandbox("CompilingStub", null, stubGraph)) {
-     *     ...
-     * } catch (Throwable e) {
-     *     throw Debug.handle(e);
-     * }
-     * 
- * - * @param name the name of the new scope - * @param config the debug configuration to use for the new scope - * @param context objects to be appended to the {@linkplain #context() current} debug context - * @return the scope entered by this method which will be exited when its {@link Scope#close()} - * method is called - */ - public static Scope sandbox(CharSequence name, DebugConfig config, Object... context) throws Throwable { - if (ENABLED) { - DebugConfig sandboxConfig = config == null ? silentConfig() : config; - return DebugScope.getInstance().scope(name, sandboxConfig, context); - } else { - return null; - } - } - - public static Scope forceLog() throws Throwable { - ArrayList context = new ArrayList<>(); - for (Object obj : context()) { - context.add(obj); - } - return Debug.sandbox("forceLog", new DelegatingDebugConfig().override(Level.LOG, Integer.MAX_VALUE).enable(LOG_METHOD), context.toArray()); - } - - /** - * Opens a scope in which exception {@linkplain DebugConfig#interceptException(Throwable) - * interception} is disabled. It is recommended to use the try-with-resource statement for - * managing entering and leaving such scopes: - * - *
-     * try (DebugConfigScope s = Debug.disableIntercept()) {
-     *     ...
-     * }
-     * 
- * - * This is particularly useful to suppress extraneous output in JUnit tests that are expected to - * throw an exception. - */ - public static DebugConfigScope disableIntercept() { - return Debug.setConfig(new DelegatingDebugConfig().disable(INTERCEPT)); - } - - /** - * Handles an exception in the context of the debug scope just exited. The just exited scope - * must have the current scope as its parent which will be the case if the try-with-resource - * pattern recommended by {@link #scope(Object)} and - * {@link #sandbox(CharSequence, DebugConfig, Object...)} is used - * - * @see #scope(Object, Object[]) - * @see #sandbox(CharSequence, DebugConfig, Object...) - */ - public static RuntimeException handle(Throwable exception) { - if (ENABLED) { - return DebugScope.getInstance().handle(exception); - } else { - if (exception instanceof Error) { - throw (Error) exception; - } - if (exception instanceof RuntimeException) { - throw (RuntimeException) exception; - } - throw new RuntimeException(exception); - } - } - - public static void log(String msg) { - log(DEFAULT_LOG_LEVEL, msg); - } - - /** - * Prints a message to the current debug scope's logging stream if logging is enabled. - * - * @param msg the message to log - */ - public static void log(int logLevel, String msg) { - if (ENABLED) { - DebugScope.getInstance().log(logLevel, msg); - } - } - - public static void log(String format, Object arg) { - log(DEFAULT_LOG_LEVEL, format, arg); - } - - /** - * Prints a message to the current debug scope's logging stream if logging is enabled. - * - * @param format a format string - * @param arg the argument referenced by the format specifiers in {@code format} - */ - public static void log(int logLevel, String format, Object arg) { - if (ENABLED) { - DebugScope.getInstance().log(logLevel, format, arg); - } - } - - public static void log(String format, int arg) { - log(DEFAULT_LOG_LEVEL, format, arg); - } - - /** - * Prints a message to the current debug scope's logging stream if logging is enabled. - * - * @param format a format string - * @param arg the argument referenced by the format specifiers in {@code format} - */ - public static void log(int logLevel, String format, int arg) { - if (ENABLED) { - DebugScope.getInstance().log(logLevel, format, arg); - } - } - - public static void log(String format, Object arg1, Object arg2) { - log(DEFAULT_LOG_LEVEL, format, arg1, arg2); - } - - /** - * @see #log(int, String, Object) - */ - public static void log(int logLevel, String format, Object arg1, Object arg2) { - if (ENABLED) { - DebugScope.getInstance().log(logLevel, format, arg1, arg2); - } - } - - public static void log(String format, int arg1, Object arg2) { - log(DEFAULT_LOG_LEVEL, format, arg1, arg2); - } - - /** - * @see #log(int, String, Object) - */ - public static void log(int logLevel, String format, int arg1, Object arg2) { - if (ENABLED) { - DebugScope.getInstance().log(logLevel, format, arg1, arg2); - } - } - - public static void log(String format, Object arg1, int arg2) { - log(DEFAULT_LOG_LEVEL, format, arg1, arg2); - } - - /** - * @see #log(int, String, Object) - */ - public static void log(int logLevel, String format, Object arg1, int arg2) { - if (ENABLED) { - DebugScope.getInstance().log(logLevel, format, arg1, arg2); - } - } - - public static void log(String format, int arg1, int arg2) { - log(DEFAULT_LOG_LEVEL, format, arg1, arg2); - } - - /** - * @see #log(int, String, Object) - */ - public static void log(int logLevel, String format, int arg1, int arg2) { - if (ENABLED) { - DebugScope.getInstance().log(logLevel, format, arg1, arg2); - } - } - - public static void log(String format, Object arg1, Object arg2, Object arg3) { - log(DEFAULT_LOG_LEVEL, format, arg1, arg2, arg3); - } - - /** - * @see #log(int, String, Object) - */ - public static void log(int logLevel, String format, Object arg1, Object arg2, Object arg3) { - if (ENABLED) { - DebugScope.getInstance().log(logLevel, format, arg1, arg2, arg3); - } - } - - public static void log(String format, int arg1, int arg2, int arg3) { - log(DEFAULT_LOG_LEVEL, format, arg1, arg2, arg3); - } - - /** - * @see #log(int, String, Object) - */ - public static void log(int logLevel, String format, int arg1, int arg2, int arg3) { - if (ENABLED) { - DebugScope.getInstance().log(logLevel, format, arg1, arg2, arg3); - } - } - - public static void log(String format, Object arg1, Object arg2, Object arg3, Object arg4) { - log(DEFAULT_LOG_LEVEL, format, arg1, arg2, arg3, arg4); - } - - /** - * @see #log(int, String, Object) - */ - public static void log(int logLevel, String format, Object arg1, Object arg2, Object arg3, Object arg4) { - if (ENABLED) { - DebugScope.getInstance().log(logLevel, format, arg1, arg2, arg3, arg4); - } - } - - public static void log(String format, Object arg1, Object arg2, Object arg3, Object arg4, Object arg5) { - log(DEFAULT_LOG_LEVEL, format, arg1, arg2, arg3, arg4, arg5); - } - - /** - * @see #log(int, String, Object) - */ - public static void log(int logLevel, String format, Object arg1, Object arg2, Object arg3, Object arg4, Object arg5) { - if (ENABLED) { - DebugScope.getInstance().log(logLevel, format, arg1, arg2, arg3, arg4, arg5); - } - } - - public static void log(String format, Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6) { - log(DEFAULT_LOG_LEVEL, format, arg1, arg2, arg3, arg4, arg5, arg6); - } - - /** - * @see #log(int, String, Object) - */ - public static void log(int logLevel, String format, Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6) { - if (ENABLED) { - DebugScope.getInstance().log(logLevel, format, arg1, arg2, arg3, arg4, arg5, arg6); - } - } - - public static void log(String format, Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7) { - log(DEFAULT_LOG_LEVEL, format, arg1, arg2, arg3, arg4, arg5, arg6, arg7); - } - - public static void log(String format, Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, Object arg8) { - log(DEFAULT_LOG_LEVEL, format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8); - } - - /** - * @see #log(int, String, Object) - */ - public static void log(int logLevel, String format, Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7) { - if (ENABLED) { - DebugScope.getInstance().log(logLevel, format, arg1, arg2, arg3, arg4, arg5, arg6, arg7); - } - } - - public static void log(int logLevel, String format, Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, Object arg8) { - if (ENABLED) { - DebugScope.getInstance().log(logLevel, format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8); - } - } - - public static void logv(String format, Object... args) { - logv(DEFAULT_LOG_LEVEL, format, args); - } - - /** - * Prints a message to the current debug scope's logging stream. This method must only be called - * if debugging is {@linkplain Debug#isEnabled() enabled} as it incurs allocation at the call - * site. If possible, call one of the other {@code log()} methods in this class that take a - * fixed number of parameters. - * - * @param format a format string - * @param args the arguments referenced by the format specifiers in {@code format} - */ - public static void logv(int logLevel, String format, Object... args) { - if (!ENABLED) { - throw new InternalError("Use of Debug.logv() must be guarded by a test of Debug.isEnabled()"); - } - DebugScope.getInstance().log(logLevel, format, args); - } - - /** - * This override exists to catch cases when {@link #log(String, Object)} is called with one - * argument bound to a varargs method parameter. It will bind to this method instead of the - * single arg variant and produce a deprecation warning instead of silently wrapping the - * Object[] inside of another Object[]. - */ - @Deprecated - public static void log(String format, Object[] args) { - assert false : "shouldn't use this"; - log(DEFAULT_LOG_LEVEL, format, args); - } - - /** - * This override exists to catch cases when {@link #log(int, String, Object)} is called with one - * argument bound to a varargs method parameter. It will bind to this method instead of the - * single arg variant and produce a deprecation warning instead of silently wrapping the - * Object[] inside of another Object[]. - */ - @Deprecated - public static void log(int logLevel, String format, Object[] args) { - assert false : "shouldn't use this"; - logv(logLevel, format, args); - } - - public static void dump(Object object, String msg) { - dump(DEFAULT_LOG_LEVEL, object, msg); - } - - public static void dump(int dumpLevel, Object object, String msg) { - if (ENABLED && DebugScope.getInstance().isDumpEnabled(dumpLevel)) { - DebugScope.getInstance().dump(dumpLevel, object, msg); - } - } - - public static void dump(Object object, String format, Object arg) { - dump(DEFAULT_LOG_LEVEL, object, format, arg); - } - - public static void dump(int dumpLevel, Object object, String format, Object arg) { - if (ENABLED && DebugScope.getInstance().isDumpEnabled(dumpLevel)) { - DebugScope.getInstance().dump(dumpLevel, object, format, arg); - } - } - - public static void dump(Object object, String format, Object arg1, Object arg2) { - dump(DEFAULT_LOG_LEVEL, object, format, arg1, arg2); - } - - public static void dump(int dumpLevel, Object object, String format, Object arg1, Object arg2) { - if (ENABLED && DebugScope.getInstance().isDumpEnabled(dumpLevel)) { - DebugScope.getInstance().dump(dumpLevel, object, format, arg1, arg2); - } - } - - public static void dump(Object object, String format, Object arg1, Object arg2, Object arg3) { - dump(DEFAULT_LOG_LEVEL, object, format, arg1, arg2, arg3); - } - - public static void dump(int dumpLevel, Object object, String format, Object arg1, Object arg2, Object arg3) { - if (ENABLED && DebugScope.getInstance().isDumpEnabled(dumpLevel)) { - DebugScope.getInstance().dump(dumpLevel, object, format, arg1, arg2, arg3); - } - } - - /** - * This override exists to catch cases when {@link #dump(Object, String, Object)} is called with - * one argument bound to a varargs method parameter. It will bind to this method instead of the - * single arg variant and produce a deprecation warning instead of silently wrapping the - * Object[] inside of another Object[]. - */ - @Deprecated - public static void dump(Object object, String format, Object[] args) { - assert false : "shouldn't use this"; - dump(DEFAULT_LOG_LEVEL, object, format, args); - } - - /** - * This override exists to catch cases when {@link #dump(int, Object, String, Object)} is called - * with one argument bound to a varargs method parameter. It will bind to this method instead of - * the single arg variant and produce a deprecation warning instead of silently wrapping the - * Object[] inside of another Object[]. - */ - @Deprecated - public static void dump(int dumpLevel, Object object, String format, Object[] args) { - assert false : "shouldn't use this"; - if (ENABLED && DebugScope.getInstance().isDumpEnabled(dumpLevel)) { - DebugScope.getInstance().dump(dumpLevel, object, format, args); - } - } - - /** - * Calls all {@link DebugVerifyHandler}s in the current {@linkplain DebugScope#getConfig() - * config} to perform verification on a given object. - * - * @param object object to verify - * @param message description of verification context - * - * @see DebugVerifyHandler#verify(Object, String) - */ - public static void verify(Object object, String message) { - if (ENABLED && DebugScope.getInstance().isVerifyEnabled()) { - DebugScope.getInstance().verify(object, message); - } - } - - /** - * Calls all {@link DebugVerifyHandler}s in the current {@linkplain DebugScope#getConfig() - * config} to perform verification on a given object. - * - * @param object object to verify - * @param format a format string for the description of the verification context - * @param arg the argument referenced by the format specifiers in {@code format} - * - * @see DebugVerifyHandler#verify(Object, String) - */ - public static void verify(Object object, String format, Object arg) { - if (ENABLED && DebugScope.getInstance().isVerifyEnabled()) { - DebugScope.getInstance().verify(object, format, arg); - } - } - - /** - * This override exists to catch cases when {@link #verify(Object, String, Object)} is called - * with one argument bound to a varargs method parameter. It will bind to this method instead of - * the single arg variant and produce a deprecation warning instead of silently wrapping the - * Object[] inside of another Object[]. - */ - @Deprecated - public static void verify(Object object, String format, Object[] args) { - assert false : "shouldn't use this"; - if (ENABLED && DebugScope.getInstance().isVerifyEnabled()) { - DebugScope.getInstance().verify(object, format, args); - } - } - - /** - * Opens a new indentation level (by adding some spaces) based on the current indentation level. - * This should be used in a {@linkplain Indent try-with-resources} pattern. - * - * @return an object that reverts to the current indentation level when - * {@linkplain Indent#close() closed} or null if debugging is disabled - * @see #logAndIndent(int, String) - * @see #logAndIndent(int, String, Object) - */ - public static Indent indent() { - if (ENABLED) { - DebugScope scope = DebugScope.getInstance(); - return scope.pushIndentLogger(); - } - return null; - } - - public static Indent logAndIndent(String msg) { - return logAndIndent(DEFAULT_LOG_LEVEL, msg); - } - - /** - * A convenience function which combines {@link #log(String)} and {@link #indent()}. - * - * @param msg the message to log - * @return an object that reverts to the current indentation level when - * {@linkplain Indent#close() closed} or null if debugging is disabled - */ - public static Indent logAndIndent(int logLevel, String msg) { - if (ENABLED && Debug.isLogEnabled(logLevel)) { - return logvAndIndentInternal(logLevel, msg); - } - return null; - } - - public static Indent logAndIndent(String format, Object arg) { - return logAndIndent(DEFAULT_LOG_LEVEL, format, arg); - } - - /** - * A convenience function which combines {@link #log(String, Object)} and {@link #indent()}. - * - * @param format a format string - * @param arg the argument referenced by the format specifiers in {@code format} - * @return an object that reverts to the current indentation level when - * {@linkplain Indent#close() closed} or null if debugging is disabled - */ - public static Indent logAndIndent(int logLevel, String format, Object arg) { - if (ENABLED && Debug.isLogEnabled(logLevel)) { - return logvAndIndentInternal(logLevel, format, arg); - } - return null; - } - - public static Indent logAndIndent(String format, int arg) { - return logAndIndent(DEFAULT_LOG_LEVEL, format, arg); - } - - /** - * A convenience function which combines {@link #log(String, Object)} and {@link #indent()}. - * - * @param format a format string - * @param arg the argument referenced by the format specifiers in {@code format} - * @return an object that reverts to the current indentation level when - * {@linkplain Indent#close() closed} or null if debugging is disabled - */ - public static Indent logAndIndent(int logLevel, String format, int arg) { - if (ENABLED && Debug.isLogEnabled(logLevel)) { - return logvAndIndentInternal(logLevel, format, arg); - } - return null; - } - - public static Indent logAndIndent(String format, int arg1, Object arg2) { - return logAndIndent(DEFAULT_LOG_LEVEL, format, arg1, arg2); - } - - /** - * @see #logAndIndent(int, String, Object) - */ - public static Indent logAndIndent(int logLevel, String format, int arg1, Object arg2) { - if (ENABLED && Debug.isLogEnabled(logLevel)) { - return logvAndIndentInternal(logLevel, format, arg1, arg2); - } - return null; - } - - public static Indent logAndIndent(String format, Object arg1, int arg2) { - return logAndIndent(DEFAULT_LOG_LEVEL, format, arg1, arg2); - } - - /** - * @see #logAndIndent(int, String, Object) - */ - public static Indent logAndIndent(int logLevel, String format, Object arg1, int arg2) { - if (ENABLED && Debug.isLogEnabled(logLevel)) { - return logvAndIndentInternal(logLevel, format, arg1, arg2); - } - return null; - } - - public static Indent logAndIndent(String format, int arg1, int arg2) { - return logAndIndent(DEFAULT_LOG_LEVEL, format, arg1, arg2); - } - - /** - * @see #logAndIndent(int, String, Object) - */ - public static Indent logAndIndent(int logLevel, String format, int arg1, int arg2) { - if (ENABLED && Debug.isLogEnabled(logLevel)) { - return logvAndIndentInternal(logLevel, format, arg1, arg2); - } - return null; - } - - public static Indent logAndIndent(String format, Object arg1, Object arg2) { - return logAndIndent(DEFAULT_LOG_LEVEL, format, arg1, arg2); - } - - /** - * @see #logAndIndent(int, String, Object) - */ - public static Indent logAndIndent(int logLevel, String format, Object arg1, Object arg2) { - if (ENABLED && Debug.isLogEnabled(logLevel)) { - return logvAndIndentInternal(logLevel, format, arg1, arg2); - } - return null; - } - - public static Indent logAndIndent(String format, Object arg1, Object arg2, Object arg3) { - return logAndIndent(DEFAULT_LOG_LEVEL, format, arg1, arg2, arg3); - } - - /** - * @see #logAndIndent(int, String, Object) - */ - public static Indent logAndIndent(int logLevel, String format, Object arg1, Object arg2, Object arg3) { - if (ENABLED && Debug.isLogEnabled(logLevel)) { - return logvAndIndentInternal(logLevel, format, arg1, arg2, arg3); - } - return null; - } - - public static Indent logAndIndent(String format, int arg1, int arg2, int arg3) { - return logAndIndent(DEFAULT_LOG_LEVEL, format, arg1, arg2, arg3); - } - - /** - * @see #logAndIndent(int, String, Object) - */ - public static Indent logAndIndent(int logLevel, String format, int arg1, int arg2, int arg3) { - if (ENABLED && Debug.isLogEnabled(logLevel)) { - return logvAndIndentInternal(logLevel, format, arg1, arg2, arg3); - } - return null; - } - - public static Indent logAndIndent(String format, Object arg1, int arg2, int arg3) { - return logAndIndent(DEFAULT_LOG_LEVEL, format, arg1, arg2, arg3); - } - - /** - * @see #logAndIndent(int, String, Object) - */ - public static Indent logAndIndent(int logLevel, String format, Object arg1, int arg2, int arg3) { - if (ENABLED && Debug.isLogEnabled(logLevel)) { - return logvAndIndentInternal(logLevel, format, arg1, arg2, arg3); - } - return null; - } - - public static Indent logAndIndent(String format, Object arg1, Object arg2, Object arg3, Object arg4) { - return logAndIndent(DEFAULT_LOG_LEVEL, format, arg1, arg2, arg3, arg4); - } - - /** - * @see #logAndIndent(int, String, Object) - */ - public static Indent logAndIndent(int logLevel, String format, Object arg1, Object arg2, Object arg3, Object arg4) { - if (ENABLED && Debug.isLogEnabled(logLevel)) { - return logvAndIndentInternal(logLevel, format, arg1, arg2, arg3, arg4); - } - return null; - } - - public static Indent logAndIndent(String format, Object arg1, Object arg2, Object arg3, Object arg4, Object arg5) { - return logAndIndent(DEFAULT_LOG_LEVEL, format, arg1, arg2, arg3, arg4, arg5); - } - - /** - * @see #logAndIndent(int, String, Object) - */ - public static Indent logAndIndent(int logLevel, String format, Object arg1, Object arg2, Object arg3, Object arg4, Object arg5) { - if (ENABLED && Debug.isLogEnabled(logLevel)) { - return logvAndIndentInternal(logLevel, format, arg1, arg2, arg3, arg4, arg5); - } - return null; - } - - public static Indent logAndIndent(String format, Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6) { - return logAndIndent(DEFAULT_LOG_LEVEL, format, arg1, arg2, arg3, arg4, arg5, arg6); - } - - /** - * @see #logAndIndent(int, String, Object) - */ - public static Indent logAndIndent(int logLevel, String format, Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6) { - if (ENABLED && Debug.isLogEnabled(logLevel)) { - return logvAndIndentInternal(logLevel, format, arg1, arg2, arg3, arg4, arg5, arg6); - } - return null; - } - - /** - * A convenience function which combines {@link #logv(int, String, Object...)} and - * {@link #indent()}. - * - * @param format a format string - * @param args the arguments referenced by the format specifiers in {@code format} - * @return an object that reverts to the current indentation level when - * {@linkplain Indent#close() closed} or null if debugging is disabled - */ - public static Indent logvAndIndent(int logLevel, String format, Object... args) { - if (ENABLED) { - if (Debug.isLogEnabled(logLevel)) { - return logvAndIndentInternal(logLevel, format, args); - } - return null; - } - throw new InternalError("Use of Debug.logvAndIndent() must be guarded by a test of Debug.isEnabled()"); - } - - private static Indent logvAndIndentInternal(int logLevel, String format, Object... args) { - assert ENABLED && Debug.isLogEnabled(logLevel) : "must have checked Debug.isLogEnabled()"; - DebugScope scope = DebugScope.getInstance(); - scope.log(logLevel, format, args); - return scope.pushIndentLogger(); - } - - /** - * This override exists to catch cases when {@link #logAndIndent(String, Object)} is called with - * one argument bound to a varargs method parameter. It will bind to this method instead of the - * single arg variant and produce a deprecation warning instead of silently wrapping the - * Object[] inside of another Object[]. - */ - @Deprecated - public static void logAndIndent(String format, Object[] args) { - assert false : "shouldn't use this"; - logAndIndent(DEFAULT_LOG_LEVEL, format, args); - } - - /** - * This override exists to catch cases when {@link #logAndIndent(int, String, Object)} is called - * with one argument bound to a varargs method parameter. It will bind to this method instead of - * the single arg variant and produce a deprecation warning instead of silently wrapping the - * Object[] inside of another Object[]. - */ - @Deprecated - public static void logAndIndent(int logLevel, String format, Object[] args) { - assert false : "shouldn't use this"; - logvAndIndent(logLevel, format, args); - } - - public static Iterable context() { - if (ENABLED) { - return DebugScope.getInstance().getCurrentContext(); - } else { - return Collections.emptyList(); - } - } - - @SuppressWarnings("unchecked") - public static List contextSnapshot(Class clazz) { - if (ENABLED) { - List result = new ArrayList<>(); - for (Object o : context()) { - if (clazz.isInstance(o)) { - result.add((T) o); - } - } - return result; - } else { - return Collections.emptyList(); - } - } - - /** - * Searches the current debug scope, bottom up, for a context object that is an instance of a - * given type. The first such object found is returned. - */ - @SuppressWarnings("unchecked") - public static T contextLookup(Class clazz) { - if (ENABLED) { - for (Object o : context()) { - if (clazz.isInstance(o)) { - return ((T) o); - } - } - } - return null; - } - - /** - * Creates a {@linkplain DebugMemUseTracker memory use tracker} that is enabled iff debugging is - * {@linkplain #isEnabled() enabled}. - *

- * A disabled tracker has virtually no overhead. - */ - public static DebugMemUseTracker memUseTracker(CharSequence name) { - if (!isUnconditionalMemUseTrackingEnabled && !ENABLED) { - return VOID_MEM_USE_TRACKER; - } - return createMemUseTracker("%s", name, null); - } - - /** - * Creates a debug memory use tracker. Invoking this method is equivalent to: - * - *

-     * Debug.memUseTracker(format, arg, null)
-     * 
- * - * except that the string formatting only happens if metering is enabled. - * - * @see #metric(String, Object, Object) - */ - public static DebugMemUseTracker memUseTracker(String format, Object arg) { - if (!isUnconditionalMemUseTrackingEnabled && !ENABLED) { - return VOID_MEM_USE_TRACKER; - } - return createMemUseTracker(format, arg, null); - } - - /** - * Creates a debug memory use tracker. Invoking this method is equivalent to: - * - *
-     * Debug.memUseTracker(String.format(format, arg1, arg2))
-     * 
- * - * except that the string formatting only happens if memory use tracking is enabled. In - * addition, each argument is subject to the following type based conversion before being passed - * as an argument to {@link String#format(String, Object...)}: - * - *
-     *     Type          | Conversion
-     * ------------------+-----------------
-     *  java.lang.Class  | arg.getSimpleName()
-     *                   |
-     * 
- * - * @see #memUseTracker(CharSequence) - */ - public static DebugMemUseTracker memUseTracker(String format, Object arg1, Object arg2) { - if (!isUnconditionalMemUseTrackingEnabled && !ENABLED) { - return VOID_MEM_USE_TRACKER; - } - return createMemUseTracker(format, arg1, arg2); - } - - private static DebugMemUseTracker createMemUseTracker(String format, Object arg1, Object arg2) { - String name = formatDebugName(format, arg1, arg2); - return new MemUseTrackerImpl(name, !isUnconditionalMemUseTrackingEnabled); - } - - /** - * Creates a {@linkplain DebugMetric metric} that is enabled iff debugging is - * {@linkplain #isEnabled() enabled} or the system property whose name is formed by adding to - * {@value #ENABLE_METRIC_PROPERTY_NAME_PREFIX} to {@code name} is - * {@linkplain Boolean#getBoolean(String) true}. If the latter condition is true, then the - * returned metric is {@linkplain DebugMetric#isConditional() unconditional} otherwise it is - * conditional. - *

- * A disabled metric has virtually no overhead. - */ - public static DebugMetric metric(CharSequence name) { - if (!areUnconditionalMetricsEnabled() && !ENABLED) { - return VOID_METRIC; - } - return createMetric("%s", name, null); - } - - public static String applyFormattingFlagsAndWidth(String s, int flags, int width) { - if (flags == 0 && width < 0) { - return s; - } - StringBuilder sb = new StringBuilder(s); - - // apply width and justification - int len = sb.length(); - if (len < width) { - for (int i = 0; i < width - len; i++) { - if ((flags & LEFT_JUSTIFY) == LEFT_JUSTIFY) { - sb.append(' '); - } else { - sb.insert(0, ' '); - } - } - } - - String res = sb.toString(); - if ((flags & UPPERCASE) == UPPERCASE) { - res = res.toUpperCase(); - } - return res; - } - - /** - * Creates a debug metric. Invoking this method is equivalent to: - * - *

-     * Debug.metric(format, arg, null)
-     * 
- * - * except that the string formatting only happens if metering is enabled. - * - * @see #metric(String, Object, Object) - */ - public static DebugMetric metric(String format, Object arg) { - if (!areUnconditionalMetricsEnabled() && !ENABLED) { - return VOID_METRIC; - } - return createMetric(format, arg, null); - } - - /** - * Creates a debug metric. Invoking this method is equivalent to: - * - *
-     * Debug.metric(String.format(format, arg1, arg2))
-     * 
- * - * except that the string formatting only happens if metering is enabled. In addition, each - * argument is subject to the following type based conversion before being passed as an argument - * to {@link String#format(String, Object...)}: - * - *
-     *     Type          | Conversion
-     * ------------------+-----------------
-     *  java.lang.Class  | arg.getSimpleName()
-     *                   |
-     * 
- * - * @see #metric(CharSequence) - */ - public static DebugMetric metric(String format, Object arg1, Object arg2) { - if (!areUnconditionalMetricsEnabled() && !ENABLED) { - return VOID_METRIC; - } - return createMetric(format, arg1, arg2); - } - - private static DebugMetric createMetric(String format, Object arg1, Object arg2) { - String name = formatDebugName(format, arg1, arg2); - boolean conditional = enabledMetrics == null || !findMatch(enabledMetrics, enabledMetricsSubstrings, name); - if (!ENABLED && conditional) { - return VOID_METRIC; - } - return new MetricImpl(name, conditional); - } - - /** - * Changes the debug configuration for the current thread. - * - * @param config new configuration to use for the current thread - * @return an object that when {@linkplain DebugConfigScope#close() closed} will restore the - * debug configuration for the current thread to what it was before this method was - * called - */ - public static DebugConfigScope setConfig(DebugConfig config) { - if (ENABLED) { - return new DebugConfigScope(config); - } else { - return null; - } - } - - /** - * Creates an object for counting value frequencies. - */ - public static DebugHistogram createHistogram(String name) { - return new DebugHistogramImpl(name); - } - - public static DebugConfig silentConfig() { - return fixedConfig(0, 0, false, false, false, false, Collections. emptyList(), Collections. emptyList(), null); - } - - public static DebugConfig fixedConfig(final int logLevel, final int dumpLevel, final boolean isMeterEnabled, final boolean isMemUseTrackingEnabled, final boolean isTimerEnabled, - final boolean isVerifyEnabled, final Collection dumpHandlers, final Collection verifyHandlers, final PrintStream output) { - return new DebugConfig() { - - @Override - public int getLogLevel() { - return logLevel; - } - - public boolean isLogEnabledForMethod() { - return logLevel > 0; - } - - @Override - public boolean isMeterEnabled() { - return isMeterEnabled; - } - - @Override - public boolean isMemUseTrackingEnabled() { - return isMemUseTrackingEnabled; - } - - @Override - public int getDumpLevel() { - return dumpLevel; - } - - public boolean isDumpEnabledForMethod() { - return dumpLevel > 0; - } - - @Override - public boolean isVerifyEnabled() { - return isVerifyEnabled; - } - - public boolean isVerifyEnabledForMethod() { - return isVerifyEnabled; - } - - @Override - public boolean isTimeEnabled() { - return isTimerEnabled; - } - - @Override - public RuntimeException interceptException(Throwable e) { - return null; - } - - @Override - public Collection dumpHandlers() { - return dumpHandlers; - } - - @Override - public Collection verifyHandlers() { - return verifyHandlers; - } - - @Override - public PrintStream output() { - return output; - } - - @Override - public void addToContext(Object o) { - } - - @Override - public void removeFromContext(Object o) { - } - }; - } - - private static final DebugMetric VOID_METRIC = new DebugMetric() { - - public void increment() { - } - - public void add(long value) { - } - - public void setConditional(boolean flag) { - throw new InternalError("Cannot make void metric conditional"); - } - - public boolean isConditional() { - return false; - } - - public long getCurrentValue() { - return 0L; - } - }; - - private static final DebugMemUseTracker VOID_MEM_USE_TRACKER = new DebugMemUseTracker() { - - public DebugCloseable start() { - return DebugCloseable.VOID_CLOSEABLE; - } - - public long getCurrentValue() { - return 0; - } - }; - - public static final String ENABLE_UNSCOPED_TIMERS_PROPERTY_NAME = "jvmci.debug.unscopedTimers"; - public static final String ENABLE_UNSCOPED_METRICS_PROPERTY_NAME = "jvmci.debug.unscopedMetrics"; - public static final String ENABLE_UNSCOPED_MEM_USE_TRACKERS_PROPERTY_NAME = "jvmci.debug.unscopedMemUseTrackers"; - - /** - * @see #timer(CharSequence) - */ - public static final String ENABLE_TIMER_PROPERTY_NAME_PREFIX = "jvmci.debug.timer."; - - /** - * @see #metric(CharSequence) - */ - public static final String ENABLE_METRIC_PROPERTY_NAME_PREFIX = "jvmci.debug.metric."; - - /** - * Set of unconditionally enabled metrics. Possible values and their meanings: - *
    - *
  • {@code null}: no unconditionally enabled metrics
  • - *
  • {@code isEmpty()}: all metrics are unconditionally enabled
  • - *
  • {@code !isEmpty()}: use {@link #findMatch(Set, Set, String)} on this set and - * {@link #enabledMetricsSubstrings} to determine which metrics are unconditionally enabled
  • - *
- */ - private static final Set enabledMetrics; - - /** - * Set of unconditionally enabled timers. Same interpretation of values as for - * {@link #enabledMetrics}. - */ - private static final Set enabledTimers; - - private static final Set enabledMetricsSubstrings = new HashSet<>(); - private static final Set enabledTimersSubstrings = new HashSet<>(); - - /** - * Specifies if all mem use trackers are unconditionally enabled. - */ - private static final boolean isUnconditionalMemUseTrackingEnabled; - - static { - Set metrics = new HashSet<>(); - Set timers = new HashSet<>(); - parseMetricAndTimerSystemProperties(metrics, timers, enabledMetricsSubstrings, enabledTimersSubstrings); - metrics = metrics.isEmpty() && enabledMetricsSubstrings.isEmpty() ? null : metrics; - timers = timers.isEmpty() && enabledTimersSubstrings.isEmpty() ? null : timers; - if (metrics == null && Boolean.getBoolean(ENABLE_UNSCOPED_METRICS_PROPERTY_NAME)) { - metrics = Collections.emptySet(); - } - if (timers == null && Boolean.getBoolean(ENABLE_UNSCOPED_TIMERS_PROPERTY_NAME)) { - timers = Collections.emptySet(); - } - enabledMetrics = metrics; - enabledTimers = timers; - isUnconditionalMemUseTrackingEnabled = Boolean.getBoolean(ENABLE_UNSCOPED_MEM_USE_TRACKERS_PROPERTY_NAME); - } - - private static boolean findMatch(Set haystack, Set haystackSubstrings, String needle) { - if (haystack.isEmpty()) { - // Empty haystack means match all - return true; - } - if (haystack.contains(needle)) { - return true; - } - if (!haystackSubstrings.isEmpty()) { - for (String h : haystackSubstrings) { - if (needle.startsWith(h)) { - return true; - } - } - } - return false; - } - - public static boolean areUnconditionalTimersEnabled() { - return enabledTimers != null; - } - - public static boolean areUnconditionalMetricsEnabled() { - return enabledMetrics != null; - } - - protected static void parseMetricAndTimerSystemProperties(Set metrics, Set timers, Set metricsSubstrings, Set timersSubstrings) { - do { - try { - for (Map.Entry e : System.getProperties().entrySet()) { - String name = e.getKey().toString(); - if (name.startsWith(ENABLE_METRIC_PROPERTY_NAME_PREFIX) && Boolean.parseBoolean(e.getValue().toString())) { - if (name.endsWith("*")) { - metricsSubstrings.add(name.substring(ENABLE_METRIC_PROPERTY_NAME_PREFIX.length(), name.length() - 1)); - } else { - metrics.add(name.substring(ENABLE_METRIC_PROPERTY_NAME_PREFIX.length())); - } - } - if (name.startsWith(ENABLE_TIMER_PROPERTY_NAME_PREFIX) && Boolean.parseBoolean(e.getValue().toString())) { - if (name.endsWith("*")) { - timersSubstrings.add(name.substring(ENABLE_TIMER_PROPERTY_NAME_PREFIX.length(), name.length() - 1)); - } else { - timers.add(name.substring(ENABLE_TIMER_PROPERTY_NAME_PREFIX.length())); - } - } - } - return; - } catch (ConcurrentModificationException e) { - // Iterating over the system properties may race with another thread that is - // updating the system properties. Simply try again in this case. - } - } while (true); - } - - /** - * Creates a {@linkplain DebugTimer timer} that is enabled iff debugging is - * {@linkplain #isEnabled() enabled} or the system property whose name is formed by adding to - * {@value #ENABLE_TIMER_PROPERTY_NAME_PREFIX} to {@code name} is - * {@linkplain Boolean#getBoolean(String) true}. If the latter condition is true, then the - * returned timer is {@linkplain DebugMetric#isConditional() unconditional} otherwise it is - * conditional. - *

- * A disabled timer has virtually no overhead. - */ - public static DebugTimer timer(CharSequence name) { - if (!areUnconditionalTimersEnabled() && !ENABLED) { - return VOID_TIMER; - } - return createTimer("%s", name, null); - } - - /** - * Creates a debug timer. Invoking this method is equivalent to: - * - *

-     * Debug.timer(format, arg, null)
-     * 
- * - * except that the string formatting only happens if timing is enabled. - * - * @see #timer(String, Object, Object) - */ - public static DebugTimer timer(String format, Object arg) { - if (!areUnconditionalTimersEnabled() && !ENABLED) { - return VOID_TIMER; - } - return createTimer(format, arg, null); - } - - /** - * Creates a debug timer. Invoking this method is equivalent to: - * - *
-     * Debug.timer(String.format(format, arg1, arg2))
-     * 
- * - * except that the string formatting only happens if timing is enabled. In addition, each - * argument is subject to the following type based conversion before being passed as an argument - * to {@link String#format(String, Object...)}: - * - *
-     *     Type          | Conversion
-     * ------------------+-----------------
-     *  java.lang.Class  | arg.getSimpleName()
-     *                   |
-     * 
- * - * @see #timer(CharSequence) - */ - public static DebugTimer timer(String format, Object arg1, Object arg2) { - if (!areUnconditionalTimersEnabled() && !ENABLED) { - return VOID_TIMER; - } - return createTimer(format, arg1, arg2); - } - - /** - * There are paths where construction of formatted class names are common and the code below is - * surprisingly expensive, so compute it once and cache it. - */ - private static final ClassValue formattedClassName = new ClassValue() { - @Override - protected String computeValue(Class c) { - final String simpleName = c.getSimpleName(); - Class enclosingClass = c.getEnclosingClass(); - if (enclosingClass != null) { - String prefix = ""; - while (enclosingClass != null) { - prefix = enclosingClass.getSimpleName() + "_" + prefix; - enclosingClass = enclosingClass.getEnclosingClass(); - } - return prefix + simpleName; - } else { - return simpleName; - } - } - }; - - public static Object convertFormatArg(Object arg) { - if (arg instanceof Class) { - return formattedClassName.get((Class) arg); - } - return arg; - } - - private static String formatDebugName(String format, Object arg1, Object arg2) { - return String.format(format, convertFormatArg(arg1), convertFormatArg(arg2)); - } - - private static DebugTimer createTimer(String format, Object arg1, Object arg2) { - String name = formatDebugName(format, arg1, arg2); - boolean conditional = enabledTimers == null || !findMatch(enabledTimers, enabledTimersSubstrings, name); - if (!ENABLED && conditional) { - return VOID_TIMER; - } - return new TimerImpl(name, conditional); - } - - private static final DebugTimer VOID_TIMER = new DebugTimer() { - - public DebugCloseable start() { - return DebugCloseable.VOID_CLOSEABLE; - } - - public void setConditional(boolean flag) { - throw new InternalError("Cannot make void timer conditional"); - } - - public boolean isConditional() { - return false; - } - - public long getCurrentValue() { - return 0L; - } - - public TimeUnit getTimeUnit() { - return null; - } - }; -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/DebugCloseable.java --- a/graal/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/DebugCloseable.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,39 +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.jvmci.debug; - -/** - * An object returned by {@link DebugTimer#start()} that when closed, stops the associated timer and - * adds the elapsed time since {@code start()} to the total for the timer. - */ -public interface DebugCloseable extends AutoCloseable { - - DebugCloseable VOID_CLOSEABLE = new DebugCloseable() { - - @Override - public void close() { - } - }; - - void close(); -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/DebugConfig.java --- a/graal/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/DebugConfig.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,116 +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.jvmci.debug; - -import java.io.*; -import java.util.*; - -public interface DebugConfig { - - /** - * Determines the current log level in the {@linkplain Debug#currentScope() current debug scope} - * . - */ - int getLogLevel(); - - /** - * Determines the current dump level in the {@linkplain Debug#currentScope() current debug - * scope}. - */ - int getDumpLevel(); - - /** - * Determines if logging can be enabled in the current method, regardless of the - * {@linkplain Debug#currentScope() current debug scope}. - */ - boolean isLogEnabledForMethod(); - - /** - * Determines if metering is enabled in the {@linkplain Debug#currentScope() current debug - * scope}. - * - * @see Debug#metric(CharSequence) - */ - boolean isMeterEnabled(); - - /** - * Determines if memory use tracking is enabled in the {@linkplain Debug#currentScope() current - * debug scope}. - * - * @see Debug#memUseTracker(CharSequence) - */ - boolean isMemUseTrackingEnabled(); - - /** - * Determines if dumping can be enabled in the current method, regardless of the - * {@linkplain Debug#currentScope() current debug scope}. - */ - boolean isDumpEnabledForMethod(); - - /** - * @see Debug#isVerifyEnabled() - */ - boolean isVerifyEnabled(); - - /** - * @see Debug#isVerifyEnabledForMethod() - */ - boolean isVerifyEnabledForMethod(); - - /** - * Adds an object the context used by this configuration to do filtering. - */ - void addToContext(Object o); - - /** - * Removes an object the context used by this configuration to do filtering. - * - * This should only removes extra context added by {@link #addToContext(Object)}. - */ - void removeFromContext(Object o); - - /** - * @see Debug#timer(CharSequence) - */ - boolean isTimeEnabled(); - - /** - * Handles notification of an exception occurring within a debug scope. - * - * @return the exception object that is to be propagated to parent scope. A value of - * {@code null} indicates that {@code e} is to be propagated. - */ - RuntimeException interceptException(Throwable e); - - /** - * Gets the modifiable collection of dump handlers registered with this configuration. - */ - Collection dumpHandlers(); - - PrintStream output(); - - /** - * Gets the modifiable collection of verify handlers registered with this configuration. - */ - Collection verifyHandlers(); -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/DebugConfigCustomizer.java --- a/graal/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/DebugConfigCustomizer.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,29 +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.jvmci.debug; - -import com.oracle.jvmci.service.*; - -public interface DebugConfigCustomizer extends Service { - void customize(DebugConfig config); -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/DebugConfigScope.java --- a/graal/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/DebugConfigScope.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,55 +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.jvmci.debug; - -import com.oracle.jvmci.debug.internal.*; - -/** - * A utility for scoping a change to the current debug - * {@linkplain DebugScope#setConfig(DebugConfig) configuration}. For example: - * - *
- *     DebugConfig config = ...;
- *     try (DebugConfigScope s = new DebugConfigScope(config)) {
- *         // ...
- *     }
- * 
- */ -public class DebugConfigScope implements AutoCloseable { - - private final DebugConfig current; - - /** - * Sets the current debug {@linkplain DebugScope#setConfig(DebugConfig) configuration} to a - * given value and creates an object that when {@linkplain #close() closed} resets the - * configuration to the {@linkplain DebugScope#getConfig() current} configuration. - */ - public DebugConfigScope(DebugConfig config) { - this.current = DebugScope.getConfig(); - DebugScope.getInstance().setConfig(config); - } - - public void close() { - DebugScope.getInstance().setConfig(current); - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/DebugDumpHandler.java --- a/graal/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/DebugDumpHandler.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,38 +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.jvmci.debug; - -import java.io.*; - -public interface DebugDumpHandler extends Closeable { - - void dump(Object object, String message); - - /** - * Flushes and releases resources managed by this dump handler. A subsequent call to - * {@link #dump(Object, String)} will create and open new resources. That is, this method can be - * used to reset the handler. - */ - @Override - void close(); -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/DebugDumpScope.java --- a/graal/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/DebugDumpScope.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,49 +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.jvmci.debug; - -public class DebugDumpScope { - - public final String name; - - /** - * Specifies if this scope decorates an inner scope. A hierarchical or tree representation of - * nested scopes may choose to represent a decorator scope at the same level as the scope it - * decorates. - */ - public final boolean decorator; - - public DebugDumpScope(String name) { - this(name, false); - } - - public DebugDumpScope(String name, boolean decorator) { - this.name = name; - this.decorator = decorator; - } - - @Override - public String toString() { - return "DebugDumpScope[" + name + "]"; - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/DebugEnvironment.java --- a/graal/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/DebugEnvironment.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,52 +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.debug; - -import static com.oracle.jvmci.debug.JVMCIDebugConfig.*; - -import java.io.*; -import java.util.*; - -import com.oracle.jvmci.service.*; - -public class DebugEnvironment { - - public static JVMCIDebugConfig initialize(PrintStream log) { - - if (!Debug.isEnabled()) { - log.println("WARNING: Scope debugging needs to be enabled with -esa or -D" + Debug.Initialization.INITIALIZER_PROPERTY_NAME + "=true"); - return null; - } - List dumpHandlers = new ArrayList<>(); - List verifyHandlers = new ArrayList<>(); - JVMCIDebugConfig debugConfig = new JVMCIDebugConfig(Log.getValue(), Meter.getValue(), TrackMemUse.getValue(), Time.getValue(), Dump.getValue(), Verify.getValue(), MethodFilter.getValue(), - log, dumpHandlers, verifyHandlers); - - for (DebugConfigCustomizer customizer : Services.load(DebugConfigCustomizer.class)) { - customizer.customize(debugConfig); - } - - Debug.setConfig(debugConfig); - return debugConfig; - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/DebugFilter.java --- a/graal/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/DebugFilter.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,185 +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.jvmci.debug; - -import java.util.*; -import java.util.regex.*; - -import com.oracle.jvmci.debug.internal.*; - -/** - * Implements the filter specified by the {@link JVMCIDebugConfig#Dump}, - * {@link JVMCIDebugConfig#Log}, {@link JVMCIDebugConfig#Meter} and {@link JVMCIDebugConfig#Time} - * options. - *

- * These options enable the associated debug facility if their filter matches the - * {@linkplain DebugScope#getQualifiedName() name} of the {@linkplain Debug#currentScope() current - * scope}. For the {@link JVMCIDebugConfig#Dump} and {@link JVMCIDebugConfig#Log} options, the log - * or dump level is set. The {@link JVMCIDebugConfig#Meter} and {@link JVMCIDebugConfig#Time} - * options don't have a level, for them {@code level = 0} means disabled and a {@code level > 0} - * means enabled. - *

- * A filter is a list of comma-separated terms of the form {@code [:]}. - * {@code } is interpreted as a glob pattern if it contains a "*" or "?" character. - * Otherwise, it is interpreted as a substring. If {@code } is empty, it matches every - * scope. If {@code :} is omitted, it defaults to {@link Debug#DEFAULT_LOG_LEVEL}. The term - * {@code ~} is a shorthand for {@code :0} to disable a debug facility for a - * pattern. - *

- * The resulting log level of a scope is determined by the last matching term. If no term - * matches, the log level is 0 (disabled). A filter with no terms matches every scope with a log - * level of {@link Debug#DEFAULT_LOG_LEVEL}. - * - *

Examples of filters

- * - *
    - *
  • (empty string)
    - * Matches any scope with log level {@link Debug#DEFAULT_LOG_LEVEL}. - * - *
  • {@code :1}
    - * Matches any scope with log level 1. - * - *
  • {@code *}
    - * Matches any scope with log level {@link Debug#DEFAULT_LOG_LEVEL}. - * - *
  • {@code CodeGen,CodeInstall}
    - * Matches scopes containing "CodeGen" or "CodeInstall", both with log level - * {@link Debug#DEFAULT_LOG_LEVEL}. - * - *
  • {@code CodeGen:2,CodeInstall:1}
    - * Matches scopes containing "CodeGen" with log level 2, or "CodeInstall" with log level 1. - * - *
  • {@code :1,Dead:2}
    - * Matches scopes containing "Dead" with log level 2, and all other scopes with log level 1. - * - *
  • {@code :1,Dead:0}
    - * Matches all scopes with log level 1, except those containing "Dead". - * - *
  • {@code Code*}
    - * Matches scopes starting with "Code" with log level {@link Debug#DEFAULT_LOG_LEVEL}. - * - *
  • {@code Code,~Dead}
    - * Matches scopes containing "Code" but not "Dead", with log level {@link Debug#DEFAULT_LOG_LEVEL}. - *
- */ -final class DebugFilter { - - public static DebugFilter parse(String spec) { - if (spec == null) { - return null; - } - return new DebugFilter(spec.split(",")); - } - - private final Term[] terms; - - private DebugFilter(String[] terms) { - if (terms.length == 0) { - this.terms = null; - } else { - this.terms = new Term[terms.length]; - for (int i = 0; i < terms.length; i++) { - String t = terms[i]; - int idx = t.indexOf(':'); - - String pattern; - int level; - if (idx < 0) { - if (t.startsWith("~")) { - pattern = t.substring(1); - level = 0; - } else { - pattern = t; - level = Debug.DEFAULT_LOG_LEVEL; - } - } else { - pattern = t.substring(0, idx); - if (idx + 1 < t.length()) { - level = Integer.parseInt(t.substring(idx + 1)); - } else { - level = Debug.DEFAULT_LOG_LEVEL; - } - } - - this.terms[i] = new Term(pattern, level); - } - } - } - - /** - * Check whether a given input is matched by this filter, and determine the log level. - */ - public int matchLevel(String input) { - if (terms == null) { - return Debug.DEFAULT_LOG_LEVEL; - } else { - int level = 0; - for (Term t : terms) { - if (t.matches(input)) { - level = t.level; - } - } - return level; - } - } - - @Override - public String toString() { - StringBuilder buf = new StringBuilder("DebugFilter"); - if (terms != null) { - buf.append(Arrays.toString(terms)); - } else { - buf.append("[]"); - } - return buf.toString(); - } - - private static class Term { - - private final Pattern pattern; - public final int level; - - public Term(String filter, int level) { - this.level = level; - if (filter.isEmpty()) { - this.pattern = null; - } else if (filter.contains("*") || filter.contains("?")) { - this.pattern = Pattern.compile(MethodFilter.createGlobString(filter)); - } else { - this.pattern = Pattern.compile(".*" + MethodFilter.createGlobString(filter) + ".*"); - } - } - - /** - * Determines if a given input is matched by this filter. - */ - public boolean matches(String input) { - return pattern == null || pattern.matcher(input).matches(); - } - - @Override - public String toString() { - return (pattern == null ? ".*" : pattern.toString()) + ":" + level; - } - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/DebugHistogram.java --- a/graal/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/DebugHistogram.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,102 +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.debug; - -import java.util.*; - -/** - * Facility for recording value frequencies. - */ -public interface DebugHistogram { - - /** - * Gets the name specified when this objected was {@linkplain Debug#createHistogram(String) - * created}. - */ - String getName(); - - /** - * Increments the count for a given value. - */ - void add(Object value); - - void add(Object value, long count); - - /** - * A value and a frequency. The ordering imposed by {@link #compareTo(CountedValue)} places - * values with higher frequencies first. - */ - public class CountedValue implements Comparable { - - private long count; - private final Object value; - - public CountedValue(long count, Object value) { - this.count = count; - this.value = value; - } - - public int compareTo(CountedValue o) { - if (count < o.count) { - return 1; - } else if (count > o.count) { - return -1; - } - return 0; - } - - @Override - public String toString() { - return count + " -> " + value; - } - - public void inc() { - count++; - } - - public void add(long n) { - count += n; - } - - public long getCount() { - return count; - } - - public Object getValue() { - return value; - } - } - - /** - * Gets a list of the counted values, sorted in descending order of frequency. - */ - List getValues(); - - /** - * Interface for a service that can render a visualization of a histogram. - */ - public interface Printer { - - void print(DebugHistogram histogram); - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/DebugInitializationPropertyProvider.java --- a/graal/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/DebugInitializationPropertyProvider.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,32 +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.jvmci.debug; - -import com.oracle.jvmci.service.*; - -/** - * Sets one or more system properties used during initialization of the {@link Debug} class. - */ -public interface DebugInitializationPropertyProvider extends Service { - void apply(); -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/DebugMemUseTracker.java --- a/graal/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/DebugMemUseTracker.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,52 +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.jvmci.debug; - -import com.sun.management.*; - -/** - * Tracks memory usage within a scope using {@link ThreadMXBean}. This facility should be employed - * using the try-with-resources pattern: - * - *
- * try (DebugMemUseTracker.Closeable a = memUseTracker.start()) {
- *     // the code to measure
- * }
- * 
- */ -public interface DebugMemUseTracker { - - /** - * Creates a point from which memory usage will be recorded if memory use tracking is - * {@linkplain Debug#isMemUseTrackingEnabled() enabled}. - * - * @return an object that must be closed once the activity has completed to add the memory used - * since this call to the total for this tracker - */ - DebugCloseable start(); - - /** - * Gets the current value of this tracker. - */ - long getCurrentValue(); -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/DebugMetric.java --- a/graal/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/DebugMetric.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,65 +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.jvmci.debug; - -/** - * A counter for some value of interest. - */ -public interface DebugMetric { - - /** - * Adds 1 to this counter if metering is {@link Debug#isMeterEnabled() enabled} or this is an - * {@linkplain #isConditional() unconditional} metric. - */ - void increment(); - - /** - * Adds {@code value} to this counter if metering is {@link Debug#isMeterEnabled() enabled} or - * this is an {@linkplain #isConditional() unconditional} metric. - */ - void add(long value); - - /** - * Sets a flag determining if this counter is only enabled if metering is - * {@link Debug#isMeterEnabled() enabled}. - */ - void setConditional(boolean flag); - - /** - * Determines if this counter is only enabled if metering is {@link Debug#isMeterEnabled() - * enabled}. - */ - boolean isConditional(); - - /** - * Gets the current value of this metric. - */ - long getCurrentValue(); - - /** - * Determines if this counter is enabled (either conditionally or unconditionally). - */ - default boolean isEnabled() { - return !isConditional() || Debug.isMeterEnabled(); - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/DebugTimer.java --- a/graal/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/DebugTimer.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,78 +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.jvmci.debug; - -import java.util.concurrent.*; - -/** - * A timer for some activity of interest. A timer should be deployed using the try-with-resources - * pattern: - * - *
- * try (TimerCloseable a = timer.start()) {
- *     // the code to time
- * }
- * 
- */ -public interface DebugTimer { - - /** - * Starts this timer if timing is {@linkplain Debug#isTimeEnabled() enabled} or this is an - * {@linkplain #isConditional() unconditional} timer. - * - * @return an object that must be closed once the activity has completed to add the elapsed time - * since this call to the total for this timer - */ - DebugCloseable start(); - - /** - * Sets a flag determining if this timer is only enabled if timing is - * {@link Debug#isTimeEnabled() enabled}. - */ - void setConditional(boolean flag); - - /** - * Determines if this timer is only enabled if timing is {@link Debug#isTimeEnabled() enabled}. - */ - boolean isConditional(); - - /** - * Gets the current value of this timer. - */ - long getCurrentValue(); - - /** - * Gets the time unit of this timer. - */ - TimeUnit getTimeUnit(); - - /** - * Gets the timer recording the amount time spent within a timed scope minus the time spent in - * any nested timed scopes. - * - * @return null if this timer does not support flat timing - */ - default DebugTimer getFlat() { - return null; - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/DebugVerifyHandler.java --- a/graal/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/DebugVerifyHandler.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,37 +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.jvmci.debug; - -/** - * Performs some kind of verification on an object. - */ -public interface DebugVerifyHandler { - - /** - * Verifies that a given object satisfies some invariants. - * - * @param object object to verify - * @param message description of verification context - */ - void verify(Object object, String message); -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/DelegatingDebugConfig.java --- a/graal/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/DelegatingDebugConfig.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,238 +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.debug; - -import java.io.*; -import java.util.*; - -import com.oracle.jvmci.debug.internal.*; - -public class DelegatingDebugConfig implements DebugConfig { - - protected final DebugConfig delegate; - - /** - * The features of a {@link DelegatingDebugConfig} that can be force - * {@linkplain DelegatingDebugConfig#enable(Feature) enabled}/ - * {@linkplain DelegatingDebugConfig#disable(Feature) disabled} or - * {@linkplain DelegatingDebugConfig#delegate(Feature) delegated}. - */ - public enum Feature { - /** - * @see Debug#isLogEnabledForMethod() - */ - LOG_METHOD, - /** - * @see Debug#isDumpEnabledForMethod() - */ - DUMP_METHOD, - /** - * @see Debug#isVerifyEnabled() - */ - VERIFY, - /** - * @see Debug#isVerifyEnabledForMethod() - */ - VERIFY_METHOD, - /** - * @see Debug#isMeterEnabled() - */ - METER, - /** - * @see Debug#isMemUseTrackingEnabled() - */ - TRACK_MEM_USE, - /** - * @see Debug#isTimeEnabled() - */ - TIME, - /** - * @see DebugConfig#interceptException(Throwable) - */ - INTERCEPT - } - - private final Map featureState = new EnumMap<>(Feature.class); - - /** - * The debug levels of a {@link DelegatingDebugConfig} than can be - * {@linkplain DelegatingDebugConfig#override(Level, int) overridden} or - * {@linkplain DelegatingDebugConfig#delegate(Level) delegated}. - */ - public enum Level { - LOG, - DUMP - } - - private final Map levelState = new EnumMap<>(Level.class); - - /** - * Creates a config that delegates to the {@link DebugScope#getConfig() current config}. - */ - public DelegatingDebugConfig() { - this(DebugScope.getConfig()); - } - - /** - * Creates a config that delegates to a given config. - */ - public DelegatingDebugConfig(DebugConfig delegate) { - this.delegate = delegate; - } - - public DelegatingDebugConfig enable(Feature feature) { - featureState.put(feature, Boolean.TRUE); - return this; - } - - public DelegatingDebugConfig disable(Feature feature) { - featureState.put(feature, Boolean.FALSE); - return this; - } - - public DelegatingDebugConfig override(Level level, int newLevel) { - levelState.put(level, newLevel); - return this; - } - - public DelegatingDebugConfig delegate(Feature feature) { - featureState.put(feature, null); - return this; - } - - public DelegatingDebugConfig delegate(Level level) { - levelState.put(level, null); - return this; - } - - @Override - public int getLogLevel() { - Integer ls = levelState.get(Level.LOG); - if (ls == null) { - return delegate.getLogLevel(); - } - return ls.intValue(); - } - - public boolean isLogEnabledForMethod() { - Boolean fs = featureState.get(Feature.LOG_METHOD); - if (fs == null) { - return delegate.isLogEnabledForMethod(); - } - return fs.booleanValue(); - } - - @Override - public boolean isMeterEnabled() { - Boolean fs = featureState.get(Feature.METER); - if (fs == null) { - return delegate.isMeterEnabled(); - } - return fs.booleanValue(); - } - - public boolean isMemUseTrackingEnabled() { - Boolean fs = featureState.get(Feature.TRACK_MEM_USE); - if (fs == null) { - return delegate.isMemUseTrackingEnabled(); - } - return fs.booleanValue(); - } - - @Override - public int getDumpLevel() { - Integer ls = levelState.get(Level.DUMP); - if (ls == null) { - return delegate.getDumpLevel(); - } - return ls.intValue(); - } - - public boolean isDumpEnabledForMethod() { - Boolean fs = featureState.get(Feature.DUMP_METHOD); - if (fs == null) { - return delegate.isDumpEnabledForMethod(); - } - return fs.booleanValue(); - } - - @Override - public boolean isVerifyEnabled() { - Boolean fs = featureState.get(Feature.VERIFY); - if (fs == null) { - return delegate.isVerifyEnabled(); - } - return fs.booleanValue(); - } - - public boolean isVerifyEnabledForMethod() { - Boolean fs = featureState.get(Feature.VERIFY_METHOD); - if (fs == null) { - return delegate.isVerifyEnabledForMethod(); - } - return fs.booleanValue(); - } - - @Override - public boolean isTimeEnabled() { - Boolean fs = featureState.get(Feature.TIME); - if (fs == null) { - return delegate.isTimeEnabled(); - } - return fs.booleanValue(); - } - - @Override - public RuntimeException interceptException(Throwable e) { - Boolean fs = featureState.get(Feature.INTERCEPT); - if (fs == null || fs) { - return delegate.interceptException(e); - } - return null; - } - - @Override - public Collection dumpHandlers() { - return delegate.dumpHandlers(); - } - - @Override - public Collection verifyHandlers() { - return delegate.verifyHandlers(); - } - - @Override - public PrintStream output() { - return delegate.output(); - } - - @Override - public void addToContext(Object o) { - delegate.addToContext(o); - } - - @Override - public void removeFromContext(Object o) { - delegate.removeFromContext(o); - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/Fingerprint.java --- a/graal/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/Fingerprint.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,145 +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.jvmci.debug; - -import java.util.*; -import java.util.stream.*; - -/** - * Facility for fingerprinting execution. - */ -public class Fingerprint implements AutoCloseable { - - public static final String ENABLED_PROPERTY_NAME = "jvmci.fingerprint"; - - /** - * Determines whether fingerprinting is enabled. This is set by the - * {@value #ENABLED_PROPERTY_NAME} system property when this class is initialized. - */ - public static final boolean ENABLED = Boolean.getBoolean(ENABLED_PROPERTY_NAME); - - private static final ThreadLocal current = ENABLED ? new ThreadLocal<>() : null; - - private final List events; - private int index; - - /** - * Creates an object to record a fingerprint. - */ - public Fingerprint() { - events = new ArrayList<>(); - index = -1; - } - - /** - * Creates an object to verify execution matches a given fingerprint. - * - * @param toVerifyAgainst the fingerprint events to verify against - */ - public Fingerprint(List toVerifyAgainst) { - this.events = toVerifyAgainst; - index = 0; - } - - /** - * Creates an object to verify execution matches a given fingerprint. - * - * @param toVerifyAgainst the fingerprint to verify against - */ - public Fingerprint(Fingerprint toVerifyAgainst) { - this(toVerifyAgainst.events); - } - - public Collection getEvents() { - return Collections.unmodifiableCollection(events); - } - - /** - * Starts fingerprint recording or verification for the current thread. At most one fingerprint - * object can be active for any thread. - */ - public Fingerprint open() { - if (ENABLED) { - assert current.get() == null; - current.set(this); - return this; - } - return null; - } - - /** - * Finishes fingerprint recording or verification for the current thread. - */ - public void close() { - if (ENABLED) { - assert current.get() == this; - current.set(null); - } - } - - private static final int BREAKPOINT_EVENT = Integer.getInteger(ENABLED_PROPERTY_NAME + ".breakpointEvent", -1); - - /** - * Submits an execution event for the purpose of recording or verifying a fingerprint. This must - * only be called if {@link #ENABLED} is {@code true}. - */ - public static void submit(String format, Object... args) { - assert ENABLED : "fingerprinting must be enabled (-D" + ENABLED_PROPERTY_NAME + "=true)"; - Fingerprint fingerprint = current.get(); - if (fingerprint != null) { - int eventId = fingerprint.nextEventId(); - if (eventId == BREAKPOINT_EVENT) { - // Set IDE breakpoint on the following line and set the relevant - // system property to debug a fingerprint verification error. - System.console(); - } - fingerprint.event(String.format(eventId + ": " + format, args)); - } - } - - private int nextEventId() { - return index == -1 ? events.size() : index; - } - - private static final int MAX_EVENT_TAIL_IN_ERROR_MESSAGE = Integer.getInteger("jvmci.fingerprint.errorEventTailLength", 50); - - private String tail() { - int start = Math.max(index - MAX_EVENT_TAIL_IN_ERROR_MESSAGE, 0); - return events.subList(start, index).stream().collect(Collectors.joining(String.format("%n"))); - } - - private void event(String entry) { - if (index == -1) { - events.add(entry); - } else { - if (index > events.size()) { - throw new InternalError(String.format("%s%nOriginal fingerprint limit reached", tail())); - } - String l = events.get(index); - if (!l.equals(entry)) { - throw new InternalError(String.format("%s%nFingerprint differs at event %d%nexpected: %s%n actual: %s", tail(), index, l, entry)); - } - index++; - } - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/Indent.java --- a/graal/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/Indent.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,51 +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.debug; - -/** - * Object used to close a debug {@link Debug#indent() indentation} scope. - *

- * Example usage: - * - *

- *
- *      try (Indent i1 = Debug.logAndIndent("header message")) {
- *          ...
- *          Debug.log("message");
- *          ...
- *          try (Indent i2 = Debug.logAndIndent(sub-header message")) {
- *              ...
- *              Debug.log("inner message");
- *              ...
- *          }
- *      }
- *
- * 
- */ -public interface Indent extends AutoCloseable { - - /** - * Closes the current indentation scope. - */ - void close(); -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/JVMCIDebugConfig.java --- a/graal/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/JVMCIDebugConfig.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,303 +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.jvmci.debug; - -import java.io.*; -import java.util.*; - -import com.oracle.jvmci.code.*; -import com.oracle.jvmci.meta.*; -import com.oracle.jvmci.options.*; - -public class JVMCIDebugConfig implements DebugConfig { - @SuppressWarnings("all") - private static boolean assertionsEnabled() { - boolean assertionsEnabled = false; - assert assertionsEnabled = true; - return assertionsEnabled; - } - - // @formatter:off - @Option(help = "Pattern for scope(s) in which dumping is enabled (see DebugFilter and Debug.dump)", type = OptionType.Debug) - public static final OptionValue Dump = new OptionValue<>(null); - @Option(help = "Pattern for scope(s) in which metering is enabled (see DebugFilter and Debug.metric). " + - "An empty value enables all metrics unconditionally.", type = OptionType.Debug) - public static final OptionValue Meter = new OptionValue<>(null); - @Option(help = "Pattern for scope(s) in which verification is enabled (see DebugFilter and Debug.verify).", type = OptionType.Debug) - public static final OptionValue Verify = new OptionValue() { - @Override - protected String defaultValue() { - return assertionsEnabled() ? "" : null; - } - }; - @Option(help = "Pattern for scope(s) in which memory use tracking is enabled (see DebugFilter and Debug.metric). " + - "An empty value enables all memory use trackers unconditionally.", type = OptionType.Debug) - public static final OptionValue TrackMemUse = new OptionValue<>(null); - @Option(help = "Pattern for scope(s) in which timing is enabled (see DebugFilter and Debug.timer). " + - "An empty value enables all timers unconditionally.", type = OptionType.Debug) - public static final OptionValue Time = new OptionValue<>(null); - @Option(help = "Pattern for scope(s) in which logging is enabled (see DebugFilter and Debug.log)", type = OptionType.Debug) - public static final OptionValue Log = new OptionValue<>(null); - @Option(help = "Pattern for filtering debug scope output based on method context (see MethodFilter)", type = OptionType.Debug) - public static final OptionValue MethodFilter = new OptionValue<>(null); - @Option(help = "Only check MethodFilter against the root method in the context if true, otherwise check all methods", type = OptionType.Debug) - public static final OptionValue MethodFilterRootOnly = new OptionValue<>(false); - - @Option(help = "How to print metric and timing values:%n" + - "Name - aggregate by unqualified name%n" + - "Partial - aggregate by partially qualified name (e.g., A.B.C.D.Counter and X.Y.Z.D.Counter will be merged to D.Counter)%n" + - "Complete - aggregate by qualified name%n" + - "Thread - aggregate by qualified name and thread", type = OptionType.Debug) - public static final OptionValue DebugValueSummary = new OptionValue<>("Name"); - @Option(help = "Omit reporting 0-value metrics", type = OptionType.Debug) - public static final OptionValue SuppressZeroDebugValues = new OptionValue<>(true); - @Option(help = "Only report debug values for maps which match the regular expression.", type = OptionType.Debug) - public static final OptionValue DebugValueThreadFilter = new OptionValue<>(null); - @Option(help = "Send JVMCI compiler IR to dump handlers on error", type = OptionType.Debug) - public static final OptionValue DumpOnError = new OptionValue<>(false); - @Option(help = "Intercept also bailout exceptions", type = OptionType.Debug) - public static final OptionValue InterceptBailout = new OptionValue<>(false); - @Option(help = "Enable more verbose log output when available", type = OptionType.Debug) - public static final OptionValue LogVerbose = new OptionValue<>(false); - // @formatter:on - - static boolean isNotEmpty(OptionValue option) { - return option.getValue() != null && !option.getValue().isEmpty(); - } - - public static boolean areDebugScopePatternsEnabled() { - return DumpOnError.getValue() || Dump.getValue() != null || Log.getValue() != null || areScopedMetricsOrTimersEnabled(); - } - - /** - * Determines if any of {@link #Meter}, {@link #Time} or {@link #TrackMemUse} has a non-null, - * non-empty value. - */ - public static boolean areScopedMetricsOrTimersEnabled() { - return isNotEmpty(Meter) || isNotEmpty(Time) || isNotEmpty(TrackMemUse); - } - - private final DebugFilter logFilter; - private final DebugFilter meterFilter; - private final DebugFilter trackMemUseFilter; - private final DebugFilter timerFilter; - private final DebugFilter dumpFilter; - private final DebugFilter verifyFilter; - private final MethodFilter[] methodFilter; - private final List dumpHandlers; - private final List verifyHandlers; - private final PrintStream output; - private final Set extraFilters = new HashSet<>(); - - public JVMCIDebugConfig(String logFilter, String meterFilter, String trackMemUseFilter, String timerFilter, String dumpFilter, String verifyFilter, String methodFilter, PrintStream output, - List dumpHandlers, List verifyHandlers) { - this.logFilter = DebugFilter.parse(logFilter); - this.meterFilter = DebugFilter.parse(meterFilter); - this.trackMemUseFilter = DebugFilter.parse(trackMemUseFilter); - this.timerFilter = DebugFilter.parse(timerFilter); - this.dumpFilter = DebugFilter.parse(dumpFilter); - this.verifyFilter = DebugFilter.parse(verifyFilter); - if (methodFilter == null || methodFilter.isEmpty()) { - this.methodFilter = null; - } else { - this.methodFilter = com.oracle.jvmci.debug.MethodFilter.parse(methodFilter); - } - - // Report the filters that have been configured so the user can verify it's what they expect - if (logFilter != null || meterFilter != null || timerFilter != null || dumpFilter != null || methodFilter != null) { - // TTY.println(Thread.currentThread().getName() + ": " + toString()); - } - this.dumpHandlers = dumpHandlers; - this.verifyHandlers = verifyHandlers; - this.output = output; - } - - public int getLogLevel() { - return getLevel(logFilter); - } - - public boolean isLogEnabledForMethod() { - return isEnabledForMethod(logFilter); - } - - public boolean isMeterEnabled() { - return isEnabled(meterFilter); - } - - public boolean isMemUseTrackingEnabled() { - return isEnabled(trackMemUseFilter); - } - - public int getDumpLevel() { - return getLevel(dumpFilter); - } - - public boolean isDumpEnabledForMethod() { - return isEnabledForMethod(dumpFilter); - } - - public boolean isVerifyEnabled() { - return isEnabled(verifyFilter); - } - - public boolean isVerifyEnabledForMethod() { - return isEnabledForMethod(verifyFilter); - } - - public boolean isTimeEnabled() { - return isEnabled(timerFilter); - } - - public PrintStream output() { - return output; - } - - private boolean isEnabled(DebugFilter filter) { - return getLevel(filter) > 0; - } - - private int getLevel(DebugFilter filter) { - int level; - if (filter == null) { - level = 0; - } else { - level = filter.matchLevel(Debug.currentScope()); - } - if (level > 0 && !checkMethodFilter()) { - level = 0; - } - return level; - } - - private boolean isEnabledForMethod(DebugFilter filter) { - return filter != null && checkMethodFilter(); - } - - /** - * Extracts a {@link JavaMethod} from an opaque debug context. - * - * @return the {@link JavaMethod} represented by {@code context} or null - */ - public static JavaMethod asJavaMethod(Object context) { - if (context instanceof JavaMethodContex) { - return ((JavaMethodContex) context).asJavaMethod(); - } - return null; - } - - private boolean checkMethodFilter() { - if (methodFilter == null && extraFilters.isEmpty()) { - return true; - } else { - JavaMethod lastMethod = null; - for (Object o : Debug.context()) { - if (extraFilters.contains(o)) { - return true; - } else if (methodFilter != null) { - JavaMethod method = asJavaMethod(o); - if (method != null) { - if (!MethodFilterRootOnly.getValue()) { - if (com.oracle.jvmci.debug.MethodFilter.matches(methodFilter, method)) { - return true; - } - } else { - /* - * The context values operate as a stack so if we want MethodFilter to - * only apply to the root method we have to check only the last method - * seen. - */ - lastMethod = method; - } - } - } - } - if (lastMethod != null && com.oracle.jvmci.debug.MethodFilter.matches(methodFilter, lastMethod)) { - return true; - } - return false; - } - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("Debug config:"); - add(sb, "Log", logFilter); - add(sb, "Meter", meterFilter); - add(sb, "Time", timerFilter); - add(sb, "Dump", dumpFilter); - add(sb, "MethodFilter", methodFilter); - return sb.toString(); - } - - private static void add(StringBuilder sb, String name, Object filter) { - if (filter != null) { - sb.append(' '); - sb.append(name); - sb.append('='); - if (filter instanceof Object[]) { - sb.append(Arrays.toString((Object[]) filter)); - } else { - sb.append(String.valueOf(filter)); - } - } - } - - @Override - public RuntimeException interceptException(Throwable e) { - if (e instanceof BailoutException && !InterceptBailout.getValue()) { - return null; - } - Debug.setConfig(Debug.fixedConfig(Debug.DEFAULT_LOG_LEVEL, Debug.DEFAULT_LOG_LEVEL, false, false, false, false, dumpHandlers, verifyHandlers, output)); - Debug.log(String.format("Exception occurred in scope: %s", Debug.currentScope())); - for (Object o : Debug.context()) { - if (DumpOnError.getValue()) { - Debug.dump(o, "Exception"); - } else { - Debug.log("Context obj %s", o); - } - - } - return null; - } - - @Override - public Collection dumpHandlers() { - return dumpHandlers; - } - - @Override - public Collection verifyHandlers() { - return verifyHandlers; - } - - @Override - public void addToContext(Object o) { - extraFilters.add(o); - } - - @Override - public void removeFromContext(Object o) { - extraFilters.remove(o); - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/JavaMethodContex.java --- a/graal/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/JavaMethodContex.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,33 +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.jvmci.debug; - -import com.oracle.jvmci.meta.*; - -/** - * Interface for objects used in Debug {@linkplain Debug#context() context} that can provide a - * {@link JavaMethod}. - */ -public interface JavaMethodContex { - JavaMethod asJavaMethod(); -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/LogStream.java --- a/graal/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/LogStream.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,477 +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.debug; - -import java.io.*; - -/** - * A utility for printing compiler debug and informational output to an output stream. - * - * A {@link LogStream} instance maintains an internal buffer that is flushed to the underlying - * output stream every time one of the {@code println} methods is invoked, or a newline character ( - * {@code '\n'}) is written. - * - * All of the {@code print} and {@code println} methods return the {code LogStream} instance on - * which they were invoked. This allows chaining of these calls to mitigate use of String - * concatenation by the caller. - * - * A {@code LogStream} maintains a current {@linkplain #indentationLevel() indentation} level. Each - * line of output written to this stream has {@code n} spaces prefixed to it where {@code n} is the - * value that would be returned by {@link #indentationLevel()} when the first character of a new - * line is written. - * - * A {@code LogStream} maintains a current {@linkplain #position() position} for the current line - * being written. This position can be advanced to a specified position by - * {@linkplain #fillTo(int, char) filling} this stream with a given character. - */ -public class LogStream { - - /** - * Null output stream that simply swallows any output sent to it. - */ - public static final LogStream SINK = new LogStream(); - - private static final PrintStream SINK_PS = new PrintStream(new OutputStream() { - - @Override - public void write(int b) throws IOException { - } - }); - - private LogStream() { - this.ps = null; - this.lineBuffer = null; - } - - /** - * The output stream to which this log stream writes. - */ - private final PrintStream ps; - - private final StringBuilder lineBuffer; - private int indentationLevel; - private char indentation = ' '; - private boolean indentationDisabled; - - public final PrintStream out() { - if (ps == null) { - return SINK_PS; - } - return ps; - } - - /** - * The system dependent line separator. - */ - public static final String LINE_SEPARATOR = System.getProperty("line.separator"); - - /** - * Creates a new log stream. - * - * @param os the underlying output stream to which prints are sent - */ - public LogStream(OutputStream os) { - ps = os instanceof PrintStream ? (PrintStream) os : new PrintStream(os); - lineBuffer = new StringBuilder(100); - } - - /** - * Creates a new log stream that shares the same {@linkplain #ps output stream} as a given - * {@link LogStream}. - * - * @param log a LogStream whose output stream is shared with this one - */ - public LogStream(LogStream log) { - ps = log.ps; - lineBuffer = new StringBuilder(100); - } - - /** - * Prepends {@link #indentation} to the current output line until its write position is equal to - * the current {@linkplain #indentationLevel()} level. - */ - private void indent() { - if (ps != null) { - if (!indentationDisabled && indentationLevel != 0) { - while (lineBuffer.length() < indentationLevel) { - lineBuffer.append(indentation); - } - } - } - } - - private LogStream flushLine(boolean withNewline) { - if (ps != null) { - if (withNewline) { - lineBuffer.append(LINE_SEPARATOR); - } - ps.print(lineBuffer.toString()); - ps.flush(); - lineBuffer.setLength(0); - } - return this; - } - - /** - * Flushes the stream. This is done by terminating the current line if it is not at position 0 - * and then flushing the underlying output stream. - */ - public void flush() { - if (ps != null) { - if (lineBuffer.length() != 0) { - flushLine(false); - } - ps.flush(); - } - } - - /** - * Gets the current column position of this log stream. - * - * @return the current column position of this log stream - */ - public int position() { - return lineBuffer == null ? 0 : lineBuffer.length(); - - } - - /** - * Gets the current indentation level for this log stream. - * - * @return the current indentation level for this log stream. - */ - public int indentationLevel() { - return indentationLevel; - } - - /** - * Adjusts the current indentation level of this log stream. - * - * @param delta - */ - public void adjustIndentation(int delta) { - if (delta < 0) { - indentationLevel = Math.max(0, indentationLevel + delta); - } else { - indentationLevel += delta; - } - } - - /** - * Gets the current indentation character of this log stream. - */ - public char indentation() { - return indentation; - } - - public void disableIndentation() { - indentationDisabled = true; - } - - public void enableIndentation() { - indentationDisabled = false; - } - - /** - * Sets the character used for indentation. - */ - public void setIndentation(char c) { - indentation = c; - } - - /** - * Advances this stream's {@linkplain #position() position} to a given position by repeatedly - * appending a given character as necessary. - * - * @param position the position to which this stream's position will be advanced - * @param filler the character used to pad the stream - */ - public LogStream fillTo(int position, char filler) { - if (ps != null) { - indent(); - while (lineBuffer.length() < position) { - lineBuffer.append(filler); - } - } - return this; - } - - /** - * Writes a boolean value to this stream as {@code "true"} or {@code "false"}. - * - * @param b the value to be printed - * @return this {@link LogStream} instance - */ - public LogStream print(boolean b) { - if (ps != null) { - indent(); - lineBuffer.append(b); - } - return this; - } - - /** - * Writes a boolean value to this stream followed by a {@linkplain #LINE_SEPARATOR line - * separator}. - * - * @param b the value to be printed - * @return this {@link LogStream} instance - */ - public LogStream println(boolean b) { - if (ps != null) { - indent(); - lineBuffer.append(b); - return flushLine(true); - } - return this; - } - - /** - * Writes a character value to this stream. - * - * @param c the value to be printed - * @return this {@link LogStream} instance - */ - public LogStream print(char c) { - if (ps != null) { - indent(); - lineBuffer.append(c); - if (c == '\n') { - if (lineBuffer.indexOf(LINE_SEPARATOR, lineBuffer.length() - LINE_SEPARATOR.length()) != -1) { - flushLine(false); - } - } - } - return this; - } - - /** - * Writes a character value to this stream followed by a {@linkplain #LINE_SEPARATOR line - * separator}. - * - * @param c the value to be printed - * @return this {@link LogStream} instance - */ - public LogStream println(char c) { - if (ps != null) { - indent(); - lineBuffer.append(c); - flushLine(true); - } - return this; - } - - /** - * Prints an int value. - * - * @param i the value to be printed - * @return this {@link LogStream} instance - */ - public LogStream print(int i) { - if (ps != null) { - indent(); - lineBuffer.append(i); - } - return this; - } - - /** - * Writes an int value to this stream followed by a {@linkplain #LINE_SEPARATOR line separator}. - * - * @param i the value to be printed - * @return this {@link LogStream} instance - */ - public LogStream println(int i) { - if (ps != null) { - indent(); - lineBuffer.append(i); - return flushLine(true); - } - return this; - } - - /** - * Writes a float value to this stream. - * - * @param f the value to be printed - * @return this {@link LogStream} instance - */ - public LogStream print(float f) { - if (ps != null) { - indent(); - lineBuffer.append(f); - } - return this; - } - - /** - * Writes a float value to this stream followed by a {@linkplain #LINE_SEPARATOR line separator} - * . - * - * @param f the value to be printed - * @return this {@link LogStream} instance - */ - public LogStream println(float f) { - if (ps != null) { - indent(); - lineBuffer.append(f); - return flushLine(true); - } - return this; - } - - /** - * Writes a long value to this stream. - * - * @param l the value to be printed - * @return this {@link LogStream} instance - */ - public LogStream print(long l) { - if (ps != null) { - indent(); - lineBuffer.append(l); - } - return this; - } - - /** - * Writes a long value to this stream followed by a {@linkplain #LINE_SEPARATOR line separator}. - * - * @param l the value to be printed - * @return this {@link LogStream} instance - */ - public LogStream println(long l) { - if (ps != null) { - indent(); - lineBuffer.append(l); - return flushLine(true); - } - return this; - } - - /** - * Writes a double value to this stream. - * - * @param d the value to be printed - * @return this {@link LogStream} instance - */ - public LogStream print(double d) { - if (ps != null) { - indent(); - lineBuffer.append(d); - } - return this; - } - - /** - * Writes a double value to this stream followed by a {@linkplain #LINE_SEPARATOR line - * separator}. - * - * @param d the value to be printed - * @return this {@link LogStream} instance - */ - public LogStream println(double d) { - if (ps != null) { - indent(); - lineBuffer.append(d); - return flushLine(true); - } - return this; - } - - /** - * Writes a {@code String} value to this stream. This method ensures that the - * {@linkplain #position() position} of this stream is updated correctly with respect to any - * {@linkplain #LINE_SEPARATOR line separators} present in {@code s}. - * - * @param s the value to be printed - * @return this {@link LogStream} instance - */ - public LogStream print(String s) { - if (ps != null) { - if (s == null) { - indent(); - lineBuffer.append(s); - return this; - } - - int index = 0; - int next = s.indexOf(LINE_SEPARATOR, index); - while (index < s.length()) { - indent(); - if (next > index) { - lineBuffer.append(s.substring(index, next)); - flushLine(true); - index = next + LINE_SEPARATOR.length(); - next = s.indexOf(LINE_SEPARATOR, index); - } else { - lineBuffer.append(s.substring(index)); - break; - } - } - } - return this; - } - - /** - * Writes a {@code String} value to this stream followed by a {@linkplain #LINE_SEPARATOR line - * separator}. - * - * @param s the value to be printed - * @return this {@link LogStream} instance - */ - public LogStream println(String s) { - if (ps != null) { - print(s); - flushLine(true); - } - return this; - } - - /** - * Writes a formatted string to this stream. - * - * @param format a format string as described in {@link String#format(String, Object...)} - * @param args the arguments to be formatted - * @return this {@link LogStream} instance - */ - public LogStream printf(String format, Object... args) { - if (ps != null) { - print(String.format(format, args)); - } - return this; - } - - /** - * Writes a {@linkplain #LINE_SEPARATOR line separator} to this stream. - * - * @return this {@code LogStream} instance - */ - public LogStream println() { - if (ps != null) { - indent(); - flushLine(true); - } - return this; - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/MethodFilter.java --- a/graal/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/MethodFilter.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,231 +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.jvmci.debug; - -import com.oracle.jvmci.meta.JavaType; -import com.oracle.jvmci.meta.JavaMethod; -import com.oracle.jvmci.meta.Signature; -import java.util.*; -import java.util.regex.*; - -/** - * This class implements a method filter that can filter based on class name, method name and - * parameters. The syntax for the source pattern that is passed to the constructor is as follows: - * - *
- * SourcePatterns = SourcePattern ["," SourcePatterns] .
- * SourcePattern = [ Class "." ] method [ "(" [ Parameter { ";" Parameter } ] ")" ] .
- * Parameter = Class | "int" | "long" | "float" | "double" | "short" | "char" | "boolean" .
- * Class = { package "." } class .
- * 
- * - * - * Glob pattern matching (*, ?) is allowed in all parts of the source pattern. Examples for valid - * filters are: - * - *
    - *
  • - * - *
    - * visit(Argument;BlockScope)
    - * 
    - * - * Matches all methods named "visit", with the first parameter of type "Argument", and the second - * parameter of type "BlockScope". The packages of the parameter types are irrelevant.
  • - *
  • - * - *
    - * arraycopy(Object;;;;)
    - * 
    - * - * Matches all methods named "arraycopy", with the first parameter of type "Object", and four more - * parameters of any type. The packages of the parameter types are irrelevant.
  • - *
  • - * - *
    - * com.oracle.graal.compiler.graph.PostOrderNodeIterator.*
    - * 
    - * - * Matches all methods in the class "com.oracle.graal.compiler.graph.PostOrderNodeIterator".
  • - *
  • - * - *
    - * *
    - * 
    - * - * Matches all methods in all classes
  • - *
  • - * - *
    - * com.oracle.graal.compiler.graph.*.visit
    - * 
    - * - * Matches all methods named "visit" in classes in the package "com.oracle.graal.compiler.graph". - *
  • - * - *
    - * arraycopy,toString
    - * 
    - * - * Matches all methods named "arraycopy" or "toString", meaning that ',' acts as an or - * operator.
  • - *
- */ -public class MethodFilter { - - private final Pattern clazz; - private final Pattern methodName; - private final Pattern[] signature; - - /** - * Parses a string containing list of comma separated filter patterns into an array of - * {@link MethodFilter}s. - */ - public static MethodFilter[] parse(String commaSeparatedPatterns) { - String[] filters = commaSeparatedPatterns.split(","); - MethodFilter[] methodFilters = new MethodFilter[filters.length]; - for (int i = 0; i < filters.length; i++) { - methodFilters[i] = new MethodFilter(filters[i]); - } - return methodFilters; - } - - /** - * Determines if a given method is matched by a given array of filters. - */ - public static boolean matches(MethodFilter[] filters, JavaMethod method) { - for (MethodFilter filter : filters) { - if (filter.matches(method)) { - return true; - } - } - return false; - } - - /** - * Determines if a given class name is matched by a given array of filters. - */ - public static boolean matchesClassName(MethodFilter[] filters, String className) { - for (MethodFilter filter : filters) { - if (filter.matchesClassName(className)) { - return true; - } - } - return false; - } - - public MethodFilter(String sourcePattern) { - String pattern = sourcePattern.trim(); - - // extract parameter part - int pos = pattern.indexOf('('); - if (pos != -1) { - if (pattern.charAt(pattern.length() - 1) != ')') { - throw new IllegalArgumentException("missing ')' at end of method filter pattern: " + pattern); - } - String[] signatureClasses = pattern.substring(pos + 1, pattern.length() - 1).split(";", -1); - signature = new Pattern[signatureClasses.length]; - for (int i = 0; i < signatureClasses.length; i++) { - signature[i] = createClassGlobPattern(signatureClasses[i].trim()); - } - pattern = pattern.substring(0, pos); - } else { - signature = null; - } - - // If there is at least one "." then everything before the last "." is the class name. - // Otherwise, the pattern contains only the method name. - pos = pattern.lastIndexOf('.'); - if (pos != -1) { - clazz = createClassGlobPattern(pattern.substring(0, pos)); - methodName = Pattern.compile(createGlobString(pattern.substring(pos + 1))); - } else { - clazz = null; - methodName = Pattern.compile(createGlobString(pattern)); - } - } - - static String createGlobString(String pattern) { - return Pattern.quote(pattern).replace("?", "\\E.\\Q").replace("*", "\\E.*\\Q"); - } - - private static Pattern createClassGlobPattern(String pattern) { - if (pattern.length() == 0) { - return null; - } else if (pattern.contains(".")) { - return Pattern.compile(createGlobString(pattern)); - } else { - return Pattern.compile("([^\\.\\$]*[\\.\\$])*" + createGlobString(pattern)); - } - } - - /** - * Determines if the class part of this filter matches a given class name. - */ - public boolean matchesClassName(String className) { - return clazz == null || clazz.matcher(className).matches(); - } - - public boolean matches(JavaMethod o) { - // check method name first, since MetaUtil.toJavaName is expensive - if (methodName != null && !methodName.matcher(o.getName()).matches()) { - return false; - } - if (clazz != null && !clazz.matcher(o.getDeclaringClass().toJavaName()).matches()) { - return false; - } - if (signature != null) { - Signature sig = o.getSignature(); - if (sig.getParameterCount(false) != signature.length) { - return false; - } - for (int i = 0; i < signature.length; i++) { - JavaType type = sig.getParameterType(i, null); - String javaName = type.toJavaName(); - if (signature[i] != null && !signature[i].matcher(javaName).matches()) { - return false; - } - } - } - return true; - } - - @Override - public String toString() { - StringBuilder buf = new StringBuilder("MethodFilter["); - String sep = ""; - if (clazz != null) { - buf.append(sep).append("clazz=").append(clazz); - sep = ", "; - } - if (methodName != null) { - buf.append(sep).append("methodName=").append(methodName); - sep = ", "; - } - if (signature != null) { - buf.append(sep).append("signature=").append(Arrays.toString(signature)); - sep = ", "; - } - return buf.append("]").toString(); - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/TTY.java --- a/graal/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/TTY.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,305 +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.debug; - -import java.io.*; -import java.lang.reflect.*; -import java.util.*; -import java.util.regex.*; - -/** - * A collection of static methods for printing debug and informational output to a global - * {@link LogStream}. The output can be (temporarily) suppressed per thread through use of a - * {@linkplain Filter filter}. - */ -public class TTY { - - /** - * Support for thread-local suppression of {@link TTY}. - */ - public static class Filter { - - private LogStream previous; - private final Thread thread = Thread.currentThread(); - - /** - * Creates an object that will suppress {@link TTY} for the current thread if the given - * filter does not match the given object. To revert the suppression state to how it was - * before this call, the {@link #remove()} method must be called on the suppression object. - * - * @param filter the pattern for matching. If {@code null}, then the match is successful. If - * it starts with "~", then a regular expression - * {@linkplain Pattern#matches(String, CharSequence) match} is performed where - * the regular expression is specified by {@code filter} without the "~" prefix. - * Otherwise, a simple {@linkplain String#contains(CharSequence) substring} match - * is performed where {@code filter} is the substring used. - * @param object an object whose {@linkplain Object#toString() string} value is matched - * against {@code filter} - */ - public Filter(String filter, Object object) { - boolean suppressed = false; - if (filter != null) { - String input = object.toString(); - if (filter.startsWith("~")) { - suppressed = !Pattern.matches(filter.substring(1), input); - } else { - suppressed = !input.contains(filter); - } - if (suppressed) { - previous = out(); - out.set(LogStream.SINK); - } - } - } - - /** - * Creates an object that will suppress {@link TTY} for the current thread. To revert the - * suppression state to how it was before this call, the {@link #remove()} method must be - * called on this filter object. - */ - public Filter() { - previous = out(); - out.set(LogStream.SINK); - } - - /** - * Reverts the suppression state of {@link TTY} to how it was before this object was - * constructed. - */ - public void remove() { - assert thread == Thread.currentThread(); - if (previous != null) { - out.set(previous); - } - } - } - - public static PrintStream cachedOut; - - public static void initialize(PrintStream ps) { - cachedOut = ps; - } - - private static LogStream createLog() { - if (cachedOut == null) { - // In case initialize() was not called. - cachedOut = System.out; - } - return new LogStream(cachedOut); - } - - private static final ThreadLocal out = new ThreadLocal() { - - @Override - protected LogStream initialValue() { - return createLog(); - } - }; - - public static boolean isSuppressed() { - return out.get() == LogStream.SINK; - } - - /** - * Gets the thread-local log stream to which the static methods of this class send their output. - * This will either be a global log stream or the global {@linkplain LogStream#SINK sink} - * depending on whether any suppression {@linkplain Filter filters} are in effect for the - * current thread. - */ - public static LogStream out() { - return out.get(); - } - - /** - * @see LogStream#print(String) - */ - public static void print(String s) { - out().print(s); - } - - /** - * @see LogStream#print(int) - */ - public static void print(int i) { - out().print(i); - } - - /** - * @see LogStream#print(long) - */ - public static void print(long i) { - out().print(i); - } - - /** - * @see LogStream#print(char) - */ - public static void print(char c) { - out().print(c); - } - - /** - * @see LogStream#print(boolean) - */ - public static void print(boolean b) { - out().print(b); - } - - /** - * @see LogStream#print(double) - */ - public static void print(double d) { - out().print(d); - } - - /** - * @see LogStream#print(float) - */ - public static void print(float f) { - out().print(f); - } - - /** - * @see LogStream#println(String) - */ - public static void println(String s) { - out().println(s); - } - - /** - * @see LogStream#println() - */ - public static void println() { - out().println(); - } - - /** - * @see LogStream#println(int) - */ - public static void println(int i) { - out().println(i); - } - - /** - * @see LogStream#println(long) - */ - public static void println(long l) { - out().println(l); - } - - /** - * @see LogStream#println(char) - */ - public static void println(char c) { - out().println(c); - } - - /** - * @see LogStream#println(boolean) - */ - public static void println(boolean b) { - out().println(b); - } - - /** - * @see LogStream#println(double) - */ - public static void println(double d) { - out().println(d); - } - - /** - * @see LogStream#println(float) - */ - public static void println(float f) { - out().println(f); - } - - public static void print(String format, Object... args) { - out().printf(format, args); - } - - public static void println(String format, Object... args) { - out().printf(format + "%n", args); - } - - public static void fillTo(int i) { - out().fillTo(i, ' '); - } - - public static void printFields(Class javaClass) { - final String className = javaClass.getSimpleName(); - TTY.println(className + " {"); - for (final Field field : javaClass.getFields()) { - printField(field, false); - } - TTY.println("}"); - } - - public static void printField(final Field field, boolean tabbed) { - final String fieldName = String.format("%35s", field.getName()); - try { - String prefix = tabbed ? "" : " " + fieldName + " = "; - String postfix = tabbed ? "\t" : "\n"; - if (field.getType() == int.class) { - TTY.print(prefix + field.getInt(null) + postfix); - } else if (field.getType() == boolean.class) { - TTY.print(prefix + field.getBoolean(null) + postfix); - } else if (field.getType() == float.class) { - TTY.print(prefix + field.getFloat(null) + postfix); - } else if (field.getType() == String.class) { - TTY.print(prefix + field.get(null) + postfix); - } else if (field.getType() == Map.class) { - Map m = (Map) field.get(null); - TTY.print(prefix + printMap(m) + postfix); - } else { - TTY.print(prefix + field.get(null) + postfix); - } - } catch (IllegalAccessException e) { - // do nothing. - } - } - - private static String printMap(Map m) { - StringBuilder sb = new StringBuilder(); - - List keys = new ArrayList<>(); - for (Object key : m.keySet()) { - keys.add((String) key); - } - Collections.sort(keys); - - for (String key : keys) { - sb.append(key); - sb.append("\t"); - sb.append(m.get(key)); - sb.append("\n"); - } - - return sb.toString(); - } - - public static void flush() { - out().flush(); - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/TopLevelDebugConfig.java --- a/graal/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/TopLevelDebugConfig.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,31 +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.jvmci.debug; - -/** - * A marker class for a scoped debug configuration covering a compilation region. Useful for - * programmatically enabling debug config features. - * - */ -public class TopLevelDebugConfig extends DelegatingDebugConfig { -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/internal/AccumulatedDebugValue.java --- a/graal/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/internal/AccumulatedDebugValue.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,32 +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.jvmci.debug.internal; - -public abstract class AccumulatedDebugValue extends DebugValue { - protected final DebugValue flat; - - public AccumulatedDebugValue(String name, boolean conditional, DebugValue flat) { - super(name + "_Accm", conditional); - this.flat = flat; - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/internal/CloseableCounterImpl.java --- a/graal/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/internal/CloseableCounterImpl.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,70 +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.jvmci.debug.internal; - -import com.oracle.jvmci.debug.*; - -/** - * A helper class for DebugValues that can nest and need to split out accumulated and flat values - * for some kind of counter-like measurement. - */ -abstract class CloseableCounterImpl implements DebugCloseable { - - protected final CloseableCounterImpl parent; - protected final AccumulatedDebugValue counter; - protected final long start; - protected long nestedAmountToSubtract; - - CloseableCounterImpl(CloseableCounterImpl parent, AccumulatedDebugValue counter) { - this.parent = parent; - this.start = getCounterValue(); - this.counter = counter; - } - - @Override - public void close() { - long end = getCounterValue(); - long difference = end - start; - if (parent != null) { - if (!counter.getName().equals(parent.counter.getName())) { - parent.nestedAmountToSubtract += difference; - - // Look for our counter in an outer scope and fix up - // the adjustment to the flat count - CloseableCounterImpl ancestor = parent.parent; - while (ancestor != null) { - if (ancestor.counter.getName().equals(counter.getName())) { - ancestor.nestedAmountToSubtract -= difference; - break; - } - ancestor = ancestor.parent; - } - } - } - long flatAmount = difference - nestedAmountToSubtract; - counter.addToCurrentValue(difference); - counter.flat.addToCurrentValue(flatAmount); - } - - abstract long getCounterValue(); -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/internal/DebugHistogramAsciiPrinter.java --- a/graal/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/internal/DebugHistogramAsciiPrinter.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,103 +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.debug.internal; - -import java.io.*; -import java.util.*; - -import com.oracle.jvmci.debug.*; -import com.oracle.jvmci.debug.DebugHistogram.CountedValue; -import com.oracle.jvmci.debug.DebugHistogram.Printer; - -/** - * Renders a textual representation of a histogram to a given print stream. - */ -public class DebugHistogramAsciiPrinter implements Printer { - - public static final int NumberSize = 10; - public static final int DefaultNameSize = 50; - public static final int DefaultBarSize = 100; - public static final int DefaultScale = 1; - - private final PrintStream os; - private final int limit; - private final int nameSize; - private final int barSize; - private final int scale; - - public DebugHistogramAsciiPrinter(PrintStream os) { - this(os, Integer.MAX_VALUE, DefaultNameSize, DefaultBarSize, DefaultScale); - } - - /** - * @param os where to print - * @param limit limits printing to the {@code limit} most frequent values - * @param nameSize the width of the value names column - * @param barSize the width of the value frequency column - * @param scale a factor by which every result is divided - */ - public DebugHistogramAsciiPrinter(PrintStream os, int limit, int nameSize, int barSize, int scale) { - this.os = os; - this.limit = limit; - this.nameSize = nameSize; - this.barSize = barSize; - this.scale = scale; - } - - public void print(DebugHistogram histogram) { - List list = histogram.getValues(); - if (list.isEmpty()) { - os.printf("%s is empty.%n", histogram.getName()); - return; - } - - // Sum up the total number of elements. - long total = list.stream().mapToLong(CountedValue::getCount).sum(); - - // Print header. - os.printf("%s has %d unique elements and %d total elements:%n", histogram.getName(), list.size(), total / scale); - - long max = list.get(0).getCount() / scale; - final int lineSize = nameSize + NumberSize + barSize + 10; - printLine(os, '-', lineSize); - String formatString = "| %-" + nameSize + "s | %-" + NumberSize + "d | %-" + barSize + "s |\n"; - for (int i = 0; i < list.size() && i < limit; ++i) { - CountedValue cv = list.get(i); - long value = cv.getCount() / scale; - char[] bar = new char[(int) (((double) value / (double) max) * barSize)]; - Arrays.fill(bar, '='); - String objectString = String.valueOf(cv.getValue()); - if (objectString.length() > nameSize) { - objectString = objectString.substring(0, nameSize - 3) + "..."; - } - os.printf(formatString, objectString, value, new String(bar)); - } - printLine(os, '-', lineSize); - } - - private static void printLine(PrintStream printStream, char c, int lineSize) { - char[] charArr = new char[lineSize]; - Arrays.fill(charArr, c); - printStream.printf("%s%n", new String(charArr)); - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/internal/DebugHistogramImpl.java --- a/graal/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/internal/DebugHistogramImpl.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,66 +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.debug.internal; - -import java.util.*; - -import com.oracle.jvmci.debug.*; - -public class DebugHistogramImpl implements DebugHistogram { - - private final String name; - private HashMap map = new HashMap<>(); - - public DebugHistogramImpl(String name) { - this.name = name; - } - - public void add(Object value) { - CountedValue cv = map.get(value); - if (cv == null) { - map.put(value, new CountedValue(1, value)); - } else { - cv.inc(); - } - } - - public void add(Object value, long count) { - CountedValue cv = map.get(value); - if (cv == null) { - map.put(value, new CountedValue(count, value)); - } else { - cv.add(count); - } - } - - @Override - public String getName() { - return name; - } - - public List getValues() { - ArrayList res = new ArrayList<>(map.values()); - Collections.sort(res); - return res; - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/internal/DebugHistogramRPrinter.java --- a/graal/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/internal/DebugHistogramRPrinter.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,81 +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.debug.internal; - -import java.io.*; -import java.util.*; - -import com.oracle.jvmci.debug.*; -import com.oracle.jvmci.debug.DebugHistogram.CountedValue; -import com.oracle.jvmci.debug.DebugHistogram.Printer; - -/** - * Renders a histogram as an R script to a given print stream. The R script emitted for a histogram - * is a simple set of statements for defining a vector of named objects. - */ -public class DebugHistogramRPrinter implements Printer { - - private PrintStream os; - private int limit; - - public DebugHistogramRPrinter(PrintStream os) { - this(os, Integer.MAX_VALUE); - } - - /** - * @param os where to print - * @param limit limits printing to the {@code limit} most frequent values - */ - public DebugHistogramRPrinter(PrintStream os, int limit) { - this.os = os; - this.limit = limit; - } - - public void print(DebugHistogram histogram) { - List list = histogram.getValues(); - if (list.isEmpty()) { - return; - } - - String var = histogram.getName().replace('-', '.').replace(' ', '_'); - os.print(var + " <- c("); - for (int i = 0; i < list.size() && i < limit; ++i) { - CountedValue cv = list.get(i); - if (i != 0) { - os.print(", "); - } - os.print(cv.getCount()); - } - os.println(");"); - - os.print("names(" + var + ") <- c("); - for (int i = 0; i < list.size() && i < limit; ++i) { - CountedValue cv = list.get(i); - if (i != 0) { - os.print(", "); - } - os.print("\"" + cv.getValue() + "\""); - } - os.println(");"); - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/internal/DebugScope.java --- a/graal/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/internal/DebugScope.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,489 +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.jvmci.debug.internal; - -import java.io.*; -import java.util.*; -import java.util.concurrent.*; - -import com.oracle.jvmci.debug.*; - -public final class DebugScope implements Debug.Scope { - - private final class IndentImpl implements Indent { - - private static final String INDENTATION_INCREMENT = " "; - - final String indent; - final IndentImpl parentIndent; - - IndentImpl(IndentImpl parentIndent) { - this.parentIndent = parentIndent; - this.indent = (parentIndent == null ? "" : parentIndent.indent + INDENTATION_INCREMENT); - } - - private void printScopeName(StringBuilder str) { - if (logScopeName) { - if (parentIndent != null) { - parentIndent.printScopeName(str); - } - str.append(indent).append("[thread:").append(Thread.currentThread().getId()).append("] scope: ").append(getQualifiedName()).append(System.lineSeparator()); - logScopeName = false; - } - } - - public void log(int logLevel, String msg, Object... args) { - if (isLogEnabled(logLevel)) { - StringBuilder str = new StringBuilder(); - printScopeName(str); - str.append(indent); - String result = args.length == 0 ? msg : String.format(msg, args); - String lineSep = System.lineSeparator(); - str.append(result.replace(lineSep, lineSep.concat(indent))); - str.append(lineSep); - output.append(str); - lastUsedIndent = this; - } - } - - IndentImpl indent() { - lastUsedIndent = new IndentImpl(this); - return lastUsedIndent; - } - - @Override - public void close() { - if (parentIndent != null) { - lastUsedIndent = parentIndent; - } - } - } - - private static final ThreadLocal instanceTL = new ThreadLocal<>(); - private static final ThreadLocal lastClosedTL = new ThreadLocal<>(); - private static final ThreadLocal configTL = new ThreadLocal<>(); - private static final ThreadLocal lastExceptionThrownTL = new ThreadLocal<>(); - - private final DebugScope parent; - private final DebugConfig parentConfig; - private final boolean sandbox; - private IndentImpl lastUsedIndent; - private boolean logScopeName; - - private final Object[] context; - - private DebugValueMap valueMap; - - private String qualifiedName; - private final String unqualifiedName; - - private static final char SCOPE_SEP = '.'; - - private boolean meterEnabled; - private boolean timeEnabled; - private boolean memUseTrackingEnabled; - private boolean verifyEnabled; - - private int currentDumpLevel; - private int currentLogLevel; - - private PrintStream output; - - public static DebugScope getInstance() { - DebugScope result = instanceTL.get(); - if (result == null) { - DebugScope topLevelDebugScope = new DebugScope(Thread.currentThread()); - instanceTL.set(topLevelDebugScope); - return topLevelDebugScope; - } else { - return result; - } - } - - public static DebugConfig getConfig() { - return configTL.get(); - } - - static final Object[] EMPTY_CONTEXT = new Object[0]; - - private DebugScope(Thread thread) { - this(thread.getName(), null, false); - computeValueMap(thread.getName()); - DebugValueMap.registerTopLevel(getValueMap()); - } - - private DebugScope(String unqualifiedName, DebugScope parent, boolean sandbox, Object... context) { - this.parent = parent; - this.sandbox = sandbox; - this.parentConfig = getConfig(); - this.context = context; - this.unqualifiedName = unqualifiedName; - if (parent != null) { - logScopeName = !unqualifiedName.equals(""); - } else { - logScopeName = true; - } - - // Be pragmatic: provide a default log stream to prevent a crash if the stream is not - // set while logging - this.output = TTY.cachedOut; - assert context != null; - } - - private void computeValueMap(String name) { - if (parent != null) { - for (DebugValueMap child : parent.getValueMap().getChildren()) { - if (child.getName().equals(name)) { - this.valueMap = child; - return; - } - } - this.valueMap = new DebugValueMap(name); - parent.getValueMap().addChild(this.valueMap); - } else { - this.valueMap = new DebugValueMap(name); - } - } - - public void close() { - instanceTL.set(parent); - configTL.set(parentConfig); - lastClosedTL.set(this); - } - - public boolean isDumpEnabled(int dumpLevel) { - assert dumpLevel > 0; - return currentDumpLevel >= dumpLevel; - } - - /** - * Enable dumping at the new {@code dumpLevel} for the remainder of enclosing scopes. This only - * works if a {@link TopLevelDebugConfig} was installed at a higher scope. - * - * @param dumpLevel - */ - public static void setDumpLevel(int dumpLevel) { - TopLevelDebugConfig config = fetchTopLevelDebugConfig("setDebugLevel"); - if (config != null) { - config.override(DelegatingDebugConfig.Level.DUMP, dumpLevel); - recursiveUpdateFlags(); - } - } - - /** - * Enable logging at the new {@code logLevel} for the remainder of enclosing scopes. This only - * works if a {@link TopLevelDebugConfig} was installed at a higher scope. - * - * @param logLevel - */ - public static void setLogLevel(int logLevel) { - TopLevelDebugConfig config = fetchTopLevelDebugConfig("setLogLevel"); - if (config != null) { - config.override(DelegatingDebugConfig.Level.LOG, logLevel); - config.delegate(DelegatingDebugConfig.Feature.LOG_METHOD); - recursiveUpdateFlags(); - } - } - - private static void recursiveUpdateFlags() { - DebugScope c = DebugScope.getInstance(); - while (c != null) { - c.updateFlags(); - c = c.parent; - } - } - - private static TopLevelDebugConfig fetchTopLevelDebugConfig(String msg) { - DebugConfig config = getConfig(); - if (config instanceof TopLevelDebugConfig) { - return (TopLevelDebugConfig) config; - } else { - if (config == null) { - TTY.println("DebugScope.%s ignored because debugging is disabled", msg); - } else { - TTY.println("DebugScope.%s ignored because top level delegate config missing", msg); - } - return null; - } - } - - public boolean isVerifyEnabled() { - return verifyEnabled; - } - - public boolean isLogEnabled(int logLevel) { - assert logLevel > 0; - return currentLogLevel >= logLevel; - } - - public boolean isMeterEnabled() { - return meterEnabled; - } - - public boolean isTimeEnabled() { - return timeEnabled; - } - - public boolean isMemUseTrackingEnabled() { - return memUseTrackingEnabled; - } - - public void log(int logLevel, String msg, Object... args) { - if (isLogEnabled(logLevel)) { - getLastUsedIndent().log(logLevel, msg, args); - } - } - - public void dump(int dumpLevel, Object object, String formatString, Object... args) { - if (isDumpEnabled(dumpLevel)) { - DebugConfig config = getConfig(); - if (config != null) { - String message = String.format(formatString, args); - for (DebugDumpHandler dumpHandler : config.dumpHandlers()) { - dumpHandler.dump(object, message); - } - } - } - } - - /** - * This method exists mainly to allow a debugger (e.g., Eclipse) to force dump a graph. - */ - public static void forceDump(Object object, String format, Object... args) { - DebugConfig config = getConfig(); - if (config != null) { - String message = String.format(format, args); - for (DebugDumpHandler dumpHandler : config.dumpHandlers()) { - dumpHandler.dump(object, message); - } - } else { - TTY.println("Forced dump ignored because debugging is disabled - use -G:Dump=xxx option"); - } - } - - /** - * @see Debug#verify(Object, String) - */ - public void verify(Object object, String formatString, Object... args) { - if (isVerifyEnabled()) { - DebugConfig config = getConfig(); - if (config != null) { - String message = String.format(formatString, args); - for (DebugVerifyHandler handler : config.verifyHandlers()) { - handler.verify(object, message); - } - } - } - } - - /** - * Creates and enters a new debug scope which is either a child of the current scope or a - * disjoint top level scope. - * - * @param name the name of the new scope - * @param sandboxConfig the configuration to use for a new top level scope, or null if the new - * scope should be a child scope - * @param newContextObjects objects to be appended to the debug context - * @return the new scope which will be exited when its {@link #close()} method is called - */ - public DebugScope scope(CharSequence name, DebugConfig sandboxConfig, Object... newContextObjects) { - DebugScope newScope = null; - if (sandboxConfig != null) { - newScope = new DebugScope(name.toString(), this, true, newContextObjects); - configTL.set(sandboxConfig); - } else { - newScope = this.createChild(name.toString(), newContextObjects); - } - instanceTL.set(newScope); - newScope.updateFlags(); - return newScope; - } - - public RuntimeException handle(Throwable e) { - DebugScope lastClosed = lastClosedTL.get(); - assert lastClosed.parent == this : "Debug.handle() used with no matching Debug.scope(...) or Debug.sandbox(...)"; - if (e != lastExceptionThrownTL.get()) { - RuntimeException newException = null; - instanceTL.set(lastClosed); - try (DebugScope s = lastClosed) { - newException = s.interceptException(e); - } - assert instanceTL.get() == this; - assert lastClosed == lastClosedTL.get(); - if (newException == null) { - lastExceptionThrownTL.set(e); - } else { - lastExceptionThrownTL.set(newException); - throw newException; - } - } - if (e instanceof Error) { - throw (Error) e; - } - if (e instanceof RuntimeException) { - throw (RuntimeException) e; - } - throw new RuntimeException(e); - } - - private void updateFlags() { - DebugConfig config = getConfig(); - if (config == null) { - meterEnabled = false; - memUseTrackingEnabled = false; - timeEnabled = false; - verifyEnabled = false; - - currentDumpLevel = 0; - - // Be pragmatic: provide a default log stream to prevent a crash if the stream is not - // set while logging - output = TTY.cachedOut; - } else { - meterEnabled = config.isMeterEnabled(); - memUseTrackingEnabled = config.isMemUseTrackingEnabled(); - timeEnabled = config.isTimeEnabled(); - verifyEnabled = config.isVerifyEnabled(); - output = config.output(); - currentDumpLevel = config.getDumpLevel(); - currentLogLevel = config.getLogLevel(); - } - } - - private RuntimeException interceptException(final Throwable e) { - final DebugConfig config = getConfig(); - if (config != null) { - try (DebugScope s = scope("InterceptException", null, e)) { - return config.interceptException(e); - } catch (Throwable t) { - return new RuntimeException("Exception while intercepting exception", t); - } - } - return null; - } - - private DebugValueMap getValueMap() { - if (valueMap == null) { - computeValueMap(unqualifiedName); - } - return valueMap; - } - - long getCurrentValue(int index) { - return getValueMap().getCurrentValue(index); - } - - void setCurrentValue(int index, long l) { - getValueMap().setCurrentValue(index, l); - } - - private DebugScope createChild(String newName, Object[] newContext) { - return new DebugScope(newName, this, false, newContext); - } - - public Iterable getCurrentContext() { - final DebugScope scope = this; - return new Iterable() { - - @Override - public Iterator iterator() { - return new Iterator() { - - DebugScope currentScope = scope; - int objectIndex; - - @Override - public boolean hasNext() { - selectScope(); - return currentScope != null; - } - - private void selectScope() { - while (currentScope != null && currentScope.context.length <= objectIndex) { - currentScope = currentScope.sandbox ? null : currentScope.parent; - objectIndex = 0; - } - } - - @Override - public Object next() { - selectScope(); - if (currentScope != null) { - return currentScope.context[objectIndex++]; - } - throw new IllegalStateException("May only be called if there is a next element."); - } - - @Override - public void remove() { - throw new UnsupportedOperationException("This iterator is read only."); - } - }; - } - }; - } - - public static T call(Callable callable) { - try { - return callable.call(); - } catch (Exception e) { - if (e instanceof RuntimeException) { - throw (RuntimeException) e; - } else { - throw new RuntimeException(e); - } - } - } - - public void setConfig(DebugConfig newConfig) { - configTL.set(newConfig); - updateFlags(); - } - - public String getQualifiedName() { - if (qualifiedName == null) { - if (parent == null) { - qualifiedName = unqualifiedName; - } else { - qualifiedName = parent.getQualifiedName() + SCOPE_SEP + unqualifiedName; - } - } - return qualifiedName; - } - - public Indent pushIndentLogger() { - lastUsedIndent = getLastUsedIndent().indent(); - return lastUsedIndent; - } - - public IndentImpl getLastUsedIndent() { - if (lastUsedIndent == null) { - if (parent != null) { - lastUsedIndent = new IndentImpl(parent.getLastUsedIndent()); - } else { - lastUsedIndent = new IndentImpl(null); - } - } - return lastUsedIndent; - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/internal/DebugValue.java --- a/graal/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/internal/DebugValue.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,94 +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.jvmci.debug.internal; - -/** - * A name and index for a value managed in a thread local value map. All access to the value is made - * via a {@link DebugValue} instance. - */ -public abstract class DebugValue implements Comparable { - - private final String name; - private int index; - private boolean conditional; - - protected DebugValue(String name, boolean conditional) { - this.name = name; - this.index = -1; - this.conditional = conditional; - } - - public long getCurrentValue() { - ensureInitialized(); - return DebugScope.getInstance().getCurrentValue(index); - } - - protected void setCurrentValue(long l) { - ensureInitialized(); - DebugScope.getInstance().setCurrentValue(index, l); - } - - public void setConditional(boolean flag) { - conditional = flag; - } - - public boolean isConditional() { - return conditional; - } - - private void ensureInitialized() { - if (index == -1) { - index = KeyRegistry.register(this); - } - } - - protected void addToCurrentValue(long value) { - setCurrentValue(getCurrentValue() + value); - } - - /** - * Gets the globally unique index for the value represented by this object. - */ - public int getIndex() { - ensureInitialized(); - return index; - } - - /** - * Gets the globally unique name for the value represented by this object. - */ - public String getName() { - return name; - } - - public int compareTo(DebugValue o) { - return name.compareTo(o.name); - } - - @Override - public String toString() { - return name + "@" + index; - } - - public abstract String toString(long value); -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/internal/DebugValueMap.java --- a/graal/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/internal/DebugValueMap.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,171 +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.jvmci.debug.internal; - -import java.util.*; - -/** - * A node in a tree of {@link DebugValue}s. - */ -public class DebugValueMap { - - private static final List topLevelMaps = new ArrayList<>(); - - private long[] values; - private List children; - private String name; - - public DebugValueMap(String name) { - this.name = name; - } - - public void setCurrentValue(int index, long l) { - ensureSize(index); - values[index] = l; - } - - public long getCurrentValue(int index) { - ensureSize(index); - return values[index]; - } - - public void clearChildren() { - if (children != null) { - children.clear(); - } - } - - public void reset() { - if (values != null) { - Arrays.fill(values, 0L); - } - if (children != null) { - for (DebugValueMap child : children) { - child.reset(); - } - } - } - - private void ensureSize(int index) { - if (values == null) { - values = new long[index + 1]; - } - if (values.length <= index) { - values = Arrays.copyOf(values, index + 1); - } - } - - private int capacity() { - return (values == null) ? 0 : values.length; - } - - public void addChild(DebugValueMap map) { - if (children == null) { - children = new ArrayList<>(4); - } - children.add(map); - } - - public List getChildren() { - if (children == null) { - return Collections.emptyList(); - } else { - return Collections.unmodifiableList(children); - } - } - - public boolean hasChildren() { - return children != null && !children.isEmpty(); - } - - public String getName() { - return this.name; - } - - @Override - public String toString() { - return "DebugValueMap<" + getName() + ">"; - } - - public static synchronized void registerTopLevel(DebugValueMap map) { - topLevelMaps.add(map); - } - - public static synchronized List getTopLevelMaps() { - return topLevelMaps; - } - - public void normalize() { - if (hasChildren()) { - Map occurred = new HashMap<>(); - for (DebugValueMap map : children) { - String mapName = map.getName(); - if (!occurred.containsKey(mapName)) { - occurred.put(mapName, map); - map.normalize(); - } else { - occurred.get(mapName).mergeWith(map); - occurred.get(mapName).normalize(); - } - } - - if (occurred.values().size() < children.size()) { - // At least one duplicate was found. - children.clear(); - for (DebugValueMap map : occurred.values()) { - addChild(map); - map.normalize(); - } - } - } - } - - private void mergeWith(DebugValueMap map) { - if (map.hasChildren()) { - if (hasChildren()) { - children.addAll(map.children); - } else { - children = map.children; - } - map.children = null; - } - - int size = Math.max(this.capacity(), map.capacity()); - ensureSize(size); - for (int i = 0; i < size; ++i) { - long curValue = getCurrentValue(i); - long otherValue = map.getCurrentValue(i); - setCurrentValue(i, curValue + otherValue); - } - } - - public void group() { - if (this.hasChildren()) { - List oldChildren = new ArrayList<>(this.children); - this.children.clear(); - for (DebugValueMap map : oldChildren) { - mergeWith(map); - } - } - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/internal/KeyRegistry.java --- a/graal/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/internal/KeyRegistry.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,57 +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.jvmci.debug.internal; - -import java.util.*; - -/** - * Registry for allocating a globally unique integer id to each {@link DebugValue}. - */ -public class KeyRegistry { - - private static final Map keyMap = new HashMap<>(); - private static final List debugValues = new ArrayList<>(); - - /** - * Ensures a given debug value is registered. - * - * @return the globally unique id for {@code value} - */ - public static synchronized int register(DebugValue value) { - String name = value.getName(); - if (!keyMap.containsKey(name)) { - keyMap.put(name, debugValues.size()); - debugValues.add(value); - } - return keyMap.get(name); - } - - /** - * Gets a immutable view of the registered debug values. - * - * @return a list where {@code get(i).getIndex() == i} - */ - public static synchronized List getDebugValues() { - return Collections.unmodifiableList(debugValues); - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/internal/MemUseTrackerImpl.java --- a/graal/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/internal/MemUseTrackerImpl.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,98 +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.jvmci.debug.internal; - -import static com.oracle.jvmci.debug.DebugCloseable.*; -import static java.lang.Thread.*; - -import java.lang.management.*; - -import com.oracle.jvmci.debug.*; -import com.sun.management.ThreadMXBean; - -public final class MemUseTrackerImpl extends AccumulatedDebugValue implements DebugMemUseTracker { - - private static final ThreadMXBean threadMXBean = (ThreadMXBean) ManagementFactory.getThreadMXBean(); - - /** - * The amount of memory allocated by {@link ThreadMXBean#getThreadAllocatedBytes(long)} itself. - */ - private static final long threadMXBeanOverhead = -getCurrentThreadAllocatedBytes() + getCurrentThreadAllocatedBytes(); - - public static long getCurrentThreadAllocatedBytes() { - return threadMXBean.getThreadAllocatedBytes(currentThread().getId()) - threadMXBeanOverhead; - } - - /** - * Records the most recent active tracker. - */ - private static final ThreadLocal currentTracker = new ThreadLocal<>(); - - public MemUseTrackerImpl(String name, boolean conditional) { - super(name, conditional, new DebugValue(name + "_Flat", conditional) { - - @Override - public String toString(long value) { - return valueToString(value); - } - }); - } - - @Override - public DebugCloseable start() { - if (!isConditional() || Debug.isMemUseTrackingEnabled()) { - MemUseCloseableCounterImpl result = new MemUseCloseableCounterImpl(this); - currentTracker.set(result); - return result; - } else { - return VOID_CLOSEABLE; - } - } - - public static String valueToString(long value) { - return String.format("%d bytes", value); - } - - @Override - public String toString(long value) { - return valueToString(value); - } - - private static final class MemUseCloseableCounterImpl extends CloseableCounterImpl implements DebugCloseable { - - private MemUseCloseableCounterImpl(AccumulatedDebugValue counter) { - super(currentTracker.get(), counter); - } - - @Override - long getCounterValue() { - return getCurrentThreadAllocatedBytes(); - } - - @Override - public void close() { - super.close(); - currentTracker.set(parent); - } - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/internal/MetricImpl.java --- a/graal/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/internal/MetricImpl.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,51 +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.jvmci.debug.internal; - -import com.oracle.jvmci.debug.*; - -public final class MetricImpl extends DebugValue implements DebugMetric { - - public MetricImpl(String name, boolean conditional) { - super(name, conditional); - if (isEnabled()) { - // Allows for zero-count metrics to be shown - getCurrentValue(); - } - } - - public void increment() { - add(1); - } - - public void add(long value) { - if (isEnabled()) { - super.addToCurrentValue(value); - } - } - - @Override - public String toString(long value) { - return Long.toString(value); - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/internal/TimerImpl.java --- a/graal/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/internal/TimerImpl.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,136 +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.jvmci.debug.internal; - -import static com.oracle.jvmci.debug.DebugCloseable.*; - -import java.lang.management.*; -import java.util.concurrent.*; - -import com.oracle.jvmci.debug.*; - -public final class TimerImpl extends AccumulatedDebugValue implements DebugTimer { - - private static final ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean(); - - /** - * Records the most recent active timer. - */ - private static final ThreadLocal currentTimer = new ThreadLocal<>(); - - static class FlatTimer extends DebugValue implements DebugTimer { - private TimerImpl accm; - - public FlatTimer(String name, boolean conditional) { - super(name + "_Flat", conditional); - } - - @Override - public String toString(long value) { - return valueToString(value); - } - - public TimeUnit getTimeUnit() { - return accm.getTimeUnit(); - } - - public DebugCloseable start() { - return accm.start(); - } - } - - public TimerImpl(String name, boolean conditional) { - super(name, conditional, new FlatTimer(name, conditional)); - ((FlatTimer) flat).accm = this; - } - - @Override - public DebugCloseable start() { - if (!isConditional() || Debug.isTimeEnabled()) { - AbstractTimer result; - if (threadMXBean.isCurrentThreadCpuTimeSupported()) { - result = new CpuTimeTimer(this); - } else { - result = new SystemNanosTimer(this); - } - currentTimer.set(result); - return result; - } else { - return VOID_CLOSEABLE; - } - } - - public static String valueToString(long value) { - return String.format("%d.%d ms", value / 1000000, (value / 100000) % 10); - } - - public DebugTimer getFlat() { - return (FlatTimer) flat; - } - - @Override - public String toString(long value) { - return valueToString(value); - } - - public TimeUnit getTimeUnit() { - return TimeUnit.NANOSECONDS; - } - - private abstract static class AbstractTimer extends CloseableCounterImpl implements DebugCloseable { - - private AbstractTimer(AccumulatedDebugValue counter) { - super(currentTimer.get(), counter); - } - - @Override - public void close() { - super.close(); - currentTimer.set(parent); - } - } - - private final class SystemNanosTimer extends AbstractTimer { - - public SystemNanosTimer(TimerImpl timer) { - super(timer); - } - - @Override - protected long getCounterValue() { - return System.nanoTime(); - } - } - - private final class CpuTimeTimer extends AbstractTimer { - - public CpuTimeTimer(TimerImpl timer) { - super(timer); - } - - @Override - protected long getCounterValue() { - return threadMXBean.getCurrentThreadCpuTime(); - } - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.hotspot.amd64/src/com/oracle/jvmci/hotspot/amd64/AMD64HotSpotJVMCIBackendFactory.java --- a/graal/com.oracle.jvmci.hotspot.amd64/src/com/oracle/jvmci/hotspot/amd64/AMD64HotSpotJVMCIBackendFactory.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,169 +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.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 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.hotspot.amd64/src/com/oracle/jvmci/hotspot/amd64/AMD64HotSpotRegisterConfig.java --- a/graal/com.oracle.jvmci.hotspot.amd64/src/com/oracle/jvmci/hotspot/amd64/AMD64HotSpotRegisterConfig.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,268 +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.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 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.hotspot.jfr/src/com/oracle/jvmci/hotspot/jfr/events/JFREventProvider.java --- a/graal/com.oracle.jvmci.hotspot.jfr/src/com/oracle/jvmci/hotspot/jfr/events/JFREventProvider.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,170 +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.jvmci.hotspot.jfr.events; - -import java.net.*; - -import com.oracle.jrockit.jfr.*; -import com.oracle.jvmci.hotspot.*; -import com.oracle.jvmci.hotspot.events.*; -import com.oracle.jvmci.hotspot.events.EmptyEventProvider.EmptyCompilerFailureEvent; -import com.oracle.jvmci.hotspot.events.EmptyEventProvider.EmptyCompilationEvent; -import com.oracle.jvmci.service.*; - -/** - * A JFR implementation for {@link EventProvider}. This implementation is used when Flight Recorder - * is turned on. - */ -@ServiceProvider(EventProvider.class) -public final class JFREventProvider implements EventProvider { - - private final boolean enabled; - - @SuppressWarnings("deprecation") - public JFREventProvider() { - enabled = HotSpotJVMCIRuntime.runtime().getConfig().flightRecorder; - if (enabled) { - try { - /* - * The "HotSpot JVM" producer is a native producer and we cannot use it. So we - * create our own. This has the downside that Mission Control is confused and - * doesn't show JVMCI events in the "Code" tab. There are plans to revise the JFR - * code for JDK 9. - */ - Producer producer = new Producer("HotSpot JVM", "Oracle Hotspot JVM", "http://www.oracle.com/hotspot/jvm/"); - producer.register(); - // Register event classes with Producer. - for (Class c : JFREventProvider.class.getDeclaredClasses()) { - if (c.isAnnotationPresent(EventDefinition.class)) { - assert com.oracle.jrockit.jfr.InstantEvent.class.isAssignableFrom(c) : c; - registerEvent(producer, c); - } - } - } catch (URISyntaxException e) { - throw new InternalError(e); - } - } - } - - /** - * Register an event class with the {@link Producer}. - * - * @param c event class - * @return the {@link EventToken event token} - */ - @SuppressWarnings({"deprecation", "javadoc", "unchecked"}) - private static EventToken registerEvent(Producer producer, Class c) { - try { - return producer.addEvent((Class) c); - } catch (InvalidEventDefinitionException | InvalidValueException e) { - throw new InternalError(e); - } - } - - public CompilationEvent newCompilationEvent() { - if (enabled) { - return new JFRCompilationEvent(); - } - return new EmptyCompilationEvent(); - } - - /** - * A JFR compilation event. - * - *

- * See: event {@code Compilation} in {@code src/share/vm/trace/trace.xml} - */ - @SuppressWarnings("deprecation") - @EventDefinition(name = "Compilation", path = "vm/compiler/compilation") - public static class JFRCompilationEvent extends com.oracle.jrockit.jfr.DurationEvent implements CompilationEvent { - - /* - * FIXME method should be a Method* but we can't express that in Java. - */ - @ValueDefinition(name = "Java Method") public String method; - @ValueDefinition(name = "Compilation ID", relationKey = "COMP_ID") public int compileId; - @ValueDefinition(name = "Compilation Level") public short compileLevel; - @ValueDefinition(name = "Succeeded") public boolean succeeded; - @ValueDefinition(name = "On Stack Replacement") public boolean isOsr; - @ValueDefinition(name = "Compiled Code Size", contentType = ContentType.Bytes) public int codeSize; - @ValueDefinition(name = "Inlined Code Size", contentType = ContentType.Bytes) public int inlinedBytes; - - public void setMethod(String method) { - this.method = method; - } - - public void setCompileId(int id) { - this.compileId = id; - } - - public void setCompileLevel(int compileLevel) { - this.compileLevel = (short) compileLevel; - } - - public void setSucceeded(boolean succeeded) { - this.succeeded = succeeded; - } - - public void setIsOsr(boolean isOsr) { - this.isOsr = isOsr; - } - - public void setCodeSize(int codeSize) { - this.codeSize = codeSize; - } - - public void setInlinedBytes(int inlinedBytes) { - this.inlinedBytes = inlinedBytes; - } - } - - public CompilerFailureEvent newCompilerFailureEvent() { - if (enabled) { - return new JFRCompilerFailureEvent(); - } - return new EmptyCompilerFailureEvent(); - } - - /** - * A JFR compiler failure event. - * - *

- * See: event {@code CompilerFailure} in {@code src/share/vm/trace/trace.xml} - */ - @SuppressWarnings("deprecation") - @EventDefinition(name = "Compilation Failure", path = "vm/compiler/failure") - public static class JFRCompilerFailureEvent extends com.oracle.jrockit.jfr.InstantEvent implements CompilerFailureEvent { - - @ValueDefinition(name = "Compilation ID", relationKey = "COMP_ID") public int compileId; - @ValueDefinition(name = "Message", description = "The failure message") public String failure; - - public void setCompileId(int id) { - this.compileId = id; - } - - public void setMessage(String message) { - this.failure = message; - } - } - -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.hotspot.sparc/src/com/oracle/jvmci/hotspot/sparc/SPARCHotSpotJVMCIBackendFactory.java --- a/graal/com.oracle.jvmci.hotspot.sparc/src/com/oracle/jvmci/hotspot/sparc/SPARCHotSpotJVMCIBackendFactory.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,100 +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.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 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.hotspot.sparc/src/com/oracle/jvmci/hotspot/sparc/SPARCHotSpotRegisterConfig.java --- a/graal/com.oracle.jvmci.hotspot.sparc/src/com/oracle/jvmci/hotspot/sparc/SPARCHotSpotRegisterConfig.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,304 +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.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 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/CompilationStatistics.java --- a/graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/CompilationStatistics.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,212 +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.jvmci.hotspot; - -import static java.lang.Thread.*; - -import java.io.*; -import java.lang.annotation.*; -import java.lang.management.*; -import java.lang.reflect.*; -import java.util.*; -import java.util.concurrent.*; - -import com.sun.management.ThreadMXBean; - -@SuppressWarnings("unused") -public final class CompilationStatistics { - - private static final long RESOLUTION = 100000000; - private static final boolean ENABLED = Boolean.getBoolean("jvmci.comp.stats"); - - private static final CompilationStatistics DUMMY = new CompilationStatistics(null, false); - - private static ConcurrentLinkedDeque list = new ConcurrentLinkedDeque<>(); - - private static final ThreadLocal> current = new ThreadLocal>() { - - @Override - protected Deque initialValue() { - return new ArrayDeque<>(); - } - }; - - @Retention(RetentionPolicy.RUNTIME) - @Target(ElementType.FIELD) - private static @interface NotReported { - } - - @Retention(RetentionPolicy.RUNTIME) - @Target(ElementType.FIELD) - private static @interface TimeValue { - } - - private static long zeroTime = System.nanoTime(); - - private static long getThreadAllocatedBytes() { - ThreadMXBean thread = (ThreadMXBean) ManagementFactory.getThreadMXBean(); - return thread.getThreadAllocatedBytes(currentThread().getId()); - } - - @NotReported private final long startTime; - @NotReported private long threadAllocatedBytesStart; - - private int bytecodeCount; - private int codeSize; - @TimeValue private long duration; - private long memoryUsed; - private final boolean osr; - private final String holder; - private final String name; - private final String signature; - - private CompilationStatistics(HotSpotResolvedJavaMethod method, boolean osr) { - this.osr = osr; - if (method != null) { - holder = method.getDeclaringClass().getName(); - name = method.getName(); - signature = method.getSignature().toMethodDescriptor(); - startTime = System.nanoTime(); - bytecodeCount = method.getCodeSize(); - threadAllocatedBytesStart = getThreadAllocatedBytes(); - } else { - holder = ""; - name = ""; - signature = ""; - startTime = 0; - } - } - - public void finish(HotSpotResolvedJavaMethod method, HotSpotInstalledCode code) { - if (ENABLED) { - duration = System.nanoTime() - startTime; - codeSize = (int) code.getCodeSize(); - memoryUsed = getThreadAllocatedBytes() - threadAllocatedBytesStart; - if (current.get().getLast() != this) { - throw new RuntimeException("mismatch in finish()"); - } - current.get().removeLast(); - } - } - - public static CompilationStatistics current() { - return current.get().isEmpty() ? null : current.get().getLast(); - } - - public static CompilationStatistics create(HotSpotResolvedJavaMethod method, boolean isOSR) { - if (ENABLED) { - CompilationStatistics stats = new CompilationStatistics(method, isOSR); - list.add(stats); - current.get().addLast(stats); - return stats; - } else { - return DUMMY; - } - } - - @SuppressWarnings("deprecation") - public static void clear(String dumpName) { - if (!ENABLED) { - return; - } - try { - ConcurrentLinkedDeque snapshot = list; - long snapshotZeroTime = zeroTime; - - list = new ConcurrentLinkedDeque<>(); - zeroTime = System.nanoTime(); - - Date now = new Date(); - String dateString = (now.getYear() + 1900) + "-" + (now.getMonth() + 1) + "-" + now.getDate() + "-" + now.getHours() + "" + now.getMinutes(); - - dumpCompilations(snapshot, dumpName, dateString); - - try (FileOutputStream fos = new FileOutputStream("timeline_" + dateString + "_" + dumpName + ".csv", true); PrintStream out = new PrintStream(fos)) { - - long[] timeSpent = new long[10000]; - int maxTick = 0; - for (CompilationStatistics stats : snapshot) { - long start = stats.startTime - snapshotZeroTime; - long duration = stats.duration; - if (start < 0) { - duration -= -start; - start = 0; - } - - int tick = (int) (start / RESOLUTION); - long timeLeft = RESOLUTION - (start % RESOLUTION); - - while (tick < timeSpent.length && duration > 0) { - if (tick > maxTick) { - maxTick = tick; - } - timeSpent[tick] += Math.min(timeLeft, duration); - duration -= timeLeft; - tick++; - timeLeft = RESOLUTION; - } - } - String timelineName = System.getProperty("stats.timeline.name"); - if (timelineName != null && !timelineName.isEmpty()) { - out.print(timelineName + "\t"); - } - for (int i = 0; i <= maxTick; i++) { - out.print((timeSpent[i] * 100 / RESOLUTION) + "\t"); - } - out.println(); - } - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - protected static void dumpCompilations(ConcurrentLinkedDeque snapshot, String dumpName, String dateString) throws IllegalAccessException, FileNotFoundException { - String fileName = "compilations_" + dateString + "_" + dumpName + ".csv"; - try (PrintStream out = new PrintStream(fileName)) { - // output the list of all compilations - - Field[] declaredFields = CompilationStatistics.class.getDeclaredFields(); - ArrayList fields = new ArrayList<>(); - for (Field field : declaredFields) { - if (!Modifier.isStatic(field.getModifiers()) && !field.isAnnotationPresent(NotReported.class)) { - fields.add(field); - } - } - for (Field field : fields) { - out.print(field.getName() + "\t"); - } - out.println(); - for (CompilationStatistics stats : snapshot) { - for (Field field : fields) { - if (field.isAnnotationPresent(TimeValue.class)) { - double value = field.getLong(stats) / 1000000d; - out.print(String.format(Locale.ENGLISH, "%.3f", value) + "\t"); - } else { - out.print(field.get(stats) + "\t"); - } - } - out.println(); - } - } - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/CompilationTask.java --- a/graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/CompilationTask.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,293 +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.jvmci.hotspot; - -import static com.oracle.jvmci.common.UnsafeAccess.*; -import static com.oracle.jvmci.debug.Debug.*; -import static com.oracle.jvmci.compiler.Compiler.*; - -import java.lang.management.*; -import java.util.concurrent.*; - -import com.oracle.jvmci.code.*; -import com.oracle.jvmci.compiler.Compiler; -import com.oracle.jvmci.debug.*; -import com.oracle.jvmci.debug.Debug.Scope; -import com.oracle.jvmci.debug.internal.*; -import com.oracle.jvmci.hotspot.events.*; -import com.oracle.jvmci.hotspot.events.EventProvider.CompilationEvent; -import com.oracle.jvmci.hotspot.events.EventProvider.CompilerFailureEvent; -import com.oracle.jvmci.meta.*; -import com.oracle.jvmci.service.*; - -//JaCoCo Exclude - -public class CompilationTask { - - private static final DebugMetric BAILOUTS = Debug.metric("Bailouts"); - - private static final EventProvider eventProvider; - static { - EventProvider provider = Services.loadSingle(EventProvider.class, false); - if (provider == null) { - eventProvider = new EmptyEventProvider(); - } else { - eventProvider = provider; - } - } - private static final Compiler compiler = Services.loadSingle(Compiler.class, true); - - private final HotSpotResolvedJavaMethod method; - private final int entryBCI; - private final int id; - - /** - * Specifies whether the compilation result is installed as the - * {@linkplain HotSpotNmethod#isDefault() default} nmethod for the compiled method. - */ - private final boolean installAsDefault; - - /** - * A {@link com.sun.management.ThreadMXBean} to be able to query some information about the - * current compiler thread, e.g. total allocated bytes. - */ - private static final com.sun.management.ThreadMXBean threadMXBean = (com.sun.management.ThreadMXBean) ManagementFactory.getThreadMXBean(); - - /** - * The address of the JVMCIEnv associated with this compilation or 0L if no such object exists. - */ - private final long jvmciEnv; - - public CompilationTask(HotSpotResolvedJavaMethod method, int entryBCI, long jvmciEnv, int id, boolean installAsDefault) { - this.method = method; - this.entryBCI = entryBCI; - this.id = id; - this.jvmciEnv = jvmciEnv; - this.installAsDefault = installAsDefault; - } - - public ResolvedJavaMethod getMethod() { - return method; - } - - /** - * Returns the compilation id of this task. - * - * @return compile id - */ - public int getId() { - return id; - } - - public int getEntryBCI() { - return entryBCI; - } - - /** - * Time spent in compilation. - */ - private static final DebugTimer CompilationTime = Debug.timer("CompilationTime"); - - /** - * Meters the {@linkplain CompilationResult#getBytecodeSize() bytecodes} compiled. - */ - private static final DebugMetric CompiledBytecodes = Debug.metric("CompiledBytecodes"); - - public static final DebugTimer CodeInstallationTime = Debug.timer("CodeInstallation"); - - public void runCompilation() { - HotSpotVMConfig config = HotSpotJVMCIRuntime.runtime().getConfig(); - final long threadId = Thread.currentThread().getId(); - long startCompilationTime = System.nanoTime(); - HotSpotInstalledCode installedCode = null; - final boolean isOSR = entryBCI != Compiler.INVOCATION_ENTRY_BCI; - - // Log a compilation event. - CompilationEvent compilationEvent = eventProvider.newCompilationEvent(); - - // If there is already compiled code for this method on our level we simply return. - // JVMCI compiles are always at the highest compile level, even in non-tiered mode so we - // only need to check for that value. - if (method.hasCodeAtLevel(entryBCI, config.compilationLevelFullOptimization)) { - return; - } - - CompilationResult result = null; - try (DebugCloseable a = CompilationTime.start()) { - CompilationStatistics stats = CompilationStatistics.create(method, isOSR); - final boolean printCompilation = PrintCompilation.getValue() && !TTY.isSuppressed(); - if (printCompilation) { - TTY.println(getMethodDescription() + "..."); - } - - TTY.Filter filter = new TTY.Filter(PrintFilter.getValue(), method); - final long start = System.currentTimeMillis(); - final long allocatedBytesBefore = threadMXBean.getThreadAllocatedBytes(threadId); - - try (Scope s = Debug.scope("Compiling", new DebugDumpScope(String.valueOf(id), true))) { - // Begin the compilation event. - compilationEvent.begin(); - - result = compiler.compile(method, entryBCI, mustRecordMethodInlining(config)); - - result.setId(getId()); - } catch (Throwable e) { - throw Debug.handle(e); - } finally { - // End the compilation event. - compilationEvent.end(); - - filter.remove(); - final boolean printAfterCompilation = PrintAfterCompilation.getValue() && !TTY.isSuppressed(); - - if (printAfterCompilation || printCompilation) { - final long stop = System.currentTimeMillis(); - final int targetCodeSize = result != null ? result.getTargetCodeSize() : -1; - final long allocatedBytesAfter = threadMXBean.getThreadAllocatedBytes(threadId); - final long allocatedBytes = (allocatedBytesAfter - allocatedBytesBefore) / 1024; - - if (printAfterCompilation) { - TTY.println(getMethodDescription() + String.format(" | %4dms %5dB %5dkB", stop - start, targetCodeSize, allocatedBytes)); - } else if (printCompilation) { - TTY.println(String.format("%-6d JVMCI %-70s %-45s %-50s | %4dms %5dB %5dkB", id, "", "", "", stop - start, targetCodeSize, allocatedBytes)); - } - } - } - - try (DebugCloseable b = CodeInstallationTime.start()) { - installedCode = (HotSpotInstalledCode) installMethod(result); - } - stats.finish(method, installedCode); - } catch (BailoutException bailout) { - BAILOUTS.increment(); - if (ExitVMOnBailout.getValue()) { - TTY.cachedOut.println(method.format("Bailout in %H.%n(%p)")); - bailout.printStackTrace(TTY.cachedOut); - System.exit(-1); - } else if (PrintBailout.getValue()) { - TTY.cachedOut.println(method.format("Bailout in %H.%n(%p)")); - bailout.printStackTrace(TTY.cachedOut); - } - } catch (Throwable t) { - if (PrintStackTraceOnException.getValue() || ExitVMOnException.getValue()) { - t.printStackTrace(TTY.cachedOut); - } - - // Log a failure event. - CompilerFailureEvent event = eventProvider.newCompilerFailureEvent(); - if (event.shouldWrite()) { - event.setCompileId(getId()); - event.setMessage(t.getMessage()); - event.commit(); - } - - if (ExitVMOnException.getValue()) { - System.exit(-1); - } - } finally { - int compiledBytecodes = 0; - int codeSize = 0; - if (result != null) { - compiledBytecodes = result.getBytecodeSize(); - } - if (installedCode != null) { - codeSize = installedCode.getSize(); - } - CompiledBytecodes.add(compiledBytecodes); - - // Log a compilation event. - if (compilationEvent.shouldWrite()) { - compilationEvent.setMethod(method.format("%H.%n(%p)")); - compilationEvent.setCompileId(getId()); - compilationEvent.setCompileLevel(config.compilationLevelFullOptimization); - compilationEvent.setSucceeded(result != null && installedCode != null); - compilationEvent.setIsOsr(isOSR); - compilationEvent.setCodeSize(codeSize); - compilationEvent.setInlinedBytes(compiledBytecodes); - compilationEvent.commit(); - } - - if (jvmciEnv != 0) { - long ctask = unsafe.getAddress(jvmciEnv + config.jvmciEnvTaskOffset); - assert ctask != 0L; - unsafe.putInt(ctask + config.compileTaskNumInlinedBytecodesOffset, compiledBytecodes); - } - long compilationTime = System.nanoTime() - startCompilationTime; - if ((config.ciTime || config.ciTimeEach) && installedCode != null) { - long timeUnitsPerSecond = TimeUnit.NANOSECONDS.convert(1, TimeUnit.SECONDS); - CompilerToVM c2vm = HotSpotJVMCIRuntime.runtime().getCompilerToVM(); - c2vm.notifyCompilationStatistics(id, method, entryBCI != Compiler.INVOCATION_ENTRY_BCI, compiledBytecodes, compilationTime, timeUnitsPerSecond, installedCode); - } - } - } - - /** - * Determines whether to disable method inlining recording for the method being compiled. - */ - private boolean mustRecordMethodInlining(HotSpotVMConfig config) { - if (config.ciTime || config.ciTimeEach || CompiledBytecodes.isEnabled()) { - return true; - } - if (jvmciEnv == 0 || unsafe.getByte(jvmciEnv + config.jvmciEnvJvmtiCanHotswapOrPostBreakpointOffset) != 0) { - return true; - } - return false; - } - - private String getMethodDescription() { - return String.format("%-6d JVMCI %-70s %-45s %-50s %s", id, method.getDeclaringClass().getName(), method.getName(), method.getSignature().toMethodDescriptor(), - entryBCI == Compiler.INVOCATION_ENTRY_BCI ? "" : "(OSR@" + entryBCI + ") "); - } - - private InstalledCode installMethod(final CompilationResult compResult) { - final HotSpotCodeCacheProvider codeCache = (HotSpotCodeCacheProvider) HotSpotJVMCIRuntime.runtime().getHostJVMCIBackend().getCodeCache(); - InstalledCode installedCode = null; - try (Scope s = Debug.scope("CodeInstall", new DebugDumpScope(String.valueOf(id), true), codeCache, method)) { - installedCode = codeCache.installMethod(method, compResult, jvmciEnv, installAsDefault); - } catch (Throwable e) { - throw Debug.handle(e); - } - return installedCode; - } - - @Override - public String toString() { - return "Compilation[id=" + id + ", " + method.format("%H.%n(%p)") + (entryBCI == Compiler.INVOCATION_ENTRY_BCI ? "" : "@" + entryBCI) + "]"; - } - - /** - * Compiles a method to machine code. - */ - public static void compileMethod(HotSpotResolvedJavaMethod method, int entryBCI, long jvmciEnv, int id) { - // Ensure a debug configuration for this thread is initialized - if (Debug.isEnabled() && DebugScope.getConfig() == null) { - DebugEnvironment.initialize(TTY.cachedOut); - } - - CompilationTask task = new CompilationTask(method, entryBCI, jvmciEnv, id, true); - try (DebugConfigScope dcs = setConfig(new TopLevelDebugConfig())) { - task.runCompilation(); - } - return; - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/CompileTheWorld.java --- a/graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/CompileTheWorld.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,503 +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.hotspot; - -import static com.oracle.jvmci.compiler.Compiler.*; -import static com.oracle.jvmci.debug.internal.MemUseTrackerImpl.*; - -import java.io.*; -import java.lang.annotation.*; -import java.lang.reflect.*; -import java.net.*; -import java.util.*; -import java.util.concurrent.*; -import java.util.concurrent.atomic.*; -import java.util.jar.*; -import java.util.stream.*; - -import com.oracle.jvmci.compiler.*; -import com.oracle.jvmci.compiler.CompilerThreadFactory.DebugConfigAccess; -import com.oracle.jvmci.compiler.Compiler; -import com.oracle.jvmci.debug.*; -import com.oracle.jvmci.debug.internal.*; -import com.oracle.jvmci.meta.*; -import com.oracle.jvmci.options.*; -import com.oracle.jvmci.options.OptionUtils.OptionConsumer; -import com.oracle.jvmci.options.OptionValue.OverrideScope; -import com.oracle.jvmci.runtime.*; - -/** - * This class implements compile-the-world functionality with JVMCI. - */ -public final class CompileTheWorld { - - /** - * Magic token to trigger reading files from the boot class path. - */ - public static final String SUN_BOOT_CLASS_PATH = "sun.boot.class.path"; - - public static class Options { - // @formatter:off - @Option(help = "Compile all methods in all classes on given class path", type = OptionType.Debug) - public static final OptionValue CompileTheWorldClasspath = new OptionValue<>(SUN_BOOT_CLASS_PATH); - @Option(help = "Verbose CompileTheWorld operation", type = OptionType.Debug) - public static final OptionValue CompileTheWorldVerbose = new OptionValue<>(true); - @Option(help = "The number of CompileTheWorld iterations to perform", type = OptionType.Debug) - public static final OptionValue CompileTheWorldIterations = new OptionValue<>(1); - @Option(help = "Only compile methods matching this filter", type = OptionType.Debug) - public static final OptionValue CompileTheWorldMethodFilter = new OptionValue<>(null); - @Option(help = "Exclude methods matching this filter from compilation", type = OptionType.Debug) - public static final OptionValue CompileTheWorldExcludeMethodFilter = new OptionValue<>(null); - @Option(help = "First class to consider when using -XX:+CompileTheWorld", type = OptionType.Debug) - public static final OptionValue CompileTheWorldStartAt = new OptionValue<>(1); - @Option(help = "Last class to consider when using -XX:+CompileTheWorld", type = OptionType.Debug) - public static final OptionValue CompileTheWorldStopAt = new OptionValue<>(Integer.MAX_VALUE); - @Option(help = "Option value overrides to use during compile the world. For example, " + - "to disable inlining and partial escape analysis specify '-PartialEscapeAnalysis -Inline'. " + - "The format for each option is the same as on the command line just without the '-G:' prefix.", type = OptionType.Debug) - public static final OptionValue CompileTheWorldConfig = new OptionValue<>(null); - - @Option(help = "Run CTW using as many threads as there are processors on the system", type = OptionType.Debug) - public static final OptionValue CompileTheWorldMultiThreaded = new OptionValue<>(false); - @Option(help = "Number of threads to use for multithreaded CTW. Defaults to Runtime.getRuntime().availableProcessors()", type = OptionType.Debug) - public static final OptionValue CompileTheWorldThreads = new OptionValue<>(0); - // @formatter:on - - /** - * Overrides {@link #CompileTheWorldStartAt} and {@link #CompileTheWorldStopAt} from - * {@code -XX} HotSpot options of the same name if the latter have non-default values. - */ - public static void overrideWithNativeOptions(HotSpotVMConfig c) { - if (c.compileTheWorldStartAt != 1) { - CompileTheWorldStartAt.setValue(c.compileTheWorldStartAt); - } - if (c.compileTheWorldStopAt != Integer.MAX_VALUE) { - CompileTheWorldStopAt.setValue(c.compileTheWorldStopAt); - } - } - } - - /** - * A mechanism for overriding JVMCI options that affect compilation. A {@link Config} object - * should be used in a try-with-resources statement to ensure overriding of options is scoped - * properly. For example: - * - *

-     *     Config config = ...;
-     *     try (AutoCloseable s = config == null ? null : config.apply()) {
-     *         // perform a JVMCI compilation
-     *     }
-     * 
- */ - @SuppressWarnings("serial") - public static class Config extends HashMap, Object> implements OptionConsumer { - /** - * Creates a {@link Config} object by parsing a set of space separated override options. - * - * @param options a space separated set of option value settings with each option setting in - * a format compatible with - * {@link OptionUtils#parseOption(String, OptionConsumer)}. Ignored if null. - */ - public Config(String options) { - if (options != null) { - for (String option : options.split("\\s+")) { - OptionUtils.parseOption(option, this); - } - } - } - - /** - * Applies the overrides represented by this object. The overrides are in effect until - * {@link OverrideScope#close()} is called on the returned object. - */ - OverrideScope apply() { - return OptionValue.override(this); - } - - public void set(OptionDescriptor desc, Object value) { - put(desc.getOptionValue(), value); - } - } - - /** List of Zip/Jar files to compile (see {@link Options#CompileTheWorldClasspath}). */ - private final String files; - - /** Class index to start compilation at (see {@link Options#CompileTheWorldStartAt}). */ - private final int startAt; - - /** Class index to stop compilation at (see {@link Options#CompileTheWorldStopAt}). */ - private final int stopAt; - - /** Only compile methods matching one of the filters in this array if the array is non-null. */ - private final MethodFilter[] methodFilters; - - /** Exclude methods matching one of the filters in this array if the array is non-null. */ - private final MethodFilter[] excludeMethodFilters; - - // Counters - private int classFileCounter = 0; - private AtomicLong compiledMethodsCounter = new AtomicLong(); - private AtomicLong compileTime = new AtomicLong(); - private AtomicLong memoryUsed = new AtomicLong(); - - private boolean verbose; - private final Config config; - - /** - * Signal that the threads should start compiling in multithreaded mode. - */ - private boolean running; - - private ThreadPoolExecutor threadPool; - - /** - * Creates a compile-the-world instance. - * - * @param files {@link File#pathSeparator} separated list of Zip/Jar files to compile - * @param startAt index of the class file to start compilation at - * @param stopAt index of the class file to stop compilation at - * @param methodFilters - * @param excludeMethodFilters - */ - public CompileTheWorld(String files, Config config, int startAt, int stopAt, String methodFilters, String excludeMethodFilters, boolean verbose) { - this.files = files; - this.startAt = startAt; - this.stopAt = stopAt; - this.methodFilters = methodFilters == null || methodFilters.isEmpty() ? null : MethodFilter.parse(methodFilters); - this.excludeMethodFilters = excludeMethodFilters == null || excludeMethodFilters.isEmpty() ? null : MethodFilter.parse(excludeMethodFilters); - this.verbose = verbose; - this.config = config; - - // We don't want the VM to exit when a method fails to compile... - config.putIfAbsent(ExitVMOnException, false); - - // ...but we want to see exceptions. - config.putIfAbsent(PrintBailout, true); - config.putIfAbsent(PrintStackTraceOnException, true); - config.putIfAbsent(HotSpotResolvedJavaMethodImpl.Options.UseProfilingInformation, false); - } - - /** - * Compiles all methods in all classes in the Zip/Jar archive files in - * {@link Options#CompileTheWorldClasspath}. If {@link Options#CompileTheWorldClasspath} - * contains the magic token {@link #SUN_BOOT_CLASS_PATH} passed up from HotSpot we take the - * files from the boot class path. - */ - public void compile() throws Throwable { - // By default only report statistics for the CTW threads themselves - if (JVMCIDebugConfig.DebugValueThreadFilter.hasDefaultValue()) { - JVMCIDebugConfig.DebugValueThreadFilter.setValue("^CompileTheWorld"); - } - - if (SUN_BOOT_CLASS_PATH.equals(files)) { - final String[] entries = System.getProperty(SUN_BOOT_CLASS_PATH).split(File.pathSeparator); - String bcpFiles = ""; - for (int i = 0; i < entries.length; i++) { - final String entry = entries[i]; - - // We stop at rt.jar, unless it is the first boot class path entry. - if (entry.endsWith("rt.jar") && (i > 0)) { - break; - } - if (i > 0) { - bcpFiles += File.pathSeparator; - } - bcpFiles += entry; - } - compile(bcpFiles); - } else { - compile(files); - } - } - - public void println() { - println(""); - } - - public void println(String format, Object... args) { - println(String.format(format, args)); - } - - public void println(String s) { - if (verbose) { - TTY.println(s); - } - } - - @SuppressWarnings("unused") - private static void dummy() { - } - - /** - * Compiles all methods in all classes in the Zip/Jar files passed. - * - * @param fileList {@link File#pathSeparator} separated list of Zip/Jar files to compile - * @throws IOException - */ - private void compile(String fileList) throws IOException { - final String[] entries = fileList.split(File.pathSeparator); - long start = System.currentTimeMillis(); - - CompilerThreadFactory factory = new CompilerThreadFactory("CompileTheWorld", new DebugConfigAccess() { - public JVMCIDebugConfig getDebugConfig() { - if (Debug.isEnabled() && DebugScope.getConfig() == null) { - return DebugEnvironment.initialize(System.out); - } - return null; - } - }); - - try { - // compile dummy method to get compiler initilized outside of the config debug override. - HotSpotResolvedJavaMethod dummyMethod = (HotSpotResolvedJavaMethod) JVMCI.getRuntime().getHostJVMCIBackend().getMetaAccess().lookupJavaMethod( - CompileTheWorld.class.getDeclaredMethod("dummy")); - CompilationTask task = new CompilationTask(dummyMethod, Compiler.INVOCATION_ENTRY_BCI, 0L, dummyMethod.allocateCompileId(Compiler.INVOCATION_ENTRY_BCI), false); - task.runCompilation(); - } catch (NoSuchMethodException | SecurityException e1) { - e1.printStackTrace(); - } - - /* - * Always use a thread pool, even for single threaded mode since it simplifies the use of - * DebugValueThreadFilter to filter on the thread names. - */ - int threadCount = 1; - if (Options.CompileTheWorldMultiThreaded.getValue()) { - threadCount = Options.CompileTheWorldThreads.getValue(); - if (threadCount == 0) { - threadCount = Runtime.getRuntime().availableProcessors(); - } - } else { - running = true; - } - threadPool = new ThreadPoolExecutor(threadCount, threadCount, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue(), factory); - - try (OverrideScope s = config.apply()) { - for (int i = 0; i < entries.length; i++) { - final String entry = entries[i]; - - // For now we only compile all methods in all classes in zip/jar files. - if (!entry.endsWith(".zip") && !entry.endsWith(".jar")) { - println("CompileTheWorld : Skipped classes in " + entry); - println(); - continue; - } - - if (methodFilters == null || methodFilters.length == 0) { - println("CompileTheWorld : Compiling all classes in " + entry); - } else { - String include = Arrays.asList(methodFilters).stream().map(MethodFilter::toString).collect(Collectors.joining(", ")); - println("CompileTheWorld : Compiling all methods in " + entry + " matching one of the following filters: " + include); - } - if (excludeMethodFilters != null && excludeMethodFilters.length > 0) { - String exclude = Arrays.asList(excludeMethodFilters).stream().map(MethodFilter::toString).collect(Collectors.joining(", ")); - println("CompileTheWorld : Excluding all methods matching one of the following filters: " + exclude); - } - println(); - - URL url = new URL("jar", "", "file:" + entry + "!/"); - ClassLoader loader = new URLClassLoader(new URL[]{url}); - - JarFile jarFile = new JarFile(entry); - Enumeration e = jarFile.entries(); - - while (e.hasMoreElements()) { - JarEntry je = e.nextElement(); - if (je.isDirectory() || !je.getName().endsWith(".class")) { - continue; - } - - // Are we done? - if (classFileCounter >= stopAt) { - break; - } - - String className = je.getName().substring(0, je.getName().length() - ".class".length()); - String dottedClassName = className.replace('/', '.'); - classFileCounter++; - - if (methodFilters != null && !MethodFilter.matchesClassName(methodFilters, dottedClassName)) { - continue; - } - if (excludeMethodFilters != null && MethodFilter.matchesClassName(excludeMethodFilters, dottedClassName)) { - continue; - } - - if (dottedClassName.startsWith("jdk.management.") || dottedClassName.startsWith("jdk.internal.cmm.*")) { - continue; - } - - try { - // Load and initialize class - Class javaClass = Class.forName(dottedClassName, true, loader); - - // Pre-load all classes in the constant pool. - try { - HotSpotResolvedObjectType objectType = HotSpotResolvedObjectTypeImpl.fromObjectClass(javaClass); - ConstantPool constantPool = objectType.constantPool(); - for (int cpi = 1; cpi < constantPool.length(); cpi++) { - constantPool.loadReferencedType(cpi, HotSpotConstantPool.Bytecodes.LDC); - } - } catch (Throwable t) { - // If something went wrong during pre-loading we just ignore it. - println("Preloading failed for (%d) %s: %s", classFileCounter, className, t); - } - - // Are we compiling this class? - MetaAccessProvider metaAccess = JVMCI.getRuntime().getHostJVMCIBackend().getMetaAccess(); - if (classFileCounter >= startAt) { - println("CompileTheWorld (%d) : %s", classFileCounter, className); - - // Compile each constructor/method in the class. - for (Constructor constructor : javaClass.getDeclaredConstructors()) { - HotSpotResolvedJavaMethod javaMethod = (HotSpotResolvedJavaMethod) metaAccess.lookupJavaMethod(constructor); - if (canBeCompiled(javaMethod, constructor.getModifiers())) { - compileMethod(javaMethod); - } - } - for (Method method : javaClass.getDeclaredMethods()) { - HotSpotResolvedJavaMethod javaMethod = (HotSpotResolvedJavaMethod) metaAccess.lookupJavaMethod(method); - if (canBeCompiled(javaMethod, method.getModifiers())) { - compileMethod(javaMethod); - } - } - } - } catch (Throwable t) { - println("CompileTheWorld (%d) : Skipping %s %s", classFileCounter, className, t.toString()); - t.printStackTrace(); - } - } - jarFile.close(); - } - } - - if (!running) { - startThreads(); - } - int wakeups = 0; - while (threadPool.getCompletedTaskCount() != threadPool.getTaskCount()) { - if (wakeups % 15 == 0) { - TTY.println("CompileTheWorld : Waiting for " + (threadPool.getTaskCount() - threadPool.getCompletedTaskCount()) + " compiles"); - } - try { - threadPool.awaitTermination(1, TimeUnit.SECONDS); - wakeups++; - } catch (InterruptedException e) { - } - } - threadPool = null; - - long elapsedTime = System.currentTimeMillis() - start; - - println(); - if (Options.CompileTheWorldMultiThreaded.getValue()) { - TTY.println("CompileTheWorld : Done (%d classes, %d methods, %d ms elapsed, %d ms compile time, %d bytes of memory used)", classFileCounter, compiledMethodsCounter.get(), elapsedTime, - compileTime.get(), memoryUsed.get()); - } else { - TTY.println("CompileTheWorld : Done (%d classes, %d methods, %d ms, %d bytes of memory used)", classFileCounter, compiledMethodsCounter.get(), compileTime.get(), memoryUsed.get()); - } - } - - private synchronized void startThreads() { - running = true; - // Wake up any waiting threads - notifyAll(); - } - - private synchronized void waitToRun() { - while (!running) { - try { - wait(); - } catch (InterruptedException e) { - } - } - } - - private void compileMethod(HotSpotResolvedJavaMethod method) throws InterruptedException, ExecutionException { - if (methodFilters != null && !MethodFilter.matches(methodFilters, method)) { - return; - } - if (excludeMethodFilters != null && MethodFilter.matches(excludeMethodFilters, method)) { - return; - } - Future task = threadPool.submit(new Runnable() { - public void run() { - waitToRun(); - try (OverrideScope s = config.apply()) { - compileMethod(method, classFileCounter); - } - } - }); - if (threadPool.getCorePoolSize() == 1) { - task.get(); - } - } - - /** - * Compiles a method and gathers some statistics. - */ - private void compileMethod(HotSpotResolvedJavaMethod method, int counter) { - try { - long start = System.currentTimeMillis(); - long allocatedAtStart = getCurrentThreadAllocatedBytes(); - - CompilationTask task = new CompilationTask(method, Compiler.INVOCATION_ENTRY_BCI, 0L, method.allocateCompileId(Compiler.INVOCATION_ENTRY_BCI), false); - task.runCompilation(); - - memoryUsed.getAndAdd(getCurrentThreadAllocatedBytes() - allocatedAtStart); - compileTime.getAndAdd(System.currentTimeMillis() - start); - compiledMethodsCounter.incrementAndGet(); - } catch (Throwable t) { - // Catch everything and print a message - println("CompileTheWorld (%d) : Error compiling method: %s", counter, method.format("%H.%n(%p):%r")); - t.printStackTrace(TTY.cachedOut); - } - } - - /** - * Determines if a method should be compiled (Cf. CompilationPolicy::can_be_compiled). - * - * @return true if it can be compiled, false otherwise - */ - private static boolean canBeCompiled(HotSpotResolvedJavaMethod javaMethod, int modifiers) { - if (Modifier.isAbstract(modifiers) || Modifier.isNative(modifiers)) { - return false; - } - HotSpotVMConfig c = HotSpotJVMCIRuntime.runtime().getConfig(); - if (c.dontCompileHugeMethods && javaMethod.getCodeSize() > c.hugeMethodLimit) { - return false; - } - // Allow use of -XX:CompileCommand=dontinline to exclude problematic methods - if (!javaMethod.canBeInlined()) { - return false; - } - // Skip @Snippets for now - for (Annotation annotation : javaMethod.getAnnotations()) { - if (annotation.annotationType().getName().equals("com.oracle.graal.replacements.Snippet")) { - return false; - } - } - return true; - } - -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/CompilerToVM.java --- a/graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/CompilerToVM.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,342 +0,0 @@ -/* - * Copyright (c) 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 sun.misc.*; - -import com.oracle.jvmci.code.*; -import com.oracle.jvmci.hotspotvmconfig.*; -import com.oracle.jvmci.meta.*; - -/** - * Calls from Java into HotSpot. - */ -public interface CompilerToVM { - - /** - * Copies the original bytecode of a given method into a new byte array and returns it. - * - * @param metaspaceMethod the metaspace Method object - * @return a new byte array containing the original bytecode - */ - byte[] getBytecode(long metaspaceMethod); - - int exceptionTableLength(long metaspaceMethod); - - long exceptionTableStart(long metaspaceMethod); - - /** - * Determines if a given metaspace Method object has balanced monitors. - * - * @param metaspaceMethod the metaspace Method object to query - * @return true if the method has balanced monitors - */ - boolean hasBalancedMonitors(long metaspaceMethod); - - /** - * Determines if a given metaspace Method can be inlined. A method may not be inlinable for a - * number of reasons such as: - *
    - *
  • a CompileOracle directive may prevent inlining or compilation of methods
  • - *
  • the method may have a bytecode breakpoint set
  • - *
  • the method may have other bytecode features that require special handling by the VM
  • - *
- * - * @param metaspaceMethod the metaspace Method object to query - * @return true if the method can be inlined - */ - boolean canInlineMethod(long metaspaceMethod); - - /** - * Determines if a given metaspace Method should be inlined at any cost. This could be because: - *
    - *
  • a CompileOracle directive may forces inlining of this methods
  • - *
  • an annotation forces inlining of this method
  • - *
- * - * @param metaspaceMethod the metaspace Method object to query - * @return true if the method should be inlined - */ - boolean shouldInlineMethod(long metaspaceMethod); - - /** - * Used to implement {@link ResolvedJavaType#findUniqueConcreteMethod(ResolvedJavaMethod)}. - * - * @param metaspaceMethod the metaspace Method on which to based the search - * @param actualHolderMetaspaceKlass the best known type of receiver - * @return the metaspace Method result or 0 is there is no unique concrete method for - * {@code metaspaceMethod} - */ - long findUniqueConcreteMethod(long actualHolderMetaspaceKlass, long metaspaceMethod); - - /** - * Returns the implementor for the given interface class, if there is a single implementor. - * - * @param metaspaceKlass the metaspace klass to get the implementor for - * @return the implementor as metaspace klass pointer if there is a single implementor, null if - * there is no implementor, or the input metaspace klass pointer ({@code metaspaceKlass} - * ) itself if there is more than one implementor. - */ - long getKlassImplementor(long metaspaceKlass); - - /** - * Determines if a given metaspace method is ignored by security stack walks. - * - * @param metaspaceMethod the metaspace Method object - * @return true if the method is ignored - */ - boolean methodIsIgnoredBySecurityStackWalk(long metaspaceMethod); - - /** - * Converts a name to a metaspace klass. - * - * @param name a well formed Java type in {@linkplain JavaType#getName() internal} format - * @param accessingClass the context of resolution (must not be null) - * @param resolve force resolution to a {@link ResolvedJavaType}. If true, this method will - * either return a {@link ResolvedJavaType} or throw an exception - * @return a metaspace klass for {@code name} - * @throws LinkageError if {@code resolve == true} and the resolution failed - */ - long lookupType(String name, Class accessingClass, boolean resolve); - - Object resolveConstantInPool(long metaspaceConstantPool, int cpi); - - Object resolvePossiblyCachedConstantInPool(long metaspaceConstantPool, int cpi); - - int lookupNameAndTypeRefIndexInPool(long metaspaceConstantPool, int cpi); - - String lookupNameRefInPool(long metaspaceConstantPool, int cpi); - - String lookupSignatureRefInPool(long metaspaceConstantPool, int cpi); - - int lookupKlassRefIndexInPool(long metaspaceConstantPool, int cpi); - - long constantPoolKlassAt(long metaspaceConstantPool, int cpi); - - /** - * Looks up a class entry in a constant pool. - * - * @param metaspaceConstantPool metaspace constant pool pointer - * @param cpi constant pool index - * @return a metaspace Klass for a resolved method entry, a metaspace Symbol otherwise (with - * tagging) - */ - long lookupKlassInPool(long metaspaceConstantPool, int cpi); - - /** - * Looks up a method entry in a constant pool. - * - * @param metaspaceConstantPool metaspace constant pool pointer - * @param cpi constant pool index - * @return a metaspace Method for a resolved method entry, 0 otherwise - */ - long lookupMethodInPool(long metaspaceConstantPool, int cpi, byte opcode); - - /** - * Looks up a field entry in a constant pool and attempts to resolve it. The values returned in - * {@code info} are: - * - *
-     *     [(int) flags,   // only valid if field is resolved
-     *      (int) offset]  // only valid if field is resolved
-     * 
- * - * @param metaspaceConstantPool metaspace constant pool pointer - * @param cpi constant pool index - * @param info an array in which the details of the field are returned - * @return true if the field is resolved - */ - long resolveField(long metaspaceConstantPool, int cpi, byte opcode, long[] info); - - int constantPoolRemapInstructionOperandFromCache(long metaspaceConstantPool, int cpi); - - Object lookupAppendixInPool(long metaspaceConstantPool, int cpi); - - /** - * Installs the result of a compilation into the code cache. - * - * @param compiledCode the result of a compilation - * @param code the details of the installed CodeBlob are written to this object - * @return the outcome of the installation which will be one of - * {@link HotSpotVMConfig#codeInstallResultOk}, - * {@link HotSpotVMConfig#codeInstallResultCacheFull}, - * {@link HotSpotVMConfig#codeInstallResultCodeTooLarge}, - * {@link HotSpotVMConfig#codeInstallResultDependenciesFailed} or - * {@link HotSpotVMConfig#codeInstallResultDependenciesInvalid}. - */ - int installCode(HotSpotCompiledCode compiledCode, InstalledCode code, SpeculationLog speculationLog); - - /** - * Notifies the VM of statistics for a completed compilation. - * - * @param id the identifier of the compilation - * @param method the method compiled - * @param osr specifies if the compilation was for on-stack-replacement - * @param processedBytecodes the number of bytecodes processed during the compilation, including - * the bytecodes of all inlined methods - * @param time the amount time spent compiling {@code method} - * @param timeUnitsPerSecond the granularity of the units for the {@code time} value - * @param installedCode the nmethod installed as a result of the compilation - */ - void notifyCompilationStatistics(int id, HotSpotResolvedJavaMethod method, boolean osr, int processedBytecodes, long time, long timeUnitsPerSecond, InstalledCode installedCode); - - void resetCompilationStatistics(); - - void initializeConfiguration(HotSpotVMConfig config); - - long resolveMethod(long metaspaceKlassExactReceiver, long metaspaceMethod, long metaspaceKlassCaller); - - long getClassInitializer(long metaspaceKlass); - - boolean hasFinalizableSubclass(long metaspaceKlass); - - /** - * Gets the metaspace Method object corresponding to a given {@link Class} object and slot - * number. - * - * @param holder method holder - * @param slot slot number of the method - * @return the metaspace Method - */ - long getMetaspaceMethod(Class holder, int slot); - - long getMaxCallTargetOffset(long address); - - String disassembleCodeBlob(long codeBlob); - - StackTraceElement getStackTraceElement(long metaspaceMethod, int bci); - - Object executeCompiledMethod(Object arg1, Object arg2, Object arg3, InstalledCode hotspotInstalledCode) throws InvalidInstalledCodeException; - - Object executeCompiledMethodVarargs(Object[] args, InstalledCode hotspotInstalledCode) throws InvalidInstalledCodeException; - - long[] getLineNumberTable(long metaspaceMethod); - - long getLocalVariableTableStart(long metaspaceMethod); - - int getLocalVariableTableLength(long metaspaceMethod); - - String getFileName(HotSpotResolvedJavaType method); - - Class getJavaMirror(long metaspaceKlass); - - long readUnsafeKlassPointer(Object o); - - /** - * Reads an object pointer within a VM data structure. That is, any {@link HotSpotVMField} whose - * {@link HotSpotVMField#type() type} is {@code "oop"} (e.g., - * {@code ArrayKlass::_component_mirror}, {@code Klass::_java_mirror}, - * {@code JavaThread::_threadObj}). - * - * Note that {@link Unsafe#getObject(Object, long)} cannot be used for this since it does a - * {@code narrowOop} read if the VM is using compressed oops whereas oops within VM data - * structures are (currently) always uncompressed. - * - * @param address address of an oop field within a VM data structure - */ - Object readUncompressedOop(long address); - - void doNotInlineOrCompile(long metaspaceMethod); - - /** - * Invalidates the profiling information and restarts profiling upon the next invocation. - * - * @param metaspaceMethod the metaspace Method object - */ - void reprofile(long metaspaceMethod); - - void invalidateInstalledCode(InstalledCode hotspotInstalledCode); - - /** - * Collects the current values of all JVMCI benchmark counters, summed up over all threads. - */ - long[] collectCounters(); - - boolean isMature(long metaspaceMethodData); - - /** - * Generate a unique id to identify the result of the compile. - */ - int allocateCompileId(long metaspaceMethod, int entryBCI); - - /** - * Gets the names of the supported GPU architectures. - * - * @return a comma separated list of names - */ - String getGPUs(); - - /** - * - * @param metaspaceMethod the method to check - * @param entryBCI - * @param level the compilation level - * @return true if the {@code metaspaceMethod} has code for {@code level} - */ - boolean hasCompiledCodeForOSR(long metaspaceMethod, int entryBCI, int level); - - /** - * Fetch the time stamp used for printing inside hotspot. It's relative to VM start to that all - * events can be ordered. - * - * @return milliseconds since VM start - */ - long getTimeStamp(); - - /** - * Gets the value of a metaspace {@code Symbol} as a String. - * - * @param metaspaceSymbol - */ - String getSymbol(long metaspaceSymbol); - - /** - * Looks for the next Java stack frame with the given method. - * - * @param frame the starting point of the search, where {@code null} refers to the topmost frame - * @param methods the metaspace methods to look for, where {@code null} means that any frame is - * returned - * @return the frame, or {@code null} if the end of the stack was reached during the search - */ - HotSpotStackFrameReference getNextStackFrame(HotSpotStackFrameReference frame, long[] methods, int initialSkip); - - /** - * Materialized all virtual objects within the given stack frame and update the locals within - * the given stackFrame object. - * - * @param invalidate if {@code true}, the compiled method for the stack frame will be - * invalidated. - */ - void materializeVirtualObjects(HotSpotStackFrameReference stackFrame, boolean invalidate); - - void resolveInvokeDynamic(long metaspaceConstantPool, int index); - - int getVtableIndexForInterface(long metaspaceKlass, long metaspaceMethod); - - boolean shouldDebugNonSafepoints(); - - void writeDebugOutput(byte[] bytes, int offset, int length); - - void flushDebugOutput(); -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/CompilerToVMImpl.java --- a/graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/CompilerToVMImpl.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,206 +0,0 @@ -/* - * Copyright (c) 2011, 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; - -import static com.oracle.jvmci.hotspot.InitTimer.*; - -import com.oracle.jvmci.code.*; -import com.oracle.jvmci.meta.*; - -/** - * Entries into the HotSpot VM from Java code. - */ -public class CompilerToVMImpl implements CompilerToVM { - - /** - * Initializes the native part of the JVMCI runtime. - */ - private static native void init(); - - static { - try (InitTimer t = timer("CompilerToVMImpl.init")) { - init(); - } - } - - @Override - public native int installCode(HotSpotCompiledCode compiledCode, InstalledCode code, SpeculationLog speculationLog); - - @Override - public native long getMetaspaceMethod(Class holder, int slot); - - @Override - public native byte[] getBytecode(long metaspaceMethod); - - @Override - public native int exceptionTableLength(long metaspaceMethod); - - @Override - public native long exceptionTableStart(long metaspaceMethod); - - @Override - public native boolean hasBalancedMonitors(long metaspaceMethod); - - @Override - public native long findUniqueConcreteMethod(long actualHolderMetaspaceKlass, long metaspaceMethod); - - @Override - public native long getKlassImplementor(long metaspaceKlass); - - @Override - public native long lookupType(String name, Class accessingClass, boolean eagerResolve); - - public native Object resolveConstantInPool(long metaspaceConstantPool, int cpi); - - public native Object resolvePossiblyCachedConstantInPool(long metaspaceConstantPool, int cpi); - - @Override - public native int lookupNameAndTypeRefIndexInPool(long metaspaceConstantPool, int cpi); - - @Override - public native String lookupNameRefInPool(long metaspaceConstantPool, int cpi); - - @Override - public native String lookupSignatureRefInPool(long metaspaceConstantPool, int cpi); - - @Override - public native int lookupKlassRefIndexInPool(long metaspaceConstantPool, int cpi); - - public native long constantPoolKlassAt(long metaspaceConstantPool, int cpi); - - @Override - public native long lookupKlassInPool(long metaspaceConstantPool, int cpi); - - @Override - public native long lookupMethodInPool(long metaspaceConstantPool, int cpi, byte opcode); - - @Override - public native long resolveField(long metaspaceConstantPool, int cpi, byte opcode, long[] info); - - public native int constantPoolRemapInstructionOperandFromCache(long metaspaceConstantPool, int cpi); - - @Override - public native Object lookupAppendixInPool(long metaspaceConstantPool, int cpi); - - @Override - public native void initializeConfiguration(HotSpotVMConfig config); - - @Override - public native long resolveMethod(long metaspaceKlassExactReceiver, long metaspaceMethod, long metaspaceKlassCaller); - - @Override - public native boolean hasFinalizableSubclass(long metaspaceKlass); - - public native boolean methodIsIgnoredBySecurityStackWalk(long metaspaceMethod); - - @Override - public native long getClassInitializer(long metaspaceKlass); - - @Override - public native long getMaxCallTargetOffset(long address); - - // The HotSpot disassembler seems not to be thread safe so it's better to synchronize its usage - @Override - public synchronized native String disassembleCodeBlob(long codeBlob); - - @Override - public native StackTraceElement getStackTraceElement(long metaspaceMethod, int bci); - - @Override - public native Object executeCompiledMethodVarargs(Object[] args, InstalledCode hotspotInstalledCode); - - @Override - public native long[] getLineNumberTable(long metaspaceMethod); - - @Override - public native long getLocalVariableTableStart(long metaspaceMethod); - - @Override - public native int getLocalVariableTableLength(long metaspaceMethod); - - @Override - public native String getFileName(HotSpotResolvedJavaType method); - - @Override - public native void reprofile(long metaspaceMethod); - - @Override - public native void invalidateInstalledCode(InstalledCode hotspotInstalledCode); - - @Override - public native Class getJavaMirror(long metaspaceKlass); - - @Override - public native long readUnsafeKlassPointer(Object o); - - @Override - public native Object readUncompressedOop(long address); - - @Override - public native void doNotInlineOrCompile(long metaspaceMethod); - - @Override - public Object executeCompiledMethod(Object arg1, Object arg2, Object arg3, InstalledCode hotspotInstalledCode) throws InvalidInstalledCodeException { - return executeCompiledMethodVarargs(new Object[]{arg1, arg2, arg3}, hotspotInstalledCode); - } - - public synchronized native void notifyCompilationStatistics(int id, HotSpotResolvedJavaMethod method, boolean osr, int processedBytecodes, long time, long timeUnitsPerSecond, - InstalledCode installedCode); - - public native void resetCompilationStatistics(); - - public native long[] collectCounters(); - - public native boolean isMature(long method); - - public native int allocateCompileId(long metaspaceMethod, int entryBCI); - - public String getGPUs() { - return ""; - } - - public native boolean canInlineMethod(long metaspaceMethod); - - public native boolean shouldInlineMethod(long metaspaceMethod); - - public native boolean hasCompiledCodeForOSR(long metaspaceMethod, int entryBCI, int level); - - public native HotSpotStackFrameReference getNextStackFrame(HotSpotStackFrameReference frame, long[] methods, int initialSkip); - - public native void materializeVirtualObjects(HotSpotStackFrameReference stackFrame, boolean invalidate); - - public native long getTimeStamp(); - - public native String getSymbol(long metaspaceSymbol); - - public native void resolveInvokeDynamic(long metaspaceConstantPool, int index); - - public native int getVtableIndexForInterface(long metaspaceKlass, long metaspaceMethod); - - public native boolean shouldDebugNonSafepoints(); - - public native void writeDebugOutput(byte[] bytes, int offset, int length); - - public native void flushDebugOutput(); -} diff -r 42452d2dfbec -r 395ac43a8578 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 Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,242 +0,0 @@ -/* - * 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.jvmci.hotspot; - -import static com.oracle.jvmci.hotspot.HotSpotCompressedNullConstant.*; - -import java.lang.reflect.*; - -import com.oracle.jvmci.code.*; -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.Mark; -import com.oracle.jvmci.code.DataSection.Data; -import com.oracle.jvmci.code.DataSection.DataBuilder; -import com.oracle.jvmci.common.*; -import com.oracle.jvmci.debug.*; -import com.oracle.jvmci.meta.*; - -/** - * HotSpot implementation of {@link CodeCacheProvider}. - */ -public class HotSpotCodeCacheProvider implements CodeCacheProvider { - - protected final HotSpotJVMCIRuntimeProvider runtime; - public final HotSpotVMConfig config; - protected final TargetDescription target; - protected final RegisterConfig regConfig; - - public HotSpotCodeCacheProvider(HotSpotJVMCIRuntimeProvider runtime, HotSpotVMConfig config, TargetDescription target, RegisterConfig regConfig) { - this.runtime = runtime; - this.config = config; - this.target = target; - this.regConfig = regConfig; - } - - @Override - 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_")) { - f.setAccessible(true); - try { - if (f.getInt(runtime.getConfig()) == markId) { - return f.getName(); - } - } catch (Exception e) { - } - } - } - return CodeCacheProvider.super.getMarkName(mark); - } - - /** - * Decodes a call target to a mnemonic if possible. - */ - @Override - public String getTargetName(Call call) { - Field[] fields = runtime.getConfig().getClass().getDeclaredFields(); - for (Field f : fields) { - if (f.getName().endsWith("Stub")) { - f.setAccessible(true); - try { - Object address = f.get(runtime.getConfig()); - if (address.equals(call.target)) { - return f.getName() + ":0x" + Long.toHexString((Long) address); - } - } catch (Exception e) { - } - } - } - return CodeCacheProvider.super.getTargetName(call); - } - - @Override - public RegisterConfig getRegisterConfig() { - return regConfig; - } - - @Override - public int getMinimumOutgoingSize() { - return runtime.getConfig().runtimeCallStackSize; - } - - public InstalledCode logOrDump(InstalledCode installedCode, CompilationResult compResult) { - if (Debug.isDumpEnabled()) { - Debug.dump(new Object[]{compResult, installedCode}, "After code installation"); - } - if (Debug.isLogEnabled()) { - Debug.log("%s", disassemble(installedCode)); - } - return installedCode; - } - - public InstalledCode installMethod(HotSpotResolvedJavaMethod method, CompilationResult compResult, long jvmciEnv, boolean isDefault) { - if (compResult.getId() == -1) { - compResult.setId(method.allocateCompileId(compResult.getEntryBCI())); - } - HotSpotInstalledCode installedCode = new HotSpotNmethod(method, compResult.getName(), isDefault); - runtime.getCompilerToVM().installCode(new HotSpotCompiledNmethod(method, compResult, jvmciEnv), installedCode, method.getSpeculationLog()); - return logOrDump(installedCode, compResult); - } - - @Override - public InstalledCode addMethod(ResolvedJavaMethod method, CompilationResult compResult, SpeculationLog log, InstalledCode predefinedInstalledCode) { - HotSpotResolvedJavaMethod hotspotMethod = (HotSpotResolvedJavaMethod) method; - if (compResult.getId() == -1) { - compResult.setId(hotspotMethod.allocateCompileId(compResult.getEntryBCI())); - } - InstalledCode installedCode = predefinedInstalledCode; - if (installedCode == null) { - HotSpotInstalledCode code = new HotSpotNmethod(hotspotMethod, compResult.getName(), false); - installedCode = code; - } - HotSpotCompiledNmethod compiledCode = new HotSpotCompiledNmethod(hotspotMethod, compResult); - int result = runtime.getCompilerToVM().installCode(compiledCode, installedCode, log); - if (result != config.codeInstallResultOk) { - String msg = compiledCode.getInstallationFailureMessage(); - String resultDesc = config.getCodeInstallResultDescription(result); - if (msg != null) { - msg = String.format("Code installation failed: %s%n%s", resultDesc, msg); - } else { - msg = String.format("Code installation failed: %s", resultDesc); - } - if (result == config.codeInstallResultDependenciesInvalid) { - throw new AssertionError(resultDesc + " " + msg); - } - throw new BailoutException(result != config.codeInstallResultDependenciesFailed, msg); - } - return logOrDump(installedCode, compResult); - } - - @Override - public InstalledCode setDefaultMethod(ResolvedJavaMethod method, CompilationResult compResult) { - HotSpotResolvedJavaMethod hotspotMethod = (HotSpotResolvedJavaMethod) method; - return installMethod(hotspotMethod, compResult, 0L, true); - } - - public HotSpotNmethod addExternalMethod(ResolvedJavaMethod method, CompilationResult compResult) { - HotSpotResolvedJavaMethod javaMethod = (HotSpotResolvedJavaMethod) method; - if (compResult.getId() == -1) { - compResult.setId(javaMethod.allocateCompileId(compResult.getEntryBCI())); - } - HotSpotNmethod code = new HotSpotNmethod(javaMethod, compResult.getName(), false, true); - HotSpotCompiledNmethod compiled = new HotSpotCompiledNmethod(javaMethod, compResult); - CompilerToVM vm = runtime.getCompilerToVM(); - int result = vm.installCode(compiled, code, null); - if (result != runtime.getConfig().codeInstallResultOk) { - return null; - } - return code; - } - - public boolean needsDataPatch(JavaConstant constant) { - return constant instanceof HotSpotMetaspaceConstant; - } - - public Data createDataItem(Constant constant) { - int size; - DataBuilder builder; - if (constant instanceof VMConstant) { - VMConstant vmConstant = (VMConstant) constant; - boolean compressed; - long raw; - if (constant instanceof HotSpotObjectConstant) { - HotSpotObjectConstant c = (HotSpotObjectConstant) vmConstant; - compressed = c.isCompressed(); - raw = 0xDEADDEADDEADDEADL; - } else if (constant instanceof HotSpotMetaspaceConstant) { - HotSpotMetaspaceConstant meta = (HotSpotMetaspaceConstant) constant; - compressed = meta.isCompressed(); - raw = meta.rawValue(); - } else { - throw new JVMCIError(String.valueOf(constant)); - } - - size = target.getSizeInBytes(compressed ? Kind.Int : target.wordKind); - if (size == 4) { - builder = (buffer, patch) -> { - patch.accept(new DataPatch(buffer.position(), new ConstantReference(vmConstant))); - buffer.putInt((int) raw); - }; - } else { - assert size == 8; - builder = (buffer, patch) -> { - patch.accept(new DataPatch(buffer.position(), new ConstantReference(vmConstant))); - buffer.putLong(raw); - }; - } - } else if (JavaConstant.isNull(constant)) { - boolean compressed = COMPRESSED_NULL.equals(constant); - size = target.getSizeInBytes(compressed ? Kind.Int : target.wordKind); - builder = DataBuilder.zero(size); - } else if (constant instanceof SerializableConstant) { - SerializableConstant s = (SerializableConstant) constant; - size = s.getSerializedSize(); - builder = DataBuilder.serializable(s); - } else { - throw new JVMCIError(String.valueOf(constant)); - } - - return new Data(size, size, builder); - } - - @Override - public TargetDescription getTarget() { - return target; - } - - public String disassemble(InstalledCode code) { - if (code.isValid()) { - long codeBlob = code.getAddress(); - return runtime.getCompilerToVM().disassembleCodeBlob(codeBlob); - } - return null; - } - - public SpeculationLog createSpeculationLog() { - return new HotSpotSpeculationLog(); - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotCompiledCode.java --- a/graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotCompiledCode.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,174 +0,0 @@ -/* - * Copyright (c) 2011, 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 java.nio.*; -import java.util.*; -import java.util.stream.*; -import java.util.stream.Stream.Builder; - -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.DataPatch; -import com.oracle.jvmci.code.CompilationResult.ExceptionHandler; -import com.oracle.jvmci.code.CompilationResult.Infopoint; -import com.oracle.jvmci.code.CompilationResult.JumpTable; -import com.oracle.jvmci.code.CompilationResult.Mark; -import com.oracle.jvmci.code.CompilationResult.Site; -import com.oracle.jvmci.meta.Assumptions.Assumption; -import com.oracle.jvmci.meta.*; - -/** - * A {@link CompilationResult} with additional HotSpot-specific information required for installing - * the code in HotSpot's code cache. - */ -public abstract class HotSpotCompiledCode { - - public final String name; - public final Site[] sites; - public final ExceptionHandler[] exceptionHandlers; - public final Comment[] comments; - public final Assumption[] assumptions; - - public final byte[] targetCode; - public final int targetCodeSize; - - public final byte[] dataSection; - public final int dataSectionAlignment; - public final DataPatch[] dataSectionPatches; - - public final int totalFrameSize; - public final int customStackAreaOffset; - - /** - * The list of the methods whose bytecodes were used as input to the compilation. If - * {@code null}, then the compilation did not record method dependencies. Otherwise, the first - * element of this array is the root method of the compilation. - */ - public final ResolvedJavaMethod[] methods; - - public static class Comment { - - public final String text; - public final int pcOffset; - - public Comment(int pcOffset, String text) { - this.text = text; - this.pcOffset = pcOffset; - } - } - - public HotSpotCompiledCode(CompilationResult compResult) { - name = compResult.getName(); - sites = getSortedSites(compResult); - if (compResult.getExceptionHandlers().isEmpty()) { - exceptionHandlers = null; - } else { - exceptionHandlers = compResult.getExceptionHandlers().toArray(new ExceptionHandler[compResult.getExceptionHandlers().size()]); - } - List annotations = compResult.getAnnotations(); - comments = new Comment[annotations.size()]; - if (!annotations.isEmpty()) { - for (int i = 0; i < comments.length; i++) { - CodeAnnotation annotation = annotations.get(i); - String text; - if (annotation instanceof CodeComment) { - CodeComment codeComment = (CodeComment) annotation; - text = codeComment.value; - } else if (annotation instanceof JumpTable) { - JumpTable jumpTable = (JumpTable) annotation; - text = "JumpTable [" + jumpTable.low + " .. " + jumpTable.high + "]"; - } else { - text = annotation.toString(); - } - comments[i] = new Comment(annotation.position, text); - } - } - assumptions = compResult.getAssumptions(); - assert validateFrames(); - - targetCode = compResult.getTargetCode(); - targetCodeSize = compResult.getTargetCodeSize(); - - DataSection data = compResult.getDataSection(); - data.finalizeLayout(); - dataSection = new byte[data.getSectionSize()]; - - ByteBuffer buffer = ByteBuffer.wrap(dataSection).order(ByteOrder.nativeOrder()); - Builder patchBuilder = Stream.builder(); - data.buildDataSection(buffer, patchBuilder); - - dataSectionAlignment = data.getSectionAlignment(); - dataSectionPatches = patchBuilder.build().toArray(len -> new DataPatch[len]); - - totalFrameSize = compResult.getTotalFrameSize(); - customStackAreaOffset = compResult.getCustomStackAreaOffset(); - - methods = compResult.getMethods(); - } - - /** - * Ensure that all the frames passed into HotSpot are properly formatted with an empty or - * illegal slot following double word slots. - */ - private boolean validateFrames() { - for (Site site : sites) { - if (site instanceof Infopoint) { - Infopoint info = (Infopoint) site; - if (info.debugInfo != null) { - BytecodeFrame frame = info.debugInfo.frame(); - assert frame == null || frame.validateFormat(false); - } - } - } - return true; - } - - static class SiteComparator implements Comparator { - - public int compare(Site s1, Site s2) { - if (s1.pcOffset == s2.pcOffset && (s1 instanceof Mark ^ s2 instanceof Mark)) { - return s1 instanceof Mark ? -1 : 1; - } - return s1.pcOffset - s2.pcOffset; - } - } - - private static Site[] getSortedSites(CompilationResult target) { - List[] lists = new List[]{target.getInfopoints(), target.getDataPatches(), target.getMarks()}; - int count = 0; - for (List list : lists) { - count += list.size(); - } - Site[] result = new Site[count]; - int pos = 0; - for (List list : lists) { - for (Object elem : list) { - result[pos++] = (Site) elem; - } - } - Arrays.sort(result, new SiteComparator()); - return result; - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotCompiledNmethod.java --- a/graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotCompiledNmethod.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,65 +0,0 @@ -/* - * Copyright (c) 2011, 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.*; - -import edu.umd.cs.findbugs.annotations.*; - -/** - * {@link HotSpotCompiledCode} destined for installation as an nmethod. - */ -public final class HotSpotCompiledNmethod extends HotSpotCompiledCode { - - public final HotSpotResolvedJavaMethod method; - public final int entryBCI; - public final int id; - public final long jvmciEnv; - - /** - * May be set by VM if code installation fails. It will describe in more detail why installation - * failed (e.g., exactly which dependency failed). - */ - @SuppressFBWarnings("UWF_UNWRITTEN_FIELD") private String installationFailureMessage; - - public HotSpotCompiledNmethod(HotSpotResolvedJavaMethod method, CompilationResult compResult) { - this(method, compResult, 0L); - } - - public HotSpotCompiledNmethod(HotSpotResolvedJavaMethod method, CompilationResult compResult, long jvmciEnv) { - super(compResult); - this.method = method; - this.entryBCI = compResult.getEntryBCI(); - this.id = compResult.getId(); - this.jvmciEnv = jvmciEnv; - } - - @Override - public String toString() { - return getClass().getSimpleName() + "[" + id + ":" + method.format("%H.%n(%p)%r@") + entryBCI + "]"; - } - - public String getInstallationFailureMessage() { - return installationFailureMessage; - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotCompressedNullConstant.java --- a/graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotCompressedNullConstant.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,102 +0,0 @@ -/* - * 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 - * 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.meta.*; - -/** - * The compressed representation of the {@link JavaConstant#NULL_POINTER null constant}. - */ -public final class HotSpotCompressedNullConstant extends AbstractValue implements JavaConstant, HotSpotConstant { - - public static final JavaConstant COMPRESSED_NULL = new HotSpotCompressedNullConstant(); - - private HotSpotCompressedNullConstant() { - super(LIRKind.reference(Kind.Int)); - } - - @Override - public boolean isNull() { - return true; - } - - @Override - public boolean isCompressed() { - return true; - } - - @Override - public boolean isDefaultForKind() { - return true; - } - - @Override - public Object asBoxedPrimitive() { - throw new IllegalArgumentException(); - } - - @Override - public int asInt() { - throw new IllegalArgumentException(); - } - - @Override - public boolean asBoolean() { - throw new IllegalArgumentException(); - } - - @Override - public long asLong() { - throw new IllegalArgumentException(); - } - - @Override - public float asFloat() { - throw new IllegalArgumentException(); - } - - @Override - public double asDouble() { - throw new IllegalArgumentException(); - } - - @Override - public String toString() { - return JavaConstant.toString(this); - } - - @Override - public String toValueString() { - return "null"; - } - - @Override - public int hashCode() { - return System.identityHashCode(this); - } - - @Override - public boolean equals(Object o) { - return o instanceof HotSpotCompressedNullConstant; - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotConstant.java --- a/graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotConstant.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,33 +0,0 @@ -/* - * 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 - * 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.meta.*; - -/** - * Marker interface for hotspot specific constants. - */ -public interface HotSpotConstant extends Constant { - - boolean isCompressed(); -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotConstantPool.java --- a/graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotConstantPool.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,653 +0,0 @@ -/* - * Copyright (c) 2011, 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; - -import static com.oracle.jvmci.common.UnsafeAccess.*; -import static com.oracle.jvmci.hotspot.HotSpotJVMCIRuntime.*; - -import java.lang.invoke.*; - -import com.oracle.jvmci.common.*; -import com.oracle.jvmci.meta.*; - -/** - * Implementation of {@link ConstantPool} for HotSpot. - */ -public class HotSpotConstantPool implements ConstantPool, HotSpotProxified { - - /** - * Subset of JVM bytecode opcodes used by {@link HotSpotConstantPool}. - */ - public static class Bytecodes { - public static final int LDC = 18; // 0x12 - public static final int LDC_W = 19; // 0x13 - public static final int LDC2_W = 20; // 0x14 - public static final int GETSTATIC = 178; // 0xB2 - public static final int PUTSTATIC = 179; // 0xB3 - public static final int GETFIELD = 180; // 0xB4 - public static final int PUTFIELD = 181; // 0xB5 - public static final int INVOKEVIRTUAL = 182; // 0xB6 - public static final int INVOKESPECIAL = 183; // 0xB7 - public static final int INVOKESTATIC = 184; // 0xB8 - public static final int INVOKEINTERFACE = 185; // 0xB9 - public static final int INVOKEDYNAMIC = 186; // 0xBA - public static final int NEW = 187; // 0xBB - public static final int NEWARRAY = 188; // 0xBC - public static final int ANEWARRAY = 189; // 0xBD - public static final int CHECKCAST = 192; // 0xC0 - public static final int INSTANCEOF = 193; // 0xC1 - public static final int MULTIANEWARRAY = 197; // 0xC5 - - static boolean isInvoke(int opcode) { - switch (opcode) { - case INVOKEVIRTUAL: - case INVOKESPECIAL: - case INVOKESTATIC: - case INVOKEINTERFACE: - case INVOKEDYNAMIC: - return true; - default: - return false; - } - } - } - - /** - * Enum of all {@code JVM_CONSTANT} constants used in the VM. This includes the public and - * internal ones. - */ - private enum JVM_CONSTANT { - // @formatter:off - Utf8(config().jvmConstantUtf8), - Integer(config().jvmConstantInteger), - Long(config().jvmConstantLong), - Float(config().jvmConstantFloat), - Double(config().jvmConstantDouble), - Class(config().jvmConstantClass), - UnresolvedClass(config().jvmConstantUnresolvedClass), - UnresolvedClassInError(config().jvmConstantUnresolvedClassInError), - String(config().jvmConstantString), - Fieldref(config().jvmConstantFieldref), - MethodRef(config().jvmConstantMethodref), - InterfaceMethodref(config().jvmConstantInterfaceMethodref), - NameAndType(config().jvmConstantNameAndType), - MethodHandle(config().jvmConstantMethodHandle), - MethodHandleInError(config().jvmConstantMethodHandleInError), - MethodType(config().jvmConstantMethodType), - MethodTypeInError(config().jvmConstantMethodTypeInError), - InvokeDynamic(config().jvmConstantInvokeDynamic); - // @formatter:on - - private final int tag; - - private static final int ExternalMax = config().jvmConstantExternalMax; - private static final int InternalMin = config().jvmConstantInternalMin; - private static final int InternalMax = config().jvmConstantInternalMax; - - private JVM_CONSTANT(int tag) { - this.tag = tag; - } - - private static HotSpotVMConfig config() { - return runtime().getConfig(); - } - - /** - * Maps JVM_CONSTANT tags to {@link JVM_CONSTANT} values. Using a separate class for lazy - * initialization. - */ - static class TagValueMap { - private static final JVM_CONSTANT[] table = new JVM_CONSTANT[ExternalMax + 1 + (InternalMax - InternalMin) + 1]; - static { - assert InternalMin > ExternalMax; - for (JVM_CONSTANT e : values()) { - table[indexOf(e.tag)] = e; - } - } - - private static int indexOf(int tag) { - if (tag >= InternalMin) { - return tag - InternalMin + ExternalMax + 1; - } else { - assert tag <= ExternalMax; - } - return tag; - } - - static JVM_CONSTANT get(int tag) { - JVM_CONSTANT res = table[indexOf(tag)]; - if (res != null) { - return res; - } - throw new JVMCIError("Unknown JVM_CONSTANT tag %s", tag); - } - } - - public static JVM_CONSTANT getEnum(int tag) { - return TagValueMap.get(tag); - } - } - - private static class LookupTypeCacheElement { - int lastCpi = Integer.MIN_VALUE; - JavaType javaType; - - public LookupTypeCacheElement(int lastCpi, JavaType javaType) { - super(); - this.lastCpi = lastCpi; - this.javaType = javaType; - } - } - - /** - * Reference to the C++ ConstantPool object. - */ - private final long metaspaceConstantPool; - private final Object[] cache; - private volatile LookupTypeCacheElement lastLookupType; - - public HotSpotConstantPool(long metaspaceConstantPool) { - this.metaspaceConstantPool = metaspaceConstantPool; - cache = new Object[length()]; - } - - /** - * Gets the holder for this constant pool as {@link HotSpotResolvedObjectTypeImpl}. - * - * @return holder for this constant pool - */ - private HotSpotResolvedObjectType getHolder() { - final long metaspaceKlass = unsafe.getAddress(metaspaceConstantPool + runtime().getConfig().constantPoolHolderOffset); - return HotSpotResolvedObjectTypeImpl.fromMetaspaceKlass(metaspaceKlass); - } - - /** - * Converts a raw index from the bytecodes to a constant pool index by adding a - * {@link HotSpotVMConfig#constantPoolCpCacheIndexTag constant}. - * - * @param rawIndex index from the bytecode - * @param opcode bytecode to convert the index for - * @return constant pool index - */ - private static int toConstantPoolIndex(int rawIndex, int opcode) { - int index; - if (opcode == Bytecodes.INVOKEDYNAMIC) { - index = rawIndex; - // See: ConstantPool::is_invokedynamic_index - assert index < 0 : "not an invokedynamic constant pool index " + index; - } else { - assert opcode == Bytecodes.GETFIELD || opcode == Bytecodes.PUTFIELD || opcode == Bytecodes.GETSTATIC || opcode == Bytecodes.PUTSTATIC || opcode == Bytecodes.INVOKEINTERFACE || - opcode == Bytecodes.INVOKEVIRTUAL || opcode == Bytecodes.INVOKESPECIAL || opcode == Bytecodes.INVOKESTATIC : "unexpected invoke opcode " + opcode; - index = rawIndex + runtime().getConfig().constantPoolCpCacheIndexTag; - } - return index; - } - - /** - * Decode a constant pool cache index to a constant pool index. - * - * See {@code ConstantPool::decode_cpcache_index}. - * - * @param index constant pool cache index - * @return decoded index - */ - private static int decodeConstantPoolCacheIndex(int index) { - if (isInvokedynamicIndex(index)) { - return decodeInvokedynamicIndex(index); - } else { - return index - runtime().getConfig().constantPoolCpCacheIndexTag; - } - } - - /** - * See {@code ConstantPool::is_invokedynamic_index}. - */ - private static boolean isInvokedynamicIndex(int index) { - return index < 0; - } - - /** - * See {@code ConstantPool::decode_invokedynamic_index}. - */ - private static int decodeInvokedynamicIndex(int i) { - assert isInvokedynamicIndex(i) : i; - return ~i; - } - - /** - * Gets the constant pool tag at index {@code index}. - * - * @param index constant pool index - * @return constant pool tag - */ - private JVM_CONSTANT getTagAt(int index) { - assertBounds(index); - HotSpotVMConfig config = runtime().getConfig(); - final long metaspaceConstantPoolTags = unsafe.getAddress(metaspaceConstantPool + config.constantPoolTagsOffset); - final int tag = unsafe.getByteVolatile(null, metaspaceConstantPoolTags + config.arrayU1DataOffset + index); - if (tag == 0) { - return null; - } - return JVM_CONSTANT.getEnum(tag); - } - - /** - * Gets the constant pool entry at index {@code index}. - * - * @param index constant pool index - * @return constant pool entry - */ - private long getEntryAt(int index) { - assertBounds(index); - return unsafe.getAddress(metaspaceConstantPool + runtime().getConfig().constantPoolSize + index * runtime().getHostJVMCIBackend().getTarget().wordSize); - } - - /** - * Gets the integer constant pool entry at index {@code index}. - * - * @param index constant pool index - * @return integer constant pool entry at index - */ - private int getIntAt(int index) { - assertTag(index, JVM_CONSTANT.Integer); - return unsafe.getInt(metaspaceConstantPool + runtime().getConfig().constantPoolSize + index * runtime().getHostJVMCIBackend().getTarget().wordSize); - } - - /** - * Gets the long constant pool entry at index {@code index}. - * - * @param index constant pool index - * @return long constant pool entry - */ - private long getLongAt(int index) { - assertTag(index, JVM_CONSTANT.Long); - return unsafe.getLong(metaspaceConstantPool + runtime().getConfig().constantPoolSize + index * runtime().getHostJVMCIBackend().getTarget().wordSize); - } - - /** - * Gets the float constant pool entry at index {@code index}. - * - * @param index constant pool index - * @return float constant pool entry - */ - private float getFloatAt(int index) { - assertTag(index, JVM_CONSTANT.Float); - return unsafe.getFloat(metaspaceConstantPool + runtime().getConfig().constantPoolSize + index * runtime().getHostJVMCIBackend().getTarget().wordSize); - } - - /** - * Gets the double constant pool entry at index {@code index}. - * - * @param index constant pool index - * @return float constant pool entry - */ - private double getDoubleAt(int index) { - assertTag(index, JVM_CONSTANT.Double); - return unsafe.getDouble(metaspaceConstantPool + runtime().getConfig().constantPoolSize + index * runtime().getHostJVMCIBackend().getTarget().wordSize); - } - - /** - * Gets the {@code JVM_CONSTANT_NameAndType} constant pool entry at index {@code index}. - * - * @param index constant pool index - * @return {@code JVM_CONSTANT_NameAndType} constant pool entry - */ - private int getNameAndTypeAt(int index) { - assertTag(index, JVM_CONSTANT.NameAndType); - return unsafe.getInt(metaspaceConstantPool + runtime().getConfig().constantPoolSize + index * runtime().getHostJVMCIBackend().getTarget().wordSize); - } - - /** - * Gets the {@code JVM_CONSTANT_NameAndType} reference index constant pool entry at index - * {@code index}. - * - * @param index constant pool index - * @return {@code JVM_CONSTANT_NameAndType} reference constant pool entry - */ - private int getNameAndTypeRefIndexAt(int index) { - return runtime().getCompilerToVM().lookupNameAndTypeRefIndexInPool(metaspaceConstantPool, index); - } - - /** - * Gets the name of a {@code JVM_CONSTANT_NameAndType} constant pool entry at index - * {@code index}. - * - * @param index constant pool index - * @return name as {@link String} - */ - private String getNameRefAt(int index) { - return runtime().getCompilerToVM().lookupNameRefInPool(metaspaceConstantPool, index); - } - - /** - * Gets the name reference index of a {@code JVM_CONSTANT_NameAndType} constant pool entry at - * index {@code index}. - * - * @param index constant pool index - * @return name reference index - */ - private int getNameRefIndexAt(int index) { - final int refIndex = getNameAndTypeAt(index); - // name ref index is in the low 16-bits. - return refIndex & 0xFFFF; - } - - /** - * Gets the signature of a {@code JVM_CONSTANT_NameAndType} constant pool entry at index - * {@code index}. - * - * @param index constant pool index - * @return signature as {@link String} - */ - private String getSignatureRefAt(int index) { - return runtime().getCompilerToVM().lookupSignatureRefInPool(metaspaceConstantPool, index); - } - - /** - * Gets the signature reference index of a {@code JVM_CONSTANT_NameAndType} constant pool entry - * at index {@code index}. - * - * @param index constant pool index - * @return signature reference index - */ - private int getSignatureRefIndexAt(int index) { - final int refIndex = getNameAndTypeAt(index); - // signature ref index is in the high 16-bits. - return refIndex >>> 16; - } - - /** - * Gets the klass reference index constant pool entry at index {@code index}. - * - * @param index constant pool index - * @return klass reference index - */ - private int getKlassRefIndexAt(int index) { - return runtime().getCompilerToVM().lookupKlassRefIndexInPool(metaspaceConstantPool, index); - } - - /** - * Gets the uncached klass reference index constant pool entry at index {@code index}. See: - * {@code ConstantPool::uncached_klass_ref_index_at}. - * - * @param index constant pool index - * @return klass reference index - */ - private int getUncachedKlassRefIndexAt(int index) { - assert getTagAt(index) == JVM_CONSTANT.Fieldref || getTagAt(index) == JVM_CONSTANT.MethodRef || getTagAt(index) == JVM_CONSTANT.InterfaceMethodref; - final int refIndex = unsafe.getInt(metaspaceConstantPool + runtime().getConfig().constantPoolSize + index * runtime().getHostJVMCIBackend().getTarget().wordSize); - // klass ref index is in the low 16-bits. - return refIndex & 0xFFFF; - } - - /** - * Asserts that the constant pool index {@code index} is in the bounds of the constant pool. - * - * @param index constant pool index - */ - private void assertBounds(int index) { - assert 0 <= index && index < length() : "index " + index + " not between 0 and " + length(); - } - - /** - * Asserts that the constant pool tag at index {@code index} is equal to {@code tag}. - * - * @param index constant pool index - * @param tag expected tag - */ - private void assertTag(int index, JVM_CONSTANT tag) { - assert getTagAt(index) == tag : "constant pool tag at index " + index + " is " + getTagAt(index) + " but expected " + tag; - } - - @Override - public int length() { - return unsafe.getInt(metaspaceConstantPool + runtime().getConfig().constantPoolLengthOffset); - } - - @Override - public Object lookupConstant(int cpi) { - assert cpi != 0; - final JVM_CONSTANT tag = getTagAt(cpi); - switch (tag) { - case Integer: - return JavaConstant.forInt(getIntAt(cpi)); - case Long: - return JavaConstant.forLong(getLongAt(cpi)); - case Float: - return JavaConstant.forFloat(getFloatAt(cpi)); - case Double: - return JavaConstant.forDouble(getDoubleAt(cpi)); - case Class: - case UnresolvedClass: - case UnresolvedClassInError: - final int opcode = -1; // opcode is not used - return lookupType(cpi, opcode); - case String: - Object string = runtime().getCompilerToVM().resolvePossiblyCachedConstantInPool(metaspaceConstantPool, cpi); - return HotSpotObjectConstantImpl.forObject(string); - case MethodHandle: - case MethodHandleInError: - case MethodType: - case MethodTypeInError: - Object obj = runtime().getCompilerToVM().resolveConstantInPool(metaspaceConstantPool, cpi); - return HotSpotObjectConstantImpl.forObject(obj); - default: - throw new JVMCIError("Unknown constant pool tag %s", tag); - } - } - - @Override - public String lookupUtf8(int cpi) { - assertTag(cpi, JVM_CONSTANT.Utf8); - return runtime().getCompilerToVM().getSymbol(getEntryAt(cpi)); - } - - @Override - public Signature lookupSignature(int cpi) { - return new HotSpotSignature(runtime(), lookupUtf8(cpi)); - } - - @Override - public JavaConstant lookupAppendix(int cpi, int opcode) { - assert Bytecodes.isInvoke(opcode); - final int index = toConstantPoolIndex(cpi, opcode); - Object result = runtime().getCompilerToVM().lookupAppendixInPool(metaspaceConstantPool, index); - if (result == null) { - return null; - } else { - return HotSpotObjectConstantImpl.forObject(result); - } - } - - /** - * Gets a {@link JavaType} corresponding a given metaspace Klass or a metaspace Symbol depending - * on the {@link HotSpotVMConfig#compilerToVMKlassTag tag}. - * - * @param metaspacePointer either a metaspace Klass or a metaspace Symbol - */ - private static JavaType getJavaType(final long metaspacePointer) { - HotSpotJVMCIRuntime runtime = runtime(); - HotSpotVMConfig config = runtime.getConfig(); - if ((metaspacePointer & config.compilerToVMSymbolTag) != 0) { - final long metaspaceSymbol = metaspacePointer & ~config.compilerToVMSymbolTag; - String name = runtime.getCompilerToVM().getSymbol(metaspaceSymbol); - return HotSpotUnresolvedJavaType.create(runtime(), "L" + name + ";"); - } else { - assert (metaspacePointer & config.compilerToVMKlassTag) == 0; - return HotSpotResolvedObjectTypeImpl.fromMetaspaceKlass(metaspacePointer); - } - } - - @Override - public JavaMethod lookupMethod(int cpi, int opcode) { - if (opcode != Bytecodes.INVOKEDYNAMIC) { - Object result = cache[cpi]; - if (result != null) { - return (ResolvedJavaMethod) result; - } - } - final int index = toConstantPoolIndex(cpi, opcode); - final long metaspaceMethod = runtime().getCompilerToVM().lookupMethodInPool(metaspaceConstantPool, index, (byte) opcode); - if (metaspaceMethod != 0L) { - HotSpotResolvedJavaMethod result = HotSpotResolvedJavaMethodImpl.fromMetaspace(metaspaceMethod); - if (opcode != Bytecodes.INVOKEDYNAMIC) { - cache[cpi] = result; - } - return result; - } else { - // Get the method's name and signature. - String name = getNameRefAt(index); - HotSpotSignature signature = new HotSpotSignature(runtime(), getSignatureRefAt(index)); - if (opcode == Bytecodes.INVOKEDYNAMIC) { - HotSpotResolvedObjectType holder = HotSpotResolvedObjectTypeImpl.fromObjectClass(MethodHandle.class); - return new HotSpotMethodUnresolved(name, signature, holder); - } else { - final int klassIndex = getKlassRefIndexAt(index); - final long metaspacePointer = runtime().getCompilerToVM().lookupKlassInPool(metaspaceConstantPool, klassIndex); - JavaType holder = getJavaType(metaspacePointer); - return new HotSpotMethodUnresolved(name, signature, holder); - } - } - } - - @Override - public JavaType lookupType(int cpi, int opcode) { - final LookupTypeCacheElement elem = this.lastLookupType; - if (elem != null && elem.lastCpi == cpi) { - return elem.javaType; - } else { - final long metaspacePointer = runtime().getCompilerToVM().lookupKlassInPool(metaspaceConstantPool, cpi); - JavaType result = getJavaType(metaspacePointer); - if (result instanceof ResolvedJavaType) { - this.lastLookupType = new LookupTypeCacheElement(cpi, result); - } - return result; - } - } - - @Override - public JavaField lookupField(int cpi, int opcode) { - Object resolvedJavaField = cache[cpi]; - if (resolvedJavaField != null) { - return (ResolvedJavaField) resolvedJavaField; - } - final int index = toConstantPoolIndex(cpi, opcode); - final int nameAndTypeIndex = getNameAndTypeRefIndexAt(index); - final int nameIndex = getNameRefIndexAt(nameAndTypeIndex); - String name = lookupUtf8(nameIndex); - final int typeIndex = getSignatureRefIndexAt(nameAndTypeIndex); - String typeName = lookupUtf8(typeIndex); - JavaType type = runtime().lookupType(typeName, getHolder(), false); - - final int holderIndex = getKlassRefIndexAt(index); - JavaType holder = lookupType(holderIndex, opcode); - - if (holder instanceof HotSpotResolvedObjectTypeImpl) { - long[] info = new long[2]; - long metaspaceKlass; - try { - metaspaceKlass = runtime().getCompilerToVM().resolveField(metaspaceConstantPool, index, (byte) opcode, info); - } catch (Throwable t) { - /* - * If there was an exception resolving the field we give up and return an unresolved - * field. - */ - return new HotSpotUnresolvedField(holder, name, type); - } - HotSpotResolvedObjectTypeImpl resolvedHolder = HotSpotResolvedObjectTypeImpl.fromMetaspaceKlass(metaspaceKlass); - final int flags = (int) info[0]; - final long offset = info[1]; - HotSpotResolvedJavaField result = resolvedHolder.createField(name, type, offset, flags); - if (type instanceof ResolvedJavaType) { - cache[cpi] = result; - } - return result; - } else { - return new HotSpotUnresolvedField(holder, name, type); - } - } - - @Override - public void loadReferencedType(int cpi, int opcode) { - int index; - switch (opcode) { - case Bytecodes.CHECKCAST: - case Bytecodes.INSTANCEOF: - case Bytecodes.NEW: - case Bytecodes.ANEWARRAY: - case Bytecodes.MULTIANEWARRAY: - case Bytecodes.LDC: - case Bytecodes.LDC_W: - case Bytecodes.LDC2_W: - index = cpi; - break; - case Bytecodes.INVOKEDYNAMIC: - // invokedynamic instructions point to a constant pool cache entry. - index = decodeConstantPoolCacheIndex(cpi) + runtime().getConfig().constantPoolCpCacheIndexTag; - index = runtime().getCompilerToVM().constantPoolRemapInstructionOperandFromCache(metaspaceConstantPool, index); - break; - default: - index = toConstantPoolIndex(cpi, opcode); - index = runtime().getCompilerToVM().constantPoolRemapInstructionOperandFromCache(metaspaceConstantPool, index); - } - - JVM_CONSTANT tag = getTagAt(index); - if (tag == null) { - assert getTagAt(index - 1) == JVM_CONSTANT.Double || getTagAt(index - 1) == JVM_CONSTANT.Long; - return; - } - switch (tag) { - case Fieldref: - case MethodRef: - case InterfaceMethodref: - index = getUncachedKlassRefIndexAt(index); - tag = getTagAt(index); - assert tag == JVM_CONSTANT.Class || tag == JVM_CONSTANT.UnresolvedClass || tag == JVM_CONSTANT.UnresolvedClassInError : tag; - // fall through - case Class: - case UnresolvedClass: - case UnresolvedClassInError: - final long metaspaceKlass = runtime().getCompilerToVM().constantPoolKlassAt(metaspaceConstantPool, index); - HotSpotResolvedObjectTypeImpl type = HotSpotResolvedObjectTypeImpl.fromMetaspaceKlass(metaspaceKlass); - Class klass = type.mirror(); - if (!klass.isPrimitive() && !klass.isArray()) { - unsafe.ensureClassInitialized(klass); - } - break; - case InvokeDynamic: - if (isInvokedynamicIndex(cpi)) { - runtime().getCompilerToVM().resolveInvokeDynamic(metaspaceConstantPool, cpi); - } - break; - default: - // nothing - break; - } - } - - @Override - public String toString() { - HotSpotResolvedObjectType holder = getHolder(); - return "HotSpotConstantPool<" + holder.toJavaName() + ">"; - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotConstantReflectionProvider.java --- a/graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotConstantReflectionProvider.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,364 +0,0 @@ -/* - * Copyright (c) 2011, 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; - -import static com.oracle.jvmci.hotspot.HotSpotConstantReflectionProvider.Options.*; - -import java.lang.reflect.*; - -import com.oracle.jvmci.meta.*; -import com.oracle.jvmci.options.*; - -/** - * HotSpot implementation of {@link ConstantReflectionProvider}. - */ -public class HotSpotConstantReflectionProvider implements ConstantReflectionProvider, HotSpotProxified { - - static class Options { - //@formatter:off - @Option(help = "Constant fold final fields with default values.", type = OptionType.Debug) - public static final OptionValue TrustFinalDefaultFields = new OptionValue<>(true); - //@formatter:on - } - - protected final HotSpotJVMCIRuntimeProvider runtime; - protected final HotSpotMethodHandleAccessProvider methodHandleAccess; - protected final HotSpotMemoryAccessProviderImpl memoryAccess; - - public HotSpotConstantReflectionProvider(HotSpotJVMCIRuntimeProvider runtime) { - this.runtime = runtime; - this.methodHandleAccess = new HotSpotMethodHandleAccessProvider(this); - this.memoryAccess = new HotSpotMemoryAccessProviderImpl(runtime); - } - - public MethodHandleAccessProvider getMethodHandleAccess() { - return methodHandleAccess; - } - - @Override - public MemoryAccessProvider getMemoryAccessProvider() { - return memoryAccess; - } - - @Override - public Boolean constantEquals(Constant x, Constant y) { - if (x == y) { - return true; - } else if (x instanceof HotSpotObjectConstantImpl) { - return y instanceof HotSpotObjectConstantImpl && ((HotSpotObjectConstantImpl) x).object() == ((HotSpotObjectConstantImpl) y).object(); - } else { - return x.equals(y); - } - } - - @Override - public Integer readArrayLength(JavaConstant array) { - if (array.getKind() != Kind.Object || array.isNull()) { - return null; - } - - Object arrayObject = ((HotSpotObjectConstantImpl) array).object(); - if (!arrayObject.getClass().isArray()) { - return null; - } - return Array.getLength(arrayObject); - } - - public JavaConstant readConstantArrayElement(JavaConstant array, int index) { - if (array instanceof HotSpotObjectConstantImpl && ((HotSpotObjectConstantImpl) array).getStableDimension() > 0) { - JavaConstant element = readArrayElement(array, index); - if (element != null && (((HotSpotObjectConstantImpl) array).isDefaultStable() || !element.isDefaultForKind())) { - return element; - } - } - return null; - } - - /** - * Try to convert {@code offset} into an an index into {@code array}. - * - * @return the computed index or -1 if the offset isn't within the array - */ - private int indexForOffset(JavaConstant array, long offset) { - if (array.getKind() != Kind.Object || array.isNull()) { - return -1; - } - Class componentType = ((HotSpotObjectConstantImpl) array).object().getClass().getComponentType(); - Kind kind = runtime.getHostJVMCIBackend().getMetaAccess().lookupJavaType(componentType).getKind(); - int arraybase = runtime.getArrayBaseOffset(kind); - int scale = runtime.getArrayIndexScale(kind); - if (offset < arraybase) { - return -1; - } - long index = offset - arraybase; - if (index % scale != 0) { - return -1; - } - long result = index / scale; - if (result >= Integer.MAX_VALUE) { - return -1; - } - return (int) result; - } - - public JavaConstant readConstantArrayElementForOffset(JavaConstant array, long offset) { - if (array instanceof HotSpotObjectConstantImpl && ((HotSpotObjectConstantImpl) array).getStableDimension() > 0) { - return readConstantArrayElement(array, indexForOffset(array, offset)); - } - return null; - } - - @Override - public JavaConstant readArrayElement(JavaConstant array, int index) { - if (array.getKind() != Kind.Object || array.isNull()) { - return null; - } - Object a = ((HotSpotObjectConstantImpl) array).object(); - - if (index < 0 || index >= Array.getLength(a)) { - return null; - } - - if (a instanceof Object[]) { - Object element = ((Object[]) a)[index]; - if (((HotSpotObjectConstantImpl) array).getStableDimension() > 1) { - return HotSpotObjectConstantImpl.forStableArray(element, ((HotSpotObjectConstantImpl) array).getStableDimension() - 1, ((HotSpotObjectConstantImpl) array).isDefaultStable()); - } else { - return HotSpotObjectConstantImpl.forObject(element); - } - } else { - return JavaConstant.forBoxedPrimitive(Array.get(a, index)); - } - } - - /** - * Check if the constant is a boxed value that is guaranteed to be cached by the platform. - * Otherwise the generated code might be the only reference to the boxed value and since object - * references from nmethods are weak this can cause GC problems. - * - * @param source - * @return true if the box is cached - */ - private static boolean isBoxCached(JavaConstant source) { - switch (source.getKind()) { - case Boolean: - return true; - case Char: - return source.asInt() <= 127; - case Byte: - case Short: - case Int: - return source.asInt() >= -128 && source.asInt() <= 127; - case Long: - return source.asLong() >= -128 && source.asLong() <= 127; - case Float: - case Double: - return false; - default: - throw new IllegalArgumentException("unexpected kind " + source.getKind()); - } - } - - @Override - public JavaConstant boxPrimitive(JavaConstant source) { - if (!source.getKind().isPrimitive() || !isBoxCached(source)) { - return null; - } - return HotSpotObjectConstantImpl.forObject(source.asBoxedPrimitive()); - } - - @Override - public JavaConstant unboxPrimitive(JavaConstant source) { - if (!source.getKind().isObject()) { - return null; - } - if (source.isNull()) { - return null; - } - return JavaConstant.forBoxedPrimitive(((HotSpotObjectConstantImpl) source).object()); - } - - public JavaConstant forString(String value) { - return HotSpotObjectConstantImpl.forObject(value); - } - - @Override - public ResolvedJavaType asJavaType(Constant constant) { - if (constant instanceof HotSpotObjectConstant) { - Object obj = ((HotSpotObjectConstantImpl) constant).object(); - if (obj instanceof Class) { - return runtime.getHostJVMCIBackend().getMetaAccess().lookupJavaType((Class) obj); - } - } - if (constant instanceof HotSpotMetaspaceConstant) { - Object obj = HotSpotMetaspaceConstantImpl.getMetaspaceObject(constant); - if (obj instanceof HotSpotResolvedObjectTypeImpl) { - return (ResolvedJavaType) obj; - } - } - return null; - } - - private static final String SystemClassName = "Ljava/lang/System;"; - - /** - * Determines if a static field is constant for the purpose of - * {@link #readConstantFieldValue(JavaField, JavaConstant)}. - */ - protected boolean isStaticFieldConstant(HotSpotResolvedJavaField staticField) { - if (staticField.isFinal() || staticField.isStable()) { - ResolvedJavaType holder = staticField.getDeclaringClass(); - if (holder.isInitialized() && !holder.getName().equals(SystemClassName)) { - return true; - } - } - return false; - } - - /** - * Determines if a value read from a {@code final} instance field is considered constant. The - * implementation in {@link HotSpotConstantReflectionProvider} returns true if {@code value} is - * not the {@link JavaConstant#isDefaultForKind default value} for its kind or if - * {@link Options#TrustFinalDefaultFields} is true. - * - * @param value a value read from a {@code final} instance field - * @param receiverClass the {@link Object#getClass() class} of object from which the - * {@code value} was read - */ - protected boolean isFinalInstanceFieldValueConstant(JavaConstant value, Class receiverClass) { - return !value.isDefaultForKind() || TrustFinalDefaultFields.getValue(); - } - - /** - * Determines if a value read from a {@link Stable} instance field is considered constant. The - * implementation in {@link HotSpotConstantReflectionProvider} returns true if {@code value} is - * not the {@link JavaConstant#isDefaultForKind default value} for its kind. - * - * @param value a value read from a {@link Stable} field - * @param receiverClass the {@link Object#getClass() class} of object from which the - * {@code value} was read - */ - protected boolean isStableInstanceFieldValueConstant(JavaConstant value, Class receiverClass) { - return !value.isDefaultForKind(); - } - - /** - * {@inheritDoc} - *

- * The {@code value} field in {@link OptionValue} is considered constant if the type of - * {@code receiver} is (assignable to) {@link StableOptionValue}. - */ - public JavaConstant readConstantFieldValue(JavaField field, JavaConstant receiver) { - HotSpotResolvedJavaField hotspotField = (HotSpotResolvedJavaField) field; - - if (hotspotField.isStatic()) { - if (isStaticFieldConstant(hotspotField)) { - JavaConstant value = readFieldValue(field, receiver); - if (hotspotField.isFinal() || !value.isDefaultForKind()) { - return value; - } - } - } else { - /* - * for non-static final fields, we must assume that they are only initialized if they - * have a non-default value. - */ - Object object = receiver.isNull() ? null : ((HotSpotObjectConstantImpl) receiver).object(); - - // Canonicalization may attempt to process an unsafe read before - // processing a guard (e.g. a null check or a type check) for this read - // so we need to check the object being read - if (object != null) { - if (hotspotField.isFinal()) { - if (hotspotField.isInObject(object)) { - JavaConstant value = readFieldValue(field, receiver); - if (isFinalInstanceFieldValueConstant(value, object.getClass())) { - return value; - } - } - } else if (hotspotField.isStable()) { - if (hotspotField.isInObject(object)) { - JavaConstant value = readFieldValue(field, receiver); - if (isStableInstanceFieldValueConstant(value, object.getClass())) { - return value; - } - } - } else { - Class clazz = object.getClass(); - if (StableOptionValue.class.isAssignableFrom(clazz)) { - if (hotspotField.isInObject(object) && hotspotField.getName().equals("value")) { - StableOptionValue option = (StableOptionValue) object; - return HotSpotObjectConstantImpl.forObject(option.getValue()); - } - } - } - } - } - return null; - } - - public JavaConstant readFieldValue(JavaField field, JavaConstant receiver) { - HotSpotResolvedJavaField hotspotField = (HotSpotResolvedJavaField) field; - if (!hotspotField.isStable()) { - return readNonStableFieldValue(field, receiver); - } else { - return readStableFieldValue(field, receiver, false); - } - } - - private JavaConstant readNonStableFieldValue(JavaField field, JavaConstant receiver) { - HotSpotResolvedJavaField hotspotField = (HotSpotResolvedJavaField) field; - if (hotspotField.isStatic()) { - HotSpotResolvedJavaType holder = (HotSpotResolvedJavaType) hotspotField.getDeclaringClass(); - if (holder.isInitialized()) { - return memoryAccess.readUnsafeConstant(hotspotField.getKind(), HotSpotObjectConstantImpl.forObject(holder.mirror()), hotspotField.offset()); - } - } else { - if (receiver.isNonNull() && hotspotField.isInObject(((HotSpotObjectConstantImpl) receiver).object())) { - return memoryAccess.readUnsafeConstant(hotspotField.getKind(), receiver, hotspotField.offset()); - } - } - return null; - } - - public JavaConstant readStableFieldValue(JavaField field, JavaConstant receiver, boolean isDefaultStable) { - JavaConstant fieldValue = readNonStableFieldValue(field, receiver); - if (fieldValue.isNonNull()) { - JavaType declaredType = field.getType(); - if (declaredType.getComponentType() != null) { - int stableDimension = getArrayDimension(declaredType); - return HotSpotObjectConstantImpl.forStableArray(((HotSpotObjectConstantImpl) fieldValue).object(), stableDimension, isDefaultStable); - } - } - return fieldValue; - } - - private static int getArrayDimension(JavaType type) { - int dimensions = 0; - JavaType componentType = type; - while ((componentType = componentType.getComponentType()) != null) { - dimensions++; - } - return dimensions; - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotForeignCallTarget.java --- a/graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotForeignCallTarget.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,42 +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.jvmci.hotspot; - -import com.oracle.jvmci.meta.*; - -public class HotSpotForeignCallTarget { - /** - * The descriptor of the call. - */ - protected final ForeignCallDescriptor descriptor; - - /** - * The entry point address of this call's target. - */ - protected long address; - - public HotSpotForeignCallTarget(ForeignCallDescriptor descriptor, long address) { - this.descriptor = descriptor; - this.address = address; - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotInstalledCode.java --- a/graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotInstalledCode.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,97 +0,0 @@ -/* - * Copyright (c) 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 static com.oracle.jvmci.common.UnsafeAccess.*; -import sun.misc.*; - -import com.oracle.jvmci.code.*; - -import edu.umd.cs.findbugs.annotations.*; - -/** - * Implementation of {@link InstalledCode} for HotSpot. - */ -public abstract class HotSpotInstalledCode extends InstalledCode { - - /** - * Total size of the code blob. - */ - @SuppressFBWarnings(value = "UWF_UNWRITTEN_FIELD", justification = "field is set by the native part") private int size; - - /** - * Start address of the code. - */ - @SuppressFBWarnings(value = "UWF_UNWRITTEN_FIELD", justification = "field is set by the native part") private long codeStart; - - /** - * Size of the code. - */ - @SuppressFBWarnings(value = "UWF_UNWRITTEN_FIELD", justification = "field is set by the native part") private int codeSize; - - public HotSpotInstalledCode(String name) { - super(name); - } - - /** - * @return the total size of this code blob - */ - public int getSize() { - return size; - } - - /** - * @return a copy of this code blob if it is {@linkplain #isValid() valid}, null otherwise. - */ - public byte[] getBlob() { - if (!isValid()) { - return null; - } - byte[] blob = new byte[size]; - unsafe.copyMemory(null, getAddress(), blob, Unsafe.ARRAY_BYTE_BASE_OFFSET, size); - return blob; - } - - @Override - public abstract String toString(); - - @Override - public long getStart() { - return codeStart; - } - - @Override - public long getCodeSize() { - return codeSize; - } - - @Override - public byte[] getCode() { - if (!isValid()) { - return null; - } - byte[] code = new byte[codeSize]; - unsafe.copyMemory(null, codeStart, code, Unsafe.ARRAY_BYTE_BASE_OFFSET, codeSize); - return code; - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotJVMCIBackendFactory.java --- a/graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotJVMCIBackendFactory.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,38 +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.jvmci.hotspot; - -import com.oracle.jvmci.runtime.*; -import com.oracle.jvmci.service.*; - -public interface HotSpotJVMCIBackendFactory extends Service { - - JVMCIBackend createJVMCIBackend(HotSpotJVMCIRuntimeProvider runtime, JVMCIBackend host); - - /** - * Gets the CPU architecture of this backend. - */ - String getArchitecture(); - - String getJVMCIRuntimeName(); -} diff -r 42452d2dfbec -r 395ac43a8578 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 Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,328 +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.jvmci.hotspot; - -import static com.oracle.jvmci.common.UnsafeAccess.*; -import static com.oracle.jvmci.hotspot.InitTimer.*; - -import java.lang.reflect.*; -import java.util.*; - -import com.oracle.jvmci.code.*; -import com.oracle.jvmci.common.*; -import com.oracle.jvmci.debug.*; -import com.oracle.jvmci.hotspot.logging.*; -import com.oracle.jvmci.meta.*; -import com.oracle.jvmci.options.*; -import com.oracle.jvmci.runtime.*; -import com.oracle.jvmci.service.*; - -//JaCoCo Exclude - -public final class HotSpotJVMCIRuntime implements HotSpotJVMCIRuntimeProvider, HotSpotProxified { - - private static final HotSpotJVMCIRuntime instance; - - static { - try (InitTimer t0 = timer("HotSpotJVMCIRuntime.")) { - try (InitTimer t = timer("HotSpotJVMCIRuntime.")) { - instance = new HotSpotJVMCIRuntime(); - } - - try (InitTimer t = timer("HotSpotJVMCIRuntime.completeInitialization")) { - // Why deferred initialization? See comment in completeInitialization(). - instance.completeInitialization(); - } - } - } - - /** - * Gets the singleton {@link HotSpotJVMCIRuntime} object. - */ - public static HotSpotJVMCIRuntime runtime() { - assert instance != null; - return instance; - } - - /** - * Do deferred initialization. - */ - public void completeInitialization() { - TTY.initialize(Options.LogFile.getStream(compilerToVm)); - - // Proxies for the VM/Compiler interfaces cannot be initialized - // in the constructor as proxy creation causes static - // initializers to be executed for all the types involved in the - // proxied methods. Some of these static initializers (e.g. in - // HotSpotMethodData) rely on the static 'instance' field being set - // to retrieve configuration details. - CompilerToVM toVM = this.compilerToVm; - - if (CountingProxy.ENABLED) { - toVM = CountingProxy.getProxy(CompilerToVM.class, toVM); - } - if (Logger.ENABLED) { - toVM = LoggingProxy.getProxy(CompilerToVM.class, toVM); - } - - this.compilerToVm = toVM; - } - - public static class Options { - - // @formatter:off - @Option(help = "The JVMCI runtime configuration to use", type = OptionType.Expert) - public static final OptionValue JVMCIRuntime = new OptionValue<>(""); - - @Option(help = "File to which logging is sent. A %p in the name will be replaced with a string identifying the process, usually the process id.", type = OptionType.Expert) - public static final PrintStreamOption LogFile = new PrintStreamOption(); - // @formatter:on - } - - public static HotSpotJVMCIBackendFactory findFactory(String architecture) { - HotSpotJVMCIBackendFactory basic = null; - HotSpotJVMCIBackendFactory selected = null; - HotSpotJVMCIBackendFactory nonBasic = null; - int nonBasicCount = 0; - - for (HotSpotJVMCIBackendFactory factory : Services.load(HotSpotJVMCIBackendFactory.class)) { - if (factory.getArchitecture().equalsIgnoreCase(architecture)) { - if (factory.getJVMCIRuntimeName().equals(Options.JVMCIRuntime.getValue())) { - assert selected == null || checkFactoryOverriding(selected, factory); - selected = factory; - } - if (factory.getJVMCIRuntimeName().equals("basic")) { - assert basic == null || checkFactoryOverriding(basic, factory); - basic = factory; - } else { - nonBasic = factory; - nonBasicCount++; - } - } - } - - if (selected != null) { - return selected; - } else { - if (!Options.JVMCIRuntime.getValue().equals("")) { - // Fail fast if a non-default value for JVMCIRuntime was specified - // and the corresponding factory is not available - throw new JVMCIError("Specified runtime \"%s\" not available for the %s architecture", Options.JVMCIRuntime.getValue(), architecture); - } else if (nonBasicCount == 1) { - // If there is exactly one non-basic runtime, select this one. - return nonBasic; - } else { - return basic; - } - } - } - - /** - * Checks that a factory overriding is valid. A factory B can only override/replace a factory A - * if the B.getClass() is a subclass of A.getClass(). This models the assumption that B is - * extends the behavior of A and has therefore understood the behavior expected of A. - * - * @param baseFactory - * @param overridingFactory - */ - private static boolean checkFactoryOverriding(HotSpotJVMCIBackendFactory baseFactory, HotSpotJVMCIBackendFactory overridingFactory) { - return baseFactory.getClass().isAssignableFrom(overridingFactory.getClass()); - } - - /** - * Gets the kind of a word value on the {@linkplain #getHostJVMCIBackend() host} backend. - */ - public static Kind getHostWordKind() { - return instance.getHostJVMCIBackend().getCodeCache().getTarget().wordKind; - } - - /** - * Reads a klass pointer from a constant object. - */ - public static long unsafeReadKlassPointer(Object object) { - return instance.getCompilerToVM().readUnsafeKlassPointer(object); - } - - /** - * Reads a word value from a given object. - */ - public static long unsafeReadWord(Object object, long offset) { - if (getHostWordKind() == Kind.Long) { - return unsafe.getLong(object, offset); - } - return unsafe.getInt(object, offset) & 0xFFFFFFFFL; - } - - protected/* final */CompilerToVM compilerToVm; - - protected final HotSpotVMConfig config; - private final JVMCIBackend hostBackend; - - /** - * JVMCI mirrors are stored as a {@link ClassValue} associated with the {@link Class} of the - * type. This data structure stores both {@link HotSpotResolvedObjectType} and - * {@link HotSpotResolvedPrimitiveType} types. - */ - private final ClassValue jvmciMirrors = new ClassValue() { - @Override - protected ResolvedJavaType computeValue(Class javaClass) { - if (javaClass.isPrimitive()) { - Kind kind = Kind.fromJavaClass(javaClass); - return new HotSpotResolvedPrimitiveType(kind); - } else { - return new HotSpotResolvedObjectTypeImpl(javaClass); - } - } - }; - - private final Map, JVMCIBackend> backends = new HashMap<>(); - - private final Iterable vmEventListeners; - - private HotSpotJVMCIRuntime() { - CompilerToVM toVM = new CompilerToVMImpl(); - compilerToVm = toVM; - try (InitTimer t = timer("HotSpotVMConfig")) { - config = new HotSpotVMConfig(compilerToVm); - } - - if (Boolean.valueOf(System.getProperty("jvmci.printconfig"))) { - printConfig(config); - } - - String hostArchitecture = config.getHostArchitectureName(); - - HotSpotJVMCIBackendFactory factory; - try (InitTimer t = timer("find factory:", hostArchitecture)) { - factory = findFactory(hostArchitecture); - } - try (InitTimer t = timer("create JVMCI backend:", hostArchitecture)) { - hostBackend = registerBackend(factory.createJVMCIBackend(this, null)); - } - - Iterable listeners = Services.load(HotSpotVMEventListener.class); - if (!listeners.iterator().hasNext()) { - listeners = Arrays.asList(new HotSpotVMEventListener() { - }); - } - vmEventListeners = listeners; - } - - private JVMCIBackend registerBackend(JVMCIBackend backend) { - Class arch = backend.getCodeCache().getTarget().arch.getClass(); - JVMCIBackend oldValue = backends.put(arch, backend); - assert oldValue == null : "cannot overwrite existing backend for architecture " + arch.getSimpleName(); - return backend; - } - - public ResolvedJavaType fromClass(Class javaClass) { - return jvmciMirrors.get(javaClass); - } - - private static void printConfig(HotSpotVMConfig config) { - Field[] fields = config.getClass().getDeclaredFields(); - Map sortedFields = new TreeMap<>(); - for (Field f : fields) { - f.setAccessible(true); - sortedFields.put(f.getName(), f); - } - for (Field f : sortedFields.values()) { - try { - Logger.info(String.format("%9s %-40s = %s", f.getType().getSimpleName(), f.getName(), Logger.pretty(f.get(config)))); - } catch (Exception e) { - } - } - } - - public HotSpotVMConfig getConfig() { - return config; - } - - public CompilerToVM getCompilerToVM() { - return compilerToVm; - } - - public JavaType lookupType(String name, HotSpotResolvedObjectType accessingType, boolean resolve) { - Objects.requireNonNull(accessingType, "cannot resolve type without an accessing class"); - // If the name represents a primitive type we can short-circuit the lookup. - if (name.length() == 1) { - Kind kind = Kind.fromPrimitiveOrVoidTypeChar(name.charAt(0)); - return fromClass(kind.toJavaClass()); - } - - // Resolve non-primitive types in the VM. - HotSpotResolvedObjectTypeImpl hsAccessingType = (HotSpotResolvedObjectTypeImpl) accessingType; - final long metaspaceKlass = compilerToVm.lookupType(name, hsAccessingType.mirror(), resolve); - - if (metaspaceKlass == 0L) { - assert resolve == false; - return HotSpotUnresolvedJavaType.create(this, name); - } - return HotSpotResolvedObjectTypeImpl.fromMetaspaceKlass(metaspaceKlass); - } - - public JVMCIBackend getHostJVMCIBackend() { - return hostBackend; - } - - public JVMCIBackend getJVMCIBackend(Class arch) { - assert arch != Architecture.class; - return backends.get(arch); - } - - public Map, JVMCIBackend> getBackends() { - return Collections.unmodifiableMap(backends); - } - - /** - * Called from the VM. - */ - @SuppressWarnings({"unused"}) - private void compileMetaspaceMethod(long metaspaceMethod, int entryBCI, long jvmciEnv, int id) { - for (HotSpotVMEventListener vmEventListener : vmEventListeners) { - vmEventListener.compileMetaspaceMethod(metaspaceMethod, entryBCI, jvmciEnv, id); - } - } - - /** - * Called from the VM. - */ - @SuppressWarnings({"unused"}) - private void compileTheWorld() throws Throwable { - for (HotSpotVMEventListener vmEventListener : vmEventListeners) { - vmEventListener.notifyCompileTheWorld(); - } - } - - /** - * Shuts down the runtime. - * - * Called from the VM. - */ - @SuppressWarnings({"unused"}) - private void shutdown() throws Exception { - for (HotSpotVMEventListener vmEventListener : vmEventListeners) { - vmEventListener.notifyShutdown(); - } - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotJVMCIRuntimeProvider.java --- a/graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotJVMCIRuntimeProvider.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,123 +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.jvmci.hotspot; - -import sun.misc.*; - -import com.oracle.jvmci.common.*; -import com.oracle.jvmci.meta.*; -import com.oracle.jvmci.runtime.*; - -//JaCoCo Exclude - -/** - * Configuration information for the HotSpot JVMCI runtime. - */ -public interface HotSpotJVMCIRuntimeProvider extends JVMCIRuntime { - - HotSpotVMConfig getConfig(); - - CompilerToVM getCompilerToVM(); - - /** - * Converts a name to a Java type. This method attempts to resolve {@code name} to a - * {@link ResolvedJavaType}. - * - * @param name a well formed Java type in {@linkplain JavaType#getName() internal} format - * @param accessingType the context of resolution which must be non-null - * @param resolve specifies whether resolution failure results in an unresolved type being - * return or a {@link LinkageError} being thrown - * @return a Java type for {@code name} which is guaranteed to be of type - * {@link ResolvedJavaType} if {@code resolve == true} - * @throws LinkageError if {@code resolve == true} and the resolution failed - * @throws NullPointerException if {@code accessingClass} is {@code null} - */ - JavaType lookupType(String name, HotSpotResolvedObjectType accessingType, boolean resolve); - - /** - * Gets the JVMCI mirror for a {@link Class} object. - * - * @return the {@link ResolvedJavaType} corresponding to {@code javaClass} - */ - ResolvedJavaType fromClass(Class clazz); - - /** - * The offset from the origin of an array to the first element. - * - * @return the offset in bytes - */ - default int getArrayBaseOffset(Kind kind) { - switch (kind) { - case Boolean: - return Unsafe.ARRAY_BOOLEAN_BASE_OFFSET; - case Byte: - return Unsafe.ARRAY_BYTE_BASE_OFFSET; - case Char: - return Unsafe.ARRAY_CHAR_BASE_OFFSET; - case Short: - return Unsafe.ARRAY_SHORT_BASE_OFFSET; - case Int: - return Unsafe.ARRAY_INT_BASE_OFFSET; - case Long: - return Unsafe.ARRAY_LONG_BASE_OFFSET; - case Float: - return Unsafe.ARRAY_FLOAT_BASE_OFFSET; - case Double: - return Unsafe.ARRAY_DOUBLE_BASE_OFFSET; - case Object: - return Unsafe.ARRAY_OBJECT_BASE_OFFSET; - default: - throw new JVMCIError("%s", kind); - } - } - - /** - * The scale used for the index when accessing elements of an array of this kind. - * - * @return the scale in order to convert the index into a byte offset - */ - default int getArrayIndexScale(Kind kind) { - switch (kind) { - case Boolean: - return Unsafe.ARRAY_BOOLEAN_INDEX_SCALE; - case Byte: - return Unsafe.ARRAY_BYTE_INDEX_SCALE; - case Char: - return Unsafe.ARRAY_CHAR_INDEX_SCALE; - case Short: - return Unsafe.ARRAY_SHORT_INDEX_SCALE; - case Int: - return Unsafe.ARRAY_INT_INDEX_SCALE; - case Long: - return Unsafe.ARRAY_LONG_INDEX_SCALE; - case Float: - return Unsafe.ARRAY_FLOAT_INDEX_SCALE; - case Double: - return Unsafe.ARRAY_DOUBLE_INDEX_SCALE; - case Object: - return Unsafe.ARRAY_OBJECT_INDEX_SCALE; - default: - throw new JVMCIError("%s", kind); - } - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotJVMCIVMEventListener.java --- a/graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotJVMCIVMEventListener.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,58 +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.jvmci.hotspot; - -import static com.oracle.jvmci.hotspot.CompileTheWorld.Options.*; - -import com.oracle.jvmci.debug.*; -import com.oracle.jvmci.hotspot.CompileTheWorld.Config; -import com.oracle.jvmci.service.*; - -@ServiceProvider(HotSpotVMEventListener.class) -public class HotSpotJVMCIVMEventListener implements HotSpotVMEventListener { - - @Override - public void notifyCompileTheWorld() throws Throwable { - CompilerToVM compilerToVM = HotSpotJVMCIRuntime.runtime().getCompilerToVM(); - int iterations = CompileTheWorld.Options.CompileTheWorldIterations.getValue(); - for (int i = 0; i < iterations; i++) { - compilerToVM.resetCompilationStatistics(); - TTY.println("CompileTheWorld : iteration " + i); - CompileTheWorld ctw = new CompileTheWorld(CompileTheWorldClasspath.getValue(), new Config(CompileTheWorldConfig.getValue()), CompileTheWorldStartAt.getValue(), - CompileTheWorldStopAt.getValue(), CompileTheWorldMethodFilter.getValue(), CompileTheWorldExcludeMethodFilter.getValue(), CompileTheWorldVerbose.getValue()); - ctw.compile(); - } - System.exit(0); - } - - @Override - public void notifyShutdown() { - // nothing to do - } - - @Override - public void compileMetaspaceMethod(long metaspaceMethod, int entryBCI, long jvmciEnv, int id) { - HotSpotResolvedJavaMethod method = HotSpotResolvedJavaMethodImpl.fromMetaspace(metaspaceMethod); - CompilationTask.compileMethod(method, entryBCI, jvmciEnv, id); - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotJavaType.java --- a/graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotJavaType.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,42 +0,0 @@ -/* - * Copyright (c) 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 com.oracle.jvmci.meta.*; - -/** - * Common base class for all HotSpot {@link JavaType} implementations. - */ -public abstract class HotSpotJavaType implements JavaType { - - private final String name; - - public HotSpotJavaType(String name) { - this.name = name; - } - - @Override - public final String getName() { - return name; - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotMemoryAccessProvider.java --- a/graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotMemoryAccessProvider.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,40 +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.hotspot; - -import com.oracle.jvmci.hotspot.HotSpotVMConfig.CompressEncoding; -import com.oracle.jvmci.meta.*; - -/** - * HotSpot specific extension of {@link MemoryAccessProvider}. - */ -public interface HotSpotMemoryAccessProvider extends MemoryAccessProvider { - - JavaConstant readNarrowOopConstant(Constant base, long displacement, CompressEncoding encoding); - - Constant readKlassPointerConstant(Constant base, long displacement); - - Constant readNarrowKlassPointerConstant(Constant base, long displacement, CompressEncoding encoding); - - Constant readMethodPointerConstant(Constant base, long displacement); -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotMemoryAccessProviderImpl.java --- a/graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotMemoryAccessProviderImpl.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,232 +0,0 @@ -/* - * Copyright (c) 2011, 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; - -import static com.oracle.jvmci.common.UnsafeAccess.*; - -import com.oracle.jvmci.code.*; -import com.oracle.jvmci.common.*; -import com.oracle.jvmci.hotspot.HotSpotVMConfig.CompressEncoding; -import com.oracle.jvmci.meta.*; - -/** - * HotSpot implementation of {@link MemoryAccessProvider}. - */ -public class HotSpotMemoryAccessProviderImpl implements HotSpotMemoryAccessProvider, HotSpotProxified { - - protected final HotSpotJVMCIRuntimeProvider runtime; - - public HotSpotMemoryAccessProviderImpl(HotSpotJVMCIRuntimeProvider runtime) { - this.runtime = runtime; - } - - private static Object asObject(Constant base) { - if (base instanceof HotSpotObjectConstantImpl) { - return ((HotSpotObjectConstantImpl) base).object(); - } else { - return null; - } - } - - private boolean isValidObjectFieldDisplacement(Constant base, long displacement) { - if (base instanceof HotSpotMetaspaceConstant) { - Object metaspaceObject = HotSpotMetaspaceConstantImpl.getMetaspaceObject(base); - if (metaspaceObject instanceof HotSpotResolvedObjectTypeImpl) { - if (displacement == runtime.getConfig().classMirrorOffset) { - // Klass::_java_mirror is valid for all Klass* values - return true; - } else if (displacement == runtime.getConfig().arrayKlassComponentMirrorOffset) { - // ArrayKlass::_component_mirror is only valid for all ArrayKlass* values - return ((HotSpotResolvedObjectTypeImpl) metaspaceObject).mirror().isArray(); - } - } else { - throw new JVMCIError("%s", metaspaceObject); - } - } - return false; - } - - private static long asRawPointer(Constant base) { - if (base instanceof HotSpotMetaspaceConstant) { - return ((HotSpotMetaspaceConstant) base).rawValue(); - } else if (base instanceof PrimitiveConstant) { - PrimitiveConstant prim = (PrimitiveConstant) base; - if (prim.getKind().isNumericInteger()) { - return prim.asLong(); - } - } - throw new JVMCIError("%s", base); - } - - private static long readRawValue(Constant baseConstant, long displacement, int bits) { - Object base = asObject(baseConstant); - if (base != null) { - switch (bits) { - case 8: - return unsafe.getByte(base, displacement); - case 16: - return unsafe.getShort(base, displacement); - case 32: - return unsafe.getInt(base, displacement); - case 64: - return unsafe.getLong(base, displacement); - default: - throw new JVMCIError("%d", bits); - } - } else { - long pointer = asRawPointer(baseConstant); - switch (bits) { - case 8: - return unsafe.getByte(pointer + displacement); - case 16: - return unsafe.getShort(pointer + displacement); - case 32: - return unsafe.getInt(pointer + displacement); - case 64: - return unsafe.getLong(pointer + displacement); - default: - throw new JVMCIError("%d", bits); - } - } - } - - private boolean verifyReadRawObject(Object expected, Constant base, long displacement, boolean compressed) { - if (compressed == runtime.getConfig().useCompressedOops) { - Object obj = asObject(base); - if (obj != null) { - assert expected == unsafe.getObject(obj, displacement) : "readUnsafeOop doesn't agree with unsafe.getObject"; - } - } - if (base instanceof HotSpotMetaspaceConstant) { - Object metaspaceObject = HotSpotMetaspaceConstantImpl.getMetaspaceObject(base); - if (metaspaceObject instanceof HotSpotResolvedObjectTypeImpl) { - if (displacement == runtime.getConfig().classMirrorOffset) { - assert expected == ((HotSpotResolvedObjectTypeImpl) metaspaceObject).mirror(); - } else if (displacement == runtime.getConfig().arrayKlassComponentMirrorOffset) { - assert expected == ((HotSpotResolvedObjectTypeImpl) metaspaceObject).mirror().getComponentType(); - } - } - } - return true; - } - - private Object readRawObject(Constant baseConstant, long initialDisplacement, boolean compressed) { - long displacement = initialDisplacement; - - Object ret; - Object base = asObject(baseConstant); - if (base == null) { - assert !compressed; - displacement += asRawPointer(baseConstant); - ret = runtime.getCompilerToVM().readUncompressedOop(displacement); - } else { - assert runtime.getConfig().useCompressedOops == compressed; - ret = unsafe.getObject(base, displacement); - } - assert verifyReadRawObject(ret, baseConstant, initialDisplacement, compressed); - return ret; - } - - @Override - public JavaConstant readUnsafeConstant(Kind kind, JavaConstant baseConstant, long displacement) { - if (kind == Kind.Object) { - Object o = readRawObject(baseConstant, displacement, runtime.getConfig().useCompressedOops); - return HotSpotObjectConstantImpl.forObject(o); - } else { - return readPrimitiveConstant(kind, baseConstant, displacement, kind.getByteCount() * 8); - } - } - - @Override - public JavaConstant readPrimitiveConstant(Kind kind, Constant baseConstant, long initialDisplacement, int bits) { - try { - long rawValue = readRawValue(baseConstant, initialDisplacement, bits); - switch (kind) { - case Boolean: - return JavaConstant.forBoolean(rawValue != 0); - case Byte: - return JavaConstant.forByte((byte) rawValue); - case Char: - return JavaConstant.forChar((char) rawValue); - case Short: - return JavaConstant.forShort((short) rawValue); - case Int: - return JavaConstant.forInt((int) rawValue); - case Long: - return JavaConstant.forLong(rawValue); - case Float: - return JavaConstant.forFloat(Float.intBitsToFloat((int) rawValue)); - case Double: - return JavaConstant.forDouble(Double.longBitsToDouble(rawValue)); - default: - throw new JVMCIError("Unsupported kind: %s", kind); - } - } catch (NullPointerException e) { - return null; - } - } - - @Override - public JavaConstant readObjectConstant(Constant base, long displacement) { - if (!isValidObjectFieldDisplacement(base, displacement)) { - return null; - } - return HotSpotObjectConstantImpl.forObject(readRawObject(base, displacement, false)); - } - - @Override - public JavaConstant readNarrowOopConstant(Constant base, long displacement, CompressEncoding encoding) { - assert encoding.equals(runtime.getConfig().getOopEncoding()) : "unexpected oop encoding: " + encoding + " != " + runtime.getConfig().getOopEncoding(); - return HotSpotObjectConstantImpl.forObject(readRawObject(base, displacement, true), true); - } - - @Override - public Constant readKlassPointerConstant(Constant base, long displacement) { - TargetDescription target = runtime.getHostJVMCIBackend().getCodeCache().getTarget(); - long klass = readRawValue(base, displacement, target.wordSize * 8); - if (klass == 0) { - return JavaConstant.NULL_POINTER; - } - HotSpotResolvedObjectType metaKlass = HotSpotResolvedObjectTypeImpl.fromMetaspaceKlass(klass); - return HotSpotMetaspaceConstantImpl.forMetaspaceObject(target.wordKind, klass, metaKlass, false); - } - - @Override - public Constant readNarrowKlassPointerConstant(Constant base, long displacement, CompressEncoding encoding) { - int compressed = (int) readRawValue(base, displacement, 32); - long klass = encoding.uncompress(compressed); - if (klass == 0) { - return HotSpotCompressedNullConstant.COMPRESSED_NULL; - } - HotSpotResolvedObjectType metaKlass = HotSpotResolvedObjectTypeImpl.fromMetaspaceKlass(klass); - return HotSpotMetaspaceConstantImpl.forMetaspaceObject(Kind.Int, compressed, metaKlass, true); - } - - @Override - public Constant readMethodPointerConstant(Constant base, long displacement) { - TargetDescription target = runtime.getHostJVMCIBackend().getCodeCache().getTarget(); - long method = readRawValue(base, displacement, target.wordSize * 8); - HotSpotResolvedJavaMethod metaMethod = HotSpotResolvedJavaMethodImpl.fromMetaspace(method); - return HotSpotMetaspaceConstantImpl.forMetaspaceObject(target.wordKind, method, metaMethod, false); - } -} diff -r 42452d2dfbec -r 395ac43a8578 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 Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,326 +0,0 @@ -/* - * Copyright (c) 2011, 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; - -import static com.oracle.jvmci.common.UnsafeAccess.*; -import static com.oracle.jvmci.hotspot.HotSpotResolvedJavaType.*; -import static com.oracle.jvmci.hotspot.HotSpotResolvedObjectTypeImpl.*; - -import java.lang.reflect.*; - -import com.oracle.jvmci.code.*; -import com.oracle.jvmci.common.*; -import com.oracle.jvmci.meta.*; - -// JaCoCo Exclude - -/** - * HotSpot implementation of {@link MetaAccessProvider}. - */ -public class HotSpotMetaAccessProvider implements MetaAccessProvider, HotSpotProxified { - - protected final HotSpotJVMCIRuntimeProvider runtime; - - public HotSpotMetaAccessProvider(HotSpotJVMCIRuntimeProvider runtime) { - this.runtime = runtime; - } - - public ResolvedJavaType lookupJavaType(Class clazz) { - if (clazz == null) { - throw new IllegalArgumentException("Class parameter was null"); - } - return runtime.fromClass(clazz); - } - - public HotSpotResolvedObjectType lookupJavaType(JavaConstant constant) { - if (constant.isNull() || !(constant instanceof HotSpotObjectConstant)) { - return null; - } - return ((HotSpotObjectConstant) constant).getType(); - } - - public Signature parseMethodDescriptor(String signature) { - return new HotSpotSignature(runtime, signature); - } - - /** - * {@link Field} object of {@link Method#slot}. - */ - @SuppressWarnings("javadoc") private Field reflectionMethodSlot = getReflectionSlotField(Method.class); - - /** - * {@link Field} object of {@link Constructor#slot}. - */ - @SuppressWarnings("javadoc") private Field reflectionConstructorSlot = getReflectionSlotField(Constructor.class); - - private static Field getReflectionSlotField(Class reflectionClass) { - try { - Field field = reflectionClass.getDeclaredField("slot"); - field.setAccessible(true); - return field; - } catch (NoSuchFieldException | SecurityException e) { - throw new JVMCIError(e); - } - } - - public ResolvedJavaMethod lookupJavaMethod(Executable reflectionMethod) { - try { - Class holder = reflectionMethod.getDeclaringClass(); - Field slotField = reflectionMethod instanceof Constructor ? reflectionConstructorSlot : reflectionMethodSlot; - final int slot = slotField.getInt(reflectionMethod); - final long metaspaceMethod = runtime.getCompilerToVM().getMetaspaceMethod(holder, slot); - return HotSpotResolvedJavaMethodImpl.fromMetaspace(metaspaceMethod); - } catch (IllegalArgumentException | IllegalAccessException e) { - throw new JVMCIError(e); - } - } - - public ResolvedJavaField lookupJavaField(Field reflectionField) { - String name = reflectionField.getName(); - Class fieldHolder = reflectionField.getDeclaringClass(); - Class fieldType = reflectionField.getType(); - // java.lang.reflect.Field's modifiers should be enough here since VM internal modifier bits - // are not used (yet). - final int modifiers = reflectionField.getModifiers(); - final long offset = Modifier.isStatic(modifiers) ? unsafe.staticFieldOffset(reflectionField) : unsafe.objectFieldOffset(reflectionField); - - HotSpotResolvedObjectType holder = fromObjectClass(fieldHolder); - JavaType type = fromClass(fieldType); - - if (offset != -1) { - HotSpotResolvedObjectType resolved = holder; - return resolved.createField(name, type, offset, modifiers); - } else { - throw new JVMCIError("unresolved field %s", reflectionField); - } - } - - private static int intMaskRight(int n) { - assert n <= 32; - return n == 32 ? -1 : (1 << n) - 1; - } - - @Override - public JavaConstant encodeDeoptActionAndReason(DeoptimizationAction action, DeoptimizationReason reason, int debugId) { - HotSpotVMConfig config = runtime.getConfig(); - int actionValue = convertDeoptAction(action); - int reasonValue = convertDeoptReason(reason); - int debugValue = debugId & intMaskRight(config.deoptimizationDebugIdBits); - JavaConstant c = JavaConstant.forInt(~((debugValue << config.deoptimizationDebugIdShift) | (reasonValue << config.deoptimizationReasonShift) | (actionValue << config.deoptimizationActionShift))); - assert c.asInt() < 0; - return c; - } - - public DeoptimizationReason decodeDeoptReason(JavaConstant constant) { - HotSpotVMConfig config = runtime.getConfig(); - int reasonValue = ((~constant.asInt()) >> config.deoptimizationReasonShift) & intMaskRight(config.deoptimizationReasonBits); - DeoptimizationReason reason = convertDeoptReason(reasonValue); - return reason; - } - - public DeoptimizationAction decodeDeoptAction(JavaConstant constant) { - HotSpotVMConfig config = runtime.getConfig(); - int actionValue = ((~constant.asInt()) >> config.deoptimizationActionShift) & intMaskRight(config.deoptimizationActionBits); - DeoptimizationAction action = convertDeoptAction(actionValue); - return action; - } - - public int decodeDebugId(JavaConstant constant) { - HotSpotVMConfig config = runtime.getConfig(); - return ((~constant.asInt()) >> config.deoptimizationDebugIdShift) & intMaskRight(config.deoptimizationDebugIdBits); - } - - public int convertDeoptAction(DeoptimizationAction action) { - HotSpotVMConfig config = runtime.getConfig(); - switch (action) { - case None: - return config.deoptActionNone; - case RecompileIfTooManyDeopts: - return config.deoptActionMaybeRecompile; - case InvalidateReprofile: - return config.deoptActionReinterpret; - case InvalidateRecompile: - return config.deoptActionMakeNotEntrant; - case InvalidateStopCompiling: - return config.deoptActionMakeNotCompilable; - default: - throw new JVMCIError("%s", action); - } - } - - public DeoptimizationAction convertDeoptAction(int action) { - HotSpotVMConfig config = runtime.getConfig(); - if (action == config.deoptActionNone) { - return DeoptimizationAction.None; - } - if (action == config.deoptActionMaybeRecompile) { - return DeoptimizationAction.RecompileIfTooManyDeopts; - } - if (action == config.deoptActionReinterpret) { - return DeoptimizationAction.InvalidateReprofile; - } - if (action == config.deoptActionMakeNotEntrant) { - return DeoptimizationAction.InvalidateRecompile; - } - if (action == config.deoptActionMakeNotCompilable) { - return DeoptimizationAction.InvalidateStopCompiling; - } - throw new JVMCIError("%d", action); - } - - public int convertDeoptReason(DeoptimizationReason reason) { - HotSpotVMConfig config = runtime.getConfig(); - switch (reason) { - case None: - return config.deoptReasonNone; - case NullCheckException: - return config.deoptReasonNullCheck; - case BoundsCheckException: - return config.deoptReasonRangeCheck; - case ClassCastException: - return config.deoptReasonClassCheck; - case ArrayStoreException: - return config.deoptReasonArrayCheck; - case UnreachedCode: - return config.deoptReasonUnreached0; - case TypeCheckedInliningViolated: - return config.deoptReasonTypeCheckInlining; - case OptimizedTypeCheckViolated: - return config.deoptReasonOptimizedTypeCheck; - case NotCompiledExceptionHandler: - return config.deoptReasonNotCompiledExceptionHandler; - case Unresolved: - return config.deoptReasonUnresolved; - case JavaSubroutineMismatch: - return config.deoptReasonJsrMismatch; - case ArithmeticException: - return config.deoptReasonDiv0Check; - case RuntimeConstraint: - return config.deoptReasonConstraint; - case LoopLimitCheck: - return config.deoptReasonLoopLimitCheck; - case Aliasing: - return config.deoptReasonAliasing; - case TransferToInterpreter: - return config.deoptReasonTransferToInterpreter; - default: - throw new JVMCIError("%s", reason); - } - } - - public DeoptimizationReason convertDeoptReason(int reason) { - HotSpotVMConfig config = runtime.getConfig(); - if (reason == config.deoptReasonNone) { - return DeoptimizationReason.None; - } - if (reason == config.deoptReasonNullCheck) { - return DeoptimizationReason.NullCheckException; - } - if (reason == config.deoptReasonRangeCheck) { - return DeoptimizationReason.BoundsCheckException; - } - if (reason == config.deoptReasonClassCheck) { - return DeoptimizationReason.ClassCastException; - } - if (reason == config.deoptReasonArrayCheck) { - return DeoptimizationReason.ArrayStoreException; - } - if (reason == config.deoptReasonUnreached0) { - return DeoptimizationReason.UnreachedCode; - } - if (reason == config.deoptReasonTypeCheckInlining) { - return DeoptimizationReason.TypeCheckedInliningViolated; - } - if (reason == config.deoptReasonOptimizedTypeCheck) { - return DeoptimizationReason.OptimizedTypeCheckViolated; - } - if (reason == config.deoptReasonNotCompiledExceptionHandler) { - return DeoptimizationReason.NotCompiledExceptionHandler; - } - if (reason == config.deoptReasonUnresolved) { - return DeoptimizationReason.Unresolved; - } - if (reason == config.deoptReasonJsrMismatch) { - return DeoptimizationReason.JavaSubroutineMismatch; - } - if (reason == config.deoptReasonDiv0Check) { - return DeoptimizationReason.ArithmeticException; - } - if (reason == config.deoptReasonConstraint) { - return DeoptimizationReason.RuntimeConstraint; - } - if (reason == config.deoptReasonLoopLimitCheck) { - return DeoptimizationReason.LoopLimitCheck; - } - if (reason == config.deoptReasonAliasing) { - return DeoptimizationReason.Aliasing; - } - if (reason == config.deoptReasonTransferToInterpreter) { - return DeoptimizationReason.TransferToInterpreter; - } - throw new JVMCIError("%x", reason); - } - - @Override - public long getMemorySize(JavaConstant constant) { - if (constant.getKind() == Kind.Object) { - HotSpotResolvedObjectType lookupJavaType = lookupJavaType(constant); - - if (lookupJavaType == null) { - return 0; - } else { - if (lookupJavaType.isArray()) { - // TODO(tw): Add compressed pointer support. - int length = Array.getLength(((HotSpotObjectConstantImpl) constant).object()); - ResolvedJavaType elementType = lookupJavaType.getComponentType(); - Kind elementKind = elementType.getKind(); - final int headerSize = runtime.getArrayBaseOffset(elementKind); - TargetDescription target = runtime.getHostJVMCIBackend().getTarget(); - int sizeOfElement = target.getSizeInBytes(elementKind); - int alignment = target.wordSize; - int log2ElementSize = CodeUtil.log2(sizeOfElement); - return computeArrayAllocationSize(length, alignment, headerSize, log2ElementSize); - } - return lookupJavaType.instanceSize(); - } - } else { - return constant.getKind().getByteCount(); - } - } - - /** - * Computes the size of the memory chunk allocated for an array. This size accounts for the - * array header size, body size and any padding after the last element to satisfy object - * alignment requirements. - * - * @param length the number of elements in the array - * @param alignment the object alignment requirement - * @param headerSize the size of the array header - * @param log2ElementSize log2 of the size of an element in the array - */ - public static int computeArrayAllocationSize(int length, int alignment, int headerSize, int log2ElementSize) { - int size = (length << log2ElementSize) + headerSize + (alignment - 1); - int mask = ~(alignment - 1); - return size & mask; - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotMetaspaceConstant.java --- a/graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotMetaspaceConstant.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,37 +0,0 @@ -/* - * 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 - * 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.hotspot.HotSpotVMConfig.CompressEncoding; -import com.oracle.jvmci.meta.*; - -public interface HotSpotMetaspaceConstant extends HotSpotConstant, VMConstant { - - Constant compress(CompressEncoding encoding); - - Constant uncompress(CompressEncoding encoding); - - HotSpotResolvedObjectType asResolvedJavaType(); - - long rawValue(); -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotMetaspaceConstantImpl.java --- a/graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotMetaspaceConstantImpl.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,92 +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.hotspot; - -import java.util.*; - -import com.oracle.jvmci.hotspot.HotSpotVMConfig.CompressEncoding; -import com.oracle.jvmci.meta.*; - -public final class HotSpotMetaspaceConstantImpl extends PrimitiveConstant implements HotSpotMetaspaceConstant, VMConstant, HotSpotProxified { - - static HotSpotMetaspaceConstantImpl forMetaspaceObject(Kind kind, long primitive, Object metaspaceObject, boolean compressed) { - return new HotSpotMetaspaceConstantImpl(kind, primitive, metaspaceObject, compressed); - } - - static Object getMetaspaceObject(Constant constant) { - return ((HotSpotMetaspaceConstantImpl) constant).metaspaceObject; - } - - private final Object metaspaceObject; - private final boolean compressed; - - private HotSpotMetaspaceConstantImpl(Kind kind, long primitive, Object metaspaceObject, boolean compressed) { - super(kind, primitive); - this.metaspaceObject = metaspaceObject; - this.compressed = compressed; - } - - @Override - public int hashCode() { - return super.hashCode() ^ System.identityHashCode(metaspaceObject); - } - - @Override - public boolean equals(Object o) { - return o == this || (o instanceof HotSpotMetaspaceConstantImpl && super.equals(o) && Objects.equals(metaspaceObject, ((HotSpotMetaspaceConstantImpl) o).metaspaceObject)); - } - - @Override - public String toString() { - return super.toString() + "{" + metaspaceObject + (compressed ? ";compressed}" : "}"); - } - - public boolean isCompressed() { - return compressed; - } - - public JavaConstant compress(CompressEncoding encoding) { - assert !isCompressed(); - HotSpotMetaspaceConstantImpl res = HotSpotMetaspaceConstantImpl.forMetaspaceObject(Kind.Int, encoding.compress(asLong()), metaspaceObject, true); - assert res.isCompressed(); - return res; - } - - public JavaConstant uncompress(CompressEncoding encoding) { - assert isCompressed(); - HotSpotMetaspaceConstantImpl res = HotSpotMetaspaceConstantImpl.forMetaspaceObject(Kind.Long, encoding.uncompress(asInt()), metaspaceObject, false); - assert !res.isCompressed(); - return res; - } - - public HotSpotResolvedObjectType asResolvedJavaType() { - if (metaspaceObject instanceof HotSpotResolvedObjectType) { - return (HotSpotResolvedObjectType) metaspaceObject; - } - return null; - } - - public long rawValue() { - return asLong(); - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotMethod.java --- a/graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotMethod.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,68 +0,0 @@ -/* - * Copyright (c) 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 static com.oracle.jvmci.debug.Debug.*; -import static java.util.FormattableFlags.*; - -import java.util.*; - -import com.oracle.jvmci.debug.*; -import com.oracle.jvmci.meta.*; - -public abstract class HotSpotMethod implements JavaMethod, Formattable, JavaMethodContex { - - protected String name; - - /** - * Controls whether {@link #toString()} includes the qualified or simple name of the class in - * which the method is declared. - */ - public static final boolean FULLY_QUALIFIED_METHOD_NAME = false; - - protected HotSpotMethod(String name) { - this.name = name; - } - - @Override - public final String getName() { - return name; - } - - @Override - public final String toString() { - char h = FULLY_QUALIFIED_METHOD_NAME ? 'H' : 'h'; - String suffix = this instanceof ResolvedJavaMethod ? "" : ", unresolved"; - String fmt = String.format("HotSpotMethod<%%%c.%%n(%%p)%s>", h, suffix); - return format(fmt); - } - - public void formatTo(Formatter formatter, int flags, int width, int precision) { - String base = (flags & ALTERNATE) == ALTERNATE ? getName() : toString(); - formatter.format(applyFormattingFlagsAndWidth(base, flags & ~ALTERNATE, width)); - } - - public JavaMethod asJavaMethod() { - return this; - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotMethodData.java --- a/graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotMethodData.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,858 +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.jvmci.hotspot; - -import static com.oracle.jvmci.common.UnsafeAccess.*; -import static com.oracle.jvmci.hotspot.HotSpotJVMCIRuntime.*; -import static java.lang.String.*; - -import java.util.*; - -import sun.misc.*; - -import com.oracle.jvmci.hotspot.HotSpotMethodDataAccessor.Tag; -import com.oracle.jvmci.meta.*; -import com.oracle.jvmci.meta.JavaMethodProfile.ProfiledMethod; -import com.oracle.jvmci.meta.JavaTypeProfile.ProfiledType; - -/** - * Access to a HotSpot MethodData structure (defined in methodData.hpp). - */ -public final class HotSpotMethodData { - - private static final HotSpotVMConfig config = runtime().getConfig(); - private static final HotSpotMethodDataAccessor NO_DATA_NO_EXCEPTION_ACCESSOR = new NoMethodData(TriState.FALSE); - private static final HotSpotMethodDataAccessor NO_DATA_EXCEPTION_POSSIBLY_NOT_RECORDED_ACCESSOR = new NoMethodData(TriState.UNKNOWN); - - // sorted by tag - // @formatter:off - private static final HotSpotMethodDataAccessor[] PROFILE_DATA_ACCESSORS = { - null, - new BitData(), - new CounterData(), - new JumpData(), - new TypeCheckData(), - new VirtualCallData(), - new RetData(), - new BranchData(), - new MultiBranchData(), - new ArgInfoData(), - null, // call_type_data_tag - null, // virtual_call_type_data_tag - null, // parameters_type_data_tag - null, // speculative_trap_data_tag - }; - // @formatter:on - - /** - * Reference to the C++ MethodData object. - */ - private final long metaspaceMethodData; - - public HotSpotMethodData(long metaspaceMethodData) { - this.metaspaceMethodData = metaspaceMethodData; - } - - /** - * @return value of the MethodData::_data_size field - */ - private int normalDataSize() { - return unsafe.getInt(metaspaceMethodData + config.methodDataDataSize); - } - - /** - * Returns the size of the extra data records. This method does the same calculation as - * MethodData::extra_data_size(). - * - * @return size of extra data records - */ - private int extraDataSize() { - final int extraDataBase = config.methodDataOopDataOffset + normalDataSize(); - final int extraDataLimit = unsafe.getInt(metaspaceMethodData + config.methodDataSize); - return extraDataLimit - extraDataBase; - } - - public boolean hasNormalData() { - return normalDataSize() > 0; - } - - public boolean hasExtraData() { - return extraDataSize() > 0; - } - - public int getExtraDataBeginOffset() { - return normalDataSize(); - } - - public boolean isWithin(int position) { - return position >= 0 && position < normalDataSize() + extraDataSize(); - } - - public int getDeoptimizationCount(DeoptimizationReason reason) { - HotSpotMetaAccessProvider metaAccess = (HotSpotMetaAccessProvider) runtime().getHostJVMCIBackend().getMetaAccess(); - int reasonIndex = metaAccess.convertDeoptReason(reason); - return unsafe.getByte(metaspaceMethodData + config.methodDataOopTrapHistoryOffset + reasonIndex) & 0xFF; - } - - public int getOSRDeoptimizationCount(DeoptimizationReason reason) { - HotSpotMetaAccessProvider metaAccess = (HotSpotMetaAccessProvider) runtime().getHostJVMCIBackend().getMetaAccess(); - int reasonIndex = metaAccess.convertDeoptReason(reason); - return unsafe.getByte(metaspaceMethodData + config.methodDataOopTrapHistoryOffset + config.deoptReasonOSROffset + reasonIndex) & 0xFF; - } - - public HotSpotMethodDataAccessor getNormalData(int position) { - if (position >= normalDataSize()) { - return null; - } - - HotSpotMethodDataAccessor result = getData(position); - assert result != null : "NO_DATA tag is not allowed"; - return result; - } - - public HotSpotMethodDataAccessor getExtraData(int position) { - if (position >= normalDataSize() + extraDataSize()) { - return null; - } - HotSpotMethodDataAccessor data = getData(position); - if (data != null) { - return data; - } - return data; - } - - public static HotSpotMethodDataAccessor getNoDataAccessor(boolean exceptionPossiblyNotRecorded) { - if (exceptionPossiblyNotRecorded) { - return NO_DATA_EXCEPTION_POSSIBLY_NOT_RECORDED_ACCESSOR; - } else { - return NO_DATA_NO_EXCEPTION_ACCESSOR; - } - } - - private HotSpotMethodDataAccessor getData(int position) { - assert position >= 0 : "out of bounds"; - final Tag tag = AbstractMethodData.readTag(this, position); - HotSpotMethodDataAccessor accessor = PROFILE_DATA_ACCESSORS[tag.getValue()]; - assert accessor == null || accessor.getTag() == tag : "wrong data accessor " + accessor + " for tag " + tag; - return accessor; - } - - private int readUnsignedByte(int position, int offsetInBytes) { - long fullOffsetInBytes = computeFullOffset(position, offsetInBytes); - return unsafe.getByte(metaspaceMethodData + fullOffsetInBytes) & 0xFF; - } - - private int readUnsignedShort(int position, int offsetInBytes) { - long fullOffsetInBytes = computeFullOffset(position, offsetInBytes); - return unsafe.getShort(metaspaceMethodData + fullOffsetInBytes) & 0xFFFF; - } - - /** - * Since the values are stored in cells (platform words) this method uses - * {@link Unsafe#getAddress} to read the right value on both little and big endian machines. - */ - private long readUnsignedInt(int position, int offsetInBytes) { - long fullOffsetInBytes = computeFullOffset(position, offsetInBytes); - return unsafe.getAddress(metaspaceMethodData + fullOffsetInBytes) & 0xFFFFFFFFL; - } - - private int readUnsignedIntAsSignedInt(int position, int offsetInBytes) { - long value = readUnsignedInt(position, offsetInBytes); - return truncateLongToInt(value); - } - - /** - * Since the values are stored in cells (platform words) this method uses - * {@link Unsafe#getAddress} to read the right value on both little and big endian machines. - */ - private int readInt(int position, int offsetInBytes) { - long fullOffsetInBytes = computeFullOffset(position, offsetInBytes); - return (int) unsafe.getAddress(metaspaceMethodData + fullOffsetInBytes); - } - - private long readWord(int position, int offsetInBytes) { - long fullOffsetInBytes = computeFullOffset(position, offsetInBytes); - return unsafe.getAddress(metaspaceMethodData + fullOffsetInBytes); - } - - private static int truncateLongToInt(long value) { - return value > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) value; - } - - private static int computeFullOffset(int position, int offsetInBytes) { - return config.methodDataOopDataOffset + position + offsetInBytes; - } - - private static int cellIndexToOffset(int cells) { - return config.dataLayoutHeaderSize + cellsToBytes(cells); - } - - private static int cellsToBytes(int cells) { - return cells * config.dataLayoutCellSize; - } - - /** - * Returns whether profiling ran long enough that the profile information is mature. Other - * informational data will still be valid even if the profile isn't mature. - */ - public boolean isProfileMature() { - return runtime().getCompilerToVM().isMature(metaspaceMethodData); - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - String nl = String.format("%n"); - String nlIndent = String.format("%n%38s", ""); - if (hasNormalData()) { - int pos = 0; - HotSpotMethodDataAccessor data; - while ((data = getNormalData(pos)) != null) { - if (pos != 0) { - sb.append(nl); - } - int bci = data.getBCI(this, pos); - sb.append(String.format("%-6d bci: %-6d%-20s", pos, bci, data.getClass().getSimpleName())); - sb.append(data.appendTo(new StringBuilder(), this, pos).toString().replace(nl, nlIndent)); - pos = pos + data.getSize(this, pos); - } - } - - if (hasExtraData()) { - int pos = getExtraDataBeginOffset(); - HotSpotMethodDataAccessor data; - while ((data = getExtraData(pos)) != null) { - if (pos == getExtraDataBeginOffset()) { - sb.append(nl).append("--- Extra data:"); - } - int bci = data.getBCI(this, pos); - sb.append(String.format("%n%-6d bci: %-6d%-20s", pos, bci, data.getClass().getSimpleName())); - sb.append(data.appendTo(new StringBuilder(), this, pos).toString().replace(nl, nlIndent)); - pos = pos + data.getSize(this, pos); - } - - } - return sb.toString(); - } - - private abstract static class AbstractMethodData implements HotSpotMethodDataAccessor { - - /** - * Corresponds to {@code exception_seen_flag}. - */ - private static final int EXCEPTIONS_MASK = 0x2; - - private final Tag tag; - private final int staticSize; - - protected AbstractMethodData(Tag tag, int staticSize) { - this.tag = tag; - this.staticSize = staticSize; - } - - public Tag getTag() { - return tag; - } - - public static Tag readTag(HotSpotMethodData data, int position) { - final int tag = data.readUnsignedByte(position, config.dataLayoutTagOffset); - return Tag.getEnum(tag); - } - - @Override - public int getBCI(HotSpotMethodData data, int position) { - return data.readUnsignedShort(position, config.dataLayoutBCIOffset); - } - - @Override - public int getSize(HotSpotMethodData data, int position) { - return staticSize + getDynamicSize(data, position); - } - - @Override - public TriState getExceptionSeen(HotSpotMethodData data, int position) { - return TriState.get((getFlags(data, position) & EXCEPTIONS_MASK) != 0); - } - - @Override - public JavaTypeProfile getTypeProfile(HotSpotMethodData data, int position) { - return null; - } - - @Override - public JavaMethodProfile getMethodProfile(HotSpotMethodData data, int position) { - return null; - } - - @Override - public double getBranchTakenProbability(HotSpotMethodData data, int position) { - return -1; - } - - @Override - public double[] getSwitchProbabilities(HotSpotMethodData data, int position) { - return null; - } - - @Override - public int getExecutionCount(HotSpotMethodData data, int position) { - return -1; - } - - @Override - public TriState getNullSeen(HotSpotMethodData data, int position) { - return TriState.UNKNOWN; - } - - protected int getFlags(HotSpotMethodData data, int position) { - return data.readUnsignedByte(position, config.dataLayoutFlagsOffset); - } - - /** - * @param data - * @param position - */ - protected int getDynamicSize(HotSpotMethodData data, int position) { - return 0; - } - - public abstract StringBuilder appendTo(StringBuilder sb, HotSpotMethodData data, int pos); - } - - private static class NoMethodData extends AbstractMethodData { - - private static final int NO_DATA_SIZE = cellIndexToOffset(0); - - private final TriState exceptionSeen; - - protected NoMethodData(TriState exceptionSeen) { - super(Tag.No, NO_DATA_SIZE); - this.exceptionSeen = exceptionSeen; - } - - @Override - public int getBCI(HotSpotMethodData data, int position) { - return -1; - } - - @Override - public TriState getExceptionSeen(HotSpotMethodData data, int position) { - return exceptionSeen; - } - - @Override - public StringBuilder appendTo(StringBuilder sb, HotSpotMethodData data, int pos) { - return sb; - } - } - - private static class BitData extends AbstractMethodData { - - private static final int BIT_DATA_SIZE = cellIndexToOffset(0); - private static final int BIT_DATA_NULL_SEEN_FLAG = 0x01; - - private BitData() { - super(Tag.BitData, BIT_DATA_SIZE); - } - - protected BitData(Tag tag, int staticSize) { - super(tag, staticSize); - } - - @Override - public TriState getNullSeen(HotSpotMethodData data, int position) { - return TriState.get((getFlags(data, position) & BIT_DATA_NULL_SEEN_FLAG) != 0); - } - - @Override - public StringBuilder appendTo(StringBuilder sb, HotSpotMethodData data, int pos) { - return sb.append(format("exception_seen(%s)", getExceptionSeen(data, pos))); - } - } - - private static class CounterData extends BitData { - - private static final int COUNTER_DATA_SIZE = cellIndexToOffset(1); - private static final int COUNTER_DATA_COUNT_OFFSET = cellIndexToOffset(0); - - public CounterData() { - super(Tag.CounterData, COUNTER_DATA_SIZE); - } - - protected CounterData(Tag tag, int staticSize) { - super(tag, staticSize); - } - - @Override - public int getExecutionCount(HotSpotMethodData data, int position) { - return getCounterValue(data, position); - } - - protected int getCounterValue(HotSpotMethodData data, int position) { - return data.readUnsignedIntAsSignedInt(position, COUNTER_DATA_COUNT_OFFSET); - } - - @Override - public StringBuilder appendTo(StringBuilder sb, HotSpotMethodData data, int pos) { - return sb.append(format("count(%d) null_seen(%s) exception_seen(%s)", getCounterValue(data, pos), getNullSeen(data, pos), getExceptionSeen(data, pos))); - } - } - - private static class JumpData extends AbstractMethodData { - - private static final int JUMP_DATA_SIZE = cellIndexToOffset(2); - protected static final int TAKEN_COUNT_OFFSET = cellIndexToOffset(0); - protected static final int TAKEN_DISPLACEMENT_OFFSET = cellIndexToOffset(1); - - public JumpData() { - super(Tag.JumpData, JUMP_DATA_SIZE); - } - - protected JumpData(Tag tag, int staticSize) { - super(tag, staticSize); - } - - @Override - public double getBranchTakenProbability(HotSpotMethodData data, int position) { - return getExecutionCount(data, position) != 0 ? 1 : 0; - } - - @Override - public int getExecutionCount(HotSpotMethodData data, int position) { - return data.readUnsignedIntAsSignedInt(position, TAKEN_COUNT_OFFSET); - } - - public int getTakenDisplacement(HotSpotMethodData data, int position) { - return data.readInt(position, TAKEN_DISPLACEMENT_OFFSET); - } - - @Override - public StringBuilder appendTo(StringBuilder sb, HotSpotMethodData data, int pos) { - return sb.append(format("taken(%d) displacement(%d)", getExecutionCount(data, pos), getTakenDisplacement(data, pos))); - } - } - - static class RawItemProfile { - final int entries; - final T[] items; - final long[] counts; - final long totalCount; - - public RawItemProfile(int entries, T[] items, long[] counts, long totalCount) { - this.entries = entries; - this.items = items; - this.counts = counts; - this.totalCount = totalCount; - } - } - - private abstract static class AbstractTypeData extends CounterData { - - protected static final int TYPE_DATA_ROW_SIZE = cellsToBytes(2); - - protected static final int NONPROFILED_COUNT_OFFSET = cellIndexToOffset(1); - protected static final int TYPE_DATA_FIRST_TYPE_OFFSET = cellIndexToOffset(2); - protected static final int TYPE_DATA_FIRST_TYPE_COUNT_OFFSET = cellIndexToOffset(3); - - protected AbstractTypeData(Tag tag, int staticSize) { - super(tag, staticSize); - } - - @Override - public JavaTypeProfile getTypeProfile(HotSpotMethodData data, int position) { - return createTypeProfile(getNullSeen(data, position), getRawTypeProfile(data, position)); - } - - private RawItemProfile getRawTypeProfile(HotSpotMethodData data, int position) { - int typeProfileWidth = config.typeProfileWidth; - - ResolvedJavaType[] types = new ResolvedJavaType[typeProfileWidth]; - long[] counts = new long[typeProfileWidth]; - long totalCount = 0; - int entries = 0; - - outer: for (int i = 0; i < typeProfileWidth; i++) { - long receiverKlass = data.readWord(position, getTypeOffset(i)); - if (receiverKlass != 0) { - HotSpotResolvedObjectTypeImpl klass = HotSpotResolvedObjectTypeImpl.fromMetaspaceKlass(receiverKlass); - long count = data.readUnsignedInt(position, getTypeCountOffset(i)); - /* - * Because of races in the profile collection machinery it's possible for a - * class to appear multiple times so merge them to make the profile look - * rational. - */ - for (int j = 0; j < entries; j++) { - if (types[j].equals(klass)) { - totalCount += count; - counts[j] += count; - continue outer; - } - } - types[entries] = klass; - totalCount += count; - counts[entries] = count; - entries++; - } - } - - totalCount += getTypesNotRecordedExecutionCount(data, position); - return new RawItemProfile<>(entries, types, counts, totalCount); - } - - protected abstract long getTypesNotRecordedExecutionCount(HotSpotMethodData data, int position); - - private static JavaTypeProfile createTypeProfile(TriState nullSeen, RawItemProfile profile) { - if (profile.entries <= 0 || profile.totalCount <= 0) { - return null; - } - - ProfiledType[] ptypes = new ProfiledType[profile.entries]; - double totalProbability = 0.0; - for (int i = 0; i < profile.entries; i++) { - double p = profile.counts[i]; - p = p / profile.totalCount; - totalProbability += p; - ptypes[i] = new ProfiledType(profile.items[i], p); - } - - Arrays.sort(ptypes); - - double notRecordedTypeProbability = profile.entries < config.typeProfileWidth ? 0.0 : Math.min(1.0, Math.max(0.0, 1.0 - totalProbability)); - assert notRecordedTypeProbability == 0 || profile.entries == config.typeProfileWidth; - return new JavaTypeProfile(nullSeen, notRecordedTypeProbability, ptypes); - } - - private static int getTypeOffset(int row) { - return TYPE_DATA_FIRST_TYPE_OFFSET + row * TYPE_DATA_ROW_SIZE; - } - - protected static int getTypeCountOffset(int row) { - return TYPE_DATA_FIRST_TYPE_COUNT_OFFSET + row * TYPE_DATA_ROW_SIZE; - } - - @Override - public StringBuilder appendTo(StringBuilder sb, HotSpotMethodData data, int pos) { - RawItemProfile profile = getRawTypeProfile(data, pos); - TriState nullSeen = getNullSeen(data, pos); - TriState exceptionSeen = getExceptionSeen(data, pos); - sb.append(format("count(%d) null_seen(%s) exception_seen(%s) nonprofiled_count(%d) entries(%d)", getCounterValue(data, pos), nullSeen, exceptionSeen, - getTypesNotRecordedExecutionCount(data, pos), profile.entries)); - for (int i = 0; i < profile.entries; i++) { - long count = profile.counts[i]; - sb.append(format("%n %s (%d, %4.2f)", profile.items[i].toJavaName(), count, (double) count / profile.totalCount)); - } - return sb; - } - } - - private static class TypeCheckData extends AbstractTypeData { - - private static final int TYPE_CHECK_DATA_SIZE = cellIndexToOffset(2) + TYPE_DATA_ROW_SIZE * config.typeProfileWidth; - - public TypeCheckData() { - super(Tag.ReceiverTypeData, TYPE_CHECK_DATA_SIZE); - } - - @Override - public int getExecutionCount(HotSpotMethodData data, int position) { - return -1; - } - - @Override - protected long getTypesNotRecordedExecutionCount(HotSpotMethodData data, int position) { - return data.readUnsignedIntAsSignedInt(position, NONPROFILED_COUNT_OFFSET); - } - } - - private static class VirtualCallData extends AbstractTypeData { - - private static final int VIRTUAL_CALL_DATA_SIZE = cellIndexToOffset(2) + TYPE_DATA_ROW_SIZE * (config.typeProfileWidth + config.methodProfileWidth); - private static final int VIRTUAL_CALL_DATA_FIRST_METHOD_OFFSET = TYPE_DATA_FIRST_TYPE_OFFSET + TYPE_DATA_ROW_SIZE * config.typeProfileWidth; - private static final int VIRTUAL_CALL_DATA_FIRST_METHOD_COUNT_OFFSET = TYPE_DATA_FIRST_TYPE_COUNT_OFFSET + TYPE_DATA_ROW_SIZE * config.typeProfileWidth; - - public VirtualCallData() { - super(Tag.VirtualCallData, VIRTUAL_CALL_DATA_SIZE); - } - - @Override - public int getExecutionCount(HotSpotMethodData data, int position) { - final int typeProfileWidth = config.typeProfileWidth; - - long total = 0; - for (int i = 0; i < typeProfileWidth; i++) { - total += data.readUnsignedInt(position, getTypeCountOffset(i)); - } - - total += getCounterValue(data, position); - return truncateLongToInt(total); - } - - @Override - protected long getTypesNotRecordedExecutionCount(HotSpotMethodData data, int position) { - return getCounterValue(data, position); - } - - private static long getMethodsNotRecordedExecutionCount(HotSpotMethodData data, int position) { - return data.readUnsignedIntAsSignedInt(position, NONPROFILED_COUNT_OFFSET); - } - - @Override - public JavaMethodProfile getMethodProfile(HotSpotMethodData data, int position) { - return createMethodProfile(getRawMethodProfile(data, position)); - } - - private static RawItemProfile getRawMethodProfile(HotSpotMethodData data, int position) { - int profileWidth = config.methodProfileWidth; - - ResolvedJavaMethod[] methods = new ResolvedJavaMethod[profileWidth]; - long[] counts = new long[profileWidth]; - long totalCount = 0; - int entries = 0; - - for (int i = 0; i < profileWidth; i++) { - long method = data.readWord(position, getMethodOffset(i)); - if (method != 0) { - methods[entries] = HotSpotResolvedJavaMethodImpl.fromMetaspace(method); - long count = data.readUnsignedInt(position, getMethodCountOffset(i)); - totalCount += count; - counts[entries] = count; - - entries++; - } - } - - totalCount += getMethodsNotRecordedExecutionCount(data, position); - return new RawItemProfile<>(entries, methods, counts, totalCount); - } - - private static JavaMethodProfile createMethodProfile(RawItemProfile profile) { - if (profile.entries <= 0 || profile.totalCount <= 0) { - return null; - } - - ProfiledMethod[] pmethods = new ProfiledMethod[profile.entries]; - double totalProbability = 0.0; - for (int i = 0; i < profile.entries; i++) { - double p = profile.counts[i]; - p = p / profile.totalCount; - totalProbability += p; - pmethods[i] = new ProfiledMethod(profile.items[i], p); - } - - Arrays.sort(pmethods); - - double notRecordedMethodProbability = profile.entries < config.methodProfileWidth ? 0.0 : Math.min(1.0, Math.max(0.0, 1.0 - totalProbability)); - assert notRecordedMethodProbability == 0 || profile.entries == config.methodProfileWidth; - return new JavaMethodProfile(notRecordedMethodProbability, pmethods); - } - - private static int getMethodOffset(int row) { - return VIRTUAL_CALL_DATA_FIRST_METHOD_OFFSET + row * TYPE_DATA_ROW_SIZE; - } - - private static int getMethodCountOffset(int row) { - return VIRTUAL_CALL_DATA_FIRST_METHOD_COUNT_OFFSET + row * TYPE_DATA_ROW_SIZE; - } - - @Override - public StringBuilder appendTo(StringBuilder sb, HotSpotMethodData data, int pos) { - RawItemProfile profile = getRawMethodProfile(data, pos); - super.appendTo(sb.append(format("exception_seen(%s) ", getExceptionSeen(data, pos))), data, pos).append(format("%nmethod_entries(%d)", profile.entries)); - for (int i = 0; i < profile.entries; i++) { - long count = profile.counts[i]; - sb.append(format("%n %s (%d, %4.2f)", profile.items[i].format("%H.%n(%p)"), count, (double) count / profile.totalCount)); - } - return sb; - } - } - - private static class RetData extends CounterData { - - private static final int RET_DATA_ROW_SIZE = cellsToBytes(3); - private static final int RET_DATA_SIZE = cellIndexToOffset(1) + RET_DATA_ROW_SIZE * config.bciProfileWidth; - - public RetData() { - super(Tag.RetData, RET_DATA_SIZE); - } - } - - private static class BranchData extends JumpData { - - private static final int BRANCH_DATA_SIZE = cellIndexToOffset(3); - private static final int NOT_TAKEN_COUNT_OFFSET = cellIndexToOffset(2); - - public BranchData() { - super(Tag.BranchData, BRANCH_DATA_SIZE); - } - - @Override - public double getBranchTakenProbability(HotSpotMethodData data, int position) { - long takenCount = data.readUnsignedInt(position, TAKEN_COUNT_OFFSET); - long notTakenCount = data.readUnsignedInt(position, NOT_TAKEN_COUNT_OFFSET); - long total = takenCount + notTakenCount; - - return total <= 0 ? -1 : takenCount / (double) total; - } - - @Override - public int getExecutionCount(HotSpotMethodData data, int position) { - long count = data.readUnsignedInt(position, TAKEN_COUNT_OFFSET) + data.readUnsignedInt(position, NOT_TAKEN_COUNT_OFFSET); - return truncateLongToInt(count); - } - - @Override - public StringBuilder appendTo(StringBuilder sb, HotSpotMethodData data, int pos) { - long taken = data.readUnsignedInt(pos, TAKEN_COUNT_OFFSET); - long notTaken = data.readUnsignedInt(pos, NOT_TAKEN_COUNT_OFFSET); - double takenProbability = getBranchTakenProbability(data, pos); - return sb.append(format("taken(%d, %4.2f) not_taken(%d, %4.2f) displacement(%d)", taken, takenProbability, notTaken, 1.0D - takenProbability, getTakenDisplacement(data, pos))); - } - } - - private static class ArrayData extends AbstractMethodData { - - private static final int ARRAY_DATA_LENGTH_OFFSET = cellIndexToOffset(0); - protected static final int ARRAY_DATA_START_OFFSET = cellIndexToOffset(1); - - public ArrayData(Tag tag, int staticSize) { - super(tag, staticSize); - } - - @Override - protected int getDynamicSize(HotSpotMethodData data, int position) { - return cellsToBytes(getLength(data, position)); - } - - protected static int getLength(HotSpotMethodData data, int position) { - return data.readInt(position, ARRAY_DATA_LENGTH_OFFSET); - } - - @Override - public StringBuilder appendTo(StringBuilder sb, HotSpotMethodData data, int pos) { - return sb.append(format("length(%d)", getLength(data, pos))); - } - } - - private static class MultiBranchData extends ArrayData { - - private static final int MULTI_BRANCH_DATA_SIZE = cellIndexToOffset(1); - private static final int MULTI_BRANCH_DATA_ROW_SIZE_IN_CELLS = 2; - private static final int MULTI_BRANCH_DATA_ROW_SIZE = cellsToBytes(MULTI_BRANCH_DATA_ROW_SIZE_IN_CELLS); - private static final int MULTI_BRANCH_DATA_FIRST_COUNT_OFFSET = ARRAY_DATA_START_OFFSET + cellsToBytes(0); - private static final int MULTI_BRANCH_DATA_FIRST_DISPLACEMENT_OFFSET = ARRAY_DATA_START_OFFSET + cellsToBytes(1); - - public MultiBranchData() { - super(Tag.MultiBranchData, MULTI_BRANCH_DATA_SIZE); - } - - @Override - public double[] getSwitchProbabilities(HotSpotMethodData data, int position) { - int arrayLength = getLength(data, position); - assert arrayLength > 0 : "switch must have at least the default case"; - assert arrayLength % MULTI_BRANCH_DATA_ROW_SIZE_IN_CELLS == 0 : "array must have full rows"; - - int length = arrayLength / MULTI_BRANCH_DATA_ROW_SIZE_IN_CELLS; - long totalCount = 0; - double[] result = new double[length]; - - // default case is first in HotSpot but last for the compiler - long count = readCount(data, position, 0); - totalCount += count; - result[length - 1] = count; - - for (int i = 1; i < length; i++) { - count = readCount(data, position, i); - totalCount += count; - result[i - 1] = count; - } - - if (totalCount <= 0) { - return null; - } else { - for (int i = 0; i < length; i++) { - result[i] = result[i] / totalCount; - } - return result; - } - } - - private static long readCount(HotSpotMethodData data, int position, int i) { - int offset; - long count; - offset = getCountOffset(i); - count = data.readUnsignedInt(position, offset); - return count; - } - - @Override - public int getExecutionCount(HotSpotMethodData data, int position) { - int arrayLength = getLength(data, position); - assert arrayLength > 0 : "switch must have at least the default case"; - assert arrayLength % MULTI_BRANCH_DATA_ROW_SIZE_IN_CELLS == 0 : "array must have full rows"; - - int length = arrayLength / MULTI_BRANCH_DATA_ROW_SIZE_IN_CELLS; - long totalCount = 0; - for (int i = 0; i < length; i++) { - int offset = getCountOffset(i); - totalCount += data.readUnsignedInt(position, offset); - } - - return truncateLongToInt(totalCount); - } - - private static int getCountOffset(int index) { - return MULTI_BRANCH_DATA_FIRST_COUNT_OFFSET + index * MULTI_BRANCH_DATA_ROW_SIZE; - } - - private static int getDisplacementOffset(int index) { - return MULTI_BRANCH_DATA_FIRST_DISPLACEMENT_OFFSET + index * MULTI_BRANCH_DATA_ROW_SIZE; - } - - @Override - public StringBuilder appendTo(StringBuilder sb, HotSpotMethodData data, int pos) { - int entries = getLength(data, pos) / MULTI_BRANCH_DATA_ROW_SIZE_IN_CELLS; - sb.append(format("entries(%d)", entries)); - for (int i = 0; i < entries; i++) { - sb.append(format("%n %d: count(%d) displacement(%d)", i, data.readUnsignedInt(pos, getCountOffset(i)), data.readUnsignedInt(pos, getDisplacementOffset(i)))); - } - return sb; - } - } - - private static class ArgInfoData extends ArrayData { - - private static final int ARG_INFO_DATA_SIZE = cellIndexToOffset(1); - - public ArgInfoData() { - super(Tag.ArgInfoData, ARG_INFO_DATA_SIZE); - } - } - - public void setCompiledIRSize(int size) { - unsafe.putInt(metaspaceMethodData + config.methodDataIRSizeOffset, size); - } - - public int getCompiledIRSize() { - return unsafe.getInt(metaspaceMethodData + config.methodDataIRSizeOffset); - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotMethodDataAccessor.java --- a/graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotMethodDataAccessor.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,112 +0,0 @@ -/* - * Copyright (c) 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 static com.oracle.jvmci.hotspot.HotSpotJVMCIRuntime.*; - -import com.oracle.jvmci.meta.*; - -/** - * Interface for accessor objects that encapsulate the logic for accessing the different kinds of - * data in a HotSpot methodDataOop. This interface is similar to the interface {@link ProfilingInfo} - * , but most methods require a MethodDataObject and the exact position within the methodData. - */ -public interface HotSpotMethodDataAccessor { - - /** - * {@code DataLayout} tag values. - */ - enum Tag { - No(config().dataLayoutNoTag), - BitData(config().dataLayoutBitDataTag), - CounterData(config().dataLayoutCounterDataTag), - JumpData(config().dataLayoutJumpDataTag), - ReceiverTypeData(config().dataLayoutReceiverTypeDataTag), - VirtualCallData(config().dataLayoutVirtualCallDataTag), - RetData(config().dataLayoutRetDataTag), - BranchData(config().dataLayoutBranchDataTag), - MultiBranchData(config().dataLayoutMultiBranchDataTag), - ArgInfoData(config().dataLayoutArgInfoDataTag), - CallTypeData(config().dataLayoutCallTypeDataTag), - VirtualCallTypeData(config().dataLayoutVirtualCallTypeDataTag), - ParametersTypeData(config().dataLayoutParametersTypeDataTag), - SpeculativeTrapData(config().dataLayoutSpeculativeTrapDataTag); - - private final int value; - - private Tag(int value) { - this.value = value; - } - - public int getValue() { - return value; - } - - private static HotSpotVMConfig config() { - return runtime().getConfig(); - } - - public static Tag getEnum(int value) { - Tag result = values()[value]; - assert value == result.value; - return result; - } - } - - /** - * Returns the {@link Tag} stored in the LayoutData header. - * - * @return tag stored in the LayoutData header - */ - Tag getTag(); - - /** - * Returns the BCI stored in the LayoutData header. - * - * @return An integer ≥ 0 and ≤ Short.MAX_VALUE, or -1 if not supported. - */ - int getBCI(HotSpotMethodData data, int position); - - /** - * Computes the size for the specific data at the given position. - * - * @return An integer > 0. - */ - int getSize(HotSpotMethodData data, int position); - - JavaTypeProfile getTypeProfile(HotSpotMethodData data, int position); - - JavaMethodProfile getMethodProfile(HotSpotMethodData data, int position); - - double getBranchTakenProbability(HotSpotMethodData data, int position); - - double[] getSwitchProbabilities(HotSpotMethodData data, int position); - - TriState getExceptionSeen(HotSpotMethodData data, int position); - - TriState getNullSeen(HotSpotMethodData data, int position); - - int getExecutionCount(HotSpotMethodData data, int position); - - StringBuilder appendTo(StringBuilder sb, HotSpotMethodData data, int pos); -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotMethodHandleAccessProvider.java --- a/graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotMethodHandleAccessProvider.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,162 +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.hotspot; - -import static com.oracle.jvmci.hotspot.HotSpotJVMCIRuntime.*; -import static com.oracle.jvmci.hotspot.HotSpotResolvedJavaType.*; -import static com.oracle.jvmci.hotspot.HotSpotResolvedObjectTypeImpl.*; - -import com.oracle.jvmci.common.*; -import com.oracle.jvmci.meta.*; - -public class HotSpotMethodHandleAccessProvider implements MethodHandleAccessProvider, HotSpotProxified { - - private final ConstantReflectionProvider constantReflection; - - public HotSpotMethodHandleAccessProvider(ConstantReflectionProvider constantReflection) { - this.constantReflection = constantReflection; - } - - /** - * Lazy initialization to break class initialization cycle. Field and method lookup is only - * possible after the {@link HotSpotJVMCIRuntime} is fully initialized. - */ - static class LazyInitialization { - static final ResolvedJavaField methodHandleFormField; - static final ResolvedJavaField lambdaFormVmentryField; - static final ResolvedJavaMethod lambdaFormCompileToBytecodeMethod; - static final ResolvedJavaField memberNameVmtargetField; - - /** - * Search for an instance field with the given name in a class. - * - * @param className name of the class to search in - * @param fieldName name of the field to be searched - * @return resolved java field - * @throws ClassNotFoundException - */ - private static ResolvedJavaField findFieldInClass(String className, String fieldName) throws ClassNotFoundException { - Class clazz = Class.forName(className); - ResolvedJavaType type = fromClass(clazz); - ResolvedJavaField[] fields = type.getInstanceFields(false); - for (ResolvedJavaField field : fields) { - if (field.getName().equals(fieldName)) { - return field; - } - } - return null; - } - - private static ResolvedJavaMethod findMethodInClass(String className, String methodName) throws ClassNotFoundException { - Class clazz = Class.forName(className); - HotSpotResolvedObjectTypeImpl type = fromObjectClass(clazz); - ResolvedJavaMethod result = null; - for (ResolvedJavaMethod method : type.getDeclaredMethods()) { - if (method.getName().equals(methodName)) { - assert result == null : "more than one method found: " + className + "." + methodName; - result = method; - } - } - assert result != null : "method not found: " + className + "." + methodName; - return result; - } - - static { - try { - methodHandleFormField = findFieldInClass("java.lang.invoke.MethodHandle", "form"); - lambdaFormVmentryField = findFieldInClass("java.lang.invoke.LambdaForm", "vmentry"); - lambdaFormCompileToBytecodeMethod = findMethodInClass("java.lang.invoke.LambdaForm", "compileToBytecode"); - memberNameVmtargetField = findFieldInClass("java.lang.invoke.MemberName", "vmtarget"); - } catch (Throwable ex) { - throw new JVMCIError(ex); - } - } - } - - @Override - public IntrinsicMethod lookupMethodHandleIntrinsic(ResolvedJavaMethod method) { - int intrinsicId = ((HotSpotResolvedJavaMethodImpl) method).intrinsicId(); - if (intrinsicId != 0) { - return getMethodHandleIntrinsic(intrinsicId); - } - return null; - } - - public static IntrinsicMethod getMethodHandleIntrinsic(int intrinsicId) { - HotSpotVMConfig config = runtime().getConfig(); - if (intrinsicId == config.vmIntrinsicInvokeBasic) { - return IntrinsicMethod.INVOKE_BASIC; - } else if (intrinsicId == config.vmIntrinsicLinkToInterface) { - return IntrinsicMethod.LINK_TO_INTERFACE; - } else if (intrinsicId == config.vmIntrinsicLinkToSpecial) { - return IntrinsicMethod.LINK_TO_SPECIAL; - } else if (intrinsicId == config.vmIntrinsicLinkToStatic) { - return IntrinsicMethod.LINK_TO_STATIC; - } else if (intrinsicId == config.vmIntrinsicLinkToVirtual) { - return IntrinsicMethod.LINK_TO_VIRTUAL; - } - return null; - } - - @Override - public ResolvedJavaMethod resolveInvokeBasicTarget(JavaConstant methodHandle, boolean forceBytecodeGeneration) { - if (methodHandle.isNull()) { - return null; - } - - /* Load non-public field: LambdaForm MethodHandle.form */ - JavaConstant lambdaForm = constantReflection.readFieldValue(LazyInitialization.methodHandleFormField, methodHandle); - if (lambdaForm.isNull()) { - return null; - } - - JavaConstant memberName; - if (forceBytecodeGeneration) { - /* Invoke non-public method: MemberName LambdaForm.compileToBytecode() */ - memberName = LazyInitialization.lambdaFormCompileToBytecodeMethod.invoke(lambdaForm, new JavaConstant[0]); - } else { - /* Load non-public field: MemberName LambdaForm.vmentry */ - memberName = constantReflection.readFieldValue(LazyInitialization.lambdaFormVmentryField, lambdaForm); - } - return getTargetMethod(memberName); - } - - @Override - public ResolvedJavaMethod resolveLinkToTarget(JavaConstant memberName) { - return getTargetMethod(memberName); - } - - /** - * Returns the {@link ResolvedJavaMethod} for the vmtarget of a java.lang.invoke.MemberName. - */ - private ResolvedJavaMethod getTargetMethod(JavaConstant memberName) { - if (memberName.isNull()) { - return null; - } - - /* Load injected field: JVM_Method* MemberName.vmtarget */ - JavaConstant vmtarget = constantReflection.readFieldValue(LazyInitialization.memberNameVmtargetField, memberName); - /* Create a method from the vmtarget method pointer. */ - return HotSpotResolvedJavaMethodImpl.fromMetaspace(vmtarget.asLong()); - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotMethodUnresolved.java --- a/graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotMethodUnresolved.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,67 +0,0 @@ -/* - * Copyright (c) 2011, 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; - -import com.oracle.jvmci.meta.*; - -/** - * Implementation of {@link JavaMethod} for unresolved HotSpot methods. - */ -public final class HotSpotMethodUnresolved extends HotSpotMethod { - - private final Signature signature; - protected JavaType holder; - - public HotSpotMethodUnresolved(String name, Signature signature, JavaType holder) { - super(name); - this.holder = holder; - this.signature = signature; - } - - @Override - public Signature getSignature() { - return signature; - } - - @Override - public JavaType getDeclaringClass() { - return holder; - } - - @Override - public int hashCode() { - return super.hashCode(); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null || !(obj instanceof HotSpotMethodUnresolved)) { - return false; - } - HotSpotMethodUnresolved that = (HotSpotMethodUnresolved) obj; - return this.name.equals(that.name) && this.signature.equals(that.signature) && this.holder.equals(that.holder); - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotNmethod.java --- a/graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotNmethod.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,116 +0,0 @@ -/* - * Copyright (c) 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 static com.oracle.jvmci.hotspot.HotSpotJVMCIRuntime.*; - -import com.oracle.jvmci.code.*; -import com.oracle.jvmci.meta.*; - -/** - * Implementation of {@link InstalledCode} for code installed as an nmethod. The nmethod stores a - * weak reference to an instance of this class. This is necessary to keep the nmethod from being - * unloaded while the associated {@link HotSpotNmethod} instance is alive. - *

- * Note that there is no (current) way for the reference from an nmethod to a {@link HotSpotNmethod} - * instance to be anything but weak. This is due to the fact that HotSpot does not treat nmethods as - * strong GC roots. - */ -public class HotSpotNmethod extends HotSpotInstalledCode { - - /** - * This (indirect) Method* reference is safe since class redefinition preserves all methods - * associated with nmethods in the code cache. - */ - private final HotSpotResolvedJavaMethod method; - - private final boolean isDefault; - private final boolean isExternal; - - public HotSpotNmethod(HotSpotResolvedJavaMethod method, String name, boolean isDefault) { - this(method, name, isDefault, false); - } - - public HotSpotNmethod(HotSpotResolvedJavaMethod method, String name, boolean isDefault, boolean isExternal) { - super(name); - this.method = method; - this.isDefault = isDefault; - this.isExternal = isExternal; - } - - public boolean isDefault() { - return isDefault; - } - - public boolean isExternal() { - return isExternal; - } - - public ResolvedJavaMethod getMethod() { - return method; - } - - @Override - public void invalidate() { - runtime().getCompilerToVM().invalidateInstalledCode(this); - } - - @Override - public String toString() { - return String.format("InstalledNmethod[method=%s, codeBlob=0x%x, isDefault=%b, name=%s]", method, getAddress(), isDefault, name); - } - - protected boolean checkThreeObjectArgs() { - assert method.getSignature().getParameterCount(!method.isStatic()) == 3; - assert method.getSignature().getParameterKind(0) == Kind.Object; - assert method.getSignature().getParameterKind(1) == Kind.Object; - assert !method.isStatic() || method.getSignature().getParameterKind(2) == Kind.Object; - return true; - } - - private boolean checkArgs(Object... args) { - JavaType[] sig = method.toParameterTypes(); - assert args.length == sig.length : method.format("%H.%n(%p): expected ") + sig.length + " args, got " + args.length; - for (int i = 0; i < sig.length; i++) { - Object arg = args[i]; - if (arg == null) { - assert sig[i].getKind() == Kind.Object : method.format("%H.%n(%p): expected arg ") + i + " to be Object, not " + sig[i]; - } else if (sig[i].getKind() != Kind.Object) { - assert sig[i].getKind().toBoxedJavaClass() == arg.getClass() : method.format("%H.%n(%p): expected arg ") + i + " to be " + sig[i] + ", not " + arg.getClass(); - } - } - return true; - } - - @Override - public Object executeVarargs(Object... args) throws InvalidInstalledCodeException { - assert checkArgs(args); - assert !isExternal(); - return runtime().getCompilerToVM().executeCompiledMethodVarargs(args, this); - } - - @Override - public long getStart() { - return isValid() ? super.getStart() : 0; - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotObjectConstant.java --- a/graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotObjectConstant.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,113 +0,0 @@ -/* - * Copyright (c) 2009, 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; - -import java.lang.invoke.*; -import java.util.*; - -import com.oracle.jvmci.meta.*; - -/** - * Represents a constant non-{@code null} object reference, within the compiler and across the - * compiler/runtime interface. - */ -public interface HotSpotObjectConstant extends JavaConstant, HotSpotConstant, VMConstant { - - JavaConstant compress(); - - JavaConstant uncompress(); - - /** - * Gets the resolved Java type of the object represented by this constant. - */ - HotSpotResolvedObjectType getType(); - - /** - * Gets the result of {@link Class#getClassLoader()} for the {@link Class} object represented by - * this constant. - * - * @return {@code null} if this constant does not represent a {@link Class} object - */ - JavaConstant getClassLoader(); - - /** - * Gets the {@linkplain System#identityHashCode(Object) identity} has code for the object - * represented by this constant. - */ - int getIdentityHashCode(); - - /** - * Gets the result of {@link Class#getComponentType()} for the {@link Class} object represented - * by this constant. - * - * @return {@code null} if this constant does not represent a {@link Class} object - */ - JavaConstant getComponentType(); - - /** - * Gets the result of {@link Class#getSuperclass()} for the {@link Class} object represented by - * this constant. - * - * @return {@code null} if this constant does not represent a {@link Class} object - */ - JavaConstant getSuperclass(); - - /** - * Gets the result of {@link CallSite#getTarget()} for the {@link CallSite} object represented - * by this constant. - * - * @param assumptions used to register an assumption that the {@link CallSite}'s target does not - * change - * @return {@code null} if this constant does not represent a {@link CallSite} object - */ - JavaConstant getCallSiteTarget(Assumptions assumptions); - - /** - * Determines if this constant represents an {@linkplain String#intern() interned} string. - */ - boolean isInternedString(); - - /** - * Gets the object represented by this constant represents if it is of a given type. - * - * @param type the expected type of the object represented by this constant. If the object is - * required to be of this type, then wrap the call to this method in - * {@link Objects#requireNonNull(Object)}. - * @return the object value represented by this constant if it is an - * {@link ResolvedJavaType#isInstance(JavaConstant) instance of} {@code type} otherwise - * {@code null} - */ - T asObject(Class type); - - /** - * Gets the object represented by this constant represents if it is of a given type. - * - * @param type the expected type of the object represented by this constant. If the object is - * required to be of this type, then wrap the call to this method in - * {@link Objects#requireNonNull(Object)}. - * @return the object value represented by this constant if it is an - * {@link ResolvedJavaType#isInstance(JavaConstant) instance of} {@code type} otherwise - * {@code null} - */ - Object asObject(ResolvedJavaType type); -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotObjectConstantImpl.java --- a/graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotObjectConstantImpl.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,290 +0,0 @@ -/* - * Copyright (c) 2009, 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 static com.oracle.jvmci.hotspot.HotSpotResolvedObjectTypeImpl.*; - -import java.lang.invoke.*; - -import com.oracle.jvmci.meta.*; - -import edu.umd.cs.findbugs.annotations.*; - -/** - * Represents a constant non-{@code null} object reference, within the compiler and across the - * compiler/runtime interface. - */ -public final class HotSpotObjectConstantImpl extends AbstractValue implements HotSpotObjectConstant, HotSpotProxified { - - public static JavaConstant forObject(Object object) { - return forObject(object, false); - } - - static JavaConstant forObject(Object object, boolean compressed) { - if (object == null) { - return compressed ? HotSpotCompressedNullConstant.COMPRESSED_NULL : JavaConstant.NULL_POINTER; - } else { - return new HotSpotObjectConstantImpl(object, compressed); - } - } - - static JavaConstant forStableArray(Object object, int stableDimension, boolean isDefaultStable) { - if (object == null) { - return JavaConstant.NULL_POINTER; - } else { - assert object.getClass().isArray(); - return new HotSpotObjectConstantImpl(object, false, stableDimension, isDefaultStable); - } - } - - public static JavaConstant forBoxedValue(Kind kind, Object value) { - if (kind == Kind.Object) { - return HotSpotObjectConstantImpl.forObject(value); - } else { - return JavaConstant.forBoxedPrimitive(value); - } - } - - static Object asBoxedValue(Constant constant) { - if (JavaConstant.isNull(constant)) { - return null; - } else if (constant instanceof HotSpotObjectConstantImpl) { - return ((HotSpotObjectConstantImpl) constant).object; - } else { - return ((JavaConstant) constant).asBoxedPrimitive(); - } - } - - private final Object object; - private final boolean compressed; - private final byte stableDimension; - private final boolean isDefaultStable; - - private HotSpotObjectConstantImpl(Object object, boolean compressed, int stableDimension, boolean isDefaultStable) { - super(LIRKind.reference(compressed ? Kind.Int : Kind.Object)); - this.object = object; - this.compressed = compressed; - this.stableDimension = (byte) stableDimension; - this.isDefaultStable = isDefaultStable; - assert object != null; - assert stableDimension == 0 || (object != null && object.getClass().isArray()); - assert stableDimension >= 0 && stableDimension <= 255; - assert !isDefaultStable || stableDimension > 0; - } - - private HotSpotObjectConstantImpl(Object object, boolean compressed) { - this(object, compressed, 0, false); - } - - /** - * Package-private accessor for the object represented by this constant. - */ - Object object() { - return object; - } - - /** - * Determines if the object represented by this constant is {@link Object#equals(Object) equal} - * to a given object. - */ - public boolean isEqualTo(Object obj) { - return object.equals(obj); - } - - /** - * Gets the class of the object represented by this constant. - */ - public Class getObjectClass() { - return object.getClass(); - } - - public boolean isCompressed() { - return compressed; - } - - public JavaConstant compress() { - assert !compressed; - return new HotSpotObjectConstantImpl(object, true, stableDimension, isDefaultStable); - } - - public JavaConstant uncompress() { - assert compressed; - return new HotSpotObjectConstantImpl(object, false, stableDimension, isDefaultStable); - } - - public HotSpotResolvedObjectType getType() { - return fromObjectClass(object.getClass()); - } - - public JavaConstant getClassLoader() { - if (object instanceof Class) { - /* - * This is an intrinsic for getClassLoader0, which occurs after any security checks. We - * can't call that directly so just call getClassLoader. - */ - return HotSpotObjectConstantImpl.forObject(((Class) object).getClassLoader()); - } - return null; - } - - public int getIdentityHashCode() { - return System.identityHashCode(object); - } - - public JavaConstant getComponentType() { - if (object instanceof Class) { - return HotSpotObjectConstantImpl.forObject(((Class) object).getComponentType()); - } - return null; - } - - public JavaConstant getSuperclass() { - if (object instanceof Class) { - return HotSpotObjectConstantImpl.forObject(((Class) object).getSuperclass()); - } - return null; - } - - public JavaConstant getCallSiteTarget(Assumptions assumptions) { - if (object instanceof CallSite) { - CallSite callSite = (CallSite) object; - MethodHandle target = callSite.getTarget(); - if (!(callSite instanceof ConstantCallSite)) { - if (assumptions == null) { - return null; - } - assumptions.record(new Assumptions.CallSiteTargetValue(callSite, target)); - } - return HotSpotObjectConstantImpl.forObject(target); - } - return null; - } - - @SuppressFBWarnings(value = "ES_COMPARING_STRINGS_WITH_EQ", justification = "reference equality is what we want") - public boolean isInternedString() { - if (object instanceof String) { - String s = (String) object; - return s.intern() == s; - } - return false; - } - - public T asObject(Class type) { - if (type.isInstance(object)) { - return type.cast(object); - } - return null; - } - - public Object asObject(ResolvedJavaType type) { - if (type.isInstance(this)) { - return object; - } - return null; - } - - @Override - public boolean isNull() { - return false; - } - - @Override - public boolean isDefaultForKind() { - return false; - } - - @Override - public Object asBoxedPrimitive() { - throw new IllegalArgumentException(); - } - - @Override - public int asInt() { - throw new IllegalArgumentException(); - } - - @Override - public boolean asBoolean() { - throw new IllegalArgumentException(); - } - - @Override - public long asLong() { - throw new IllegalArgumentException(); - } - - @Override - public float asFloat() { - throw new IllegalArgumentException(); - } - - @Override - public double asDouble() { - throw new IllegalArgumentException(); - } - - @Override - public int hashCode() { - return System.identityHashCode(object); - } - - @Override - public boolean equals(Object o) { - if (o == this) { - return true; - } else if (o instanceof HotSpotObjectConstantImpl) { - HotSpotObjectConstantImpl other = (HotSpotObjectConstantImpl) o; - return super.equals(o) && object == other.object && compressed == other.compressed && stableDimension == other.stableDimension && isDefaultStable == other.isDefaultStable; - } - return false; - } - - @Override - public String toValueString() { - if (object instanceof String) { - return (String) object; - } else { - return Kind.Object.format(object); - } - } - - @Override - public String toString() { - return (compressed ? "NarrowOop" : getKind().getJavaName()) + "[" + Kind.Object.format(object) + "]"; - } - - /** - * Number of stable dimensions if this constant is a stable array. - */ - public int getStableDimension() { - return stableDimension & 0xff; - } - - /** - * Returns {@code true} if this is a stable array constant and its elements should be considered - * as stable regardless of whether they are default values. - */ - public boolean isDefaultStable() { - return isDefaultStable; - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotOptions.java --- a/graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotOptions.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,55 +0,0 @@ -/* - * Copyright (c) 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.util.*; - -import com.oracle.jvmci.options.*; - -//JaCoCo Exclude - -/** - * Sets JVMCI options from the HotSpot command line. Such options are distinguished by the - * {@link #JVMCI_OPTION_PREFIX} prefix. - */ -public class HotSpotOptions { - - private static final String JVMCI_OPTION_PREFIX = "-G:"; - - /** - * Called from VM. - */ - static void printFlags() { - SortedMap options = new TreeMap<>(); - - for (Options opts : ServiceLoader.load(Options.class, HotSpotOptions.class.getClassLoader())) { - for (OptionDescriptor desc : opts) { - String name = desc.getName(); - OptionDescriptor existing = options.put(name, desc); - assert existing == null : "Option named \"" + name + "\" has multiple definitions: " + existing.getLocation() + " and " + desc.getLocation(); - } - } - - OptionUtils.printFlags(options, JVMCI_OPTION_PREFIX); - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotProfilingInfo.java --- a/graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotProfilingInfo.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,237 +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.jvmci.hotspot; - -import com.oracle.jvmci.debug.*; -import com.oracle.jvmci.meta.*; - -public final class HotSpotProfilingInfo implements ProfilingInfo, HotSpotProxified { - - private static final DebugMetric metricInsufficentSpace = Debug.metric("InsufficientSpaceForProfilingData"); - - private final HotSpotMethodData methodData; - private final HotSpotResolvedJavaMethod method; - - private boolean isMature; - private int position; - private int hintPosition; - private int hintBCI; - private HotSpotMethodDataAccessor dataAccessor; - - private boolean includeNormal; - private boolean includeOSR; - - public HotSpotProfilingInfo(HotSpotMethodData methodData, HotSpotResolvedJavaMethod method, boolean includeNormal, boolean includeOSR) { - this.methodData = methodData; - this.method = method; - this.includeNormal = includeNormal; - this.includeOSR = includeOSR; - this.isMature = methodData.isProfileMature(); - hintPosition = 0; - hintBCI = -1; - } - - @Override - public int getCodeSize() { - return method.getCodeSize(); - } - - @Override - public JavaTypeProfile getTypeProfile(int bci) { - if (!isMature) { - return null; - } - findBCI(bci, false); - return dataAccessor.getTypeProfile(methodData, position); - } - - @Override - public JavaMethodProfile getMethodProfile(int bci) { - if (!isMature) { - return null; - } - findBCI(bci, false); - return dataAccessor.getMethodProfile(methodData, position); - } - - @Override - public double getBranchTakenProbability(int bci) { - if (!isMature) { - return -1; - } - findBCI(bci, false); - return dataAccessor.getBranchTakenProbability(methodData, position); - } - - @Override - public double[] getSwitchProbabilities(int bci) { - if (!isMature) { - return null; - } - findBCI(bci, false); - return dataAccessor.getSwitchProbabilities(methodData, position); - } - - @Override - public TriState getExceptionSeen(int bci) { - findBCI(bci, true); - return dataAccessor.getExceptionSeen(methodData, position); - } - - @Override - public TriState getNullSeen(int bci) { - findBCI(bci, false); - return dataAccessor.getNullSeen(methodData, position); - } - - @Override - public int getExecutionCount(int bci) { - if (!isMature) { - return -1; - } - findBCI(bci, false); - return dataAccessor.getExecutionCount(methodData, position); - } - - @Override - public int getDeoptimizationCount(DeoptimizationReason reason) { - int count = 0; - if (includeNormal) { - count += methodData.getDeoptimizationCount(reason); - } - if (includeOSR) { - count += methodData.getOSRDeoptimizationCount(reason); - } - return count; - } - - private void findBCI(int targetBCI, boolean searchExtraData) { - assert targetBCI >= 0 : "invalid BCI"; - - if (methodData.hasNormalData()) { - int currentPosition = targetBCI < hintBCI ? 0 : hintPosition; - HotSpotMethodDataAccessor currentAccessor; - while ((currentAccessor = methodData.getNormalData(currentPosition)) != null) { - int currentBCI = currentAccessor.getBCI(methodData, currentPosition); - if (currentBCI == targetBCI) { - normalDataFound(currentAccessor, currentPosition, currentBCI); - return; - } else if (currentBCI > targetBCI) { - break; - } - currentPosition = currentPosition + currentAccessor.getSize(methodData, currentPosition); - } - } - - boolean exceptionPossiblyNotRecorded = false; - if (searchExtraData && methodData.hasExtraData()) { - int currentPosition = methodData.getExtraDataBeginOffset(); - HotSpotMethodDataAccessor currentAccessor; - while ((currentAccessor = methodData.getExtraData(currentPosition)) != null) { - int currentBCI = currentAccessor.getBCI(methodData, currentPosition); - if (currentBCI == targetBCI) { - extraDataFound(currentAccessor, currentPosition); - return; - } - currentPosition = currentPosition + currentAccessor.getSize(methodData, currentPosition); - } - - if (!methodData.isWithin(currentPosition)) { - exceptionPossiblyNotRecorded = true; - metricInsufficentSpace.increment(); - } - } - - noDataFound(exceptionPossiblyNotRecorded); - } - - private void normalDataFound(HotSpotMethodDataAccessor data, int pos, int bci) { - setCurrentData(data, pos); - this.hintPosition = position; - this.hintBCI = bci; - } - - private void extraDataFound(HotSpotMethodDataAccessor data, int pos) { - setCurrentData(data, pos); - } - - private void noDataFound(boolean exceptionPossiblyNotRecorded) { - HotSpotMethodDataAccessor accessor = HotSpotMethodData.getNoDataAccessor(exceptionPossiblyNotRecorded); - setCurrentData(accessor, -1); - } - - private void setCurrentData(HotSpotMethodDataAccessor dataAccessor, int position) { - this.dataAccessor = dataAccessor; - this.position = position; - } - - @Override - public boolean isMature() { - return isMature; - } - - public void ignoreMature() { - isMature = true; - } - - @Override - public String toString() { - return "HotSpotProfilingInfo<" + this.toString(null, "; ") + ">"; - } - - @Override - public void setMature() { - isMature = true; - } - - /** - * {@code MethodData::_jvmci_ir_size} (currently) supports at most one JVMCI compiler IR type - * which will be determined by the first JVMCI compiler that calls - * {@link #setCompilerIRSize(Class, int)}. - */ - private static volatile Class supportedCompilerIRType; - - @Override - public boolean setCompilerIRSize(Class irType, int size) { - if (supportedCompilerIRType == null) { - synchronized (HotSpotProfilingInfo.class) { - if (supportedCompilerIRType == null) { - supportedCompilerIRType = irType; - } - } - } - if (supportedCompilerIRType != irType) { - return false; - } - methodData.setCompiledIRSize(size); - return true; - } - - @Override - public int getCompilerIRSize(Class irType) { - if (irType == supportedCompilerIRType) { - return methodData.getCompiledIRSize(); - } - return -1; - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotProxified.java --- a/graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotProxified.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,29 +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.jvmci.hotspot; - -/** - * Marker interface for classes whose values are proxied during replay compilation capture. - */ -public interface HotSpotProxified { -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotReferenceMap.java --- a/graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotReferenceMap.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,109 +0,0 @@ -/* - * Copyright (c) 2009, 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 static com.oracle.jvmci.code.ValueUtil.*; - -import java.util.*; - -import com.oracle.jvmci.code.*; -import com.oracle.jvmci.meta.*; - -public final class HotSpotReferenceMap extends ReferenceMap { - - private Value[] objects; - private int[] bytesPerElement; - private int maxRegisterSize; - private ArrayList objectValues; - - private final TargetDescription target; - - public HotSpotReferenceMap(TargetDescription target) { - this.target = target; - this.objects = Value.NO_VALUES; - } - - @Override - public void reset() { - objectValues = new ArrayList<>(); - objects = Value.NO_VALUES; - bytesPerElement = null; - maxRegisterSize = 0; - } - - @Override - public void addLiveValue(Value v) { - if (isConstant(v)) { - return; - } - LIRKind lirKind = v.getLIRKind(); - if (!lirKind.isValue()) { - objectValues.add(v); - } - if (isRegister(v)) { - int size = target.getSizeInBytes(lirKind.getPlatformKind()); - if (size > maxRegisterSize) { - maxRegisterSize = size; - } - } - } - - @Override - public void finish() { - objects = objectValues.toArray(new Value[objectValues.size()]); - this.bytesPerElement = new int[objects.length]; - for (int i = 0; i < objects.length; i++) { - bytesPerElement[i] = bytesPerElement(objects[i].getLIRKind()); - } - objectValues = null; - } - - private int bytesPerElement(LIRKind kind) { - PlatformKind platformKind = kind.getPlatformKind(); - return target.getSizeInBytes(platformKind) / platformKind.getVectorLength(); - } - - @Override - public int hashCode() { - throw new UnsupportedOperationException(); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj instanceof HotSpotReferenceMap) { - HotSpotReferenceMap that = (HotSpotReferenceMap) obj; - if (Arrays.equals(objects, that.objects) && this.target.equals(that.target)) { - return true; - } - } - return false; - } - - @Override - public String toString() { - return Arrays.toString(objects); - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotResolvedJavaField.java --- a/graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotResolvedJavaField.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2011, 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.meta.*; - -/** - * Represents a field in a HotSpot type. - */ -public interface HotSpotResolvedJavaField extends ResolvedJavaField { - - /** - * Determines if a given object contains this field. - * - * @return true iff this is a non-static field and its declaring class is assignable from - * {@code object}'s class - */ - boolean isInObject(Object object); - - int offset(); - - /** - * Checks if this field has the {@link Stable} annotation. - * - * @return true if field has {@link Stable} annotation, false otherwise - */ - boolean isStable(); -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotResolvedJavaFieldImpl.java --- a/graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotResolvedJavaFieldImpl.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,289 +0,0 @@ -/* - * Copyright (c) 2011, 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 static com.oracle.jvmci.hotspot.HotSpotJVMCIRuntime.*; -import static com.oracle.jvmci.hotspot.HotSpotResolvedJavaFieldImpl.Options.*; -import static com.oracle.jvmci.hotspot.HotSpotResolvedObjectTypeImpl.*; - -import java.lang.annotation.*; -import java.lang.reflect.*; - -import com.oracle.jvmci.common.*; -import com.oracle.jvmci.meta.*; -import com.oracle.jvmci.options.*; - -/** - * Represents a field in a HotSpot type. - */ -public class HotSpotResolvedJavaFieldImpl implements HotSpotResolvedJavaField, HotSpotProxified { - - static class Options { - //@formatter:off - @Option(help = "Mark well-known stable fields as such.", type = OptionType.Debug) - public static final OptionValue ImplicitStableValues = new OptionValue<>(true); - //@formatter:on - } - - private final HotSpotResolvedObjectTypeImpl holder; - private final String name; - private JavaType type; - private final int offset; - - /** - * This value contains all flags as stored in the VM including internal ones. - */ - private final int modifiers; - private final LocationIdentity locationIdentity = new FieldLocationIdentity(this); - - public static class FieldLocationIdentity extends LocationIdentity { - HotSpotResolvedJavaField inner; - - public FieldLocationIdentity(HotSpotResolvedJavaFieldImpl inner) { - this.inner = inner; - } - - @Override - public boolean isImmutable() { - return false; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj instanceof FieldLocationIdentity) { - FieldLocationIdentity fieldLocationIdentity = (FieldLocationIdentity) obj; - return inner.equals(fieldLocationIdentity.inner); - - } - return false; - } - - @Override - public int hashCode() { - return inner.hashCode(); - } - - @Override - public String toString() { - return inner.getName(); - } - } - - public HotSpotResolvedJavaFieldImpl(HotSpotResolvedObjectTypeImpl holder, String name, JavaType type, long offset, int modifiers) { - this.holder = holder; - this.name = name; - this.type = type; - assert offset != -1; - assert offset == (int) offset : "offset larger than int"; - this.offset = (int) offset; - this.modifiers = modifiers; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj instanceof HotSpotResolvedJavaField) { - HotSpotResolvedJavaFieldImpl that = (HotSpotResolvedJavaFieldImpl) obj; - if (that.offset != this.offset || that.isStatic() != this.isStatic()) { - return false; - } else if (this.holder.equals(that.holder)) { - assert this.name.equals(that.name) && this.type.equals(that.type); - return true; - } - } - return false; - } - - @Override - public int hashCode() { - return name.hashCode(); - } - - @Override - public int getModifiers() { - return modifiers & getReflectionFieldModifiers(); - } - - @Override - public boolean isInternal() { - return (modifiers & runtime().getConfig().jvmAccFieldInternal) != 0; - } - - /** - * Determines if a given object contains this field. - * - * @return true iff this is a non-static field and its declaring class is assignable from - * {@code object}'s class - */ - public boolean isInObject(Object object) { - if (isStatic()) { - return false; - } - return getDeclaringClass().isAssignableFrom(HotSpotResolvedObjectTypeImpl.fromObjectClass(object.getClass())); - } - - @Override - public HotSpotResolvedObjectTypeImpl getDeclaringClass() { - return holder; - } - - @Override - public String getName() { - return name; - } - - @Override - public JavaType getType() { - // Pull field into local variable to prevent a race causing - // a ClassCastException below - JavaType currentType = type; - if (currentType instanceof HotSpotUnresolvedJavaType) { - // Don't allow unresolved types to hang around forever - HotSpotUnresolvedJavaType unresolvedType = (HotSpotUnresolvedJavaType) currentType; - ResolvedJavaType resolved = unresolvedType.reresolve(holder); - if (resolved != null) { - type = resolved; - } - } - return type; - } - - public int offset() { - return offset; - } - - @Override - public String toString() { - return format("HotSpotField<%H.%n %t:") + offset + ">"; - } - - @Override - public boolean isSynthetic() { - return (runtime().getConfig().syntheticFlag & modifiers) != 0; - } - - /** - * Checks if this field has the {@link Stable} annotation. - * - * @return true if field has {@link Stable} annotation, false otherwise - */ - public boolean isStable() { - if ((runtime().getConfig().jvmAccFieldStable & modifiers) != 0) { - return true; - } - assert getAnnotation(Stable.class) == null; - if (ImplicitStableValues.getValue() && isImplicitStableField()) { - return true; - } - return false; - } - - @Override - public T getAnnotation(Class annotationClass) { - Field javaField = toJava(); - if (javaField != null) { - return javaField.getAnnotation(annotationClass); - } - return null; - } - - private Field toJavaCache; - - private Field toJava() { - if (toJavaCache != null) { - return toJavaCache; - } - - if (isInternal()) { - return null; - } - try { - return toJavaCache = holder.mirror().getDeclaredField(name); - } catch (NoSuchFieldException | NoClassDefFoundError e) { - return null; - } - } - - private boolean isArray() { - JavaType fieldType = getType(); - return fieldType instanceof ResolvedJavaType && ((ResolvedJavaType) fieldType).isArray(); - } - - private boolean isImplicitStableField() { - if (isSynthetic()) { - if (isSyntheticImplicitStableField()) { - return true; - } - } else if (isWellKnownImplicitStableField()) { - return true; - } - return false; - } - - private boolean isSyntheticImplicitStableField() { - assert this.isSynthetic(); - if (isStatic() && isArray()) { - if (isFinal() && name.equals("$VALUES") || name.equals("ENUM$VALUES")) { - // generated int[] field for EnumClass::values() - return true; - } else if (name.startsWith("$SwitchMap$") || name.startsWith("$SWITCH_TABLE$")) { - // javac and ecj generate a static field in an inner class for a switch on an enum - // named $SwitchMap$p$k$g$EnumClass and $SWITCH_TABLE$p$k$g$EnumClass, respectively - return true; - } - } - return false; - } - - private boolean isWellKnownImplicitStableField() { - return WellKnownImplicitStableField.test(this); - } - - static class WellKnownImplicitStableField { - /** - * @return {@code true} if the field is a well-known stable field. - */ - public static boolean test(HotSpotResolvedJavaField field) { - return field.equals(STRING_VALUE_FIELD); - } - - private static final ResolvedJavaField STRING_VALUE_FIELD; - static { - try { - MetaAccessProvider metaAccess = runtime().getHostJVMCIBackend().getMetaAccess(); - STRING_VALUE_FIELD = metaAccess.lookupJavaField(String.class.getDeclaredField("value")); - } catch (SecurityException | NoSuchFieldException e) { - throw new JVMCIError(e); - } - } - } - - public LocationIdentity getLocationIdentity() { - return locationIdentity; - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotResolvedJavaMethod.java --- a/graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotResolvedJavaMethod.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,116 +0,0 @@ -/* - * Copyright (c) 2011, 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 java.lang.reflect.*; - -import com.oracle.jvmci.meta.*; - -/** - * Implementation of {@link JavaMethod} for resolved HotSpot methods. - */ -public interface HotSpotResolvedJavaMethod extends ResolvedJavaMethod { - - /** - * Returns true if this method has a {@code CallerSensitive} annotation. - * - * @return true if CallerSensitive annotation present, false otherwise - */ - boolean isCallerSensitive(); - - HotSpotResolvedObjectType getDeclaringClass(); - - /** - * Returns true if this method has a {@code ForceInline} annotation. - * - * @return true if ForceInline annotation present, false otherwise - */ - boolean isForceInline(); - - /** - * Returns true if this method has a {@code DontInline} annotation. - * - * @return true if DontInline annotation present, false otherwise - */ - boolean isDontInline(); - - /** - * Manually adds a DontInline annotation to this method. - */ - void setNotInlineable(); - - /** - * Returns true if this method is one of the special methods that is ignored by security stack - * walks. - * - * @return true if special method ignored by security stack walks, false otherwise - */ - boolean ignoredBySecurityStackWalk(); - - boolean hasBalancedMonitors(); - - ResolvedJavaMethod uniqueConcreteMethod(HotSpotResolvedObjectType receiver); - - /** - * Returns whether this method has compiled code. - * - * @return true if this method has compiled code, false otherwise - */ - boolean hasCompiledCode(); - - /** - * @param level - * @return true if the currently installed code was generated at {@code level}. - */ - boolean hasCompiledCodeAtLevel(int level); - - default boolean isDefault() { - if (isConstructor()) { - return false; - } - // Copied from java.lang.Method.isDefault() - int mask = Modifier.ABSTRACT | Modifier.PUBLIC | Modifier.STATIC; - return ((getModifiers() & mask) == Modifier.PUBLIC) && getDeclaringClass().isInterface(); - } - - /** - * Returns the offset of this method into the v-table. The method must have a v-table entry as - * indicated by {@link #isInVirtualMethodTable(ResolvedJavaType)}, otherwise an exception is - * thrown. - * - * @return the offset of this method into the v-table - */ - int vtableEntryOffset(ResolvedJavaType resolved); - - int intrinsicId(); - - /** - * Allocates a compile id for this method by asking the VM for one. - * - * @param entryBCI entry bci - * @return compile id - */ - int allocateCompileId(int entryBCI); - - boolean hasCodeAtLevel(int entryBCI, int level); -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotResolvedJavaMethodImpl.java --- a/graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotResolvedJavaMethodImpl.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,750 +0,0 @@ -/* - * Copyright (c) 2011, 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 static com.oracle.jvmci.common.UnsafeAccess.*; -import static com.oracle.jvmci.hotspot.HotSpotJVMCIRuntime.*; -import static com.oracle.jvmci.hotspot.HotSpotResolvedJavaMethodImpl.Options.*; - -import java.lang.annotation.*; -import java.lang.reflect.*; -import java.util.*; - -import com.oracle.jvmci.common.*; -import com.oracle.jvmci.debug.*; -import com.oracle.jvmci.meta.*; -import com.oracle.jvmci.options.*; - -/** - * Implementation of {@link JavaMethod} for resolved HotSpot methods. - */ -public final class HotSpotResolvedJavaMethodImpl extends HotSpotMethod implements HotSpotResolvedJavaMethod, HotSpotProxified, MethodIdHolder { - - static class Options { - // @formatter:off - @Option(help = "", type = OptionType.Debug) - public static final OptionValue UseProfilingInformation = new OptionValue<>(true); - // @formatter:on - } - - /** - * Reference to metaspace Method object. - */ - private final long metaspaceMethod; - - private final HotSpotResolvedObjectTypeImpl holder; - private final HotSpotConstantPool constantPool; - private final HotSpotSignature signature; - private HotSpotMethodData methodData; - private byte[] code; - private Member toJavaCache; - - /** - * Gets the holder of a HotSpot metaspace method native object. - * - * @param metaspaceMethod a metaspace Method object - * @return the {@link ResolvedJavaType} corresponding to the holder of the - * {@code metaspaceMethod} - */ - public static HotSpotResolvedObjectTypeImpl getHolder(long metaspaceMethod) { - HotSpotVMConfig config = runtime().getConfig(); - final long metaspaceConstMethod = unsafe.getAddress(metaspaceMethod + config.methodConstMethodOffset); - final long metaspaceConstantPool = unsafe.getAddress(metaspaceConstMethod + config.constMethodConstantsOffset); - final long metaspaceKlass = unsafe.getAddress(metaspaceConstantPool + config.constantPoolHolderOffset); - return HotSpotResolvedObjectTypeImpl.fromMetaspaceKlass(metaspaceKlass); - } - - /** - * Gets the {@link ResolvedJavaMethod} for a HotSpot metaspace method native object. - * - * @param metaspaceMethod a metaspace Method object - * @return the {@link ResolvedJavaMethod} corresponding to {@code metaspaceMethod} - */ - public static HotSpotResolvedJavaMethod fromMetaspace(long metaspaceMethod) { - HotSpotResolvedObjectTypeImpl holder = getHolder(metaspaceMethod); - return holder.createMethod(metaspaceMethod); - } - - public HotSpotResolvedJavaMethodImpl(HotSpotResolvedObjectTypeImpl holder, long metaspaceMethod) { - // It would be too much work to get the method name here so we fill it in later. - super(null); - this.metaspaceMethod = metaspaceMethod; - this.holder = holder; - - HotSpotVMConfig config = runtime().getConfig(); - final long constMethod = getConstMethod(); - - /* - * Get the constant pool from the metaspace method. Some methods (e.g. intrinsics for - * signature-polymorphic method handle methods) have their own constant pool instead of the - * one from their holder. - */ - final long metaspaceConstantPool = unsafe.getAddress(constMethod + config.constMethodConstantsOffset); - this.constantPool = new HotSpotConstantPool(metaspaceConstantPool); - - final int nameIndex = unsafe.getChar(constMethod + config.constMethodNameIndexOffset); - this.name = constantPool.lookupUtf8(nameIndex); - - final int signatureIndex = unsafe.getChar(constMethod + config.constMethodSignatureIndexOffset); - this.signature = (HotSpotSignature) constantPool.lookupSignature(signatureIndex); - } - - /** - * Returns a pointer to this method's constant method data structure ( - * {@code Method::_constMethod}). - * - * @return pointer to this method's ConstMethod - */ - private long getConstMethod() { - assert metaspaceMethod != 0; - return unsafe.getAddress(metaspaceMethod + runtime().getConfig().methodConstMethodOffset); - } - - @Override - public boolean equals(Object obj) { - if (obj instanceof HotSpotResolvedJavaMethodImpl) { - HotSpotResolvedJavaMethodImpl that = (HotSpotResolvedJavaMethodImpl) obj; - return that.metaspaceMethod == metaspaceMethod; - } - return false; - } - - @Override - public int hashCode() { - return (int) metaspaceMethod; - } - - /** - * Returns this method's flags ({@code Method::_flags}). - * - * @return flags of this method - */ - private int getFlags() { - return unsafe.getByte(metaspaceMethod + runtime().getConfig().methodFlagsOffset); - } - - /** - * Returns this method's constant method flags ({@code ConstMethod::_flags}). - * - * @return flags of this method's ConstMethod - */ - private int getConstMethodFlags() { - return unsafe.getChar(getConstMethod() + runtime().getConfig().constMethodFlagsOffset); - } - - @Override - public HotSpotResolvedObjectTypeImpl getDeclaringClass() { - return holder; - } - - /** - * Gets the address of the C++ Method object for this method. - */ - public JavaConstant getMetaspaceMethodConstant() { - return HotSpotMetaspaceConstantImpl.forMetaspaceObject(getHostWordKind(), metaspaceMethod, this, false); - } - - public long getMetaspaceMethod() { - return metaspaceMethod; - } - - @Override - public JavaConstant getEncoding() { - return getMetaspaceMethodConstant(); - } - - /** - * Gets the complete set of modifiers for this method which includes the JVM specification - * modifiers as well as the HotSpot internal modifiers. - */ - public int getAllModifiers() { - return unsafe.getInt(metaspaceMethod + runtime().getConfig().methodAccessFlagsOffset); - } - - @Override - public int getModifiers() { - return getAllModifiers() & Modifier.methodModifiers(); - } - - @Override - public boolean canBeStaticallyBound() { - return (isFinal() || isPrivate() || isStatic() || holder.isFinal()) && isConcrete(); - } - - @Override - public byte[] getCode() { - if (getCodeSize() == 0) { - return null; - } - if (code == null && holder.isLinked()) { - code = runtime().getCompilerToVM().getBytecode(metaspaceMethod); - assert code.length == getCodeSize() : "expected: " + getCodeSize() + ", actual: " + code.length; - } - return code; - } - - @Override - public int getCodeSize() { - return unsafe.getChar(getConstMethod() + runtime().getConfig().constMethodCodeSizeOffset); - } - - @Override - public ExceptionHandler[] getExceptionHandlers() { - final boolean hasExceptionTable = (getConstMethodFlags() & runtime().getConfig().constMethodHasExceptionTable) != 0; - if (!hasExceptionTable) { - return new ExceptionHandler[0]; - } - - HotSpotVMConfig config = runtime().getConfig(); - final int exceptionTableLength = runtime().getCompilerToVM().exceptionTableLength(metaspaceMethod); - ExceptionHandler[] handlers = new ExceptionHandler[exceptionTableLength]; - long exceptionTableElement = runtime().getCompilerToVM().exceptionTableStart(metaspaceMethod); - - for (int i = 0; i < exceptionTableLength; i++) { - final int startPc = unsafe.getChar(exceptionTableElement + config.exceptionTableElementStartPcOffset); - final int endPc = unsafe.getChar(exceptionTableElement + config.exceptionTableElementEndPcOffset); - final int handlerPc = unsafe.getChar(exceptionTableElement + config.exceptionTableElementHandlerPcOffset); - int catchTypeIndex = unsafe.getChar(exceptionTableElement + config.exceptionTableElementCatchTypeIndexOffset); - - JavaType catchType; - if (catchTypeIndex == 0) { - catchType = null; - } else { - final int opcode = -1; // opcode is not used - catchType = constantPool.lookupType(catchTypeIndex, opcode); - - // Check for Throwable which catches everything. - if (catchType instanceof HotSpotResolvedObjectTypeImpl) { - HotSpotResolvedObjectTypeImpl resolvedType = (HotSpotResolvedObjectTypeImpl) catchType; - if (resolvedType.mirror() == Throwable.class) { - catchTypeIndex = 0; - catchType = null; - } - } - } - handlers[i] = new ExceptionHandler(startPc, endPc, handlerPc, catchTypeIndex, catchType); - - // Go to the next ExceptionTableElement - exceptionTableElement += config.exceptionTableElementSize; - } - - return handlers; - } - - /** - * Returns true if this method has a {@code CallerSensitive} annotation. - * - * @return true if CallerSensitive annotation present, false otherwise - */ - public boolean isCallerSensitive() { - return (getFlags() & runtime().getConfig().methodFlagsCallerSensitive) != 0; - } - - /** - * Returns true if this method has a {@code ForceInline} annotation. - * - * @return true if ForceInline annotation present, false otherwise - */ - public boolean isForceInline() { - return (getFlags() & runtime().getConfig().methodFlagsForceInline) != 0; - } - - /** - * Returns true if this method has a {@code DontInline} annotation. - * - * @return true if DontInline annotation present, false otherwise - */ - public boolean isDontInline() { - return (getFlags() & runtime().getConfig().methodFlagsDontInline) != 0; - } - - /** - * Manually adds a DontInline annotation to this method. - */ - public void setNotInlineable() { - runtime().getCompilerToVM().doNotInlineOrCompile(metaspaceMethod); - } - - /** - * Returns true if this method is one of the special methods that is ignored by security stack - * walks. - * - * @return true if special method ignored by security stack walks, false otherwise - */ - public boolean ignoredBySecurityStackWalk() { - return runtime().getCompilerToVM().methodIsIgnoredBySecurityStackWalk(metaspaceMethod); - } - - public boolean hasBalancedMonitors() { - HotSpotVMConfig config = runtime().getConfig(); - final int modifiers = getAllModifiers(); - - // Method has no monitorenter/exit bytecodes. - if ((modifiers & config.jvmAccHasMonitorBytecodes) == 0) { - return false; - } - - // Check to see if a previous compilation computed the monitor-matching analysis. - if ((modifiers & config.jvmAccMonitorMatch) != 0) { - return true; - } - - // This either happens only once if monitors are balanced or very rarely multiple-times. - return runtime().getCompilerToVM().hasBalancedMonitors(metaspaceMethod); - } - - @Override - public boolean isClassInitializer() { - return "".equals(name) && isStatic(); - } - - @Override - public boolean isConstructor() { - return "".equals(name) && !isStatic(); - } - - @Override - public int getMaxLocals() { - if (isAbstract() || isNative()) { - return 0; - } - HotSpotVMConfig config = runtime().getConfig(); - return unsafe.getChar(getConstMethod() + config.methodMaxLocalsOffset); - } - - @Override - public int getMaxStackSize() { - if (isAbstract() || isNative()) { - return 0; - } - HotSpotVMConfig config = runtime().getConfig(); - return config.extraStackEntries + unsafe.getChar(getConstMethod() + config.constMethodMaxStackOffset); - } - - @Override - public StackTraceElement asStackTraceElement(int bci) { - if (bci < 0 || bci >= getCodeSize()) { - // HotSpot code can only construct stack trace elements for valid bcis - StackTraceElement ste = runtime().getCompilerToVM().getStackTraceElement(metaspaceMethod, 0); - return new StackTraceElement(ste.getClassName(), ste.getMethodName(), ste.getFileName(), -1); - } - return runtime().getCompilerToVM().getStackTraceElement(metaspaceMethod, bci); - } - - public ResolvedJavaMethod uniqueConcreteMethod(HotSpotResolvedObjectType receiver) { - if (receiver.isInterface()) { - // Cannot trust interfaces. Because of: - // interface I { void foo(); } - // class A { public void foo() {} } - // class B extends A implements I { } - // class C extends B { public void foo() { } } - // class D extends B { } - // Would lead to identify C.foo() as the unique concrete method for I.foo() without - // seeing A.foo(). - return null; - } - long metaspaceKlass = ((HotSpotResolvedObjectTypeImpl) receiver).getMetaspaceKlass(); - final long uniqueConcreteMethod = runtime().getCompilerToVM().findUniqueConcreteMethod(metaspaceKlass, metaspaceMethod); - if (uniqueConcreteMethod == 0) { - return null; - } - return fromMetaspace(uniqueConcreteMethod); - } - - @Override - public HotSpotSignature getSignature() { - return signature; - } - - /** - * Gets the value of {@code Method::_code}. - * - * @return the value of {@code Method::_code} - */ - private long getCompiledCode() { - HotSpotVMConfig config = runtime().getConfig(); - return unsafe.getAddress(metaspaceMethod + config.methodCodeOffset); - } - - /** - * Returns whether this method has compiled code. - * - * @return true if this method has compiled code, false otherwise - */ - public boolean hasCompiledCode() { - return getCompiledCode() != 0L; - } - - /** - * @param level - * @return true if the currently installed code was generated at {@code level}. - */ - public boolean hasCompiledCodeAtLevel(int level) { - long compiledCode = getCompiledCode(); - if (compiledCode != 0) { - return unsafe.getInt(compiledCode + runtime().getConfig().nmethodCompLevelOffset) == level; - } - return false; - } - - private static final String TraceMethodDataFilter = System.getProperty("jvmci.traceMethodDataFilter"); - - @Override - public ProfilingInfo getProfilingInfo(boolean includeNormal, boolean includeOSR) { - ProfilingInfo info; - - if (UseProfilingInformation.getValue() && methodData == null) { - long metaspaceMethodData = unsafe.getAddress(metaspaceMethod + runtime().getConfig().methodDataOffset); - if (metaspaceMethodData != 0) { - methodData = new HotSpotMethodData(metaspaceMethodData); - if (TraceMethodDataFilter != null && this.format("%H.%n").contains(TraceMethodDataFilter)) { - TTY.println("Raw method data for " + this.format("%H.%n(%p)") + ":"); - TTY.println(methodData.toString()); - } - } - } - - if (methodData == null || (!methodData.hasNormalData() && !methodData.hasExtraData())) { - // Be optimistic and return false for exceptionSeen. A methodDataOop is allocated in - // case of a deoptimization. - info = DefaultProfilingInfo.get(TriState.FALSE); - } else { - info = new HotSpotProfilingInfo(methodData, this, includeNormal, includeOSR); - } - return info; - } - - @Override - public void reprofile() { - runtime().getCompilerToVM().reprofile(metaspaceMethod); - } - - @Override - public ConstantPool getConstantPool() { - return constantPool; - } - - @Override - public Annotation[][] getParameterAnnotations() { - if (isConstructor()) { - Constructor javaConstructor = toJavaConstructor(); - return javaConstructor == null ? null : javaConstructor.getParameterAnnotations(); - } - Method javaMethod = toJava(); - return javaMethod == null ? null : javaMethod.getParameterAnnotations(); - } - - @Override - public Annotation[] getAnnotations() { - if (isConstructor()) { - Constructor javaConstructor = toJavaConstructor(); - return javaConstructor == null ? new Annotation[0] : javaConstructor.getAnnotations(); - } - Method javaMethod = toJava(); - return javaMethod == null ? new Annotation[0] : javaMethod.getAnnotations(); - } - - @Override - public T getAnnotation(Class annotationClass) { - if (isConstructor()) { - Constructor javaConstructor = toJavaConstructor(); - return javaConstructor == null ? null : javaConstructor.getAnnotation(annotationClass); - } - Method javaMethod = toJava(); - return javaMethod == null ? null : javaMethod.getAnnotation(annotationClass); - } - - @Override - public boolean isSynthetic() { - int modifiers = getAllModifiers(); - return (runtime().getConfig().syntheticFlag & modifiers) != 0; - } - - public boolean isDefault() { - if (isConstructor()) { - return false; - } - // Copied from java.lang.Method.isDefault() - int mask = Modifier.ABSTRACT | Modifier.PUBLIC | Modifier.STATIC; - return ((getModifiers() & mask) == Modifier.PUBLIC) && getDeclaringClass().isInterface(); - } - - @Override - public Type[] getGenericParameterTypes() { - if (isConstructor()) { - Constructor javaConstructor = toJavaConstructor(); - return javaConstructor == null ? null : javaConstructor.getGenericParameterTypes(); - } - Method javaMethod = toJava(); - return javaMethod == null ? null : javaMethod.getGenericParameterTypes(); - } - - public Class[] signatureToTypes() { - Signature sig = getSignature(); - int count = sig.getParameterCount(false); - Class[] result = new Class[count]; - for (int i = 0; i < result.length; ++i) { - JavaType parameterType = sig.getParameterType(i, holder); - HotSpotResolvedJavaType resolvedParameterType = (HotSpotResolvedJavaType) parameterType.resolve(holder); - result[i] = resolvedParameterType.mirror(); - } - return result; - } - - private Method toJava() { - if (toJavaCache != null) { - return (Method) toJavaCache; - } - try { - Method result = holder.mirror().getDeclaredMethod(name, signatureToTypes()); - toJavaCache = result; - return result; - } catch (NoSuchMethodException | NoClassDefFoundError e) { - return null; - } - } - - private Constructor toJavaConstructor() { - if (toJavaCache != null) { - return (Constructor) toJavaCache; - } - try { - Constructor result = holder.mirror().getDeclaredConstructor(signatureToTypes()); - toJavaCache = result; - return result; - } catch (NoSuchMethodException | NoClassDefFoundError e) { - return null; - } - } - - @Override - public boolean canBeInlined() { - if (isDontInline()) { - return false; - } - return runtime().getCompilerToVM().canInlineMethod(metaspaceMethod); - } - - @Override - public boolean shouldBeInlined() { - if (isForceInline()) { - return true; - } - return runtime().getCompilerToVM().shouldInlineMethod(metaspaceMethod); - } - - @Override - public LineNumberTable getLineNumberTable() { - final boolean hasLineNumberTable = (getConstMethodFlags() & runtime().getConfig().constMethodHasLineNumberTable) != 0; - if (!hasLineNumberTable) { - return null; - } - - long[] values = runtime().getCompilerToVM().getLineNumberTable(metaspaceMethod); - if (values.length == 0) { - // Empty table so treat is as non-existent - return null; - } - assert values.length % 2 == 0; - int[] bci = new int[values.length / 2]; - int[] line = new int[values.length / 2]; - - for (int i = 0; i < values.length / 2; i++) { - bci[i] = (int) values[i * 2]; - line[i] = (int) values[i * 2 + 1]; - } - - return new LineNumberTableImpl(line, bci); - } - - @Override - public LocalVariableTable getLocalVariableTable() { - final boolean hasLocalVariableTable = (getConstMethodFlags() & runtime().getConfig().constMethodHasLocalVariableTable) != 0; - if (!hasLocalVariableTable) { - return null; - } - - HotSpotVMConfig config = runtime().getConfig(); - long localVariableTableElement = runtime().getCompilerToVM().getLocalVariableTableStart(metaspaceMethod); - final int localVariableTableLength = runtime().getCompilerToVM().getLocalVariableTableLength(metaspaceMethod); - Local[] locals = new Local[localVariableTableLength]; - - for (int i = 0; i < localVariableTableLength; i++) { - final int startBci = unsafe.getChar(localVariableTableElement + config.localVariableTableElementStartBciOffset); - final int endBci = startBci + unsafe.getChar(localVariableTableElement + config.localVariableTableElementLengthOffset); - final int nameCpIndex = unsafe.getChar(localVariableTableElement + config.localVariableTableElementNameCpIndexOffset); - final int typeCpIndex = unsafe.getChar(localVariableTableElement + config.localVariableTableElementDescriptorCpIndexOffset); - final int slot = unsafe.getChar(localVariableTableElement + config.localVariableTableElementSlotOffset); - - String localName = getConstantPool().lookupUtf8(nameCpIndex); - String localType = getConstantPool().lookupUtf8(typeCpIndex); - - locals[i] = new LocalImpl(localName, runtime().lookupType(localType, holder, false), startBci, endBci, slot); - - // Go to the next LocalVariableTableElement - localVariableTableElement += config.localVariableTableElementSize; - } - - return new LocalVariableTableImpl(locals); - } - - /** - * Returns the offset of this method into the v-table. The method must have a v-table entry as - * indicated by {@link #isInVirtualMethodTable(ResolvedJavaType)}, otherwise an exception is - * thrown. - * - * @return the offset of this method into the v-table - */ - public int vtableEntryOffset(ResolvedJavaType resolved) { - if (!isInVirtualMethodTable(resolved)) { - throw new JVMCIError("%s does not have a vtable entry", this); - } - HotSpotVMConfig config = runtime().getConfig(); - final int vtableIndex = getVtableIndex((HotSpotResolvedObjectTypeImpl) resolved); - return config.instanceKlassVtableStartOffset + vtableIndex * config.vtableEntrySize + config.vtableEntryMethodOffset; - } - - @Override - public boolean isInVirtualMethodTable(ResolvedJavaType resolved) { - if (resolved instanceof HotSpotResolvedObjectTypeImpl) { - HotSpotResolvedObjectTypeImpl hotspotResolved = (HotSpotResolvedObjectTypeImpl) resolved; - int vtableIndex = getVtableIndex(hotspotResolved); - return vtableIndex >= 0 && vtableIndex < hotspotResolved.getVtableLength(); - } - return false; - } - - private int getVtableIndex(HotSpotResolvedObjectTypeImpl resolved) { - if (!holder.isLinked()) { - return runtime().getConfig().invalidVtableIndex; - } - if (holder.isInterface()) { - if (resolved.isInterface()) { - return runtime().getConfig().invalidVtableIndex; - } - return getVtableIndexForInterface(resolved); - } - return getVtableIndex(); - } - - /** - * Returns this method's virtual table index. - * - * @return virtual table index - */ - private int getVtableIndex() { - assert !holder.isInterface(); - HotSpotVMConfig config = runtime().getConfig(); - int result = unsafe.getInt(metaspaceMethod + config.methodVtableIndexOffset); - assert result >= config.nonvirtualVtableIndex : "must be linked"; - return result; - } - - private int getVtableIndexForInterface(ResolvedJavaType resolved) { - HotSpotResolvedObjectTypeImpl hotspotType = (HotSpotResolvedObjectTypeImpl) resolved; - return runtime().getCompilerToVM().getVtableIndexForInterface(hotspotType.getMetaspaceKlass(), getMetaspaceMethod()); - } - - /** - * The {@link SpeculationLog} for methods compiled by JVMCI hang off this per-declaring-type - * {@link ClassValue}. The raw Method* value is safe to use as a key in the map as a) it is - * never moves and b) we never read from it. - *

- * One implication is that we will preserve {@link SpeculationLog}s for methods that have been - * redefined via class redefinition. It's tempting to periodically flush such logs but we cannot - * read the JVM_ACC_IS_OBSOLETE bit (or anything else) via the raw pointer as obsoleted methods - * are subject to clean up and deletion (see InstanceKlass::purge_previous_versions_internal). - */ - private static final ClassValue> SpeculationLogs = new ClassValue>() { - @Override - protected Map computeValue(java.lang.Class type) { - return new HashMap<>(4); - } - }; - - public SpeculationLog getSpeculationLog() { - Map map = SpeculationLogs.get(holder.mirror()); - synchronized (map) { - SpeculationLog log = map.get(this.metaspaceMethod); - if (log == null) { - log = new HotSpotSpeculationLog(); - map.put(metaspaceMethod, log); - } - return log; - } - } - - public int intrinsicId() { - HotSpotVMConfig config = runtime().getConfig(); - return unsafe.getByte(metaspaceMethod + config.methodIntrinsicIdOffset) & 0xff; - } - - @Override - public JavaConstant invoke(JavaConstant receiver, JavaConstant[] arguments) { - assert !isConstructor(); - Method javaMethod = toJava(); - javaMethod.setAccessible(true); - - Object[] objArguments = new Object[arguments.length]; - for (int i = 0; i < arguments.length; i++) { - objArguments[i] = HotSpotObjectConstantImpl.asBoxedValue(arguments[i]); - } - Object objReceiver = receiver != null && !receiver.isNull() ? ((HotSpotObjectConstantImpl) receiver).object() : null; - - try { - Object objResult = javaMethod.invoke(objReceiver, objArguments); - return javaMethod.getReturnType() == void.class ? null : HotSpotObjectConstantImpl.forBoxedValue(getSignature().getReturnKind(), objResult); - - } catch (IllegalAccessException | InvocationTargetException ex) { - throw new IllegalArgumentException(ex); - } - } - - /** - * Allocates a compile id for this method by asking the VM for one. - * - * @param entryBCI entry bci - * @return compile id - */ - public int allocateCompileId(int entryBCI) { - return runtime().getCompilerToVM().allocateCompileId(metaspaceMethod, entryBCI); - } - - public boolean hasCodeAtLevel(int entryBCI, int level) { - if (entryBCI == runtime().getConfig().invocationEntryBci) { - return hasCompiledCodeAtLevel(level); - } - return runtime().getCompilerToVM().hasCompiledCodeForOSR(metaspaceMethod, entryBCI, level); - } - - private int methodId; - - public void setMethodId(int id) { - assert methodId == 0; - methodId = id; - } - - public int getMethodId() { - return methodId; - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotResolvedJavaType.java --- a/graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotResolvedJavaType.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,60 +0,0 @@ -/* - * Copyright (c) 2012, 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.hotspot; - -import static com.oracle.jvmci.hotspot.HotSpotJVMCIRuntime.*; - -import com.oracle.jvmci.meta.*; - -public abstract class HotSpotResolvedJavaType extends HotSpotJavaType implements ResolvedJavaType { - - /** - * Gets the JVMCI mirror for a {@link Class} object. - * - * @return the {@link HotSpotResolvedJavaType} corresponding to {@code javaClass} - */ - public static ResolvedJavaType fromClass(Class javaClass) { - return runtime().fromClass(javaClass); - } - - public HotSpotResolvedJavaType(String name) { - super(name); - } - - public abstract Class mirror(); - - @Override - public final boolean equals(Object obj) { - if (!(obj instanceof HotSpotResolvedJavaType)) { - return false; - } - HotSpotResolvedJavaType that = (HotSpotResolvedJavaType) obj; - return this.mirror().equals(that.mirror()); - } - - @Override - public final int hashCode() { - return getName().hashCode(); - } - -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotResolvedObjectType.java --- a/graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotResolvedObjectType.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,96 +0,0 @@ -/* - * Copyright (c) 2011, 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; - -import com.oracle.jvmci.meta.Assumptions.AssumptionResult; -import com.oracle.jvmci.meta.*; - -/** - * Implementation of {@link JavaType} for resolved non-primitive HotSpot classes. - */ -public interface HotSpotResolvedObjectType extends ResolvedJavaType { - - HotSpotResolvedObjectType getArrayClass(); - - ResolvedJavaType getComponentType(); - - AssumptionResult findLeafConcreteSubtype(); - - HotSpotResolvedObjectType getSuperclass(); - - HotSpotResolvedObjectType[] getInterfaces(); - - HotSpotResolvedObjectType getSupertype(); - - HotSpotResolvedObjectType findLeastCommonAncestor(ResolvedJavaType otherType); - - HotSpotResolvedObjectType asExactType(); - - default boolean isPrimitive() { - return false; - } - - default Kind getKind() { - return Kind.Object; - } - - ConstantPool constantPool(); - - /** - * Gets the instance size of this type. If an instance of this type cannot be fast path - * allocated, then the returned value is negative (its absolute value gives the size). Must not - * be called if this is an array or interface type. - */ - int instanceSize(); - - int getVtableLength(); - - @Override - AssumptionResult findUniqueConcreteMethod(ResolvedJavaMethod method); - - /** - * Performs a fast-path check that this type is resolved in the context of a given accessing - * class. A negative result does not mean this type is not resolved with respect to - * {@code accessingClass}. That can only be determined by - * {@linkplain HotSpotJVMCIRuntime#lookupType(String, HotSpotResolvedObjectType, boolean) - * re-resolving} the type. - */ - boolean isDefinitelyResolvedWithRespectTo(ResolvedJavaType accessingClass); - - /** - * Gets the metaspace Klass boxed in a {@link JavaConstant}. - */ - Constant klass(); - - boolean isPrimaryType(); - - int superCheckOffset(); - - long prototypeMarkWord(); - - HotSpotResolvedObjectType getEnclosingType(); - - ResolvedJavaMethod getClassInitializer(); - - ResolvedJavaField createField(String name, JavaType type, long offset, int modifiers); -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotResolvedObjectTypeImpl.java --- a/graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotResolvedObjectTypeImpl.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,902 +0,0 @@ -/* - * Copyright (c) 2011, 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; - -import static com.oracle.jvmci.common.UnsafeAccess.*; -import static com.oracle.jvmci.hotspot.HotSpotJVMCIRuntime.*; -import static java.util.Objects.*; - -import java.lang.annotation.*; -import java.lang.reflect.*; -import java.net.*; -import java.nio.*; -import java.util.*; - -import com.oracle.jvmci.common.*; -import com.oracle.jvmci.meta.Assumptions.AssumptionResult; -import com.oracle.jvmci.meta.Assumptions.ConcreteMethod; -import com.oracle.jvmci.meta.Assumptions.ConcreteSubtype; -import com.oracle.jvmci.meta.Assumptions.LeafType; -import com.oracle.jvmci.meta.Assumptions.NoFinalizableSubclass; -import com.oracle.jvmci.meta.*; - -/** - * Implementation of {@link JavaType} for resolved non-primitive HotSpot classes. - */ -public final class HotSpotResolvedObjectTypeImpl extends HotSpotResolvedJavaType implements HotSpotResolvedObjectType, HotSpotProxified { - - /** - * The Java class this type represents. - */ - private final Class javaClass; - - private HashMap fieldCache; - private HashMap methodCache; - private HotSpotResolvedJavaField[] instanceFields; - private HotSpotResolvedObjectTypeImpl[] interfaces; - private ConstantPool constantPool; - private HotSpotResolvedObjectType arrayOfType; - - /** - * Gets the JVMCI mirror for a {@link Class} object. - * - * @return the {@link HotSpotResolvedJavaType} corresponding to {@code javaClass} - */ - public static HotSpotResolvedObjectTypeImpl fromObjectClass(Class javaClass) { - return (HotSpotResolvedObjectTypeImpl) runtime().fromClass(javaClass); - } - - /** - * Gets the JVMCI mirror from a HotSpot metaspace Klass native object. - * - * @param metaspaceKlass a metaspace Klass object - * @return the {@link ResolvedJavaType} corresponding to {@code metaspaceKlass} - */ - public static HotSpotResolvedObjectTypeImpl fromMetaspaceKlass(long metaspaceKlass) { - assert metaspaceKlass != 0; - Class javaClass = runtime().getCompilerToVM().getJavaMirror(metaspaceKlass); - assert javaClass != null; - return fromObjectClass(javaClass); - } - - /** - * Creates the JVMCI mirror for a {@link Class} object. - * - *

- * NOTE: Creating an instance of this class does not install the mirror for the - * {@link Class} type. Use {@link #fromObjectClass(Class)} or {@link #fromMetaspaceKlass(long)} - * instead. - *

- * - * @param javaClass the Class to create the mirror for - */ - public HotSpotResolvedObjectTypeImpl(Class javaClass) { - super(getSignatureName(javaClass)); - this.javaClass = javaClass; - assert getName().charAt(0) != '[' || isArray() : getName(); - } - - /** - * Returns the name of this type as it would appear in a signature. - */ - private static String getSignatureName(Class javaClass) { - if (javaClass.isArray()) { - return javaClass.getName().replace('.', '/'); - } - return "L" + javaClass.getName().replace('.', '/') + ";"; - } - - /** - * Gets the metaspace Klass for this type. - */ - public long getMetaspaceKlass() { - if (HotSpotJVMCIRuntime.getHostWordKind() == Kind.Long) { - return unsafe.getLong(javaClass, (long) runtime().getConfig().klassOffset); - } - return unsafe.getInt(javaClass, (long) runtime().getConfig().klassOffset) & 0xFFFFFFFFL; - } - - @Override - public int getModifiers() { - return mirror().getModifiers(); - } - - public int getAccessFlags() { - HotSpotVMConfig config = runtime().getConfig(); - return unsafe.getInt(getMetaspaceKlass() + config.klassAccessFlagsOffset); - } - - @Override - public HotSpotResolvedObjectType getArrayClass() { - if (arrayOfType == null) { - arrayOfType = fromObjectClass(Array.newInstance(mirror(), 0).getClass()); - } - return arrayOfType; - } - - @Override - public ResolvedJavaType getComponentType() { - Class javaComponentType = mirror().getComponentType(); - return javaComponentType == null ? null : fromClass(javaComponentType); - } - - @Override - public AssumptionResult findLeafConcreteSubtype() { - HotSpotVMConfig config = runtime().getConfig(); - if (isArray()) { - return getElementalType().isFinal() ? new AssumptionResult<>(this) : null; - } else if (isInterface()) { - HotSpotResolvedObjectTypeImpl implementor = getSingleImplementor(); - /* - * If the implementor field contains itself that indicates that the interface has more - * than one implementors (see: InstanceKlass::add_implementor). - */ - if (implementor == null || implementor.equals(this)) { - return null; - } - - assert !implementor.isInterface(); - if (implementor.isAbstract() || !implementor.isLeafClass()) { - AssumptionResult leafConcreteSubtype = implementor.findLeafConcreteSubtype(); - if (leafConcreteSubtype != null) { - assert !leafConcreteSubtype.getResult().equals(implementor); - AssumptionResult newResult = new AssumptionResult<>(leafConcreteSubtype.getResult(), new ConcreteSubtype(this, implementor)); - // Accumulate leaf assumptions and return the combined result. - newResult.add(leafConcreteSubtype); - return newResult; - } - return null; - } - - return new AssumptionResult<>(implementor, new LeafType(implementor), new ConcreteSubtype(this, implementor)); - } else { - HotSpotResolvedObjectTypeImpl type = this; - while (type.isAbstract()) { - long subklass = type.getSubklass(); - if (subklass == 0 || unsafe.getAddress(subklass + config.nextSiblingOffset) != 0) { - return null; - } - type = fromMetaspaceKlass(subklass); - } - if (type.isAbstract() || type.isInterface() || !type.isLeafClass()) { - return null; - } - if (this.isAbstract()) { - return new AssumptionResult<>(type, new LeafType(type), new ConcreteSubtype(this, type)); - } else { - assert this.equals(type); - return new AssumptionResult<>(type, new LeafType(type)); - } - } - } - - /** - * Returns if type {@code type} is a leaf class. This is the case if the - * {@code Klass::_subklass} field of the underlying class is zero. - * - * @return true if the type is a leaf class - */ - private boolean isLeafClass() { - return getSubklass() == 0; - } - - /** - * Returns the {@code Klass::_subklass} field of the underlying metaspace klass for the given - * type {@code type}. - * - * @return value of the subklass field as metaspace klass pointer - */ - private long getSubklass() { - return unsafe.getAddress(getMetaspaceKlass() + runtime().getConfig().subklassOffset); - } - - @Override - public HotSpotResolvedObjectTypeImpl getSuperclass() { - Class javaSuperclass = mirror().getSuperclass(); - return javaSuperclass == null ? null : (HotSpotResolvedObjectTypeImpl) fromObjectClass(javaSuperclass); - } - - @Override - public HotSpotResolvedObjectTypeImpl[] getInterfaces() { - if (interfaces == null) { - Class[] javaInterfaces = mirror().getInterfaces(); - HotSpotResolvedObjectTypeImpl[] result = new HotSpotResolvedObjectTypeImpl[javaInterfaces.length]; - for (int i = 0; i < javaInterfaces.length; i++) { - result[i] = fromObjectClass(javaInterfaces[i]); - } - interfaces = result; - } - return interfaces; - } - - @Override - public HotSpotResolvedObjectTypeImpl getSingleImplementor() { - if (!isInterface()) { - throw new JVMCIError("Cannot call getSingleImplementor() on a non-interface type: %s", this); - } - final long implementorMetaspaceKlass = runtime().getCompilerToVM().getKlassImplementor(getMetaspaceKlass()); - - // No implementor. - if (implementorMetaspaceKlass == 0) { - return null; - } - - return fromMetaspaceKlass(implementorMetaspaceKlass); - } - - public HotSpotResolvedObjectTypeImpl getSupertype() { - if (isArray()) { - ResolvedJavaType componentType = getComponentType(); - if (mirror() == Object[].class || componentType.isPrimitive()) { - return fromObjectClass(Object.class); - } - return (HotSpotResolvedObjectTypeImpl) ((HotSpotResolvedObjectTypeImpl) componentType).getSupertype().getArrayClass(); - } - if (isInterface()) { - return fromObjectClass(Object.class); - } - return getSuperclass(); - } - - @Override - public HotSpotResolvedObjectType findLeastCommonAncestor(ResolvedJavaType otherType) { - if (otherType.isPrimitive()) { - return null; - } else { - HotSpotResolvedObjectTypeImpl t1 = this; - HotSpotResolvedObjectTypeImpl t2 = (HotSpotResolvedObjectTypeImpl) otherType; - while (true) { - if (t1.isAssignableFrom(t2)) { - return t1; - } - if (t2.isAssignableFrom(t1)) { - return t2; - } - t1 = t1.getSupertype(); - t2 = t2.getSupertype(); - } - } - } - - @Override - public HotSpotResolvedObjectType asExactType() { - if (isArray()) { - return getComponentType().asExactType() != null ? this : null; - } - return isFinal() ? this : null; - } - - @Override - public JavaConstant getJavaClass() { - return HotSpotObjectConstantImpl.forObject(mirror()); - } - - @Override - public JavaConstant getObjectHub() { - return klass(); - } - - @Override - public AssumptionResult hasFinalizableSubclass() { - assert !isArray(); - if (!runtime().getCompilerToVM().hasFinalizableSubclass(getMetaspaceKlass())) { - return new AssumptionResult<>(false, new NoFinalizableSubclass(this)); - } - return new AssumptionResult<>(true); - } - - @Override - public boolean hasFinalizer() { - HotSpotVMConfig config = runtime().getConfig(); - return (getAccessFlags() & config.klassHasFinalizerFlag) != 0; - } - - @Override - public boolean isPrimitive() { - return false; - } - - @Override - public boolean isArray() { - return mirror().isArray(); - } - - @Override - public boolean isInitialized() { - return isArray() ? true : getInitState() == runtime().getConfig().instanceKlassStateFullyInitialized; - } - - @Override - public boolean isLinked() { - return isArray() ? true : getInitState() >= runtime().getConfig().instanceKlassStateLinked; - } - - /** - * Returns the value of the state field {@code InstanceKlass::_init_state} of the metaspace - * klass. - * - * @return state field value of this type - */ - private int getInitState() { - assert !isArray() : "_init_state only exists in InstanceKlass"; - return unsafe.getByte(getMetaspaceKlass() + runtime().getConfig().instanceKlassInitStateOffset) & 0xFF; - } - - @Override - public void initialize() { - if (!isInitialized()) { - unsafe.ensureClassInitialized(mirror()); - assert isInitialized(); - } - } - - @Override - public boolean isInstance(JavaConstant obj) { - if (obj.getKind() == Kind.Object && !obj.isNull()) { - return mirror().isInstance(((HotSpotObjectConstantImpl) obj).object()); - } - return false; - } - - @Override - public boolean isInstanceClass() { - return !isArray() && !isInterface(); - } - - @Override - public boolean isInterface() { - return mirror().isInterface(); - } - - @Override - public boolean isAssignableFrom(ResolvedJavaType other) { - assert other != null; - if (other instanceof HotSpotResolvedObjectTypeImpl) { - HotSpotResolvedObjectTypeImpl otherType = (HotSpotResolvedObjectTypeImpl) other; - return mirror().isAssignableFrom(otherType.mirror()); - } - return false; - } - - @Override - public boolean isJavaLangObject() { - return javaClass.equals(Object.class); - } - - @Override - public Kind getKind() { - return Kind.Object; - } - - @Override - public ResolvedJavaMethod resolveConcreteMethod(ResolvedJavaMethod method, ResolvedJavaType callerType) { - ResolvedJavaMethod resolvedMethod = resolveMethod(method, callerType, true); - if (resolvedMethod == null || resolvedMethod.isAbstract()) { - return null; - } - return resolvedMethod; - } - - @Override - public ResolvedJavaMethod resolveMethod(ResolvedJavaMethod method, ResolvedJavaType callerType, boolean includeAbstract) { - if (!includeAbstract) { - return resolveConcreteMethod(method, callerType); - } - assert !callerType.isArray(); - if (method.isConcrete() && method.getDeclaringClass().equals(this) && method.isPublic()) { - return method; - } - if (!method.getDeclaringClass().isAssignableFrom(this)) { - return null; - } - HotSpotResolvedJavaMethodImpl hotSpotMethod = (HotSpotResolvedJavaMethodImpl) method; - HotSpotResolvedObjectTypeImpl hotSpotCallerType = (HotSpotResolvedObjectTypeImpl) callerType; - final long resolvedMetaspaceMethod = runtime().getCompilerToVM().resolveMethod(getMetaspaceKlass(), hotSpotMethod.getMetaspaceMethod(), hotSpotCallerType.getMetaspaceKlass()); - if (resolvedMetaspaceMethod == 0) { - return null; - } - return HotSpotResolvedJavaMethodImpl.fromMetaspace(resolvedMetaspaceMethod); - } - - public ConstantPool constantPool() { - if (constantPool == null) { - final long metaspaceConstantPool = unsafe.getAddress(getMetaspaceKlass() + runtime().getConfig().instanceKlassConstantsOffset); - constantPool = new HotSpotConstantPool(metaspaceConstantPool); - } - return constantPool; - } - - /** - * Gets the instance size of this type. If an instance of this type cannot be fast path - * allocated, then the returned value is negative (its absolute value gives the size). Must not - * be called if this is an array or interface type. - */ - public int instanceSize() { - assert !isArray(); - assert !isInterface(); - - HotSpotVMConfig config = runtime().getConfig(); - final int layoutHelper = unsafe.getInt(getMetaspaceKlass() + config.klassLayoutHelperOffset); - assert layoutHelper > config.klassLayoutHelperNeutralValue : "must be instance"; - - // See: Klass::layout_helper_size_in_bytes - int size = layoutHelper & ~config.klassLayoutHelperInstanceSlowPathBit; - - // See: Klass::layout_helper_needs_slow_path - boolean needsSlowPath = (layoutHelper & config.klassLayoutHelperInstanceSlowPathBit) != 0; - - return needsSlowPath ? -size : size; - } - - public synchronized HotSpotResolvedJavaMethod createMethod(long metaspaceMethod) { - HotSpotResolvedJavaMethod method = null; - if (methodCache == null) { - methodCache = new HashMap<>(8); - } else { - method = methodCache.get(metaspaceMethod); - } - if (method == null) { - method = new HotSpotResolvedJavaMethodImpl(this, metaspaceMethod); - methodCache.put(metaspaceMethod, method); - } - return method; - } - - public int getVtableLength() { - HotSpotVMConfig config = runtime().getConfig(); - if (isInterface() || isArray()) { - /* Everything has the core vtable of java.lang.Object */ - return config.baseVtableLength; - } - int result = unsafe.getInt(getMetaspaceKlass() + config.instanceKlassVtableLengthOffset) / (config.vtableEntrySize / config.heapWordSize); - assert result >= config.baseVtableLength : unsafe.getInt(getMetaspaceKlass() + config.instanceKlassVtableLengthOffset) + " " + config.vtableEntrySize; - return result; - } - - /** - * Gets the mask used to filter out HotSpot internal flags for fields when a {@link Field} - * object is created. This is the value of {@code JVM_RECOGNIZED_FIELD_MODIFIERS} in - * {@code jvm.h}, not {@link Modifier#fieldModifiers()}. - */ - public static int getReflectionFieldModifiers() { - return runtime().getConfig().recognizedFieldModifiers; - } - - public synchronized HotSpotResolvedJavaField createField(String fieldName, JavaType type, long offset, int rawFlags) { - HotSpotResolvedJavaField result = null; - - final int flags = rawFlags & getReflectionFieldModifiers(); - - final long id = offset + ((long) flags << 32); - - // (thomaswue) Must cache the fields, because the local load elimination only works if the - // objects from two field lookups are identical. - if (fieldCache == null) { - fieldCache = new HashMap<>(8); - } else { - result = fieldCache.get(id); - } - - if (result == null) { - result = new HotSpotResolvedJavaFieldImpl(this, fieldName, type, offset, rawFlags); - fieldCache.put(id, result); - } else { - assert result.getName().equals(fieldName); - // assert result.getType().equals(type); - assert result.offset() == offset; - assert result.getModifiers() == flags; - } - - return result; - } - - @Override - public AssumptionResult findUniqueConcreteMethod(ResolvedJavaMethod method) { - HotSpotResolvedJavaMethod hmethod = (HotSpotResolvedJavaMethod) method; - HotSpotResolvedObjectType declaredHolder = hmethod.getDeclaringClass(); - /* - * Sometimes the receiver type in the graph hasn't stabilized to a subtype of declared - * holder, usually because of phis, so make sure that the type is related to the declared - * type before using it for lookup. Unlinked types should also be ignored because we can't - * resolve the proper method to invoke. Generally unlinked types in invokes should result in - * a deopt instead since they can't really be used if they aren't linked yet. - */ - if (!declaredHolder.isAssignableFrom(this) || this.isArray() || this.equals(declaredHolder) || !isLinked() || isInterface()) { - ResolvedJavaMethod result = hmethod.uniqueConcreteMethod(declaredHolder); - if (result != null) { - return new AssumptionResult<>(result, new ConcreteMethod(method, declaredHolder, result)); - } - return null; - } - /* - * The holder may be a subtype of the declaredHolder so make sure to resolve the method to - * the correct method for the subtype. - */ - HotSpotResolvedJavaMethod resolvedMethod = (HotSpotResolvedJavaMethod) resolveMethod(hmethod, this, true); - if (resolvedMethod == null) { - // The type isn't known to implement the method. - return null; - } - - ResolvedJavaMethod result = resolvedMethod.uniqueConcreteMethod(this); - if (result != null) { - return new AssumptionResult<>(result, new ConcreteMethod(method, this, result)); - } - return null; - } - - /** - * This class represents the field information for one field contained in the fields array of an - * {@code InstanceKlass}. The implementation is similar to the native {@code FieldInfo} class. - */ - private class FieldInfo { - /** - * Native pointer into the array of Java shorts. - */ - private final long metaspaceData; - - /** - * Creates a field info for the field in the fields array at index {@code index}. - * - * @param index index to the fields array - */ - public FieldInfo(int index) { - HotSpotVMConfig config = runtime().getConfig(); - // Get Klass::_fields - final long metaspaceFields = unsafe.getAddress(getMetaspaceKlass() + config.instanceKlassFieldsOffset); - assert config.fieldInfoFieldSlots == 6 : "revisit the field parsing code"; - metaspaceData = metaspaceFields + config.arrayU2DataOffset + config.fieldInfoFieldSlots * Short.BYTES * index; - } - - private int getAccessFlags() { - return readFieldSlot(runtime().getConfig().fieldInfoAccessFlagsOffset); - } - - private int getNameIndex() { - return readFieldSlot(runtime().getConfig().fieldInfoNameIndexOffset); - } - - private int getSignatureIndex() { - return readFieldSlot(runtime().getConfig().fieldInfoSignatureIndexOffset); - } - - public int getOffset() { - HotSpotVMConfig config = runtime().getConfig(); - final int lowPacked = readFieldSlot(config.fieldInfoLowPackedOffset); - final int highPacked = readFieldSlot(config.fieldInfoHighPackedOffset); - final int offset = ((highPacked << Short.SIZE) | lowPacked) >> config.fieldInfoTagSize; - return offset; - } - - /** - * Helper method to read an entry (slot) from the field array. Currently field info is laid - * on top an array of Java shorts. - */ - private int readFieldSlot(int index) { - return unsafe.getChar(metaspaceData + Short.BYTES * index); - } - - /** - * Returns the name of this field as a {@link String}. If the field is an internal field the - * name index is pointing into the vmSymbols table. - */ - public String getName() { - final int nameIndex = getNameIndex(); - return isInternal() ? HotSpotVmSymbols.symbolAt(nameIndex) : constantPool().lookupUtf8(nameIndex); - } - - /** - * Returns the signature of this field as {@link String}. If the field is an internal field - * the signature index is pointing into the vmSymbols table. - */ - public String getSignature() { - final int signatureIndex = getSignatureIndex(); - return isInternal() ? HotSpotVmSymbols.symbolAt(signatureIndex) : constantPool().lookupUtf8(signatureIndex); - } - - public JavaType getType() { - String signature = getSignature(); - return runtime().lookupType(signature, HotSpotResolvedObjectTypeImpl.this, false); - } - - private boolean isInternal() { - return (getAccessFlags() & runtime().getConfig().jvmAccFieldInternal) != 0; - } - - public boolean isStatic() { - return Modifier.isStatic(getAccessFlags()); - } - - public boolean hasGenericSignature() { - return (getAccessFlags() & runtime().getConfig().jvmAccFieldHasGenericSignature) != 0; - } - } - - private static class OffsetComparator implements java.util.Comparator { - @Override - public int compare(HotSpotResolvedJavaField o1, HotSpotResolvedJavaField o2) { - return o1.offset() - o2.offset(); - } - } - - @Override - public ResolvedJavaField[] getInstanceFields(boolean includeSuperclasses) { - if (instanceFields == null) { - if (isArray() || isInterface()) { - instanceFields = new HotSpotResolvedJavaField[0]; - } else { - final int fieldCount = getFieldCount(); - ArrayList fieldsArray = new ArrayList<>(fieldCount); - - for (int i = 0; i < fieldCount; i++) { - FieldInfo field = new FieldInfo(i); - - // We are only interested in instance fields. - if (!field.isStatic()) { - HotSpotResolvedJavaField resolvedJavaField = createField(field.getName(), field.getType(), field.getOffset(), field.getAccessFlags()); - fieldsArray.add(resolvedJavaField); - } - } - - fieldsArray.sort(new OffsetComparator()); - - HotSpotResolvedJavaField[] myFields = fieldsArray.toArray(new HotSpotResolvedJavaField[0]); - - if (mirror() != Object.class) { - HotSpotResolvedJavaField[] superFields = (HotSpotResolvedJavaField[]) getSuperclass().getInstanceFields(true); - HotSpotResolvedJavaField[] fields = Arrays.copyOf(superFields, superFields.length + myFields.length); - System.arraycopy(myFields, 0, fields, superFields.length, myFields.length); - instanceFields = fields; - } else { - assert myFields.length == 0 : "java.lang.Object has fields!"; - instanceFields = myFields; - } - - } - } - if (!includeSuperclasses) { - int myFieldsStart = 0; - while (myFieldsStart < instanceFields.length && !instanceFields[myFieldsStart].getDeclaringClass().equals(this)) { - myFieldsStart++; - } - if (myFieldsStart == 0) { - return instanceFields; - } - if (myFieldsStart == instanceFields.length) { - return new HotSpotResolvedJavaField[0]; - } - return Arrays.copyOfRange(instanceFields, myFieldsStart, instanceFields.length); - } - return instanceFields; - } - - @Override - public ResolvedJavaField[] getStaticFields() { - if (isArray()) { - return new HotSpotResolvedJavaField[0]; - } else { - final int fieldCount = getFieldCount(); - ArrayList fieldsArray = new ArrayList<>(fieldCount); - - for (int i = 0; i < fieldCount; i++) { - FieldInfo field = new FieldInfo(i); - - // We are only interested in static fields. - if (field.isStatic()) { - HotSpotResolvedJavaField resolvedJavaField = createField(field.getName(), field.getType(), field.getOffset(), field.getAccessFlags()); - fieldsArray.add(resolvedJavaField); - } - } - - fieldsArray.sort(new OffsetComparator()); - return fieldsArray.toArray(new HotSpotResolvedJavaField[fieldsArray.size()]); - } - } - - /** - * Returns the actual field count of this class's internal {@code InstanceKlass::_fields} array - * by walking the array and discounting the generic signature slots at the end of the array. - * - *

- * See {@code FieldStreamBase::init_generic_signature_start_slot} - */ - private int getFieldCount() { - HotSpotVMConfig config = runtime().getConfig(); - final long metaspaceFields = unsafe.getAddress(getMetaspaceKlass() + config.instanceKlassFieldsOffset); - int metaspaceFieldsLength = unsafe.getInt(metaspaceFields + config.arrayU1LengthOffset); - int fieldCount = 0; - - for (int i = 0, index = 0; i < metaspaceFieldsLength; i += config.fieldInfoFieldSlots, index++) { - FieldInfo field = new FieldInfo(index); - if (field.hasGenericSignature()) { - metaspaceFieldsLength--; - } - fieldCount++; - } - return fieldCount; - } - - @Override - public Class mirror() { - return javaClass; - } - - @Override - public String getSourceFileName() { - HotSpotVMConfig config = runtime().getConfig(); - final int sourceFileNameIndex = unsafe.getChar(getMetaspaceKlass() + config.instanceKlassSourceFileNameIndexOffset); - if (sourceFileNameIndex == 0) { - return null; - } - return constantPool().lookupUtf8(sourceFileNameIndex); - } - - @Override - public T getAnnotation(Class annotationClass) { - return mirror().getAnnotation(annotationClass); - } - - /** - * Performs a fast-path check that this type is resolved in the context of a given accessing - * class. A negative result does not mean this type is not resolved with respect to - * {@code accessingClass}. That can only be determined by - * {@linkplain HotSpotJVMCIRuntime#lookupType(String, HotSpotResolvedObjectType, boolean) - * re-resolving} the type. - */ - public boolean isDefinitelyResolvedWithRespectTo(ResolvedJavaType accessingClass) { - assert accessingClass != null; - ResolvedJavaType elementType = getElementalType(); - if (elementType.isPrimitive()) { - // Primitive type resolution is context free. - return true; - } - if (elementType.getName().startsWith("Ljava/")) { - // Classes in a java.* package can only be defined by the - // boot class loader. This is enforced by ClassLoader.preDefineClass() - assert mirror().getClassLoader() == null; - return true; - } - ClassLoader thisCl = mirror().getClassLoader(); - ClassLoader accessingClassCl = ((HotSpotResolvedObjectTypeImpl) accessingClass).mirror().getClassLoader(); - return thisCl == accessingClassCl; - } - - @Override - public ResolvedJavaType resolve(ResolvedJavaType accessingClass) { - if (isDefinitelyResolvedWithRespectTo(requireNonNull(accessingClass))) { - return this; - } - HotSpotResolvedObjectTypeImpl accessingType = (HotSpotResolvedObjectTypeImpl) accessingClass; - return (ResolvedJavaType) runtime().lookupType(getName(), accessingType, true); - } - - /** - * Gets the metaspace Klass boxed in a {@link JavaConstant}. - */ - public JavaConstant klass() { - return HotSpotMetaspaceConstantImpl.forMetaspaceObject(runtime().getHostJVMCIBackend().getTarget().wordKind, getMetaspaceKlass(), this, false); - } - - public boolean isPrimaryType() { - return runtime().getConfig().secondarySuperCacheOffset != superCheckOffset(); - } - - public int superCheckOffset() { - HotSpotVMConfig config = runtime().getConfig(); - return unsafe.getInt(getMetaspaceKlass() + config.superCheckOffsetOffset); - } - - public long prototypeMarkWord() { - HotSpotVMConfig config = runtime().getConfig(); - if (isArray()) { - return config.arrayPrototypeMarkWord(); - } else { - return unsafe.getAddress(getMetaspaceKlass() + config.prototypeMarkWordOffset); - } - } - - @Override - public ResolvedJavaField findInstanceFieldWithOffset(long offset, Kind expectedEntryKind) { - ResolvedJavaField[] declaredFields = getInstanceFields(true); - for (ResolvedJavaField field : declaredFields) { - HotSpotResolvedJavaField resolvedField = (HotSpotResolvedJavaField) field; - long resolvedFieldOffset = resolvedField.offset(); - // @formatter:off - if (ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN && - expectedEntryKind.isPrimitive() && - !expectedEntryKind.equals(Kind.Void) && - resolvedField.getKind().isPrimitive()) { - resolvedFieldOffset += - resolvedField.getKind().getByteCount() - - Math.min(resolvedField.getKind().getByteCount(), 4 + expectedEntryKind.getByteCount()); - } - if (resolvedFieldOffset == offset) { - return field; - } - // @formatter:on - } - return null; - } - - @Override - public URL getClassFilePath() { - Class cls = mirror(); - return cls.getResource(MetaUtil.getSimpleName(cls, true).replace('.', '$') + ".class"); - } - - @Override - public boolean isLocal() { - return mirror().isLocalClass(); - } - - @Override - public boolean isMember() { - return mirror().isMemberClass(); - } - - @Override - public HotSpotResolvedObjectTypeImpl getEnclosingType() { - final Class encl = mirror().getEnclosingClass(); - return encl == null ? null : fromObjectClass(encl); - } - - @Override - public ResolvedJavaMethod[] getDeclaredConstructors() { - Constructor[] constructors = mirror().getDeclaredConstructors(); - ResolvedJavaMethod[] result = new ResolvedJavaMethod[constructors.length]; - for (int i = 0; i < constructors.length; i++) { - result[i] = runtime().getHostJVMCIBackend().getMetaAccess().lookupJavaMethod(constructors[i]); - assert result[i].isConstructor(); - } - return result; - } - - @Override - public ResolvedJavaMethod[] getDeclaredMethods() { - Method[] methods = mirror().getDeclaredMethods(); - ResolvedJavaMethod[] result = new ResolvedJavaMethod[methods.length]; - for (int i = 0; i < methods.length; i++) { - result[i] = runtime().getHostJVMCIBackend().getMetaAccess().lookupJavaMethod(methods[i]); - assert !result[i].isConstructor(); - } - return result; - } - - public ResolvedJavaMethod getClassInitializer() { - final long metaspaceMethod = runtime().getCompilerToVM().getClassInitializer(getMetaspaceKlass()); - if (metaspaceMethod != 0L) { - return createMethod(metaspaceMethod); - } - return null; - } - - @Override - public String toString() { - return "HotSpotType<" + getName() + ", resolved>"; - } - - @Override - public boolean isTrustedInterfaceType() { - return TrustedInterface.class.isAssignableFrom(mirror()); - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotResolvedPrimitiveType.java --- a/graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotResolvedPrimitiveType.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,280 +0,0 @@ -/* - * Copyright (c) 2011, 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 static java.util.Objects.*; - -import java.lang.annotation.*; -import java.lang.reflect.*; -import java.net.*; - -import com.oracle.jvmci.common.*; -import com.oracle.jvmci.meta.Assumptions.AssumptionResult; -import com.oracle.jvmci.meta.*; - -/** - * Implementation of {@link JavaType} for primitive HotSpot types. - */ -public final class HotSpotResolvedPrimitiveType extends HotSpotResolvedJavaType implements HotSpotProxified { - - private final Kind kind; - - /** - * Creates the JVMCI mirror for a primitive {@link Kind}. - * - *

- * NOTE: Creating an instance of this class does not install the mirror for the - * {@link Class} type. Use {@link #fromClass(Class)} instead. - *

- * - * @param kind the Kind to create the mirror for - */ - public HotSpotResolvedPrimitiveType(Kind kind) { - super(String.valueOf(Character.toUpperCase(kind.getTypeChar()))); - this.kind = kind; - assert mirror().isPrimitive() : mirror() + " not a primitive type"; - } - - @Override - public int getModifiers() { - return Modifier.ABSTRACT | Modifier.FINAL | Modifier.PUBLIC; - } - - @Override - public HotSpotResolvedObjectTypeImpl getArrayClass() { - if (kind == Kind.Void) { - return null; - } - Class javaArrayMirror = Array.newInstance(mirror(), 0).getClass(); - return HotSpotResolvedObjectTypeImpl.fromObjectClass(javaArrayMirror); - } - - public ResolvedJavaType getElementalType() { - return this; - } - - @Override - public ResolvedJavaType getComponentType() { - return null; - } - - @Override - public ResolvedJavaType asExactType() { - return this; - } - - @Override - public ResolvedJavaType getSuperclass() { - return null; - } - - @Override - public ResolvedJavaType[] getInterfaces() { - return new ResolvedJavaType[0]; - } - - @Override - public ResolvedJavaType getSingleImplementor() { - throw new JVMCIError("Cannot call getSingleImplementor() on a non-interface type: %s", this); - } - - @Override - public ResolvedJavaType findLeastCommonAncestor(ResolvedJavaType otherType) { - return null; - } - - @Override - public JavaConstant getObjectHub() { - throw JVMCIError.unimplemented(); - } - - @Override - public JavaConstant getJavaClass() { - throw JVMCIError.unimplemented(); - } - - @Override - public AssumptionResult hasFinalizableSubclass() { - return new AssumptionResult<>(false); - } - - @Override - public boolean hasFinalizer() { - return false; - } - - @Override - public boolean isArray() { - return false; - } - - @Override - public boolean isPrimitive() { - return true; - } - - @Override - public boolean isInitialized() { - return true; - } - - public boolean isLinked() { - return true; - } - - @Override - public boolean isInstance(JavaConstant obj) { - return false; - } - - @Override - public boolean isInstanceClass() { - return false; - } - - @Override - public boolean isInterface() { - return false; - } - - @Override - public boolean isAssignableFrom(ResolvedJavaType other) { - assert other != null; - return other.equals(this); - } - - @Override - public Kind getKind() { - return kind; - } - - @Override - public boolean isJavaLangObject() { - return false; - } - - @Override - public ResolvedJavaMethod resolveConcreteMethod(ResolvedJavaMethod method, ResolvedJavaType callerType) { - return null; - } - - @Override - public ResolvedJavaMethod resolveMethod(ResolvedJavaMethod method, ResolvedJavaType callerType, boolean includeAbstract) { - return null; - } - - @Override - public String toString() { - return "HotSpotResolvedPrimitiveType<" + kind + ">"; - } - - @Override - public AssumptionResult findLeafConcreteSubtype() { - return new AssumptionResult<>(this); - } - - @Override - public AssumptionResult findUniqueConcreteMethod(ResolvedJavaMethod method) { - return null; - } - - @Override - public ResolvedJavaField[] getInstanceFields(boolean includeSuperclasses) { - return new ResolvedJavaField[0]; - } - - @Override - public ResolvedJavaField[] getStaticFields() { - return new ResolvedJavaField[0]; - } - - @Override - public T getAnnotation(Class annotationClass) { - return null; - } - - @Override - public ResolvedJavaType resolve(ResolvedJavaType accessingClass) { - requireNonNull(accessingClass); - return this; - } - - @Override - public void initialize() { - } - - @Override - public ResolvedJavaField findInstanceFieldWithOffset(long offset, Kind expectedType) { - return null; - } - - @Override - public String getSourceFileName() { - throw JVMCIError.unimplemented(); - } - - @Override - public Class mirror() { - return kind.toJavaClass(); - } - - @Override - public URL getClassFilePath() { - return null; - } - - @Override - public boolean isLocal() { - return false; - } - - @Override - public boolean isMember() { - return false; - } - - @Override - public ResolvedJavaType getEnclosingType() { - return null; - } - - @Override - public ResolvedJavaMethod[] getDeclaredConstructors() { - return new ResolvedJavaMethod[0]; - } - - @Override - public ResolvedJavaMethod[] getDeclaredMethods() { - return new ResolvedJavaMethod[0]; - } - - @Override - public ResolvedJavaMethod getClassInitializer() { - return null; - } - - @Override - public boolean isTrustedInterfaceType() { - return false; - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotSignature.java --- a/graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotSignature.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,212 +0,0 @@ -/* - * Copyright (c) 2011, 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; - -import java.util.*; - -import com.oracle.jvmci.common.*; -import com.oracle.jvmci.meta.*; - -/** - * Represents a method signature. - */ -public class HotSpotSignature implements Signature { - - private final List parameters = new ArrayList<>(); - private final String returnType; - private final String originalString; - private ResolvedJavaType[] parameterTypes; - private ResolvedJavaType returnTypeCache; - private final HotSpotJVMCIRuntimeProvider runtime; - - public HotSpotSignature(HotSpotJVMCIRuntimeProvider runtime, String signature) { - this.runtime = runtime; - assert signature.length() > 0; - this.originalString = signature; - - if (signature.charAt(0) == '(') { - int cur = 1; - while (cur < signature.length() && signature.charAt(cur) != ')') { - int nextCur = parseSignature(signature, cur); - parameters.add(signature.substring(cur, nextCur)); - cur = nextCur; - } - - cur++; - int nextCur = parseSignature(signature, cur); - returnType = signature.substring(cur, nextCur); - assert nextCur == signature.length(); - } else { - returnType = null; - } - } - - public HotSpotSignature(HotSpotJVMCIRuntimeProvider runtime, ResolvedJavaType returnType, ResolvedJavaType... parameterTypes) { - this.runtime = runtime; - this.parameterTypes = parameterTypes.clone(); - this.returnTypeCache = returnType; - this.returnType = returnType.getName(); - StringBuilder sb = new StringBuilder("("); - for (JavaType type : parameterTypes) { - parameters.add(type.getName()); - sb.append(type.getName()); - } - sb.append(")").append(returnType.getName()); - this.originalString = sb.toString(); - assert new HotSpotSignature(runtime, originalString).equals(this); - } - - private static int parseSignature(String signature, int start) { - int cur = start; - char first; - do { - first = signature.charAt(cur++); - } while (first == '['); - - switch (first) { - case 'L': - while (signature.charAt(cur) != ';') { - cur++; - } - cur++; - break; - case 'V': - case 'I': - case 'B': - case 'C': - case 'D': - case 'F': - case 'J': - case 'S': - case 'Z': - break; - default: - throw new JVMCIError("Invalid character at index %d in signature: %s", cur, signature); - } - return cur; - } - - @Override - public int getParameterCount(boolean withReceiver) { - return parameters.size() + (withReceiver ? 1 : 0); - } - - @Override - public Kind getParameterKind(int index) { - return Kind.fromTypeString(parameters.get(index)); - } - - private static boolean checkValidCache(ResolvedJavaType type, ResolvedJavaType accessingClass) { - assert accessingClass != null; - if (type == null) { - return false; - } else if (type instanceof HotSpotResolvedObjectTypeImpl) { - return ((HotSpotResolvedObjectTypeImpl) type).isDefinitelyResolvedWithRespectTo(accessingClass); - } - return true; - } - - private static JavaType getUnresolvedOrPrimitiveType(HotSpotJVMCIRuntimeProvider runtime, String name) { - if (name.length() == 1) { - Kind kind = Kind.fromPrimitiveOrVoidTypeChar(name.charAt(0)); - return runtime.getHostJVMCIBackend().getMetaAccess().lookupJavaType(kind.toJavaClass()); - } - return new HotSpotUnresolvedJavaType(name, runtime); - } - - @Override - public JavaType getParameterType(int index, ResolvedJavaType accessingClass) { - if (accessingClass == null) { - // Caller doesn't care about resolution context so return an unresolved - // or primitive type (primitive type resolution is context free) - return getUnresolvedOrPrimitiveType(runtime, parameters.get(index)); - } - if (parameterTypes == null) { - parameterTypes = new ResolvedJavaType[parameters.size()]; - } - - ResolvedJavaType type = parameterTypes[index]; - if (!checkValidCache(type, accessingClass)) { - JavaType result = runtime.lookupType(parameters.get(index), (HotSpotResolvedObjectType) accessingClass, false); - if (result instanceof ResolvedJavaType) { - type = (ResolvedJavaType) result; - parameterTypes[index] = type; - } else { - return result; - } - } - return type; - } - - @Override - public String toMethodDescriptor() { - assert originalString.equals(Signature.super.toMethodDescriptor()); - return originalString; - } - - @Override - public Kind getReturnKind() { - return Kind.fromTypeString(returnType); - } - - @Override - public JavaType getReturnType(ResolvedJavaType accessingClass) { - if (accessingClass == null) { - // Caller doesn't care about resolution context so return an unresolved - // or primitive type (primitive type resolution is context free) - return getUnresolvedOrPrimitiveType(runtime, returnType); - } - if (!checkValidCache(returnTypeCache, accessingClass)) { - JavaType result = runtime.lookupType(returnType, (HotSpotResolvedObjectType) accessingClass, false); - if (result instanceof ResolvedJavaType) { - returnTypeCache = (ResolvedJavaType) result; - } else { - return result; - } - } - return returnTypeCache; - } - - @Override - public String toString() { - return "HotSpotSignature<" + originalString + ">"; - } - - @Override - public boolean equals(Object obj) { - if (obj instanceof HotSpotSignature) { - HotSpotSignature other = (HotSpotSignature) obj; - if (other.originalString.equals(originalString)) { - assert other.parameters.equals(parameters); - assert other.returnType.equals(returnType); - return true; - } - } - return false; - } - - @Override - public int hashCode() { - return originalString.hashCode(); - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotSpeculationLog.java --- a/graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotSpeculationLog.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,34 +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.hotspot; - -import com.oracle.jvmci.meta.*; - -public class HotSpotSpeculationLog extends SpeculationLog { - - @Override - public JavaConstant speculate(Object reason) { - addSpeculation(reason); - return HotSpotObjectConstantImpl.forObject(reason); - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotStackFrameReference.java --- a/graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotStackFrameReference.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,92 +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.jvmci.hotspot; - -import java.util.*; - -import com.oracle.jvmci.code.stack.*; -import com.oracle.jvmci.meta.*; - -public class HotSpotStackFrameReference implements InspectedFrame { - - private CompilerToVM compilerToVM; - - // information used to find the stack frame - private long stackPointer; - private int frameNumber; - - // information about the stack frame's contents - private int bci; - private long metaspaceMethod; - private Object[] locals; - private boolean[] localIsVirtual; - - public long getStackPointer() { - return stackPointer; - } - - public int getFrameNumber() { - return frameNumber; - } - - @Override - public Object getLocal(int index) { - return locals[index]; - } - - @Override - public boolean isVirtual(int index) { - return localIsVirtual == null ? false : localIsVirtual[index]; - } - - @Override - public void materializeVirtualObjects(boolean invalidateCode) { - compilerToVM.materializeVirtualObjects(this, invalidateCode); - } - - @Override - public int getBytecodeIndex() { - return bci; - } - - @Override - public ResolvedJavaMethod getMethod() { - return HotSpotResolvedJavaMethodImpl.fromMetaspace(metaspaceMethod); - } - - @Override - public boolean isMethod(ResolvedJavaMethod method) { - return metaspaceMethod == ((HotSpotResolvedJavaMethodImpl) method).getMetaspaceMethod(); - } - - @Override - public boolean hasVirtualObjects() { - return localIsVirtual != null; - } - - @Override - public String toString() { - return "HotSpotStackFrameReference [stackPointer=" + stackPointer + ", frameNumber=" + frameNumber + ", bci=" + bci + ", method=" + getMethod() + ", locals=" + Arrays.toString(locals) + - ", localIsVirtual=" + Arrays.toString(localIsVirtual) + "]"; - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotTargetDescription.java --- a/graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotTargetDescription.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,37 +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.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 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotUnresolvedField.java --- a/graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotUnresolvedField.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,78 +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 com.oracle.jvmci.meta.*; - -/** - * A implementation of {@link JavaField} for an unresolved field. - */ -public class HotSpotUnresolvedField implements JavaField { - - private final String name; - private final JavaType holder; - private final JavaType type; - - public HotSpotUnresolvedField(JavaType holder, String name, JavaType type) { - this.name = name; - this.type = type; - this.holder = holder; - } - - public String getName() { - return name; - } - - public JavaType getType() { - return type; - } - - public JavaType getDeclaringClass() { - return holder; - } - - @Override - public int hashCode() { - return super.hashCode(); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null || !(obj instanceof HotSpotUnresolvedField)) { - return false; - } - HotSpotUnresolvedField that = (HotSpotUnresolvedField) obj; - return this.holder.equals(that.holder) && this.name.equals(that.name) && this.type.equals(that.type); - } - - /** - * Converts this compiler interface field to a string. - */ - @Override - public String toString() { - return format("HotSpotField<%H.%n %t, unresolved>"); - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotUnresolvedJavaType.java --- a/graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotUnresolvedJavaType.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,103 +0,0 @@ -/* - * Copyright (c) 2011, 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; - -import com.oracle.jvmci.meta.*; - -/** - * Implementation of {@link JavaType} for unresolved HotSpot classes. - */ -public class HotSpotUnresolvedJavaType extends HotSpotJavaType { - - private final HotSpotJVMCIRuntimeProvider runtime; - - public HotSpotUnresolvedJavaType(String name, HotSpotJVMCIRuntimeProvider runtime) { - super(name); - assert name.charAt(0) == '[' || name.charAt(name.length() - 1) == ';' : name; - this.runtime = runtime; - } - - /** - * Creates an unresolved type for a valid {@link JavaType#getName() type name}. - */ - public static HotSpotUnresolvedJavaType create(HotSpotJVMCIRuntimeProvider runtime, String name) { - return new HotSpotUnresolvedJavaType(name, runtime); - } - - @Override - public JavaType getComponentType() { - assert getName().charAt(0) == '[' : "no array class" + getName(); - return new HotSpotUnresolvedJavaType(getName().substring(1), runtime); - } - - @Override - public JavaType getArrayClass() { - return new HotSpotUnresolvedJavaType('[' + getName(), runtime); - } - - @Override - public Kind getKind() { - return Kind.Object; - } - - @Override - public int hashCode() { - return getName().hashCode(); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null || !(obj instanceof HotSpotUnresolvedJavaType)) { - return false; - } - HotSpotUnresolvedJavaType that = (HotSpotUnresolvedJavaType) obj; - return this.getName().equals(that.getName()); - } - - @Override - public String toString() { - return "HotSpotType<" + getName() + ", unresolved>"; - } - - @Override - public ResolvedJavaType resolve(ResolvedJavaType accessingClass) { - return (ResolvedJavaType) runtime.lookupType(getName(), (HotSpotResolvedObjectType) accessingClass, true); - } - - /** - * Try to find a loaded version of this class. - * - * @param accessingClass - * @return the resolved class or null. - */ - ResolvedJavaType reresolve(HotSpotResolvedObjectType accessingClass) { - JavaType type = runtime.lookupType(getName(), accessingClass, false); - if (type instanceof ResolvedJavaType) { - return (ResolvedJavaType) type; - } - return null; - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotVMConfig.java --- a/graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotVMConfig.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1663 +0,0 @@ -/* - * Copyright (c) 2011, 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; - -import static com.oracle.jvmci.common.UnsafeAccess.*; - -import java.lang.reflect.*; -import java.util.*; - -import com.oracle.jvmci.common.*; -import com.oracle.jvmci.hotspotvmconfig.*; - -//JaCoCo Exclude - -/** - * Used to access native configuration details. - * - * All non-static, public fields in this class are so that they can be compiled as constants. - */ -public class HotSpotVMConfig { - - /** - * Determines if the current architecture is included in a given architecture set specification. - * - * @param currentArch - * @param archsSpecification specifies a set of architectures. A zero length value implies all - * architectures. - */ - private static boolean isRequired(String currentArch, String[] archsSpecification) { - if (archsSpecification.length == 0) { - return true; - } - for (String arch : archsSpecification) { - if (arch.equals(currentArch)) { - return true; - } - } - return false; - } - - /** - * Maximum allowed size of allocated area for a frame. - */ - public final int maxFrameSize = 16 * 1024; - - @Override - public String toString() { - return getClass().getSimpleName(); - } - - public HotSpotVMConfig(CompilerToVM compilerToVm) { - compilerToVm.initializeConfiguration(this); - assert verifyInitialization(); - - oopEncoding = new CompressEncoding(narrowOopBase, narrowOopShift, logMinObjAlignment()); - klassEncoding = new CompressEncoding(narrowKlassBase, narrowKlassShift, logKlassAlignment); - - codeCacheLowBoundary = unsafe.getAddress(codeCacheHeap + codeHeapMemoryOffset + virtualSpaceLowBoundaryOffset); - codeCacheHighBoundary = unsafe.getAddress(codeCacheHeap + codeHeapMemoryOffset + virtualSpaceHighBoundaryOffset); - - final long barrierSetAddress = unsafe.getAddress(universeCollectedHeap + collectedHeapBarrierSetOffset); - final int kind = unsafe.getInt(barrierSetAddress + barrierSetKindOffset); - if ((kind == barrierSetCardTableModRef) || (kind == barrierSetCardTableExtension) || (kind == barrierSetG1SATBCT) || (kind == barrierSetG1SATBCTLogging)) { - final long base = unsafe.getAddress(barrierSetAddress + cardTableModRefBSByteMapBaseOffset); - assert base != 0 : "unexpected byte_map_base: " + base; - cardtableStartAddress = base; - cardtableShift = cardTableModRefBSCardShift; - } else if ((kind == barrierSetModRef) || (kind == barrierSetOther)) { - // No post barriers - cardtableStartAddress = 0; - cardtableShift = 0; - } else { - cardtableStartAddress = -1; - cardtableShift = -1; - } - - inlineCacheMissStub = inlineCacheMissBlob + unsafe.getInt(inlineCacheMissBlob + codeBlobCodeOffsetOffset); - - assert check(); - assert HotSpotVMConfigVerifier.check(); - } - - /** - * Check that the initialization produces the same result as the values captured through - * vmStructs. - */ - private boolean verifyInitialization() { - /** These fields are set in {@link CompilerToVM#initializeConfiguration}. */ - assert gHotSpotVMStructs != 0; - assert gHotSpotVMTypes != 0; - assert gHotSpotVMIntConstants != 0; - assert gHotSpotVMLongConstants != 0; - - // Fill the VM fields hash map. - HashMap vmFields = new HashMap<>(); - for (VMFields.Field e : new VMFields(gHotSpotVMStructs)) { - vmFields.put(e.getName(), e); - } - - // Fill the VM types hash map. - HashMap vmTypes = new HashMap<>(); - for (VMTypes.Type e : new VMTypes(gHotSpotVMTypes)) { - vmTypes.put(e.getTypeName(), e); - } - - // Fill the VM constants hash map. - HashMap vmConstants = new HashMap<>(); - for (AbstractConstant e : new VMIntConstants(gHotSpotVMIntConstants)) { - vmConstants.put(e.getName(), e); - } - for (AbstractConstant e : new VMLongConstants(gHotSpotVMLongConstants)) { - vmConstants.put(e.getName(), e); - } - - // Fill the flags hash map. - HashMap flags = new HashMap<>(); - for (Flags.Flag e : new Flags(vmFields, vmTypes)) { - flags.put(e.getName(), e); - } - - String currentArch = getHostArchitectureName(); - - for (Field f : HotSpotVMConfig.class.getDeclaredFields()) { - if (f.isAnnotationPresent(HotSpotVMField.class)) { - HotSpotVMField annotation = f.getAnnotation(HotSpotVMField.class); - String name = annotation.name(); - String type = annotation.type(); - VMFields.Field entry = vmFields.get(name); - if (entry == null) { - if (!isRequired(currentArch, annotation.archs())) { - continue; - } - throw new IllegalArgumentException("field not found: " + name); - } - - // Make sure the native type is still the type we expect. - if (!type.equals("")) { - if (!type.equals(entry.getTypeString())) { - throw new IllegalArgumentException("compiler expects type " + type + " but field " + name + " is of type " + entry.getTypeString()); - } - } - - switch (annotation.get()) { - case OFFSET: - checkField(f, entry.getOffset()); - break; - case ADDRESS: - checkField(f, entry.getAddress()); - break; - case VALUE: - checkField(f, entry.getValue()); - break; - default: - throw new JVMCIError("unknown kind %s", annotation.get()); - } - } else if (f.isAnnotationPresent(HotSpotVMType.class)) { - HotSpotVMType annotation = f.getAnnotation(HotSpotVMType.class); - String name = annotation.name(); - VMTypes.Type entry = vmTypes.get(name); - if (entry == null) { - throw new IllegalArgumentException("type not found: " + name); - } - switch (annotation.get()) { - case SIZE: - checkField(f, entry.getSize()); - break; - default: - throw new JVMCIError("unknown kind %s", annotation.get()); - } - } else if (f.isAnnotationPresent(HotSpotVMConstant.class)) { - HotSpotVMConstant annotation = f.getAnnotation(HotSpotVMConstant.class); - String name = annotation.name(); - AbstractConstant entry = vmConstants.get(name); - if (entry == null) { - if (!isRequired(currentArch, annotation.archs())) { - continue; - } - throw new IllegalArgumentException("constant not found: " + name); - } - checkField(f, entry.getValue()); - } else if (f.isAnnotationPresent(HotSpotVMFlag.class)) { - HotSpotVMFlag annotation = f.getAnnotation(HotSpotVMFlag.class); - String name = annotation.name(); - Flags.Flag entry = flags.get(name); - if (entry == null) { - if (annotation.optional() || !isRequired(currentArch, annotation.archs())) { - continue; - } - throw new IllegalArgumentException("flag not found: " + name); - - } - checkField(f, entry.getValue()); - } - } - return true; - } - - private final CompressEncoding oopEncoding; - private final CompressEncoding klassEncoding; - - public CompressEncoding getOopEncoding() { - return oopEncoding; - } - - public CompressEncoding getKlassEncoding() { - return klassEncoding; - } - - private void checkField(Field field, Object value) { - try { - Class fieldType = field.getType(); - if (fieldType == boolean.class) { - if (value instanceof String) { - assert field.getBoolean(this) == Boolean.valueOf((String) value) : field + " " + value + " " + field.getBoolean(this); - } else if (value instanceof Boolean) { - assert field.getBoolean(this) == (boolean) value : field + " " + value + " " + field.getBoolean(this); - } else if (value instanceof Long) { - assert field.getBoolean(this) == (((long) value) != 0) : field + " " + value + " " + field.getBoolean(this); - } else { - throw new JVMCIError(value.getClass().getSimpleName()); - } - } else if (fieldType == int.class) { - if (value instanceof Integer) { - assert field.getInt(this) == (int) value : field + " " + value + " " + field.getInt(this); - } else if (value instanceof Long) { - assert field.getInt(this) == (int) (long) value : field + " " + value + " " + field.getInt(this); - } else { - throw new JVMCIError(value.getClass().getSimpleName()); - } - } else if (fieldType == long.class) { - assert field.getLong(this) == (long) value : field + " " + value + " " + field.getLong(this); - } else { - throw new JVMCIError(field.toString()); - } - } catch (IllegalAccessException e) { - throw new JVMCIError("%s: %s", field, e); - } - } - - /** - * Gets the host architecture name for the purpose of finding the corresponding - * {@linkplain HotSpotJVMCIBackendFactory backend}. - */ - public String getHostArchitectureName() { - String arch = System.getProperty("os.arch"); - switch (arch) { - case "x86_64": - arch = "amd64"; - break; - case "sparcv9": - arch = "sparc"; - break; - } - return arch; - } - - /** - * VMStructEntry (see vmStructs.hpp). - */ - @HotSpotVMValue(expression = "gHotSpotVMStructs", get = HotSpotVMValue.Type.ADDRESS) @Stable private long gHotSpotVMStructs; - @HotSpotVMValue(expression = "gHotSpotVMStructEntryTypeNameOffset") @Stable private long gHotSpotVMStructEntryTypeNameOffset; - @HotSpotVMValue(expression = "gHotSpotVMStructEntryFieldNameOffset") @Stable private long gHotSpotVMStructEntryFieldNameOffset; - @HotSpotVMValue(expression = "gHotSpotVMStructEntryTypeStringOffset") @Stable private long gHotSpotVMStructEntryTypeStringOffset; - @HotSpotVMValue(expression = "gHotSpotVMStructEntryIsStaticOffset") @Stable private long gHotSpotVMStructEntryIsStaticOffset; - @HotSpotVMValue(expression = "gHotSpotVMStructEntryOffsetOffset") @Stable private long gHotSpotVMStructEntryOffsetOffset; - @HotSpotVMValue(expression = "gHotSpotVMStructEntryAddressOffset") @Stable private long gHotSpotVMStructEntryAddressOffset; - @HotSpotVMValue(expression = "gHotSpotVMStructEntryArrayStride") @Stable private long gHotSpotVMStructEntryArrayStride; - - class VMFields implements Iterable { - - private long address; - - public VMFields(long address) { - this.address = address; - } - - public Iterator iterator() { - return new Iterator() { - - private int index = 0; - - private Field current() { - return new Field(address + gHotSpotVMStructEntryArrayStride * index); - } - - /** - * The last entry is identified by a NULL fieldName. - */ - public boolean hasNext() { - Field entry = current(); - return entry.getFieldName() != null; - } - - public Field next() { - Field entry = current(); - index++; - return entry; - } - }; - } - - class Field { - - private long entryAddress; - - Field(long address) { - this.entryAddress = address; - } - - public String getTypeName() { - long typeNameAddress = unsafe.getAddress(entryAddress + gHotSpotVMStructEntryTypeNameOffset); - return readCString(typeNameAddress); - } - - public String getFieldName() { - long fieldNameAddress = unsafe.getAddress(entryAddress + gHotSpotVMStructEntryFieldNameOffset); - return readCString(fieldNameAddress); - } - - public String getTypeString() { - long typeStringAddress = unsafe.getAddress(entryAddress + gHotSpotVMStructEntryTypeStringOffset); - return readCString(typeStringAddress); - } - - public boolean isStatic() { - return unsafe.getInt(entryAddress + gHotSpotVMStructEntryIsStaticOffset) != 0; - } - - public long getOffset() { - return unsafe.getLong(entryAddress + gHotSpotVMStructEntryOffsetOffset); - } - - public long getAddress() { - return unsafe.getAddress(entryAddress + gHotSpotVMStructEntryAddressOffset); - } - - public String getName() { - String typeName = getTypeName(); - String fieldName = getFieldName(); - return typeName + "::" + fieldName; - } - - public long getValue() { - String type = getTypeString(); - switch (type) { - case "int": - return unsafe.getInt(getAddress()); - case "address": - case "intptr_t": - return unsafe.getAddress(getAddress()); - default: - // All foo* types are addresses. - if (type.endsWith("*")) { - return unsafe.getAddress(getAddress()); - } - throw new JVMCIError(type); - } - } - - @Override - public String toString() { - return String.format("Field[typeName=%s, fieldName=%s, typeString=%s, isStatic=%b, offset=%d, address=0x%x]", getTypeName(), getFieldName(), getTypeString(), isStatic(), getOffset(), - getAddress()); - } - } - } - - /** - * VMTypeEntry (see vmStructs.hpp). - */ - @HotSpotVMValue(expression = "gHotSpotVMTypes", get = HotSpotVMValue.Type.ADDRESS) @Stable private long gHotSpotVMTypes; - @HotSpotVMValue(expression = "gHotSpotVMTypeEntryTypeNameOffset") @Stable private long gHotSpotVMTypeEntryTypeNameOffset; - @HotSpotVMValue(expression = "gHotSpotVMTypeEntrySuperclassNameOffset") @Stable private long gHotSpotVMTypeEntrySuperclassNameOffset; - @HotSpotVMValue(expression = "gHotSpotVMTypeEntryIsOopTypeOffset") @Stable private long gHotSpotVMTypeEntryIsOopTypeOffset; - @HotSpotVMValue(expression = "gHotSpotVMTypeEntryIsIntegerTypeOffset") @Stable private long gHotSpotVMTypeEntryIsIntegerTypeOffset; - @HotSpotVMValue(expression = "gHotSpotVMTypeEntryIsUnsignedOffset") @Stable private long gHotSpotVMTypeEntryIsUnsignedOffset; - @HotSpotVMValue(expression = "gHotSpotVMTypeEntrySizeOffset") @Stable private long gHotSpotVMTypeEntrySizeOffset; - @HotSpotVMValue(expression = "gHotSpotVMTypeEntryArrayStride") @Stable private long gHotSpotVMTypeEntryArrayStride; - - class VMTypes implements Iterable { - - private long address; - - public VMTypes(long address) { - this.address = address; - } - - public Iterator iterator() { - return new Iterator() { - - private int index = 0; - - private Type current() { - return new Type(address + gHotSpotVMTypeEntryArrayStride * index); - } - - /** - * The last entry is identified by a NULL type name. - */ - public boolean hasNext() { - Type entry = current(); - return entry.getTypeName() != null; - } - - public Type next() { - Type entry = current(); - index++; - return entry; - } - }; - } - - class Type { - - private long entryAddress; - - Type(long address) { - this.entryAddress = address; - } - - public String getTypeName() { - long typeNameAddress = unsafe.getAddress(entryAddress + gHotSpotVMTypeEntryTypeNameOffset); - return readCString(typeNameAddress); - } - - public String getSuperclassName() { - long superclassNameAddress = unsafe.getAddress(entryAddress + gHotSpotVMTypeEntrySuperclassNameOffset); - return readCString(superclassNameAddress); - } - - public boolean isOopType() { - return unsafe.getInt(entryAddress + gHotSpotVMTypeEntryIsOopTypeOffset) != 0; - } - - public boolean isIntegerType() { - return unsafe.getInt(entryAddress + gHotSpotVMTypeEntryIsIntegerTypeOffset) != 0; - } - - public boolean isUnsigned() { - return unsafe.getInt(entryAddress + gHotSpotVMTypeEntryIsUnsignedOffset) != 0; - } - - public long getSize() { - return unsafe.getLong(entryAddress + gHotSpotVMTypeEntrySizeOffset); - } - - @Override - public String toString() { - return String.format("Type[typeName=%s, superclassName=%s, isOopType=%b, isIntegerType=%b, isUnsigned=%b, size=%d]", getTypeName(), getSuperclassName(), isOopType(), isIntegerType(), - isUnsigned(), getSize()); - } - } - } - - public abstract class AbstractConstant { - - protected long address; - protected long nameOffset; - protected long valueOffset; - - AbstractConstant(long address, long nameOffset, long valueOffset) { - this.address = address; - this.nameOffset = nameOffset; - this.valueOffset = valueOffset; - } - - public String getName() { - long nameAddress = unsafe.getAddress(address + nameOffset); - return readCString(nameAddress); - } - - public abstract long getValue(); - } - - /** - * VMIntConstantEntry (see vmStructs.hpp). - */ - @HotSpotVMValue(expression = "gHotSpotVMIntConstants", get = HotSpotVMValue.Type.ADDRESS) @Stable private long gHotSpotVMIntConstants; - @HotSpotVMValue(expression = "gHotSpotVMIntConstantEntryNameOffset") @Stable private long gHotSpotVMIntConstantEntryNameOffset; - @HotSpotVMValue(expression = "gHotSpotVMIntConstantEntryValueOffset") @Stable private long gHotSpotVMIntConstantEntryValueOffset; - @HotSpotVMValue(expression = "gHotSpotVMIntConstantEntryArrayStride") @Stable private long gHotSpotVMIntConstantEntryArrayStride; - - class VMIntConstants implements Iterable { - - private long address; - - public VMIntConstants(long address) { - this.address = address; - } - - public Iterator iterator() { - return new Iterator() { - - private int index = 0; - - private Constant current() { - return new Constant(address + gHotSpotVMIntConstantEntryArrayStride * index); - } - - /** - * The last entry is identified by a NULL name. - */ - public boolean hasNext() { - Constant entry = current(); - return entry.getName() != null; - } - - public Constant next() { - Constant entry = current(); - index++; - return entry; - } - }; - } - - class Constant extends AbstractConstant { - - Constant(long address) { - super(address, gHotSpotVMIntConstantEntryNameOffset, gHotSpotVMIntConstantEntryValueOffset); - } - - @Override - public long getValue() { - return unsafe.getInt(address + valueOffset); - } - - @Override - public String toString() { - return String.format("IntConstant[name=%s, value=%d (0x%x)]", getName(), getValue(), getValue()); - } - } - } - - /** - * VMLongConstantEntry (see vmStructs.hpp). - */ - @HotSpotVMValue(expression = "gHotSpotVMLongConstants", get = HotSpotVMValue.Type.ADDRESS) @Stable private long gHotSpotVMLongConstants; - @HotSpotVMValue(expression = "gHotSpotVMLongConstantEntryNameOffset") @Stable private long gHotSpotVMLongConstantEntryNameOffset; - @HotSpotVMValue(expression = "gHotSpotVMLongConstantEntryValueOffset") @Stable private long gHotSpotVMLongConstantEntryValueOffset; - @HotSpotVMValue(expression = "gHotSpotVMLongConstantEntryArrayStride") @Stable private long gHotSpotVMLongConstantEntryArrayStride; - - class VMLongConstants implements Iterable { - - private long address; - - public VMLongConstants(long address) { - this.address = address; - } - - public Iterator iterator() { - return new Iterator() { - - private int index = 0; - - private Constant currentEntry() { - return new Constant(address + gHotSpotVMLongConstantEntryArrayStride * index); - } - - /** - * The last entry is identified by a NULL name. - */ - public boolean hasNext() { - Constant entry = currentEntry(); - return entry.getName() != null; - } - - public Constant next() { - Constant entry = currentEntry(); - index++; - return entry; - } - }; - } - - class Constant extends AbstractConstant { - - Constant(long address) { - super(address, gHotSpotVMLongConstantEntryNameOffset, gHotSpotVMLongConstantEntryValueOffset); - } - - @Override - public long getValue() { - return unsafe.getLong(address + valueOffset); - } - - @Override - public String toString() { - return String.format("LongConstant[name=%s, value=%d (0x%x)]", getName(), getValue(), getValue()); - } - } - } - - class Flags implements Iterable { - - private long address; - private long entrySize; - private long typeOffset; - private long nameOffset; - private long addrOffset; - - public Flags(HashMap vmStructs, HashMap vmTypes) { - address = vmStructs.get("Flag::flags").getValue(); - entrySize = vmTypes.get("Flag").getSize(); - typeOffset = vmStructs.get("Flag::_type").getOffset(); - nameOffset = vmStructs.get("Flag::_name").getOffset(); - addrOffset = vmStructs.get("Flag::_addr").getOffset(); - - assert vmTypes.get("bool").getSize() == Byte.BYTES; - assert vmTypes.get("intx").getSize() == Long.BYTES; - assert vmTypes.get("uintx").getSize() == Long.BYTES; - } - - public Iterator iterator() { - return new Iterator() { - - private int index = 0; - - private Flag current() { - return new Flag(address + entrySize * index); - } - - /** - * The last entry is identified by a NULL name. - */ - public boolean hasNext() { - Flag entry = current(); - return entry.getName() != null; - } - - public Flag next() { - Flag entry = current(); - index++; - return entry; - } - }; - } - - class Flag { - - private long entryAddress; - - Flag(long address) { - this.entryAddress = address; - } - - public String getType() { - long typeAddress = unsafe.getAddress(entryAddress + typeOffset); - return readCString(typeAddress); - } - - public String getName() { - long nameAddress = unsafe.getAddress(entryAddress + nameOffset); - return readCString(nameAddress); - } - - public long getAddr() { - return unsafe.getAddress(entryAddress + addrOffset); - } - - public Object getValue() { - switch (getType()) { - case "bool": - return Boolean.valueOf(unsafe.getByte(getAddr()) != 0); - case "intx": - case "uintx": - case "uint64_t": - return Long.valueOf(unsafe.getLong(getAddr())); - case "double": - return Double.valueOf(unsafe.getDouble(getAddr())); - case "ccstr": - case "ccstrlist": - return readCString(getAddr()); - default: - throw new JVMCIError(getType()); - } - } - - @Override - public String toString() { - return String.format("Flag[type=%s, name=%s, value=%s]", getType(), getName(), getValue()); - } - } - } - - // os information, register layout, code generation, ... - @HotSpotVMValue(expression = "DEBUG_ONLY(1) NOT_DEBUG(0)") @Stable public boolean cAssertions; - public final boolean windowsOs = System.getProperty("os.name", "").startsWith("Windows"); - - @HotSpotVMFlag(name = "CodeEntryAlignment") @Stable public int codeEntryAlignment; - @HotSpotVMFlag(name = "VerifyOops") @Stable public boolean verifyOops; - @HotSpotVMFlag(name = "CITime") @Stable public boolean ciTime; - @HotSpotVMFlag(name = "CITimeEach") @Stable public boolean ciTimeEach; - @HotSpotVMFlag(name = "CompileTheWorldStartAt", optional = true) @Stable public int compileTheWorldStartAt; - @HotSpotVMFlag(name = "CompileTheWorldStopAt", optional = true) @Stable public int compileTheWorldStopAt; - @HotSpotVMFlag(name = "DontCompileHugeMethods") @Stable public boolean dontCompileHugeMethods; - @HotSpotVMFlag(name = "HugeMethodLimit") @Stable public int hugeMethodLimit; - @HotSpotVMFlag(name = "PrintInlining") @Stable public boolean printInlining; - @HotSpotVMFlag(name = "JVMCIUseFastLocking") @Stable public boolean useFastLocking; - @HotSpotVMFlag(name = "ForceUnreachable") @Stable public boolean forceUnreachable; - - @HotSpotVMFlag(name = "UseTLAB") @Stable public boolean useTLAB; - @HotSpotVMFlag(name = "UseBiasedLocking") @Stable public boolean useBiasedLocking; - @HotSpotVMFlag(name = "UsePopCountInstruction") @Stable public boolean usePopCountInstruction; - @HotSpotVMFlag(name = "UseCountLeadingZerosInstruction", archs = {"amd64"}) @Stable public boolean useCountLeadingZerosInstruction; - @HotSpotVMFlag(name = "UseCountTrailingZerosInstruction", archs = {"amd64"}) @Stable public boolean useCountTrailingZerosInstruction; - @HotSpotVMFlag(name = "UseAESIntrinsics") @Stable public boolean useAESIntrinsics; - @HotSpotVMFlag(name = "UseCRC32Intrinsics") @Stable public boolean useCRC32Intrinsics; - @HotSpotVMFlag(name = "UseG1GC") @Stable public boolean useG1GC; - @HotSpotVMFlag(name = "UseConcMarkSweepGC") @Stable public boolean useCMSGC; - - @HotSpotVMFlag(name = "AllocatePrefetchStyle") @Stable public int allocatePrefetchStyle; - @HotSpotVMFlag(name = "AllocatePrefetchInstr") @Stable public int allocatePrefetchInstr; - @HotSpotVMFlag(name = "AllocatePrefetchLines") @Stable public int allocatePrefetchLines; - @HotSpotVMFlag(name = "AllocateInstancePrefetchLines") @Stable public int allocateInstancePrefetchLines; - @HotSpotVMFlag(name = "AllocatePrefetchStepSize") @Stable public int allocatePrefetchStepSize; - @HotSpotVMFlag(name = "AllocatePrefetchDistance") @Stable public int allocatePrefetchDistance; - - @HotSpotVMFlag(name = "FlightRecorder", optional = true) @Stable public boolean flightRecorder; - - @HotSpotVMField(name = "Universe::_collectedHeap", type = "CollectedHeap*", get = HotSpotVMField.Type.VALUE) @Stable private long universeCollectedHeap; - @HotSpotVMField(name = "CollectedHeap::_total_collections", type = "unsigned int", get = HotSpotVMField.Type.OFFSET) @Stable private int collectedHeapTotalCollectionsOffset; - - public long gcTotalCollectionsAddress() { - return universeCollectedHeap + collectedHeapTotalCollectionsOffset; - } - - @HotSpotVMFlag(name = "JVMCIDeferredInitBarriers") @Stable public boolean useDeferredInitBarriers; - @HotSpotVMFlag(name = "JVMCIHProfEnabled") @Stable public boolean useHeapProfiler; - - // Compressed Oops related values. - @HotSpotVMFlag(name = "UseCompressedOops") @Stable public boolean useCompressedOops; - @HotSpotVMFlag(name = "UseCompressedClassPointers") @Stable public boolean useCompressedClassPointers; - - @HotSpotVMField(name = "Universe::_narrow_oop._base", type = "address", get = HotSpotVMField.Type.VALUE) @Stable public long narrowOopBase; - @HotSpotVMField(name = "Universe::_narrow_oop._shift", type = "int", get = HotSpotVMField.Type.VALUE) @Stable public int narrowOopShift; - @HotSpotVMFlag(name = "ObjectAlignmentInBytes") @Stable public int objectAlignment; - - public int logMinObjAlignment() { - return (int) (Math.log(objectAlignment) / Math.log(2)); - } - - @HotSpotVMField(name = "Universe::_narrow_klass._base", type = "address", get = HotSpotVMField.Type.VALUE) @Stable public long narrowKlassBase; - @HotSpotVMField(name = "Universe::_narrow_klass._shift", type = "int", get = HotSpotVMField.Type.VALUE) @Stable public int narrowKlassShift; - @HotSpotVMConstant(name = "LogKlassAlignmentInBytes") @Stable public int logKlassAlignment; - - // CPU capabilities - @HotSpotVMFlag(name = "UseSSE") @Stable public int useSSE; - @HotSpotVMFlag(name = "UseAVX", archs = {"amd64"}) @Stable public int useAVX; - - // X86 specific values - @HotSpotVMField(name = "VM_Version::_cpuFeatures", type = "int", get = HotSpotVMField.Type.VALUE, archs = {"amd64"}) @Stable public int x86CPUFeatures; - @HotSpotVMConstant(name = "VM_Version::CPU_CX8", archs = {"amd64"}) @Stable public int cpuCX8; - @HotSpotVMConstant(name = "VM_Version::CPU_CMOV", archs = {"amd64"}) @Stable public int cpuCMOV; - @HotSpotVMConstant(name = "VM_Version::CPU_FXSR", archs = {"amd64"}) @Stable public int cpuFXSR; - @HotSpotVMConstant(name = "VM_Version::CPU_HT", archs = {"amd64"}) @Stable public int cpuHT; - @HotSpotVMConstant(name = "VM_Version::CPU_MMX", archs = {"amd64"}) @Stable public int cpuMMX; - @HotSpotVMConstant(name = "VM_Version::CPU_3DNOW_PREFETCH", archs = {"amd64"}) @Stable public int cpu3DNOWPREFETCH; - @HotSpotVMConstant(name = "VM_Version::CPU_SSE", archs = {"amd64"}) @Stable public int cpuSSE; - @HotSpotVMConstant(name = "VM_Version::CPU_SSE2", archs = {"amd64"}) @Stable public int cpuSSE2; - @HotSpotVMConstant(name = "VM_Version::CPU_SSE3", archs = {"amd64"}) @Stable public int cpuSSE3; - @HotSpotVMConstant(name = "VM_Version::CPU_SSSE3", archs = {"amd64"}) @Stable public int cpuSSSE3; - @HotSpotVMConstant(name = "VM_Version::CPU_SSE4A", archs = {"amd64"}) @Stable public int cpuSSE4A; - @HotSpotVMConstant(name = "VM_Version::CPU_SSE4_1", archs = {"amd64"}) @Stable public int cpuSSE41; - @HotSpotVMConstant(name = "VM_Version::CPU_SSE4_2", archs = {"amd64"}) @Stable public int cpuSSE42; - @HotSpotVMConstant(name = "VM_Version::CPU_POPCNT", archs = {"amd64"}) @Stable public int cpuPOPCNT; - @HotSpotVMConstant(name = "VM_Version::CPU_LZCNT", archs = {"amd64"}) @Stable public int cpuLZCNT; - @HotSpotVMConstant(name = "VM_Version::CPU_TSC", archs = {"amd64"}) @Stable public int cpuTSC; - @HotSpotVMConstant(name = "VM_Version::CPU_TSCINV", archs = {"amd64"}) @Stable public int cpuTSCINV; - @HotSpotVMConstant(name = "VM_Version::CPU_AVX", archs = {"amd64"}) @Stable public int cpuAVX; - @HotSpotVMConstant(name = "VM_Version::CPU_AVX2", archs = {"amd64"}) @Stable public int cpuAVX2; - @HotSpotVMConstant(name = "VM_Version::CPU_AES", archs = {"amd64"}) @Stable public int cpuAES; - @HotSpotVMConstant(name = "VM_Version::CPU_ERMS", archs = {"amd64"}) @Stable public int cpuERMS; - @HotSpotVMConstant(name = "VM_Version::CPU_CLMUL", archs = {"amd64"}) @Stable public int cpuCLMUL; - @HotSpotVMConstant(name = "VM_Version::CPU_BMI1", archs = {"amd64"}) @Stable public int cpuBMI1; - - // SPARC specific values - @HotSpotVMField(name = "VM_Version::_features", type = "int", get = HotSpotVMField.Type.VALUE, archs = {"sparc"}) @Stable public int sparcFeatures; - @HotSpotVMConstant(name = "VM_Version::vis3_instructions_m", archs = {"sparc"}) @Stable public int vis3Instructions; - @HotSpotVMConstant(name = "VM_Version::vis2_instructions_m", archs = {"sparc"}) @Stable public int vis2Instructions; - @HotSpotVMConstant(name = "VM_Version::vis1_instructions_m", archs = {"sparc"}) @Stable public int vis1Instructions; - @HotSpotVMConstant(name = "VM_Version::cbcond_instructions_m", archs = {"sparc"}) @Stable public int cbcondInstructions; - - // offsets, ... - @HotSpotVMFlag(name = "StackShadowPages") @Stable public int stackShadowPages; - @HotSpotVMFlag(name = "UseStackBanging") @Stable public boolean useStackBanging; - @HotSpotVMConstant(name = "STACK_BIAS") @Stable public int stackBias; - - @HotSpotVMField(name = "oopDesc::_mark", type = "markOop", get = HotSpotVMField.Type.OFFSET) @Stable public int markOffset; - @HotSpotVMField(name = "oopDesc::_metadata._klass", type = "Klass*", get = HotSpotVMField.Type.OFFSET) @Stable public int hubOffset; - - @HotSpotVMField(name = "Klass::_prototype_header", type = "markOop", get = HotSpotVMField.Type.OFFSET) @Stable public int prototypeMarkWordOffset; - @HotSpotVMField(name = "Klass::_subklass", type = "Klass*", get = HotSpotVMField.Type.OFFSET) @Stable public int subklassOffset; - @HotSpotVMField(name = "Klass::_next_sibling", type = "Klass*", get = HotSpotVMField.Type.OFFSET) @Stable public int nextSiblingOffset; - @HotSpotVMField(name = "Klass::_super_check_offset", type = "juint", get = HotSpotVMField.Type.OFFSET) @Stable public int superCheckOffsetOffset; - @HotSpotVMField(name = "Klass::_secondary_super_cache", type = "Klass*", get = HotSpotVMField.Type.OFFSET) @Stable public int secondarySuperCacheOffset; - @HotSpotVMField(name = "Klass::_secondary_supers", type = "Array*", get = HotSpotVMField.Type.OFFSET) @Stable public int secondarySupersOffset; - - /** - * The offset of the _java_mirror field (of type {@link Class}) in a Klass. - */ - @HotSpotVMField(name = "Klass::_java_mirror", type = "oop", get = HotSpotVMField.Type.OFFSET) @Stable public int classMirrorOffset; - - @HotSpotVMField(name = "Klass::_super", type = "Klass*", get = HotSpotVMField.Type.OFFSET) @Stable public int klassSuperKlassOffset; - @HotSpotVMField(name = "Klass::_modifier_flags", type = "jint", get = HotSpotVMField.Type.OFFSET) @Stable public int klassModifierFlagsOffset; - @HotSpotVMField(name = "Klass::_access_flags", type = "AccessFlags", get = HotSpotVMField.Type.OFFSET) @Stable public int klassAccessFlagsOffset; - @HotSpotVMField(name = "Klass::_layout_helper", type = "jint", get = HotSpotVMField.Type.OFFSET) @Stable public int klassLayoutHelperOffset; - - @HotSpotVMConstant(name = "Klass::_lh_neutral_value") @Stable public int klassLayoutHelperNeutralValue; - @HotSpotVMConstant(name = "Klass::_lh_instance_slow_path_bit") @Stable public int klassLayoutHelperInstanceSlowPathBit; - @HotSpotVMConstant(name = "Klass::_lh_log2_element_size_shift") @Stable public int layoutHelperLog2ElementSizeShift; - @HotSpotVMConstant(name = "Klass::_lh_log2_element_size_mask") @Stable public int layoutHelperLog2ElementSizeMask; - @HotSpotVMConstant(name = "Klass::_lh_element_type_shift") @Stable public int layoutHelperElementTypeShift; - @HotSpotVMConstant(name = "Klass::_lh_element_type_mask") @Stable public int layoutHelperElementTypeMask; - @HotSpotVMConstant(name = "Klass::_lh_header_size_shift") @Stable public int layoutHelperHeaderSizeShift; - @HotSpotVMConstant(name = "Klass::_lh_header_size_mask") @Stable public int layoutHelperHeaderSizeMask; - @HotSpotVMConstant(name = "Klass::_lh_array_tag_shift") @Stable public int layoutHelperArrayTagShift; - @HotSpotVMConstant(name = "Klass::_lh_array_tag_type_value") @Stable public int layoutHelperArrayTagTypeValue; - @HotSpotVMConstant(name = "Klass::_lh_array_tag_obj_value") @Stable public int layoutHelperArrayTagObjectValue; - - /** - * This filters out the bit that differentiates a type array from an object array. - */ - public int layoutHelperElementTypePrimitiveInPlace() { - return (layoutHelperArrayTagTypeValue & ~layoutHelperArrayTagObjectValue) << layoutHelperArrayTagShift; - } - - /** - * Bit pattern in the klass layout helper that can be used to identify arrays. - */ - public final int arrayKlassLayoutHelperIdentifier = 0x80000000; - - @HotSpotVMField(name = "ArrayKlass::_component_mirror", type = "oop", get = HotSpotVMField.Type.OFFSET) @Stable public int arrayKlassComponentMirrorOffset; - - @HotSpotVMType(name = "vtableEntry", get = HotSpotVMType.Type.SIZE) @Stable public int vtableEntrySize; - @HotSpotVMField(name = "vtableEntry::_method", type = "Method*", get = HotSpotVMField.Type.OFFSET) @Stable public int vtableEntryMethodOffset; - @HotSpotVMValue(expression = "InstanceKlass::vtable_start_offset() * HeapWordSize") @Stable public int instanceKlassVtableStartOffset; - @HotSpotVMValue(expression = "InstanceKlass::vtable_length_offset() * HeapWordSize") @Stable public int instanceKlassVtableLengthOffset; - @HotSpotVMValue(expression = "Universe::base_vtable_size() / vtableEntry::size()") @Stable public int baseVtableLength; - - /** - * The offset of the array length word in an array object's header. - */ - @HotSpotVMValue(expression = "arrayOopDesc::length_offset_in_bytes()") @Stable public int arrayLengthOffset; - - @HotSpotVMField(name = "Array::_length", type = "int", get = HotSpotVMField.Type.OFFSET) @Stable public int arrayU1LengthOffset; - @HotSpotVMField(name = "Array::_data", type = "", get = HotSpotVMField.Type.OFFSET) @Stable public int arrayU1DataOffset; - @HotSpotVMField(name = "Array::_data", type = "", get = HotSpotVMField.Type.OFFSET) @Stable public int arrayU2DataOffset; - @HotSpotVMField(name = "Array::_length", type = "int", get = HotSpotVMField.Type.OFFSET) @Stable public int metaspaceArrayLengthOffset; - @HotSpotVMField(name = "Array::_data[0]", type = "Klass*", get = HotSpotVMField.Type.OFFSET) @Stable public int metaspaceArrayBaseOffset; - - @HotSpotVMField(name = "InstanceKlass::_source_file_name_index", type = "u2", get = HotSpotVMField.Type.OFFSET) @Stable public int instanceKlassSourceFileNameIndexOffset; - @HotSpotVMField(name = "InstanceKlass::_init_state", type = "u1", get = HotSpotVMField.Type.OFFSET) @Stable public int instanceKlassInitStateOffset; - @HotSpotVMField(name = "InstanceKlass::_constants", type = "ConstantPool*", get = HotSpotVMField.Type.OFFSET) @Stable public int instanceKlassConstantsOffset; - @HotSpotVMField(name = "InstanceKlass::_fields", type = "Array*", get = HotSpotVMField.Type.OFFSET) @Stable public int instanceKlassFieldsOffset; - - @HotSpotVMConstant(name = "InstanceKlass::linked") @Stable public int instanceKlassStateLinked; - @HotSpotVMConstant(name = "InstanceKlass::fully_initialized") @Stable public int instanceKlassStateFullyInitialized; - - @HotSpotVMField(name = "ObjArrayKlass::_element_klass", type = "Klass*", get = HotSpotVMField.Type.OFFSET) @Stable public int arrayClassElementOffset; - - @HotSpotVMConstant(name = "FieldInfo::access_flags_offset") @Stable public int fieldInfoAccessFlagsOffset; - @HotSpotVMConstant(name = "FieldInfo::name_index_offset") @Stable public int fieldInfoNameIndexOffset; - @HotSpotVMConstant(name = "FieldInfo::signature_index_offset") @Stable public int fieldInfoSignatureIndexOffset; - @HotSpotVMConstant(name = "FieldInfo::initval_index_offset") @Stable public int fieldInfoInitvalIndexOffset; - @HotSpotVMConstant(name = "FieldInfo::low_packed_offset") @Stable public int fieldInfoLowPackedOffset; - @HotSpotVMConstant(name = "FieldInfo::high_packed_offset") @Stable public int fieldInfoHighPackedOffset; - @HotSpotVMConstant(name = "FieldInfo::field_slots") @Stable public int fieldInfoFieldSlots; - - @HotSpotVMConstant(name = "FIELDINFO_TAG_SIZE") @Stable public int fieldInfoTagSize; - - @HotSpotVMConstant(name = "JVM_ACC_FIELD_INTERNAL") @Stable public int jvmAccFieldInternal; - @HotSpotVMConstant(name = "JVM_ACC_FIELD_STABLE") @Stable public int jvmAccFieldStable; - @HotSpotVMConstant(name = "JVM_ACC_FIELD_HAS_GENERIC_SIGNATURE") @Stable public int jvmAccFieldHasGenericSignature; - @HotSpotVMConstant(name = "JVM_ACC_WRITTEN_FLAGS") @Stable public int jvmAccWrittenFlags; - - @HotSpotVMField(name = "Thread::_tlab", type = "ThreadLocalAllocBuffer", get = HotSpotVMField.Type.OFFSET) @Stable public int threadTlabOffset; - - @HotSpotVMField(name = "JavaThread::_anchor", type = "JavaFrameAnchor", get = HotSpotVMField.Type.OFFSET) @Stable public int javaThreadAnchorOffset; - @HotSpotVMField(name = "JavaThread::_threadObj", type = "oop", get = HotSpotVMField.Type.OFFSET) @Stable public int threadObjectOffset; - @HotSpotVMField(name = "JavaThread::_osthread", type = "OSThread*", get = HotSpotVMField.Type.OFFSET) @Stable public int osThreadOffset; - @HotSpotVMField(name = "JavaThread::_dirty_card_queue", type = "DirtyCardQueue", get = HotSpotVMField.Type.OFFSET) @Stable public int javaThreadDirtyCardQueueOffset; - @HotSpotVMField(name = "JavaThread::_is_method_handle_return", type = "int", get = HotSpotVMField.Type.OFFSET) @Stable public int threadIsMethodHandleReturnOffset; - @HotSpotVMField(name = "JavaThread::_satb_mark_queue", type = "ObjPtrQueue", get = HotSpotVMField.Type.OFFSET) @Stable public int javaThreadSatbMarkQueueOffset; - @HotSpotVMField(name = "JavaThread::_vm_result", type = "oop", get = HotSpotVMField.Type.OFFSET) @Stable public int threadObjectResultOffset; - @HotSpotVMValue(expression = "in_bytes(JavaThread::jvmci_counters_offset())") @Stable public int jvmciCountersThreadOffset; - - /** - * An invalid value for {@link #rtldDefault}. - */ - public static final long INVALID_RTLD_DEFAULT_HANDLE = 0xDEADFACE; - - /** - * Address of the library lookup routine. The C signature of this routine is: - * - *
-     *     void* (const char *filename, char *ebuf, int ebuflen)
-     * 
- */ - @HotSpotVMValue(expression = "os::dll_load", get = HotSpotVMValue.Type.ADDRESS) @Stable public long dllLoad; - - /** - * Address of the library lookup routine. The C signature of this routine is: - * - *
-     *     void* (void* handle, const char* name)
-     * 
- */ - @HotSpotVMValue(expression = "os::dll_lookup", get = HotSpotVMValue.Type.ADDRESS) @Stable public long dllLookup; - - /** - * A pseudo-handle which when used as the first argument to {@link #dllLookup} means lookup will - * return the first occurrence of the desired symbol using the default library search order. If - * this field is {@value #INVALID_RTLD_DEFAULT_HANDLE}, then this capability is not supported on - * the current platform. - */ - @HotSpotVMValue(expression = "RTLD_DEFAULT", defines = {"TARGET_OS_FAMILY_bsd", "TARGET_OS_FAMILY_linux"}, get = HotSpotVMValue.Type.ADDRESS) @Stable public long rtldDefault = INVALID_RTLD_DEFAULT_HANDLE; - - /** - * This field is used to pass exception objects into and out of the runtime system during - * exception handling for compiled code. - *

- * NOTE: This is not the same as {@link #pendingExceptionOffset}. - */ - @HotSpotVMField(name = "JavaThread::_exception_oop", type = "oop", get = HotSpotVMField.Type.OFFSET) @Stable public int threadExceptionOopOffset; - @HotSpotVMField(name = "JavaThread::_exception_pc", type = "address", get = HotSpotVMField.Type.OFFSET) @Stable public int threadExceptionPcOffset; - - @HotSpotVMField(name = "JavaFrameAnchor::_last_Java_sp", type = "intptr_t*", get = HotSpotVMField.Type.OFFSET) @Stable private int javaFrameAnchorLastJavaSpOffset; - @HotSpotVMField(name = "JavaFrameAnchor::_last_Java_pc", type = "address", get = HotSpotVMField.Type.OFFSET) @Stable private int javaFrameAnchorLastJavaPcOffset; - @HotSpotVMField(name = "JavaFrameAnchor::_last_Java_fp", type = "intptr_t*", get = HotSpotVMField.Type.OFFSET, archs = {"amd64"}) @Stable private int javaFrameAnchorLastJavaFpOffset; - @HotSpotVMField(name = "JavaFrameAnchor::_flags", type = "int", get = HotSpotVMField.Type.OFFSET, archs = {"sparc"}) @Stable private int javaFrameAnchorFlagsOffset; - - public int threadLastJavaSpOffset() { - return javaThreadAnchorOffset + javaFrameAnchorLastJavaSpOffset; - } - - public int threadLastJavaPcOffset() { - return javaThreadAnchorOffset + javaFrameAnchorLastJavaPcOffset; - } - - /** - * This value is only valid on AMD64. - */ - public int threadLastJavaFpOffset() { - // TODO add an assert for AMD64 - return javaThreadAnchorOffset + javaFrameAnchorLastJavaFpOffset; - } - - /** - * This value is only valid on SPARC. - */ - public int threadJavaFrameAnchorFlagsOffset() { - // TODO add an assert for SPARC - return javaThreadAnchorOffset + javaFrameAnchorFlagsOffset; - } - - // These are only valid on AMD64. - @HotSpotVMConstant(name = "frame::arg_reg_save_area_bytes", archs = {"amd64"}) @Stable public int runtimeCallStackSize; - @HotSpotVMConstant(name = "frame::interpreter_frame_sender_sp_offset", archs = {"amd64"}) @Stable public int frameInterpreterFrameSenderSpOffset; - @HotSpotVMConstant(name = "frame::interpreter_frame_last_sp_offset", archs = {"amd64"}) @Stable public int frameInterpreterFrameLastSpOffset; - - @HotSpotVMField(name = "PtrQueue::_active", type = "bool", get = HotSpotVMField.Type.OFFSET) @Stable public int ptrQueueActiveOffset; - @HotSpotVMField(name = "PtrQueue::_buf", type = "void**", get = HotSpotVMField.Type.OFFSET) @Stable public int ptrQueueBufferOffset; - @HotSpotVMField(name = "PtrQueue::_index", type = "size_t", get = HotSpotVMField.Type.OFFSET) @Stable public int ptrQueueIndexOffset; - - @HotSpotVMField(name = "OSThread::_interrupted", type = "jint", get = HotSpotVMField.Type.OFFSET) @Stable public int osThreadInterruptedOffset; - - @HotSpotVMConstant(name = "markOopDesc::unlocked_value") @Stable public int unlockedMask; - @HotSpotVMConstant(name = "markOopDesc::biased_lock_mask_in_place") @Stable public int biasedLockMaskInPlace; - @HotSpotVMConstant(name = "markOopDesc::age_mask_in_place") @Stable public int ageMaskInPlace; - @HotSpotVMConstant(name = "markOopDesc::epoch_mask_in_place") @Stable public int epochMaskInPlace; - - @HotSpotVMConstant(name = "markOopDesc::hash_shift") @Stable public long markOopDescHashShift; - @HotSpotVMConstant(name = "markOopDesc::hash_mask") @Stable public long markOopDescHashMask; - @HotSpotVMConstant(name = "markOopDesc::hash_mask_in_place") @Stable public long markOopDescHashMaskInPlace; - - @HotSpotVMConstant(name = "markOopDesc::biased_lock_pattern") @Stable public int biasedLockPattern; - @HotSpotVMConstant(name = "markOopDesc::no_hash_in_place") @Stable public int markWordNoHashInPlace; - @HotSpotVMConstant(name = "markOopDesc::no_lock_in_place") @Stable public int markWordNoLockInPlace; - - /** - * See markOopDesc::prototype(). - */ - public long arrayPrototypeMarkWord() { - return markWordNoHashInPlace | markWordNoLockInPlace; - } - - /** - * See markOopDesc::copy_set_hash(). - */ - public long tlabIntArrayMarkWord() { - long tmp = arrayPrototypeMarkWord() & (~markOopDescHashMaskInPlace); - tmp |= ((0x2 & markOopDescHashMask) << markOopDescHashShift); - return tmp; - } - - /** - * Offset of the _pending_exception field in ThreadShadow (defined in exceptions.hpp). This - * field is used to propagate exceptions through C/C++ calls. - *

- * NOTE: This is not the same as {@link #threadExceptionOopOffset}. - */ - @HotSpotVMField(name = "ThreadShadow::_pending_exception", type = "oop", get = HotSpotVMField.Type.OFFSET) @Stable public int pendingExceptionOffset; - @HotSpotVMField(name = "ThreadShadow::_pending_deoptimization", type = "int", get = HotSpotVMField.Type.OFFSET) @Stable public int pendingDeoptimizationOffset; - @HotSpotVMField(name = "ThreadShadow::_pending_failed_speculation", type = "oop", get = HotSpotVMField.Type.OFFSET) @Stable public int pendingFailedSpeculationOffset; - @HotSpotVMField(name = "ThreadShadow::_pending_transfer_to_interpreter", type = "bool", get = HotSpotVMField.Type.OFFSET) @Stable public int pendingTransferToInterpreterOffset; - - /** - * Mark word right shift to get identity hash code. - */ - @HotSpotVMConstant(name = "markOopDesc::hash_shift") @Stable public int identityHashCodeShift; - - /** - * Identity hash code value when uninitialized. - */ - @HotSpotVMConstant(name = "markOopDesc::no_hash") @Stable public int uninitializedIdentityHashCodeValue; - - @HotSpotVMField(name = "Method::_access_flags", type = "AccessFlags", get = HotSpotVMField.Type.OFFSET) @Stable public int methodAccessFlagsOffset; - @HotSpotVMField(name = "Method::_constMethod", type = "ConstMethod*", get = HotSpotVMField.Type.OFFSET) @Stable public int methodConstMethodOffset; - @HotSpotVMField(name = "Method::_intrinsic_id", type = "u1", get = HotSpotVMField.Type.OFFSET) @Stable public int methodIntrinsicIdOffset; - @HotSpotVMField(name = "Method::_flags", type = "u1", get = HotSpotVMField.Type.OFFSET) @Stable public int methodFlagsOffset; - @HotSpotVMField(name = "Method::_vtable_index", type = "int", get = HotSpotVMField.Type.OFFSET) @Stable public int methodVtableIndexOffset; - - @HotSpotVMConstant(name = "Method::_jfr_towrite") @Stable public int methodFlagsJfrTowrite; - @HotSpotVMConstant(name = "Method::_caller_sensitive") @Stable public int methodFlagsCallerSensitive; - @HotSpotVMConstant(name = "Method::_force_inline") @Stable public int methodFlagsForceInline; - @HotSpotVMConstant(name = "Method::_dont_inline") @Stable public int methodFlagsDontInline; - @HotSpotVMConstant(name = "Method::_hidden") @Stable public int methodFlagsHidden; - @HotSpotVMConstant(name = "Method::nonvirtual_vtable_index") @Stable public int nonvirtualVtableIndex; - @HotSpotVMConstant(name = "Method::invalid_vtable_index") @Stable public int invalidVtableIndex; - - @HotSpotVMConstant(name = "InvocationEntryBci") @Stable public int invocationEntryBci; - - @HotSpotVMConstant(name = "JVM_ACC_MONITOR_MATCH") @Stable public int jvmAccMonitorMatch; - @HotSpotVMConstant(name = "JVM_ACC_HAS_MONITOR_BYTECODES") @Stable public int jvmAccHasMonitorBytecodes; - - @HotSpotVMField(name = "JVMCIEnv::_task", type = "CompileTask*", get = HotSpotVMField.Type.OFFSET) @Stable public int jvmciEnvTaskOffset; - @HotSpotVMField(name = "JVMCIEnv::_jvmti_can_hotswap_or_post_breakpoint", type = "bool", get = HotSpotVMField.Type.OFFSET) @Stable public int jvmciEnvJvmtiCanHotswapOrPostBreakpointOffset; - @HotSpotVMField(name = "CompileTask::_num_inlined_bytecodes", type = "int", get = HotSpotVMField.Type.OFFSET) @Stable public int compileTaskNumInlinedBytecodesOffset; - - /** - * Value of Method::extra_stack_entries(). - */ - @HotSpotVMValue(expression = "Method::extra_stack_entries()") @Stable public int extraStackEntries; - - @HotSpotVMField(name = "ConstMethod::_constants", type = "ConstantPool*", get = HotSpotVMField.Type.OFFSET) @Stable public int constMethodConstantsOffset; - @HotSpotVMField(name = "ConstMethod::_flags", type = "u2", get = HotSpotVMField.Type.OFFSET) @Stable public int constMethodFlagsOffset; - @HotSpotVMField(name = "ConstMethod::_code_size", type = "u2", get = HotSpotVMField.Type.OFFSET) @Stable public int constMethodCodeSizeOffset; - @HotSpotVMField(name = "ConstMethod::_name_index", type = "u2", get = HotSpotVMField.Type.OFFSET) @Stable public int constMethodNameIndexOffset; - @HotSpotVMField(name = "ConstMethod::_signature_index", type = "u2", get = HotSpotVMField.Type.OFFSET) @Stable public int constMethodSignatureIndexOffset; - @HotSpotVMField(name = "ConstMethod::_max_stack", type = "u2", get = HotSpotVMField.Type.OFFSET) @Stable public int constMethodMaxStackOffset; - @HotSpotVMField(name = "ConstMethod::_max_locals", type = "u2", get = HotSpotVMField.Type.OFFSET) @Stable public int methodMaxLocalsOffset; - - @HotSpotVMConstant(name = "ConstMethod::_has_linenumber_table") @Stable public int constMethodHasLineNumberTable; - @HotSpotVMConstant(name = "ConstMethod::_has_localvariable_table") @Stable public int constMethodHasLocalVariableTable; - @HotSpotVMConstant(name = "ConstMethod::_has_exception_table") @Stable public int constMethodHasExceptionTable; - - @HotSpotVMType(name = "ExceptionTableElement", get = HotSpotVMType.Type.SIZE) @Stable public int exceptionTableElementSize; - @HotSpotVMField(name = "ExceptionTableElement::start_pc", type = "u2", get = HotSpotVMField.Type.OFFSET) @Stable public int exceptionTableElementStartPcOffset; - @HotSpotVMField(name = "ExceptionTableElement::end_pc", type = "u2", get = HotSpotVMField.Type.OFFSET) @Stable public int exceptionTableElementEndPcOffset; - @HotSpotVMField(name = "ExceptionTableElement::handler_pc", type = "u2", get = HotSpotVMField.Type.OFFSET) @Stable public int exceptionTableElementHandlerPcOffset; - @HotSpotVMField(name = "ExceptionTableElement::catch_type_index", type = "u2", get = HotSpotVMField.Type.OFFSET) @Stable public int exceptionTableElementCatchTypeIndexOffset; - - @HotSpotVMType(name = "LocalVariableTableElement", get = HotSpotVMType.Type.SIZE) @Stable public int localVariableTableElementSize; - @HotSpotVMField(name = "LocalVariableTableElement::start_bci", type = "u2", get = HotSpotVMField.Type.OFFSET) @Stable public int localVariableTableElementStartBciOffset; - @HotSpotVMField(name = "LocalVariableTableElement::length", type = "u2", get = HotSpotVMField.Type.OFFSET) @Stable public int localVariableTableElementLengthOffset; - @HotSpotVMField(name = "LocalVariableTableElement::name_cp_index", type = "u2", get = HotSpotVMField.Type.OFFSET) @Stable public int localVariableTableElementNameCpIndexOffset; - @HotSpotVMField(name = "LocalVariableTableElement::descriptor_cp_index", type = "u2", get = HotSpotVMField.Type.OFFSET) @Stable public int localVariableTableElementDescriptorCpIndexOffset; - @HotSpotVMField(name = "LocalVariableTableElement::signature_cp_index", type = "u2", get = HotSpotVMField.Type.OFFSET) @Stable public int localVariableTableElementSignatureCpIndexOffset; - @HotSpotVMField(name = "LocalVariableTableElement::slot", type = "u2", get = HotSpotVMField.Type.OFFSET) @Stable public int localVariableTableElementSlotOffset; - - @HotSpotVMType(name = "ConstantPool", get = HotSpotVMType.Type.SIZE) @Stable public int constantPoolSize; - @HotSpotVMField(name = "ConstantPool::_tags", type = "Array*", get = HotSpotVMField.Type.OFFSET) @Stable public int constantPoolTagsOffset; - @HotSpotVMField(name = "ConstantPool::_pool_holder", type = "InstanceKlass*", get = HotSpotVMField.Type.OFFSET) @Stable public int constantPoolHolderOffset; - @HotSpotVMField(name = "ConstantPool::_length", type = "int", get = HotSpotVMField.Type.OFFSET) @Stable public int constantPoolLengthOffset; - - @HotSpotVMConstant(name = "ConstantPool::CPCACHE_INDEX_TAG") @Stable public int constantPoolCpCacheIndexTag; - - @HotSpotVMConstant(name = "JVM_CONSTANT_Utf8") @Stable public int jvmConstantUtf8; - @HotSpotVMConstant(name = "JVM_CONSTANT_Integer") @Stable public int jvmConstantInteger; - @HotSpotVMConstant(name = "JVM_CONSTANT_Long") @Stable public int jvmConstantLong; - @HotSpotVMConstant(name = "JVM_CONSTANT_Float") @Stable public int jvmConstantFloat; - @HotSpotVMConstant(name = "JVM_CONSTANT_Double") @Stable public int jvmConstantDouble; - @HotSpotVMConstant(name = "JVM_CONSTANT_Class") @Stable public int jvmConstantClass; - @HotSpotVMConstant(name = "JVM_CONSTANT_UnresolvedClass") @Stable public int jvmConstantUnresolvedClass; - @HotSpotVMConstant(name = "JVM_CONSTANT_UnresolvedClassInError") @Stable public int jvmConstantUnresolvedClassInError; - @HotSpotVMConstant(name = "JVM_CONSTANT_String") @Stable public int jvmConstantString; - @HotSpotVMConstant(name = "JVM_CONSTANT_Fieldref") @Stable public int jvmConstantFieldref; - @HotSpotVMConstant(name = "JVM_CONSTANT_Methodref") @Stable public int jvmConstantMethodref; - @HotSpotVMConstant(name = "JVM_CONSTANT_InterfaceMethodref") @Stable public int jvmConstantInterfaceMethodref; - @HotSpotVMConstant(name = "JVM_CONSTANT_NameAndType") @Stable public int jvmConstantNameAndType; - @HotSpotVMConstant(name = "JVM_CONSTANT_MethodHandle") @Stable public int jvmConstantMethodHandle; - @HotSpotVMConstant(name = "JVM_CONSTANT_MethodHandleInError") @Stable public int jvmConstantMethodHandleInError; - @HotSpotVMConstant(name = "JVM_CONSTANT_MethodType") @Stable public int jvmConstantMethodType; - @HotSpotVMConstant(name = "JVM_CONSTANT_MethodTypeInError") @Stable public int jvmConstantMethodTypeInError; - @HotSpotVMConstant(name = "JVM_CONSTANT_InvokeDynamic") @Stable public int jvmConstantInvokeDynamic; - - @HotSpotVMConstant(name = "JVM_CONSTANT_ExternalMax") @Stable public int jvmConstantExternalMax; - @HotSpotVMConstant(name = "JVM_CONSTANT_InternalMin") @Stable public int jvmConstantInternalMin; - @HotSpotVMConstant(name = "JVM_CONSTANT_InternalMax") @Stable public int jvmConstantInternalMax; - - @HotSpotVMConstant(name = "HeapWordSize") @Stable public int heapWordSize; - - @HotSpotVMType(name = "Symbol*", get = HotSpotVMType.Type.SIZE) @Stable public int symbolPointerSize; - @HotSpotVMField(name = "Symbol::_length", type = "unsigned short", get = HotSpotVMField.Type.OFFSET) @Stable public int symbolLengthOffset; - @HotSpotVMField(name = "Symbol::_body[0]", type = "jbyte", get = HotSpotVMField.Type.OFFSET) @Stable public int symbolBodyOffset; - - @HotSpotVMField(name = "vmSymbols::_symbols[0]", type = "Symbol*", get = HotSpotVMField.Type.ADDRESS) @Stable public long vmSymbolsSymbols; - @HotSpotVMConstant(name = "vmSymbols::FIRST_SID") @Stable public int vmSymbolsFirstSID; - @HotSpotVMConstant(name = "vmSymbols::SID_LIMIT") @Stable public int vmSymbolsSIDLimit; - - @HotSpotVMConstant(name = "JVM_ACC_HAS_FINALIZER") @Stable public int klassHasFinalizerFlag; - - // Modifier.SYNTHETIC is not public so we get it via vmStructs. - @HotSpotVMConstant(name = "JVM_ACC_SYNTHETIC") @Stable public int syntheticFlag; - - /** - * @see HotSpotResolvedObjectTypeImpl#createField - */ - @HotSpotVMConstant(name = "JVM_RECOGNIZED_FIELD_MODIFIERS") @Stable public int recognizedFieldModifiers; - - /** - * Bit pattern that represents a non-oop. Neither the high bits nor the low bits of this value - * are allowed to look like (respectively) the high or low bits of a real oop. - */ - @HotSpotVMField(name = "Universe::_non_oop_bits", type = "intptr_t", get = HotSpotVMField.Type.VALUE) @Stable public long nonOopBits; - - @HotSpotVMField(name = "StubRoutines::_verify_oop_count", type = "jint", get = HotSpotVMField.Type.ADDRESS) @Stable public long verifyOopCounterAddress; - @HotSpotVMValue(expression = "Universe::verify_oop_mask()") @Stable public long verifyOopMask; - @HotSpotVMValue(expression = "Universe::verify_oop_bits()") @Stable public long verifyOopBits; - - @HotSpotVMField(name = "CollectedHeap::_barrier_set", type = "BarrierSet*", get = HotSpotVMField.Type.OFFSET) @Stable public int collectedHeapBarrierSetOffset; - - @HotSpotVMField(name = "HeapRegion::LogOfHRGrainBytes", type = "int", get = HotSpotVMField.Type.VALUE) @Stable public int logOfHRGrainBytes; - - @HotSpotVMField(name = "BarrierSet::_kind", type = "BarrierSet::Name", get = HotSpotVMField.Type.OFFSET) @Stable private int barrierSetKindOffset; - @HotSpotVMConstant(name = "BarrierSet::CardTableModRef") @Stable public int barrierSetCardTableModRef; - @HotSpotVMConstant(name = "BarrierSet::CardTableExtension") @Stable public int barrierSetCardTableExtension; - @HotSpotVMConstant(name = "BarrierSet::G1SATBCT") @Stable public int barrierSetG1SATBCT; - @HotSpotVMConstant(name = "BarrierSet::G1SATBCTLogging") @Stable public int barrierSetG1SATBCTLogging; - @HotSpotVMConstant(name = "BarrierSet::ModRef") @Stable public int barrierSetModRef; - @HotSpotVMConstant(name = "BarrierSet::Other") @Stable public int barrierSetOther; - - @HotSpotVMField(name = "CardTableModRefBS::byte_map_base", type = "jbyte*", get = HotSpotVMField.Type.OFFSET) @Stable private int cardTableModRefBSByteMapBaseOffset; - @HotSpotVMConstant(name = "CardTableModRefBS::card_shift") @Stable public int cardTableModRefBSCardShift; - - @HotSpotVMValue(expression = "(jbyte)CardTableModRefBS::dirty_card_val()") @Stable public byte dirtyCardValue; - @HotSpotVMValue(expression = "(jbyte)G1SATBCardTableModRefBS::g1_young_card_val()") @Stable public byte g1YoungCardValue; - - private final long cardtableStartAddress; - private final int cardtableShift; - - public long cardtableStartAddress() { - if (cardtableStartAddress == -1) { - throw JVMCIError.shouldNotReachHere(); - } - return cardtableStartAddress; - } - - public int cardtableShift() { - if (cardtableShift == -1) { - throw JVMCIError.shouldNotReachHere(); - } - return cardtableShift; - } - - @HotSpotVMField(name = "os::_polling_page", type = "address", get = HotSpotVMField.Type.VALUE) @Stable public long safepointPollingAddress; - - // G1 Collector Related Values. - - public int g1CardQueueIndexOffset() { - return javaThreadDirtyCardQueueOffset + ptrQueueIndexOffset; - } - - public int g1CardQueueBufferOffset() { - return javaThreadDirtyCardQueueOffset + ptrQueueBufferOffset; - } - - public int g1SATBQueueMarkingOffset() { - return javaThreadSatbMarkQueueOffset + ptrQueueActiveOffset; - } - - public int g1SATBQueueIndexOffset() { - return javaThreadSatbMarkQueueOffset + ptrQueueIndexOffset; - } - - public int g1SATBQueueBufferOffset() { - return javaThreadSatbMarkQueueOffset + ptrQueueBufferOffset; - } - - @HotSpotVMField(name = "java_lang_Class::_klass_offset", type = "int", get = HotSpotVMField.Type.VALUE) @Stable public int klassOffset; - @HotSpotVMField(name = "java_lang_Class::_array_klass_offset", type = "int", get = HotSpotVMField.Type.VALUE) @Stable public int arrayKlassOffset; - - @HotSpotVMField(name = "Method::_method_data", type = "MethodData*", get = HotSpotVMField.Type.OFFSET) @Stable public int methodDataOffset; - @HotSpotVMField(name = "Method::_from_compiled_entry", type = "address", get = HotSpotVMField.Type.OFFSET) @Stable public int methodCompiledEntryOffset; - @HotSpotVMField(name = "Method::_code", type = "nmethod*", get = HotSpotVMField.Type.OFFSET) @Stable public int methodCodeOffset; - - @HotSpotVMField(name = "MethodData::_size", type = "int", get = HotSpotVMField.Type.OFFSET) @Stable public int methodDataSize; - @HotSpotVMField(name = "MethodData::_data_size", type = "int", get = HotSpotVMField.Type.OFFSET) @Stable public int methodDataDataSize; - @HotSpotVMField(name = "MethodData::_data[0]", type = "intptr_t", get = HotSpotVMField.Type.OFFSET) @Stable public int methodDataOopDataOffset; - @HotSpotVMField(name = "MethodData::_trap_hist._array[0]", type = "u1", get = HotSpotVMField.Type.OFFSET) @Stable public int methodDataOopTrapHistoryOffset; - @HotSpotVMField(name = "MethodData::_jvmci_ir_size", type = "int", get = HotSpotVMField.Type.OFFSET) @Stable public int methodDataIRSizeOffset; - - @HotSpotVMField(name = "nmethod::_verified_entry_point", type = "address", get = HotSpotVMField.Type.OFFSET) @Stable public int nmethodEntryOffset; - @HotSpotVMField(name = "nmethod::_comp_level", type = "int", get = HotSpotVMField.Type.OFFSET) @Stable public int nmethodCompLevelOffset; - - @HotSpotVMConstant(name = "CompLevel_full_optimization") @Stable public int compilationLevelFullOptimization; - - @HotSpotVMType(name = "BasicLock", get = HotSpotVMType.Type.SIZE) @Stable public int basicLockSize; - @HotSpotVMField(name = "BasicLock::_displaced_header", type = "markOop", get = HotSpotVMField.Type.OFFSET) @Stable public int basicLockDisplacedHeaderOffset; - - @HotSpotVMValue(expression = "Universe::heap()->supports_inline_contig_alloc() ? Universe::heap()->end_addr() : (HeapWord**)-1", get = HotSpotVMValue.Type.ADDRESS) @Stable public long heapEndAddress; - @HotSpotVMValue(expression = "Universe::heap()->supports_inline_contig_alloc() ? Universe::heap()->top_addr() : (HeapWord**)-1", get = HotSpotVMValue.Type.ADDRESS) @Stable public long heapTopAddress; - - @HotSpotVMField(name = "Thread::_allocated_bytes", type = "jlong", get = HotSpotVMField.Type.OFFSET) @Stable public int threadAllocatedBytesOffset; - - @HotSpotVMFlag(name = "TLABWasteIncrement") @Stable public int tlabRefillWasteIncrement; - @HotSpotVMValue(expression = "ThreadLocalAllocBuffer::alignment_reserve()") @Stable public int tlabAlignmentReserve; - - @HotSpotVMField(name = "ThreadLocalAllocBuffer::_start", type = "HeapWord*", get = HotSpotVMField.Type.OFFSET) @Stable private int threadLocalAllocBufferStartOffset; - @HotSpotVMField(name = "ThreadLocalAllocBuffer::_end", type = "HeapWord*", get = HotSpotVMField.Type.OFFSET) @Stable private int threadLocalAllocBufferEndOffset; - @HotSpotVMField(name = "ThreadLocalAllocBuffer::_top", type = "HeapWord*", get = HotSpotVMField.Type.OFFSET) @Stable private int threadLocalAllocBufferTopOffset; - @HotSpotVMField(name = "ThreadLocalAllocBuffer::_pf_top", type = "HeapWord*", get = HotSpotVMField.Type.OFFSET) @Stable private int threadLocalAllocBufferPfTopOffset; - @HotSpotVMField(name = "ThreadLocalAllocBuffer::_slow_allocations", type = "unsigned", get = HotSpotVMField.Type.OFFSET) @Stable private int threadLocalAllocBufferSlowAllocationsOffset; - @HotSpotVMField(name = "ThreadLocalAllocBuffer::_fast_refill_waste", type = "unsigned", get = HotSpotVMField.Type.OFFSET) @Stable private int threadLocalAllocBufferFastRefillWasteOffset; - @HotSpotVMField(name = "ThreadLocalAllocBuffer::_number_of_refills", type = "unsigned", get = HotSpotVMField.Type.OFFSET) @Stable private int threadLocalAllocBufferNumberOfRefillsOffset; - @HotSpotVMField(name = "ThreadLocalAllocBuffer::_refill_waste_limit", type = "size_t", get = HotSpotVMField.Type.OFFSET) @Stable private int threadLocalAllocBufferRefillWasteLimitOffset; - @HotSpotVMField(name = "ThreadLocalAllocBuffer::_desired_size", type = "size_t", get = HotSpotVMField.Type.OFFSET) @Stable private int threadLocalAllocBufferDesiredSizeOffset; - - public int tlabSlowAllocationsOffset() { - return threadTlabOffset + threadLocalAllocBufferSlowAllocationsOffset; - } - - public int tlabFastRefillWasteOffset() { - return threadTlabOffset + threadLocalAllocBufferFastRefillWasteOffset; - } - - public int tlabNumberOfRefillsOffset() { - return threadTlabOffset + threadLocalAllocBufferNumberOfRefillsOffset; - } - - public int tlabRefillWasteLimitOffset() { - return threadTlabOffset + threadLocalAllocBufferRefillWasteLimitOffset; - } - - public int threadTlabSizeOffset() { - return threadTlabOffset + threadLocalAllocBufferDesiredSizeOffset; - } - - public int threadTlabStartOffset() { - return threadTlabOffset + threadLocalAllocBufferStartOffset; - } - - public int threadTlabEndOffset() { - return threadTlabOffset + threadLocalAllocBufferEndOffset; - } - - public int threadTlabTopOffset() { - return threadTlabOffset + threadLocalAllocBufferTopOffset; - } - - public int threadTlabPfTopOffset() { - return threadTlabOffset + threadLocalAllocBufferPfTopOffset; - } - - @HotSpotVMFlag(name = "TLABStats") @Stable public boolean tlabStats; - @HotSpotVMValue(expression = " !CMSIncrementalMode && Universe::heap()->supports_inline_contig_alloc()") @Stable public boolean inlineContiguousAllocationSupported; - - /** - * The DataLayout header size is the same as the cell size. - */ - @HotSpotVMConstant(name = "DataLayout::cell_size") @Stable public int dataLayoutHeaderSize; - @HotSpotVMField(name = "DataLayout::_header._struct._tag", type = "u1", get = HotSpotVMField.Type.OFFSET) @Stable public int dataLayoutTagOffset; - @HotSpotVMField(name = "DataLayout::_header._struct._flags", type = "u1", get = HotSpotVMField.Type.OFFSET) @Stable public int dataLayoutFlagsOffset; - @HotSpotVMField(name = "DataLayout::_header._struct._bci", type = "u2", get = HotSpotVMField.Type.OFFSET) @Stable public int dataLayoutBCIOffset; - @HotSpotVMField(name = "DataLayout::_cells[0]", type = "intptr_t", get = HotSpotVMField.Type.OFFSET) @Stable public int dataLayoutCellsOffset; - @HotSpotVMConstant(name = "DataLayout::cell_size") @Stable public int dataLayoutCellSize; - - @HotSpotVMConstant(name = "DataLayout::no_tag") @Stable public int dataLayoutNoTag; - @HotSpotVMConstant(name = "DataLayout::bit_data_tag") @Stable public int dataLayoutBitDataTag; - @HotSpotVMConstant(name = "DataLayout::counter_data_tag") @Stable public int dataLayoutCounterDataTag; - @HotSpotVMConstant(name = "DataLayout::jump_data_tag") @Stable public int dataLayoutJumpDataTag; - @HotSpotVMConstant(name = "DataLayout::receiver_type_data_tag") @Stable public int dataLayoutReceiverTypeDataTag; - @HotSpotVMConstant(name = "DataLayout::virtual_call_data_tag") @Stable public int dataLayoutVirtualCallDataTag; - @HotSpotVMConstant(name = "DataLayout::ret_data_tag") @Stable public int dataLayoutRetDataTag; - @HotSpotVMConstant(name = "DataLayout::branch_data_tag") @Stable public int dataLayoutBranchDataTag; - @HotSpotVMConstant(name = "DataLayout::multi_branch_data_tag") @Stable public int dataLayoutMultiBranchDataTag; - @HotSpotVMConstant(name = "DataLayout::arg_info_data_tag") @Stable public int dataLayoutArgInfoDataTag; - @HotSpotVMConstant(name = "DataLayout::call_type_data_tag") @Stable public int dataLayoutCallTypeDataTag; - @HotSpotVMConstant(name = "DataLayout::virtual_call_type_data_tag") @Stable public int dataLayoutVirtualCallTypeDataTag; - @HotSpotVMConstant(name = "DataLayout::parameters_type_data_tag") @Stable public int dataLayoutParametersTypeDataTag; - @HotSpotVMConstant(name = "DataLayout::speculative_trap_data_tag") @Stable public int dataLayoutSpeculativeTrapDataTag; - - @HotSpotVMFlag(name = "BciProfileWidth") @Stable public int bciProfileWidth; - @HotSpotVMFlag(name = "TypeProfileWidth") @Stable public int typeProfileWidth; - @HotSpotVMFlag(name = "MethodProfileWidth") @Stable public int methodProfileWidth; - - @HotSpotVMField(name = "CodeBlob::_code_offset", type = "int", get = HotSpotVMField.Type.OFFSET) @Stable private int codeBlobCodeOffsetOffset; - @HotSpotVMField(name = "SharedRuntime::_ic_miss_blob", type = "RuntimeStub*", get = HotSpotVMField.Type.VALUE) @Stable private long inlineCacheMissBlob; - - @HotSpotVMValue(expression = "SharedRuntime::deopt_blob()->unpack()", get = HotSpotVMValue.Type.ADDRESS) @Stable public long handleDeoptStub; - @HotSpotVMValue(expression = "SharedRuntime::deopt_blob()->uncommon_trap()", get = HotSpotVMValue.Type.ADDRESS) @Stable public long uncommonTrapStub; - - private final long inlineCacheMissStub; - - public long inlineCacheMissStub() { - return inlineCacheMissStub; - } - - @HotSpotVMField(name = "CodeCache::_heap", type = "CodeHeap*", get = HotSpotVMField.Type.VALUE) @Stable private long codeCacheHeap; - @HotSpotVMField(name = "CodeHeap::_memory", type = "VirtualSpace", get = HotSpotVMField.Type.OFFSET) @Stable private int codeHeapMemoryOffset; - @HotSpotVMField(name = "VirtualSpace::_low_boundary", type = "char*", get = HotSpotVMField.Type.OFFSET) @Stable private int virtualSpaceLowBoundaryOffset; - @HotSpotVMField(name = "VirtualSpace::_high_boundary", type = "char*", get = HotSpotVMField.Type.OFFSET) @Stable private int virtualSpaceHighBoundaryOffset; - - private final long codeCacheLowBoundary; - private final long codeCacheHighBoundary; - - /** - * @return CodeCache::_heap->_memory._low_boundary - */ - public long codeCacheLowBoundary() { - return codeCacheLowBoundary; - } - - /** - * @return CodeCache::_heap->_memory._high_boundary - */ - public long codeCacheHighBoundary() { - return codeCacheHighBoundary; - } - - @HotSpotVMField(name = "StubRoutines::_aescrypt_encryptBlock", type = "address", get = HotSpotVMField.Type.VALUE) @Stable public long aescryptEncryptBlockStub; - @HotSpotVMField(name = "StubRoutines::_aescrypt_decryptBlock", type = "address", get = HotSpotVMField.Type.VALUE) @Stable public long aescryptDecryptBlockStub; - @HotSpotVMField(name = "StubRoutines::_cipherBlockChaining_encryptAESCrypt", type = "address", get = HotSpotVMField.Type.VALUE) @Stable public long cipherBlockChainingEncryptAESCryptStub; - @HotSpotVMField(name = "StubRoutines::_cipherBlockChaining_decryptAESCrypt", type = "address", get = HotSpotVMField.Type.VALUE) @Stable public long cipherBlockChainingDecryptAESCryptStub; - @HotSpotVMField(name = "StubRoutines::_updateBytesCRC32", type = "address", get = HotSpotVMField.Type.VALUE) @Stable public long updateBytesCRC32Stub; - @HotSpotVMField(name = "StubRoutines::_crc_table_adr", type = "address", get = HotSpotVMField.Type.VALUE) @Stable public long crcTableAddress; - - @HotSpotVMField(name = "StubRoutines::_jbyte_arraycopy", type = "address", get = HotSpotVMField.Type.VALUE) @Stable public long jbyteArraycopy; - @HotSpotVMField(name = "StubRoutines::_jshort_arraycopy", type = "address", get = HotSpotVMField.Type.VALUE) @Stable public long jshortArraycopy; - @HotSpotVMField(name = "StubRoutines::_jint_arraycopy", type = "address", get = HotSpotVMField.Type.VALUE) @Stable public long jintArraycopy; - @HotSpotVMField(name = "StubRoutines::_jlong_arraycopy", type = "address", get = HotSpotVMField.Type.VALUE) @Stable public long jlongArraycopy; - @HotSpotVMField(name = "StubRoutines::_oop_arraycopy", type = "address", get = HotSpotVMField.Type.VALUE) @Stable public long oopArraycopy; - @HotSpotVMField(name = "StubRoutines::_oop_arraycopy_uninit", type = "address", get = HotSpotVMField.Type.VALUE) @Stable public long oopArraycopyUninit; - @HotSpotVMField(name = "StubRoutines::_jbyte_disjoint_arraycopy", type = "address", get = HotSpotVMField.Type.VALUE) @Stable public long jbyteDisjointArraycopy; - @HotSpotVMField(name = "StubRoutines::_jshort_disjoint_arraycopy", type = "address", get = HotSpotVMField.Type.VALUE) @Stable public long jshortDisjointArraycopy; - @HotSpotVMField(name = "StubRoutines::_jint_disjoint_arraycopy", type = "address", get = HotSpotVMField.Type.VALUE) @Stable public long jintDisjointArraycopy; - @HotSpotVMField(name = "StubRoutines::_jlong_disjoint_arraycopy", type = "address", get = HotSpotVMField.Type.VALUE) @Stable public long jlongDisjointArraycopy; - @HotSpotVMField(name = "StubRoutines::_oop_disjoint_arraycopy", type = "address", get = HotSpotVMField.Type.VALUE) @Stable public long oopDisjointArraycopy; - @HotSpotVMField(name = "StubRoutines::_oop_disjoint_arraycopy_uninit", type = "address", get = HotSpotVMField.Type.VALUE) @Stable public long oopDisjointArraycopyUninit; - @HotSpotVMField(name = "StubRoutines::_arrayof_jbyte_arraycopy", type = "address", get = HotSpotVMField.Type.VALUE) @Stable public long jbyteAlignedArraycopy; - @HotSpotVMField(name = "StubRoutines::_arrayof_jshort_arraycopy", type = "address", get = HotSpotVMField.Type.VALUE) @Stable public long jshortAlignedArraycopy; - @HotSpotVMField(name = "StubRoutines::_arrayof_jint_arraycopy", type = "address", get = HotSpotVMField.Type.VALUE) @Stable public long jintAlignedArraycopy; - @HotSpotVMField(name = "StubRoutines::_arrayof_jlong_arraycopy", type = "address", get = HotSpotVMField.Type.VALUE) @Stable public long jlongAlignedArraycopy; - @HotSpotVMField(name = "StubRoutines::_arrayof_oop_arraycopy", type = "address", get = HotSpotVMField.Type.VALUE) @Stable public long oopAlignedArraycopy; - @HotSpotVMField(name = "StubRoutines::_arrayof_oop_arraycopy_uninit", type = "address", get = HotSpotVMField.Type.VALUE) @Stable public long oopAlignedArraycopyUninit; - @HotSpotVMField(name = "StubRoutines::_arrayof_jbyte_disjoint_arraycopy", type = "address", get = HotSpotVMField.Type.VALUE) @Stable public long jbyteAlignedDisjointArraycopy; - @HotSpotVMField(name = "StubRoutines::_arrayof_jshort_disjoint_arraycopy", type = "address", get = HotSpotVMField.Type.VALUE) @Stable public long jshortAlignedDisjointArraycopy; - @HotSpotVMField(name = "StubRoutines::_arrayof_jint_disjoint_arraycopy", type = "address", get = HotSpotVMField.Type.VALUE) @Stable public long jintAlignedDisjointArraycopy; - @HotSpotVMField(name = "StubRoutines::_arrayof_jlong_disjoint_arraycopy", type = "address", get = HotSpotVMField.Type.VALUE) @Stable public long jlongAlignedDisjointArraycopy; - @HotSpotVMField(name = "StubRoutines::_arrayof_oop_disjoint_arraycopy", type = "address", get = HotSpotVMField.Type.VALUE) @Stable public long oopAlignedDisjointArraycopy; - @HotSpotVMField(name = "StubRoutines::_arrayof_oop_disjoint_arraycopy_uninit", type = "address", get = HotSpotVMField.Type.VALUE) @Stable public long oopAlignedDisjointArraycopyUninit; - @HotSpotVMField(name = "StubRoutines::_checkcast_arraycopy", type = "address", get = HotSpotVMField.Type.VALUE) @Stable public long checkcastArraycopy; - @HotSpotVMField(name = "StubRoutines::_checkcast_arraycopy_uninit", type = "address", get = HotSpotVMField.Type.VALUE) @Stable public long checkcastArraycopyUninit; - @HotSpotVMField(name = "StubRoutines::_unsafe_arraycopy", type = "address", get = HotSpotVMField.Type.VALUE) @Stable public long unsafeArraycopy; - @HotSpotVMField(name = "StubRoutines::_generic_arraycopy", type = "address", get = HotSpotVMField.Type.VALUE) @Stable public long genericArraycopy; - - @HotSpotVMValue(expression = "JVMCIRuntime::new_instance", get = HotSpotVMValue.Type.ADDRESS) @Stable public long newInstanceAddress; - @HotSpotVMValue(expression = "JVMCIRuntime::new_array", get = HotSpotVMValue.Type.ADDRESS) @Stable public long newArrayAddress; - @HotSpotVMValue(expression = "JVMCIRuntime::new_multi_array", get = HotSpotVMValue.Type.ADDRESS) @Stable public long newMultiArrayAddress; - @HotSpotVMValue(expression = "JVMCIRuntime::dynamic_new_array", get = HotSpotVMValue.Type.ADDRESS) @Stable public long dynamicNewArrayAddress; - @HotSpotVMValue(expression = "JVMCIRuntime::dynamic_new_instance", get = HotSpotVMValue.Type.ADDRESS) @Stable public long dynamicNewInstanceAddress; - @HotSpotVMValue(expression = "JVMCIRuntime::thread_is_interrupted", get = HotSpotVMValue.Type.ADDRESS) @Stable public long threadIsInterruptedAddress; - @HotSpotVMValue(expression = "JVMCIRuntime::vm_message", signature = "(unsigned char, long, long, long, long)", get = HotSpotVMValue.Type.ADDRESS) @Stable public long vmMessageAddress; - @HotSpotVMValue(expression = "JVMCIRuntime::identity_hash_code", get = HotSpotVMValue.Type.ADDRESS) @Stable public long identityHashCodeAddress; - @HotSpotVMValue(expression = "JVMCIRuntime::exception_handler_for_pc", signature = "(JavaThread*)", get = HotSpotVMValue.Type.ADDRESS) @Stable public long exceptionHandlerForPcAddress; - @HotSpotVMValue(expression = "JVMCIRuntime::monitorenter", get = HotSpotVMValue.Type.ADDRESS) @Stable public long monitorenterAddress; - @HotSpotVMValue(expression = "JVMCIRuntime::monitorexit", get = HotSpotVMValue.Type.ADDRESS) @Stable public long monitorexitAddress; - @HotSpotVMValue(expression = "JVMCIRuntime::create_null_exception", get = HotSpotVMValue.Type.ADDRESS) @Stable public long createNullPointerExceptionAddress; - @HotSpotVMValue(expression = "JVMCIRuntime::create_out_of_bounds_exception", get = HotSpotVMValue.Type.ADDRESS) @Stable public long createOutOfBoundsExceptionAddress; - @HotSpotVMValue(expression = "JVMCIRuntime::log_primitive", get = HotSpotVMValue.Type.ADDRESS) @Stable public long logPrimitiveAddress; - @HotSpotVMValue(expression = "JVMCIRuntime::log_object", get = HotSpotVMValue.Type.ADDRESS) @Stable public long logObjectAddress; - @HotSpotVMValue(expression = "JVMCIRuntime::log_printf", get = HotSpotVMValue.Type.ADDRESS) @Stable public long logPrintfAddress; - @HotSpotVMValue(expression = "JVMCIRuntime::vm_error", get = HotSpotVMValue.Type.ADDRESS) @Stable public long vmErrorAddress; - @HotSpotVMValue(expression = "JVMCIRuntime::load_and_clear_exception", get = HotSpotVMValue.Type.ADDRESS) @Stable public long loadAndClearExceptionAddress; - @HotSpotVMValue(expression = "JVMCIRuntime::write_barrier_pre", get = HotSpotVMValue.Type.ADDRESS) @Stable public long writeBarrierPreAddress; - @HotSpotVMValue(expression = "JVMCIRuntime::write_barrier_post", get = HotSpotVMValue.Type.ADDRESS) @Stable public long writeBarrierPostAddress; - @HotSpotVMValue(expression = "JVMCIRuntime::validate_object", get = HotSpotVMValue.Type.ADDRESS) @Stable public long validateObject; - - @HotSpotVMValue(expression = "JVMCIRuntime::test_deoptimize_call_int", get = HotSpotVMValue.Type.ADDRESS) @Stable public long testDeoptimizeCallInt; - - @HotSpotVMValue(expression = "SharedRuntime::register_finalizer", get = HotSpotVMValue.Type.ADDRESS) @Stable public long registerFinalizerAddress; - @HotSpotVMValue(expression = "SharedRuntime::exception_handler_for_return_address", get = HotSpotVMValue.Type.ADDRESS) @Stable public long exceptionHandlerForReturnAddressAddress; - @HotSpotVMValue(expression = "SharedRuntime::OSR_migration_end", get = HotSpotVMValue.Type.ADDRESS) @Stable public long osrMigrationEndAddress; - - @HotSpotVMValue(expression = "os::javaTimeMillis", get = HotSpotVMValue.Type.ADDRESS) @Stable public long javaTimeMillisAddress; - @HotSpotVMValue(expression = "os::javaTimeNanos", get = HotSpotVMValue.Type.ADDRESS) @Stable public long javaTimeNanosAddress; - @HotSpotVMValue(expression = "SharedRuntime::dsin", get = HotSpotVMValue.Type.ADDRESS) @Stable public long arithmeticSinAddress; - @HotSpotVMValue(expression = "SharedRuntime::dcos", get = HotSpotVMValue.Type.ADDRESS) @Stable public long arithmeticCosAddress; - @HotSpotVMValue(expression = "SharedRuntime::dtan", get = HotSpotVMValue.Type.ADDRESS) @Stable public long arithmeticTanAddress; - @HotSpotVMValue(expression = "SharedRuntime::dexp", get = HotSpotVMValue.Type.ADDRESS) @Stable public long arithmeticExpAddress; - @HotSpotVMValue(expression = "SharedRuntime::dlog", get = HotSpotVMValue.Type.ADDRESS) @Stable public long arithmeticLogAddress; - @HotSpotVMValue(expression = "SharedRuntime::dlog10", get = HotSpotVMValue.Type.ADDRESS) @Stable public long arithmeticLog10Address; - @HotSpotVMValue(expression = "SharedRuntime::dpow", get = HotSpotVMValue.Type.ADDRESS) @Stable public long arithmeticPowAddress; - - @HotSpotVMValue(expression = "(jint) JVMCICounterSize") @Stable public int jvmciCountersSize; - - @HotSpotVMValue(expression = "Deoptimization::fetch_unroll_info", signature = "(JavaThread*)", get = HotSpotVMValue.Type.ADDRESS) @Stable public long deoptimizationFetchUnrollInfo; - @HotSpotVMValue(expression = "Deoptimization::uncommon_trap", get = HotSpotVMValue.Type.ADDRESS) @Stable public long deoptimizationUncommonTrap; - @HotSpotVMValue(expression = "Deoptimization::unpack_frames", signature = "(JavaThread*, int)", get = HotSpotVMValue.Type.ADDRESS) @Stable public long deoptimizationUnpackFrames; - - @HotSpotVMConstant(name = "Deoptimization::Reason_none") @Stable public int deoptReasonNone; - @HotSpotVMConstant(name = "Deoptimization::Reason_null_check") @Stable public int deoptReasonNullCheck; - @HotSpotVMConstant(name = "Deoptimization::Reason_range_check") @Stable public int deoptReasonRangeCheck; - @HotSpotVMConstant(name = "Deoptimization::Reason_class_check") @Stable public int deoptReasonClassCheck; - @HotSpotVMConstant(name = "Deoptimization::Reason_array_check") @Stable public int deoptReasonArrayCheck; - @HotSpotVMConstant(name = "Deoptimization::Reason_unreached0") @Stable public int deoptReasonUnreached0; - @HotSpotVMConstant(name = "Deoptimization::Reason_type_checked_inlining") @Stable public int deoptReasonTypeCheckInlining; - @HotSpotVMConstant(name = "Deoptimization::Reason_optimized_type_check") @Stable public int deoptReasonOptimizedTypeCheck; - @HotSpotVMConstant(name = "Deoptimization::Reason_not_compiled_exception_handler") @Stable public int deoptReasonNotCompiledExceptionHandler; - @HotSpotVMConstant(name = "Deoptimization::Reason_unresolved") @Stable public int deoptReasonUnresolved; - @HotSpotVMConstant(name = "Deoptimization::Reason_jsr_mismatch") @Stable public int deoptReasonJsrMismatch; - @HotSpotVMConstant(name = "Deoptimization::Reason_div0_check") @Stable public int deoptReasonDiv0Check; - @HotSpotVMConstant(name = "Deoptimization::Reason_constraint") @Stable public int deoptReasonConstraint; - @HotSpotVMConstant(name = "Deoptimization::Reason_loop_limit_check") @Stable public int deoptReasonLoopLimitCheck; - @HotSpotVMConstant(name = "Deoptimization::Reason_aliasing") @Stable public int deoptReasonAliasing; - @HotSpotVMConstant(name = "Deoptimization::Reason_transfer_to_interpreter") @Stable public int deoptReasonTransferToInterpreter; - @HotSpotVMConstant(name = "Deoptimization::Reason_LIMIT") @Stable public int deoptReasonOSROffset; - - @HotSpotVMConstant(name = "Deoptimization::Action_none") @Stable public int deoptActionNone; - @HotSpotVMConstant(name = "Deoptimization::Action_maybe_recompile") @Stable public int deoptActionMaybeRecompile; - @HotSpotVMConstant(name = "Deoptimization::Action_reinterpret") @Stable public int deoptActionReinterpret; - @HotSpotVMConstant(name = "Deoptimization::Action_make_not_entrant") @Stable public int deoptActionMakeNotEntrant; - @HotSpotVMConstant(name = "Deoptimization::Action_make_not_compilable") @Stable public int deoptActionMakeNotCompilable; - - @HotSpotVMConstant(name = "Deoptimization::_action_bits") @Stable public int deoptimizationActionBits; - @HotSpotVMConstant(name = "Deoptimization::_reason_bits") @Stable public int deoptimizationReasonBits; - @HotSpotVMConstant(name = "Deoptimization::_debug_id_bits") @Stable public int deoptimizationDebugIdBits; - @HotSpotVMConstant(name = "Deoptimization::_action_shift") @Stable public int deoptimizationActionShift; - @HotSpotVMConstant(name = "Deoptimization::_reason_shift") @Stable public int deoptimizationReasonShift; - @HotSpotVMConstant(name = "Deoptimization::_debug_id_shift") @Stable public int deoptimizationDebugIdShift; - - @HotSpotVMConstant(name = "Deoptimization::Unpack_deopt") @Stable public int deoptimizationUnpackDeopt; - @HotSpotVMConstant(name = "Deoptimization::Unpack_exception") @Stable public int deoptimizationUnpackException; - @HotSpotVMConstant(name = "Deoptimization::Unpack_uncommon_trap") @Stable public int deoptimizationUnpackUncommonTrap; - @HotSpotVMConstant(name = "Deoptimization::Unpack_reexecute") @Stable public int deoptimizationUnpackReexecute; - - @HotSpotVMField(name = "Deoptimization::UnrollBlock::_size_of_deoptimized_frame", type = "int", get = HotSpotVMField.Type.OFFSET) @Stable public int deoptimizationUnrollBlockSizeOfDeoptimizedFrameOffset; - @HotSpotVMField(name = "Deoptimization::UnrollBlock::_caller_adjustment", type = "int", get = HotSpotVMField.Type.OFFSET) @Stable public int deoptimizationUnrollBlockCallerAdjustmentOffset; - @HotSpotVMField(name = "Deoptimization::UnrollBlock::_number_of_frames", type = "int", get = HotSpotVMField.Type.OFFSET) @Stable public int deoptimizationUnrollBlockNumberOfFramesOffset; - @HotSpotVMField(name = "Deoptimization::UnrollBlock::_total_frame_sizes", type = "int", get = HotSpotVMField.Type.OFFSET) @Stable public int deoptimizationUnrollBlockTotalFrameSizesOffset; - @HotSpotVMField(name = "Deoptimization::UnrollBlock::_frame_sizes", type = "intptr_t*", get = HotSpotVMField.Type.OFFSET) @Stable public int deoptimizationUnrollBlockFrameSizesOffset; - @HotSpotVMField(name = "Deoptimization::UnrollBlock::_frame_pcs", type = "address*", get = HotSpotVMField.Type.OFFSET) @Stable public int deoptimizationUnrollBlockFramePcsOffset; - @HotSpotVMField(name = "Deoptimization::UnrollBlock::_initial_info", type = "intptr_t", get = HotSpotVMField.Type.OFFSET) @Stable public int deoptimizationUnrollBlockInitialInfoOffset; - - @HotSpotVMConstant(name = "vmIntrinsics::_invokeBasic") @Stable public int vmIntrinsicInvokeBasic; - @HotSpotVMConstant(name = "vmIntrinsics::_linkToVirtual") @Stable public int vmIntrinsicLinkToVirtual; - @HotSpotVMConstant(name = "vmIntrinsics::_linkToStatic") @Stable public int vmIntrinsicLinkToStatic; - @HotSpotVMConstant(name = "vmIntrinsics::_linkToSpecial") @Stable public int vmIntrinsicLinkToSpecial; - @HotSpotVMConstant(name = "vmIntrinsics::_linkToInterface") @Stable public int vmIntrinsicLinkToInterface; - - @HotSpotVMConstant(name = "JVMCIEnv::ok") @Stable public int codeInstallResultOk; - @HotSpotVMConstant(name = "JVMCIEnv::dependencies_failed") @Stable public int codeInstallResultDependenciesFailed; - @HotSpotVMConstant(name = "JVMCIEnv::dependencies_invalid") @Stable public int codeInstallResultDependenciesInvalid; - @HotSpotVMConstant(name = "JVMCIEnv::cache_full") @Stable public int codeInstallResultCacheFull; - @HotSpotVMConstant(name = "JVMCIEnv::code_too_large") @Stable public int codeInstallResultCodeTooLarge; - - public String getCodeInstallResultDescription(int codeInstallResult) { - if (codeInstallResult == codeInstallResultOk) { - return "ok"; - } - if (codeInstallResult == codeInstallResultDependenciesFailed) { - return "dependencies failed"; - } - if (codeInstallResult == codeInstallResultDependenciesInvalid) { - return "dependencies invalid"; - } - if (codeInstallResult == codeInstallResultCacheFull) { - return "code cache is full"; - } - if (codeInstallResult == codeInstallResultCodeTooLarge) { - return "code is too large"; - } - assert false : codeInstallResult; - return "unknown"; - } - - @HotSpotVMConstant(name = "CompilerToVM::KLASS_TAG") @Stable public int compilerToVMKlassTag; - @HotSpotVMConstant(name = "CompilerToVM::SYMBOL_TAG") @Stable public int compilerToVMSymbolTag; - - // Checkstyle: stop - @HotSpotVMConstant(name = "CodeInstaller::VERIFIED_ENTRY") @Stable public int MARKID_VERIFIED_ENTRY; - @HotSpotVMConstant(name = "CodeInstaller::UNVERIFIED_ENTRY") @Stable public int MARKID_UNVERIFIED_ENTRY; - @HotSpotVMConstant(name = "CodeInstaller::OSR_ENTRY") @Stable public int MARKID_OSR_ENTRY; - @HotSpotVMConstant(name = "CodeInstaller::EXCEPTION_HANDLER_ENTRY") @Stable public int MARKID_EXCEPTION_HANDLER_ENTRY; - @HotSpotVMConstant(name = "CodeInstaller::DEOPT_HANDLER_ENTRY") @Stable public int MARKID_DEOPT_HANDLER_ENTRY; - @HotSpotVMConstant(name = "CodeInstaller::INVOKEINTERFACE") @Stable public int MARKID_INVOKEINTERFACE; - @HotSpotVMConstant(name = "CodeInstaller::INVOKEVIRTUAL") @Stable public int MARKID_INVOKEVIRTUAL; - @HotSpotVMConstant(name = "CodeInstaller::INVOKESTATIC") @Stable public int MARKID_INVOKESTATIC; - @HotSpotVMConstant(name = "CodeInstaller::INVOKESPECIAL") @Stable public int MARKID_INVOKESPECIAL; - @HotSpotVMConstant(name = "CodeInstaller::INLINE_INVOKE") @Stable public int MARKID_INLINE_INVOKE; - @HotSpotVMConstant(name = "CodeInstaller::POLL_NEAR") @Stable public int MARKID_POLL_NEAR; - @HotSpotVMConstant(name = "CodeInstaller::POLL_RETURN_NEAR") @Stable public int MARKID_POLL_RETURN_NEAR; - @HotSpotVMConstant(name = "CodeInstaller::POLL_FAR") @Stable public int MARKID_POLL_FAR; - @HotSpotVMConstant(name = "CodeInstaller::POLL_RETURN_FAR") @Stable public int MARKID_POLL_RETURN_FAR; - @HotSpotVMConstant(name = "CodeInstaller::CARD_TABLE_SHIFT") @Stable public int MARKID_CARD_TABLE_SHIFT; - @HotSpotVMConstant(name = "CodeInstaller::CARD_TABLE_ADDRESS") @Stable public int MARKID_CARD_TABLE_ADDRESS; - @HotSpotVMConstant(name = "CodeInstaller::INVOKE_INVALID") @Stable public int MARKID_INVOKE_INVALID; - - // Checkstyle: resume - - public boolean check() { - for (Field f : getClass().getDeclaredFields()) { - int modifiers = f.getModifiers(); - if (Modifier.isPublic(modifiers) && !Modifier.isStatic(modifiers)) { - assert Modifier.isFinal(modifiers) || f.getAnnotation(Stable.class) != null : "field should either be final or @Stable: " + f; - } - } - - assert codeEntryAlignment > 0 : codeEntryAlignment; - assert (layoutHelperArrayTagObjectValue & (1 << (Integer.SIZE - 1))) != 0 : "object array must have first bit set"; - assert (layoutHelperArrayTagTypeValue & (1 << (Integer.SIZE - 1))) != 0 : "type array must have first bit set"; - - return true; - } - - /** - * A compact representation of the different encoding strategies for Objects and metadata. - */ - public static class CompressEncoding { - public final long base; - public final int shift; - public final int alignment; - - CompressEncoding(long base, int shift, int alignment) { - this.base = base; - this.shift = shift; - this.alignment = alignment; - } - - public int compress(long ptr) { - if (ptr == 0L) { - return 0; - } else { - return (int) ((ptr - base) >>> shift); - } - } - - public long uncompress(int ptr) { - if (ptr == 0) { - return 0L; - } else { - return ((ptr & 0xFFFFFFFFL) << shift) + base; - } - } - - @Override - public String toString() { - return "base: " + base + " shift: " + shift + " alignment: " + alignment; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + alignment; - result = prime * result + (int) (base ^ (base >>> 32)); - result = prime * result + shift; - return result; - } - - @Override - public boolean equals(Object obj) { - if (obj instanceof CompressEncoding) { - CompressEncoding other = (CompressEncoding) obj; - return alignment == other.alignment && base == other.base && shift == other.shift; - } else { - return false; - } - } - } - - /** - * Returns the name of the C/C++ symbol that is associated (via HotSpotVMValue annotation) with - * the HotSpotVMConfig object's field containing {@code value}; returns null if no field holds - * the provided address. - * - * @param value value of the field - * @return C/C++ symbol name or null - */ - public String getVMValueCSymbol(long value) { - for (Field f : HotSpotVMConfig.class.getDeclaredFields()) { - if (f.isAnnotationPresent(HotSpotVMValue.class)) { - HotSpotVMValue annotation = f.getAnnotation(HotSpotVMValue.class); - - if (annotation.get() == HotSpotVMValue.Type.ADDRESS) { - try { - if (value == f.getLong(this)) { - return (annotation.expression() + annotation.signature()); - } - } catch (IllegalArgumentException e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); - } catch (IllegalAccessException e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); - } - } - } - } - return null; - } - - /** - * Returns the name of the C/C++ symbol that is associated (via HotSpotVMField annotation) with - * the HotSpotVMConfig object's field containing {@code value}; returns null if no field holds - * the provided address. - * - * @param value value of the field - * @return C/C++ symbol name or null - */ - public String getVMFieldCSymbol(long value) { - for (Field f : HotSpotVMConfig.class.getDeclaredFields()) { - if (f.isAnnotationPresent(HotSpotVMField.class)) { - HotSpotVMField annotation = f.getAnnotation(HotSpotVMField.class); - - if (annotation.get() == HotSpotVMField.Type.VALUE) { - try { - if (value == f.getLong(this)) { - return (annotation.name()); - } - } catch (IllegalArgumentException e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); - } catch (IllegalAccessException e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); - } - } - } - } - return null; - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotVMConfigVerifier.java --- a/graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotVMConfigVerifier.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,156 +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.jvmci.hotspot; - -import static java.lang.String.*; - -import java.io.*; -import java.lang.reflect.*; -import java.util.*; - -import jdk.internal.org.objectweb.asm.*; -import jdk.internal.org.objectweb.asm.Type; -import sun.misc.*; - -import com.oracle.jvmci.common.*; - -/** - * A {@link ClassVisitor} that verifies {@link HotSpotVMConfig} does not access {@link Unsafe} from - * any of its non-static, non-constructor methods. This ensures that a deserialized - * {@link HotSpotVMConfig} object does not perform any unsafe reads on addresses that are only valid - * in the context in which the object was serialized. Note that this does not catch cases where a - * client uses an address stored in a {@link HotSpotVMConfig} field. - */ -final class HotSpotVMConfigVerifier extends ClassVisitor { - - public static boolean check() { - Class cls = HotSpotVMConfig.class; - String classFilePath = "/" + cls.getName().replace('.', '/') + ".class"; - try { - InputStream classfile = cls.getResourceAsStream(classFilePath); - ClassReader cr = new ClassReader(Objects.requireNonNull(classfile, "Could not find class file for " + cls.getName())); - ClassVisitor cv = new HotSpotVMConfigVerifier(); - cr.accept(cv, 0); - return true; - } catch (IOException e) { - throw new JVMCIError(e); - } - } - - /** - * Source file context for error reporting. - */ - String sourceFile = null; - - /** - * Line number for error reporting. - */ - int lineNo = -1; - - private static Class resolve(String name) { - try { - return Class.forName(name.replace('/', '.')); - } catch (ClassNotFoundException e) { - throw new JVMCIError(e); - } - } - - HotSpotVMConfigVerifier() { - super(Opcodes.ASM5); - } - - @Override - public void visitSource(String source, String debug) { - this.sourceFile = source; - } - - void verify(boolean condition, String message) { - if (!condition) { - error(message); - } - } - - void error(String message) { - String errorMessage = format("%s:%d: %s is not allowed in the context of compilation replay. The unsafe access should be moved into the %s constructor and the result cached in a field", - sourceFile, lineNo, message, HotSpotVMConfig.class.getSimpleName()); - throw new JVMCIError(errorMessage); - - } - - @Override - public MethodVisitor visitMethod(int access, String name, String d, String signature, String[] exceptions) { - if (!Modifier.isStatic(access) && Modifier.isPublic(access) && !name.equals("")) { - return new MethodVisitor(Opcodes.ASM5) { - - @Override - public void visitLineNumber(int line, Label start) { - lineNo = line; - } - - private Executable resolveMethod(String owner, String methodName, String methodDesc) { - Class declaringClass = resolve(owner); - while (declaringClass != null) { - if (methodName.equals("")) { - for (Constructor c : declaringClass.getDeclaredConstructors()) { - if (methodDesc.equals(Type.getConstructorDescriptor(c))) { - return c; - } - } - } else { - Type[] argumentTypes = Type.getArgumentTypes(methodDesc); - for (Method m : declaringClass.getDeclaredMethods()) { - if (m.getName().equals(methodName)) { - if (Arrays.equals(argumentTypes, Type.getArgumentTypes(m))) { - if (Type.getReturnType(methodDesc).equals(Type.getReturnType(m))) { - return m; - } - } - } - } - } - declaringClass = declaringClass.getSuperclass(); - } - throw new NoSuchMethodError(owner + "." + methodName + methodDesc); - } - - /** - * Checks whether a given method is allowed to be called. - */ - private boolean checkInvokeTarget(Executable method) { - if (method.getDeclaringClass().equals(Unsafe.class)) { - return false; - } - return true; - } - - @Override - public void visitMethodInsn(int opcode, String owner, String methodName, String methodDesc, boolean itf) { - Executable callee = resolveMethod(owner, methodName, methodDesc); - verify(checkInvokeTarget(callee), "invocation of " + callee); - } - }; - } else { - return null; - } - } -} diff -r 42452d2dfbec -r 395ac43a8578 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 Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,53 +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.jvmci.hotspot; - -import com.oracle.jvmci.service.*; - -public interface HotSpotVMEventListener extends Service { - - /** - * 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 - */ - 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. - */ - default void notifyCompileTheWorld() throws Throwable { - } - - /** - * Notifies this client that the VM is shutting down. - */ - default void notifyShutdown() { - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotVmSymbols.java --- a/graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotVmSymbols.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,48 +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.jvmci.hotspot; - -import static com.oracle.jvmci.common.UnsafeAccess.*; -import static com.oracle.jvmci.hotspot.HotSpotJVMCIRuntime.*; -import sun.misc.*; - -/** - * Class to access the C++ {@code vmSymbols} table. - */ -public final class HotSpotVmSymbols { - - /** - * Returns the symbol in the {@code vmSymbols} table at position {@code index} as {@link String} - * . - * - * @param index position in the symbol table - * @return the symbol at position id - */ - public static String symbolAt(int index) { - HotSpotJVMCIRuntimeProvider runtime = runtime(); - HotSpotVMConfig config = runtime.getConfig(); - assert config.vmSymbolsFirstSID <= index && index < config.vmSymbolsSIDLimit : "index " + index + " is out of bounds"; - assert config.symbolPointerSize == Unsafe.ADDRESS_SIZE : "the following address read is broken"; - return runtime.getCompilerToVM().getSymbol(unsafe.getAddress(config.vmSymbolsSymbols + index * config.symbolPointerSize)); - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/InitTimer.java --- a/graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/InitTimer.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,82 +0,0 @@ -/* - * 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 - * 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.debug.*; - -import edu.umd.cs.findbugs.annotations.*; - -/** - * A facility for timing a step in the runtime initialization sequence. This exists separate from - * {@link DebugTimer} as it must be independent from all other JVMCI code so as to not perturb the - * initialization sequence. - */ -public final class InitTimer implements AutoCloseable { - final String name; - final long start; - - private InitTimer(String name) { - this.name = name; - this.start = System.currentTimeMillis(); - System.out.println("START: " + SPACES.substring(0, timerDepth * 2) + name); - assert Thread.currentThread() == initializingThread : Thread.currentThread() + " != " + initializingThread; - timerDepth++; - } - - @SuppressFBWarnings(value = "ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD", justification = "only the initializing thread accesses this field") - public void close() { - final long end = System.currentTimeMillis(); - timerDepth--; - System.out.println(" DONE: " + SPACES.substring(0, timerDepth * 2) + name + " [" + (end - start) + " ms]"); - } - - public static InitTimer timer(String name) { - return ENABLED ? new InitTimer(name) : null; - } - - public static InitTimer timer(String name, Object suffix) { - return ENABLED ? new InitTimer(name + suffix) : null; - } - - /** - * Specifies if initialization timing is enabled. This can only be set via a system property as - * the timing facility is used to time initialization of {@link HotSpotOptions}. - */ - private static final boolean ENABLED = Boolean.getBoolean("jvmci.runtime.TimeInit"); - - public static int timerDepth = 0; - public static final String SPACES = " "; - - /** - * Used to assert the invariant that all initialization happens on the same thread. - */ - public static final Thread initializingThread; - static { - if (ENABLED) { - initializingThread = Thread.currentThread(); - System.out.println("INITIALIZING THREAD: " + initializingThread); - } else { - initializingThread = null; - } - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/PrintStreamOption.java --- a/graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/PrintStreamOption.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,137 +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.jvmci.hotspot; - -import java.io.*; -import java.lang.management.*; - -import com.oracle.jvmci.options.*; - -/** - * An option that encapsulates and configures a print stream. - */ -public class PrintStreamOption extends OptionValue { - - public PrintStreamOption() { - super(null); - } - - /** - * The print stream to which output will be written. - * - * Declared {@code volatile} to enable safe use of double-checked locking in - * {@link #getStream(CompilerToVM)} and {@link #setValue(Object)}. - */ - private volatile PrintStream ps; - - /** - * Replace any instance of %p with a an identifying name. Try to get it from the RuntimeMXBean - * name. - * - * @return the name of the file to log to - */ - private String getFilename() { - String name = getValue(); - if (name.contains("%p")) { - String runtimeName = ManagementFactory.getRuntimeMXBean().getName(); - try { - int index = runtimeName.indexOf('@'); - if (index != -1) { - long pid = Long.parseLong(runtimeName.substring(0, index)); - runtimeName = Long.toString(pid); - } - name = name.replaceAll("%p", runtimeName); - } catch (NumberFormatException e) { - - } - } - return name; - } - - /** - * Gets the print stream configured by this option. If no file is configured, the print stream - * will output to {@link CompilerToVM#writeDebugOutput(byte[], int, int)}. - */ - public PrintStream getStream(final CompilerToVM compilerToVM) { - if (ps == null) { - if (getValue() != null) { - synchronized (this) { - if (ps == null) { - try { - final boolean enableAutoflush = true; - ps = new PrintStream(new FileOutputStream(getFilename()), enableAutoflush); - /* Add the JVM and Java arguments to the log file to help identity it. */ - String inputArguments = String.join(" ", ManagementFactory.getRuntimeMXBean().getInputArguments()); - ps.println("VM Arguments: " + inputArguments); - String cmd = System.getProperty("sun.java.command"); - if (cmd != null) { - ps.println("sun.java.command=" + cmd); - } - } catch (FileNotFoundException e) { - throw new RuntimeException("couldn't open file: " + getValue(), e); - } - } - } - } else { - OutputStream ttyOut = new OutputStream() { - @Override - public void write(byte[] b, int off, int len) throws IOException { - if (b == null) { - throw new NullPointerException(); - } else if (off < 0 || off > b.length || len < 0 || (off + len) > b.length || (off + len) < 0) { - throw new IndexOutOfBoundsException(); - } else if (len == 0) { - return; - } - compilerToVM.writeDebugOutput(b, off, len); - } - - @Override - public void write(int b) throws IOException { - write(new byte[]{(byte) b}, 0, 1); - } - - @Override - public void flush() throws IOException { - compilerToVM.flushDebugOutput(); - } - }; - ps = new PrintStream(ttyOut); - } - } - return ps; - } - - @Override - public void setValue(Object v) { - if (ps != null) { - synchronized (this) { - if (ps != null) { - ps.close(); - ps = null; - } - } - } - super.setValue(v); - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/Stable.java --- a/graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/Stable.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,35 +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.hotspot; - -import java.lang.annotation.*; - -/** - * This annotation functions as an alias for the sun.invoke.Stable annotation within JVMCI code. It - * is specially recognized during class file parsing in the same way as that annotation. - */ -@Target(ElementType.FIELD) -@Retention(RetentionPolicy.RUNTIME) -public @interface Stable { -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/events/EmptyEventProvider.java --- a/graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/events/EmptyEventProvider.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,105 +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.jvmci.hotspot.events; - -import com.oracle.jvmci.common.*; - -/** - * An empty implementation for {@link EventProvider}. This implementation is used when no logging is - * requested. - */ -public final class EmptyEventProvider implements EventProvider { - - public CompilationEvent newCompilationEvent() { - return new EmptyCompilationEvent(); - } - - public static class EmptyCompilationEvent implements CompilationEvent { - public void commit() { - throw JVMCIError.shouldNotReachHere(); - } - - public boolean shouldWrite() { - // Events of this class should never been written. - return false; - } - - public void begin() { - } - - public void end() { - } - - public void setMethod(String method) { - throw JVMCIError.shouldNotReachHere(); - } - - public void setCompileId(int compileId) { - throw JVMCIError.shouldNotReachHere(); - } - - public void setCompileLevel(int compileLevel) { - throw JVMCIError.shouldNotReachHere(); - } - - public void setSucceeded(boolean succeeded) { - throw JVMCIError.shouldNotReachHere(); - } - - public void setIsOsr(boolean isOsr) { - throw JVMCIError.shouldNotReachHere(); - } - - public void setCodeSize(int codeSize) { - throw JVMCIError.shouldNotReachHere(); - } - - public void setInlinedBytes(int inlinedBytes) { - throw JVMCIError.shouldNotReachHere(); - } - } - - public CompilerFailureEvent newCompilerFailureEvent() { - return new EmptyCompilerFailureEvent(); - } - - public static class EmptyCompilerFailureEvent implements CompilerFailureEvent { - public void commit() { - throw JVMCIError.shouldNotReachHere(); - } - - public boolean shouldWrite() { - // Events of this class should never been written. - return false; - } - - public void setCompileId(int compileId) { - throw JVMCIError.shouldNotReachHere(); - } - - public void setMessage(String message) { - throw JVMCIError.shouldNotReachHere(); - } - } - -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/events/EventProvider.java --- a/graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/events/EventProvider.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,107 +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.jvmci.hotspot.events; - -import com.oracle.jvmci.service.*; - -/** - * A provider that provides a specific implementation for events that can be logged in the compiler. - */ -public interface EventProvider extends Service { - - /** - * An instant event is an event that is not considered to have taken any time. - */ - interface InstantEvent { - /** - * Commits the event. - */ - void commit(); - - /** - * Determines if this particular event instance would be committed to the data stream right - * now if application called {@link #commit()}. This in turn depends on whether the event is - * enabled and possible other factors. - * - * @return if this event would be committed on a call to {@link #commit()}. - */ - boolean shouldWrite(); - } - - /** - * Timed events describe an operation that somehow consumes time. - */ - interface TimedEvent extends InstantEvent { - /** - * Starts the timing for this event. - */ - void begin(); - - /** - * Ends the timing period for this event. - */ - void end(); - } - - /** - * Creates a new {@link CompilationEvent}. - * - * @return a compilation event - */ - CompilationEvent newCompilationEvent(); - - /** - * A compilation event. - */ - interface CompilationEvent extends TimedEvent { - void setMethod(String method); - - void setCompileId(int compileId); - - void setCompileLevel(int compileLevel); - - void setSucceeded(boolean succeeded); - - void setIsOsr(boolean isOsr); - - void setCodeSize(int codeSize); - - void setInlinedBytes(int inlinedBytes); - } - - /** - * Creates a new {@link CompilerFailureEvent}. - * - * @return a compiler failure event - */ - CompilerFailureEvent newCompilerFailureEvent(); - - /** - * A compiler failure event. - */ - interface CompilerFailureEvent extends InstantEvent { - void setCompileId(int compileId); - - void setMessage(String message); - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/logging/CountingProxy.java --- a/graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/logging/CountingProxy.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,107 +0,0 @@ -/* - * Copyright (c) 2011, 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.logging; - -import java.lang.reflect.*; -import java.util.*; -import java.util.concurrent.*; -import java.util.concurrent.atomic.*; - -import com.oracle.jvmci.debug.*; - -/** - * A java.lang.reflect proxy that hierarchically logs all method invocations along with their - * parameters and return values. - */ -public class CountingProxy implements InvocationHandler { - - public static final boolean ENABLED = Boolean.valueOf(System.getProperty("jvmci.countcalls")); - - private T delegate; - - private ConcurrentHashMap calls = new ConcurrentHashMap<>(); - - public CountingProxy(T delegate) { - assert ENABLED; - TTY.println("Counting proxy for " + delegate.getClass().getSimpleName() + " created"); - this.delegate = delegate; - proxies.add(this); - } - - @Override - public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { - int argCount = args == null ? 0 : args.length; - if (method.getParameterTypes().length != argCount) { - throw new RuntimeException("wrong parameter count"); - } - final Object result; - if (!calls.containsKey(method)) { - calls.putIfAbsent(method, new AtomicLong(0)); - } - AtomicLong count = calls.get(method); - count.incrementAndGet(); - try { - if (args == null) { - result = method.invoke(delegate); - } else { - result = method.invoke(delegate, args); - } - } catch (InvocationTargetException e) { - throw e.getCause(); - } - return result; - } - - public static T getProxy(Class interf, T delegate) { - Class[] interfaces = ProxyUtil.getAllInterfaces(delegate.getClass()); - Object obj = Proxy.newProxyInstance(interf.getClassLoader(), interfaces, new CountingProxy<>(delegate)); - return interf.cast(obj); - } - - private static ArrayList> proxies = new ArrayList<>(); - - static { - if (ENABLED) { - Runtime.getRuntime().addShutdownHook(new Thread() { - - @Override - public void run() { - for (CountingProxy proxy : proxies) { - proxy.print(); - } - } - }); - } - } - - protected void print() { - long sum = 0; - for (Map.Entry entry : calls.entrySet()) { - Method method = entry.getKey(); - long count = entry.getValue().get(); - sum += count; - TTY.println(delegate.getClass().getSimpleName() + "." + method.getName() + ": " + count); - } - TTY.println(delegate.getClass().getSimpleName() + " calls: " + sum); - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/logging/Logger.java --- a/graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/logging/Logger.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,199 +0,0 @@ -/* - * Copyright (c) 2011, 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.logging; - -import java.io.*; -import java.lang.reflect.*; -import java.util.*; - -import com.oracle.jvmci.debug.*; -import com.oracle.jvmci.hotspot.*; - -/** - * Scoped logging class used to display the call hierarchy of {@link CompilerToVM} calls. - */ -public class Logger { - - public static final boolean ENABLED = Boolean.valueOf(System.getProperty("jvmci.debug")); - private static final int SPACING = 4; - private static final ThreadLocal loggerTL; - - private Deque openStack = new LinkedList<>(); - private boolean open = false; - private int level = 0; - - private static final PrintStream out; - - static { - if (ENABLED) { - loggerTL = new ThreadLocal() { - - @Override - protected Logger initialValue() { - return new Logger(); - } - }; - } else { - loggerTL = null; - } - - PrintStream ps = null; - String filename = System.getProperty("jvmci.info_file"); - if (filename != null && !"".equals(filename)) { - try { - ps = new PrintStream(new FileOutputStream(filename)); - } catch (FileNotFoundException e) { - e.printStackTrace(); - ps = null; - } - } - out = ps; - if (out != null) { - out.println("start: " + new Date()); - } - } - - public static void info(String message) { - if (ENABLED) { - log(message); - } else { - TTY.println(message); - } - if (out != null) { - out.println(message); - out.flush(); - } - } - - public static void log(String message) { - if (ENABLED) { - Logger logger = loggerTL.get(); - for (String line : message.split("\n")) { - if (logger.open) { - TTY.println("..."); - logger.open = false; - } - TTY.print(space(logger.level)); - TTY.println(line); - } - } - } - - public static void startScope(String message) { - if (ENABLED) { - Logger logger = loggerTL.get(); - if (logger.open) { - TTY.println("..."); - logger.open = false; - } - TTY.print(space(logger.level)); - TTY.print(message); - logger.openStack.push(logger.open); - logger.open = true; - logger.level++; - } - } - - public static void endScope(String message) { - if (ENABLED) { - Logger logger = loggerTL.get(); - logger.level--; - if (logger.open) { - TTY.println(message); - } else { - TTY.println(space(logger.level) + "..." + message); - } - logger.open = logger.openStack.pop(); - } - } - - private static String[] spaces = new String[50]; - - private static String space(int count) { - assert count >= 0; - String result; - if (count >= spaces.length || spaces[count] == null) { - StringBuilder str = new StringBuilder(); - for (int i = 0; i < count * SPACING; i++) { - str.append(' '); - } - result = str.toString(); - if (count < spaces.length) { - spaces[count] = result; - } - } else { - result = spaces[count]; - } - return result; - } - - public static String pretty(Object value) { - if (value == null) { - return "null"; - } - - Class klass = value.getClass(); - if (value instanceof Void) { - return "void"; - } else if (value instanceof String) { - return "\"" + value + "\""; - } else if (value instanceof Method) { - return "method \"" + ((Method) value).getName() + "\""; - } else if (value instanceof Class) { - return "class \"" + ((Class) value).getSimpleName() + "\""; - } else if (value instanceof Integer) { - if ((Integer) value < 10) { - return value.toString(); - } - return value + " (0x" + Integer.toHexString((Integer) value) + ")"; - } else if (value instanceof Long) { - if ((Long) value < 10 && (Long) value > -10) { - return value + "l"; - } - return value + "l (0x" + Long.toHexString((Long) value) + "l)"; - } else if (klass.isArray()) { - StringBuilder str = new StringBuilder(); - int dimensions = 0; - while (klass.isArray()) { - dimensions++; - klass = klass.getComponentType(); - } - int length = Array.getLength(value); - str.append(klass.getSimpleName()).append('[').append(length).append(']'); - for (int i = 1; i < dimensions; i++) { - str.append("[]"); - } - str.append(" {"); - for (int i = 0; i < length; i++) { - str.append(pretty(Array.get(value, i))); - if (i < length - 1) { - str.append(", "); - } - } - str.append('}'); - return str.toString(); - } - - return value.toString(); - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/logging/LoggingProxy.java --- a/graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/logging/LoggingProxy.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,77 +0,0 @@ -/* - * Copyright (c) 2011, 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.logging; - -import java.lang.reflect.*; - -/** - * A java.lang.reflect proxy that hierarchically logs all method invocations along with their - * parameters and return values. - */ -public class LoggingProxy implements InvocationHandler { - - private T delegate; - - public LoggingProxy(T delegate) { - this.delegate = delegate; - } - - @Override - public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { - int argCount = args == null ? 0 : args.length; - if (method.getParameterTypes().length != argCount) { - throw new RuntimeException("wrong parameter count"); - } - StringBuilder str = new StringBuilder(); - str.append(method.getReturnType().getSimpleName() + " " + method.getDeclaringClass().getSimpleName() + "." + method.getName() + "("); - for (int i = 0; i < argCount; i++) { - str.append(i == 0 ? "" : ", "); - str.append(Logger.pretty(args[i])); - } - str.append(")"); - Logger.startScope(str.toString()); - final Object result; - try { - if (args == null) { - result = method.invoke(delegate); - } else { - result = method.invoke(delegate, args); - } - } catch (InvocationTargetException e) { - Logger.endScope(" = Exception " + e.getMessage()); - throw e.getCause(); - } - Logger.endScope(" = " + Logger.pretty(result)); - return result; - } - - /** - * The object returned by this method will implement all interfaces that are implemented by - * delegate. - */ - public static T getProxy(Class interf, T delegate) { - Class[] interfaces = ProxyUtil.getAllInterfaces(delegate.getClass()); - Object obj = Proxy.newProxyInstance(interf.getClassLoader(), interfaces, new LoggingProxy<>(delegate)); - return interf.cast(obj); - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/logging/ProxyUtil.java --- a/graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/logging/ProxyUtil.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2011, 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.logging; - -import java.util.*; - -public final class ProxyUtil { - - public static Class[] getAllInterfaces(Class clazz) { - HashSet> interfaces = new HashSet<>(); - getAllInterfaces(clazz, interfaces); - return interfaces.toArray(new Class[interfaces.size()]); - } - - private static void getAllInterfaces(Class clazz, HashSet> interfaces) { - for (Class iface : clazz.getInterfaces()) { - if (!interfaces.contains(iface)) { - interfaces.add(iface); - getAllInterfaces(iface, interfaces); - } - } - if (clazz.getSuperclass() != null) { - getAllInterfaces(clazz.getSuperclass(), interfaces); - } - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/logging/package-info.java --- a/graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/logging/package-info.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2011, 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. - */ -/** - * Logging framework for the HotSpot CRI implementation. - */ -package com.oracle.jvmci.hotspot.logging; - diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.hotspotvmconfig.processor/src/META-INF/services/javax.annotation.processing.Processor --- a/graal/com.oracle.jvmci.hotspotvmconfig.processor/src/META-INF/services/javax.annotation.processing.Processor Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -com.oracle.jvmci.hotspotvmconfig.processor.HotSpotVMConfigProcessor diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.hotspotvmconfig.processor/src/com/oracle/jvmci/hotspotvmconfig/processor/HotSpotVMConfigProcessor.java --- a/graal/com.oracle.jvmci.hotspotvmconfig.processor/src/com/oracle/jvmci/hotspotvmconfig/processor/HotSpotVMConfigProcessor.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,430 +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.jvmci.hotspotvmconfig.processor; - -import java.io.*; -import java.lang.annotation.*; -import java.util.*; -import java.util.Map.Entry; -import java.util.function.*; - -import javax.annotation.processing.*; -import javax.lang.model.*; -import javax.lang.model.element.*; -import javax.tools.Diagnostic.Kind; -import javax.tools.*; - -import com.oracle.jvmci.common.*; -import com.oracle.jvmci.hotspotvmconfig.*; - -@SupportedAnnotationTypes({ - // @formatter:off - "com.oracle.jvmci.hotspotvmconfig.HotSpotVMConstant", - "com.oracle.jvmci.hotspotvmconfig.HotSpotVMFlag", - "com.oracle.jvmci.hotspotvmconfig.HotSpotVMField", - "com.oracle.jvmci.hotspotvmconfig.HotSpotVMType", - "com.oracle.jvmci.hotspotvmconfig.HotSpotVMValue"}) - // @formatter:on -public class HotSpotVMConfigProcessor extends AbstractProcessor { - - public HotSpotVMConfigProcessor() { - } - - @Override - public SourceVersion getSupportedSourceVersion() { - return SourceVersion.latest(); - } - - /** - * Set to true to enable logging to a local file during annotation processing. There's no normal - * channel for any debug messages and debugging annotation processors requires some special - * setup. - */ - private static final boolean DEBUG = false; - - private PrintWriter log; - - /** - * Logging facility for debugging the annotation processor. - */ - - private PrintWriter getLog() { - if (log == null) { - try { - // Create the log file within the generated source directory so it's easy to find. - // /tmp isn't platform independent and java.io.tmpdir can map anywhere, particularly - // on the mac. - FileObject file = processingEnv.getFiler().createResource(StandardLocation.SOURCE_OUTPUT, "", getClass().getSimpleName() + "log"); - log = new PrintWriter(new FileWriter(file.toUri().getPath(), true)); - } catch (IOException e) { - // Do nothing - } - } - return log; - } - - private void logMessage(String format, Object... args) { - if (!DEBUG) { - return; - } - PrintWriter bw = getLog(); - if (bw != null) { - bw.printf(format, args); - bw.flush(); - } - } - - private void logException(Throwable t) { - if (!DEBUG) { - return; - } - PrintWriter bw = getLog(); - if (bw != null) { - t.printStackTrace(bw); - bw.flush(); - } - } - - /** - * Bugs in an annotation processor can cause silent failure so try to report any exception - * throws as errors. - */ - private void reportExceptionThrow(Element element, Throwable t) { - if (element != null) { - logMessage("throw for %s:\n", element); - } - logException(t); - errorMessage(element, "Exception throw during processing: %s %s", t, Arrays.toString(Arrays.copyOf(t.getStackTrace(), 4))); - } - - //@formatter:off - String[] prologue = new String[]{ - "// The normal wrappers CommandLineFlags::boolAt and CommandLineFlags::intxAt skip constant flags", - "static bool boolAt(char* name, bool* value) {", - " Flag* result = Flag::find_flag(name, strlen(name), true, true);", - " if (result == NULL) return false;", - " if (!result->is_bool()) return false;", - " *value = result->get_bool();", - " return true;", - "}", - "", - "static bool intxAt(char* name, intx* value) {", - " Flag* result = Flag::find_flag(name, strlen(name), true, true);", - " if (result == NULL) return false;", - " if (!result->is_intx()) return false;", - " *value = result->get_intx();", - " return true;", - "}", - "", - "#define set_boolean(name, value) vmconfig_oop->bool_field_put(fs.offset(), value)", - "#define set_byte(name, value) vmconfig_oop->byte_field_put(fs.offset(), (jbyte)(value))", - "#define set_short(name, value) vmconfig_oop->short_field_put(fs.offset(), (jshort)(value))", - "#define set_int(name, value) vmconfig_oop->int_field_put(fs.offset(), (int)(value))", - "#define set_long(name, value) vmconfig_oop->long_field_put(fs.offset(), value)", - "#define set_address(name, value) do { set_long(name, (jlong)(value)); } while (0)", - "", - "#define set_optional_boolean_flag(varName, flagName) do { bool flagValue; if (boolAt((char*) flagName, &flagValue)) { set_boolean(varName, flagValue); } } while (0)", - "#define set_optional_int_flag(varName, flagName) do { intx flagValue; if (intxAt((char*) flagName, &flagValue)) { set_int(varName, flagValue); } } while (0)", - "#define set_optional_long_flag(varName, flagName) do { intx flagValue; if (intxAt((char*) flagName, &flagValue)) { set_long(varName, flagValue); } } while (0)", - "", - "void VMStructs::initHotSpotVMConfig(oop vmconfig_oop) {", - " InstanceKlass* vmconfig_klass = InstanceKlass::cast(vmconfig_oop->klass());", - "", - }; - //@formatter:on - - String outputName = "HotSpotVMConfig.inline.hpp"; - String outputDirectory = "hotspot"; - - private void createFiles(Map annotations, Element element) { - - Filer filer = processingEnv.getFiler(); - try (PrintWriter out = createSourceFile(outputDirectory, outputName, filer, element)) { - - for (String line : prologue) { - out.println(line); - } - - Map expectedValues = new HashMap<>(); - for (VMConfigField value : annotations.values()) { - if (!value.optional) { - String key = value.define != null ? value.define : ""; - if (expectedValues.get(key) == null) { - expectedValues.put(key, 1); - } else { - expectedValues.put(key, expectedValues.get(key) + 1); - } - } - } - - out.printf(" int expected = %s;%n", expectedValues.get("")); - for (Entry entry : expectedValues.entrySet()) { - if (entry.getKey().equals("")) { - continue; - } - out.printf("#if %s%n", entry.getKey()); - out.printf(" expected += %s;%n", entry.getValue()); - out.printf("#endif%n"); - } - out.println(" int assigned = 0;"); - out.println(" for (JavaFieldStream fs(vmconfig_klass); !fs.done(); fs.next()) {"); - - Set fieldTypes = new HashSet<>(); - for (VMConfigField key : annotations.values()) { - fieldTypes.add(key.getType()); - } - // For each type of field, generate a switch on the length of the symbol and then do a - // direct compare. In general this reduces each operation to 2 tests plus a string - // compare. Being more perfect than that is probably not worth it. - for (String type : fieldTypes) { - String sigtype = type.equals("boolean") ? "bool" : type; - out.println(" if (fs.signature() == vmSymbols::" + sigtype + "_signature()) {"); - Set lengths = new HashSet<>(); - for (Entry entry : annotations.entrySet()) { - if (entry.getValue().getType().equals(type)) { - lengths.add(entry.getKey().length()); - } - } - out.println(" switch (fs.name()->utf8_length()) {"); - for (int len : lengths) { - out.println(" case " + len + ":"); - for (Entry entry : annotations.entrySet()) { - if (entry.getValue().getType().equals(type) && entry.getKey().length() == len) { - out.println(" if (fs.name()->equals(\"" + entry.getKey() + "\")) {"); - entry.getValue().emit(out); - out.println(" continue;"); - out.println(" }"); - } - } - out.println(" continue;"); - } - out.println(" } // switch"); - out.println(" continue;"); - out.println(" } // if"); - } - out.println(" } // for"); - out.println(" guarantee(assigned == expected, \"Didn't find all fields during init of HotSpotVMConfig. Maybe recompile?\");"); - out.println("}"); - } - } - - protected PrintWriter createSourceFile(String pkg, String relativeName, Filer filer, Element... originatingElements) { - try { - // Ensure Unix line endings to comply with code style guide checked by Checkstyle - FileObject sourceFile = filer.createResource(StandardLocation.SOURCE_OUTPUT, pkg, relativeName, originatingElements); - logMessage("%s\n", sourceFile); - return new PrintWriter(sourceFile.openWriter()) { - - @Override - public void println() { - print("\n"); - } - }; - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - static class VMConfigField { - final String setter; - final String define; - private boolean optional; - final VariableElement field; - - public VMConfigField(VariableElement field, HotSpotVMField value) { - this.field = field; - define = archDefines(value.archs()); - String type = field.asType().toString(); - String name = value.name(); - int i = name.lastIndexOf("::"); - switch (value.get()) { - case OFFSET: - setter = String.format("set_%s(\"%s\", offset_of(%s, %s));", type, field.getSimpleName(), name.substring(0, i), name.substring(i + 2)); - break; - case ADDRESS: - setter = String.format("set_address(\"%s\", &%s);", field.getSimpleName(), name); - break; - case VALUE: - setter = String.format("set_%s(\"%s\", (%s) (intptr_t) %s);", type, field.getSimpleName(), type, name); - break; - default: - throw new JVMCIError("unexpected type: " + value.get()); - } - } - - public VMConfigField(VariableElement field, HotSpotVMType value) { - this.field = field; - define = null; // ((HotSpotVMType) annotation).archs(); - String type = field.asType().toString(); - setter = String.format("set_%s(\"%s\", sizeof(%s));", type, field.getSimpleName(), value.name()); - } - - public VMConfigField(VariableElement field, HotSpotVMValue value) { - this.field = field; - String[] defines = value.defines(); - int length = defines.length; - if (length != 0) { - for (int i = 0; i < length; i++) { - defines[i] = "defined(" + defines[i] + ")"; - } - define = String.join(" || ", defines); - } else { - define = null; // ((HotSpotVMValue) annotation).archs(); - } - String type = field.asType().toString(); - if (value.get() == HotSpotVMValue.Type.ADDRESS) { - setter = String.format("set_address(\"%s\", %s);", field.getSimpleName(), value.expression()); - } else { - setter = String.format("set_%s(\"%s\", %s);", type, field.getSimpleName(), value.expression()); - } - } - - public VMConfigField(VariableElement field, HotSpotVMConstant value) { - this.field = field; - define = archDefines(value.archs()); - String type = field.asType().toString(); - setter = String.format("set_%s(\"%s\", %s);", type, field.getSimpleName(), value.name()); - } - - public VMConfigField(VariableElement field, HotSpotVMFlag value) { - this.field = field; - define = archDefines(value.archs()); - optional = value.optional(); - String type = field.asType().toString(); - if (value.optional()) { - setter = String.format("set_optional_%s_flag(\"%s\", \"%s\");", type, field.getSimpleName(), value.name()); - } else { - setter = String.format("set_%s(\"%s\", %s);", type, field.getSimpleName(), value.name()); - } - } - - public String getType() { - return field.asType().toString(); - } - - private static String archDefine(String arch) { - switch (arch) { - case "amd64": - return "defined(AMD64)"; - case "sparcv9": - return "(defined(SPARC) && defined(_LP64))"; - case "sparc": - return "defined(SPARC)"; - default: - throw new JVMCIError("unexpected arch: " + arch); - } - } - - private static String archDefines(String[] archs) { - if (archs == null || archs.length == 0) { - return null; - } - if (archs.length == 1) { - return archDefine(archs[0]); - } - String[] defs = new String[archs.length]; - int i = 0; - for (String arch : archs) { - defs[i++] = archDefine(arch); - } - return String.join(" || ", defs); - } - - public void emit(PrintWriter out) { - if (define != null) { - out.printf("#if %s\n", define); - } - out.printf(" %s%n", setter); - if (!optional) { - out.printf(" assigned++;%n"); - } - if (define != null) { - out.printf("#endif\n"); - } - } - - } - - @SuppressWarnings("unchecked") - private void collectAnnotations(RoundEnvironment roundEnv, Map annotationMap, Class annotationClass, - BiFunction builder) { - for (Element element : roundEnv.getElementsAnnotatedWith(annotationClass)) { - Annotation constant = element.getAnnotation(annotationClass); - if (element.getKind() != ElementKind.FIELD) { - errorMessage(element, "%s annotations may only be on fields", annotationClass.getSimpleName()); - } - if (annotationClass == HotSpotVMValue.class) { - HotSpotVMValue value = (HotSpotVMValue) constant; - if (value.get() == HotSpotVMValue.Type.ADDRESS && !element.asType().toString().equals("long")) { - errorMessage(element, "HotSpotVMValue with get == ADDRESS must be of type long, but found %s", element.asType()); - } - } - if (currentTypeElement == null) { - currentTypeElement = element.getEnclosingElement(); - } else { - if (!currentTypeElement.equals(element.getEnclosingElement())) { - errorMessage(element, "Multiple types encountered. Only HotSpotVMConfig is supported"); - } - } - annotationMap.put(element.getSimpleName().toString(), builder.apply((VariableElement) element, (T) constant)); - } - } - - private void errorMessage(Element element, String format, Object... args) { - processingEnv.getMessager().printMessage(Kind.ERROR, String.format(format, args), element); - } - - Element currentTypeElement = null; - - @Override - public boolean process(Set annotations, RoundEnvironment roundEnv) { - if (roundEnv.processingOver()) { - return true; - } - logMessage("Starting round %s %s\n", roundEnv, annotations); - try { - - currentTypeElement = null; - - // First collect all the annotations. - Map annotationMap = new HashMap<>(); - collectAnnotations(roundEnv, annotationMap, HotSpotVMConstant.class, (e, v) -> new VMConfigField(e, v)); - collectAnnotations(roundEnv, annotationMap, HotSpotVMFlag.class, (e, v) -> new VMConfigField(e, v)); - collectAnnotations(roundEnv, annotationMap, HotSpotVMField.class, (e, v) -> new VMConfigField(e, v)); - collectAnnotations(roundEnv, annotationMap, HotSpotVMType.class, (e, v) -> new VMConfigField(e, v)); - collectAnnotations(roundEnv, annotationMap, HotSpotVMValue.class, (e, v) -> new VMConfigField(e, v)); - - if (annotationMap.isEmpty()) { - return true; - } - - logMessage("type element %s\n", currentTypeElement); - createFiles(annotationMap, currentTypeElement); - - } catch (Throwable t) { - reportExceptionThrow(null, t); - } - - return true; - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.hotspotvmconfig/src/com/oracle/jvmci/hotspotvmconfig/HotSpotVMConstant.java --- a/graal/com.oracle.jvmci.hotspotvmconfig/src/com/oracle/jvmci/hotspotvmconfig/HotSpotVMConstant.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,48 +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.jvmci.hotspotvmconfig; - -import java.lang.annotation.*; - -/** - * Refers to a C++ constant in the VM. - */ -@Target(ElementType.FIELD) -@Retention(RetentionPolicy.RUNTIME) -public @interface HotSpotVMConstant { - - /** - * Returns the name of the constant. - * - * @return name of constant - */ - String name(); - - /** - * List of architectures where this constant is required. Names are derived from - * {@link HotSpotVMConfig#getHostArchitectureName()}. An empty list implies that the constant is - * required on all architectures. - */ - @SuppressWarnings("javadoc") - String[] archs() default {}; -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.hotspotvmconfig/src/com/oracle/jvmci/hotspotvmconfig/HotSpotVMField.java --- a/graal/com.oracle.jvmci.hotspotvmconfig/src/com/oracle/jvmci/hotspotvmconfig/HotSpotVMField.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,82 +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.jvmci.hotspotvmconfig; - -import java.lang.annotation.*; - -/** - * Refers to a C++ field in the VM. - */ -@Target(ElementType.FIELD) -@Retention(RetentionPolicy.RUNTIME) -public @interface HotSpotVMField { - - /** - * Types of information this annotation can return. - */ - enum Type { - /** - * Returns the offset of this field within the type. Only valid for instance fields. - */ - OFFSET, - - /** - * Returns the absolute address of this field. Only valid for static fields. - */ - ADDRESS, - - /** - * Returns the value of this field. Only valid for static fields. - */ - VALUE; - } - - /** - * Specifies what type of information to return. - * - * @see Type - */ - Type get(); - - /** - * Returns the type name containing this field. - * - * @return name of containing type - */ - String type(); - - /** - * Returns the name of this field. - * - * @return name of field - */ - String name(); - - /** - * List of architectures where this constant is required. Names are derived from - * {@link HotSpotVMConfig#getHostArchitectureName()}. An empty list implies that the constant is - * required on all architectures. - */ - @SuppressWarnings("javadoc") - String[] archs() default {}; -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.hotspotvmconfig/src/com/oracle/jvmci/hotspotvmconfig/HotSpotVMFlag.java --- a/graal/com.oracle.jvmci.hotspotvmconfig/src/com/oracle/jvmci/hotspotvmconfig/HotSpotVMFlag.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,50 +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.jvmci.hotspotvmconfig; - -import java.lang.annotation.*; - -/** - * Refers to a C++ flag in the VM. - */ -@Target(ElementType.FIELD) -@Retention(RetentionPolicy.RUNTIME) -public @interface HotSpotVMFlag { - - /** - * Returns the name of this flag. - * - * @return name of flag. - */ - String name(); - - /** - * List of architectures where this constant is required. Names are derived from - * {@link HotSpotVMConfig#getHostArchitectureName()}. An empty list implies that the constant is - * required on all architectures. - */ - @SuppressWarnings("javadoc") - String[] archs() default {}; - - boolean optional() default false; -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.hotspotvmconfig/src/com/oracle/jvmci/hotspotvmconfig/HotSpotVMType.java --- a/graal/com.oracle.jvmci.hotspotvmconfig/src/com/oracle/jvmci/hotspotvmconfig/HotSpotVMType.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,57 +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.jvmci.hotspotvmconfig; - -import java.lang.annotation.*; - -/** - * Refers to a C++ type in the VM. - */ -@Target(ElementType.FIELD) -@Retention(RetentionPolicy.RUNTIME) -public @interface HotSpotVMType { - - /** - * Types of information this annotation can return. - */ - enum Type { - /** - * Returns the size of the type (C++ {@code sizeof()}). - */ - SIZE; - } - - /** - * Specifies what type of information to return. - * - * @see Type - */ - Type get(); - - /** - * Returns the name of the type. - * - * @return name of type - */ - String name(); -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.hotspotvmconfig/src/com/oracle/jvmci/hotspotvmconfig/HotSpotVMValue.java --- a/graal/com.oracle.jvmci.hotspotvmconfig/src/com/oracle/jvmci/hotspotvmconfig/HotSpotVMValue.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,62 +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.jvmci.hotspotvmconfig; - -import java.lang.annotation.*; - -@Target(ElementType.FIELD) -@Retention(RetentionPolicy.RUNTIME) -public @interface HotSpotVMValue { - - /** - * A C++ expression to be evaluated and assigned to the field. - */ - String expression(); - - enum Type { - /** - * A C++ address which might require extra casts to be safely assigned to a Java field. - */ - ADDRESS, - - /** - * A simple value which can be assigned to a regular Java field. - */ - VALUE - } - - /** - * If {@link #expression} is a C++ function name, {@link #signature} represents the signature of - * the function. - * - */ - String signature() default ""; - - Type get() default Type.VALUE; - - /** - * List of preprocessor symbols that should guard initialization of this value. - */ - String[] defines() default {}; - -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.meta/overview.html --- a/graal/com.oracle.jvmci.meta/overview.html Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,38 +0,0 @@ - - - - - - - - -The com.oracle.jvmci.meta project provides an API to the runtime data structures -for various Java elements. Unlike standard Java reflection, it can model elements that are not yet loaded. -It can also expose profiling information collected by the runtime system. - - - diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/AbstractJavaProfile.java --- a/graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/AbstractJavaProfile.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,158 +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.meta; - -/** - * This object holds probability information for a set of items that were profiled at a specific - * BCI. The precision of the supplied values may vary, but a runtime that provides this information - * should be aware that it will be used to guide performance-critical decisions like speculative - * inlining, etc. - * - * @param a subclass of AbstractProfiledItem - * @param the class of the items that are profiled at the specific BCI and for which - * probabilities are stored. E.g., a ResolvedJavaType or a ResolvedJavaMethod. - */ -public abstract class AbstractJavaProfile, U> { - - private final double notRecordedProbability; - private final T[] pitems; - - public AbstractJavaProfile(double notRecordedProbability, T[] pitems) { - this.pitems = pitems; - assert !Double.isNaN(notRecordedProbability); - this.notRecordedProbability = notRecordedProbability; - assert isSorted(); - assert totalProbablility() >= 0 && totalProbablility() <= 1.0001 : totalProbablility() + " " + this; - } - - private double totalProbablility() { - double total = notRecordedProbability; - for (T item : pitems) { - total += item.probability; - } - return total; - } - - /** - * Determines if an array of profiled items are sorted in descending order of their - * probabilities. - */ - private boolean isSorted() { - for (int i = 1; i < pitems.length; i++) { - if (pitems[i - 1].getProbability() < pitems[i].getProbability()) { - return false; - } - } - return true; - } - - /** - * Returns the estimated probability of all types that could not be recorded due to profiling - * limitations. - * - * @return double value ≥ 0.0 and ≤ 1.0 - */ - public double getNotRecordedProbability() { - return notRecordedProbability; - } - - protected T[] getItems() { - return pitems; - } - - /** - * Searches for an entry of a given resolved Java type. - * - * @param type the type for which an entry should be searched - * @return the entry or null if no entry for this type can be found - */ - public T findEntry(ResolvedJavaType type) { - if (pitems != null) { - for (T pt : pitems) { - if (pt.getItem().equals(type)) { - return pt; - } - } - } - return null; - } - - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getName()); - builder.append("["); - if (pitems != null) { - for (T pt : pitems) { - builder.append(pt.toString()); - builder.append(", "); - } - } - builder.append(this.notRecordedProbability); - builder.append("]"); - return builder.toString(); - } - - public boolean isIncluded(U item) { - if (this.getNotRecordedProbability() > 0.0) { - return true; - } else { - for (int i = 0; i < getItems().length; i++) { - T pitem = getItems()[i]; - U curType = pitem.getItem(); - if (curType == item) { - return true; - } - } - } - return false; - } - - @Override - public boolean equals(Object obj) { - if (obj == this) { - return true; - } - if (!(obj instanceof AbstractJavaProfile)) { - return false; - } - AbstractJavaProfile that = (AbstractJavaProfile) obj; - if (that.notRecordedProbability != notRecordedProbability) { - return false; - } - if (that.pitems.length != pitems.length) { - return false; - } - for (int i = 0; i < pitems.length; ++i) { - if (!pitems[i].equals(that.pitems[i])) { - return false; - } - } - return true; - } - - @Override - public int hashCode() { - return (int) Double.doubleToLongBits(notRecordedProbability) + pitems.length * 13; - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/AbstractProfiledItem.java --- a/graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/AbstractProfiledItem.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,95 +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.meta; - -/** - * A profiled type that has a probability. Profiled types are naturally sorted in descending order - * of their probabilities. - */ -public abstract class AbstractProfiledItem implements Comparable> { - - protected final T item; - protected final double probability; - - public AbstractProfiledItem(T item, double probability) { - assert item != null; - assert probability >= 0.0D && probability <= 1.0D; - this.item = item; - this.probability = probability; - } - - protected T getItem() { - return item; - } - - /** - * Returns the estimated probability of {@link #getItem()}. - * - * @return double value ≥ 0.0 and ≤ 1.0 - */ - public double getProbability() { - return probability; - } - - @Override - public int compareTo(AbstractProfiledItem o) { - if (getProbability() > o.getProbability()) { - return -1; - } else if (getProbability() < o.getProbability()) { - return 1; - } - return 0; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - long temp; - temp = Double.doubleToLongBits(probability); - result = prime * result + (int) (temp ^ (temp >>> 32)); - result = prime * result + item.hashCode(); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - AbstractProfiledItem other = (AbstractProfiledItem) obj; - if (Double.doubleToLongBits(probability) != Double.doubleToLongBits(other.probability)) { - return false; - } - return item.equals(other.item); - } - - @Override - public abstract String toString(); -} diff -r 42452d2dfbec -r 395ac43a8578 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 Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,98 +0,0 @@ -/* - * Copyright (c) 2009, 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; - -/** - * Abstract base class for values. - */ -public abstract class AbstractValue implements Value, KindProvider { - - public static final AllocatableValue ILLEGAL = Value.ILLEGAL; - - private final Kind kind; - private final LIRKind lirKind; - - /** - * Initializes a new value of the specified kind. - * - * @param lirKind the kind - */ - protected AbstractValue(LIRKind lirKind) { - this.lirKind = lirKind; - if (getPlatformKind() instanceof Kind) { - this.kind = (Kind) getPlatformKind(); - } else { - this.kind = Kind.Illegal; - } - } - - /** - * Returns a String representation of the kind, which should be the end of all - * {@link #toString()} implementation of subclasses. - */ - protected final String getKindSuffix() { - return "|" + getKind().getTypeChar(); - } - - /** - * Returns the kind of this value. - */ - public final Kind getKind() { - return kind; - } - - public final LIRKind getLIRKind() { - return lirKind; - } - - /** - * Returns the platform specific kind used to store this value. - */ - public final PlatformKind getPlatformKind() { - return lirKind.getPlatformKind(); - } - - @Override - public int hashCode() { - return 41 + lirKind.hashCode(); - } - - @Override - public boolean equals(Object obj) { - if (obj instanceof AbstractValue) { - AbstractValue that = (AbstractValue) obj; - return kind.equals(that.kind) && lirKind.equals(that.lirKind); - } - return false; - } - - /** - * Checks if this value is identical to {@code other}. - * - * Warning: Use with caution! Usually equivalence {@link #equals(Object)} is sufficient and - * should be used. - */ - public final boolean identityEquals(AbstractValue other) { - return this == other; - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/AllocatableValue.java --- a/graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/AllocatableValue.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,36 +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.jvmci.meta; - -/** - * Common base class for values that are stored in some location that's managed by the register - * allocator (e.g. register, stack slot). - */ -public abstract class AllocatableValue extends AbstractValue implements JavaValue, KindProvider { - - public static final AllocatableValue[] NONE = {}; - - public AllocatableValue(LIRKind lirKind) { - super(lirKind); - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/Assumptions.java --- a/graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/Assumptions.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,380 +0,0 @@ -/* - * Copyright (c) 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.meta; - -import java.lang.invoke.*; -import java.util.*; - -/** - * Class for recording assumptions made during compilation. - */ -public final class Assumptions implements Iterable { - - /** - * Abstract base class for assumptions. An assumption assumes a property of the runtime that may - * be invalidated by subsequent execution (e.g., that a class has no subclasses implementing - * {@link NoFinalizableSubclass Object.finalize()}). - */ - public abstract static class Assumption { - } - - /** - * A class for providing information that is only valid in association with a set of - * {@link Assumption}s. - * - * @param - */ - public static class AssumptionResult { - Assumption[] assumptions; - final T result; - - private static final Assumption[] EMPTY = new Assumption[0]; - - public AssumptionResult(T result, Assumption... assumptions) { - this.result = result; - this.assumptions = assumptions; - } - - public AssumptionResult(T result) { - this(result, EMPTY); - } - - public T getResult() { - return result; - } - - public boolean isAssumptionFree() { - return assumptions.length == 0; - } - - public void add(AssumptionResult other) { - Assumption[] newAssumptions = Arrays.copyOf(this.assumptions, this.assumptions.length + other.assumptions.length); - System.arraycopy(other.assumptions, 0, newAssumptions, this.assumptions.length, other.assumptions.length); - this.assumptions = newAssumptions; - } - } - - /** - * An assumption that a given class has no subclasses implementing {@link Object#finalize()}). - */ - public static final class NoFinalizableSubclass extends Assumption { - - private ResolvedJavaType receiverType; - - public NoFinalizableSubclass(ResolvedJavaType receiverType) { - this.receiverType = receiverType; - } - - @Override - public int hashCode() { - return 31 + receiverType.hashCode(); - } - - @Override - public boolean equals(Object obj) { - if (obj instanceof NoFinalizableSubclass) { - NoFinalizableSubclass other = (NoFinalizableSubclass) obj; - return other.receiverType.equals(receiverType); - } - return false; - } - - @Override - public String toString() { - return "NoFinalizableSubclass[receiverType=" + receiverType.toJavaName() + "]"; - } - - } - - /** - * An assumption that a given abstract or interface type has one direct concrete subtype. There - * is no requirement that the subtype is a leaf type. - */ - public static final class ConcreteSubtype extends Assumption { - - /** - * Type the assumption is made about. - */ - public final ResolvedJavaType context; - - /** - * Assumed concrete sub-type of the context type. - */ - public final ResolvedJavaType subtype; - - public ConcreteSubtype(ResolvedJavaType context, ResolvedJavaType subtype) { - this.context = context; - this.subtype = subtype; - assert context.isAbstract(); - assert subtype.isConcrete() || context.isInterface() : subtype.toString() + " : " + context.toString(); - assert !subtype.isArray() || subtype.getElementalType().isFinal() : subtype.toString() + " : " + context.toString(); - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + context.hashCode(); - result = prime * result + subtype.hashCode(); - return result; - } - - @Override - public boolean equals(Object obj) { - if (obj instanceof ConcreteSubtype) { - ConcreteSubtype other = (ConcreteSubtype) obj; - return other.context.equals(context) && other.subtype.equals(subtype); - } - return false; - } - - @Override - public String toString() { - return "ConcreteSubtype[context=" + context.toJavaName() + ", subtype=" + subtype.toJavaName() + "]"; - } - } - - /** - * An assumption that a given type has no subtypes. - */ - public static final class LeafType extends Assumption { - - /** - * Type the assumption is made about. - */ - public final ResolvedJavaType context; - - public LeafType(ResolvedJavaType context) { - this.context = context; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + context.hashCode(); - return result; - } - - @Override - public boolean equals(Object obj) { - if (obj instanceof LeafType) { - LeafType other = (LeafType) obj; - return other.context.equals(context); - } - return false; - } - - @Override - public String toString() { - return "LeafSubtype[context=" + context.toJavaName() + "]"; - } - } - - /** - * An assumption that a given virtual method has a given unique implementation. - */ - public static final class ConcreteMethod extends Assumption { - - /** - * A virtual (or interface) method whose unique implementation for the receiver type in - * {@link #context} is {@link #impl}. - */ - public final ResolvedJavaMethod method; - - /** - * A receiver type. - */ - public final ResolvedJavaType context; - - /** - * The unique implementation of {@link #method} for {@link #context}. - */ - public final ResolvedJavaMethod impl; - - public ConcreteMethod(ResolvedJavaMethod method, ResolvedJavaType context, ResolvedJavaMethod impl) { - this.method = method; - this.context = context; - this.impl = impl; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + method.hashCode(); - result = prime * result + context.hashCode(); - result = prime * result + impl.hashCode(); - return result; - } - - @Override - public boolean equals(Object obj) { - if (obj instanceof ConcreteMethod) { - ConcreteMethod other = (ConcreteMethod) obj; - return other.method.equals(method) && other.context.equals(context) && other.impl.equals(impl); - } - return false; - } - - @Override - public String toString() { - return "ConcreteMethod[method=" + method.format("%H.%n(%p)%r") + ", context=" + context.toJavaName() + ", impl=" + impl.format("%H.%n(%p)%r") + "]"; - } - } - - /** - * An assumption that a given call site's method handle did not change. - */ - public static final class CallSiteTargetValue extends Assumption { - - public final CallSite callSite; - public final MethodHandle methodHandle; - - public CallSiteTargetValue(CallSite callSite, MethodHandle methodHandle) { - this.callSite = callSite; - this.methodHandle = methodHandle; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + callSite.hashCode(); - result = prime * result + methodHandle.hashCode(); - return result; - } - - @Override - public boolean equals(Object obj) { - if (obj instanceof CallSiteTargetValue) { - CallSiteTargetValue other = (CallSiteTargetValue) obj; - return callSite.equals(other.callSite) && methodHandle.equals(other.methodHandle); - } - return false; - } - - @Override - public String toString() { - return "CallSiteTargetValue[callSite=" + callSite + ", methodHandle=" + methodHandle + "]"; - } - } - - private final Set assumptions = new HashSet<>(); - - /** - * Returns whether any assumptions have been registered. - * - * @return {@code true} if at least one assumption has been registered, {@code false} otherwise. - */ - public boolean isEmpty() { - return assumptions.isEmpty(); - } - - @Override - public int hashCode() { - throw new UnsupportedOperationException("hashCode"); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj instanceof Assumptions) { - Assumptions that = (Assumptions) obj; - if (!this.assumptions.equals(that.assumptions)) { - return false; - } - return true; - } - return false; - } - - @Override - public Iterator iterator() { - return assumptions.iterator(); - } - - /** - * Records an assumption that the specified type has no finalizable subclasses. - * - * @param receiverType the type that is assumed to have no finalizable subclasses - */ - public void recordNoFinalizableSubclassAssumption(ResolvedJavaType receiverType) { - record(new NoFinalizableSubclass(receiverType)); - } - - /** - * Records that {@code subtype} is the only concrete subtype in the class hierarchy below - * {@code context}. - * - * @param context the root of the subtree of the class hierarchy that this assumptions is about - * @param subtype the one concrete subtype - */ - public void recordConcreteSubtype(ResolvedJavaType context, ResolvedJavaType subtype) { - record(new ConcreteSubtype(context, subtype)); - } - - /** - * Records that {@code impl} is the only possible concrete target for a virtual call to - * {@code method} with a receiver of type {@code context}. - * - * @param method a method that is the target of a virtual call - * @param context the receiver type of a call to {@code method} - * @param impl the concrete method that is the only possible target for the virtual call - */ - public void recordConcreteMethod(ResolvedJavaMethod method, ResolvedJavaType context, ResolvedJavaMethod impl) { - record(new ConcreteMethod(method, context, impl)); - } - - public void record(AssumptionResult result) { - for (Assumption assumption : result.assumptions) { - record(assumption); - } - } - - public void record(Assumption assumption) { - assumptions.add(assumption); - } - - /** - * Gets a copy of the assumptions recorded in this object as an array. - */ - public Assumption[] toArray() { - return assumptions.toArray(new Assumption[assumptions.size()]); - } - - /** - * Copies assumptions recorded by another {@link Assumptions} object into this object. - */ - public void record(Assumptions other) { - assert other != this; - assumptions.addAll(other.assumptions); - } - - @Override - public String toString() { - return "Assumptions[" + assumptions + "]"; - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/Constant.java --- a/graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/Constant.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,33 +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; - -/** - * Represents a compile-time constant (boxed) value within the compiler. - */ -public interface Constant { - - boolean isDefaultForKind(); - - String toValueString(); -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/ConstantPool.java --- a/graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/ConstantPool.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,121 +0,0 @@ -/* - * Copyright (c) 2009, 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; - -/** - * Represents the runtime representation of the constant pool that is used by the compiler when - * parsing bytecode. Provides methods to look up a constant pool entry without performing - * resolution. They are used during compilation. - */ -public interface ConstantPool { - - /** - * Returns the number of entries the constant pool. - * - * @return number of entries in the constant pool - */ - int length(); - - /** - * Ensures that the type referenced by the specified constant pool entry is loaded and - * initialized. This can be used to compile time resolve a type. It works for field, method, or - * type constant pool entries. - * - * @param cpi the index of the constant pool entry that references the type - * @param opcode the opcode of the instruction that references the type - */ - void loadReferencedType(int cpi, int opcode); - - /** - * Looks up a reference to a field. If {@code opcode} is non-negative, then resolution checks - * specific to the bytecode it denotes are performed if the field is already resolved. Should - * any of these checks fail, an unresolved field reference is returned. - * - * @param cpi the constant pool index - * @param opcode the opcode of the instruction for which the lookup is being performed or - * {@code -1} - * @return a reference to the field at {@code cpi} in this pool - * @throws ClassFormatError if the entry at {@code cpi} is not a field - */ - JavaField lookupField(int cpi, int opcode); - - /** - * Looks up a reference to a method. If {@code opcode} is non-negative, then resolution checks - * specific to the bytecode it denotes are performed if the method is already resolved. Should - * any of these checks fail, an unresolved method reference is returned. - * - * @param cpi the constant pool index - * @param opcode the opcode of the instruction for which the lookup is being performed or - * {@code -1} - * @return a reference to the method at {@code cpi} in this pool - * @throws ClassFormatError if the entry at {@code cpi} is not a method - */ - JavaMethod lookupMethod(int cpi, int opcode); - - /** - * Looks up a reference to a type. If {@code opcode} is non-negative, then resolution checks - * specific to the bytecode it denotes are performed if the type is already resolved. Should any - * of these checks fail, an unresolved type reference is returned. - * - * @param cpi the constant pool index - * @param opcode the opcode of the instruction for which the lookup is being performed or - * {@code -1} - * @return a reference to the compiler interface type - */ - JavaType lookupType(int cpi, int opcode); - - /** - * Looks up an Utf8 string. - * - * @param cpi the constant pool index - * @return the Utf8 string at index {@code cpi} in this constant pool - */ - String lookupUtf8(int cpi); - - /** - * Looks up a method signature. - * - * @param cpi the constant pool index - * @return the method signature at index {@code cpi} in this constant pool - */ - Signature lookupSignature(int cpi); - - /** - * Looks up a constant at the specified index. - * - * @param cpi the constant pool index - * @return the {@code Constant} or {@code JavaType} instance representing the constant pool - * entry - */ - Object lookupConstant(int cpi); - - /** - * Looks up the appendix at the specified index. - * - * @param cpi the constant pool index - * @param opcode the opcode of the instruction for which the lookup is being performed or - * {@code -1} - * @return the appendix if it exists and is resolved or {@code null} - */ - JavaConstant lookupAppendix(int cpi, int opcode); -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/ConstantReflectionProvider.java --- a/graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/ConstantReflectionProvider.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,152 +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.jvmci.meta; - -import java.lang.invoke.*; - -/** - * Reflection operations on values represented as {@linkplain JavaConstant constants}. All methods - * in this interface require the VM to access the actual object encapsulated in {@link Kind#Object - * object} constants. This access is not always possible, depending on kind of VM and the state that - * the VM is in. Therefore, all methods can return {@code null} at any time, to indicate that the - * result is not available at this point. The caller is responsible to check for {@code null} - * results and handle them properly, e.g., not perform an optimization. - */ -public interface ConstantReflectionProvider { - - /** - * Compares two constants for equality. The equality relationship is symmetric. Returns - * {@link Boolean#TRUE true} if the two constants represent the same run time value, - * {@link Boolean#FALSE false} if they are different. Returns {@code null} if the constants - * cannot be compared at this point. - */ - Boolean constantEquals(Constant x, Constant y); - - /** - * Returns the length of the array constant. Returns {@code null} if the constant is not an - * array, or if the array length is not available at this point. - */ - Integer readArrayLength(JavaConstant array); - - /** - * Reads a value from the given array at the given index. Returns {@code null} if the constant - * is not an array, if the index is out of bounds, or if the value is not available at this - * point. - */ - JavaConstant readArrayElement(JavaConstant array, int index); - - /** - * Reads a value from the given array at the given index if it is a stable array. Returns - * {@code null} if the constant is not a stable array, if it is a default value, if the index is - * out of bounds, or if the value is not available at this point. - */ - JavaConstant readConstantArrayElement(JavaConstant array, int index); - - /** - * Reads a value from the given array at the given offset if it is a stable array. The offset - * will be decoded relative to the platform addressing into an index into the array. Returns - * {@code null} if the constant is not a stable array, if it is a default value, if the offset - * is out of bounds, or if the value is not available at this point. - */ - JavaConstant readConstantArrayElementForOffset(JavaConstant array, long offset); - - /** - * Gets the constant value of this field. Note that a {@code static final} field may not be - * considered constant if its declaring class is not yet initialized or if it is a well known - * field that can be updated via other means (e.g., {@link System#setOut(java.io.PrintStream)}). - * - * @param receiver object from which this field's value is to be read. This value is ignored if - * this field is static. - * @return the constant value of this field or {@code null} if this field is not considered - * constant by the runtime - */ - JavaConstant readConstantFieldValue(JavaField field, JavaConstant receiver); - - /** - * Gets the current value of this field for a given object, if available. - * - * There is no guarantee that the same value will be returned by this method for a field unless - * the field is considered to be {@linkplain #readConstantFieldValue(JavaField, JavaConstant) - * constant} by the runtime. - * - * @param receiver object from which this field's value is to be read. This value is ignored if - * this field is static. - * @return the value of this field or {@code null} if the value is not available (e.g., because - * the field holder is not yet initialized). - */ - JavaConstant readFieldValue(JavaField field, JavaConstant receiver); - - /** - * Gets the current value of this field for a given object, if available. Like - * {@link #readFieldValue(JavaField, JavaConstant)} but treats array fields as stable. - * - * There is no guarantee that the same value will be returned by this method for a field unless - * the field is considered to be {@linkplain #readConstantFieldValue(JavaField, JavaConstant) - * constant} by the runtime. - * - * @param receiver object from which this field's value is to be read. This value is ignored if - * this field is static. - * @param isDefaultStable if {@code true}, default values are considered stable - * @return the value of this field or {@code null} if the value is not available (e.g., because - * the field holder is not yet initialized). - */ - JavaConstant readStableFieldValue(JavaField field, JavaConstant receiver, boolean isDefaultStable); - - /** - * Converts the given {@link Kind#isPrimitive() primitive} constant to a boxed - * {@link Kind#Object object} constant, according to the Java boxing rules. Returns {@code null} - * if the source is is not a primitive constant, or the boxed value is not available at this - * point. - */ - JavaConstant boxPrimitive(JavaConstant source); - - /** - * Converts the given {@link Kind#Object object} constant to a {@link Kind#isPrimitive() - * primitive} constant, according to the Java unboxing rules. Returns {@code null} if the source - * is is not an object constant that can be unboxed, or the unboxed value is not available at - * this point. - */ - JavaConstant unboxPrimitive(JavaConstant source); - - /** - * Gets a string as a {@link JavaConstant}. - */ - JavaConstant forString(String value); - - /** - * Returns the {@link ResolvedJavaType} for a {@link Class} object (or any other object regarded - * as a class by the VM) encapsulated in the given constant. Returns {@code null} if the - * constant does not encapsulate a class, or if the type is not available at this point. - */ - ResolvedJavaType asJavaType(Constant constant); - - /** - * Gets access to the internals of {@link MethodHandle}. - */ - MethodHandleAccessProvider getMethodHandleAccess(); - - /** - * Gets raw memory access. - */ - MemoryAccessProvider getMemoryAccessProvider(); -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/DefaultProfilingInfo.java --- a/graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/DefaultProfilingInfo.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,110 +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.jvmci.meta; - -/** - * An implementation of {@link ProfilingInfo} that can used in the absence of real profile - * information. - */ -public final class DefaultProfilingInfo implements ProfilingInfo { - - private static final ProfilingInfo[] NO_PROFILING_INFO = new ProfilingInfo[]{new DefaultProfilingInfo(TriState.TRUE), new DefaultProfilingInfo(TriState.FALSE), - new DefaultProfilingInfo(TriState.UNKNOWN)}; - - private final TriState exceptionSeen; - - DefaultProfilingInfo(TriState exceptionSeen) { - this.exceptionSeen = exceptionSeen; - } - - @Override - public int getCodeSize() { - return 0; - } - - @Override - public JavaTypeProfile getTypeProfile(int bci) { - return null; - } - - @Override - public JavaMethodProfile getMethodProfile(int bci) { - return null; - } - - @Override - public double getBranchTakenProbability(int bci) { - return -1; - } - - @Override - public double[] getSwitchProbabilities(int bci) { - return null; - } - - @Override - public TriState getExceptionSeen(int bci) { - return exceptionSeen; - } - - @Override - public TriState getNullSeen(int bci) { - return TriState.UNKNOWN; - } - - @Override - public int getExecutionCount(int bci) { - return -1; - } - - public static ProfilingInfo get(TriState exceptionSeen) { - return NO_PROFILING_INFO[exceptionSeen.ordinal()]; - } - - @Override - public int getDeoptimizationCount(DeoptimizationReason reason) { - return 0; - } - - @Override - public boolean isMature() { - return false; - } - - @Override - public String toString() { - return "BaseProfilingInfo<" + this.toString(null, "; ") + ">"; - } - - public void setMature() { - // Do nothing - } - - public boolean setCompilerIRSize(Class irType, int nodeCount) { - return false; - } - - public int getCompilerIRSize(Class irType) { - return -1; - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/DeoptimizationAction.java --- a/graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/DeoptimizationAction.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,70 +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.jvmci.meta; - -/** - * Specifies the action that should be taken by the runtime in case a certain deoptimization is - * triggered. - */ -public enum DeoptimizationAction { - /** - * Do not invalidate the machine code. This is typically used when deoptimizing at a point where - * it's highly likely nothing will change the likelihood of the deoptimization happening again. - * For example, a compiled array allocation where the size is negative. - */ - None(false), - - /** - * Do not invalidate the machine code, but schedule a recompilation if this deoptimization is - * triggered too often. - */ - RecompileIfTooManyDeopts(true), - - /** - * Invalidate the machine code and reset the profiling information. - */ - InvalidateReprofile(true), - - /** - * Invalidate the machine code and immediately schedule a recompilation. This is typically used - * when deoptimizing to resolve an unresolved symbol in which case extra profiling is not - * required to determine that the deoptimization will not re-occur. - */ - InvalidateRecompile(true), - - /** - * Invalidate the machine code and stop compiling the outermost method of this compilation. - */ - InvalidateStopCompiling(true); - - private final boolean invalidatesCompilation; - - private DeoptimizationAction(boolean invalidatesCompilation) { - this.invalidatesCompilation = invalidatesCompilation; - } - - public boolean doesInvalidateCompilation() { - return invalidatesCompilation; - } - -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/DeoptimizationReason.java --- a/graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/DeoptimizationReason.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2012, 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.meta; - -/** - * Enumeration of reasons for why a deoptimization is happening. - */ -public enum DeoptimizationReason { - None, - NullCheckException, - BoundsCheckException, - ClassCastException, - ArrayStoreException, - UnreachedCode, - TypeCheckedInliningViolated, - OptimizedTypeCheckViolated, - NotCompiledExceptionHandler, - Unresolved, - JavaSubroutineMismatch, - ArithmeticException, - RuntimeConstraint, - LoopLimitCheck, - Aliasing, - TransferToInterpreter, -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/ExceptionHandler.java --- a/graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/ExceptionHandler.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,121 +0,0 @@ -/* - * Copyright (c) 2009, 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.meta; - -import java.util.*; - -/** - * Represents an exception handler within the bytecodes. - */ -public final class ExceptionHandler { - - private final int startBCI; - private final int endBCI; - private final int handlerBCI; - private final int catchTypeCPI; - private final JavaType catchType; - - /** - * Creates a new exception handler with the specified ranges. - * - * @param startBCI the start index of the protected range - * @param endBCI the end index of the protected range - * @param catchBCI the index of the handler - * @param catchTypeCPI the index of the throwable class in the constant pool - * @param catchType the type caught by this exception handler - */ - public ExceptionHandler(int startBCI, int endBCI, int catchBCI, int catchTypeCPI, JavaType catchType) { - this.startBCI = startBCI; - this.endBCI = endBCI; - this.handlerBCI = catchBCI; - this.catchTypeCPI = catchTypeCPI; - this.catchType = catchType; - } - - /** - * Returns the start bytecode index of the protected range of this handler. - */ - public int getStartBCI() { - return startBCI; - } - - /** - * Returns the end bytecode index of the protected range of this handler. - */ - public int getEndBCI() { - return endBCI; - } - - /** - * Returns the bytecode index of the handler block of this handler. - */ - public int getHandlerBCI() { - return handlerBCI; - } - - /** - * Returns the index into the constant pool representing the type of exception caught by this - * handler. - */ - public int catchTypeCPI() { - return catchTypeCPI; - } - - /** - * Checks whether this handler catches all exceptions. - * - * @return {@code true} if this handler catches all exceptions - */ - public boolean isCatchAll() { - return catchTypeCPI == 0; - } - - /** - * Returns the type of exception caught by this exception handler. - */ - public JavaType getCatchType() { - return catchType; - } - - @Override - public boolean equals(Object obj) { - if (!(obj instanceof ExceptionHandler)) { - return false; - } - ExceptionHandler that = (ExceptionHandler) obj; - if (this.startBCI != that.startBCI || this.endBCI != that.endBCI || this.handlerBCI != that.handlerBCI || this.catchTypeCPI != that.catchTypeCPI) { - return false; - } - return Objects.equals(this.catchType, that.catchType); - } - - @Override - public String toString() { - return "ExceptionHandler"; - } - - @Override - public int hashCode() { - return catchTypeCPI ^ endBCI ^ handlerBCI; - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/ForeignCallDescriptor.java --- a/graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/ForeignCallDescriptor.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,98 +0,0 @@ -/* - * Copyright (c) 2009, 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.meta; - -import java.util.*; - -/** - * The name and signature of a foreign call. A foreign call differs from a normal compiled Java call - * in at least one of these aspects: - *

    - *
  • The call is to C/C++/assembler code.
  • - *
  • The call uses different conventions for passing parameters or returning values.
  • - *
  • The callee has different register saving semantics. For example, the callee may save all - * registers (apart from some specified temporaries) in which case the register allocator doesn't - * not need to spill all live registers around the call site.
  • - *
  • The call does not occur at an INVOKE* bytecode. Such a call could be transformed into a - * standard Java call if the foreign routine is a normal Java method and the runtime supports - * linking Java calls at arbitrary bytecodes.
  • - *
- */ -public class ForeignCallDescriptor { - - private final String name; - private final Class resultType; - private final Class[] argumentTypes; - - public ForeignCallDescriptor(String name, Class resultType, Class... argumentTypes) { - this.name = name; - this.resultType = resultType; - this.argumentTypes = argumentTypes; - } - - /** - * Gets the name of this foreign call. - */ - public String getName() { - return name; - } - - /** - * Gets the return type of this foreign call. - */ - public Class getResultType() { - return resultType; - } - - /** - * Gets the argument types of this foreign call. - */ - public Class[] getArgumentTypes() { - return argumentTypes.clone(); - } - - @Override - public int hashCode() { - return name.hashCode(); - } - - @Override - public boolean equals(Object obj) { - if (obj instanceof ForeignCallDescriptor) { - ForeignCallDescriptor other = (ForeignCallDescriptor) obj; - return other.name.equals(name) && other.resultType.equals(resultType) && Arrays.equals(other.argumentTypes, argumentTypes); - } - return false; - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(name).append('('); - String sep = ""; - for (Class arg : argumentTypes) { - sb.append(sep).append(arg.getSimpleName()); - sep = ","; - } - return sb.append(')').append(resultType.getSimpleName()).toString(); - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/InvokeTarget.java --- a/graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/InvokeTarget.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,29 +0,0 @@ -/* - * Copyright (c) 2013, 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.meta; - -/** - * Represents the resolved target of an invocation. - */ -public interface InvokeTarget { -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/JavaConstant.java --- a/graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/JavaConstant.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,458 +0,0 @@ -/* - * Copyright (c) 2009, 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; - -/** - * Represents a constant (boxed) value, such as an integer, floating point number, or object - * reference, within the compiler and across the compiler/runtime interface. Exports a set of - * {@code JavaConstant} instances that represent frequently used constant values, such as - * {@link #NULL_POINTER}. - */ -public interface JavaConstant extends Constant, JavaValue, Value { - - /* - * Using a larger cache for integers leads to only a slight increase in cache hit ratio which is - * not enough to justify the impact on startup time. - */ - JavaConstant NULL_POINTER = new NullConstant(); - PrimitiveConstant INT_MINUS_1 = new PrimitiveConstant(Kind.Int, -1); - PrimitiveConstant INT_0 = new PrimitiveConstant(Kind.Int, 0); - PrimitiveConstant INT_1 = new PrimitiveConstant(Kind.Int, 1); - PrimitiveConstant INT_2 = new PrimitiveConstant(Kind.Int, 2); - PrimitiveConstant LONG_0 = new PrimitiveConstant(Kind.Long, 0L); - PrimitiveConstant LONG_1 = new PrimitiveConstant(Kind.Long, 1L); - PrimitiveConstant FLOAT_0 = new PrimitiveConstant(Kind.Float, Float.floatToRawIntBits(0.0F)); - PrimitiveConstant FLOAT_1 = new PrimitiveConstant(Kind.Float, Float.floatToRawIntBits(1.0F)); - PrimitiveConstant DOUBLE_0 = new PrimitiveConstant(Kind.Double, Double.doubleToRawLongBits(0.0D)); - PrimitiveConstant DOUBLE_1 = new PrimitiveConstant(Kind.Double, Double.doubleToRawLongBits(1.0D)); - PrimitiveConstant TRUE = new PrimitiveConstant(Kind.Boolean, 1L); - PrimitiveConstant FALSE = new PrimitiveConstant(Kind.Boolean, 0L); - - /** - * Checks whether this constant is null. - * - * @return {@code true} if this constant is the null constant - */ - boolean isNull(); - - static boolean isNull(Constant c) { - if (c instanceof JavaConstant) { - return ((JavaConstant) c).isNull(); - } else { - return false; - } - } - - /** - * Checks whether this constant is non-null. - * - * @return {@code true} if this constant is a primitive, or an object constant that is not null - */ - default boolean isNonNull() { - return !isNull(); - } - - /** - * Checks whether this constant is the default value for its kind (null, 0, 0.0, false). - * - * @return {@code true} if this constant is the default value for its kind - */ - boolean isDefaultForKind(); - - /** - * Returns the value of this constant as a boxed Java value. - * - * @return the value of this constant - */ - Object asBoxedPrimitive(); - - /** - * Returns the primitive int value this constant represents. The constant must have a - * {@link Kind#getStackKind()} of {@link Kind#Int}. - * - * @return the constant value - */ - int asInt(); - - /** - * Returns the primitive boolean value this constant represents. The constant must have kind - * {@link Kind#Boolean}. - * - * @return the constant value - */ - boolean asBoolean(); - - /** - * Returns the primitive long value this constant represents. The constant must have kind - * {@link Kind#Long}, a {@link Kind#getStackKind()} of {@link Kind#Int}. - * - * @return the constant value - */ - long asLong(); - - /** - * Returns the primitive float value this constant represents. The constant must have kind - * {@link Kind#Float}. - * - * @return the constant value - */ - float asFloat(); - - /** - * Returns the primitive double value this constant represents. The constant must have kind - * {@link Kind#Double}. - * - * @return the constant value - */ - double asDouble(); - - default String toValueString() { - if (getKind() == Kind.Illegal) { - return "illegal"; - } else { - return getKind().format(asBoxedPrimitive()); - } - } - - static String toString(JavaConstant constant) { - if (constant.getKind() == Kind.Illegal) { - return "illegal"; - } else { - return constant.getKind().getJavaName() + "[" + constant.toValueString() + "]"; - } - } - - /** - * Creates a boxed double constant. - * - * @param d the double value to box - * @return a boxed copy of {@code value} - */ - static PrimitiveConstant forDouble(double d) { - if (Double.compare(0.0D, d) == 0) { - return DOUBLE_0; - } - if (Double.compare(d, 1.0D) == 0) { - return DOUBLE_1; - } - return new PrimitiveConstant(Kind.Double, Double.doubleToRawLongBits(d)); - } - - /** - * Creates a boxed float constant. - * - * @param f the float value to box - * @return a boxed copy of {@code value} - */ - static PrimitiveConstant forFloat(float f) { - if (Float.compare(f, 0.0F) == 0) { - return FLOAT_0; - } - if (Float.compare(f, 1.0F) == 0) { - return FLOAT_1; - } - return new PrimitiveConstant(Kind.Float, Float.floatToRawIntBits(f)); - } - - /** - * Creates a boxed long constant. - * - * @param i the long value to box - * @return a boxed copy of {@code value} - */ - static PrimitiveConstant forLong(long i) { - if (i == 0) { - return LONG_0; - } else if (i == 1) { - return LONG_1; - } else { - return new PrimitiveConstant(Kind.Long, i); - } - } - - /** - * Creates a boxed integer constant. - * - * @param i the integer value to box - * @return a boxed copy of {@code value} - */ - static PrimitiveConstant forInt(int i) { - switch (i) { - case -1: - return INT_MINUS_1; - case 0: - return INT_0; - case 1: - return INT_1; - case 2: - return INT_2; - default: - return new PrimitiveConstant(Kind.Int, i); - } - } - - /** - * Creates a boxed byte constant. - * - * @param i the byte value to box - * @return a boxed copy of {@code value} - */ - static PrimitiveConstant forByte(byte i) { - return new PrimitiveConstant(Kind.Byte, i); - } - - /** - * Creates a boxed boolean constant. - * - * @param i the boolean value to box - * @return a boxed copy of {@code value} - */ - static PrimitiveConstant forBoolean(boolean i) { - return i ? TRUE : FALSE; - } - - /** - * Creates a boxed char constant. - * - * @param i the char value to box - * @return a boxed copy of {@code value} - */ - static PrimitiveConstant forChar(char i) { - return new PrimitiveConstant(Kind.Char, i); - } - - /** - * Creates a boxed short constant. - * - * @param i the short value to box - * @return a boxed copy of {@code value} - */ - static PrimitiveConstant forShort(short i) { - return new PrimitiveConstant(Kind.Short, i); - } - - /** - * Creates a {@link JavaConstant} from a primitive integer of a certain kind. - */ - static PrimitiveConstant forIntegerKind(Kind kind, long i) { - switch (kind) { - case Boolean: - return forBoolean(i != 0); - case Byte: - return forByte((byte) i); - case Short: - return forShort((short) i); - case Char: - return forChar((char) i); - case Int: - return forInt((int) i); - case Long: - return forLong(i); - default: - throw new IllegalArgumentException("not an integer kind: " + kind); - } - } - - /** - * Creates a {@link JavaConstant} from a primitive integer of a certain width. - */ - static PrimitiveConstant forPrimitiveInt(int bits, long i) { - assert bits <= 64; - switch (bits) { - case 1: - return forBoolean(i != 0); - case 8: - return forByte((byte) i); - case 16: - return forShort((short) i); - case 32: - return forInt((int) i); - case 64: - return forLong(i); - default: - throw new IllegalArgumentException("unsupported integer width: " + bits); - } - } - - /** - * Creates a boxed constant for the given boxed primitive value. - * - * @param value the Java boxed value - * @return the primitive constant holding the {@code value} - */ - static PrimitiveConstant forBoxedPrimitive(Object value) { - if (value instanceof Boolean) { - return forBoolean((Boolean) value); - } else if (value instanceof Byte) { - return forByte((Byte) value); - } else if (value instanceof Character) { - return forChar((Character) value); - } else if (value instanceof Short) { - return forShort((Short) value); - } else if (value instanceof Integer) { - return forInt((Integer) value); - } else if (value instanceof Long) { - return forLong((Long) value); - } else if (value instanceof Float) { - return forFloat((Float) value); - } else if (value instanceof Double) { - return forDouble((Double) value); - } else { - return null; - } - } - - static PrimitiveConstant forIllegal() { - return new PrimitiveConstant(Kind.Illegal, 0); - } - - /** - * Returns a constant with the default value for the given kind. - */ - static JavaConstant defaultForKind(Kind kind) { - switch (kind) { - case Boolean: - return FALSE; - case Byte: - return forByte((byte) 0); - case Char: - return forChar((char) 0); - case Short: - return forShort((short) 0); - case Int: - return INT_0; - case Double: - return DOUBLE_0; - case Float: - return FLOAT_0; - case Long: - return LONG_0; - case Object: - return NULL_POINTER; - default: - throw new IllegalArgumentException(kind.toString()); - } - } - - /** - * Returns the zero value for a given numeric kind. - */ - static JavaConstant zero(Kind kind) { - switch (kind) { - case Boolean: - return FALSE; - case Byte: - return forByte((byte) 0); - case Char: - return forChar((char) 0); - case Double: - return DOUBLE_0; - case Float: - return FLOAT_0; - case Int: - return INT_0; - case Long: - return LONG_0; - case Short: - return forShort((short) 0); - default: - throw new IllegalArgumentException(kind.toString()); - } - } - - /** - * Returns the one value for a given numeric kind. - */ - static JavaConstant one(Kind kind) { - switch (kind) { - case Boolean: - return TRUE; - case Byte: - return forByte((byte) 1); - case Char: - return forChar((char) 1); - case Double: - return DOUBLE_1; - case Float: - return FLOAT_1; - case Int: - return INT_1; - case Long: - return LONG_1; - case Short: - return forShort((short) 1); - default: - throw new IllegalArgumentException(kind.toString()); - } - } - - /** - * Adds two numeric constants. - */ - static JavaConstant add(JavaConstant x, JavaConstant y) { - assert x.getKind() == y.getKind(); - switch (x.getKind()) { - case Byte: - return forByte((byte) (x.asInt() + y.asInt())); - case Char: - return forChar((char) (x.asInt() + y.asInt())); - case Double: - return forDouble(x.asDouble() + y.asDouble()); - case Float: - return forFloat(x.asFloat() + y.asFloat()); - case Int: - return forInt(x.asInt() + y.asInt()); - case Long: - return forLong(x.asLong() + y.asLong()); - case Short: - return forShort((short) (x.asInt() + y.asInt())); - default: - throw new IllegalArgumentException(x.getKind().toString()); - } - } - - /** - * Multiplies two numeric constants. - */ - static PrimitiveConstant mul(JavaConstant x, JavaConstant y) { - assert x.getKind() == y.getKind(); - switch (x.getKind()) { - case Byte: - return forByte((byte) (x.asInt() * y.asInt())); - case Char: - return forChar((char) (x.asInt() * y.asInt())); - case Double: - return forDouble(x.asDouble() * y.asDouble()); - case Float: - return forFloat(x.asFloat() * y.asFloat()); - case Int: - return forInt(x.asInt() * y.asInt()); - case Long: - return forLong(x.asLong() * y.asLong()); - case Short: - return forShort((short) (x.asInt() * y.asInt())); - default: - throw new IllegalArgumentException(x.getKind().toString()); - } - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/JavaField.java --- a/graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/JavaField.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,129 +0,0 @@ -/* - * Copyright (c) 2009, 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.meta; - -import java.util.*; - -/** - * Represents a reference to a Java field, either resolved or unresolved fields. Fields, like - * methods and types, are resolved through {@link ConstantPool constant pools}. - */ -public interface JavaField extends TrustedInterface { - - /** - * Returns the name of this field. - */ - String getName(); - - /** - * Returns a {@link JavaType} object that identifies the declared type for this field. - */ - JavaType getType(); - - /** - * Returns the kind of this field. This is the same as calling {@link #getType}. - * {@link JavaType#getKind getKind}. - */ - default Kind getKind() { - return getType().getKind(); - } - - /** - * Returns the {@link JavaType} object representing the class or interface that declares this - * field. - */ - JavaType getDeclaringClass(); - - /** - * Gets a string for this field formatted according to a given format specification. A format - * specification is composed of characters that are to be copied verbatim to the result and - * specifiers that denote an attribute of this field that is to be copied to the result. A - * specifier is a single character preceded by a '%' character. The accepted specifiers and the - * field attributes they denote are described below: - * - *
-     *     Specifier | Description                                          | Example(s)
-     *     ----------+------------------------------------------------------------------------------------------
-     *     'T'       | Qualified type                                       | "int" "java.lang.String"
-     *     't'       | Unqualified type                                     | "int" "String"
-     *     'H'       | Qualified holder                                     | "java.util.Map.Entry"
-     *     'h'       | Unqualified holder                                   | "Entry"
-     *     'n'       | Field name                                           | "age"
-     *     'f'       | Indicator if field is unresolved, static or instance | "unresolved" "static" "instance"
-     *     '%'       | A '%' character                                      | "%"
-     * 
- * - * @param format a format specification - * @return the result of formatting this field according to {@code format} - * @throws IllegalFormatException if an illegal specifier is encountered in {@code format} - */ - default String format(String format) throws IllegalFormatException { - StringBuilder sb = new StringBuilder(); - int index = 0; - JavaType type = getType(); - while (index < format.length()) { - char ch = format.charAt(index++); - if (ch == '%') { - if (index >= format.length()) { - throw new UnknownFormatConversionException("An unquoted '%' character cannot terminate a field format specification"); - } - char specifier = format.charAt(index++); - boolean qualified = false; - switch (specifier) { - case 'T': - qualified = true; - // fall through - case 't': { - sb.append(type.toJavaName(qualified)); - break; - } - case 'H': - qualified = true; - // fall through - case 'h': { - sb.append(getDeclaringClass().toJavaName(qualified)); - break; - } - case 'n': { - sb.append(getName()); - break; - } - case 'f': { - sb.append(!(this instanceof ResolvedJavaField) ? "unresolved" : ((ResolvedJavaField) this).isStatic() ? "static" : "instance"); - break; - } - case '%': { - sb.append('%'); - break; - } - default: { - throw new UnknownFormatConversionException(String.valueOf(specifier)); - } - } - } else { - sb.append(ch); - } - } - return sb.toString(); - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/JavaMethod.java --- a/graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/JavaMethod.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,141 +0,0 @@ -/* - * Copyright (c) 2009, 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.meta; - -import java.util.*; - -/** - * Represents a reference to a Java method, either resolved or unresolved. Methods, like fields and - * types, are resolved through {@link ConstantPool constant pools}. - */ -public interface JavaMethod extends TrustedInterface { - - /** - * Returns the name of this method. - */ - String getName(); - - /** - * Returns the {@link JavaType} object representing the class or interface that declares this - * method. - */ - JavaType getDeclaringClass(); - - /** - * Returns the signature of this method. - */ - Signature getSignature(); - - /** - * Gets a string for this method formatted according to a given format specification. A format - * specification is composed of characters that are to be copied verbatim to the result and - * specifiers that denote an attribute of this method that is to be copied to the result. A - * specifier is a single character preceded by a '%' character. The accepted specifiers and the - * method attributes they denote are described below: - * - *
-     *     Specifier | Description                                          | Example(s)
-     *     ----------+------------------------------------------------------------------------------------------
-     *     'R'       | Qualified return type                                | "int" "java.lang.String"
-     *     'r'       | Unqualified return type                              | "int" "String"
-     *     'H'       | Qualified holder                                     | "java.util.Map.Entry"
-     *     'h'       | Unqualified holder                                   | "Entry"
-     *     'n'       | Method name                                          | "add"
-     *     'P'       | Qualified parameter types, separated by ', '         | "int, java.lang.String"
-     *     'p'       | Unqualified parameter types, separated by ', '       | "int, String"
-     *     'f'       | Indicator if method is unresolved, static or virtual | "unresolved" "static" "virtual"
-     *     '%'       | A '%' character                                      | "%"
-     * 
- * - * @param format a format specification - * @return the result of formatting this method according to {@code format} - * @throws IllegalFormatException if an illegal specifier is encountered in {@code format} - */ - default String format(String format) throws IllegalFormatException { - StringBuilder sb = new StringBuilder(); - int index = 0; - Signature sig = null; - while (index < format.length()) { - char ch = format.charAt(index++); - if (ch == '%') { - if (index >= format.length()) { - throw new UnknownFormatConversionException("An unquoted '%' character cannot terminate a method format specification"); - } - char specifier = format.charAt(index++); - boolean qualified = false; - switch (specifier) { - case 'R': - qualified = true; - // fall through - case 'r': { - if (sig == null) { - sig = getSignature(); - } - sb.append(sig.getReturnType(null).toJavaName(qualified)); - break; - } - case 'H': - qualified = true; - // fall through - case 'h': { - sb.append(getDeclaringClass().toJavaName(qualified)); - break; - } - case 'n': { - sb.append(getName()); - break; - } - case 'P': - qualified = true; - // fall through - case 'p': { - if (sig == null) { - sig = getSignature(); - } - for (int i = 0; i < sig.getParameterCount(false); i++) { - if (i != 0) { - sb.append(", "); - } - sb.append(sig.getParameterType(i, null).toJavaName(qualified)); - } - break; - } - case 'f': { - sb.append(!(this instanceof ResolvedJavaMethod) ? "unresolved" : ((ResolvedJavaMethod) this).isStatic() ? "static" : "virtual"); - break; - } - case '%': { - sb.append('%'); - break; - } - default: { - throw new UnknownFormatConversionException(String.valueOf(specifier)); - } - } - } else { - sb.append(ch); - } - } - return sb.toString(); - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/JavaMethodProfile.java --- a/graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/JavaMethodProfile.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,60 +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.meta; - -import com.oracle.jvmci.meta.JavaMethodProfile.ProfiledMethod; - -/** - * This profile object represents the method profile at a specific BCI. The precision of the - * supplied values may vary, but a runtime that provides this information should be aware that it - * will be used to guide performance-critical decisions like speculative inlining, etc. - */ -public final class JavaMethodProfile extends AbstractJavaProfile { - - public JavaMethodProfile(double notRecordedProbability, ProfiledMethod[] pitems) { - super(notRecordedProbability, pitems); - } - - public ProfiledMethod[] getMethods() { - return super.getItems(); - } - - public static class ProfiledMethod extends AbstractProfiledItem { - - public ProfiledMethod(ResolvedJavaMethod method, double probability) { - super(method, probability); - } - - /** - * Returns the type for this profile entry. - */ - public ResolvedJavaMethod getMethod() { - return getItem(); - } - - @Override - public String toString() { - return "{" + item.getName() + ", " + probability + "}"; - } - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/JavaType.java --- a/graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/JavaType.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,153 +0,0 @@ -/* - * Copyright (c) 2009, 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.meta; - -import static com.oracle.jvmci.meta.MetaUtil.*; - -/** - * Represents a resolved or unresolved type. Types include primitives, objects, {@code void}, and - * arrays thereof. - */ -public interface JavaType extends TrustedInterface { - - /** - * Returns the name of this type in internal form. The following are examples of strings - * returned by this method: - * - *
-     *     "Ljava/lang/Object;"
-     *     "I"
-     *     "[[B"
-     * 
- */ - String getName(); - - /** - * Returns an unqualified name of this type. - * - *
-     *     "Object"
-     *     "Integer"
-     * 
- */ - default String getUnqualifiedName() { - String name = getName(); - if (name.indexOf('/') != -1) { - name = name.substring(name.lastIndexOf('/') + 1); - } - if (name.endsWith(";")) { - name = name.substring(0, name.length() - 1); - } - return name; - } - - /** - * For array types, gets the type of the components, or {@code null} if this is not an array - * type. This method is analogous to {@link Class#getComponentType()}. - */ - JavaType getComponentType(); - - /** - * Gets the elemental type for this given type. The elemental type is the corresponding zero - * dimensional type of an array type. For example, the elemental type of {@code int[][][]} is - * {@code int}. A non-array type is its own elemental type. - */ - default JavaType getElementalType() { - JavaType t = this; - while (t.getComponentType() != null) { - t = t.getComponentType(); - } - return t; - } - - /** - * Gets the array class type representing an array with elements of this type. - */ - JavaType getArrayClass(); - - /** - * Gets the kind of this type. - */ - Kind getKind(); - - /** - * Resolves this type to a {@link ResolvedJavaType}. - * - * @param accessingClass the context of resolution (must not be null) - * @return the resolved Java type - * @throws LinkageError if the resolution failed - * @throws NullPointerException if {@code accessingClass} is {@code null} - */ - ResolvedJavaType resolve(ResolvedJavaType accessingClass); - - /** - * Gets the Java programming language name for this type. The following are examples of strings - * returned by this method: - * - *
-     *      java.lang.Object
-     *      int
-     *      boolean[][]
-     * 
- * - * @return the Java name corresponding to this type - */ - default String toJavaName() { - return internalNameToJava(getName(), true, false); - } - - /** - * Gets the Java programming language name for this type. The following are examples of strings - * returned by this method: - * - *
-     *     qualified == true:
-     *         java.lang.Object
-     *         int
-     *         boolean[][]
-     *     qualified == false:
-     *         Object
-     *         int
-     *         boolean[][]
-     * 
- * - * @param qualified specifies if the package prefix of this type should be included in the - * returned name - * @return the Java name corresponding to this type - */ - default String toJavaName(boolean qualified) { - Kind kind = getKind(); - if (kind == Kind.Object) { - return internalNameToJava(getName(), qualified, false); - } - return getKind().getJavaName(); - } - - /** - * Returns this type's name in the same format as {@link Class#getName()}. - */ - default String toClassName() { - return internalNameToJava(getName(), true, true); - } - -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/JavaTypeProfile.java --- a/graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/JavaTypeProfile.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,195 +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.jvmci.meta; - -import java.util.*; - -import com.oracle.jvmci.meta.JavaTypeProfile.ProfiledType; - -/** - * This profile object represents the type profile at a specific BCI. The precision of the supplied - * values may vary, but a runtime that provides this information should be aware that it will be - * used to guide performance-critical decisions like speculative inlining, etc. - */ -public final class JavaTypeProfile extends AbstractJavaProfile { - - private static final ProfiledType[] EMPTY_ARRAY = new ProfiledType[0]; - - private final TriState nullSeen; - - public JavaTypeProfile(TriState nullSeen, double notRecordedProbability, ProfiledType[] pitems) { - super(notRecordedProbability, pitems); - this.nullSeen = nullSeen; - } - - /** - * Returns whether a null value was at the type check. - */ - public TriState getNullSeen() { - return nullSeen; - } - - /** - * A list of types for which the runtime has recorded probability information. Note that this - * includes both positive and negative types where a positive type is a subtype of the checked - * type and a negative type is not. - */ - public ProfiledType[] getTypes() { - return getItems(); - } - - public JavaTypeProfile restrict(JavaTypeProfile otherProfile) { - if (otherProfile.getNotRecordedProbability() > 0.0) { - // Not useful for restricting since there is an unknown set of types occurring. - return this; - } - - if (this.getNotRecordedProbability() > 0.0) { - // We are unrestricted, so the other profile is always a better estimate. - return otherProfile; - } - - ArrayList result = new ArrayList<>(); - for (int i = 0; i < getItems().length; i++) { - ProfiledType ptype = getItems()[i]; - ResolvedJavaType type = ptype.getItem(); - if (otherProfile.isIncluded(type)) { - result.add(ptype); - } - } - - TriState newNullSeen = (otherProfile.getNullSeen() == TriState.FALSE) ? TriState.FALSE : getNullSeen(); - double newNotRecorded = getNotRecordedProbability(); - return createAdjustedProfile(result, newNullSeen, newNotRecorded); - } - - public JavaTypeProfile restrict(ResolvedJavaType declaredType, boolean nonNull) { - ArrayList result = new ArrayList<>(); - for (int i = 0; i < getItems().length; i++) { - ProfiledType ptype = getItems()[i]; - ResolvedJavaType type = ptype.getItem(); - if (declaredType.isAssignableFrom(type)) { - result.add(ptype); - } - } - - TriState newNullSeen = (nonNull) ? TriState.FALSE : getNullSeen(); - double newNotRecorded = this.getNotRecordedProbability(); - // Assume for the types not recorded, the incompatibility rate is the same. - if (getItems().length != 0) { - newNotRecorded *= ((double) result.size() / (double) getItems().length); - } - return createAdjustedProfile(result, newNullSeen, newNotRecorded); - } - - private JavaTypeProfile createAdjustedProfile(ArrayList result, TriState newNullSeen, double newNotRecorded) { - if (result.size() != this.getItems().length || newNotRecorded != getNotRecordedProbability() || newNullSeen != getNullSeen()) { - if (result.size() == 0) { - return new JavaTypeProfile(newNullSeen, 1.0, EMPTY_ARRAY); - } - double factor; - if (result.size() == this.getItems().length) { - /* List of types did not change, no need to recompute probabilities. */ - factor = 1.0; - } else { - double probabilitySum = 0.0; - for (int i = 0; i < result.size(); i++) { - probabilitySum += result.get(i).getProbability(); - } - probabilitySum += newNotRecorded; - - factor = 1.0 / probabilitySum; // Normalize to 1.0 - assert factor >= 1.0; - } - ProfiledType[] newResult = new ProfiledType[result.size()]; - for (int i = 0; i < newResult.length; ++i) { - ProfiledType curType = result.get(i); - newResult[i] = new ProfiledType(curType.getItem(), Math.min(1.0, curType.getProbability() * factor)); - } - double newNotRecordedTypeProbability = Math.min(1.0, newNotRecorded * factor); - return new JavaTypeProfile(newNullSeen, newNotRecordedTypeProbability, newResult); - } - return this; - } - - @Override - public boolean equals(Object other) { - return super.equals(other) && nullSeen.equals(((JavaTypeProfile) other).nullSeen); - } - - @Override - public int hashCode() { - return nullSeen.hashCode() + super.hashCode(); - } - - public static class ProfiledType extends AbstractProfiledItem { - - public ProfiledType(ResolvedJavaType type, double probability) { - super(type, probability); - assert type.isArray() || type.isConcrete() : type; - } - - /** - * Returns the type for this profile entry. - */ - public ResolvedJavaType getType() { - return getItem(); - } - - @Override - public String toString() { - return String.format("%.6f#%s", probability, item); - } - } - - @Override - public String toString() { - StringBuilder buf = new StringBuilder("JavaTypeProfile", getNotRecordedProbability())).toString(); - } - - /** - * Returns {@code true} if all types seen at this location have been recorded in the profile. - */ - public boolean allTypesRecorded() { - return this.getNotRecordedProbability() == 0.0; - } - - /** - * Returns the single monormorphic type representing this profile or {@code null} if no such - * type exists. - */ - public ResolvedJavaType asSingleType() { - if (allTypesRecorded() && this.getTypes().length == 1) { - return getTypes()[0].getType(); - } - return null; - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/JavaValue.java --- a/graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/JavaValue.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,34 +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; - -/** - * Interface for things that represent a Java value. - */ -public interface JavaValue { - - /** - * Returns the kind of this value. - */ - Kind getKind(); -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/Kind.java --- a/graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/Kind.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,486 +0,0 @@ -/* - * Copyright (c) 2009, 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.reflect.*; - -//JaCoCo Exclude - -/** - * Denotes the basic kinds of types in CRI, including the all the Java primitive types, for example, - * {@link Kind#Int} for {@code int} and {@link Kind#Object} for all object types. A kind has a - * single character short name, a Java name, and a set of flags further describing its behavior. - */ -public enum Kind implements PlatformKind { - /** The primitive boolean kind, represented as an int on the stack. */ - Boolean('z', "boolean", 1, true, java.lang.Boolean.TYPE, java.lang.Boolean.class), - - /** The primitive byte kind, represented as an int on the stack. */ - Byte('b', "byte", 1, true, java.lang.Byte.TYPE, java.lang.Byte.class), - - /** The primitive short kind, represented as an int on the stack. */ - Short('s', "short", 1, true, java.lang.Short.TYPE, java.lang.Short.class), - - /** The primitive char kind, represented as an int on the stack. */ - Char('c', "char", 1, true, java.lang.Character.TYPE, java.lang.Character.class), - - /** The primitive int kind, represented as an int on the stack. */ - Int('i', "int", 1, true, java.lang.Integer.TYPE, java.lang.Integer.class), - - /** The primitive float kind. */ - Float('f', "float", 1, false, java.lang.Float.TYPE, java.lang.Float.class), - - /** The primitive long kind. */ - Long('j', "long", 2, false, java.lang.Long.TYPE, java.lang.Long.class), - - /** The primitive double kind. */ - Double('d', "double", 2, false, java.lang.Double.TYPE, java.lang.Double.class), - - /** The Object kind, also used for arrays. */ - Object('a', "Object", 1, false, null, null), - - /** The void float kind. */ - Void('v', "void", 0, false, java.lang.Void.TYPE, java.lang.Void.class), - - /** The non-type. */ - Illegal('-', "illegal", 0, false, null, null); - - private final char typeChar; - private final String javaName; - private final boolean isStackInt; - private final Class primitiveJavaClass; - private final Class boxedJavaClass; - private final EnumKey key = new EnumKey(this); - private final int slotCount; - - private Kind(char typeChar, String javaName, int slotCount, boolean isStackInt, Class primitiveJavaClass, Class boxedJavaClass) { - this.typeChar = typeChar; - this.javaName = javaName; - this.slotCount = slotCount; - this.isStackInt = isStackInt; - this.primitiveJavaClass = primitiveJavaClass; - this.boxedJavaClass = boxedJavaClass; - assert primitiveJavaClass == null || javaName.equals(primitiveJavaClass.getName()); - } - - /** - * Returns the number of stack slots occupied by this kind according to the Java bytecodes - * specification. - */ - public int getSlotCount() { - return this.slotCount; - } - - /** - * Returns whether this kind occupied two stack slots. - */ - public boolean needsTwoSlots() { - return this.slotCount == 2; - } - - /** - * Returns the name of the kind as a single character. - */ - public char getTypeChar() { - return typeChar; - } - - /** - * Returns the name of this kind which will also be it Java programming language name if it is - * {@linkplain #isPrimitive() primitive} or {@code void}. - */ - public String getJavaName() { - return javaName; - } - - public Key getKey() { - return key; - } - - /** - * Checks whether this type is a Java primitive type. - * - * @return {@code true} if this is {@link #Boolean}, {@link #Byte}, {@link #Char}, - * {@link #Short}, {@link #Int}, {@link #Long}, {@link #Float}, {@link #Double}, or - * {@link #Void}. - */ - public boolean isPrimitive() { - return primitiveJavaClass != null; - } - - /** - * Returns the kind that represents this kind when on the Java operand stack. - * - * @return the kind used on the operand stack - */ - public Kind getStackKind() { - if (isStackInt) { - return Int; - } - return this; - } - - /** - * Checks whether this type is a Java primitive type representing an integer number. - * - * @return {@code true} if the stack kind is {@link #Int} or {@link #Long}. - */ - public boolean isNumericInteger() { - return isStackInt || this == Kind.Long; - } - - /** - * Checks whether this type is a Java primitive type representing an unsigned number. - * - * @return {@code true} if the kind is {@link #Boolean} or {@link #Char}. - */ - public boolean isUnsigned() { - return this == Kind.Boolean || this == Kind.Char; - } - - /** - * Checks whether this type is a Java primitive type representing a floating point number. - * - * @return {@code true} if this is {@link #Float} or {@link #Double}. - */ - public boolean isNumericFloat() { - return this == Kind.Float || this == Kind.Double; - } - - /** - * Checks whether this represent an Object of some sort. - * - * @return {@code true} if this is {@link #Object}. - */ - public boolean isObject() { - return this == Kind.Object; - } - - /** - * Returns the kind corresponding to the Java type string. - * - * @param typeString the Java type string - * @return the kind - */ - public static Kind fromTypeString(String typeString) { - assert typeString.length() > 0; - final char first = typeString.charAt(0); - if (first == '[' || first == 'L') { - return Kind.Object; - } - return Kind.fromPrimitiveOrVoidTypeChar(first); - } - - /** - * Returns the kind of a word given the size of a word in bytes. - * - * @param wordSizeInBytes the size of a word in bytes - * @return the kind representing a word value - */ - public static Kind fromWordSize(int wordSizeInBytes) { - if (wordSizeInBytes == 8) { - return Kind.Long; - } else { - assert wordSizeInBytes == 4 : "Unsupported word size!"; - return Kind.Int; - } - } - - /** - * Returns the kind from the character describing a primitive or void. - * - * @param ch the character - * @return the kind - */ - public static Kind fromPrimitiveOrVoidTypeChar(char ch) { - switch (ch) { - case 'Z': - return Boolean; - case 'C': - return Char; - case 'F': - return Float; - case 'D': - return Double; - case 'B': - return Byte; - case 'S': - return Short; - case 'I': - return Int; - case 'J': - return Long; - case 'V': - return Void; - } - throw new IllegalArgumentException("unknown primitive or void type character: " + ch); - } - - /** - * Returns the Kind representing the given Java class. - * - * @param klass the class - * @return the kind - */ - public static Kind fromJavaClass(Class klass) { - if (klass == Boolean.primitiveJavaClass) { - return Boolean; - } else if (klass == Byte.primitiveJavaClass) { - return Byte; - } else if (klass == Short.primitiveJavaClass) { - return Short; - } else if (klass == Char.primitiveJavaClass) { - return Char; - } else if (klass == Int.primitiveJavaClass) { - return Int; - } else if (klass == Long.primitiveJavaClass) { - return Long; - } else if (klass == Float.primitiveJavaClass) { - return Float; - } else if (klass == Double.primitiveJavaClass) { - return Double; - } else if (klass == Void.primitiveJavaClass) { - return Void; - } else { - return Object; - } - } - - /** - * Returns the Java class representing this kind. - * - * @return the Java class - */ - public Class toJavaClass() { - return primitiveJavaClass; - } - - /** - * Returns the Java class for instances of boxed values of this kind. - * - * @return the Java class - */ - public Class toBoxedJavaClass() { - return boxedJavaClass; - } - - /** - * Converts this value type to a string. - */ - @Override - public String toString() { - return javaName; - } - - /** - * Marker interface for types that should be {@linkplain Kind#format(Object) formatted} with - * their {@link Object#toString()} value. Calling {@link Object#toString()} on other objects - * poses a security risk because it can potentially call user code. - */ - public interface FormatWithToString { - } - - /** - * Classes for which invoking {@link Object#toString()} does not run user code. - */ - private static boolean isToStringSafe(Class c) { - return c == Boolean.class || c == Byte.class || c == Character.class || c == Short.class || c == Integer.class || c == Float.class || c == Long.class || c == Double.class; - } - - /** - * Gets a formatted string for a given value of this kind. - * - * @param value a value of this kind - * @return a formatted string for {@code value} based on this kind - */ - public String format(Object value) { - if (isPrimitive()) { - assert isToStringSafe(value.getClass()); - return value.toString(); - } else { - if (value == null) { - return "null"; - } else { - if (value instanceof String) { - String s = (String) value; - if (s.length() > 50) { - return "String:\"" + s.substring(0, 30) + "...\""; - } else { - return "String:\"" + s + '"'; - } - } else if (value instanceof JavaType) { - return "JavaType:" + ((JavaType) value).toJavaName(); - } else if (value instanceof Enum) { - return MetaUtil.getSimpleName(value.getClass(), true) + ":" + ((Enum) value).name(); - } else if (value instanceof FormatWithToString) { - return MetaUtil.getSimpleName(value.getClass(), true) + ":" + String.valueOf(value); - } else if (value instanceof Class) { - return "Class:" + ((Class) value).getName(); - } else if (isToStringSafe(value.getClass())) { - return value.toString(); - } else if (value.getClass().isArray()) { - return formatArray(value); - } else { - return MetaUtil.getSimpleName(value.getClass(), true) + "@" + System.identityHashCode(value); - } - } - } - } - - private static final int MAX_FORMAT_ARRAY_LENGTH = 5; - - private static String formatArray(Object array) { - Class componentType = array.getClass().getComponentType(); - assert componentType != null; - int arrayLength = Array.getLength(array); - StringBuilder buf = new StringBuilder(MetaUtil.getSimpleName(componentType, true)).append('[').append(arrayLength).append("]{"); - int length = Math.min(MAX_FORMAT_ARRAY_LENGTH, arrayLength); - boolean primitive = componentType.isPrimitive(); - for (int i = 0; i < length; i++) { - if (primitive) { - buf.append(Array.get(array, i)); - } else { - Object o = ((Object[]) array)[i]; - buf.append(Kind.Object.format(o)); - } - if (i != length - 1) { - buf.append(", "); - } - } - if (arrayLength != length) { - buf.append(", ..."); - } - return buf.append('}').toString(); - } - - /** - * The minimum value that can be represented as a value of this kind. - * - * @return the minimum value - */ - public long getMinValue() { - switch (this) { - case Boolean: - return 0; - case Byte: - return java.lang.Byte.MIN_VALUE; - case Char: - return java.lang.Character.MIN_VALUE; - case Short: - return java.lang.Short.MIN_VALUE; - case Int: - return java.lang.Integer.MIN_VALUE; - case Long: - return java.lang.Long.MIN_VALUE; - default: - throw new IllegalArgumentException("illegal call to minValue on " + this); - } - } - - /** - * The maximum value that can be represented as a value of this kind. - * - * @return the maximum value - */ - public long getMaxValue() { - switch (this) { - case Boolean: - return 1; - case Byte: - return java.lang.Byte.MAX_VALUE; - case Char: - return java.lang.Character.MAX_VALUE; - case Short: - return java.lang.Short.MAX_VALUE; - case Int: - return java.lang.Integer.MAX_VALUE; - case Long: - return java.lang.Long.MAX_VALUE; - default: - throw new IllegalArgumentException("illegal call to maxValue on " + this); - } - } - - /** - * Number of bytes that are necessary to represent a value of this kind. - * - * @return the number of bytes - */ - public int getByteCount() { - if (this == Boolean) { - return 1; - } else { - return getBitCount() >> 3; - } - } - - /** - * Number of bits that are necessary to represent a value of this kind. - * - * @return the number of bits - */ - public int getBitCount() { - switch (this) { - case Boolean: - return 1; - case Byte: - return 8; - case Char: - case Short: - return 16; - case Float: - return 32; - case Int: - return 32; - case Double: - return 64; - case Long: - return 64; - default: - throw new IllegalArgumentException("illegal call to bits on " + this); - } - } - - public JavaConstant getDefaultValue() { - switch (this) { - case Boolean: - return JavaConstant.FALSE; - case Int: - return JavaConstant.INT_0; - case Long: - return JavaConstant.LONG_0; - case Float: - return JavaConstant.FLOAT_0; - case Double: - return JavaConstant.DOUBLE_0; - case Object: - return JavaConstant.NULL_POINTER; - case Byte: - case Char: - case Short: - return new PrimitiveConstant(this, 0); - default: - throw new IllegalArgumentException("illegal call to getDefaultValue on " + this); - } - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/KindProvider.java --- a/graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/KindProvider.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,33 +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; - -/** - * Interface for classes which can be associated with a Kind. - */ -public interface KindProvider { - - Kind getKind(); - -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/LIRKind.java --- a/graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/LIRKind.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,349 +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.jvmci.meta; - -import java.util.*; - -/** - * Represents the type of values in the LIR. It is composed of a {@link PlatformKind} that gives the - * low level representation of the value, and a {@link #referenceMask} that describes the location - * of object references in the value. - * - *

Constructing {@link LIRKind} instances

- * - * During LIR generation, every new {@link Value} should get a {@link LIRKind} of the correct - * {@link PlatformKind} that also contains the correct reference information. {@linkplain LIRKind - * LIRKinds} should be created as follows: - * - *

- * If the result value is created from one or more input values, the {@link LIRKind} should be - * created with {@link LIRKind#derive}(inputs). If the result has a different {@link PlatformKind} - * than the inputs, {@link LIRKind#derive}(inputs).{@link #changeType}(resultKind) should be used. - *

- * If the result is an exact copy of one of the inputs, {@link Value#getLIRKind()} can be used. Note - * that this is only correct for move-like operations, like conditional move or compare-and-swap. - * For convert operations, {@link LIRKind#derive} should be used. - *

- * If it is known that the result will be a reference (e.g. pointer arithmetic where the end result - * is a valid oop), {@link LIRKind#reference} should be used. - *

- * If it is known that the result will neither be a reference nor be derived from a reference, - * {@link LIRKind#value} can be used. If the operation producing this value has inputs, this is very - * likely wrong, and {@link LIRKind#derive} should be used instead. - *

- * If it is known that the result is derived from a reference, {@link LIRKind#derivedReference} can - * be used. In most cases, {@link LIRKind#derive} should be used instead, since it is able to detect - * this automatically. - */ -public final class LIRKind { - - /** - * The non-type. This uses {@link #derivedReference}, so it can never be part of an oop map. - */ - public static final LIRKind Illegal = derivedReference(Kind.Illegal); - - private final PlatformKind platformKind; - private final int referenceMask; - - private static final int DERIVED_REFERENCE = -1; - - private LIRKind(PlatformKind platformKind, int referenceMask) { - this.platformKind = platformKind; - this.referenceMask = referenceMask; - } - - /** - * Create a {@link LIRKind} of type {@code platformKind} that contains a primitive value. Should - * be only used when it's guaranteed that the value is not even indirectly derived from a - * reference. Otherwise, {@link #derive(Value...)} should be used instead. - */ - public static LIRKind value(PlatformKind platformKind) { - assert platformKind != Kind.Object : "Object should always be used as reference type"; - return new LIRKind(platformKind, 0); - } - - /** - * Create a {@link LIRKind} of type {@code platformKind} that contains a single tracked oop - * reference. - */ - public static LIRKind reference(PlatformKind platformKind) { - int length = platformKind.getVectorLength(); - assert 0 < length && length < 32 : "vector of " + length + " references not supported"; - return new LIRKind(platformKind, (1 << length) - 1); - } - - /** - * Create a {@link LIRKind} of type {@code platformKind} that contains a value that is derived - * from a reference. Values of this {@link LIRKind} can not be live at safepoints. In most - * cases, this should not be called directly. {@link #derive} should be used instead to - * automatically propagate this information. - */ - public static LIRKind derivedReference(PlatformKind platformKind) { - return new LIRKind(platformKind, DERIVED_REFERENCE); - } - - /** - * Derive a new type from inputs. The result will have the {@link PlatformKind} of one of the - * inputs. If all inputs are values, the result is a value. Otherwise, the result is a derived - * reference. - * - * This method should be used to construct the result {@link LIRKind} of any operation that - * modifies values (e.g. arithmetics). - */ - public static LIRKind derive(Value... inputs) { - assert inputs.length > 0; - for (Value input : inputs) { - LIRKind kind = input.getLIRKind(); - if (kind.isDerivedReference()) { - return kind; - } else if (!kind.isValue()) { - return kind.makeDerivedReference(); - } - } - - // all inputs are values, just return one of them - return inputs[0].getLIRKind(); - } - - /** - * Merge the types of the inputs. The result will have the {@link PlatformKind} of one of the - * inputs. If all inputs are values (references), the result is a value (reference). Otherwise, - * the result is a derived reference. - * - * This method should be used to construct the result {@link LIRKind} of merge operation that do - * not modify values (e.g. phis). - */ - public static LIRKind merge(Value... inputs) { - assert inputs.length > 0; - ArrayList kinds = new ArrayList<>(inputs.length); - for (int i = 0; i < inputs.length; i++) { - kinds.add(inputs[i].getLIRKind()); - } - return merge(kinds); - } - - /** - * @see #merge(Value...) - */ - public static LIRKind merge(Iterable kinds) { - LIRKind mergeKind = null; - - for (LIRKind kind : kinds) { - - assert mergeKind == null || verifyMoveKinds(mergeKind, kind) : String.format("Input kinds do not match %s vs. %s", mergeKind, kind); - - if (kind.isDerivedReference()) { - /** - * Kind is a derived reference therefore the result can only be also a derived - * reference. - */ - return kind; - } - if (mergeKind == null) { - mergeKind = kind; - continue; - } - - if (kind.isValue()) { - /* Kind is a value. */ - if (mergeKind.referenceMask != 0) { - /* - * Inputs consists of values and references. Make the result a derived - * reference. - */ - return mergeKind.makeDerivedReference(); - } - /* Check that other inputs are also values. */ - } else { - /* Kind is a reference. */ - if (mergeKind.referenceMask != kind.referenceMask) { - /* - * Reference maps do not match so the result can only be a derived reference. - */ - return mergeKind.makeDerivedReference(); - } - } - - } - assert mergeKind != null; - - // all inputs are values or references, just return one of them - return mergeKind; - } - - /** - * Create a new {@link LIRKind} with the same reference information and a new - * {@linkplain #getPlatformKind platform kind}. If the new kind is a longer vector than this, - * the new elements are marked as untracked values. - */ - public LIRKind changeType(PlatformKind newPlatformKind) { - if (newPlatformKind == platformKind) { - return this; - } else if (isDerivedReference()) { - return derivedReference(newPlatformKind); - } else if (referenceMask == 0) { - // value type - return new LIRKind(newPlatformKind, 0); - } else { - // reference type - int newLength = Math.min(32, newPlatformKind.getVectorLength()); - int newReferenceMask = referenceMask & (0xFFFFFFFF >>> (32 - newLength)); - assert newReferenceMask != DERIVED_REFERENCE; - return new LIRKind(newPlatformKind, newReferenceMask); - } - } - - /** - * Create a new {@link LIRKind} with a new {@linkplain #getPlatformKind platform kind}. If the - * new kind is longer than this, the reference positions are repeated to fill the vector. - */ - public LIRKind repeat(PlatformKind newPlatformKind) { - if (isDerivedReference()) { - return derivedReference(newPlatformKind); - } else if (referenceMask == 0) { - // value type - return new LIRKind(newPlatformKind, 0); - } else { - // reference type - int oldLength = platformKind.getVectorLength(); - int newLength = newPlatformKind.getVectorLength(); - assert oldLength <= newLength && newLength < 32 && (newLength % oldLength) == 0; - - // repeat reference mask to fill new kind - int newReferenceMask = 0; - for (int i = 0; i < newLength; i += platformKind.getVectorLength()) { - newReferenceMask |= referenceMask << i; - } - - assert newReferenceMask != DERIVED_REFERENCE; - return new LIRKind(newPlatformKind, newReferenceMask); - } - } - - /** - * Create a new {@link LIRKind} with the same type, but marked as containing a derivedReference. - */ - public LIRKind makeDerivedReference() { - return new LIRKind(platformKind, DERIVED_REFERENCE); - } - - /** - * Get the low level type that is used in code generation. - */ - public PlatformKind getPlatformKind() { - return platformKind; - } - - /** - * Check whether this value is derived from a reference. If this returns {@code true}, this - * value must not be live at safepoints. - */ - public boolean isDerivedReference() { - return referenceMask == DERIVED_REFERENCE; - } - - /** - * Check whether the {@code idx}th part of this value is a reference that must be tracked at - * safepoints. - * - * @param idx The index into the vector if this is a vector kind. Must be 0 if this is a scalar - * kind. - */ - public boolean isReference(int idx) { - assert 0 <= idx && idx < platformKind.getVectorLength() : "invalid index " + idx + " in " + this; - return !isDerivedReference() && (referenceMask & 1 << idx) != 0; - } - - /** - * Check whether this kind is a value type that doesn't need to be tracked at safepoints. - */ - public boolean isValue() { - return referenceMask == 0; - } - - @Override - public String toString() { - if (isValue()) { - return platformKind.name(); - } else if (isDerivedReference()) { - return platformKind.name() + "[*]"; - } else { - StringBuilder ret = new StringBuilder(); - ret.append(platformKind.name()); - ret.append('['); - for (int i = 0; i < platformKind.getVectorLength(); i++) { - if (isReference(i)) { - ret.append('.'); - } else { - ret.append(' '); - } - } - ret.append(']'); - return ret.toString(); - } - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((platformKind == null) ? 0 : platformKind.hashCode()); - result = prime * result + referenceMask; - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (!(obj instanceof LIRKind)) { - return false; - } - - LIRKind other = (LIRKind) obj; - return platformKind == other.platformKind && referenceMask == other.referenceMask; - } - - public static boolean verifyMoveKinds(LIRKind dst, LIRKind src) { - if (src.equals(dst)) { - return true; - } - /* - * TODO(je,rs) What we actually want is toStackKind(src.getPlatformKind()).equals( - * dst.getPlatformKind()) but due to the handling of sub-integer at the current point - * (phi-)moves from e.g. integer to short can happen. Therefore we compare stack kinds. - */ - if (toStackKind(src.getPlatformKind()).equals(toStackKind(dst.getPlatformKind()))) { - return !src.isDerivedReference() || dst.isDerivedReference(); - } - return false; - } - - private static PlatformKind toStackKind(PlatformKind platformKind) { - if (platformKind instanceof Kind) { - return ((Kind) platformKind).getStackKind(); - } - return platformKind; - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/LineNumberTable.java --- a/graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/LineNumberTable.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,32 +0,0 @@ -/* - * Copyright (c) 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.meta; - -public interface LineNumberTable { - - int[] getLineNumberEntries(); - - int[] getBciEntries(); - - int getLineNumber(int bci); -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/LineNumberTableImpl.java --- a/graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/LineNumberTableImpl.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,54 +0,0 @@ -/* - * Copyright (c) 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.meta; - -public class LineNumberTableImpl implements LineNumberTable { - - private final int[] lineNumbers; - private final int[] bci; - - public LineNumberTableImpl(int[] lineNumbers, int[] bci) { - this.lineNumbers = lineNumbers; - this.bci = bci; - } - - @Override - public int[] getLineNumberEntries() { - return lineNumbers; - } - - @Override - public int[] getBciEntries() { - return bci; - } - - @Override - public int getLineNumber(@SuppressWarnings("hiding") int bci) { - for (int i = 0; i < this.bci.length - 1; i++) { - if (this.bci[i] <= bci && bci < this.bci[i + 1]) { - return lineNumbers[i]; - } - } - return lineNumbers[lineNumbers.length - 1]; - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/Local.java --- a/graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/Local.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,36 +0,0 @@ -/* - * Copyright (c) 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.meta; - -public interface Local { - - int getStartBCI(); - - int getEndBCI(); - - int getSlot(); - - String getName(); - - JavaType getType(); -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/LocalImpl.java --- a/graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/LocalImpl.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,84 +0,0 @@ -/* - * Copyright (c) 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.meta; - -public class LocalImpl implements Local { - - private final String name; - private final int startBci; - private final int endBci; - private final int slot; - private final JavaType type; - - public LocalImpl(String name, JavaType type, int startBci, int endBci, int slot) { - this.name = name; - this.startBci = startBci; - this.endBci = endBci; - this.slot = slot; - this.type = type; - } - - @Override - public int getStartBCI() { - return startBci; - } - - @Override - public int getEndBCI() { - return endBci; - } - - @Override - public String getName() { - return name; - } - - @Override - public JavaType getType() { - return type; - } - - @Override - public int getSlot() { - return slot; - } - - @Override - public boolean equals(Object obj) { - if (!(obj instanceof LocalImpl)) { - return false; - } - LocalImpl that = (LocalImpl) obj; - return this.name.equals(that.name) && this.startBci == that.startBci && this.endBci == that.endBci && this.slot == that.slot && this.type.equals(that.type); - } - - @Override - public int hashCode() { - return super.hashCode(); - } - - @Override - public String toString() { - return "LocalImpl"; - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/LocalVariableTable.java --- a/graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/LocalVariableTable.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,32 +0,0 @@ -/* - * Copyright (c) 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.meta; - -public interface LocalVariableTable { - - Local[] getLocals(); - - Local[] getLocalsAt(int bci); - - Local getLocal(int slot, int bci); -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/LocalVariableTableImpl.java --- a/graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/LocalVariableTableImpl.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,66 +0,0 @@ -/* - * Copyright (c) 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.meta; - -import java.util.*; - -public class LocalVariableTableImpl implements LocalVariableTable { - - private final Local[] locals; - - public LocalVariableTableImpl(Local[] locals) { - this.locals = locals; - } - - @Override - public Local getLocal(int slot, int bci) { - Local result = null; - for (Local local : locals) { - if (local.getSlot() == slot && local.getStartBCI() <= bci && local.getEndBCI() >= bci) { - if (result == null) { - result = local; - } else { - throw new IllegalStateException("Locals overlap!"); - } - } - } - return result; - } - - @Override - public Local[] getLocals() { - return locals; - } - - @Override - public Local[] getLocalsAt(int bci) { - List result = new ArrayList<>(); - for (Local l : locals) { - if (l.getStartBCI() <= bci && bci <= l.getEndBCI()) { - result.add(l); - } - } - return result.toArray(new Local[result.size()]); - } - -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/LocationIdentity.java --- a/graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/LocationIdentity.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,82 +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.jvmci.meta; - -import java.util.*; - -// JaCoCo Exclude - -/** - * Marker interface for location identities. Apart from the special values {@link #ANY_LOCATION} and - * {@link #FINAL_LOCATION}, a different location identity of two memory accesses guarantees that the - * two accesses do not interfere. - * - * Clients of {@link LocationIdentity} must use {@link #equals(Object)}, not {@code ==}, when - * comparing two {@link LocationIdentity} values for equality. Likewise, they must not use - * {@link IdentityHashMap}s with {@link LocationIdentity} values as keys. - */ -public abstract class LocationIdentity { - - /** - * Denotes any location. A write to such a location kills all values in a memory map during an - * analysis of memory accesses. A read from this location cannot be moved or coalesced with - * other reads because its interaction with other reads is not known. - */ - private static final LocationIdentity ANY_LOCATION = NamedLocationIdentity.mutable("ANY_LOCATION"); - - /** - * Denotes the location of a value that is guaranteed to be unchanging. - */ - public static final LocationIdentity FINAL_LOCATION = NamedLocationIdentity.immutable("FINAL_LOCATION"); - - /** - * Denotes the location of the length field of a Java array. - */ - public static final LocationIdentity ARRAY_LENGTH_LOCATION = NamedLocationIdentity.immutable("[].length"); - - public static LocationIdentity any() { - return ANY_LOCATION; - } - - /** - * Denotes a location is unchanging in all cases. Not that this is different than the Java - * notion of final which only requires definite assignment. - */ - public abstract boolean isImmutable(); - - public final boolean isMutable() { - return !isImmutable(); - } - - public final boolean isAny() { - return this == ANY_LOCATION; - } - - public final boolean isSingle() { - return this != ANY_LOCATION; - } - - public final boolean overlaps(LocationIdentity other) { - return isAny() || other.isAny() || this.equals(other); - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/MemoryAccessProvider.java --- a/graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/MemoryAccessProvider.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,60 +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.jvmci.meta; - -/** - * Provides memory access operations for the target VM. - */ -public interface MemoryAccessProvider { - - /** - * Reads a value of this kind using a base address and a displacement. No bounds checking or - * type checking is performed. Returns {@code null} if the value is not available at this point. - * - * @param base the base address from which the value is read. - * @param displacement the displacement within the object in bytes - * @return the read value encapsulated in a {@link JavaConstant} object, or {@code null} if the - * value cannot be read. - */ - JavaConstant readUnsafeConstant(Kind kind, JavaConstant base, long displacement); - - /** - * Reads a primitive value using a base address and a displacement. - * - * @param kind the {@link Kind} of the returned {@link JavaConstant} object - * @param base the base address from which the value is read - * @param displacement the displacement within the object in bytes - * @param bits the number of bits to read from memory - * @return the read value encapsulated in a {@link JavaConstant} object of {@link Kind} kind - */ - JavaConstant readPrimitiveConstant(Kind kind, Constant base, long displacement, int bits); - - /** - * Reads a Java {@link Object} value using a base address and a displacement. - * - * @param base the base address from which the value is read - * @param displacement the displacement within the object in bytes - * @return the read value encapsulated in a {@link Constant} object - */ - JavaConstant readObjectConstant(Constant base, long displacement); -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/MetaAccessProvider.java --- a/graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/MetaAccessProvider.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,104 +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.jvmci.meta; - -import java.lang.reflect.*; - -/** - * Provides access to the metadata of a class typically provided in a class file. - */ -public interface MetaAccessProvider { - - /** - * Returns the resolved Java type representing a given Java class. - * - * @param clazz the Java class object - * @return the resolved Java type object - */ - ResolvedJavaType lookupJavaType(Class clazz); - - /** - * Returns the resolved Java types representing some given Java classes. - * - * @param classes the Java class objects - * @return the resolved Java type objects - */ - default ResolvedJavaType[] lookupJavaTypes(Class[] classes) { - ResolvedJavaType[] result = new ResolvedJavaType[classes.length]; - for (int i = 0; i < result.length; i++) { - result[i] = lookupJavaType(classes[i]); - } - return result; - } - - /** - * Provides the {@link ResolvedJavaMethod} for a {@link Method} or {@link Constructor} obtained - * via reflection. - */ - ResolvedJavaMethod lookupJavaMethod(Executable reflectionMethod); - - /** - * Provides the {@link ResolvedJavaField} for a {@link Field} obtained via reflection. - */ - ResolvedJavaField lookupJavaField(Field reflectionField); - - /** - * Returns the resolved Java type of the given {@link JavaConstant} object. - * - * @return {@code null} if {@code constant.isNull() || !constant.kind.isObject()} - */ - ResolvedJavaType lookupJavaType(JavaConstant constant); - - /** - * Returns the number of bytes occupied by this constant value or constant object. - * - * @param constant the constant whose bytes should be measured - * @return the number of bytes occupied by this constant - */ - long getMemorySize(JavaConstant constant); - - /** - * Parses a method - * descriptor into a {@link Signature}. The behavior of this method is undefined if the - * method descriptor is not well formed. - */ - Signature parseMethodDescriptor(String methodDescriptor); - - /** - * Encodes a deoptimization action and a deoptimization reason in an integer value. - * - * @param debugId an integer that can be used to track the origin of a deoptimization at - * runtime. There is no guarantee that the runtime will use this value. The runtime - * may even keep fewer than 32 bits. - * - * @return the encoded value as an integer - */ - JavaConstant encodeDeoptActionAndReason(DeoptimizationAction action, DeoptimizationReason reason, int debugId); - - DeoptimizationReason decodeDeoptReason(JavaConstant constant); - - DeoptimizationAction decodeDeoptAction(JavaConstant constant); - - int decodeDebugId(JavaConstant constant); -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/MetaUtil.java --- a/graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/MetaUtil.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,341 +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.jvmci.meta; - -import java.io.*; -import java.util.*; - -/** - * Miscellaneous collection of utility methods used by {@code com.oracle.jvmci.meta} and its - * clients. - */ -public class MetaUtil { - - private static class ClassInfo { - public long totalSize; - public long instanceCount; - - @Override - public String toString() { - return "totalSize=" + totalSize + ", instanceCount=" + instanceCount; - } - } - - /** - * Returns the number of bytes occupied by this constant value or constant object and - * recursively all values reachable from this value. - * - * @param constant the constant whose bytes should be measured - * @param printTopN print total size and instance count of the top n classes is desired - * @return the number of bytes occupied by this constant - */ - public static long getMemorySizeRecursive(MetaAccessProvider access, ConstantReflectionProvider constantReflection, JavaConstant constant, PrintStream out, int printTopN) { - Set marked = new HashSet<>(); - Deque stack = new ArrayDeque<>(); - if (constant.getKind() == Kind.Object && constant.isNonNull()) { - marked.add(constant); - } - final HashMap histogram = new HashMap<>(); - stack.push(constant); - long sum = 0; - while (!stack.isEmpty()) { - JavaConstant c = stack.pop(); - long memorySize = access.getMemorySize(constant); - sum += memorySize; - if (c.getKind() == Kind.Object && c.isNonNull()) { - ResolvedJavaType clazz = access.lookupJavaType(c); - if (!histogram.containsKey(clazz)) { - histogram.put(clazz, new ClassInfo()); - } - ClassInfo info = histogram.get(clazz); - info.instanceCount++; - info.totalSize += memorySize; - ResolvedJavaType type = access.lookupJavaType(c); - if (type.isArray()) { - if (!type.getComponentType().isPrimitive()) { - int length = constantReflection.readArrayLength(c); - for (int i = 0; i < length; i++) { - JavaConstant value = constantReflection.readArrayElement(c, i); - pushConstant(marked, stack, value); - } - } - } else { - ResolvedJavaField[] instanceFields = type.getInstanceFields(true); - for (ResolvedJavaField f : instanceFields) { - if (f.getKind() == Kind.Object) { - JavaConstant value = constantReflection.readFieldValue(f, c); - pushConstant(marked, stack, value); - } - } - } - } - } - ArrayList clazzes = new ArrayList<>(); - clazzes.addAll(histogram.keySet()); - Collections.sort(clazzes, new Comparator() { - - @Override - public int compare(ResolvedJavaType o1, ResolvedJavaType o2) { - long l1 = histogram.get(o1).totalSize; - long l2 = histogram.get(o2).totalSize; - if (l1 > l2) { - return -1; - } else if (l1 == l2) { - return 0; - } else { - return 1; - } - } - }); - - int z = 0; - for (ResolvedJavaType c : clazzes) { - if (z > printTopN) { - break; - } - out.println("Class " + c + ", " + histogram.get(c)); - ++z; - } - - return sum; - } - - private static void pushConstant(Set marked, Deque stack, JavaConstant value) { - if (value.isNonNull()) { - if (!marked.contains(value)) { - marked.add(value); - stack.push(value); - } - } - } - - /** - * Calls {@link JavaType#resolve(ResolvedJavaType)} on an array of types. - */ - public static ResolvedJavaType[] resolveJavaTypes(JavaType[] types, ResolvedJavaType accessingClass) { - ResolvedJavaType[] result = new ResolvedJavaType[types.length]; - for (int i = 0; i < result.length; i++) { - result[i] = types[i].resolve(accessingClass); - } - return result; - } - - /** - * Extends the functionality of {@link Class#getSimpleName()} to include a non-empty string for - * anonymous and local classes. - * - * @param clazz the class for which the simple name is being requested - * @param withEnclosingClass specifies if the returned name should be qualified with the name(s) - * of the enclosing class/classes of {@code clazz} (if any). This option is ignored - * if {@code clazz} denotes an anonymous or local class. - * @return the simple name - */ - public static String getSimpleName(Class clazz, boolean withEnclosingClass) { - final String simpleName = clazz.getSimpleName(); - if (simpleName.length() != 0) { - if (withEnclosingClass) { - String prefix = ""; - Class enclosingClass = clazz; - while ((enclosingClass = enclosingClass.getEnclosingClass()) != null) { - prefix = enclosingClass.getSimpleName() + "." + prefix; - } - return prefix + simpleName; - } - return simpleName; - } - // Must be an anonymous or local class - final String name = clazz.getName(); - int index = name.indexOf('$'); - if (index == -1) { - return name; - } - index = name.lastIndexOf('.', index); - if (index == -1) { - return name; - } - return name.substring(index + 1); - } - - static String internalNameToJava(String name, boolean qualified, boolean classForNameCompatible) { - switch (name.charAt(0)) { - case 'L': { - String result = name.substring(1, name.length() - 1).replace('/', '.'); - if (!qualified) { - final int lastDot = result.lastIndexOf('.'); - if (lastDot != -1) { - result = result.substring(lastDot + 1); - } - } - return result; - } - case '[': - return classForNameCompatible ? name.replace('/', '.') : internalNameToJava(name.substring(1), qualified, classForNameCompatible) + "[]"; - default: - if (name.length() != 1) { - throw new IllegalArgumentException("Illegal internal name: " + name); - } - return Kind.fromPrimitiveOrVoidTypeChar(name.charAt(0)).getJavaName(); - } - } - - /** - * Turns an class name in internal format into a resolved Java type. - */ - public static ResolvedJavaType classForName(String internal, MetaAccessProvider metaAccess, ClassLoader cl) { - Kind k = Kind.fromTypeString(internal); - try { - String n = internalNameToJava(internal, true, true); - return metaAccess.lookupJavaType(k.isPrimitive() ? k.toJavaClass() : Class.forName(n, true, cl)); - } catch (ClassNotFoundException cnfe) { - throw new IllegalArgumentException("could not instantiate class described by " + internal, cnfe); - } - } - - /** - * Convenient shortcut for calling - * {@link #appendLocation(StringBuilder, ResolvedJavaMethod, int)} without having to supply a - * {@link StringBuilder} instance and convert the result to a string. - */ - public static String toLocation(ResolvedJavaMethod method, int bci) { - return appendLocation(new StringBuilder(), method, bci).toString(); - } - - /** - * Appends a string representation of a location specified by a given method and bci to a given - * {@link StringBuilder}. If a stack trace element with a non-null file name and non-negative - * line number is {@linkplain ResolvedJavaMethod#asStackTraceElement(int) available} for the - * given method, then the string returned is the {@link StackTraceElement#toString()} value of - * the stack trace element, suffixed by the bci location. For example: - * - *

-     *     java.lang.String.valueOf(String.java:2930) [bci: 12]
-     * 
- * - * Otherwise, the string returned is the value of applying {@link JavaMethod#format(String)} - * with the format string {@code "%H.%n(%p)"}, suffixed by the bci location. For example: - * - *
-     *     java.lang.String.valueOf(int) [bci: 12]
-     * 
- * - * @param sb - * @param method - * @param bci - */ - public static StringBuilder appendLocation(StringBuilder sb, ResolvedJavaMethod method, int bci) { - if (method != null) { - StackTraceElement ste = method.asStackTraceElement(bci); - if (ste.getFileName() != null && ste.getLineNumber() > 0) { - sb.append(ste); - } else { - sb.append(method.format("%H.%n(%p)")); - } - } else { - sb.append("Null method"); - } - return sb.append(" [bci: ").append(bci).append(']'); - } - - static void appendProfile(StringBuilder buf, AbstractJavaProfile profile, int bci, String type, String sep) { - if (profile != null) { - AbstractProfiledItem[] pitems = profile.getItems(); - if (pitems != null) { - buf.append(String.format("%s@%d:", type, bci)); - for (int j = 0; j < pitems.length; j++) { - AbstractProfiledItem pitem = pitems[j]; - buf.append(String.format(" %.6f (%s)%s", pitem.getProbability(), pitem.getItem(), sep)); - } - if (profile.getNotRecordedProbability() != 0) { - buf.append(String.format(" %.6f %s", profile.getNotRecordedProbability(), type, sep)); - } else { - buf.append(String.format(" %s", type, sep)); - } - } - } - } - - /** - * Converts a Java source-language class name into the internal form. - * - * @param className the class name - * @return the internal name form of the class name - */ - public static String toInternalName(String className) { - String prefix = ""; - String base = className; - while (base.endsWith("[]")) { - prefix += "["; - base = base.substring(base.length() - 2); - } - - switch (className) { - case "boolean": - return prefix + "Z"; - case "byte": - return prefix + "B"; - case "short": - return prefix + "S"; - case "char": - return prefix + "C"; - case "int": - return prefix + "I"; - case "float": - return prefix + "F"; - case "long": - return prefix + "J"; - case "double": - return prefix + "D"; - case "void": - return prefix + "V"; - default: - return prefix + "L" + className.replace('.', '/') + ";"; - } - } - - /** - * Prepends the String {@code indentation} to every line in String {@code lines}, including a - * possibly non-empty line following the final newline. - */ - public static String indent(String lines, String indentation) { - if (lines.length() == 0) { - return lines; - } - final String newLine = "\n"; - if (lines.endsWith(newLine)) { - return indentation + (lines.substring(0, lines.length() - 1)).replace(newLine, newLine + indentation) + newLine; - } - return indentation + lines.replace(newLine, newLine + indentation); - } - - /** - * Gets a string representation of an object based soley on its class and its - * {@linkplain System#identityHashCode(Object) identity hash code}. This avoids and calls to - * virtual methods on the object such as {@link Object#hashCode()}. - */ - public static String identityHashCodeString(Object obj) { - if (obj == null) { - return "null"; - } - return obj.getClass().getName() + "@" + System.identityHashCode(obj); - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/MethodHandleAccessProvider.java --- a/graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/MethodHandleAccessProvider.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,76 +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.invoke.*; - -/** - * Interface to access the internals of the {@link MethodHandle} implementation of the VM. An - * implementation of this interface is usually required to access non-public classes, methods, and - * fields of {@link MethodHandle}, i.e., data that is not standardized by the Java specification. - */ -public interface MethodHandleAccessProvider { - - /** - * Identification for methods defined on the class {@link MethodHandle} that are processed by - * the {@link MethodHandleAccessProvider}. - */ - public enum IntrinsicMethod { - /** The method {@code MethodHandle.invokeBasic}. */ - INVOKE_BASIC, - /** The method {@code MethodHandle.linkToStatic}. */ - LINK_TO_STATIC, - /** The method {@code MethodHandle.linkToSpecial}. */ - LINK_TO_SPECIAL, - /** The method {@code MethodHandle.linkToVirtual}. */ - LINK_TO_VIRTUAL, - /** The method {@code MethodHandle.linkToInterface}. */ - LINK_TO_INTERFACE - } - - /** - * Returns the method handle method intrinsic identifier for the provided method, or - * {@code null} if the method is not an intrinsic processed by this interface. - */ - IntrinsicMethod lookupMethodHandleIntrinsic(ResolvedJavaMethod method); - - /** - * Resolves the invocation target for an invocation of {@link IntrinsicMethod#INVOKE_BASIC - * MethodHandle.invokeBasic} with the given constant receiver {@link MethodHandle}. Returns - * {@code null} if the invocation target is not available at this time. - *

- * The first invocations of a method handle can use an interpreter to lookup the actual invoked - * method; frequently executed method handles can use Java bytecode generation to avoid the - * interpreter overhead. If the parameter forceBytecodeGeneration is set to true, the VM should - * try to generate bytecodes before this method returns. - */ - ResolvedJavaMethod resolveInvokeBasicTarget(JavaConstant methodHandle, boolean forceBytecodeGeneration); - - /** - * Resolves the invocation target for an invocation of a {@code MethodHandle.linkTo*} method - * with the given constant member name. The member name is the last parameter of the - * {@code linkTo*} method. Returns {@code null} if the invocation target is not available at - * this time. - */ - ResolvedJavaMethod resolveLinkToTarget(JavaConstant memberName); -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/MethodIdHolder.java --- a/graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/MethodIdHolder.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,93 +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.jvmci.meta; - -import java.util.*; -import java.util.function.*; - -/** - * An object that can be assigned a globally unique identifier for use as a key in a - * {@link MethodIdMap}. - */ -public interface MethodIdHolder { - /** - * Sets the unique, positive, non-zero identifier for this method. - */ - void setMethodId(int id); - - /** - * Gets the identifier set by {@link #setMethodId(int)} or 0 if no identifier was assigned to - * this method. - */ - int getMethodId(); - - /** - * A singleton class for allocating globally unique method identifiers. - */ - static final class MethodIdAllocator { - - /** - * Ensures a given method has a unique identifier. - */ - public int assignId(MethodIdHolder holder) { - assert Thread.holdsLock(instance) : "must only be called from within MethodIdHolder.allocateIds"; - int id = holder.getMethodId(); - if (id == 0) { - id = nextId++; - holder.setMethodId(id); - if (idVerifierMap != null) { - idVerifierMap.put(holder, id); - } - } else { - assert !idVerifierMap.containsKey(holder) || idVerifierMap.get(holder) == id; - } - return id; - } - - private int nextId = 1; - private final Map idVerifierMap; - - @SuppressWarnings("all") - private MethodIdAllocator() { - boolean assertionsEnabled = false; - assert assertionsEnabled = true; - idVerifierMap = assertionsEnabled ? new HashMap<>() : null; - } - - /** - * Singleton instance. - */ - private static final MethodIdAllocator instance = new MethodIdAllocator(); - } - - /** - * Executes some given code that ensures some set of {@link ResolvedJavaMethod}s have unique ids - * {@linkplain MethodIdHolder#setMethodId(int) assigned} to them. The - * {@link Consumer#accept(Object)} method of the given object is called under a global lock. - */ - static void assignIds(Consumer methodIdConsumer) { - synchronized (MethodIdAllocator.instance) { - methodIdConsumer.accept(MethodIdAllocator.instance); - } - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/MethodIdMap.java --- a/graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/MethodIdMap.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,236 +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.jvmci.meta; - -import java.lang.reflect.*; -import java.util.*; -import java.util.function.*; -import java.util.stream.*; - -import com.oracle.jvmci.meta.MethodIdHolder.MethodIdAllocator; - -/** - * A map whose keys are {@link MethodIdHolder}s. This data structure can be used for mapping - * identifiers to methods without requiring eager resolution of the latter (e.g., to - * {@link ResolvedJavaMethod}s) and has retrieval as fast as array indexing. The constraints on - * using such a map are: - *

    - *
  • at most one value can be added for any key
  • - *
  • no more entries can be added after the first {@linkplain #get(MethodIdHolder) retrieval}
  • - *
- * - * @param the type of the values in the map - */ -public class MethodIdMap { - - /** - * Key for a method. - */ - public static class MethodKey { - final boolean isStatic; - final Class declaringClass; - final String name; - final Class[] argumentTypes; - final T value; - int id; - - MethodKey(T data, boolean isStatic, Class declaringClass, String name, Class... argumentTypes) { - assert isStatic || argumentTypes[0] == declaringClass; - this.value = data; - this.isStatic = isStatic; - this.declaringClass = declaringClass; - this.name = name; - this.argumentTypes = argumentTypes; - assert resolveJava() != null; - } - - @Override - public boolean equals(Object obj) { - if (obj instanceof MethodKey) { - MethodKey that = (MethodKey) obj; - boolean res = this.name.equals(that.name) && this.declaringClass.equals(that.declaringClass) && Arrays.equals(this.argumentTypes, that.argumentTypes); - assert !res || this.isStatic == that.isStatic; - return res; - } - return false; - } - - public int getDeclaredParameterCount() { - return isStatic ? argumentTypes.length : argumentTypes.length - 1; - } - - @Override - public int hashCode() { - // Replay compilation mandates use of stable hash codes - return declaringClass.getName().hashCode() ^ name.hashCode(); - } - - private MethodIdHolder resolve(MetaAccessProvider metaAccess) { - return (MethodIdHolder) metaAccess.lookupJavaMethod(resolveJava()); - } - - private Executable resolveJava() { - try { - Executable res; - Class[] parameterTypes = isStatic ? argumentTypes : Arrays.copyOfRange(argumentTypes, 1, argumentTypes.length); - if (name.equals("")) { - res = declaringClass.getDeclaredConstructor(parameterTypes); - } else { - res = declaringClass.getDeclaredMethod(name, parameterTypes); - } - assert Modifier.isStatic(res.getModifiers()) == isStatic; - return res; - } catch (NoSuchMethodException | SecurityException e) { - throw new InternalError(e); - } - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(declaringClass.getName()).append('.').append(name).append('('); - for (Class p : argumentTypes) { - if (sb.charAt(sb.length() - 1) != '(') { - sb.append(", "); - } - sb.append(p.getSimpleName()); - } - return sb.append(')').toString(); - } - } - - private final MetaAccessProvider metaAccess; - - /** - * Initial list of entries. - */ - private final List> registrations; - - /** - * Entry array that is initialized upon first call to {@link #get(MethodIdHolder)}. - * - * Note: this must be volatile since double-checked locking is used to initialize it - */ - private volatile V[] entries; - - /** - * The minimum {@linkplain MethodIdHolder#getMethodId() id} for a key in this map. - */ - private int minId = Integer.MAX_VALUE; - - public MethodIdMap(MetaAccessProvider metaAccess) { - this.metaAccess = metaAccess; - this.registrations = new ArrayList<>(INITIAL_CAPACITY); - } - - private static final int INITIAL_CAPACITY = 64; - - /** - * Adds an entry to this map for a specified method. - * - * @param value value to be associated with the specified method - * @param isStatic specifies if the method is static - * @param declaringClass the class declaring the method - * @param name the name of the method - * @param argumentTypes the argument types of the method. Element 0 of this array must be - * {@code declaringClass} iff the method is non-static. - * @return an object representing the method - */ - public MethodKey put(V value, boolean isStatic, Class declaringClass, String name, Class... argumentTypes) { - assert isStatic || argumentTypes[0] == declaringClass; - MethodKey methodKey = new MethodKey<>(value, isStatic, declaringClass, name, argumentTypes); - assert entries == null : "registration is closed"; - assert !registrations.contains(methodKey) : "a value is already registered for " + methodKey; - registrations.add(methodKey); - return methodKey; - } - - @SuppressWarnings("unchecked") - protected V[] allocateEntries(int length) { - return (V[]) new Object[length]; - } - - /** - * Determines if a method denoted by a given {@link MethodKey} is in this map. - */ - public boolean containsKey(MethodKey key) { - return registrations.contains(key); - } - - public V get(MethodIdHolder method) { - if (entries == null) { - createEntries(); - } - - int id = method.getMethodId(); - int index = id - minId; - return index >= 0 && index < entries.length ? entries[index] : null; - } - - public void createEntries() { - // 'assignIds' synchronizes on a global lock which ensures thread safe - // allocation of identifiers across all MethodIdHolder objects - MethodIdHolder.assignIds(new Consumer() { - - public void accept(MethodIdAllocator idAllocator) { - if (entries == null) { - if (registrations.isEmpty()) { - entries = allocateEntries(0); - } else { - int max = Integer.MIN_VALUE; - for (MethodKey methodKey : registrations) { - MethodIdHolder m = methodKey.resolve(metaAccess); - int id = idAllocator.assignId(m); - if (id < minId) { - minId = id; - } - if (id > max) { - max = id; - } - methodKey.id = id; - } - - int length = (max - minId) + 1; - entries = allocateEntries(length); - for (MethodKey m : registrations) { - int index = m.id - minId; - entries[index] = m.value; - } - } - } - } - }); - } - - @Override - public String toString() { - return registrations.stream().map(MethodKey::toString).collect(Collectors.joining(", ")); - } - - public MetaAccessProvider getMetaAccess() { - return metaAccess; - } - - public int size() { - return registrations.size(); - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/ModifiersProvider.java --- a/graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/ModifiersProvider.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,140 +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.jvmci.meta; - -import static java.lang.reflect.Modifier.*; - -import java.lang.reflect.*; - -/** - * A Java element (i.e., a class, interface, field or method) that is described by a set of Java - * language {@linkplain #getModifiers() modifiers}. - */ -public interface ModifiersProvider { - - /** - * Returns the Java language modifiers for this element. - */ - int getModifiers(); - - /** - * @see Modifier#isInterface(int) - */ - default boolean isInterface() { - return Modifier.isInterface(getModifiers()); - } - - /** - * @see Modifier#isSynchronized(int) - */ - default boolean isSynchronized() { - return Modifier.isSynchronized(getModifiers()); - } - - /** - * @see Modifier#isStatic(int) - */ - default boolean isStatic() { - return Modifier.isStatic(getModifiers()); - } - - /** - * @see Modifier#isFinal(int) - */ - default boolean isFinal() { - return Modifier.isFinal(getModifiers()); - } - - /** - * @see Modifier#isPublic(int) - */ - default boolean isPublic() { - return Modifier.isPublic(getModifiers()); - } - - /** - * Determines if this element is neither {@linkplain #isPublic() public}, - * {@linkplain #isProtected() protected} nor {@linkplain #isPrivate() private}. - */ - default boolean isPackagePrivate() { - return ((PUBLIC | PROTECTED | PRIVATE) & getModifiers()) == 0; - } - - /** - * @see Modifier#isPrivate(int) - */ - default boolean isPrivate() { - return Modifier.isPrivate(getModifiers()); - } - - /** - * @see Modifier#isProtected(int) - */ - default boolean isProtected() { - return Modifier.isProtected(getModifiers()); - } - - /** - * @see Modifier#isTransient(int) - */ - default boolean isTransient() { - return Modifier.isTransient(getModifiers()); - } - - /** - * @see Modifier#isStrict(int) - */ - default boolean isStrict() { - return Modifier.isStrict(getModifiers()); - } - - /** - * @see Modifier#isVolatile(int) - */ - default boolean isVolatile() { - return Modifier.isVolatile(getModifiers()); - } - - /** - * @see Modifier#isNative(int) - */ - default boolean isNative() { - return Modifier.isNative(getModifiers()); - } - - /** - * @see Modifier#isAbstract(int) - */ - default boolean isAbstract() { - return Modifier.isAbstract(getModifiers()); - } - - /** - * Checks that the method is concrete and not abstract. - * - * @return whether the method is a concrete method - */ - default boolean isConcrete() { - return !isAbstract(); - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/NamedLocationIdentity.java --- a/graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/NamedLocationIdentity.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,118 +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.jvmci.meta; - -import java.util.*; - -import com.oracle.jvmci.meta.Kind.FormatWithToString; - -/** - * A {@link LocationIdentity} with a name. - */ -public final class NamedLocationIdentity extends LocationIdentity implements FormatWithToString { - - /** - * Map for asserting all {@link NamedLocationIdentity} instances have a unique name. - */ - static class DB { - private static final HashMap map = new HashMap<>(); - - static boolean checkUnique(NamedLocationIdentity identity) { - NamedLocationIdentity oldValue = map.put(identity.name, identity); - if (oldValue != null) { - throw new AssertionError("identity " + identity + " already exists"); - } - return true; - } - } - - private final String name; - private final boolean immutable; - - private NamedLocationIdentity(String name, boolean immutable) { - this.name = name; - this.immutable = immutable; - } - - /** - * Creates a named unique location identity for read and write operations against mutable - * memory. - * - * @param name the name of the new location identity - */ - public static NamedLocationIdentity mutable(String name) { - return create(name, false); - } - - /** - * Creates a named unique location identity for read operations against immutable memory. - * Immutable memory will never have a visible write in the graph, which is more restictive than - * Java final. - * - * @param name the name of the new location identity - */ - public static NamedLocationIdentity immutable(String name) { - return create(name, true); - } - - /** - * Creates a named unique location identity for read and write operations. - * - * @param name the name of the new location identity - * @param immutable true if the location is immutable - */ - private static NamedLocationIdentity create(String name, boolean immutable) { - NamedLocationIdentity id = new NamedLocationIdentity(name, immutable); - assert DB.checkUnique(id); - return id; - } - - @Override - public boolean isImmutable() { - return immutable; - } - - @Override - public String toString() { - return name + (isImmutable() ? ":final" : ""); - } - - /** - * Returns the named location identity for an array of the given element kind. Array accesses of - * the same kind must have the same location identity unless an alias analysis guarantees that - * two distinct arrays are accessed. - */ - public static LocationIdentity getArrayLocation(Kind elementKind) { - return ARRAY_LOCATIONS.get(elementKind); - } - - private static final EnumMap ARRAY_LOCATIONS = initArrayLocations(); - - private static EnumMap initArrayLocations() { - EnumMap result = new EnumMap<>(Kind.class); - for (Kind kind : Kind.values()) { - result.put(kind, NamedLocationIdentity.mutable("Array: " + kind.getJavaName())); - } - return result; - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/NullConstant.java --- a/graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/NullConstant.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,93 +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; - -/** - * The implementation type of the {@link JavaConstant#NULL_POINTER null constant}. - */ -final class NullConstant extends AbstractValue implements JavaConstant { - - protected NullConstant() { - super(LIRKind.reference(Kind.Object)); - } - - @Override - public boolean isNull() { - return true; - } - - @Override - public boolean isDefaultForKind() { - return true; - } - - @Override - public Object asBoxedPrimitive() { - throw new IllegalArgumentException(); - } - - @Override - public int asInt() { - throw new IllegalArgumentException(); - } - - @Override - public boolean asBoolean() { - throw new IllegalArgumentException(); - } - - @Override - public long asLong() { - throw new IllegalArgumentException(); - } - - @Override - public float asFloat() { - throw new IllegalArgumentException(); - } - - @Override - public double asDouble() { - throw new IllegalArgumentException(); - } - - @Override - public String toString() { - return JavaConstant.toString(this); - } - - @Override - public String toValueString() { - return "null"; - } - - @Override - public int hashCode() { - return 13; - } - - @Override - public boolean equals(Object o) { - return o instanceof NullConstant; - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/PlatformKind.java --- a/graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/PlatformKind.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,74 +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.jvmci.meta; - -/** - * Represents a platform-specific low-level type for values. - */ -public interface PlatformKind { - - String name(); - - JavaConstant getDefaultValue(); - - public interface Key { - - } - - public class EnumKey implements Key { - @SuppressWarnings("rawtypes") private final Enum e; - - @SuppressWarnings("rawtypes") - public EnumKey(Enum e) { - this.e = e; - } - - @Override - public int hashCode() { - return e.ordinal() ^ e.name().hashCode(); - } - - @Override - public boolean equals(Object obj) { - if (obj == this) { - return true; - } - if (obj instanceof EnumKey) { - EnumKey that = (EnumKey) obj; - return this.e == that.e; - } - return false; - } - } - - /** - * Gets a value associated with this object that can be used as a stable key in a map. The - * {@link Object#hashCode()} implementation of the returned value should be stable between VM - * executions. - */ - Key getKey(); - - default int getVectorLength() { - return 1; - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/PrimitiveConstant.java --- a/graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/PrimitiveConstant.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,164 +0,0 @@ -/* - * Copyright (c) 2009, 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.meta; - -import java.nio.*; - -/** - * Represents a primitive constant value, such as an integer or floating point number, within the - * compiler and across the compiler/runtime interface. - */ -public class PrimitiveConstant extends AbstractValue implements JavaConstant, SerializableConstant { - - /** - * The boxed primitive value as a {@code long}. For {@code float} and {@code double} values, - * this value is the result of {@link Float#floatToRawIntBits(float)} and - * {@link Double#doubleToRawLongBits(double)} respectively. - */ - private final long primitive; - - protected PrimitiveConstant(Kind kind, long primitive) { - super(LIRKind.value(kind)); - this.primitive = primitive; - - assert kind.isPrimitive() || kind == Kind.Illegal; - } - - @Override - public boolean isNull() { - return false; - } - - @Override - public boolean isDefaultForKind() { - return primitive == 0; - } - - @Override - public boolean asBoolean() { - assert getKind() == Kind.Boolean; - return primitive != 0L; - } - - @Override - public int asInt() { - assert getKind().getStackKind() == Kind.Int : getKind().getStackKind(); - return (int) primitive; - } - - @Override - public long asLong() { - assert getKind().isNumericInteger(); - return primitive; - } - - @Override - public float asFloat() { - assert getKind() == Kind.Float; - return Float.intBitsToFloat((int) primitive); - } - - @Override - public double asDouble() { - assert getKind() == Kind.Double; - return Double.longBitsToDouble(primitive); - } - - @Override - public Object asBoxedPrimitive() { - switch (getKind()) { - case Byte: - return Byte.valueOf((byte) primitive); - case Boolean: - return Boolean.valueOf(asBoolean()); - case Short: - return Short.valueOf((short) primitive); - case Char: - return Character.valueOf((char) primitive); - case Int: - return Integer.valueOf(asInt()); - case Long: - return Long.valueOf(asLong()); - case Float: - return Float.valueOf(asFloat()); - case Double: - return Double.valueOf(asDouble()); - default: - throw new IllegalArgumentException("unexpected kind " + getKind()); - } - } - - @Override - public int getSerializedSize() { - return getKind().getByteCount(); - } - - @Override - public void serialize(ByteBuffer buffer) { - switch (getKind()) { - case Byte: - case Boolean: - buffer.put((byte) primitive); - break; - case Short: - buffer.putShort((short) primitive); - break; - case Char: - buffer.putChar((char) primitive); - break; - case Int: - buffer.putInt(asInt()); - break; - case Long: - buffer.putLong(asLong()); - break; - case Float: - buffer.putFloat(asFloat()); - break; - case Double: - buffer.putDouble(asDouble()); - break; - default: - throw new IllegalArgumentException("unexpected kind " + getKind()); - } - } - - @Override - public int hashCode() { - return (int) (primitive ^ (primitive >>> 32)) * (getKind().ordinal() + 31); - } - - @Override - public boolean equals(Object o) { - return o == this || (o instanceof PrimitiveConstant && super.equals(o) && primitive == ((PrimitiveConstant) o).primitive); - } - - @Override - public String toString() { - if (getKind() == Kind.Illegal) { - return "illegal"; - } else { - return getKind().getJavaName() + "[" + asBoxedPrimitive() + "|0x" + Long.toHexString(primitive) + "]"; - } - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/ProfilingInfo.java --- a/graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/ProfilingInfo.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,199 +0,0 @@ -/* - * Copyright (c) 2012, 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.meta; - -/** - * Provides access to the profiling information of one specific method. Every accessor method - * returns the information that is available at the time of invocation. If a method is invoked - * multiple times, it may return significantly different results for every invocation as the - * profiling information may be changed by other Java threads at any time. - */ -public interface ProfilingInfo { - - /** - * Returns the length of the bytecodes associated with this profile. - */ - int getCodeSize(); - - /** - * Returns an estimate of how often the branch at the given byte code was taken. - * - * @return The estimated probability, with 0.0 meaning never and 1.0 meaning always, or -1 if - * this information is not available. - */ - double getBranchTakenProbability(int bci); - - /** - * Returns an estimate of how often the switch cases are taken at the given BCI. The default - * case is stored as the last entry. - * - * @return A double value that contains the estimated probabilities, with 0.0 meaning never and - * 1.0 meaning always, or -1 if this information is not available. - */ - double[] getSwitchProbabilities(int bci); - - /** - * Returns the TypeProfile for the given BCI. - * - * @return Returns a JavaTypeProfile object, or null if not available. - */ - JavaTypeProfile getTypeProfile(int bci); - - /** - * Returns the MethodProfile for the given BCI. - * - * @return Returns a JavaMethodProfile object, or null if not available. - */ - JavaMethodProfile getMethodProfile(int bci); - - /** - * Returns information if the given BCI did ever throw an exception. - * - * @return {@link TriState#TRUE} if the instruction has thrown an exception at least once, - * {@link TriState#FALSE} if it never threw an exception, and {@link TriState#UNKNOWN} - * if this information was not recorded. - */ - TriState getExceptionSeen(int bci); - - /** - * Returns information if null was ever seen for the given BCI. This information is collected - * for the aastore, checkcast and instanceof bytecodes. - * - * @return {@link TriState#TRUE} if null was seen for the instruction, {@link TriState#FALSE} if - * null was NOT seen, and {@link TriState#UNKNOWN} if this information was not recorded. - */ - TriState getNullSeen(int bci); - - /** - * Returns an estimate how often the current BCI was executed. Avoid comparing execution counts - * to each other, as the returned value highly depends on the time of invocation. - * - * @return the estimated execution count or -1 if not available. - */ - int getExecutionCount(int bci); - - /** - * Returns how frequently a method was deoptimized for the given deoptimization reason. This - * only indicates how often the method did fall back to the interpreter for the execution and - * does not indicate how often it was recompiled. - * - * @param reason the reason for which the number of deoptimizations should be queried - * @return the number of times the compiled method deoptimized for the given reason. - */ - int getDeoptimizationCount(DeoptimizationReason reason); - - /** - * Records the size of the compiler intermediate representation (IR) associated with this - * method. - * - * @param irType the IR type for which the size is being recorded - * @param irSize the IR size to be recorded. The unit depends on the IR. - * @return whether recording this information for {@code irType} is supported - */ - boolean setCompilerIRSize(Class irType, int irSize); - - /** - * Gets the size of the compiler intermediate representation (IR) associated with this method - * last recorded by {@link #setCompilerIRSize(Class, int)}. - * - * @param irType the IR type for which the size is being requested - * @return the requested IR size or -1 if it is unavailable for {@code irType} - */ - int getCompilerIRSize(Class irType); - - /** - * Returns true if the profiling information can be assumed as sufficiently accurate. - * - * @return true if the profiling information was recorded often enough mature enough, false - * otherwise. - */ - boolean isMature(); - - /** - * Force data to be treated as mature if possible. - */ - void setMature(); - - /** - * Formats this profiling information to a string. - * - * @param method an optional method that augments the profile string returned - * @param sep the separator to use for each separate profile record - */ - default String toString(ResolvedJavaMethod method, String sep) { - StringBuilder buf = new StringBuilder(100); - if (method != null) { - buf.append(String.format("canBeStaticallyBound: %b%s", method.canBeStaticallyBound(), sep)); - } - for (int i = 0; i < getCodeSize(); i++) { - if (getExecutionCount(i) != -1) { - buf.append(String.format("executionCount@%d: %d%s", i, getExecutionCount(i), sep)); - } - - if (getBranchTakenProbability(i) != -1) { - buf.append(String.format("branchProbability@%d: %.6f%s", i, getBranchTakenProbability(i), sep)); - } - - double[] switchProbabilities = getSwitchProbabilities(i); - if (switchProbabilities != null) { - buf.append(String.format("switchProbabilities@%d:", i)); - for (int j = 0; j < switchProbabilities.length; j++) { - buf.append(String.format(" %.6f", switchProbabilities[j])); - } - buf.append(sep); - } - - if (getExceptionSeen(i) != TriState.UNKNOWN) { - buf.append(String.format("exceptionSeen@%d: %s%s", i, getExceptionSeen(i).name(), sep)); - } - - if (getNullSeen(i) != TriState.UNKNOWN) { - buf.append(String.format("nullSeen@%d: %s%s", i, getNullSeen(i).name(), sep)); - } - - JavaTypeProfile typeProfile = getTypeProfile(i); - MetaUtil.appendProfile(buf, typeProfile, i, "types", sep); - - JavaMethodProfile methodProfile = getMethodProfile(i); - MetaUtil.appendProfile(buf, methodProfile, i, "methods", sep); - } - - boolean firstDeoptReason = true; - for (DeoptimizationReason reason : DeoptimizationReason.values()) { - int count = getDeoptimizationCount(reason); - if (count > 0) { - if (firstDeoptReason) { - buf.append("deoptimization history").append(sep); - firstDeoptReason = false; - } - buf.append(String.format(" %s: %d%s", reason.name(), count, sep)); - } - } - if (buf.length() == 0) { - return ""; - } - String s = buf.toString(); - return s.substring(0, s.length() - sep.length()); - } - -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/RawConstant.java --- a/graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/RawConstant.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,30 +0,0 @@ -/* - * Copyright (c) 2009, 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; - -public class RawConstant extends PrimitiveConstant { - - public RawConstant(long rawValue) { - super(Kind.Int, rawValue); - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/ResolvedJavaField.java --- a/graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/ResolvedJavaField.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,75 +0,0 @@ -/* - * Copyright (c) 2009, 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.*; -import java.lang.reflect.*; - -/** - * Represents a reference to a resolved Java field. Fields, like methods and types, are resolved - * through {@link ConstantPool constant pools}. - */ -public interface ResolvedJavaField extends JavaField, ModifiersProvider { - - /** - * {@inheritDoc} - *

- * Only the {@linkplain Modifier#fieldModifiers() field flags} specified in the JVM - * specification will be included in the returned mask. - */ - int getModifiers(); - - /** - * Determines if this field was injected by the VM. Such a field, for example, is not derived - * from a class file. - */ - boolean isInternal(); - - /** - * Determines if this field is a synthetic field as defined by the Java Language Specification. - */ - boolean isSynthetic(); - - /** - * Returns the {@link ResolvedJavaType} object representing the class or interface that declares - * this field. - */ - ResolvedJavaType getDeclaringClass(); - - /** - * Returns the annotation for the specified type of this field, if such an annotation is - * present. - * - * @param annotationClass the Class object corresponding to the annotation type - * @return this element's annotation for the specified annotation type if present on this field, - * else {@code null} - */ - T getAnnotation(Class annotationClass); - - /** - * Returns an object representing the unique location identity of this resolved Java field. - * - * @return the location identity of the field - */ - LocationIdentity getLocationIdentity(); -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/ResolvedJavaMethod.java --- a/graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/ResolvedJavaMethod.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,316 +0,0 @@ -/* - * Copyright (c) 2009, 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.*; -import java.lang.reflect.*; - -/** - * Represents a resolved Java method. Methods, like fields and types, are resolved through - * {@link ConstantPool constant pools}. - */ -public interface ResolvedJavaMethod extends JavaMethod, InvokeTarget, ModifiersProvider { - - /** - * Returns the bytecode of this method, if the method has code. The returned byte array does not - * contain breakpoints or non-Java bytecodes. This may return null if the - * {@link #getDeclaringClass() holder} is not {@link ResolvedJavaType#isLinked() linked}. - * - * The contained constant pool indices may not be the ones found in the original class file but - * they can be used with the JVMCI API (e.g. methods in {@link ConstantPool}). - * - * @return the bytecode of the method, or {@code null} if {@code getCodeSize() == 0} or if the - * code is not ready. - */ - byte[] getCode(); - - /** - * Returns the size of the bytecode of this method, if the method has code. This is equivalent - * to {@link #getCode()}. {@code length} if the method has code. - * - * @return the size of the bytecode in bytes, or 0 if no bytecode is available - */ - int getCodeSize(); - - /** - * Returns the {@link ResolvedJavaType} object representing the class or interface that declares - * this method. - */ - ResolvedJavaType getDeclaringClass(); - - /** - * Returns the maximum number of locals used in this method's bytecodes. - */ - int getMaxLocals(); - - /** - * Returns the maximum number of stack slots used in this method's bytecodes. - */ - int getMaxStackSize(); - - /** - * {@inheritDoc} - *

- * Only the {@linkplain Modifier#methodModifiers() method flags} specified in the JVM - * specification will be included in the returned mask. - */ - int getModifiers(); - - /** - * Determines if this method is a synthetic method as defined by the Java Language - * Specification. - */ - boolean isSynthetic(); - - /** - * Returns {@code true} if this method is a default method; returns {@code false} otherwise. - * - * A default method is a public non-abstract instance method, that is, a non-static method with - * a body, declared in an interface type. - * - * @return true if and only if this method is a default method as defined by the Java Language - * Specification. - */ - boolean isDefault(); - - /** - * Checks whether this method is a class initializer. - * - * @return {@code true} if the method is a class initializer - */ - boolean isClassInitializer(); - - /** - * Checks whether this method is a constructor. - * - * @return {@code true} if the method is a constructor - */ - boolean isConstructor(); - - /** - * Checks whether this method can be statically bound (usually, that means it is final or - * private or static, but not abstract, or the declaring class is final). - * - * @return {@code true} if this method can be statically bound - */ - boolean canBeStaticallyBound(); - - /** - * Returns the list of exception handlers for this method. - */ - ExceptionHandler[] getExceptionHandlers(); - - /** - * Returns a stack trace element for this method and a given bytecode index. - */ - StackTraceElement asStackTraceElement(int bci); - - /** - * Returns an object that provides access to the profiling information recorded for this method. - */ - default ProfilingInfo getProfilingInfo() { - return getProfilingInfo(true, true); - } - - /** - * Returns an object that provides access to the profiling information recorded for this method. - * - * @param includeNormal if true, - * {@linkplain ProfilingInfo#getDeoptimizationCount(DeoptimizationReason) - * deoptimization counts} will include deoptimization that happened during execution - * of standard non-osr methods. - * @param includeOSR if true, - * {@linkplain ProfilingInfo#getDeoptimizationCount(DeoptimizationReason) - * deoptimization counts} will include deoptimization that happened during execution - * of on-stack-replacement methods. - */ - ProfilingInfo getProfilingInfo(boolean includeNormal, boolean includeOSR); - - /** - * Invalidates the profiling information and restarts profiling upon the next invocation. - */ - void reprofile(); - - /** - * Returns the constant pool of this method. - */ - ConstantPool getConstantPool(); - - /** - * Returns all annotations of this method. If no annotations are present, an array of length 0 - * is returned. - */ - Annotation[] getAnnotations(); - - /** - * Returns the annotation for the specified type of this method, if such an annotation is - * present. - * - * @param annotationClass the Class object corresponding to the annotation type - * @return this element's annotation for the specified annotation type if present on this - * method, else {@code null} - */ - T getAnnotation(Class annotationClass); - - /** - * Returns an array of arrays that represent the annotations on the formal parameters, in - * declaration order, of this method. - * - * @see Method#getParameterAnnotations() - */ - Annotation[][] getParameterAnnotations(); - - /** - * Returns an array of {@link Type} objects that represent the formal parameter types, in - * declaration order, of this method. - * - * @see Method#getGenericParameterTypes() - */ - Type[] getGenericParameterTypes(); - - /** - * Returns {@code true} if this method is not excluded from inlining and has associated Java - * bytecodes (@see {@link ResolvedJavaMethod#hasBytecodes()}). - */ - boolean canBeInlined(); - - /** - * Returns {@code true} if the inlining of this method should be forced. - */ - boolean shouldBeInlined(); - - /** - * Returns the LineNumberTable of this method or null if this method does not have a line - * numbers table. - */ - LineNumberTable getLineNumberTable(); - - /** - * Returns the local variable table of this method or null if this method does not have a local - * variable table. - */ - LocalVariableTable getLocalVariableTable(); - - /** - * Invokes the underlying method represented by this object, on the specified object with the - * specified parameters. This method is similar to a reflective method invocation by - * {@link Method#invoke}. - * - * @param receiver The receiver for the invocation, or {@code null} if it is a static method. - * @param arguments The arguments for the invocation. - * @return The value returned by the method invocation, or {@code null} if the return type is - * {@code void}. - */ - JavaConstant invoke(JavaConstant receiver, JavaConstant[] arguments); - - /** - * Gets the encoding of (that is, a constant representing the value of) this method. - * - * @return a constant representing a reference to this method - */ - Constant getEncoding(); - - /** - * Checks if this method is present in the virtual table for subtypes of the specified - * {@linkplain ResolvedJavaType type}. - * - * @return true is this method is present in the virtual table for subtypes of this type. - */ - boolean isInVirtualMethodTable(ResolvedJavaType resolved); - - /** - * Gets the annotation of a particular type for a formal parameter of this method. - * - * @param annotationClass the Class object corresponding to the annotation type - * @param parameterIndex the index of a formal parameter of {@code method} - * @return the annotation of type {@code annotationClass} for the formal parameter present, else - * null - * @throws IndexOutOfBoundsException if {@code parameterIndex} does not denote a formal - * parameter - */ - default T getParameterAnnotation(Class annotationClass, int parameterIndex) { - if (parameterIndex >= 0) { - Annotation[][] parameterAnnotations = getParameterAnnotations(); - for (Annotation a : parameterAnnotations[parameterIndex]) { - if (a.annotationType() == annotationClass) { - return annotationClass.cast(a); - } - } - } - return null; - } - - default JavaType[] toParameterTypes() { - JavaType receiver = isStatic() || isConstructor() ? null : getDeclaringClass(); - return getSignature().toParameterTypes(receiver); - } - - /** - * Gets the annotations of a particular type for the formal parameters of this method. - * - * @param annotationClass the Class object corresponding to the annotation type - * @return the annotation of type {@code annotationClass} (if any) for each formal parameter - * present - */ - @SuppressWarnings("unchecked") - default T[] getParameterAnnotations(Class annotationClass) { - Annotation[][] parameterAnnotations = getParameterAnnotations(); - T[] result = (T[]) Array.newInstance(annotationClass, parameterAnnotations.length); - for (int i = 0; i < parameterAnnotations.length; i++) { - for (Annotation a : parameterAnnotations[i]) { - if (a.annotationType() == annotationClass) { - result[i] = annotationClass.cast(a); - } - } - } - return result; - } - - /** - * Checks whether the method has bytecodes associated with it. Methods without bytecodes are - * either abstract or native methods. - * - * @return whether the definition of this method is Java bytecodes - */ - default boolean hasBytecodes() { - return isConcrete() && !isNative(); - } - - /** - * Checks whether the method has a receiver parameter - i.e., whether it is not static. - * - * @return whether the method has a receiver parameter - */ - default boolean hasReceiver() { - return !isStatic(); - } - - /** - * Determines if this method is {@link java.lang.Object#Object()}. - */ - default boolean isJavaLangObjectInit() { - return getDeclaringClass().isJavaLangObject() && getName().equals(""); - } - - SpeculationLog getSpeculationLog(); -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/ResolvedJavaType.java --- a/graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/ResolvedJavaType.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,354 +0,0 @@ -/* - * Copyright (c) 2009, 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.*; -import java.net.*; - -import com.oracle.jvmci.meta.Assumptions.AssumptionResult; - -/** - * Represents a resolved Java type. Types include primitives, objects, {@code void}, and arrays - * thereof. Types, like fields and methods, are resolved through {@link ConstantPool constant pools} - * . - */ -public interface ResolvedJavaType extends JavaType, ModifiersProvider { - - /** - * Gets the runtime representation of the Java class object of this type. - */ - JavaConstant getJavaClass(); - - /** - * Gets the runtime representation of the "hub" of this type--that is, the closest part of the - * type representation which is typically stored in the object header. - */ - Constant getObjectHub(); - - /** - * Checks whether this type has a finalizer method. - * - * @return {@code true} if this class has a finalizer - */ - boolean hasFinalizer(); - - /** - * Checks whether this type has any finalizable subclasses so far. Any decisions based on this - * information require the registration of a dependency, since this information may change. - * - * @return {@code true} if this class has any subclasses with finalizers - */ - AssumptionResult hasFinalizableSubclass(); - - /** - * Checks whether this type is an interface. - * - * @return {@code true} if this type is an interface - */ - boolean isInterface(); - - /** - * Checks whether this type is an instance class. - * - * @return {@code true} if this type is an instance class - */ - boolean isInstanceClass(); - - /** - * Checks whether this type is an array class. - * - * @return {@code true} if this type is an array class - */ - boolean isArray(); - - /** - * Checks whether this type is primitive. - * - * @return {@code true} if this type is primitive - */ - boolean isPrimitive(); - - /** - * {@inheritDoc} - *

- * Only the flags specified in the JVM specification will be included in the returned mask. This - * method is identical to {@link Class#getModifiers()} in terms of the value return for this - * type. - */ - int getModifiers(); - - /** - * Checks whether this type is initialized. If a type is initialized it implies that it was - * {@link #isLinked() linked} and that the static initializer has run. - * - * @return {@code true} if this type is initialized - */ - boolean isInitialized(); - - /** - * Initializes this type. - */ - void initialize(); - - /** - * Checks whether this type is linked and verified. When a type is linked the static initializer - * has not necessarily run. An {@link #isInitialized() initialized} type is always linked. - * - * @return {@code true} if this type is linked - */ - boolean isLinked(); - - /** - * Determines if this type is either the same as, or is a superclass or superinterface of, the - * type represented by the specified parameter. This method is identical to - * {@link Class#isAssignableFrom(Class)} in terms of the value return for this type. - */ - boolean isAssignableFrom(ResolvedJavaType other); - - /** - * Returns true if this type is exactly the type {@link java.lang.Object}. - */ - default boolean isJavaLangObject() { - // Removed assertion due to https://bugs.eclipse.org/bugs/show_bug.cgi?id=434442 - return getSuperclass() == null && !isInterface() && getKind() == Kind.Object; - } - - /** - * Checks whether the specified object is an instance of this type. - * - * @param obj the object to test - * @return {@code true} if the object is an instance of this type - */ - boolean isInstance(JavaConstant obj); - - /** - * Returns this type if it is an exact type otherwise returns null. This type is exact if it is - * void, primitive, final, or an array of a final or primitive type. - * - * @return this type if it is exact; {@code null} otherwise - */ - ResolvedJavaType asExactType(); - - /** - * Gets the super class of this type. If this type represents either the {@code Object} class, - * an interface, a primitive type, or void, then null is returned. If this object represents an - * array class then the type object representing the {@code Object} class is returned. - */ - ResolvedJavaType getSuperclass(); - - /** - * Gets the interfaces implemented or extended by this type. This method is analogous to - * {@link Class#getInterfaces()} and as such, only returns the interfaces directly implemented - * or extended by this type. - */ - ResolvedJavaType[] getInterfaces(); - - /** - * Gets the single implementor of this type. Calling this method on a non-interface type causes - * an exception. - *

- * If the compiler uses the result of this method for its compilation, the usage must be guarded - * because the verifier can not guarantee that the assigned type really implements this - * interface. Additionally, class loading can invalidate the result of this method. - * - * @return {@code null} if there is no implementor, the implementor if there is only one, or - * {@code this} if there are more than one. - */ - ResolvedJavaType getSingleImplementor(); - - /** - * Walks the class hierarchy upwards and returns the least common class that is a superclass of - * both the current and the given type. - * - * @return the least common type that is a super type of both the current and the given type, or - * {@code null} if primitive types are involved. - */ - ResolvedJavaType findLeastCommonAncestor(ResolvedJavaType otherType); - - /** - * Attempts to get a leaf concrete subclass of this type. - *

- * For an {@linkplain #isArray() array} type A, the leaf concrete subclass is A if the - * {@linkplain #getElementalType() elemental} type of A is final (which includes primitive - * types). Otherwise {@code null} is returned for A. - *

- * For a non-array type T, the result is the leaf concrete type in the current hierarchy of T. - *

- * A runtime may decide not to manage or walk a large hierarchy and so the result is - * conservative. That is, a non-null result is guaranteed to be the leaf concrete class in T's - * hierarchy at the current point in time but a null result does not necessarily imply - * that there is no leaf concrete class in T's hierarchy. - *

- * If the compiler uses the result of this method for its compilation, it must register the - * {@link AssumptionResult} in its {@link Assumptions} because dynamic class loading can - * invalidate the result of this method. - * - * @return an {@link AssumptionResult} containing the leaf concrete subclass for this type as - * described above - */ - AssumptionResult findLeafConcreteSubtype(); - - ResolvedJavaType getComponentType(); - - default ResolvedJavaType getElementalType() { - ResolvedJavaType t = this; - while (t.isArray()) { - t = t.getComponentType(); - } - return t; - } - - ResolvedJavaType getArrayClass(); - - /** - * Resolves the method implementation for virtual dispatches on objects of this dynamic type. - * This resolution process only searches "up" the class hierarchy of this type. - * - * @param method the method to select the implementation of - * @param callerType the caller or context type used to perform access checks - * @param includeAbstract whether abstract methods should be returned. If it is {@code false} - * this method behaves like {@link #resolveConcreteMethod}. This is just a temporary - * parameter to highlight the changed semantics of this method. TODO (je) remove this - * flag. - * @return the link-time resolved method (might be abstract) or {@code null} if it can not be - * linked - */ - ResolvedJavaMethod resolveMethod(ResolvedJavaMethod method, ResolvedJavaType callerType, boolean includeAbstract); - - /** - * Resolves the method implementation for virtual dispatches on objects of this dynamic type. - * This resolution process only searches "up" the class hierarchy of this type. A broader search - * that also walks "down" the hierarchy is implemented by - * {@link #findUniqueConcreteMethod(ResolvedJavaMethod)}. - * - * @param method the method to select the implementation of - * @param callerType the caller or context type used to perform access checks - * @return the concrete method that would be selected at runtime, or {@code null} if there is no - * concrete implementation of {@code method} in this type or any of its superclasses - */ - ResolvedJavaMethod resolveConcreteMethod(ResolvedJavaMethod method, ResolvedJavaType callerType); - - /** - * Given a {@link ResolvedJavaMethod} A, returns a concrete {@link ResolvedJavaMethod} B that is - * the only possible unique target for a virtual call on A(). Returns {@code null} if either no - * such concrete method or more than one such method exists. Returns the method A if A is a - * concrete method that is not overridden. - *

- * If the compiler uses the result of this method for its compilation, it must register an - * assumption because dynamic class loading can invalidate the result of this method. - * - * @param method the method A for which a unique concrete target is searched - * @return the unique concrete target or {@code null} if no such target exists or assumptions - * are not supported by this runtime - */ - AssumptionResult findUniqueConcreteMethod(ResolvedJavaMethod method); - - /** - * Returns the instance fields of this class, including - * {@linkplain ResolvedJavaField#isInternal() internal} fields. A zero-length array is returned - * for array and primitive types. The order of fields returned by this method is stable. That - * is, for a single JVM execution the same order is returned each time this method is called. It - * is also the "natural" order, which means that the JVM would expect the fields in this order - * if no specific order is given. - * - * @param includeSuperclasses if true, then instance fields for the complete hierarchy of this - * type are included in the result - * @return an array of instance fields - */ - ResolvedJavaField[] getInstanceFields(boolean includeSuperclasses); - - /** - * Returns the static fields of this class, including - * {@linkplain ResolvedJavaField#isInternal() internal} fields. A zero-length array is returned - * for array and primitive types. The order of fields returned by this method is stable. That - * is, for a single JVM execution the same order is returned each time this method is called. - */ - ResolvedJavaField[] getStaticFields(); - - /** - * Returns the annotation for the specified type of this class, if such an annotation is - * present. - * - * @param annotationClass the Class object corresponding to the annotation type - * @return this element's annotation for the specified annotation type if present on this class, - * else {@code null} - */ - T getAnnotation(Class annotationClass); - - /** - * Returns the instance field of this class (or one of its super classes) at the given offset, - * or {@code null} if there is no such field. - * - * @param offset the offset of the field to look for - * @return the field with the given offset, or {@code null} if there is no such field. - */ - ResolvedJavaField findInstanceFieldWithOffset(long offset, Kind expectedKind); - - /** - * Returns name of source file of this type. - */ - String getSourceFileName(); - - /** - * Returns the class file path - if available - of this type, or {@code null}. - */ - URL getClassFilePath(); - - /** - * Returns {@code true} if the type is a local type. - */ - boolean isLocal(); - - /** - * Returns {@code true} if the type is a member type. - */ - boolean isMember(); - - /** - * Returns the enclosing type of this type, if it exists, or {@code null}. - */ - ResolvedJavaType getEnclosingType(); - - /** - * Returns an array reflecting all the constructors declared by this type. This method is - * similar to {@link Class#getDeclaredConstructors()} in terms of returned constructors. - */ - ResolvedJavaMethod[] getDeclaredConstructors(); - - /** - * Returns an array reflecting all the methods declared by this type. This method is similar to - * {@link Class#getDeclaredMethods()} in terms of returned methods. - */ - ResolvedJavaMethod[] getDeclaredMethods(); - - /** - * Returns the {@code } method for this class if there is one. - */ - ResolvedJavaMethod getClassInitializer(); - - /** - * Returns true if this type represents an interface and it should be trusted even in places - * where the JVM verifier would not give any guarantees other than {@link Object}. - */ - boolean isTrustedInterfaceType(); -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/SerializableConstant.java --- a/graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/SerializableConstant.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,42 +0,0 @@ -/* - * 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 - * 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.nio.*; - -/** - * Represents a compile-time constant that can be converted to a byte array. - */ -public interface SerializableConstant extends Constant { - - /** - * Return the size in bytes of the serialized representation of this constant. - */ - int getSerializedSize(); - - /** - * Serialize the constant into the ByteBuffer. There must be at least - * {@link #getSerializedSize()} bytes available capacity in the buffer. - */ - void serialize(ByteBuffer buffer); -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/Signature.java --- a/graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/Signature.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,139 +0,0 @@ -/* - * Copyright (c) 2009, 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.meta; - -/** - * Represents a method signature provided by the runtime. - * - * @see Method - * Descriptors - */ -public interface Signature { - - /** - * Returns the number of parameters in this signature, adding 1 for a receiver if requested. - * - * @param receiver true if 1 is to be added to the result for a receiver - * @return the number of parameters; + 1 iff {@code receiver == true} - */ - int getParameterCount(boolean receiver); - - /** - * Gets the parameter type at the specified position. - * - * @param index the index into the parameters, with {@code 0} indicating the first parameter - * @param accessingClass the context of the type lookup. If non-null, its class loader is used - * for resolving the type. If {@code null}, then the type returned is either - * unresolved or a resolved type whose resolution is context free (e.g., a primitive - * type or a type in a java.* package). - * @return the {@code index}'th parameter type - * @throws LinkageError if {@code accessingClass != null} and resolution fails - * - */ - JavaType getParameterType(int index, ResolvedJavaType accessingClass); - - /** - * Gets the parameter kind at the specified position. This is the same as calling - * {@link #getParameterType}. {@link JavaType#getKind getKind}. - * - * @param index the index into the parameters, with {@code 0} indicating the first parameter - * @return the kind of the parameter at the specified position - */ - default Kind getParameterKind(int index) { - return getParameterType(index, null).getKind(); - } - - /** - * Gets the return type of this signature. - * - * @param accessingClass the context of the type lookup. If non-null, its class loader is used - * for resolving the type. If {@code null}, then the type returned is either - * unresolved or a resolved type whose resolution is context free (e.g., a primitive - * type or a type in a java.* package). - * @return the return type - * @throws LinkageError if {@code accessingClass != null} and resolution fails - */ - JavaType getReturnType(ResolvedJavaType accessingClass); - - /** - * Gets the return kind of this signature. This is the same as calling {@link #getReturnType}. - * {@link JavaType#getKind getKind}. - */ - default Kind getReturnKind() { - return getReturnType(null).getKind(); - } - - /** - * Gets the method - * descriptor corresponding to this signature. For example: - * - *

-     * (ILjava/lang/String;D)V
-     * 
- * - * @return the signature as a string - */ - default String toMethodDescriptor() { - StringBuilder sb = new StringBuilder("("); - for (int i = 0; i < getParameterCount(false); ++i) { - sb.append(getParameterType(i, null).getName()); - } - sb.append(')').append(getReturnType(null).getName()); - return sb.toString(); - } - - default JavaType[] toParameterTypes(JavaType receiverType) { - int args = getParameterCount(false); - JavaType[] result; - int i = 0; - if (receiverType != null) { - result = new JavaType[args + 1]; - result[0] = receiverType; - i = 1; - } else { - result = new JavaType[args]; - } - for (int j = 0; j < args; j++) { - result[i + j] = getParameterType(j, null); - } - return result; - } - - default Kind[] toParameterKinds(boolean receiver) { - int args = getParameterCount(false); - Kind[] result; - int i = 0; - if (receiver) { - result = new Kind[args + 1]; - result[0] = Kind.Object; - i = 1; - } else { - result = new Kind[args]; - } - for (int j = 0; j < args; j++) { - result[i + j] = getParameterKind(j); - } - return result; - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/SpeculationLog.java --- a/graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/SpeculationLog.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,68 +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.jvmci.meta; - -import java.util.*; -import java.util.concurrent.*; - -/** - * Manages a list of unique deoptimization reasons. - * - */ -public abstract class SpeculationLog { - private volatile Object lastFailed; - private volatile Collection speculations; - private Set failedSpeculations; - - public synchronized void collectFailedSpeculations() { - if (lastFailed != null) { - if (failedSpeculations == null) { - failedSpeculations = new HashSet<>(2); - } - failedSpeculations.add(lastFailed); - lastFailed = null; - speculations = null; - } - } - - public boolean maySpeculate(Object reason) { - if (failedSpeculations != null && failedSpeculations.contains(reason)) { - return false; - } - return true; - } - - protected void addSpeculation(Object reason) { - assert maySpeculate(reason); - if (speculations == null) { - synchronized (this) { - if (speculations == null) { - speculations = new ConcurrentLinkedQueue<>(); - } - } - } - speculations.add(reason); - } - - public abstract JavaConstant speculate(Object reason); -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/TriState.java --- a/graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/TriState.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,77 +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.jvmci.meta; - -/** - * Represents a logic value that can be either {@link #TRUE}, {@link #FALSE}, or {@link #UNKNOWN}. - */ -public enum TriState { - TRUE, - FALSE, - UNKNOWN; - - public static TriState get(boolean value) { - return value ? TRUE : FALSE; - } - - /** - * This is optimistic about {@link #UNKNOWN} (it prefers known values over {@link #UNKNOWN}) and - * pesimistic about known (it perfers {@link #TRUE} over {@link #FALSE}). - */ - public static TriState merge(TriState a, TriState b) { - if (a == TRUE || b == TRUE) { - return TRUE; - } - if (a == FALSE || b == FALSE) { - return FALSE; - } - assert a == UNKNOWN && b == UNKNOWN; - return UNKNOWN; - } - - public boolean isTrue() { - return this == TRUE; - } - - public boolean isFalse() { - return this == FALSE; - } - - public boolean isUnknown() { - return this == UNKNOWN; - } - - public boolean isKnown() { - return this != UNKNOWN; - } - - public boolean toBoolean() { - if (isTrue()) { - return true; - } else if (isFalse()) { - return false; - } else { - throw new IllegalStateException("Cannot convert to boolean, TriState is in an unknown state"); - } - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/TrustedInterface.java --- a/graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/TrustedInterface.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,32 +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; - -/** - * Interfaces extanding this interface should be trusted by the compiler. See - * {@link ResolvedJavaType#isTrustedInterfaceType()}. - * - */ -public interface TrustedInterface { - -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/VMConstant.java --- a/graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/VMConstant.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,26 +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; - -public interface VMConstant extends Constant { -} diff -r 42452d2dfbec -r 395ac43a8578 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 Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,69 +0,0 @@ -/* - * Copyright (c) 2009, 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; - -/** - * Interface for values manipulated by the compiler. All values have a {@linkplain Kind kind} and - * are immutable. - */ -public interface Value extends KindProvider, TrustedInterface { - - Value[] NO_VALUES = new Value[0]; - - AllocatableValue ILLEGAL = new IllegalValue(); - - public final class IllegalValue extends AllocatableValue { - private IllegalValue() { - super(LIRKind.Illegal); - } - - @Override - public String toString() { - return "-"; - } - - @Override - public boolean equals(Object other) { - // Due to de-serialization this object may exist multiple times. So we compare classes - // instead of the individual objects. (This anonymous class has always the same meaning) - return other instanceof IllegalValue; - } - } - - LIRKind getLIRKind(); - - /** - * Returns the platform specific kind used to store this value. - */ - PlatformKind getPlatformKind(); - - /** - * Checks if this value is identical to {@code other}. - * - * Warning: Use with caution! Usually equivalence {@link #equals(Object)} is sufficient and - * should be used. - */ - default boolean identityEquals(Value other) { - return this == other; - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/package-info.java --- a/graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/package-info.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,29 +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 that defines the interface between a runtime and a Java application that wants to access meta information. The runtime - * provides an implementation of the {@link com.oracle.jvmci.meta.MetaAccessProvider} interface. - */ -package com.oracle.jvmci.meta; - diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.options.processor/src/META-INF/services/javax.annotation.processing.Processor --- a/graal/com.oracle.jvmci.options.processor/src/META-INF/services/javax.annotation.processing.Processor Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -com.oracle.jvmci.options.processor.OptionProcessor diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.options.processor/src/com/oracle/jvmci/options/processor/JVMCIJars.java --- a/graal/com.oracle.jvmci.options.processor/src/com/oracle/jvmci/options/processor/JVMCIJars.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,63 +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.jvmci.options.processor; - -import java.io.*; -import java.util.*; -import java.util.stream.*; -import java.util.zip.*; - -public class JVMCIJars implements Iterable { - private final List jars = new ArrayList<>(2); - - public JVMCIJars() { - String classPath = System.getProperty("java.class.path"); - for (String e : classPath.split(File.pathSeparator)) { - if (e.endsWith(File.separatorChar + "graal.jar") || e.endsWith(File.separatorChar + "graal-truffle.jar")) { - try { - jars.add(new ZipFile(e)); - } catch (IOException ioe) { - throw new InternalError(ioe); - } - } - } - if (jars.size() != 2) { - throw new InternalError("Could not find graal.jar or graal-truffle.jar on class path: " + classPath); - } - } - - public Iterator iterator() { - Stream entries = jars.stream().flatMap(ZipFile::stream); - return entries.iterator(); - } - - public InputStream getInputStream(String classFilePath) throws IOException { - for (ZipFile jar : jars) { - ZipEntry entry = jar.getEntry(classFilePath); - if (entry != null) { - return jar.getInputStream(entry); - } - } - return null; - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.options.processor/src/com/oracle/jvmci/options/processor/OptionProcessor.java --- a/graal/com.oracle.jvmci.options.processor/src/com/oracle/jvmci/options/processor/OptionProcessor.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,378 +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.options.processor; - -import java.io.*; -import java.util.*; - -import javax.annotation.processing.*; -import javax.lang.model.*; -import javax.lang.model.element.*; -import javax.lang.model.type.*; -import javax.lang.model.util.*; -import javax.tools.Diagnostic.Kind; -import javax.tools.*; - -import com.oracle.jvmci.options.*; - -/** - * Processes static fields annotated with {@link Option}. An {@link Options} service is generated - * for each top level class containing at least one such field. These service objects can be - * retrieved as follows: - * - *
- * ServiceLoader<Options> sl = ServiceLoader.load(Options.class);
- * for (Options opts : sl) {
- *     for (OptionDescriptor desc : sl) {
- *         // use desc
- *     }
- * }
- * 
- */ -@SupportedAnnotationTypes({"com.oracle.jvmci.options.Option"}) -public class OptionProcessor extends AbstractProcessor { - - @Override - public SourceVersion getSupportedSourceVersion() { - return SourceVersion.latest(); - } - - private final Set processed = new HashSet<>(); - - private void processElement(Element element, OptionsInfo info) { - - if (!element.getModifiers().contains(Modifier.STATIC)) { - processingEnv.getMessager().printMessage(Kind.ERROR, "Option field must be static", element); - return; - } - - Option annotation = element.getAnnotation(Option.class); - assert annotation != null; - assert element instanceof VariableElement; - assert element.getKind() == ElementKind.FIELD; - VariableElement field = (VariableElement) element; - String fieldName = field.getSimpleName().toString(); - - Elements elements = processingEnv.getElementUtils(); - Types types = processingEnv.getTypeUtils(); - - TypeMirror fieldType = field.asType(); - if (fieldType.getKind() != TypeKind.DECLARED) { - processingEnv.getMessager().printMessage(Kind.ERROR, "Option field must be of type " + OptionValue.class.getName(), element); - return; - } - DeclaredType declaredFieldType = (DeclaredType) fieldType; - - TypeMirror optionValueType = elements.getTypeElement(OptionValue.class.getName()).asType(); - if (!types.isSubtype(fieldType, types.erasure(optionValueType))) { - String msg = String.format("Option field type %s is not a subclass of %s", fieldType, optionValueType); - processingEnv.getMessager().printMessage(Kind.ERROR, msg, element); - return; - } - - if (!field.getModifiers().contains(Modifier.STATIC)) { - processingEnv.getMessager().printMessage(Kind.ERROR, "Option field must be static", element); - return; - } - - String help = annotation.help(); - if (help.length() != 0) { - char firstChar = help.charAt(0); - if (!Character.isUpperCase(firstChar)) { - processingEnv.getMessager().printMessage(Kind.ERROR, "Option help text must start with upper case letter", element); - return; - } - } - - String optionName = annotation.name(); - if (optionName.equals("")) { - optionName = fieldName; - } - - DeclaredType declaredOptionValueType = declaredFieldType; - while (!types.isSameType(types.erasure(declaredOptionValueType), types.erasure(optionValueType))) { - List directSupertypes = types.directSupertypes(declaredFieldType); - assert !directSupertypes.isEmpty(); - declaredOptionValueType = (DeclaredType) directSupertypes.get(0); - } - - assert !declaredOptionValueType.getTypeArguments().isEmpty(); - String optionType = declaredOptionValueType.getTypeArguments().get(0).toString(); - if (optionType.startsWith("java.lang.")) { - optionType = optionType.substring("java.lang.".length()); - } - - Element enclosing = element.getEnclosingElement(); - String declaringClass = ""; - String separator = ""; - Set originatingElementsList = info.originatingElements; - originatingElementsList.add(field); - while (enclosing != null) { - if (enclosing.getKind() == ElementKind.CLASS || enclosing.getKind() == ElementKind.INTERFACE) { - if (enclosing.getModifiers().contains(Modifier.PRIVATE)) { - String msg = String.format("Option field cannot be declared in a private %s %s", enclosing.getKind().name().toLowerCase(), enclosing); - processingEnv.getMessager().printMessage(Kind.ERROR, msg, element); - return; - } - originatingElementsList.add(enclosing); - declaringClass = enclosing.getSimpleName() + separator + declaringClass; - separator = "."; - } else { - assert enclosing.getKind() == ElementKind.PACKAGE; - } - enclosing = enclosing.getEnclosingElement(); - } - - info.options.add(new OptionInfo(optionName, help, optionType, declaringClass, field)); - } - - private void createFiles(OptionsInfo info) { - String pkg = ((PackageElement) info.topDeclaringType.getEnclosingElement()).getQualifiedName().toString(); - Name topDeclaringClass = info.topDeclaringType.getSimpleName(); - - String optionsClassName = topDeclaringClass + "_" + Options.class.getSimpleName(); - Element[] originatingElements = info.originatingElements.toArray(new Element[info.originatingElements.size()]); - - Filer filer = processingEnv.getFiler(); - try (PrintWriter out = createSourceFile(pkg, optionsClassName, filer, originatingElements)) { - - out.println("// CheckStyle: stop header check"); - out.println("// GENERATED CONTENT - DO NOT EDIT"); - out.println("// Source: " + topDeclaringClass + ".java"); - out.println("package " + pkg + ";"); - out.println(""); - out.println("import java.util.*;"); - out.println("import " + Options.class.getPackage().getName() + ".*;"); - out.println(""); - out.println("public class " + optionsClassName + " implements " + Options.class.getSimpleName() + " {"); - out.println(" @Override"); - String desc = OptionDescriptor.class.getSimpleName(); - out.println(" public Iterator<" + desc + "> iterator() {"); - out.println(" // CheckStyle: stop line length check"); - out.println(" List<" + desc + "> options = Arrays.asList("); - - boolean needPrivateFieldAccessor = false; - int i = 0; - Collections.sort(info.options); - for (OptionInfo option : info.options) { - String optionValue; - if (option.field.getModifiers().contains(Modifier.PRIVATE)) { - needPrivateFieldAccessor = true; - optionValue = "field(" + option.declaringClass + ".class, \"" + option.field.getSimpleName() + "\")"; - } else { - optionValue = option.declaringClass + "." + option.field.getSimpleName(); - } - String name = option.name; - String type = option.type; - String help = option.help; - String declaringClass = option.declaringClass; - Name fieldName = option.field.getSimpleName(); - String comma = i == info.options.size() - 1 ? "" : ","; - out.printf(" new %s(\"%s\", %s.class, \"%s\", %s.class, \"%s\", %s)%s\n", desc, name, type, help, declaringClass, fieldName, optionValue, comma); - i++; - } - out.println(" );"); - out.println(" // CheckStyle: resume line length check"); - out.println(" return options.iterator();"); - out.println(" }"); - if (needPrivateFieldAccessor) { - out.println(" private static " + OptionValue.class.getSimpleName() + " field(Class declaringClass, String fieldName) {"); - out.println(" try {"); - out.println(" java.lang.reflect.Field field = declaringClass.getDeclaredField(fieldName);"); - out.println(" field.setAccessible(true);"); - out.println(" return (" + OptionValue.class.getSimpleName() + ") field.get(null);"); - out.println(" } catch (Exception e) {"); - out.println(" throw (InternalError) new InternalError().initCause(e);"); - out.println(" }"); - out.println(" }"); - } - out.println("}"); - } - - try { - createProviderFile(pkg, optionsClassName, originatingElements); - createOptionsFile(info, pkg, topDeclaringClass.toString(), originatingElements); - } catch (IOException e) { - processingEnv.getMessager().printMessage(Kind.ERROR, e.getMessage(), info.topDeclaringType); - } - } - - private void createProviderFile(String pkg, String providerClassName, Element... originatingElements) throws IOException { - String filename = "META-INF/providers/" + pkg + "." + providerClassName; - FileObject file = processingEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT, "", filename, originatingElements); - PrintWriter writer = new PrintWriter(new OutputStreamWriter(file.openOutputStream(), "UTF-8")); - writer.println(Options.class.getName()); - writer.close(); - } - - private void createOptionsFile(OptionsInfo info, String pkg, String relativeName, Element... originatingElements) throws IOException { - String filename = "META-INF/options/" + pkg + "." + relativeName; - FileObject file = processingEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT, "", filename, originatingElements); - PrintWriter writer = new PrintWriter(new OutputStreamWriter(file.openOutputStream(), "UTF-8")); - Types types = processingEnv.getTypeUtils(); - for (OptionInfo option : info.options) { - String help = option.help; - if (help.indexOf('\t') >= 0 || help.indexOf('\r') >= 0 || help.indexOf('\n') >= 0) { - processingEnv.getMessager().printMessage(Kind.WARNING, "Option help should not contain '\\t', '\\r' or '\\n'", option.field); - help = help.replace('\t', ' ').replace('\n', ' ').replace('\r', ' '); - } - try { - char optionTypeToChar = optionTypeToChar(option); - String fqDeclaringClass = className(types.erasure(option.field.getEnclosingElement().asType())); - String fqFieldType = className(types.erasure(option.field.asType())); - writer.printf("%s\t%s\t%s\t%s\t%s%n", option.name, optionTypeToChar, help, fqDeclaringClass, fqFieldType); - } catch (IllegalArgumentException iae) { - } - } - writer.close(); - } - - private String className(TypeMirror t) { - DeclaredType dt = (DeclaredType) t; - return processingEnv.getElementUtils().getBinaryName((TypeElement) dt.asElement()).toString(); - } - - private char optionTypeToChar(OptionInfo option) { - switch (option.type) { - case "Boolean": - return 'z'; - case "Integer": - return 'i'; - case "Long": - return 'j'; - case "Float": - return 'f'; - case "Double": - return 'd'; - case "String": - return 's'; - default: - processingEnv.getMessager().printMessage(Kind.ERROR, "Unsoported option type: " + option.type, option.field); - throw new IllegalArgumentException(); - } - } - - protected PrintWriter createSourceFile(String pkg, String relativeName, Filer filer, Element... originatingElements) { - try { - // Ensure Unix line endings to comply with code style guide checked by Checkstyle - JavaFileObject sourceFile = filer.createSourceFile(pkg + "." + relativeName, originatingElements); - return new PrintWriter(sourceFile.openWriter()) { - - @Override - public void println() { - print("\n"); - } - }; - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - static class OptionInfo implements Comparable { - - final String name; - final String help; - final String type; - final String declaringClass; - final VariableElement field; - - public OptionInfo(String name, String help, String type, String declaringClass, VariableElement field) { - this.name = name; - this.help = help; - this.type = type; - this.declaringClass = declaringClass; - this.field = field; - } - - @Override - public int compareTo(OptionInfo other) { - return name.compareTo(other.name); - } - - @Override - public String toString() { - return declaringClass + "." + field; - } - } - - static class OptionsInfo { - - final Element topDeclaringType; - final List options = new ArrayList<>(); - final Set originatingElements = new HashSet<>(); - - public OptionsInfo(Element topDeclaringType) { - this.topDeclaringType = topDeclaringType; - } - } - - private static Element topDeclaringType(Element element) { - Element enclosing = element.getEnclosingElement(); - if (enclosing == null || enclosing.getKind() == ElementKind.PACKAGE) { - assert element.getKind() == ElementKind.CLASS || element.getKind() == ElementKind.INTERFACE; - return element; - } - return topDeclaringType(enclosing); - } - - @Override - public boolean process(Set annotations, RoundEnvironment roundEnv) { - if (roundEnv.processingOver()) { - return true; - } - - Map map = new HashMap<>(); - for (Element element : roundEnv.getElementsAnnotatedWith(Option.class)) { - if (!processed.contains(element)) { - processed.add(element); - Element topDeclaringType = topDeclaringType(element); - OptionsInfo options = map.get(topDeclaringType); - if (options == null) { - options = new OptionsInfo(topDeclaringType); - map.put(topDeclaringType, options); - } - processElement(element, options); - } - } - - boolean ok = true; - Map uniqueness = new HashMap<>(); - for (OptionsInfo info : map.values()) { - for (OptionInfo option : info.options) { - OptionInfo conflict = uniqueness.put(option.name, option); - if (conflict != null) { - processingEnv.getMessager().printMessage(Kind.ERROR, "Duplicate option names for " + option + " and " + conflict, option.field); - ok = false; - } - } - } - - if (ok) { - for (OptionsInfo info : map.values()) { - createFiles(info); - } - } - - return true; - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.options.test/src/com/oracle/jvmci/options/test/NestedBooleanOptionValueTest.java --- a/graal/com.oracle.jvmci.options.test/src/com/oracle/jvmci/options/test/NestedBooleanOptionValueTest.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,128 +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.options.test; - -import static com.oracle.jvmci.options.test.NestedBooleanOptionValueTest.Options.*; -import static org.junit.Assert.*; - -import org.junit.*; - -import com.oracle.jvmci.options.*; -import com.oracle.jvmci.options.OptionValue.OverrideScope; - -public class NestedBooleanOptionValueTest { - - public static class Options { - public static final OptionValue Master0 = new OptionValue<>(true); - public static final OptionValue NestedOption0 = new NestedBooleanOptionValue(Master0, true); - public static final OptionValue Master1 = new OptionValue<>(true); - public static final OptionValue NestedOption1 = new NestedBooleanOptionValue(Master1, true); - public static final OptionValue Master2 = new OptionValue<>(true); - public static final OptionValue NestedOption2 = new NestedBooleanOptionValue(Master2, false); - } - - static final OptionDescriptor master0 = new OptionDescriptor("Master0", Boolean.class, "", Options.class, "Master0", Master0); - static final OptionDescriptor nestedOption0 = new OptionDescriptor("NestedOption0", Boolean.class, "", Options.class, "NestedOption0", NestedOption0); - static final OptionDescriptor master1 = new OptionDescriptor("Master1", Boolean.class, "", Options.class, "Master1", Master1); - static final OptionDescriptor nestedOption1 = new OptionDescriptor("NestedOption1", Boolean.class, "", Options.class, "NestedOption1", NestedOption1); - static final OptionDescriptor master2 = new OptionDescriptor("Master2", Boolean.class, "", Options.class, "Master2", Master2); - static final OptionDescriptor nestedOption2 = new OptionDescriptor("NestedOption2", Boolean.class, "", Options.class, "NestedOption2", NestedOption2); - - @Test - public void runOverrides() { - assertTrue(Master0.getValue()); - assertTrue(NestedOption0.getValue()); - try (OverrideScope s1 = OptionValue.override(Master0, false)) { - assertFalse(Master0.getValue()); - assertFalse(NestedOption0.getValue()); - try (OverrideScope s2 = OptionValue.override(NestedOption0, false)) { - assertFalse(NestedOption0.getValue()); - } - try (OverrideScope s2 = OptionValue.override(NestedOption0, true)) { - assertTrue(NestedOption0.getValue()); - } - } - assertTrue(Master0.getValue()); - try (OverrideScope s1 = OptionValue.override(NestedOption0, false)) { - assertFalse(NestedOption0.getValue()); - } - try (OverrideScope s1 = OptionValue.override(NestedOption0, true)) { - assertTrue(NestedOption0.getValue()); - } - } - - @Test - public void runDefaultTrue() { - Master1.setValue(true); - assertTrue(Master1.getValue()); - assertTrue(NestedOption1.getValue()); - // nested value unset - Master1.setValue(false); - assertFalse(Master1.getValue()); - assertFalse(NestedOption1.getValue()); - // set false - Master1.setValue(false); - NestedOption1.setValue(false); - assertFalse(Master1.getValue()); - assertFalse(NestedOption1.getValue()); - Master1.setValue(true); - assertTrue(Master1.getValue()); - assertFalse(NestedOption1.getValue()); - // set true - Master1.setValue(false); - NestedOption1.setValue(true); - assertFalse(Master1.getValue()); - assertTrue(NestedOption1.getValue()); - Master1.setValue(true); - assertTrue(Master1.getValue()); - assertTrue(NestedOption1.getValue()); - } - - @Test - public void runDefaultFalse() { - Master2.setValue(true); - assertTrue(Master2.getValue()); - assertFalse(NestedOption2.getValue()); - // nested value unset - Master2.setValue(false); - assertFalse(Master2.getValue()); - assertFalse(NestedOption2.getValue()); - // set false - Master2.setValue(false); - NestedOption2.setValue(false); - assertFalse(Master2.getValue()); - assertFalse(NestedOption2.getValue()); - Master2.setValue(true); - assertTrue(Master2.getValue()); - assertFalse(NestedOption2.getValue()); - // set true - Master2.setValue(false); - NestedOption2.setValue(true); - assertFalse(Master2.getValue()); - assertTrue(NestedOption2.getValue()); - Master2.setValue(true); - assertTrue(Master2.getValue()); - assertTrue(NestedOption2.getValue()); - } - -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.options.test/src/com/oracle/jvmci/options/test/TestOptionValue.java --- a/graal/com.oracle.jvmci.options.test/src/com/oracle/jvmci/options/test/TestOptionValue.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,127 +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.options.test; - -import static com.oracle.jvmci.options.test.TestOptionValue.Options.*; -import static org.junit.Assert.*; - -import java.util.*; - -import org.junit.*; - -import com.oracle.jvmci.options.*; -import com.oracle.jvmci.options.OptionValue.OverrideScope; - -public class TestOptionValue { - - public static class Options { - public static final OptionValue Stable = new StableOptionValue<>(true); - public static final OptionValue Mutable = new OptionValue<>("original"); - public static final OptionValue SecondMutable = new OptionValue<>("second"); - } - - static final OptionDescriptor stable = new OptionDescriptor("Stable", Boolean.class, "", Options.class, "Stable", Stable); - static final OptionDescriptor mutable = new OptionDescriptor("Mutable", String.class, "", Options.class, "Mutable", Mutable); - static final OptionDescriptor secondMutable = new OptionDescriptor("SecondMutable", String.class, "", Options.class, "SecondMutable", SecondMutable); - - @Test - public void testMutable() { - assertEquals("original", Mutable.getValue()); - try (OverrideScope s1 = OptionValue.override(Mutable, "override1")) { - assertEquals("override1", Mutable.getValue()); - try (OverrideScope s2 = OptionValue.override(Mutable, "override2")) { - assertEquals("override2", Mutable.getValue()); - } - assertEquals("override1", Mutable.getValue()); - try (OverrideScope s3 = OptionValue.override(Mutable, "override3")) { - assertEquals("override3", Mutable.getValue()); - } - assertEquals("override1", Mutable.getValue()); - } - assertEquals("original", Mutable.getValue()); - try (OverrideScope s1 = OptionValue.override(Mutable, "original")) { - assertEquals("original", Mutable.getValue()); - } - } - - @Test - public void testMultiple() { - assertEquals("original", Mutable.getValue()); - assertEquals("second", SecondMutable.getValue()); - try (OverrideScope s1 = OptionValue.override(Mutable, "override1", SecondMutable, "secondOverride1")) { - assertEquals("override1", Mutable.getValue()); - assertEquals("secondOverride1", SecondMutable.getValue()); - try (OverrideScope s2 = OptionValue.override(Mutable, "override2", SecondMutable, "secondOverride2")) { - assertEquals("override2", Mutable.getValue()); - assertEquals("secondOverride2", SecondMutable.getValue()); - } - assertEquals("override1", Mutable.getValue()); - assertEquals("secondOverride1", SecondMutable.getValue()); - try (OverrideScope s3 = OptionValue.override(Mutable, "override3", SecondMutable, "secondOverride3")) { - assertEquals("override3", Mutable.getValue()); - assertEquals("secondOverride3", SecondMutable.getValue()); - } - assertEquals("override1", Mutable.getValue()); - assertEquals("secondOverride1", SecondMutable.getValue()); - } - assertEquals("original", Mutable.getValue()); - assertEquals("second", SecondMutable.getValue()); - try (OverrideScope s1 = OptionValue.override(Mutable, "original", SecondMutable, "second")) { - assertEquals("original", Mutable.getValue()); - assertEquals("second", SecondMutable.getValue()); - } - } - - @Test - public void testStable() { - assertTrue(Stable.getValue()); - try (OverrideScope s = OptionValue.override(Stable, false)) { - fail("cannot override stable option"); - } catch (IllegalArgumentException e) { - // expected - } - } - - @Test - public void toStringTest() { - assertEquals("com.oracle.jvmci.options.test.TestOptionValue$Options.Mutable=original", Mutable.toString()); - try (OverrideScope s1 = OptionValue.override(Mutable, "override1")) { - assertEquals("com.oracle.jvmci.options.test.TestOptionValue$Options.Mutable=override1", Mutable.toString()); - try (OverrideScope s2 = OptionValue.override(Mutable, "override2")) { - assertEquals("com.oracle.jvmci.options.test.TestOptionValue$Options.Mutable=override2", Mutable.toString()); - } - } - } - - @Test - public void getValuesTest() { - assertEquals(Arrays.asList("original"), Mutable.getValues(null)); - assertEquals(Arrays.asList(true), Stable.getValues(null)); - try (OverrideScope s1 = OptionValue.override(Mutable, "override1")) { - assertEquals(Arrays.asList("override1", "original"), Mutable.getValues(null)); - try (OverrideScope s2 = OptionValue.override(Mutable, "override2")) { - assertEquals(Arrays.asList("override2", "override1", "original"), Mutable.getValues(null)); - } - } - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.options/src/com/oracle/jvmci/options/DerivedOptionValue.java --- a/graal/com.oracle.jvmci.options/src/com/oracle/jvmci/options/DerivedOptionValue.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,59 +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.jvmci.options; - -import java.io.*; -import java.util.function.*; - -import com.oracle.jvmci.options.OptionValue.OverrideScope; - -/** - * A cached value that needs to be recomputed when an option changes. - */ -public class DerivedOptionValue { - - public interface OptionSupplier extends Supplier, Serializable { - } - - private final T initialValue; - private final OptionSupplier supplier; - - public DerivedOptionValue(OptionSupplier supplier) { - this.supplier = supplier; - assert OptionValue.getOverrideScope() == null : "derived option value should be initialized outside any override scope"; - this.initialValue = createValue(); - } - - public T getValue() { - OverrideScope overrideScope = OptionValue.getOverrideScope(); - if (overrideScope != null) { - return overrideScope.getDerived(this); - } else { - return initialValue; - } - } - - T createValue() { - return supplier.get(); - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.options/src/com/oracle/jvmci/options/NestedBooleanOptionValue.java --- a/graal/com.oracle.jvmci.options/src/com/oracle/jvmci/options/NestedBooleanOptionValue.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,58 +0,0 @@ -/* - * 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.jvmci.options; - -/** - * A nested Boolean {@link OptionValue} that can be overridden by a {@link #masterOption master - * option}. - *

- *

  • If the option is present on the command line the specified value is used. - *
  • Otherwise {@link #getValue()} depends on the {@link #masterOption} and evaluates as follows: - *
      - *
    • If {@link #masterOption} is set, this value equals to {@link #initialValue}. - *
    • Otherwise, if {@link #masterOption} is {@code false}, this option is {@code false}. - */ -public class NestedBooleanOptionValue extends OptionValue { - private final OptionValue masterOption; - private final Boolean initialValue; - - public NestedBooleanOptionValue(OptionValue masterOption, Boolean initialValue) { - super(null); - this.masterOption = masterOption; - this.initialValue = initialValue; - } - - public OptionValue getMasterOption() { - return masterOption; - } - - @Override - public Boolean getValue() { - Boolean v = super.getValue(); - if (v == null) { - return initialValue && masterOption.getValue(); - } - return v; - } - -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.options/src/com/oracle/jvmci/options/Option.java --- a/graal/com.oracle.jvmci.options/src/com/oracle/jvmci/options/Option.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,52 +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.options; - -import java.lang.annotation.*; - -/** - * Describes the attributes of an option whose {@link OptionValue value} is in a static field - * annotated by this annotation type. - * - * @see OptionDescriptor - */ -@Retention(RetentionPolicy.CLASS) -@Target(ElementType.FIELD) -public @interface Option { - - /** - * Gets a help message for the option. New lines can be embedded in the message with - * {@code "%n"}. - */ - String help(); - - /** - * The name of the option. By default, the name of the annotated field should be used. - */ - String name() default ""; - - /** - * Specifies the type of the option. - */ - OptionType type() default OptionType.Debug; -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.options/src/com/oracle/jvmci/options/OptionDescriptor.java --- a/graal/com.oracle.jvmci.options/src/com/oracle/jvmci/options/OptionDescriptor.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,93 +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.options; - -/** - * Describes the attributes of a static field {@linkplain Option option} and provides access to its - * {@linkplain OptionValue value}. - */ -public class OptionDescriptor { - - protected final String name; - protected final Class type; - protected final String help; - protected final OptionValue option; - protected final Class declaringClass; - protected final String fieldName; - - public OptionDescriptor(String name, Class type, String help, Class declaringClass, String fieldName, OptionValue option) { - this.name = name; - this.type = type; - this.help = help; - this.option = option; - this.declaringClass = declaringClass; - this.fieldName = fieldName; - assert !type.isPrimitive() : "must used boxed type instead of " + type; - option.setDescriptor(this); - } - - /** - * Gets the type of values stored in the option. This will be the boxed type for a primitive - * option. - */ - public Class getType() { - return type; - } - - /** - * Gets a descriptive help message for the option. - */ - public String getHelp() { - return help; - } - - /** - * Gets the name of the option. It's up to the client of this object how to use the name to get - * a user specified value for the option from the environment. - */ - public String getName() { - return name; - } - - /** - * Gets the boxed option value. - */ - public OptionValue getOptionValue() { - return option; - } - - public Class getDeclaringClass() { - return declaringClass; - } - - public String getFieldName() { - return fieldName; - } - - /** - * Gets a description of the location where this option is stored. - */ - public String getLocation() { - return getDeclaringClass().getName() + "." + getFieldName(); - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.options/src/com/oracle/jvmci/options/OptionType.java --- a/graal/com.oracle.jvmci.options/src/com/oracle/jvmci/options/OptionType.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,44 +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.jvmci.options; - -/** - * Classifies JVMCI options in several categories depending on who this option is relevant for. - * - */ -public enum OptionType { - /** - * An option common for users to apply. - */ - User, - - /** - * An option only relevant in corner cases and for fine-tuning. - */ - Expert, - - /** - * An option only relevant when debugging the compiler. - */ - Debug -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.options/src/com/oracle/jvmci/options/OptionUtils.java --- a/graal/com.oracle.jvmci.options/src/com/oracle/jvmci/options/OptionUtils.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,182 +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.jvmci.options; - -import java.util.*; - -public class OptionUtils { - - public interface OptionConsumer { - void set(OptionDescriptor desc, Object value); - } - - /** - * Parses a given option value specification. - * - * @param option the specification of an option and its value - * @param setter the object to notify of the parsed option and value. - */ - public static void parseOption(String option, OptionConsumer setter) { - SortedMap options = OptionsLoader.options; - Objects.requireNonNull(setter); - if (option.length() == 0) { - return; - } - - Object value = null; - String optionName = null; - String valueString = null; - - char first = option.charAt(0); - if (first == '+' || first == '-') { - optionName = option.substring(1); - value = (first == '+'); - } else { - int index = option.indexOf('='); - if (index == -1) { - optionName = option; - valueString = null; - } else { - optionName = option.substring(0, index); - valueString = option.substring(index + 1); - } - } - - OptionDescriptor desc = options.get(optionName); - if (desc == null) { - throw new IllegalArgumentException("Option '" + optionName + "' not found"); - } - - Class optionType = desc.getType(); - - if (value == null) { - if (optionType == Boolean.TYPE || optionType == Boolean.class) { - throw new IllegalArgumentException("Boolean option '" + optionName + "' must use +/- prefix"); - } - - if (valueString == null) { - throw new IllegalArgumentException("Missing value for non-boolean option '" + optionName + "' must use " + optionName + "= format"); - } - - if (optionType == Float.class) { - value = Float.parseFloat(valueString); - } else if (optionType == Double.class) { - value = Double.parseDouble(valueString); - } else if (optionType == Integer.class) { - value = Integer.valueOf((int) parseLong(valueString)); - } else if (optionType == Long.class) { - value = Long.valueOf(parseLong(valueString)); - } else if (optionType == String.class) { - value = valueString; - } else { - throw new IllegalArgumentException("Wrong value for option '" + optionName + "'"); - } - } else { - if (optionType != Boolean.class) { - throw new IllegalArgumentException("Non-boolean option '" + optionName + "' can not use +/- prefix. Use " + optionName + "= format"); - } - } - - setter.set(desc, value); - } - - private static long parseLong(String v) { - String valueString = v.toLowerCase(); - long scale = 1; - if (valueString.endsWith("k")) { - scale = 1024L; - } else if (valueString.endsWith("m")) { - scale = 1024L * 1024L; - } else if (valueString.endsWith("g")) { - scale = 1024L * 1024L * 1024L; - } else if (valueString.endsWith("t")) { - scale = 1024L * 1024L * 1024L * 1024L; - } - - if (scale != 1) { - /* Remove trailing scale character. */ - valueString = valueString.substring(0, valueString.length() - 1); - } - - return Long.parseLong(valueString) * scale; - } - - /** - * Wraps some given text to one or more lines of a given maximum width. - * - * @param text text to wrap - * @param width maximum width of an output line, exception for words in {@code text} longer than - * this value - * @return {@code text} broken into lines - */ - private static List wrap(String text, int width) { - List lines = Collections.singletonList(text); - if (text.length() > width) { - String[] chunks = text.split("\\s+"); - lines = new ArrayList<>(); - StringBuilder line = new StringBuilder(); - for (String chunk : chunks) { - if (line.length() + chunk.length() > width) { - lines.add(line.toString()); - line.setLength(0); - } - if (line.length() != 0) { - line.append(' '); - } - String[] embeddedLines = chunk.split("%n", -2); - if (embeddedLines.length == 1) { - line.append(chunk); - } else { - for (int i = 0; i < embeddedLines.length; i++) { - line.append(embeddedLines[i]); - if (i < embeddedLines.length - 1) { - lines.add(line.toString()); - line.setLength(0); - } - } - } - } - if (line.length() != 0) { - lines.add(line.toString()); - } - } - return lines; - } - - public static void printFlags(SortedMap options, String prefix) { - System.out.println("[List of " + prefix + " options]"); - SortedMap sortedOptions = options; - for (Map.Entry e : sortedOptions.entrySet()) { - e.getKey(); - OptionDescriptor desc = e.getValue(); - Object value = desc.getOptionValue().getValue(); - List helpLines = wrap(desc.getHelp(), 70); - System.out.println(String.format("%9s %-40s = %-14s %s", desc.getType().getSimpleName(), e.getKey(), value, helpLines.get(0))); - for (int i = 1; i < helpLines.size(); i++) { - System.out.println(String.format("%67s %s", " ", helpLines.get(i))); - } - } - - System.exit(0); - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.options/src/com/oracle/jvmci/options/OptionValue.java --- a/graal/com.oracle.jvmci.options/src/com/oracle/jvmci/options/OptionValue.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,475 +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.options; - -import java.io.*; -import java.util.*; -import java.util.Map.Entry; - -/** - * An option value. - */ -public class OptionValue { - /** - * Temporarily changes the value for an option. The {@linkplain OptionValue#getValue() value} of - * {@code option} is set to {@code value} until {@link OverrideScope#close()} is called on the - * object returned by this method. - *

      - * Since the returned object is {@link AutoCloseable} the try-with-resource construct can be - * used: - * - *

      -     * try (OverrideScope s = OptionValue.override(myOption, myValue) {
      -     *     // code that depends on myOption == myValue
      -     * }
      -     * 
      - */ - public static OverrideScope override(OptionValue option, Object value) { - OverrideScope current = getOverrideScope(); - if (current == null) { - if (!value.equals(option.getValue())) { - return new SingleOverrideScope(option, value); - } - Map, Object> overrides = Collections.emptyMap(); - return new MultipleOverridesScope(current, overrides); - } - return new MultipleOverridesScope(current, option, value); - } - - /** - * Temporarily changes the values for a set of options. The {@linkplain OptionValue#getValue() - * value} of each {@code option} in {@code overrides} is set to the corresponding {@code value} - * in {@code overrides} until {@link OverrideScope#close()} is called on the object returned by - * this method. - *

      - * Since the returned object is {@link AutoCloseable} the try-with-resource construct can be - * used: - * - *

      -     * Map<OptionValue, Object> overrides = new HashMap<>();
      -     * overrides.put(myOption1, myValue1);
      -     * overrides.put(myOption2, myValue2);
      -     * try (OverrideScope s = OptionValue.override(overrides) {
      -     *     // code that depends on myOption == myValue
      -     * }
      -     * 
      - */ - public static OverrideScope override(Map, Object> overrides) { - OverrideScope current = getOverrideScope(); - if (current == null && overrides.size() == 1) { - Entry, Object> single = overrides.entrySet().iterator().next(); - OptionValue option = single.getKey(); - Object overrideValue = single.getValue(); - if (!overrideValue.equals(option.getValue())) { - return new SingleOverrideScope(option, overrideValue); - } - } - return new MultipleOverridesScope(current, overrides); - } - - /** - * Temporarily changes the values for a set of options. The {@linkplain OptionValue#getValue() - * value} of each {@code option} in {@code overrides} is set to the corresponding {@code value} - * in {@code overrides} until {@link OverrideScope#close()} is called on the object returned by - * this method. - *

      - * Since the returned object is {@link AutoCloseable} the try-with-resource construct can be - * used: - * - *

      -     * try (OverrideScope s = OptionValue.override(myOption1, myValue1, myOption2, myValue2) {
      -     *     // code that depends on myOption == myValue
      -     * }
      -     * 
      - * - * @param overrides overrides in the form {@code [option1, override1, option2, override2, ...]} - */ - public static OverrideScope override(Object... overrides) { - OverrideScope current = getOverrideScope(); - if (current == null && overrides.length == 2) { - OptionValue option = (OptionValue) overrides[0]; - Object overrideValue = overrides[1]; - if (!overrideValue.equals(option.getValue())) { - return new SingleOverrideScope(option, overrideValue); - } - } - Map, Object> map = Collections.emptyMap(); - for (int i = 0; i < overrides.length; i += 2) { - OptionValue option = (OptionValue) overrides[i]; - Object overrideValue = overrides[i + 1]; - if (!overrideValue.equals(option.getValue())) { - if (map.isEmpty()) { - map = new HashMap<>(); - } - map.put(option, overrideValue); - } - } - return new MultipleOverridesScope(current, map); - } - - private static final ThreadLocal overrideScopeTL = new ThreadLocal<>(); - - protected static OverrideScope getOverrideScope() { - return overrideScopeTL.get(); - } - - protected static void setOverrideScope(OverrideScope overrideScope) { - overrideScopeTL.set(overrideScope); - } - - private T defaultValue; - - /** - * The raw option value. - */ - protected T value; - - private OptionDescriptor descriptor; - - private long reads; - private OptionValue next; - private static OptionValue head; - - private static final boolean ShowReadsHistogram = Boolean.getBoolean("jvmci.showOptionValueReadsHistogram"); - - private static void addToHistogram(OptionValue option) { - if (ShowReadsHistogram) { - synchronized (OptionValue.class) { - option.next = head; - head = option; - } - } - } - - @SuppressWarnings("unchecked") - public OptionValue(T value) { - this.defaultValue = value; - this.value = (T) DEFAULT; - addToHistogram(this); - } - - private static final Object DEFAULT = "DEFAULT"; - private static final Object UNINITIALIZED = "UNINITIALIZED"; - - /** - * Creates an uninitialized option value for a subclass that initializes itself - * {@link #defaultValue() lazily}. - */ - @SuppressWarnings("unchecked") - protected OptionValue() { - this.defaultValue = (T) UNINITIALIZED; - this.value = (T) DEFAULT; - addToHistogram(this); - } - - /** - * Lazy initialization of default value. - */ - protected T defaultValue() { - throw new InternalError("Option without a default value value must override defaultValue()"); - } - - /** - * Sets the descriptor for this option. - */ - public void setDescriptor(OptionDescriptor descriptor) { - this.descriptor = descriptor; - } - - /** - * Returns the descriptor for this option, if it has been set by - * {@link #setDescriptor(OptionDescriptor)}. - */ - public OptionDescriptor getDescriptor() { - return descriptor; - } - - /** - * Gets the name of this option. The name for an option value with a null - * {@linkplain #setDescriptor(OptionDescriptor) descriptor} is the value of - * {@link Object#toString()}. - */ - public String getName() { - return descriptor == null ? super.toString() : (descriptor.getDeclaringClass().getName() + "." + descriptor.getName()); - } - - @Override - public String toString() { - return getName() + "=" + getValue(); - } - - /** - * The initial value specified in source code. The returned value is not affected by calls to - * {@link #setValue(Object)} or registering {@link OverrideScope}s. Therefore, it is also not - * affected by options set on the command line. - */ - public T getDefaultValue() { - if (defaultValue == UNINITIALIZED) { - defaultValue = defaultValue(); - } - return defaultValue; - } - - /** - * Returns true if the option has the same value that was set in the source code. - */ - public boolean hasDefaultValue() { - getValue(); // ensure initialized - return value == DEFAULT || Objects.equals(value, getDefaultValue()); - } - - /** - * Gets the value of this option. - */ - public T getValue() { - if (ShowReadsHistogram) { - reads++; - } - if (!(this instanceof StableOptionValue)) { - OverrideScope overrideScope = getOverrideScope(); - if (overrideScope != null) { - T override = overrideScope.getOverride(this); - if (override != null) { - return override; - } - } - } - if (value != DEFAULT) { - return value; - } else { - return getDefaultValue(); - } - } - - /** - * Gets the values of this option including overridden values. - * - * @param c the collection to which the values are added. If null, one is allocated. - * @return the collection to which the values were added in order from most overridden to - * current value - */ - @SuppressWarnings("unchecked") - public Collection getValues(Collection c) { - Collection values = c == null ? new ArrayList<>() : c; - if (!(this instanceof StableOptionValue)) { - OverrideScope overrideScope = getOverrideScope(); - if (overrideScope != null) { - overrideScope.getOverrides(this, (Collection) values); - } - } - if (value != DEFAULT) { - values.add(value); - } else { - values.add(getDefaultValue()); - } - return values; - } - - /** - * Sets the value of this option. - */ - @SuppressWarnings("unchecked") - public void setValue(Object v) { - this.value = (T) v; - } - - /** - * An object whose {@link #close()} method reverts the option value overriding initiated by - * {@link OptionValue#override(OptionValue, Object)} or {@link OptionValue#override(Map)}. - */ - public abstract static class OverrideScope implements AutoCloseable { - - private Map, Object> derivedCache = null; - - public T getDerived(DerivedOptionValue key) { - if (derivedCache == null) { - derivedCache = new HashMap<>(); - } - @SuppressWarnings("unchecked") - T ret = (T) derivedCache.get(key); - if (ret == null) { - ret = key.createValue(); - derivedCache.put(key, ret); - } - return ret; - } - - abstract void addToInherited(Map, Object> inherited); - - abstract T getOverride(OptionValue option); - - abstract void getOverrides(OptionValue option, Collection c); - - public abstract void close(); - } - - static class SingleOverrideScope extends OverrideScope { - - private final OptionValue option; - private final Object value; - - public SingleOverrideScope(OptionValue option, Object value) { - if (option instanceof StableOptionValue) { - throw new IllegalArgumentException("Cannot override stable option " + option); - } - this.option = option; - this.value = value; - setOverrideScope(this); - } - - @Override - void addToInherited(Map, Object> inherited) { - inherited.put(option, value); - } - - @SuppressWarnings("unchecked") - @Override - T getOverride(OptionValue key) { - if (key == this.option) { - return (T) value; - } - return null; - } - - @Override - void getOverrides(OptionValue key, Collection c) { - if (key == this.option) { - c.add(value); - } - } - - @Override - public void close() { - setOverrideScope(null); - } - } - - static class MultipleOverridesScope extends OverrideScope { - final OverrideScope parent; - final Map, Object> overrides; - - public MultipleOverridesScope(OverrideScope parent, OptionValue option, Object value) { - this.parent = parent; - this.overrides = new HashMap<>(); - if (parent != null) { - parent.addToInherited(overrides); - } - if (option instanceof StableOptionValue) { - throw new IllegalArgumentException("Cannot override stable option " + option); - } - if (!value.equals(option.getValue())) { - this.overrides.put(option, value); - } - if (!overrides.isEmpty()) { - setOverrideScope(this); - } - } - - MultipleOverridesScope(OverrideScope parent, Map, Object> overrides) { - this.parent = parent; - if (overrides.isEmpty() && parent == null) { - this.overrides = Collections.emptyMap(); - return; - } - this.overrides = new HashMap<>(); - if (parent != null) { - parent.addToInherited(this.overrides); - } - for (Map.Entry, Object> e : overrides.entrySet()) { - OptionValue option = e.getKey(); - if (option instanceof StableOptionValue) { - throw new IllegalArgumentException("Cannot override stable option " + option); - } - if (!e.getValue().equals(option.getValue())) { - this.overrides.put(option, e.getValue()); - } - } - if (!this.overrides.isEmpty()) { - setOverrideScope(this); - } - } - - @Override - void addToInherited(Map, Object> inherited) { - if (parent != null) { - parent.addToInherited(inherited); - } - inherited.putAll(overrides); - } - - @SuppressWarnings("unchecked") - @Override - T getOverride(OptionValue option) { - return (T) overrides.get(option); - } - - @Override - void getOverrides(OptionValue option, Collection c) { - Object v = overrides.get(option); - if (v != null) { - c.add(v); - } - if (parent != null) { - parent.getOverrides(option, c); - } - } - - @Override - public void close() { - if (!overrides.isEmpty()) { - setOverrideScope(parent); - } - } - } - - static { - if (ShowReadsHistogram) { - Runtime.getRuntime().addShutdownHook(new Thread() { - @Override - public void run() { - ArrayList> options = new ArrayList<>(); - for (OptionValue option = head; option != null; option = option.next) { - options.add(option); - } - Collections.sort(options, new Comparator>() { - - public int compare(OptionValue o1, OptionValue o2) { - if (o1.reads < o2.reads) { - return -1; - } else if (o1.reads > o2.reads) { - return 1; - } else { - return o1.getName().compareTo(o2.getName()); - } - } - }); - PrintStream out = System.out; - out.println("=== OptionValue reads histogram ==="); - for (OptionValue option : options) { - out.println(option.reads + "\t" + option); - } - } - }); - } - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.options/src/com/oracle/jvmci/options/Options.java --- a/graal/com.oracle.jvmci.options/src/com/oracle/jvmci/options/Options.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,31 +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.options; - -import java.util.*; - -/** - * A {@linkplain ServiceLoader service} for accessing a set of {@link OptionDescriptor}s. - */ -public interface Options extends Iterable { -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.options/src/com/oracle/jvmci/options/OptionsLoader.java --- a/graal/com.oracle.jvmci.options/src/com/oracle/jvmci/options/OptionsLoader.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,45 +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.jvmci.options; - -import java.util.*; - -/** - * Helper class used to load option descriptors. Only to be used in the slow-path. - */ -public class OptionsLoader { - public static final SortedMap options = new TreeMap<>(); - - /** - * Initializes {@link #options} from {@link Options} services. - */ - static { - for (Options opts : ServiceLoader.load(Options.class, OptionsLoader.class.getClassLoader())) { - for (OptionDescriptor desc : opts) { - String name = desc.getName(); - OptionDescriptor existing = options.put(name, desc); - assert existing == null : "Option named \"" + name + "\" has multiple definitions: " + existing.getLocation() + " and " + desc.getLocation(); - } - } - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.options/src/com/oracle/jvmci/options/StableOptionValue.java --- a/graal/com.oracle.jvmci.options/src/com/oracle/jvmci/options/StableOptionValue.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,75 +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.options; - -/** - * An option that always returns the same {@linkplain #getValue() value}. - */ -public class StableOptionValue extends OptionValue { - - /** - * Creates a stable option value. - */ - public StableOptionValue(T value) { - super(value); - } - - /** - * Used to assert the invariant for stability. Without using locks, this check is not safe - * against races and so it's only an assertion. - */ - private boolean getValueCalled; - - /** - * Creates an uninitialized stable option value for a subclass that initializes itself - * {@link #defaultValue() lazily}. - */ - public StableOptionValue() { - } - - /** - * Gets the value of this option. - */ - @Override - public final T getValue() { - T result = super.getValue(); - assert initGetValueCalled(); - return result; - } - - private boolean initGetValueCalled() { - getValueCalled = true; - return true; - } - - /** - * {@inheritDoc} - *

      - * This must only be called if {@link #getValue()} has never been called. - */ - @Override - public final void setValue(Object v) { - assert !getValueCalled; - super.setValue(v); - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/ConstantTest.java --- a/graal/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/ConstantTest.java Mon Jun 08 23:40:08 2015 +0200 +++ /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.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 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/FieldUniverse.java --- a/graal/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/FieldUniverse.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,45 +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.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 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/MethodUniverse.java --- a/graal/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/MethodUniverse.java Mon Jun 08 23:40:08 2015 +0200 +++ /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.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 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/NameAndSignature.java --- a/graal/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/NameAndSignature.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,87 +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.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 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/ResolvedJavaTypeResolveConcreteMethodTest.java --- a/graal/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/ResolvedJavaTypeResolveConcreteMethodTest.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,170 +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.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 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/ResolvedJavaTypeResolveMethodTest.java --- a/graal/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/ResolvedJavaTypeResolveMethodTest.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,170 +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.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 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/TestConstantReflectionProvider.java --- a/graal/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/TestConstantReflectionProvider.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,125 +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.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 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/TestJavaField.java --- a/graal/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/TestJavaField.java Mon Jun 08 23:40:08 2015 +0200 +++ /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.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 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/TestJavaMethod.java --- a/graal/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/TestJavaMethod.java Mon Jun 08 23:40:08 2015 +0200 +++ /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.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 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/TestJavaType.java --- a/graal/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/TestJavaType.java Mon Jun 08 23:40:08 2015 +0200 +++ /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.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 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/TestMetaAccessProvider.java --- a/graal/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/TestMetaAccessProvider.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,94 +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.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 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/TestResolvedJavaField.java --- a/graal/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/TestResolvedJavaField.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,145 +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.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 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/TestResolvedJavaMethod.java --- a/graal/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/TestResolvedJavaMethod.java Mon Jun 08 23:40:08 2015 +0200 +++ /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.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 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/TestResolvedJavaType.java --- a/graal/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/TestResolvedJavaType.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,874 +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.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 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/TypeUniverse.java --- a/graal/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/TypeUniverse.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,205 +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.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 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.runtime/src/com/oracle/jvmci/runtime/JVMCI.java --- a/graal/com.oracle.jvmci.runtime/src/com/oracle/jvmci/runtime/JVMCI.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,59 +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.jvmci.runtime; - -import java.util.*; - -public class JVMCI { - - private static final JVMCIRuntime runtime; - - private static native JVMCIRuntime initializeRuntime(); - - /** - * Gets the singleton {@link JVMCIRuntime} instance available to the application. - * - * @throws UnsupportedOperationException if JVMCI is not supported - */ - public static JVMCIRuntime getRuntime() { - if (runtime == null) { - String javaHome = System.getProperty("java.home"); - String vmName = System.getProperty("java.vm.name"); - Formatter errorMessage = new Formatter(); - errorMessage.format("The VM does not support the JVMCI API.%n"); - errorMessage.format("Currently used Java home directory is %s.%n", javaHome); - errorMessage.format("Currently used VM configuration is: %s", vmName); - throw new UnsupportedOperationException(errorMessage.toString()); - } - return runtime; - } - - static { - JVMCIRuntime rt = null; - try { - rt = initializeRuntime(); - } catch (UnsatisfiedLinkError e) { - } - runtime = rt; - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.runtime/src/com/oracle/jvmci/runtime/JVMCIBackend.java --- a/graal/com.oracle.jvmci.runtime/src/com/oracle/jvmci/runtime/JVMCIBackend.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,62 +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.jvmci.runtime; - -import com.oracle.jvmci.code.CodeCacheProvider; -import com.oracle.jvmci.code.TargetDescription; -import com.oracle.jvmci.meta.MetaAccessProvider; -import com.oracle.jvmci.meta.ConstantReflectionProvider; - -/** - * A JVMCI backend encapsulates the capabilities needed by a Java based compiler for compiling and - * installing code for a single compute unit within a JVM. In a JVM with support for heterogeneous - * computing, more than one backend may be exposed. - */ -public class JVMCIBackend { - - private final MetaAccessProvider metaAccess; - private final CodeCacheProvider codeCache; - private final ConstantReflectionProvider constantReflection; - - public JVMCIBackend(MetaAccessProvider metaAccess, CodeCacheProvider codeCache, ConstantReflectionProvider constantReflection) { - this.metaAccess = metaAccess; - this.codeCache = codeCache; - this.constantReflection = constantReflection; - } - - public MetaAccessProvider getMetaAccess() { - return metaAccess; - } - - public CodeCacheProvider getCodeCache() { - return codeCache; - } - - public ConstantReflectionProvider getConstantReflection() { - return constantReflection; - } - - public TargetDescription getTarget() { - return codeCache.getTarget(); - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.runtime/src/com/oracle/jvmci/runtime/JVMCIRuntime.java --- a/graal/com.oracle.jvmci.runtime/src/com/oracle/jvmci/runtime/JVMCIRuntime.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,43 +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.jvmci.runtime; - -import com.oracle.jvmci.code.Architecture; - -/** - * Interface for accessing the {@link JVMCI} APIs supported by the runtime. - */ -public interface JVMCIRuntime { - - /** - * Gets the host JVMCI backend. - */ - JVMCIBackend getHostJVMCIBackend(); - - /** - * Gets the backend for a given architecture. - * - * @param arch a specific architecture class - */ - JVMCIBackend getJVMCIBackend(Class arch); -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.service.processor/src/META-INF/services/javax.annotation.processing.Processor --- a/graal/com.oracle.jvmci.service.processor/src/META-INF/services/javax.annotation.processing.Processor Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -com.oracle.jvmci.service.processor.ServiceProviderProcessor diff -r 42452d2dfbec -r 395ac43a8578 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 Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,119 +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.service.processor; - -import java.io.*; -import java.util.*; - -import javax.annotation.processing.*; -import javax.lang.model.*; -import javax.lang.model.element.*; -import javax.lang.model.type.*; -import javax.tools.Diagnostic.Kind; -import javax.tools.*; - -import com.oracle.jvmci.service.*; - -@SupportedAnnotationTypes("com.oracle.jvmci.service.ServiceProvider") -public class ServiceProviderProcessor extends AbstractProcessor { - - private final Set processed = new HashSet<>(); - private TypeElement baseJVMCIServiceInterface; - - @Override - public SourceVersion getSupportedSourceVersion() { - return SourceVersion.latest(); - } - - 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); - return false; - } - - return true; - } - - private void processElement(TypeElement serviceProvider) { - if (processed.contains(serviceProvider)) { - return; - } - - processed.add(serviceProvider); - ServiceProvider annotation = serviceProvider.getAnnotation(ServiceProvider.class); - if (annotation != null) { - try { - annotation.value(); - } catch (MirroredTypeException ex) { - TypeMirror serviceInterface = ex.getTypeMirror(); - if (verifyAnnotation(serviceInterface, serviceProvider)) { - String interfaceName = ex.getTypeMirror().toString(); - createProviderFile(serviceProvider, interfaceName); - } - } - } - } - - private void createProviderFile(TypeElement serviceProvider, String interfaceName) { - if (serviceProvider.getNestingKind().isNested()) { - // This is a simplifying constraint that means we don't have to - // processed the qualified name to insert '$' characters at - // the relevant positions. - String msg = String.format("Service provider class %s must be a top level class", serviceProvider.getSimpleName()); - processingEnv.getMessager().printMessage(Kind.ERROR, msg, serviceProvider); - return; - } - - String filename = "META-INF/providers/" + serviceProvider.getQualifiedName(); - try { - FileObject file = processingEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT, "", filename, serviceProvider); - PrintWriter writer = new PrintWriter(new OutputStreamWriter(file.openOutputStream(), "UTF-8")); - writer.println(interfaceName); - writer.close(); - } catch (IOException e) { - processingEnv.getMessager().printMessage(Kind.ERROR, e.getMessage(), serviceProvider); - } - } - - @Override - public boolean process(Set annotations, RoundEnvironment roundEnv) { - if (roundEnv.processingOver()) { - 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); - } - - return true; - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.service/src/com/oracle/jvmci/service/JVMCIClassLoaderFactory.java --- a/graal/com.oracle.jvmci.service/src/com/oracle/jvmci/service/JVMCIClassLoaderFactory.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,87 +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.jvmci.service; - -import java.io.*; -import java.net.*; -import java.util.*; - -/** - * Utility called from the VM to create and register a separate class loader for loading JVMCI - * classes (i.e., those in found in lib/jvmci/*.jar). - */ -class JVMCIClassLoaderFactory { - - /** - * Copy of the {@code UseJVMCIClassLoader} VM option. Set by the VM before the static - * initializer is called. - */ - private static boolean useJVMCIClassLoader; - - /** - * Registers the JVMCI class loader in the VM. - */ - private static native void init(ClassLoader loader); - - static { - init(useJVMCIClassLoader ? newClassLoader() : null); - } - - /** - * Creates a new class loader for loading JVMCI classes. - */ - private static ClassLoader newClassLoader() { - URL[] urls = getJVMCIJarsUrls(); - ClassLoader parent = null; - return URLClassLoader.newInstance(urls, parent); - } - - /** - * Gets the URLs for lib/jvmci/*.jar. - */ - private static URL[] getJVMCIJarsUrls() { - File javaHome = new File(System.getProperty("java.home")); - File lib = new File(javaHome, "lib"); - File jvmci = new File(lib, "jvmci"); - if (!jvmci.exists()) { - throw new InternalError(jvmci + " does not exist"); - } - - List urls = new ArrayList<>(); - for (String fileName : jvmci.list()) { - if (fileName.endsWith(".jar")) { - File file = new File(jvmci, fileName); - if (file.isDirectory()) { - continue; - } - try { - urls.add(file.toURI().toURL()); - } catch (MalformedURLException e) { - throw new InternalError(e); - } - } - } - - return urls.toArray(new URL[urls.size()]); - } -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.service/src/com/oracle/jvmci/service/Service.java --- a/graal/com.oracle.jvmci.service/src/com/oracle/jvmci/service/Service.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,39 +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.service; - -import java.util.*; - -/** - * Denotes a JVMCI service that can be loaded by {@link Services#load(Class)} or - * {@link Services#loadSingle(Class, boolean)}. JVMCI services differ from - * {@linkplain ServiceLoader#load(Class) standard} services in that they may have implementations - * hidden behind a class loader not accessible to applications. For this reason, - * {@link Services#load(Class)} and {@link Services#loadSingle(Class, boolean)} perform - * {@link SecurityManager} checks. - * - * @see Services - * @see ServiceProvider - */ -public interface Service { -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.service/src/com/oracle/jvmci/service/ServiceProvider.java --- a/graal/com.oracle.jvmci.service/src/com/oracle/jvmci/service/ServiceProvider.java Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,37 +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.service; - -import java.lang.annotation.*; - -/** - * Annotates a class that implements a {@linkplain Service JVMCI service}. This annotation is used - * by the JVMCI build system to deploy the necessary files used to {@linkplain Services#load(Class) - * load} JVMCI services at runtime. - */ -@Retention(RetentionPolicy.CLASS) -@Target(ElementType.TYPE) -public @interface ServiceProvider { - - Class value(); -} diff -r 42452d2dfbec -r 395ac43a8578 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 Mon Jun 08 23:40:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,123 +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.jvmci.service; - -import java.util.*; - -import sun.reflect.*; - -/** - * An mechanism for loading {@linkplain Service JVMCI services}. - */ -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) { - try { - return Arrays.asList(getServiceImpls(type)); - } catch (NoClassDefFoundError e) { - if (SuppressNoClassDefFoundError) { - return Collections.emptyList(); - } - throw e; - } - } - }; - - /** - * Gets an {@link Iterable} of the implementations available for a given JVMCI service. - * - * @throws SecurityException if a security manager is present and it denies - * {@link RuntimePermission}("jvmciServices") - */ - @SuppressWarnings("unchecked") - @CallerSensitive - public static Iterable load(Class service) { - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - sm.checkPermission(new RuntimePermission("jvmciServices")); - } - try { - return (Iterable) cache.get(service); - } catch (UnsatisfiedLinkError e) { - return Collections.emptyList(); - } - } - - /** - * Gets the implementation for a given service for which at most one implementation must be - * available. - * - * @param service the service whose implementation is being requested - * @param required specifies if an {@link InternalError} should be thrown if no implementation - * of {@code service} is available - * @throws SecurityException if a security manager is present and it denies - * {@link RuntimePermission}("jvmciServices") - */ - @SuppressWarnings("unchecked") - @CallerSensitive - public static S loadSingle(Class service, boolean required) { - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - sm.checkPermission(new RuntimePermission("jvmciServices")); - } - Iterable impls; - try { - impls = (Iterable) cache.get(service); - } catch (UnsatisfiedLinkError e) { - impls = Collections.emptyList(); - } - - S singleImpl = null; - for (S impl : impls) { - if (singleImpl != null) { - throw new InternalError(String.format("Multiple %s implementations found: %s, %s", service.getName(), singleImpl.getClass().getName(), impl.getClass().getName())); - } - singleImpl = impl; - } - if (singleImpl == null && required) { - String javaHome = System.getProperty("java.home"); - String vmName = System.getProperty("java.vm.name"); - Formatter errorMessage = new Formatter(); - errorMessage.format("The VM does not expose required service %s.%n", service.getName()); - errorMessage.format("Currently used Java home directory is %s.%n", javaHome); - errorMessage.format("Currently used VM configuration is: %s", vmName); - throw new UnsupportedOperationException(errorMessage.toString()); - } - return singleImpl; - } - - static { - Reflection.registerMethodsToFilter(Services.class, "getServiceImpls"); - Reflection.registerFieldsToFilter(Services.class, "cache"); - } - - private static native S[] getServiceImpls(Class service); -} diff -r 42452d2dfbec -r 395ac43a8578 graal/com.oracle.jvmci.sparc/src/com/oracle/jvmci/sparc/SPARC.java --- a/graal/com.oracle.jvmci.sparc/src/com/oracle/jvmci/sparc/SPARC.java Mon Jun 08 23:40:08 2015 +0200 +++ /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.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 42452d2dfbec -r 395ac43a8578 graal/findbugs-SuppressFBWarnings.jar Binary file graal/findbugs-SuppressFBWarnings.jar has changed diff -r 42452d2dfbec -r 395ac43a8578 hotspot/.project --- a/hotspot/.project Mon Jun 08 23:40:08 2015 +0200 +++ b/hotspot/.project Tue Jun 09 00:22:49 2015 +0200 @@ -113,7 +113,7 @@ generated_java_processor 2 - PARENT-1-PROJECT_LOC/graal/com.oracle.jvmci.hotspot/src_gen/hotspot + PARENT-1-PROJECT_LOC/jvmci/com.oracle.jvmci.hotspot/src_gen/hotspot linux diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.amd64/src/com/oracle/jvmci/amd64/AMD64.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.amd64/src/com/oracle/jvmci/amd64/AMD64.java Tue Jun 09 00:22:49 2015 +0200 @@ -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 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.code/overview.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.code/overview.html Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,37 @@ + + + + + + + + +The com.oracle.jvmci.code project provides an API to the runtime's native code cache. +It allows installation and execution of native code. + + + diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.code/src/com/oracle/jvmci/code/AbstractAddress.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.code/src/com/oracle/jvmci/code/AbstractAddress.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,29 @@ +/* + * 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; + +/** + * Abstract base class that represents a platform specific address. + */ +public abstract class AbstractAddress { +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.code/src/com/oracle/jvmci/code/Architecture.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.code/src/com/oracle/jvmci/code/Architecture.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,250 @@ +/* + * 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.code; + +import com.oracle.jvmci.meta.Kind; +import com.oracle.jvmci.meta.PlatformKind; +import java.nio.*; +import java.util.*; + +import com.oracle.jvmci.code.Register.RegisterCategory; + +/** + * Represents a CPU architecture, including information such as its endianness, CPU registers, word + * width, etc. + */ +public abstract class Architecture { + + /** + * The number of entries required in a {@link ReferenceMap} covering all the registers that may + * store references. The index of a register in the reference map is given by + * {@link Register#getReferenceMapIndex()}. + */ + private final int registerReferenceMapSize; + + /** + * Represents the natural size of words (typically registers and pointers) of this architecture, + * in bytes. + */ + private final int wordSize; + + /** + * The name of this architecture (e.g. "AMD64", "SPARCv9"). + */ + private final String name; + + /** + * Array of all available registers on this architecture. The index of each register in this + * array is equal to its {@linkplain Register#number number}. + */ + private final Register[] registers; + + /** + * The byte ordering can be either little or big endian. + */ + private final ByteOrder byteOrder; + + /** + * Whether the architecture supports unaligned memory accesses. + */ + private final boolean unalignedMemoryAccess; + + /** + * Mask of the barrier constants denoting the barriers that are not required to be explicitly + * inserted under this architecture. + */ + private final int implicitMemoryBarriers; + + /** + * Offset in bytes from the beginning of a call instruction to the displacement. + */ + private final int machineCodeCallDisplacementOffset; + + /** + * The size of the return address pushed to the stack by a call instruction. A value of 0 + * denotes that call linkage uses registers instead (e.g. SPARC). + */ + private final int returnAddressSize; + + protected Architecture(String name, int wordSize, ByteOrder byteOrder, boolean unalignedMemoryAccess, Register[] registers, int implicitMemoryBarriers, int nativeCallDisplacementOffset, + int registerReferenceMapSize, int returnAddressSize) { + this.name = name; + this.registers = registers; + this.wordSize = wordSize; + this.byteOrder = byteOrder; + this.unalignedMemoryAccess = unalignedMemoryAccess; + this.implicitMemoryBarriers = implicitMemoryBarriers; + this.machineCodeCallDisplacementOffset = nativeCallDisplacementOffset; + this.registerReferenceMapSize = registerReferenceMapSize; + this.returnAddressSize = returnAddressSize; + } + + /** + * Converts this architecture to a string. + * + * @return the string representation of this architecture + */ + @Override + public final String toString() { + return getName().toLowerCase(); + } + + public int getRegisterReferenceMapSize() { + return registerReferenceMapSize; + } + + /** + * Gets the natural size of words (typically registers and pointers) of this architecture, in + * bytes. + */ + public int getWordSize() { + return wordSize; + } + + /** + * Gets the name of this architecture. + */ + public String getName() { + return name; + } + + /** + * Gets an array of all available registers on this architecture. The index of each register in + * this array is equal to its {@linkplain Register#number number}. + */ + public Register[] getRegisters() { + return registers.clone(); + } + + public ByteOrder getByteOrder() { + return byteOrder; + } + + /** + * @return true if the architecture supports unaligned memory accesses. + */ + public boolean supportsUnalignedMemoryAccess() { + return unalignedMemoryAccess; + } + + /** + * Gets the size of the return address pushed to the stack by a call instruction. A value of 0 + * denotes that call linkage uses registers instead. + */ + public int getReturnAddressSize() { + return returnAddressSize; + } + + /** + * Gets the offset in bytes from the beginning of a call instruction to the displacement. + */ + public int getMachineCodeCallDisplacementOffset() { + return machineCodeCallDisplacementOffset; + } + + /** + * Determines the barriers in a given barrier mask that are explicitly required on this + * architecture. + * + * @param barriers a mask of the barrier constants + * @return the value of {@code barriers} minus the barriers unnecessary on this architecture + */ + public final int requiredBarriers(int barriers) { + return barriers & ~implicitMemoryBarriers; + } + + /** + * Gets the size in bytes of the specified kind for this target. + * + * @param kind the kind for which to get the size + * + * @return the size in bytes of {@code kind} + */ + public int getSizeInBytes(PlatformKind kind) { + switch ((Kind) kind) { + case Boolean: + return 1; + case Byte: + return 1; + case Char: + return 2; + case Short: + return 2; + case Int: + return 4; + case Long: + return 8; + case Float: + return 4; + case Double: + return 8; + case Object: + return wordSize; + default: + return 0; + } + } + + /** + * Determine whether a kind can be stored in a register of a given category. + * + * @param category the category of the register + * @param kind the kind that should be stored in the register + */ + public abstract boolean canStoreValue(RegisterCategory category, PlatformKind kind); + + /** + * Return the largest kind that can be stored in a register of a given category. + * + * @param category the category of the register + * @return the largest kind that can be stored in a register {@code category} + */ + public abstract PlatformKind getLargestStorableKind(RegisterCategory category); + + @Override + public final boolean equals(Object obj) { + if (obj == this) { + return true; + } + if (obj instanceof Architecture) { + Architecture that = (Architecture) obj; + if (this.name.equals(that.name)) { + assert this.byteOrder.equals(that.byteOrder); + assert this.implicitMemoryBarriers == that.implicitMemoryBarriers; + assert this.machineCodeCallDisplacementOffset == that.machineCodeCallDisplacementOffset; + assert this.registerReferenceMapSize == that.registerReferenceMapSize; + assert Arrays.equals(this.registers, that.registers); + assert this.returnAddressSize == that.returnAddressSize; + assert this.unalignedMemoryAccess == that.unalignedMemoryAccess; + assert this.wordSize == that.wordSize; + return true; + } + } + return false; + } + + @Override + public final int hashCode() { + return name.hashCode(); + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.code/src/com/oracle/jvmci/code/ArithmeticOperation.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.code/src/com/oracle/jvmci/code/ArithmeticOperation.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,30 @@ +/* + * 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.code; + +/** + * An {@code ArithmeticOperation} is an operation that does primitive value arithmetic without side + * effect. + */ +public interface ArithmeticOperation { +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.code/src/com/oracle/jvmci/code/BailoutException.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.code/src/com/oracle/jvmci/code/BailoutException.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,76 @@ +/* + * 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.code; + +import java.util.*; + +/** + * Exception thrown when the compiler refuses to compile a method because of problems with the + * method. e.g. bytecode wouldn't verify, too big, JSR/ret too complicated, etc. This exception is + * not meant to indicate problems with the compiler itself. + */ +public class BailoutException extends RuntimeException { + + public static final long serialVersionUID = 8974598793458772L; + private final boolean permanent; + + /** + * Creates a new {@link BailoutException}. + * + * + * @param args parameters to the formatter + */ + public BailoutException(String format, Object... args) { + super(String.format(Locale.ENGLISH, format, args)); + this.permanent = true; + } + + /** + * Creates a new {@link BailoutException}. + * + * + * @param args parameters to the formatter + */ + public BailoutException(Throwable cause, String format, Object... args) { + super(String.format(Locale.ENGLISH, format, args), cause); + this.permanent = true; + } + + /** + * Creates a new {@link BailoutException}. + * + * @param permanent specifies whether this exception will occur again if compilation is retried + * @param args parameters to the formatter + */ + public BailoutException(boolean permanent, String format, Object... args) { + super(String.format(Locale.ENGLISH, format, args)); + this.permanent = permanent; + } + + /** + * @return whether this exception will occur again if compilation is retried + */ + public boolean isPermanent() { + return permanent; + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.code/src/com/oracle/jvmci/code/BytecodeFrame.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.code/src/com/oracle/jvmci/code/BytecodeFrame.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,272 @@ +/* + * Copyright (c) 2009, 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.code; + +import com.oracle.jvmci.meta.Kind; +import com.oracle.jvmci.meta.ResolvedJavaMethod; +import com.oracle.jvmci.meta.Value; +import java.util.*; + +/** + * Represents the Java bytecode frame state(s) at a given position including {@link Value locations} + * where to find the local variables, operand stack values and locked objects of the bytecode + * frame(s). + */ +public class BytecodeFrame extends BytecodePosition { + + /** + * An array of values representing how to reconstruct the state of the Java frame. This is array + * is partitioned as follows: + *

      + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
      Start index (inclusive)End index (exclusive)Description
      0numLocalsLocal variables
      numLocalsnumLocals + numStackOperand stack
      numLocals + numStackvalues.lengthLocked objects
      + *

      + * Note that the number of locals and the number of stack slots may be smaller than the maximum + * number of locals and stack slots as specified in the compiled method. + */ + public final Value[] values; + + /** + * The number of locals in the values array. + */ + public final int numLocals; + + /** + * The number of stack slots in the values array. + */ + public final int numStack; + + /** + * The number of locks in the values array. + */ + public final int numLocks; + + /** + * True if this is a position inside an exception handler before the exception object has been + * consumed. In this case, {@link #numStack} {@code == 1} and {@link #getStackValue(int) + * getStackValue(0)} is the location of the exception object. If deoptimization happens at this + * position, the interpreter will rethrow the exception instead of executing the bytecode + * instruction at this position. + */ + public final boolean rethrowException; + + public final boolean duringCall; + + /** + * This BCI should be used for frame states that are built for code with no meaningful BCI. + */ + public static final int UNKNOWN_BCI = -5; + + /** + * The BCI for exception unwind. This is synthetic code and has no representation in bytecode. + * In contrast with {@link #AFTER_EXCEPTION_BCI}, at this point, if the method is synchronized, + * the monitor is still held. + */ + public static final int UNWIND_BCI = -1; + + /** + * The BCI for the state before starting to execute a method. Note that if the method is + * synchronized, the monitor is not yet held. + */ + public static final int BEFORE_BCI = -2; + + /** + * The BCI for the state after finishing the execution of a method and returning normally. Note + * that if the method was synchronized the monitor is already released. + */ + public static final int AFTER_BCI = -3; + + /** + * The BCI for exception unwind. This is synthetic code and has no representation in bytecode. + * In contrast with {@link #UNWIND_BCI}, at this point, if the method is synchronized, the + * monitor is already released. + */ + public static final int AFTER_EXCEPTION_BCI = -4; + + /** + * This BCI should be used for states that cannot be the target of a deoptimization, like + * snippet frame states. + */ + public static final int INVALID_FRAMESTATE_BCI = -6; + + /** + * Determines if a given BCI matches one of the placeholder BCI constants defined in this class. + */ + public static boolean isPlaceholderBci(int bci) { + return bci < 0; + } + + /** + * Gets the name of a given placeholder BCI. + */ + public static String getPlaceholderBciName(int bci) { + assert isPlaceholderBci(bci); + if (bci == BytecodeFrame.AFTER_BCI) { + return "AFTER_BCI"; + } else if (bci == BytecodeFrame.AFTER_EXCEPTION_BCI) { + return "AFTER_EXCEPTION_BCI"; + } else if (bci == BytecodeFrame.INVALID_FRAMESTATE_BCI) { + return "INVALID_FRAMESTATE_BCI"; + } else if (bci == BytecodeFrame.BEFORE_BCI) { + return "BEFORE_BCI"; + } else if (bci == BytecodeFrame.UNKNOWN_BCI) { + return "UNKNOWN_BCI"; + } else { + assert bci == BytecodeFrame.UNWIND_BCI; + return "UNWIND_BCI"; + } + } + + /** + * Creates a new frame object. + * + * @param caller the caller frame (which may be {@code null}) + * @param method the method + * @param bci a BCI within the method + * @param rethrowException specifies if the VM should re-throw the pending exception when + * deopt'ing using this frame + * @param values the frame state {@link #values} + * @param numLocals the number of local variables + * @param numStack the depth of the stack + * @param numLocks the number of locked objects + */ + public BytecodeFrame(BytecodeFrame caller, ResolvedJavaMethod method, int bci, boolean rethrowException, boolean duringCall, Value[] values, int numLocals, int numStack, int numLocks) { + super(caller, method, bci); + assert values != null; + this.rethrowException = rethrowException; + this.duringCall = duringCall; + this.values = values; + this.numLocals = numLocals; + this.numStack = numStack; + this.numLocks = numLocks; + assert !rethrowException || numStack == 1 : "must have exception on top of the stack"; + } + + /** + * Ensure that the frame state is formatted as expected by the JVM, with null or Illegal in the + * slot following a double word item. This should really be checked in FrameState itself but + * because of Word type rewriting and alternative backends that can't be done. + */ + public boolean validateFormat(boolean derivedOk) { + if (caller() != null) { + caller().validateFormat(derivedOk); + } + for (int i = 0; i < numLocals + numStack; i++) { + if (values[i] != null) { + Kind kind = values[i].getKind(); + if (kind.needsTwoSlots()) { + assert values.length > i + 1 : String.format("missing second word %s", this); + assert values[i + 1] == null || values[i + 1].getKind() == Kind.Illegal : this; + } + assert derivedOk || ValueUtil.isIllegal(values[i]) || !values[i].getLIRKind().isDerivedReference() : "Unexpected derived value: " + values[i]; + } + } + return true; + } + + /** + * Gets the value representing the specified local variable. + * + * @param i the local variable index + * @return the value that can be used to reconstruct the local's current value + */ + public Value getLocalValue(int i) { + return values[i]; + } + + /** + * Gets the value representing the specified stack slot. + * + * @param i the stack index + * @return the value that can be used to reconstruct the stack slot's current value + */ + public Value getStackValue(int i) { + return values[i + numLocals]; + } + + /** + * Gets the value representing the specified lock. + * + * @param i the lock index + * @return the value that can be used to reconstruct the lock's current value + */ + public Value getLockValue(int i) { + return values[i + numLocals + numStack]; + } + + /** + * Gets the caller of this frame. + * + * @return {@code null} if this frame has no caller + */ + public BytecodeFrame caller() { + return (BytecodeFrame) getCaller(); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof BytecodeFrame && super.equals(obj)) { + BytecodeFrame that = (BytecodeFrame) obj; + // @formatter:off + if (this.duringCall == that.duringCall && + this.rethrowException == that.rethrowException && + this.numLocals == that.numLocals && + this.numLocks == that.numLocks && + this.numStack == that.numStack && + Arrays.equals(this.values, that.values)) { + return true; + } + // @formatter:off + return true; + } + return false; + } + + @Override + public String toString() { + return CodeUtil.append(new StringBuilder(100), this).toString(); + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.code/src/com/oracle/jvmci/code/BytecodePosition.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.code/src/com/oracle/jvmci/code/BytecodePosition.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,119 @@ +/* + * 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.code; + +import com.oracle.jvmci.meta.ResolvedJavaMethod; +import java.util.*; + +/** + * Represents a code position, that is, a chain of inlined methods with bytecode locations, that is + * communicated from the compiler to the runtime system. A code position can be used by the runtime + * system to reconstruct a source-level stack trace for exceptions and to create + * {@linkplain BytecodeFrame frames} for deoptimization. + */ +public class BytecodePosition { + + private final BytecodePosition caller; + private final ResolvedJavaMethod method; + private final int bci; + + /** + * Constructs a new object representing a given parent/caller, a given method, and a given BCI. + * + * @param caller the parent position + * @param method the method + * @param bci a BCI within the method + */ + public BytecodePosition(BytecodePosition caller, ResolvedJavaMethod method, int bci) { + assert method != null; + this.caller = caller; + this.method = method; + this.bci = bci; + } + + /** + * Converts this code position to a string representation. + * + * @return a string representation of this code position + */ + @Override + public String toString() { + return CodeUtil.append(new StringBuilder(100), this).toString(); + } + + /** + * Deep equality test. + */ + @Override + public boolean equals(Object obj) { + if (obj == this) { + return true; + } + if (obj != null && getClass() == obj.getClass()) { + BytecodePosition that = (BytecodePosition) obj; + if (this.bci == that.bci && Objects.equals(this.getMethod(), that.getMethod()) && Objects.equals(this.caller, that.caller)) { + return true; + } + } + return false; + } + + @Override + public int hashCode() { + return getBCI(); + } + + /** + * @return The location within the method, as a bytecode index. The constant {@code -1} may be + * used to indicate the location is unknown, for example within code synthesized by the + * compiler. + */ + public int getBCI() { + return bci; + } + + /** + * @return The runtime interface method for this position. + */ + public ResolvedJavaMethod getMethod() { + return method; + } + + /** + * The position where this position has been called, {@code null} if none. + */ + public BytecodePosition getCaller() { + return caller; + } + + /** + * Adds a caller to the current position returning the new position. + */ + public BytecodePosition addCaller(BytecodePosition link) { + if (getCaller() == null) { + return new BytecodePosition(link, getMethod(), getBCI()); + } else { + return new BytecodePosition(getCaller().addCaller(link), getMethod(), getBCI()); + } + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.code/src/com/oracle/jvmci/code/CalleeSaveLayout.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.code/src/com/oracle/jvmci/code/CalleeSaveLayout.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,181 @@ +/* + * Copyright (c) 2010, 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.code; + +import com.oracle.jvmci.meta.PlatformKind; +import java.util.*; + +/** + * The callee save area (CSA) is a contiguous space in a stack frame used to save (and restore) the + * values of the caller's registers. This class describes the layout of a CSA in terms of its + * {@linkplain #size size}, {@linkplain #slotSize slot size} and the {@linkplain #registers callee + * save registers} covered by the CSA. + */ +public class CalleeSaveLayout { + + /** + * The size (in bytes) of the CSA. + */ + public final int size; + + /** + * The size (in bytes) of an {@linkplain #registerAt(int) indexable} slot in the CSA. + */ + public final int slotSize; + + /** + * Map from {@linkplain Register#number register numbers} to slot indexes in the CSA. + */ + private final int[] regNumToIndex; + + private final Register[] indexToReg; + + /** + * The list of registers {@linkplain #contains(int) contained} by this CSA. + */ + public final Register[] registers; + + /** + * The offset from the frame pointer to the CSA. If this is not known, then this field will have + * the value {@link Integer#MAX_VALUE}. + */ + public final int frameOffsetToCSA; + + /** + * Creates a CSA layout. + * + * @param size size (in bytes) of the CSA. If this is {@code -1}, then the CSA size will be + * computed from {@code registers}. + * @param slotSize the size (in bytes) of an {@linkplain #registerAt(int) indexable} slot in the + * CSA + * @param registers the registers that can be saved in the CSA + */ + public CalleeSaveLayout(TargetDescription target, int frameOffsetToCSA, int size, int slotSize, Register... registers) { + this.frameOffsetToCSA = frameOffsetToCSA; + assert slotSize == 0 || CodeUtil.isPowerOf2(slotSize); + this.slotSize = slotSize; + int maxRegNum = -1; + int maxOffset = 0; + this.registers = registers; + int offset = 0; + for (Register reg : registers) { + assert offset % slotSize == 0; + assert reg.number >= 0; + if (reg.number > maxRegNum) { + maxRegNum = reg.number; + } + if (offset > maxOffset) { + maxOffset = offset; + } + PlatformKind kind = target.arch.getLargestStorableKind(reg.getRegisterCategory()); + offset += target.getSizeInBytes(kind); + } + if (size == -1) { + this.size = offset; + } else { + assert offset <= size; + this.size = size; + } + + this.regNumToIndex = new int[maxRegNum + 1]; + this.indexToReg = offset == 0 ? new Register[0] : new Register[offset / slotSize]; + Arrays.fill(regNumToIndex, -1); + offset = 0; + for (Register reg : registers) { + int index = offset / slotSize; + regNumToIndex[reg.number] = index; + indexToReg[index] = reg; + PlatformKind kind = target.arch.getLargestStorableKind(reg.getRegisterCategory()); + offset += target.getSizeInBytes(kind); + } + } + + /** + * Gets the offset of a given register in the CSA. + * + * @return the offset (in bytes) of {@code reg} in the CSA + * @throws IllegalArgumentException if {@code reg} does not have a slot in the CSA + */ + public int offsetOf(int reg) { + return indexOf(reg) * slotSize; + } + + /** + * Gets the index of a given register in the CSA. + * + * @return the index of {@code reg} in the CSA + * @throws IllegalArgumentException if {@code reg} does not have a slot in the CSA + */ + public int indexOf(int reg) { + if (!contains(reg)) { + throw new IllegalArgumentException(String.valueOf(reg)); + } + return regNumToIndex[reg]; + } + + /** + * Gets the offset of a given register in the CSA. + * + * @return the offset (in bytes) of {@code reg} in the CSA + * @throws IllegalArgumentException if {@code reg} does not have a slot in the CSA + */ + public int offsetOf(Register reg) { + return offsetOf(reg.number); + } + + /** + * Determines if the CSA includes a slot for a given register. + * + * @param reg the register to test + * @return true if the CSA contains a slot for {@code reg} + */ + public boolean contains(int reg) { + return reg >= 0 && reg < regNumToIndex.length && regNumToIndex[reg] != -1; + } + + /** + * Gets the register whose slot in the CSA is at a given index. + * + * @param index an index of a slot in the CSA + * @return the register whose slot in the CSA is at {@code index} or {@code null} if + * {@code index} does not denote a slot in the CSA aligned with a register + */ + public Register registerAt(int index) { + if (index < 0 || index >= indexToReg.length) { + return null; + } + return indexToReg[index]; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("["); + for (Register reg : registers) { + if (sb.length() != 1) { + sb.append(", "); + } + sb.append(reg).append("{+").append(offsetOf(reg)).append('}'); + } + return sb.append("] size=").append(size).toString(); + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.code/src/com/oracle/jvmci/code/CallingConvention.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.code/src/com/oracle/jvmci/code/CallingConvention.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,158 @@ +/* + * Copyright (c) 2009, 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.code; + +import com.oracle.jvmci.meta.Value; +import com.oracle.jvmci.meta.AllocatableValue; +import static com.oracle.jvmci.code.ValueUtil.*; + +/** + * A calling convention describes the locations in which the arguments for a call are placed and the + * location in which the return value is placed if the call is not void. + */ +public class CallingConvention { + + /** + * Constants denoting the type of a call for which a calling convention is requested. + */ + public enum Type { + /** + * A request for the outgoing argument locations at a call site to Java code. + */ + JavaCall(true), + + /** + * A request for the incoming argument locations. + */ + JavaCallee(false), + + /** + * A request for the outgoing argument locations at a call site to external native code that + * complies with the platform ABI. + */ + NativeCall(true); + + /** + * Determines if this is a request for the outgoing argument locations at a call site. + */ + public final boolean out; + + public static final Type[] VALUES = values(); + + private Type(boolean out) { + this.out = out; + } + } + + /** + * The amount of stack space (in bytes) required for the stack-based arguments of the call. + */ + private final int stackSize; + + private final AllocatableValue returnLocation; + + /** + * The ordered locations in which the arguments are placed. + */ + private final AllocatableValue[] argumentLocations; + + /** + * Creates a description of the registers and stack locations used by a call. + * + * @param stackSize amount of stack space (in bytes) required for the stack-based arguments of + * the call + * @param returnLocation the location for the return value or {@link Value#ILLEGAL} if a void + * call + * @param argumentLocations the ordered locations in which the arguments are placed + */ + public CallingConvention(int stackSize, AllocatableValue returnLocation, AllocatableValue... argumentLocations) { + assert argumentLocations != null; + assert returnLocation != null; + this.argumentLocations = argumentLocations; + this.stackSize = stackSize; + this.returnLocation = returnLocation; + assert verify(); + } + + /** + * Gets the location for the return value or {@link Value#ILLEGAL} if a void call. + */ + public AllocatableValue getReturn() { + return returnLocation; + } + + /** + * Gets the location for the {@code index}'th argument. + */ + public AllocatableValue getArgument(int index) { + return argumentLocations[index]; + } + + /** + * Gets the amount of stack space (in bytes) required for the stack-based arguments of the call. + */ + public int getStackSize() { + return stackSize; + } + + /** + * Gets the number of locations required for the arguments. + */ + public int getArgumentCount() { + return argumentLocations.length; + } + + /** + * Gets the locations required for the arguments. + */ + public AllocatableValue[] getArguments() { + if (argumentLocations.length == 0) { + return argumentLocations; + } + return argumentLocations.clone(); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("CallingConvention["); + String sep = ""; + for (Value op : argumentLocations) { + sb.append(sep).append(op); + sep = ", "; + } + if (!returnLocation.equals(Value.ILLEGAL)) { + sb.append(" -> ").append(returnLocation); + } + sb.append("]"); + return sb.toString(); + } + + private boolean verify() { + for (int i = 0; i < argumentLocations.length; i++) { + Value location = argumentLocations[i]; + assert isStackSlot(location) || isAllocatableValue(location); + } + return true; + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.code/src/com/oracle/jvmci/code/CodeCacheProvider.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.code/src/com/oracle/jvmci/code/CodeCacheProvider.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2009, 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.code; + +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. + */ +public interface CodeCacheProvider { + + /** + * Adds the given compilation result as an implementation of the given method without making it + * the default implementation. + * + * @param method a method to which the executable code is begin added + * @param compResult the compilation result to be added + * @param speculationLog the speculation log to be used + * @return a reference to the compiled and ready-to-run code or throws a + * {@link BailoutException} if the code installation failed + */ + InstalledCode addMethod(ResolvedJavaMethod method, CompilationResult compResult, SpeculationLog speculationLog, InstalledCode predefinedInstalledCode); + + /** + * Sets the given compilation result as the default implementation of the given method. + * + * @param method a method to which the executable code is begin added + * @param compResult the compilation result to be added + * @return a reference to the compiled and ready-to-run code or null if the code installation + * failed + */ + InstalledCode setDefaultMethod(ResolvedJavaMethod method, CompilationResult compResult); + + /** + * Gets a name for a {@link Mark} mark. + */ + 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. + */ + RegisterConfig getRegisterConfig(); + + /** + * Minimum size of the stack area reserved for outgoing parameters. This area is reserved in all + * cases, even when the compiled method has no regular call instructions. + * + * @return the minimum size of the outgoing parameter area in bytes + */ + int getMinimumOutgoingSize(); + + /** + * Determines if a {@link DataPatch} should be created for a given primitive constant that is + * part of a {@link CompilationResult}. A data patch is always created for an object constant. + */ + boolean needsDataPatch(JavaConstant constant); + + /** + * Create a {@link Data} item for a {@link Constant}, that can be used in a {@link DataPatch}. + */ + Data createDataItem(Constant constant); + + /** + * Gets a description of the target architecture. + */ + TargetDescription getTarget(); + + /** + * Create a new speculation log for the target runtime. + */ + SpeculationLog createSpeculationLog(); +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.code/src/com/oracle/jvmci/code/CodeUtil.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.code/src/com/oracle/jvmci/code/CodeUtil.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,474 @@ +/* + * Copyright (c) 2010, 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; + +import com.oracle.jvmci.meta.Signature; +import com.oracle.jvmci.meta.ResolvedJavaMethod; +import com.oracle.jvmci.meta.JavaType; +import com.oracle.jvmci.meta.MetaUtil; +import java.util.*; + +/** + * Miscellaneous collection of utility methods used by {@code com.oracle.jvmci.code} and its + * clients. + */ +public class CodeUtil { + + public static final String NEW_LINE = String.format("%n"); + + public static final int K = 1024; + public static final int M = 1024 * 1024; + + public static boolean isOdd(int n) { + return (n & 1) == 1; + } + + public static boolean isEven(int n) { + return (n & 1) == 0; + } + + /** + * Checks whether the specified integer is a power of two. + * + * @param val the value to check + * @return {@code true} if the value is a power of two; {@code false} otherwise + */ + public static boolean isPowerOf2(int val) { + return val > 0 && (val & val - 1) == 0; + } + + /** + * Checks whether the specified long is a power of two. + * + * @param val the value to check + * @return {@code true} if the value is a power of two; {@code false} otherwise + */ + public static boolean isPowerOf2(long val) { + return val > 0 && (val & val - 1) == 0; + } + + /** + * Computes the log (base 2) of the specified integer, rounding down. (E.g {@code log2(8) = 3}, + * {@code log2(21) = 4} ) + * + * @param val the value + * @return the log base 2 of the value + */ + public static int log2(int val) { + assert val > 0; + return (Integer.SIZE - 1) - Integer.numberOfLeadingZeros(val); + } + + /** + * Computes the log (base 2) of the specified long, rounding down. (E.g {@code log2(8) = 3}, + * {@code log2(21) = 4}) + * + * @param val the value + * @return the log base 2 of the value + */ + public static int log2(long val) { + assert val > 0; + return (Long.SIZE - 1) - Long.numberOfLeadingZeros(val); + } + + /** + * Narrow an integer value to a given bit width, and return the result as a signed long. + * + * @param value the value + * @param resultBits the result bit width + * @return {@code value} interpreted as {@code resultBits} bit number, encoded as signed long + */ + public static long narrow(long value, int resultBits) { + long ret = value & mask(resultBits); + return signExtend(ret, resultBits); + } + + /** + * Sign extend an integer. + * + * @param value the input value + * @param inputBits the bit width of the input value + * @return a signed long with the same value as the signed {@code inputBits}-bit number + * {@code value} + */ + public static long signExtend(long value, int inputBits) { + if (inputBits < 64) { + if ((value >>> (inputBits - 1) & 1) == 1) { + return value | (-1L << inputBits); + } else { + return value & ~(-1L << inputBits); + } + } else { + return value; + } + } + + /** + * Zero extend an integer. + * + * @param value the input value + * @param inputBits the bit width of the input value + * @return an unsigned long with the same value as the unsigned {@code inputBits}-bit number + * {@code value} + */ + public static long zeroExtend(long value, int inputBits) { + if (inputBits < 64) { + return value & ~(-1L << inputBits); + } else { + return value; + } + } + + /** + * Convert an integer to long. + * + * @param value the input value + * @param inputBits the bit width of the input value + * @param unsigned whether the values should be interpreted as signed or unsigned + * @return a long with the same value as the {@code inputBits}-bit number {@code value} + */ + public static long convert(long value, int inputBits, boolean unsigned) { + if (unsigned) { + return zeroExtend(value, inputBits); + } else { + return signExtend(value, inputBits); + } + } + + /** + * Get a bitmask with the low {@code bits} bit set and the high {@code 64 - bits} bit clear. + */ + public static long mask(int bits) { + assert 0 <= bits && bits <= 64; + if (bits == 64) { + return 0xffffffffffffffffL; + } else { + return (1L << bits) - 1; + } + } + + /** + * Get the minimum value representable in a {@code bits} bit signed integer. + */ + public static long minValue(int bits) { + assert 0 < bits && bits <= 64; + return -1L << (bits - 1); + } + + /** + * Get the maximum value representable in a {@code bits} bit signed integer. + */ + public static long maxValue(int bits) { + assert 0 < bits && bits <= 64; + return mask(bits - 1); + } + + /** + * Formats the values in a frame as a tabulated string. + * + * @param frame + * @return the values in {@code frame} as a tabulated string + */ + public static String tabulateValues(BytecodeFrame frame) { + int cols = Math.max(frame.numLocals, Math.max(frame.numStack, frame.numLocks)); + assert cols > 0; + ArrayList cells = new ArrayList<>(); + cells.add(""); + for (int i = 0; i < cols; i++) { + cells.add(i); + } + cols++; + if (frame.numLocals != 0) { + cells.add("locals:"); + cells.addAll(Arrays.asList(frame.values).subList(0, frame.numLocals)); + cells.addAll(Collections.nCopies(cols - frame.numLocals - 1, "")); + } + if (frame.numStack != 0) { + cells.add("stack:"); + cells.addAll(Arrays.asList(frame.values).subList(frame.numLocals, frame.numLocals + frame.numStack)); + cells.addAll(Collections.nCopies(cols - frame.numStack - 1, "")); + } + if (frame.numLocks != 0) { + cells.add("locks:"); + cells.addAll(Arrays.asList(frame.values).subList(frame.numLocals + frame.numStack, frame.values.length)); + cells.addAll(Collections.nCopies(cols - frame.numLocks - 1, "")); + } + Object[] cellArray = cells.toArray(); + for (int i = 0; i < cellArray.length; i++) { + if ((i % cols) != 0) { + cellArray[i] = "|" + cellArray[i]; + } + } + return CodeUtil.tabulate(cellArray, cols, 1, 1); + } + + /** + * Formats a given table as a string. The value of each cell is produced by + * {@link String#valueOf(Object)}. + * + * @param cells the cells of the table in row-major order + * @param cols the number of columns per row + * @param lpad the number of space padding inserted before each formatted cell value + * @param rpad the number of space padding inserted after each formatted cell value + * @return a string with one line per row and each column left-aligned + */ + public static String tabulate(Object[] cells, int cols, int lpad, int rpad) { + int rows = (cells.length + (cols - 1)) / cols; + int[] colWidths = new int[cols]; + for (int col = 0; col < cols; col++) { + for (int row = 0; row < rows; row++) { + int index = col + (row * cols); + if (index < cells.length) { + Object cell = cells[index]; + colWidths[col] = Math.max(colWidths[col], String.valueOf(cell).length()); + } + } + } + StringBuilder sb = new StringBuilder(); + String nl = NEW_LINE; + for (int row = 0; row < rows; row++) { + for (int col = 0; col < cols; col++) { + int index = col + (row * cols); + if (index < cells.length) { + for (int i = 0; i < lpad; i++) { + sb.append(' '); + } + Object cell = cells[index]; + String s = String.valueOf(cell); + int w = s.length(); + sb.append(s); + while (w < colWidths[col]) { + sb.append(' '); + w++; + } + for (int i = 0; i < rpad; i++) { + sb.append(' '); + } + } + } + sb.append(nl); + } + return sb.toString(); + } + + /** + * Appends a formatted code position to a {@link StringBuilder}. + * + * @param sb the {@link StringBuilder} to append to + * @param pos the code position to format and append to {@code sb} + * @return the value of {@code sb} + */ + public static StringBuilder append(StringBuilder sb, BytecodePosition pos) { + MetaUtil.appendLocation(sb.append("at "), pos.getMethod(), pos.getBCI()); + if (pos.getCaller() != null) { + sb.append(NEW_LINE); + append(sb, pos.getCaller()); + } + return sb; + } + + /** + * Appends a formatted frame to a {@link StringBuilder}. + * + * @param sb the {@link StringBuilder} to append to + * @param frame the frame to format and append to {@code sb} + * @return the value of {@code sb} + */ + public static StringBuilder append(StringBuilder sb, BytecodeFrame frame) { + MetaUtil.appendLocation(sb.append("at "), frame.getMethod(), frame.getBCI()); + assert sb.charAt(sb.length() - 1) == ']'; + sb.deleteCharAt(sb.length() - 1); + sb.append(", duringCall: ").append(frame.duringCall).append(", rethrow: ").append(frame.rethrowException).append(']'); + if (frame.values != null && frame.values.length > 0) { + sb.append(NEW_LINE); + String table = tabulateValues(frame); + String[] rows = table.split(NEW_LINE); + for (int i = 0; i < rows.length; i++) { + String row = rows[i]; + if (!row.trim().isEmpty()) { + sb.append(" ").append(row); + if (i != rows.length - 1) { + sb.append(NEW_LINE); + } + } + } + } + if (frame.caller() != null) { + sb.append(NEW_LINE); + append(sb, frame.caller()); + } else if (frame.getCaller() != null) { + sb.append(NEW_LINE); + append(sb, frame.getCaller()); + } + return sb; + } + + public interface RefMapFormatter { + + String formatStackSlot(int frameRefMapIndex); + + String formatRegister(int regRefMapIndex); + } + + /** + * Formats a location in a register reference map. + */ + public static class DefaultRegFormatter implements RefMapFormatter { + + private final Register[] registers; + + public DefaultRegFormatter(Architecture arch) { + registers = new Register[arch.getRegisterReferenceMapSize()]; + for (Register r : arch.getRegisters()) { + if (r.getReferenceMapIndex() >= 0) { + registers[r.getReferenceMapIndex()] = r; + } + } + } + + public String formatStackSlot(int frameRefMapIndex) { + return null; + } + + public String formatRegister(int regRefMapIndex) { + int i = regRefMapIndex; + int idx = 0; + while (registers[i] == null) { + i--; + idx++; + } + if (idx == 0) { + return registers[i].toString(); + } else { + return String.format("%s+%d", registers[i].toString(), idx); + } + } + } + + /** + * Formats a location present in a register or frame reference map. + */ + public static class DefaultRefMapFormatter extends DefaultRegFormatter { + + /** + * The size of a stack slot. + */ + public final int slotSize; + + /** + * The register used as the frame pointer. + */ + public final Register fp; + + /** + * The offset (in bytes) from the slot pointed to by {@link #fp} to the slot corresponding + * to bit 0 in the frame reference map. + */ + public final int refMapToFPOffset; + + public DefaultRefMapFormatter(Architecture arch, int slotSize, Register fp, int refMapToFPOffset) { + super(arch); + this.slotSize = slotSize; + this.fp = fp; + this.refMapToFPOffset = refMapToFPOffset; + } + + @Override + public String formatStackSlot(int frameRefMapIndex) { + int refMapOffset = frameRefMapIndex * slotSize; + int fpOffset = refMapOffset + refMapToFPOffset; + if (fpOffset >= 0) { + return fp + "+" + fpOffset; + } + return fp.name + fpOffset; + } + } + + public static class NumberedRefMapFormatter implements RefMapFormatter { + + public String formatStackSlot(int frameRefMapIndex) { + return "s" + frameRefMapIndex; + } + + public String formatRegister(int regRefMapIndex) { + return "r" + regRefMapIndex; + } + } + + /** + * Appends a formatted debug info to a {@link StringBuilder}. + * + * @param sb the {@link StringBuilder} to append to + * @param info the debug info to format and append to {@code sb} + * @return the value of {@code sb} + */ + public static StringBuilder append(StringBuilder sb, DebugInfo info, RefMapFormatter formatterArg) { + RefMapFormatter formatter = formatterArg; + if (formatter == null) { + formatter = new NumberedRefMapFormatter(); + } + String nl = NEW_LINE; + ReferenceMap refMap = info.getReferenceMap(); + if (refMap != null) { + sb.append(refMap.toString()); + } + RegisterSaveLayout calleeSaveInfo = info.getCalleeSaveInfo(); + if (calleeSaveInfo != null) { + sb.append("callee-save-info:").append(nl); + Map map = calleeSaveInfo.slotsToRegisters(true); + for (Map.Entry e : map.entrySet()) { + sb.append(" ").append(e.getValue()).append(" -> ").append(formatter.formatStackSlot(e.getKey())).append(nl); + } + } + BytecodeFrame frame = info.frame(); + if (frame != null) { + append(sb, frame); + } else if (info.getBytecodePosition() != null) { + append(sb, info.getBytecodePosition()); + } + return sb; + } + + /** + * Create a calling convention from a {@link ResolvedJavaMethod}. + */ + public static CallingConvention getCallingConvention(CodeCacheProvider codeCache, CallingConvention.Type type, ResolvedJavaMethod method, boolean stackOnly) { + Signature sig = method.getSignature(); + JavaType retType = sig.getReturnType(null); + int sigCount = sig.getParameterCount(false); + JavaType[] argTypes; + int argIndex = 0; + if (!method.isStatic()) { + argTypes = new JavaType[sigCount + 1]; + argTypes[argIndex++] = method.getDeclaringClass(); + } else { + argTypes = new JavaType[sigCount]; + } + for (int i = 0; i < sigCount; i++) { + argTypes[argIndex++] = sig.getParameterType(i, null); + } + + RegisterConfig registerConfig = codeCache.getRegisterConfig(); + return registerConfig.getCallingConvention(type, retType, argTypes, codeCache.getTarget(), stackOnly); + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.code/src/com/oracle/jvmci/code/CompilationResult.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.code/src/com/oracle/jvmci/code/CompilationResult.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,949 @@ +/* + * Copyright (c) 2009, 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.code; + +import static com.oracle.jvmci.meta.MetaUtil.*; +import static java.util.Collections.*; + +import java.util.*; + +import com.oracle.jvmci.meta.Assumptions.Assumption; +import com.oracle.jvmci.meta.*; + +/** + * Represents the output from compiling a method, including the compiled machine code, associated + * data and references, relocation information, deoptimization information, etc. + */ +public class CompilationResult { + + /** + * Represents a code position with associated additional information. + */ + public abstract static class Site { + + /** + * The position (or offset) of this site with respect to the start of the target method. + */ + public final int pcOffset; + + public Site(int pos) { + this.pcOffset = pos; + } + + @Override + public final int hashCode() { + throw new UnsupportedOperationException("hashCode"); + } + + @Override + public String toString() { + return identityHashCodeString(this); + } + + @Override + public abstract boolean equals(Object obj); + } + + /** + * Represents an infopoint with associated debug info. Note that safepoints are also infopoints. + */ + public static class Infopoint extends Site implements Comparable { + + public final DebugInfo debugInfo; + + public final InfopointReason reason; + + public Infopoint(int pcOffset, DebugInfo debugInfo, InfopointReason reason) { + super(pcOffset); + this.debugInfo = debugInfo; + this.reason = reason; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append(pcOffset); + sb.append("[]"); + appendDebugInfo(sb, debugInfo); + return sb.toString(); + } + + @Override + public int compareTo(Infopoint o) { + if (pcOffset < o.pcOffset) { + return -1; + } else if (pcOffset > o.pcOffset) { + return 1; + } + return this.reason.compareTo(o.reason); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj != null && obj.getClass() == getClass()) { + Infopoint that = (Infopoint) obj; + if (this.pcOffset == that.pcOffset && Objects.equals(this.debugInfo, that.debugInfo) && Objects.equals(this.reason, that.reason)) { + return true; + } + } + return false; + } + } + + /** + * Represents a call in the code. + */ + public static final class Call extends Infopoint { + + /** + * The target of the call. + */ + public final InvokeTarget target; + + /** + * The size of the call instruction. + */ + public final int size; + + /** + * Specifies if this call is direct or indirect. A direct call has an immediate operand + * encoding the absolute or relative (to the call itself) address of the target. An indirect + * call has a register or memory operand specifying the target address of the call. + */ + public final boolean direct; + + public Call(InvokeTarget target, int pcOffset, int size, boolean direct, DebugInfo debugInfo) { + super(pcOffset, debugInfo, InfopointReason.CALL); + this.size = size; + this.target = target; + this.direct = direct; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof Call && super.equals(obj)) { + Call that = (Call) obj; + if (this.size == that.size && this.direct == that.direct && Objects.equals(this.target, that.target)) { + return true; + } + } + return false; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append(pcOffset); + sb.append('['); + sb.append(target); + sb.append(']'); + + if (debugInfo != null) { + appendDebugInfo(sb, debugInfo); + } + + return sb.toString(); + } + } + + /** + * Represents some external data that is referenced by the code. + */ + public abstract static class Reference { + + @Override + public abstract int hashCode(); + + @Override + public abstract boolean equals(Object obj); + } + + public static final class ConstantReference extends Reference { + + private final VMConstant constant; + + public ConstantReference(VMConstant constant) { + this.constant = constant; + } + + public VMConstant getConstant() { + return constant; + } + + @Override + public String toString() { + return constant.toString(); + } + + @Override + public int hashCode() { + return constant.hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof ConstantReference) { + ConstantReference that = (ConstantReference) obj; + return Objects.equals(this.constant, that.constant); + } + return false; + } + } + + public static final class DataSectionReference extends Reference { + + private boolean initialized; + private int offset; + + public DataSectionReference() { + // will be set after the data section layout is fixed + offset = 0xDEADDEAD; + } + + public int getOffset() { + assert initialized; + + return offset; + } + + public void setOffset(int offset) { + assert !initialized; + initialized = true; + + this.offset = offset; + } + + @Override + public int hashCode() { + return offset; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof DataSectionReference) { + DataSectionReference that = (DataSectionReference) obj; + return this.offset == that.offset; + } + return false; + } + } + + /** + * Represents a code site that references some data. The associated data can be either a + * {@link DataSectionReference reference} to the data section, or it may be an inlined + * {@link JavaConstant} that needs to be patched. + */ + public static final class DataPatch extends Site { + + public Reference reference; + + public DataPatch(int pcOffset, Reference reference) { + super(pcOffset); + this.reference = reference; + } + + @Override + public String toString() { + return String.format("%d[]", pcOffset, reference.toString()); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof DataPatch) { + DataPatch that = (DataPatch) obj; + if (this.pcOffset == that.pcOffset && Objects.equals(this.reference, that.reference)) { + return true; + } + } + return false; + } + } + + /** + * Provides extra information about instructions or data at specific positions in + * {@link CompilationResult#getTargetCode()}. This is optional information that can be used to + * enhance a disassembly of the code. + */ + public abstract static class CodeAnnotation { + + public final int position; + + public CodeAnnotation(int position) { + this.position = position; + } + + @Override + public final int hashCode() { + throw new UnsupportedOperationException("hashCode"); + } + + @Override + public String toString() { + return identityHashCodeString(this); + } + + @Override + public abstract boolean equals(Object obj); + } + + /** + * A string comment about one or more instructions at a specific position in the code. + */ + public static final class CodeComment extends CodeAnnotation { + + public final String value; + + public CodeComment(int position, String comment) { + super(position); + this.value = comment; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof CodeComment) { + CodeComment that = (CodeComment) obj; + if (this.position == that.position && this.value.equals(that.value)) { + return true; + } + } + return false; + } + + @Override + public String toString() { + return getClass().getSimpleName() + "@" + position + ": " + value; + } + } + + /** + * Describes a table of signed offsets embedded in the code. The offsets are relative to the + * starting address of the table. This type of table maybe generated when translating a + * multi-way branch based on a key value from a dense value set (e.g. the {@code tableswitch} + * JVM instruction). + * + * The table is indexed by the contiguous range of integers from {@link #low} to {@link #high} + * inclusive. + */ + public static final class JumpTable extends CodeAnnotation { + + /** + * The low value in the key range (inclusive). + */ + public final int low; + + /** + * The high value in the key range (inclusive). + */ + public final int high; + + /** + * The size (in bytes) of each table entry. + */ + public final int entrySize; + + public JumpTable(int position, int low, int high, int entrySize) { + super(position); + this.low = low; + this.high = high; + this.entrySize = entrySize; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof JumpTable) { + JumpTable that = (JumpTable) obj; + if (this.position == that.position && this.entrySize == that.entrySize && this.low == that.low && this.high == that.high) { + return true; + } + } + return false; + } + + @Override + public String toString() { + return getClass().getSimpleName() + "@" + position + ": [" + low + " .. " + high + "]"; + } + } + + /** + * Represents exception handler information for a specific code position. It includes the catch + * code position as well as the caught exception type. + */ + public static final class ExceptionHandler extends Site { + + public final int handlerPos; + + ExceptionHandler(int pcOffset, int handlerPos) { + super(pcOffset); + this.handlerPos = handlerPos; + } + + @Override + public String toString() { + return String.format("%d[]", pcOffset, handlerPos); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof ExceptionHandler) { + ExceptionHandler that = (ExceptionHandler) obj; + if (this.pcOffset == that.pcOffset && this.handlerPos == that.handlerPos) { + return true; + } + } + return false; + } + } + + /** + * Represents a mark in the machine code that can be used by the runtime for its own purposes. A + * mark can reference other marks. + */ + public static final class Mark extends Site { + + public final Object id; + + public Mark(int pcOffset, Object id) { + super(pcOffset); + this.id = id; + } + + @Override + public String toString() { + if (id == null) { + return String.format("%d[]", pcOffset); + } else if (id instanceof Integer) { + return String.format("%d[]", pcOffset, Integer.toHexString((Integer) id)); + } else { + return String.format("%d[]", pcOffset, id.toString()); + } + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof Mark) { + Mark that = (Mark) obj; + if (this.pcOffset == that.pcOffset && Objects.equals(this.id, that.id)) { + return true; + } + } + return false; + } + } + + private int id = -1; + private int entryBCI = -1; + + private final DataSection dataSection = new DataSection(); + + private final List infopoints = new ArrayList<>(); + private final List dataPatches = new ArrayList<>(); + private final List exceptionHandlers = new ArrayList<>(); + private final List marks = new ArrayList<>(); + + private int totalFrameSize = -1; + private int customStackAreaOffset = -1; + + private final String name; + + /** + * The buffer containing the emitted machine code. + */ + private byte[] targetCode; + + /** + * The leading number of bytes in {@link #targetCode} containing the emitted machine code. + */ + private int targetCodeSize; + + private ArrayList annotations; + + private Assumption[] assumptions; + + /** + * The list of the methods whose bytecodes were used as input to the compilation. If + * {@code null}, then the compilation did not record method dependencies. Otherwise, the first + * element of this array is the root method of the compilation. + */ + private ResolvedJavaMethod[] methods; + + private int bytecodeSize; + + public CompilationResult() { + this(null); + } + + public CompilationResult(String name) { + this.name = name; + } + + @Override + public int hashCode() { + // CompilationResult instances should not be used as hash map keys + throw new UnsupportedOperationException("hashCode"); + } + + @Override + public String toString() { + if (methods != null) { + return getClass().getName() + "[" + methods[0].format("%H.%n(%p)%r") + "]"; + } + return identityHashCodeString(this); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj != null && obj.getClass() == getClass()) { + CompilationResult that = (CompilationResult) obj; + // @formatter:off + if (this.entryBCI == that.entryBCI && + this.id == that.id && + this.customStackAreaOffset == that.customStackAreaOffset && + this.totalFrameSize == that.totalFrameSize && + this.targetCodeSize == that.targetCodeSize && + Objects.equals(this.name, that.name) && + Objects.equals(this.annotations, that.annotations) && + Objects.equals(this.dataSection, that.dataSection) && + Objects.equals(this.exceptionHandlers, that.exceptionHandlers) && + Objects.equals(this.dataPatches, that.dataPatches) && + Objects.equals(this.infopoints, that.infopoints) && + Objects.equals(this.marks, that.marks) && + Arrays.equals(this.assumptions, that.assumptions) && + Arrays.equals(targetCode, that.targetCode)) { + return true; + } + // @formatter:on + } + return false; + } + + /** + * @return the compile id + */ + public int getId() { + return id; + } + + /** + * @param id the compile id to set + */ + public void setId(int id) { + this.id = id; + } + + /** + * @return the entryBCI + */ + public int getEntryBCI() { + return entryBCI; + } + + /** + * @param entryBCI the entryBCI to set + */ + public void setEntryBCI(int entryBCI) { + this.entryBCI = entryBCI; + } + + /** + * Sets the assumptions made during compilation. + */ + public void setAssumptions(Assumption[] assumptions) { + this.assumptions = assumptions; + } + + /** + * Gets the assumptions made during compilation. + */ + public Assumption[] getAssumptions() { + return assumptions; + } + + /** + * Sets the methods whose bytecodes were used as input to the compilation. + * + * @param rootMethod the root method of the compilation + * @param inlinedMethods the methods inlined during compilation + */ + public void setMethods(ResolvedJavaMethod rootMethod, Collection inlinedMethods) { + assert rootMethod != null; + assert inlinedMethods != null; + if (inlinedMethods.contains(rootMethod)) { + methods = inlinedMethods.toArray(new ResolvedJavaMethod[inlinedMethods.size()]); + for (int i = 0; i < methods.length; i++) { + if (methods[i].equals(rootMethod)) { + if (i != 0) { + ResolvedJavaMethod tmp = methods[0]; + methods[0] = methods[i]; + methods[i] = tmp; + } + break; + } + } + } else { + methods = new ResolvedJavaMethod[1 + inlinedMethods.size()]; + methods[0] = rootMethod; + int i = 1; + for (ResolvedJavaMethod m : inlinedMethods) { + methods[i++] = m; + } + } + } + + /** + * Gets the methods whose bytecodes were used as input to the compilation. + * + * @return {@code null} if the compilation did not record method dependencies otherwise the + * methods whose bytecodes were used as input to the compilation with the first element + * being the root method of the compilation + */ + public ResolvedJavaMethod[] getMethods() { + return methods; + } + + public void setBytecodeSize(int bytecodeSize) { + this.bytecodeSize = bytecodeSize; + } + + public int getBytecodeSize() { + return bytecodeSize; + } + + public DataSection getDataSection() { + return dataSection; + } + + /** + * The total frame size of the method in bytes. This includes the return address pushed onto the + * stack, if any. + * + * @return the frame size + */ + public int getTotalFrameSize() { + assert totalFrameSize != -1 : "frame size not yet initialized!"; + return totalFrameSize; + } + + /** + * Sets the total frame size in bytes. This includes the return address pushed onto the stack, + * if any. + * + * @param size the size of the frame in bytes + */ + public void setTotalFrameSize(int size) { + totalFrameSize = size; + } + + /** + * Sets the machine that has been generated by the compiler. + * + * @param code the machine code generated + * @param size the size of the machine code + */ + public void setTargetCode(byte[] code, int size) { + targetCode = code; + targetCodeSize = size; + } + + /** + * Records a data patch in the code section. The data patch can refer to something in the + * {@link DataSectionReference data section} or directly to an {@link ConstantReference inlined + * constant}. + * + * @param codePos The position in the code that needs to be patched. + * @param ref The reference that should be inserted in the code. + */ + public void recordDataPatch(int codePos, Reference ref) { + assert codePos >= 0 && ref != null; + dataPatches.add(new DataPatch(codePos, ref)); + } + + /** + * Records a call in the code array. + * + * @param codePos the position of the call in the code array + * @param size the size of the call instruction + * @param target the being called + * @param debugInfo the debug info for the call + * @param direct specifies if this is a {@linkplain Call#direct direct} call + */ + public void recordCall(int codePos, int size, InvokeTarget target, DebugInfo debugInfo, boolean direct) { + final Call call = new Call(target, codePos, size, direct, debugInfo); + addInfopoint(call); + } + + /** + * Records an exception handler for this method. + * + * @param codePos the position in the code that is covered by the handler + * @param handlerPos the position of the handler + */ + public void recordExceptionHandler(int codePos, int handlerPos) { + assert validateExceptionHandlerAdd(codePos, handlerPos) : String.format("Duplicate exception handler for pc 0x%x handlerPos 0x%x", codePos, handlerPos); + exceptionHandlers.add(new ExceptionHandler(codePos, handlerPos)); + } + + /** + * Validate if the exception handler for codePos already exists and handlerPos is different. + * + * @param codePos + * @param handlerPos + * @return true if the validation is successful + */ + private boolean validateExceptionHandlerAdd(int codePos, int handlerPos) { + ExceptionHandler exHandler = getExceptionHandlerForCodePos(codePos); + return exHandler == null || exHandler.handlerPos == handlerPos; + } + + /** + * Returns the first ExceptionHandler which matches codePos. + * + * @param codePos position to search for + * @return first matching ExceptionHandler + */ + private ExceptionHandler getExceptionHandlerForCodePos(int codePos) { + for (ExceptionHandler h : exceptionHandlers) { + if (h.pcOffset == codePos) { + return h; + } + } + return null; + } + + /** + * Records an infopoint in the code array. + * + * @param codePos the position of the infopoint in the code array + * @param debugInfo the debug info for the infopoint + */ + public void recordInfopoint(int codePos, DebugInfo debugInfo, InfopointReason reason) { + addInfopoint(new Infopoint(codePos, debugInfo, reason)); + } + + /** + * Records a custom infopoint in the code section. + * + * Compiler implementations can use this method to record non-standard infopoints, which are not + * handled by the dedicated methods like {@link #recordCall}. + * + * @param infopoint the infopoint to record, usually a derived class from {@link Infopoint} + */ + public void addInfopoint(Infopoint infopoint) { + // The infopoints list must always be sorted + if (!infopoints.isEmpty()) { + Infopoint previousInfopoint = infopoints.get(infopoints.size() - 1); + if (previousInfopoint.pcOffset > infopoint.pcOffset) { + // This re-sorting should be very rare + Collections.sort(infopoints); + previousInfopoint = infopoints.get(infopoints.size() - 1); + } + if (previousInfopoint.pcOffset == infopoint.pcOffset) { + if (infopoint.reason.canBeOmitted()) { + return; + } + if (previousInfopoint.reason.canBeOmitted()) { + Infopoint removed = infopoints.remove(infopoints.size() - 1); + assert removed == previousInfopoint; + } else { + throw new RuntimeException("Infopoints that can not be omited should have distinct PCs"); + } + } + } + infopoints.add(infopoint); + } + + /** + * Records an instruction mark within this method. + * + * @param codePos the position in the code that is covered by the handler + * @param markId the identifier for this mark + */ + public Mark recordMark(int codePos, Object markId) { + Mark mark = new Mark(codePos, markId); + marks.add(mark); + return mark; + } + + /** + * Offset in bytes for the custom stack area (relative to sp). + * + * @return the offset in bytes + */ + public int getCustomStackAreaOffset() { + return customStackAreaOffset; + } + + /** + * @see #getCustomStackAreaOffset() + * @param offset + */ + public void setCustomStackAreaOffset(int offset) { + customStackAreaOffset = offset; + } + + /** + * @return the machine code generated for this method + */ + public byte[] getTargetCode() { + return targetCode; + } + + /** + * @return the size of the machine code generated for this method + */ + public int getTargetCodeSize() { + return targetCodeSize; + } + + /** + * @return the code annotations or {@code null} if there are none + */ + public List getAnnotations() { + if (annotations == null) { + return Collections.emptyList(); + } + return annotations; + } + + public void addAnnotation(CodeAnnotation annotation) { + assert annotation != null; + if (annotations == null) { + annotations = new ArrayList<>(); + } + annotations.add(annotation); + } + + private static void appendDebugInfo(StringBuilder sb, DebugInfo info) { + if (info != null) { + ReferenceMap refMap = info.getReferenceMap(); + if (refMap != null) { + sb.append(refMap.toString()); + sb.append(']'); + } + RegisterSaveLayout calleeSaveInfo = info.getCalleeSaveInfo(); + if (calleeSaveInfo != null) { + sb.append(" callee-save-info["); + String sep = ""; + for (Map.Entry e : calleeSaveInfo.registersToSlots(true).entrySet()) { + sb.append(sep).append(e.getKey()).append("->").append(e.getValue()); + sep = ", "; + } + sb.append(']'); + } + BytecodePosition codePos = info.getBytecodePosition(); + if (codePos != null) { + MetaUtil.appendLocation(sb.append(" "), codePos.getMethod(), codePos.getBCI()); + if (info.hasFrame()) { + sb.append(" #locals=").append(info.frame().numLocals).append(" #expr=").append(info.frame().numStack); + if (info.frame().numLocks > 0) { + sb.append(" #locks=").append(info.frame().numLocks); + } + } + } + } + } + + /** + * @return the list of infopoints, sorted by {@link Site#pcOffset} + */ + public List getInfopoints() { + if (infopoints.isEmpty()) { + return emptyList(); + } + return unmodifiableList(infopoints); + } + + /** + * @return the list of data references + */ + public List getDataPatches() { + if (dataPatches.isEmpty()) { + return emptyList(); + } + return unmodifiableList(dataPatches); + } + + /** + * @return the list of exception handlers + */ + public List getExceptionHandlers() { + if (exceptionHandlers.isEmpty()) { + return emptyList(); + } + return unmodifiableList(exceptionHandlers); + } + + /** + * @return the list of marks + */ + public List getMarks() { + if (marks.isEmpty()) { + return emptyList(); + } + return unmodifiableList(marks); + } + + public String getName() { + return name; + } + + public void reset() { + infopoints.clear(); + dataPatches.clear(); + exceptionHandlers.clear(); + marks.clear(); + if (annotations != null) { + annotations.clear(); + } + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.code/src/com/oracle/jvmci/code/DataSection.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.code/src/com/oracle/jvmci/code/DataSection.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,278 @@ +/* + * 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.code; + +import com.oracle.jvmci.meta.SerializableConstant; +import static com.oracle.jvmci.meta.MetaUtil.*; + +import java.nio.*; +import java.util.*; +import java.util.function.*; + +import com.oracle.jvmci.code.CompilationResult.DataPatch; +import com.oracle.jvmci.code.CompilationResult.DataSectionReference; +import com.oracle.jvmci.code.DataSection.Data; + +public final class DataSection implements Iterable { + + @FunctionalInterface + public interface DataBuilder { + + void emit(ByteBuffer buffer, Consumer patch); + + static DataBuilder raw(byte[] data) { + return (buffer, patch) -> buffer.put(data); + } + + static DataBuilder serializable(SerializableConstant c) { + return (buffer, patch) -> c.serialize(buffer); + } + + static DataBuilder zero(int size) { + switch (size) { + case 1: + return (buffer, patch) -> buffer.put((byte) 0); + case 2: + return (buffer, patch) -> buffer.putShort((short) 0); + case 4: + return (buffer, patch) -> buffer.putInt(0); + case 8: + return (buffer, patch) -> buffer.putLong(0L); + default: + return (buffer, patch) -> { + int rest = size; + while (rest > 8) { + buffer.putLong(0L); + rest -= 8; + } + while (rest > 0) { + buffer.put((byte) 0); + rest--; + } + }; + } + } + } + + public static final class Data { + + private int alignment; + private final int size; + private final DataBuilder builder; + + private DataSectionReference ref; + + public Data(int alignment, int size, DataBuilder builder) { + this.alignment = alignment; + this.size = size; + this.builder = builder; + + // initialized in DataSection.insertData(Data) + ref = null; + } + + public void updateAlignment(int newAlignment) { + if (newAlignment == alignment) { + return; + } + alignment = lcm(alignment, newAlignment); + } + + public int getAlignment() { + return alignment; + } + + public int getSize() { + return size; + } + + public DataBuilder getBuilder() { + return builder; + } + + @Override + public int hashCode() { + // Data instances should not be used as hash map keys + throw new UnsupportedOperationException("hashCode"); + } + + @Override + public String toString() { + return identityHashCodeString(this); + } + + @Override + public boolean equals(Object obj) { + assert ref != null; + if (obj == this) { + return true; + } + if (obj instanceof Data) { + Data that = (Data) obj; + if (this.alignment == that.alignment && this.size == that.size && this.ref.equals(that.ref)) { + return true; + } + } + return false; + } + } + + private final ArrayList dataItems = new ArrayList<>(); + + private boolean finalLayout; + private int sectionAlignment; + private int sectionSize; + + @Override + public int hashCode() { + // DataSection instances should not be used as hash map keys + throw new UnsupportedOperationException("hashCode"); + } + + @Override + public String toString() { + return identityHashCodeString(this); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof DataSection) { + DataSection that = (DataSection) obj; + if (this.finalLayout == that.finalLayout && this.sectionAlignment == that.sectionAlignment && this.sectionSize == that.sectionSize && Objects.equals(this.dataItems, that.dataItems)) { + return true; + } + } + return false; + } + + /** + * Insert a {@link Data} item into the data section. If the item is already in the data section, + * the same {@link DataSectionReference} is returned. + * + * @param data the {@link Data} item to be inserted + * @return a unique {@link DataSectionReference} identifying the {@link Data} item + */ + public DataSectionReference insertData(Data data) { + assert !finalLayout; + if (data.ref == null) { + data.ref = new DataSectionReference(); + dataItems.add(data); + } + return data.ref; + } + + /** + * Compute the layout of the data section. This can be called only once, and after it has been + * called, the data section can no longer be modified. + */ + public void finalizeLayout() { + assert !finalLayout; + finalLayout = true; + + // simple heuristic: put items with larger alignment requirement first + dataItems.sort((a, b) -> a.alignment - b.alignment); + + int position = 0; + for (Data d : dataItems) { + sectionAlignment = lcm(sectionAlignment, d.alignment); + position = align(position, d.alignment); + + d.ref.setOffset(position); + position += d.size; + } + + sectionSize = position; + } + + /** + * Get the size of the data section. Can only be called after {@link #finalizeLayout}. + */ + public int getSectionSize() { + assert finalLayout; + return sectionSize; + } + + /** + * Get the minimum alignment requirement of the data section. Can only be called after + * {@link #finalizeLayout}. + */ + public int getSectionAlignment() { + assert finalLayout; + return sectionAlignment; + } + + /** + * Build the data section. Can only be called after {@link #finalizeLayout}. + * + * @param buffer The {@link ByteBuffer} where the data section should be built. The buffer must + * hold at least {@link #getSectionSize()} bytes. + * @param patch A {@link Consumer} to receive {@link DataPatch data patches} for relocations in + * the data section. + */ + public void buildDataSection(ByteBuffer buffer, Consumer patch) { + assert finalLayout; + for (Data d : dataItems) { + buffer.position(d.ref.getOffset()); + d.builder.emit(buffer, patch); + } + } + + public Data findData(DataSectionReference ref) { + for (Data d : dataItems) { + if (d.ref == ref) { + return d; + } + } + return null; + } + + public Iterator iterator() { + return dataItems.iterator(); + } + + private static int lcm(int x, int y) { + if (x == 0) { + return y; + } else if (y == 0) { + return x; + } + + int a = Math.max(x, y); + int b = Math.min(x, y); + while (b > 0) { + int tmp = a % b; + a = b; + b = tmp; + } + + int gcd = a; + return x * y / gcd; + } + + private static int align(int position, int alignment) { + return ((position + alignment - 1) / alignment) * alignment; + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.code/src/com/oracle/jvmci/code/DebugInfo.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.code/src/com/oracle/jvmci/code/DebugInfo.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,136 @@ +/* + * 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.code; + +import com.oracle.jvmci.meta.Value; +import java.util.*; + +/** + * Represents the debugging information for a particular point of execution. This information + * includes: + *
        + *
      • a {@linkplain #getBytecodePosition() bytecode position}
      • + *
      • a reference map for registers and stack slots in the current frame
      • + *
      • a map from bytecode locals and operand stack slots to their values or locations from which + * their values can be read
      • + *
      • a map from the registers (in the caller's frame) to the slots where they are saved in the + * current frame
      • + *
      + */ +public final class DebugInfo { + + private final BytecodePosition bytecodePosition; + private final ReferenceMap referenceMap; + @SuppressWarnings("unused") private final Value[] virtualObjectMapping; + private RegisterSaveLayout calleeSaveInfo; + + /** + * Creates a new {@link DebugInfo} from the given values. + * + * @param codePos the {@linkplain BytecodePosition code position} or {@linkplain BytecodeFrame + * frame} info + * @param referenceMap the reference map + * @param virtualObjectMapping the mapping of {@link VirtualObject}s to their real values + */ + public DebugInfo(BytecodePosition codePos, ReferenceMap referenceMap, Value[] virtualObjectMapping) { + this.bytecodePosition = codePos; + this.referenceMap = referenceMap; + this.virtualObjectMapping = virtualObjectMapping; + } + + public DebugInfo(BytecodePosition codePos) { + this(codePos, null, null); + } + + /** + * @return {@code true} if this debug information has a frame + */ + public boolean hasFrame() { + return getBytecodePosition() instanceof BytecodeFrame; + } + + /** + * Gets the deoptimization information for each inlined frame (if available). + * + * @return {@code null} if no frame de-opt info is {@linkplain #hasFrame() available} + */ + public BytecodeFrame frame() { + if (hasFrame()) { + return (BytecodeFrame) getBytecodePosition(); + } + return null; + } + + @Override + public String toString() { + return CodeUtil.append(new StringBuilder(100), this, null).toString(); + } + + /** + * @return The code position (including all inlined methods) of this debug info. If this is a + * {@link BytecodeFrame} instance, then it is also the deoptimization information for + * each inlined frame. + */ + public BytecodePosition getBytecodePosition() { + return bytecodePosition; + } + + public ReferenceMap getReferenceMap() { + return referenceMap; + } + + /** + * Sets the map from the registers (in the caller's frame) to the slots where they are saved in + * the current frame. + */ + public void setCalleeSaveInfo(RegisterSaveLayout calleeSaveInfo) { + this.calleeSaveInfo = calleeSaveInfo; + } + + /** + * Gets the map from the registers (in the caller's frame) to the slots where they are saved in + * the current frame. If no such information is available, {@code null} is returned. + */ + public RegisterSaveLayout getCalleeSaveInfo() { + return calleeSaveInfo; + } + + @Override + public int hashCode() { + throw new UnsupportedOperationException("hashCode"); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof DebugInfo) { + DebugInfo that = (DebugInfo) obj; + if (Objects.equals(this.bytecodePosition, that.bytecodePosition) && Objects.equals(this.calleeSaveInfo, that.calleeSaveInfo) && Objects.equals(this.referenceMap, that.referenceMap)) { + return true; + } + } + return false; + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.code/src/com/oracle/jvmci/code/ForeignCallLinkage.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.code/src/com/oracle/jvmci/code/ForeignCallLinkage.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2009, 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.code; + +import com.oracle.jvmci.meta.InvokeTarget; +import com.oracle.jvmci.meta.Value; +import com.oracle.jvmci.meta.ForeignCallDescriptor; + +/** + * The runtime specific details of a {@linkplain ForeignCallDescriptor foreign} call. + */ +public interface ForeignCallLinkage extends InvokeTarget { + + /** + * Gets the details of where parameters are passed and value(s) are returned from the caller's + * perspective. + */ + CallingConvention getOutgoingCallingConvention(); + + /** + * Gets the details of where parameters are passed and value(s) are returned from the callee's + * perspective. + */ + CallingConvention getIncomingCallingConvention(); + + /** + * Returns the maximum absolute offset of PC relative call to this stub from any position in the + * code cache or -1 when not applicable. Intended for determining the required size of + * address/offset fields. + */ + long getMaxCallTargetOffset(); + + ForeignCallDescriptor getDescriptor(); + + /** + * Gets the values used/killed by this foreign call. + */ + Value[] getTemporaries(); + + /** + * Determines if the foreign call target destroys all registers. + * + * @return {@code true} if the register allocator must save all live registers around a call to + * this target + */ + boolean destroysRegisters(); + + /** + * Determines if this is call to a function that does not deoptimize, and therefore also does + * not lock, GC or throw exceptions. That is, the thread's execution state during the call is + * never inspected by another thread. + */ + boolean canDeoptimize(); +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.code/src/com/oracle/jvmci/code/ForeignCallsProvider.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.code/src/com/oracle/jvmci/code/ForeignCallsProvider.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,55 @@ +/* + * 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; + +import com.oracle.jvmci.meta.LocationIdentity; +import com.oracle.jvmci.meta.ForeignCallDescriptor; + +/** + * Details about a set of supported {@link ForeignCallDescriptor foreign calls}. + */ +public interface ForeignCallsProvider { + + /** + * Determines if a given foreign call is side-effect free. Deoptimization cannot return + * execution to a point before a foreign call that has a side effect. + */ + boolean isReexecutable(ForeignCallDescriptor descriptor); + + /** + * Gets the set of memory locations killed by a given foreign call. Returning the special value + * {@link LocationIdentity#any()} denotes that the call kills all memory locations. Returning + * any empty array denotes that the call does not kill any memory locations. + */ + LocationIdentity[] getKilledLocations(ForeignCallDescriptor descriptor); + + /** + * Determines if deoptimization can occur during a given foreign call. + */ + boolean canDeoptimize(ForeignCallDescriptor descriptor); + + /** + * Gets the linkage for a foreign call. + */ + ForeignCallLinkage lookupForeignCall(ForeignCallDescriptor descriptor); +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.code/src/com/oracle/jvmci/code/InfopointReason.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.code/src/com/oracle/jvmci/code/InfopointReason.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,46 @@ +/* + * 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; + +/** + * A reason for infopoint insertion. + */ +public enum InfopointReason { + UNKNOWN(false), + SAFEPOINT(false), + CALL(false), + IMPLICIT_EXCEPTION(false), + METHOD_START(true), + METHOD_END(true), + LINE_NUMBER(true); + + private InfopointReason(boolean canBeOmitted) { + this.canBeOmitted = canBeOmitted; + } + + private final boolean canBeOmitted; + + public boolean canBeOmitted() { + return canBeOmitted; + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.code/src/com/oracle/jvmci/code/InstalledCode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.code/src/com/oracle/jvmci/code/InstalledCode.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,121 @@ +/* + * Copyright (c) 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.code; + +/** + * Represents a compiled instance of a method. It may have been invalidated or removed in the + * meantime. + */ +public class InstalledCode { + + /** + * Raw address of this code blob. + */ + private long address; + + /** + * Counts how often the address field was reassigned. + */ + private long version; + + protected final String name; + + public InstalledCode(String name) { + this.name = name; + } + + public final void setAddress(long address) { + this.address = address; + version++; + } + + /** + * @return the address of this code blob + */ + public final long getAddress() { + return address; + } + + /** + * @return the address of this code blob + */ + public final long getVersion() { + return version; + } + + /** + * Returns the name of this code blob. + */ + public String getName() { + return name; + } + + /** + * Returns the start address of this installed code if it is {@linkplain #isValid() valid}, 0 + * otherwise. + */ + public long getStart() { + return 0; + } + + /** + * Returns the number of instruction bytes for this code. + */ + public long getCodeSize() { + return 0; + } + + /** + * Returns a copy of this installed code if it is {@linkplain #isValid() valid}, null otherwise. + */ + public byte[] getCode() { + return null; + } + + /** + * @return true if the code represented by this object is still valid, false otherwise (may + * happen due to deopt, etc.) + */ + public boolean isValid() { + return address != 0; + } + + /** + * Invalidates this installed code such that any subsequent invocation will throw an + * {@link InvalidInstalledCodeException}. + */ + public void invalidate() { + throw new UnsupportedOperationException(); + } + + /** + * Executes the installed code with a variable number of arguments. + * + * @param args the array of object arguments + * @return the value returned by the executed code + */ + @SuppressWarnings("unused") + public Object executeVarargs(Object... args) throws InvalidInstalledCodeException { + throw new UnsupportedOperationException(); + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.code/src/com/oracle/jvmci/code/InvalidInstalledCodeException.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.code/src/com/oracle/jvmci/code/InvalidInstalledCodeException.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,31 @@ +/* + * 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; + +/** + * Exception thrown by the runtime in case an invalidated machine code is called. + */ +public final class InvalidInstalledCodeException extends Exception { + + private static final long serialVersionUID = -3540232440794244844L; +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.code/src/com/oracle/jvmci/code/MemoryBarriers.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.code/src/com/oracle/jvmci/code/MemoryBarriers.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,121 @@ +/* + * Copyright (c) 2011, 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.code; + +/** + * Constants and intrinsic definition for memory barriers. + * + * The documentation for each constant is taken from Doug Lea's The JSR-133 Cookbook for Compiler + * Writers. + *

      + * The {@code JMM_*} constants capture the memory barriers necessary to implement the Java Memory + * Model with respect to volatile field accesses. Their values are explained by this comment from + * templateTable_i486.cpp in the HotSpot source code: + * + *

      + * Volatile variables demand their effects be made known to all CPU's in
      + * order.  Store buffers on most chips allow reads & writes to reorder; the
      + * JMM's ReadAfterWrite.java test fails in -Xint mode without some kind of
      + * memory barrier (i.e., it's not sufficient that the interpreter does not
      + * reorder volatile references, the hardware also must not reorder them).
      + *
      + * According to the new Java Memory Model (JMM):
      + * (1) All volatiles are serialized wrt to each other.
      + * ALSO reads & writes act as acquire & release, so:
      + * (2) A read cannot let unrelated NON-volatile memory refs that happen after
      + * the read float up to before the read.  It's OK for non-volatile memory refs
      + * that happen before the volatile read to float down below it.
      + * (3) Similarly, a volatile write cannot let unrelated NON-volatile memory refs
      + * that happen BEFORE the write float down to after the write.  It's OK for
      + * non-volatile memory refs that happen after the volatile write to float up
      + * before it.
      + *
      + * We only put in barriers around volatile refs (they are expensive), not
      + * _between_ memory refs (which would require us to track the flavor of the
      + * previous memory refs).  Requirements (2) and (3) require some barriers
      + * before volatile stores and after volatile loads.  These nearly cover
      + * requirement (1) but miss the volatile-store-volatile-load case.  This final
      + * case is placed after volatile-stores although it could just as well go
      + * before volatile-loads.
      + * 
      + */ +public class MemoryBarriers { + + /** + * The sequence {@code Load1; LoadLoad; Load2} ensures that {@code Load1}'s data are loaded + * before data accessed by {@code Load2} and all subsequent load instructions are loaded. In + * general, explicit {@code LoadLoad} barriers are needed on processors that perform speculative + * loads and/or out-of-order processing in which waiting load instructions can bypass waiting + * stores. On processors that guarantee to always preserve load ordering, these barriers amount + * to no-ops. + */ + public static final int LOAD_LOAD = 0x0001; + + /** + * The sequence {@code Load1; LoadStore; Store2} ensures that {@code Load1}'s data are loaded + * before all data associated with {@code Store2} and subsequent store instructions are flushed. + * {@code LoadStore} barriers are needed only on those out-of-order processors in which waiting + * store instructions can bypass loads. + */ + public static final int LOAD_STORE = 0x0002; + + /** + * The sequence {@code Store1; StoreLoad; Load2} ensures that {@code Store1}'s data are made + * visible to other processors (i.e., flushed to main memory) before data accessed by + * {@code Load2} and all subsequent load instructions are loaded. {@code StoreLoad} barriers + * protect against a subsequent load incorrectly using {@code Store1}'s data value rather than + * that from a more recent store to the same location performed by a different processor. + * Because of this, on the processors discussed below, a {@code StoreLoad} is strictly necessary + * only for separating stores from subsequent loads of the same location(s) as were stored + * before the barrier. {@code StoreLoad} barriers are needed on nearly all recent + * multiprocessors, and are usually the most expensive kind. Part of the reason they are + * expensive is that they must disable mechanisms that ordinarily bypass cache to satisfy loads + * from write-buffers. This might be implemented by letting the buffer fully flush, among other + * possible stalls. + */ + public static final int STORE_LOAD = 0x0004; + + /** + * The sequence {@code Store1; StoreStore; Store2} ensures that {@code Store1}'s data are + * visible to other processors (i.e., flushed to memory) before the data associated with + * {@code Store2} and all subsequent store instructions. In general, {@code StoreStore} barriers + * are needed on processors that do not otherwise guarantee strict ordering of flushes from + * write buffers and/or caches to other processors or main memory. + */ + public static final int STORE_STORE = 0x0008; + + public static final int JMM_PRE_VOLATILE_WRITE = LOAD_STORE | STORE_STORE; + public static final int JMM_POST_VOLATILE_WRITE = STORE_LOAD | STORE_STORE; + public static final int JMM_PRE_VOLATILE_READ = 0; + public static final int JMM_POST_VOLATILE_READ = LOAD_LOAD | LOAD_STORE; + + public static String barriersString(int barriers) { + StringBuilder sb = new StringBuilder(); + sb.append((barriers & LOAD_LOAD) != 0 ? "LOAD_LOAD " : ""); + sb.append((barriers & LOAD_STORE) != 0 ? "LOAD_STORE " : ""); + sb.append((barriers & STORE_LOAD) != 0 ? "STORE_LOAD " : ""); + sb.append((barriers & STORE_STORE) != 0 ? "STORE_STORE " : ""); + return sb.toString().trim(); + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.code/src/com/oracle/jvmci/code/ReferenceMap.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.code/src/com/oracle/jvmci/code/ReferenceMap.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2009, 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.code; + +import com.oracle.jvmci.meta.*; + +public abstract class ReferenceMap { + + /** + * Empty out the reference map. + */ + public abstract void reset(); + + /** + * Add {@code value} to the current set of reference values. + * + * @param v + */ + public abstract void addLiveValue(Value v); + + /** + * Perform any final encoding needed before use. + */ + public abstract void finish(); +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.code/src/com/oracle/jvmci/code/Register.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.code/src/com/oracle/jvmci/code/Register.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,241 @@ +/* + * Copyright (c) 2009, 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.code; + +import com.oracle.jvmci.meta.*; + +/** + * Represents a target machine register. + */ +public final class Register implements Comparable { + + public static final RegisterCategory SPECIAL = new RegisterCategory("SPECIAL"); + + /** + * Invalid register. + */ + public static final Register None = new Register(-1, -1, "noreg", SPECIAL); + + /** + * Frame pointer of the current method. All spill slots and outgoing stack-based arguments are + * addressed relative to this register. + */ + public static final Register Frame = new Register(-2, -2, "framereg", SPECIAL); + + public static final Register CallerFrame = new Register(-3, -3, "callerframereg", SPECIAL); + + /** + * The identifier for this register that is unique across all the registers in a + * {@link Architecture}. A valid register has {@code number > 0}. + */ + public final int number; + + /** + * The mnemonic of this register. + */ + public final String name; + + /** + * The actual encoding in a target machine instruction for this register, which may or may not + * be the same as {@link #number}. + */ + public final int encoding; + + /** + * The assembler calls this method to get the register's encoding. + */ + public int encoding() { + return encoding; + } + + /** + * A platform specific register category that describes which values can be stored in a + * register. + */ + private final RegisterCategory registerCategory; + + /** + * A platform specific register type that describes which values can be stored in a register. + */ + public static class RegisterCategory { + + private final String name; + + private final int referenceMapOffset; + private final int referenceMapShift; + + public RegisterCategory(String name) { + this(name, 0, 0); + } + + public RegisterCategory(String name, int referenceMapOffset) { + this(name, referenceMapOffset, 0); + } + + public RegisterCategory(String name, int referenceMapOffset, int referenceMapShift) { + this.name = name; + this.referenceMapOffset = referenceMapOffset; + this.referenceMapShift = referenceMapShift; + } + + @Override + public String toString() { + return name; + } + + @Override + public int hashCode() { + return 23 + name.hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof RegisterCategory) { + RegisterCategory that = (RegisterCategory) obj; + return this.referenceMapOffset == that.referenceMapOffset && this.referenceMapShift == that.referenceMapShift && this.name.equals(that.name); + } + return false; + } + } + + /** + * Creates a {@link Register} instance. + * + * @param number unique identifier for the register + * @param encoding the target machine encoding for the register + * @param name the mnemonic name for the register + * @param registerCategory the register category + */ + public Register(int number, int encoding, String name, RegisterCategory registerCategory) { + this.number = number; + this.name = name; + this.registerCategory = registerCategory; + this.encoding = encoding; + } + + public RegisterCategory getRegisterCategory() { + return registerCategory; + } + + /** + * Get the start index of this register in the {@link ReferenceMap}. + */ + public int getReferenceMapIndex() { + return (encoding << registerCategory.referenceMapShift) + registerCategory.referenceMapOffset; + } + + /** + * Gets this register as a {@linkplain RegisterValue value} with a specified kind. + * + * @param kind the specified kind + * @return the {@link RegisterValue} + */ + public RegisterValue asValue(LIRKind kind) { + return new RegisterValue(kind, this); + } + + /** + * Gets this register as a {@linkplain RegisterValue value} with no particular kind. + * + * @return a {@link RegisterValue} with {@link Kind#Illegal} kind. + */ + public RegisterValue asValue() { + return asValue(LIRKind.Illegal); + } + + /** + * Determines if this is a valid register. + * + * @return {@code true} iff this register is valid + */ + public boolean isValid() { + return number >= 0; + } + + /** + * Gets the maximum register {@linkplain #number number} in a given set of registers. + * + * @param registers the set of registers to process + * @return the maximum register number for any register in {@code registers} + */ + public static int maxRegisterNumber(Register[] registers) { + int max = Integer.MIN_VALUE; + for (Register r : registers) { + if (r.number > max) { + max = r.number; + } + } + return max; + } + + /** + * Gets the maximum register {@linkplain #encoding encoding} in a given set of registers. + * + * @param registers the set of registers to process + * @return the maximum register encoding for any register in {@code registers} + */ + public static int maxRegisterEncoding(Register[] registers) { + int max = Integer.MIN_VALUE; + for (Register r : registers) { + if (r.encoding > max) { + max = r.encoding; + } + } + return max; + } + + @Override + public String toString() { + return name; + } + + @Override + public int compareTo(Register o) { + if (number < o.number) { + return -1; + } + if (number > o.number) { + return 1; + } + return 0; + } + + @Override + public int hashCode() { + return 17 + name.hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof Register) { + Register other = (Register) obj; + if (number == other.number) { + assert name.equals(other.name); + assert encoding == other.encoding; + assert registerCategory.equals(other.registerCategory); + return true; + } + } + return false; + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.code/src/com/oracle/jvmci/code/RegisterAttributes.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.code/src/com/oracle/jvmci/code/RegisterAttributes.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2010, 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.code; + +import java.util.*; + +/** + * A collection of register attributes. The specific attribute values for a register may be local to + * a compilation context. For example, a {@link RegisterConfig} in use during a compilation will + * determine which registers are callee saved. + */ +public class RegisterAttributes { + + private final boolean callerSave; + private final boolean calleeSave; + private final boolean allocatable; + + public RegisterAttributes(boolean isCallerSave, boolean isCalleeSave, boolean isAllocatable) { + this.callerSave = isCallerSave; + this.calleeSave = isCalleeSave; + this.allocatable = isAllocatable; + } + + public static final RegisterAttributes NONE = new RegisterAttributes(false, false, false); + + /** + * Creates a map from register {@linkplain Register#number numbers} to register + * {@linkplain RegisterAttributes attributes} for a given register configuration and set of + * registers. + * + * @param registerConfig a register configuration + * @param registers a set of registers + * @return an array whose length is the max register number in {@code registers} plus 1. An + * element at index i holds the attributes of the register whose number is i. + */ + public static RegisterAttributes[] createMap(RegisterConfig registerConfig, Register[] registers) { + RegisterAttributes[] map = new RegisterAttributes[registers.length]; + for (Register reg : registers) { + if (reg != null) { + CalleeSaveLayout csl = registerConfig.getCalleeSaveLayout(); + RegisterAttributes attr = new RegisterAttributes(Arrays.asList(registerConfig.getCallerSaveRegisters()).contains(reg), + csl == null ? false : Arrays.asList(csl.registers).contains(reg), Arrays.asList(registerConfig.getAllocatableRegisters()).contains(reg)); + if (map.length <= reg.number) { + map = Arrays.copyOf(map, reg.number + 1); + } + map[reg.number] = attr; + } + } + for (int i = 0; i < map.length; i++) { + if (map[i] == null) { + map[i] = NONE; + } + } + return map; + } + + /** + * @return Denotes a register that is available for use by a register allocator. + */ + public boolean isAllocatable() { + return allocatable; + } + + /** + * @return Denotes a register whose value preservation (if required) across a call is the + * responsibility of the callee. + */ + public boolean isCalleeSave() { + return calleeSave; + } + + /** + * @return Denotes a register whose value preservation (if required) across a call is the + * responsibility of the caller. + */ + public boolean isCallerSave() { + return callerSave; + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.code/src/com/oracle/jvmci/code/RegisterConfig.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.code/src/com/oracle/jvmci/code/RegisterConfig.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,124 @@ +/* + * 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.code; + +import com.oracle.jvmci.meta.Kind; +import com.oracle.jvmci.meta.JavaType; +import com.oracle.jvmci.meta.PlatformKind; +import com.oracle.jvmci.code.CallingConvention.Type; + +/** + * A register configuration binds roles and {@linkplain RegisterAttributes attributes} to physical + * registers. + */ +public interface RegisterConfig { + + /** + * Gets the register to be used for returning a value of a given kind. + */ + Register getReturnRegister(Kind kind); + + /** + * Gets the maximum allowed size of the frame. + */ + default int getMaximumFrameSize() { + return Integer.MAX_VALUE; + } + + /** + * Gets the register to which {@link Register#Frame} and {@link Register#CallerFrame} are bound. + */ + Register getFrameRegister(); + + /** + * Gets the calling convention describing how arguments are passed. + * + * @param type the type of calling convention being requested + * @param returnType the return type (can be null for methods returning {@code void}) + * @param parameterTypes the types of the arguments of the call + * @param target the target platform + * @param stackOnly ignore registers + */ + CallingConvention getCallingConvention(Type type, JavaType returnType, JavaType[] parameterTypes, TargetDescription target, boolean stackOnly); + + /** + * Gets the ordered set of registers that are can be used to pass parameters according to a + * given calling convention. + * + * @param type the type of calling convention + * @param kind specifies what kind of registers is being requested + * @return the ordered set of registers that may be used to pass parameters in a call conforming + * to {@code type} + */ + Register[] getCallingConventionRegisters(Type type, Kind kind); + + /** + * Gets the set of all registers that might be used by the register allocator. + * + * To get the set of registers the register allocator is allowed to use see + * {@link RegisterAllocationConfig#getAllocatableRegisters()} + */ + @SuppressWarnings("javadoc") + Register[] getAllocatableRegisters(); + + /** + * Filters a set of registers and returns only those that can be used by the register allocator + * for a value of a particular kind. + */ + Register[] filterAllocatableRegisters(PlatformKind kind, Register[] registers); + + /** + * Gets the registers whose values must be preserved by a method across any call it makes. + */ + Register[] getCallerSaveRegisters(); + + /** + * Gets the layout of the callee save area of this register configuration. + * + * @return {@code null} if there is no callee save area + */ + CalleeSaveLayout getCalleeSaveLayout(); + + /** + * Gets a map from register {@linkplain Register#number numbers} to register + * {@linkplain RegisterAttributes attributes} for this register configuration. + * + * @return an array where an element at index i holds the attributes of the register whose + * number is i + */ + RegisterAttributes[] getAttributesMap(); + + /** + * Gets the register corresponding to a runtime-defined role. + * + * @param id the identifier of a runtime-defined register role + * @return the register playing the role specified by {@code id} + */ + Register getRegisterForRole(int id); + + /** + * Determines if all {@link #getAllocatableRegisters() allocatable} registers are + * {@link #getCallerSaveRegisters() caller saved}. + */ + boolean areAllAllocatableRegistersCallerSaved(); +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.code/src/com/oracle/jvmci/code/RegisterSaveLayout.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.code/src/com/oracle/jvmci/code/RegisterSaveLayout.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,127 @@ +/* + * 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.code; + +import java.util.*; + +/** + * A map from registers to frame slots. This can be used to describe where callee saved registers + * are saved in a callee's frame. + */ +public final class RegisterSaveLayout { + + /** + * Keys. + */ + private final Register[] registers; + + /** + * Slot indexes relative to stack pointer. + */ + private final int[] slots; + + /** + * Creates a map from registers to frame slots. + * + * @param registers the keys in the map + * @param slots frame slot index for each register in {@code registers} + */ + public RegisterSaveLayout(Register[] registers, int[] slots) { + assert registers.length == slots.length; + this.registers = registers; + this.slots = slots; + assert registersToSlots(false).size() == registers.length : "non-unique registers"; + assert new HashSet<>(registersToSlots(false).values()).size() == slots.length : "non-unqiue slots"; + } + + /** + * Gets the frame slot index for a given register. + * + * @param register register to get the frame slot index for + * @return frame slot index + */ + public int registerToSlot(Register register) { + for (int i = 0; i < registers.length; i++) { + if (register.equals(registers[i])) { + return slots[i]; + } + } + throw new IllegalArgumentException(register + " not saved by this layout: " + this); + } + + /** + * Gets this layout information as a {@link Map} from registers to slots. + */ + public Map registersToSlots(boolean sorted) { + Map result; + if (sorted) { + result = new TreeMap<>(); + } else { + result = new HashMap<>(); + } + for (int i = 0; i < registers.length; i++) { + result.put(registers[i], slots[i]); + } + return result; + } + + /** + * Gets this layout information as a {@link Map} from slots to registers. + */ + public Map slotsToRegisters(boolean sorted) { + Map result; + if (sorted) { + result = new TreeMap<>(); + } else { + result = new HashMap<>(); + } + for (int i = 0; i < registers.length; i++) { + result.put(slots[i], registers[i]); + } + return result; + } + + @Override + public int hashCode() { + throw new UnsupportedOperationException(); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof RegisterSaveLayout) { + RegisterSaveLayout that = (RegisterSaveLayout) obj; + if (Arrays.equals(registers, that.registers) && Arrays.equals(slots, that.slots)) { + return true; + } + } + return false; + } + + @Override + public String toString() { + return registersToSlots(true).toString(); + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.code/src/com/oracle/jvmci/code/RegisterValue.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.code/src/com/oracle/jvmci/code/RegisterValue.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2009, 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.code; + +import com.oracle.jvmci.meta.*; + +/** + * Denotes a register that stores a value of a fixed kind. There is exactly one (canonical) instance + * of {@link RegisterValue} for each ({@link Register}, {@link Kind}) pair. Use + * {@link Register#asValue(LIRKind)} to retrieve the canonical {@link RegisterValue} instance for a + * given (register,kind) pair. + */ +public final class RegisterValue extends AllocatableValue { + + private final Register reg; + + /** + * Should only be called from {@link Register#Register} to ensure canonicalization. + */ + protected RegisterValue(LIRKind kind, Register register) { + super(kind); + this.reg = register; + } + + @Override + public String toString() { + return getRegister().name + getKindSuffix(); + } + + /** + * @return the register that contains the value + */ + public Register getRegister() { + return reg; + } + + @Override + public int hashCode() { + return 29 * super.hashCode() + reg.hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof RegisterValue) { + RegisterValue other = (RegisterValue) obj; + return super.equals(obj) && reg.equals(other.reg); + } + return false; + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.code/src/com/oracle/jvmci/code/SourceStackTrace.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.code/src/com/oracle/jvmci/code/SourceStackTrace.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,50 @@ +/* + * 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.jvmci.code; + +/** + * Class representing a exception with a stack trace of the currently processed position in the + * compiled Java program instead of the stack trace of the compiler. The exception of the compiler + * is saved as the cause of this exception. + */ +public abstract class SourceStackTrace extends BailoutException { + private static final long serialVersionUID = 2144811793442316776L; + + public static SourceStackTrace create(Throwable cause, String format, StackTraceElement[] elements) { + return new SourceStackTrace(cause, format) { + + private static final long serialVersionUID = 6279381376051787907L; + + @Override + public final synchronized Throwable fillInStackTrace() { + assert elements != null; + setStackTrace(elements); + return this; + } + }; + } + + private SourceStackTrace(Throwable cause, String format) { + super(cause, format); + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.code/src/com/oracle/jvmci/code/StackLockValue.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.code/src/com/oracle/jvmci/code/StackLockValue.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2011, 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.code; + +import com.oracle.jvmci.meta.JavaValue; +import com.oracle.jvmci.meta.AbstractValue; +import com.oracle.jvmci.meta.Value; +import com.oracle.jvmci.meta.LIRKind; +import static com.oracle.jvmci.code.ValueUtil.*; + +/** + * Represents lock information in the debug information. + */ +public final class StackLockValue extends AbstractValue implements JavaValue { + + private Value owner; + private StackSlotValue slot; + private final boolean eliminated; + + public StackLockValue(Value object, StackSlotValue slot, boolean eliminated) { + super(LIRKind.Illegal); + this.owner = object; + this.slot = slot; + this.eliminated = eliminated; + } + + public Value getOwner() { + return owner; + } + + public void setOwner(Value newOwner) { + this.owner = newOwner; + } + + public Value getSlot() { + return slot; + } + + public boolean isEliminated() { + return eliminated; + } + + @Override + public String toString() { + return "monitor[" + owner + (slot != null ? ", " + slot : "") + (eliminated ? ", eliminated" : "") + "]"; + } + + @Override + public int hashCode() { + final int prime = 43; + int result = super.hashCode(); + result = prime * result + (eliminated ? 1231 : 1237); + result = prime * result + owner.hashCode(); + result = prime * result + slot.hashCode(); + return result; + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof StackLockValue) { + StackLockValue other = (StackLockValue) obj; + return super.equals(obj) && eliminated == other.eliminated && owner.equals(other.owner) && slot.equals(other.slot); + } + return false; + } + + public void setSlot(StackSlotValue stackSlot) { + assert slot == null || (isVirtualStackSlot(slot) && (slot.equals(stackSlot) || isStackSlot(stackSlot))) : String.format("Can not set slot for %s to %s", this, stackSlot); + slot = stackSlot; + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.code/src/com/oracle/jvmci/code/StackSlot.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.code/src/com/oracle/jvmci/code/StackSlot.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,134 @@ +/* + * Copyright (c) 2010, 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.code; + +import com.oracle.jvmci.meta.LIRKind; + +/** + * Represents a compiler spill slot or an outgoing stack-based argument in a method's frame or an + * incoming stack-based argument in a method's {@linkplain #isInCallerFrame() caller's frame}. + */ +public final class StackSlot extends StackSlotValue { + + private final int offset; + private final boolean addFrameSize; + + /** + * Gets a {@link StackSlot} instance representing a stack slot at a given index holding a value + * of a given kind. + * + * @param kind The kind of the value stored in the stack slot. + * @param offset The offset of the stack slot (in bytes) + * @param addFrameSize Specifies if the offset is relative to the stack pointer, or the + * beginning of the frame (stack pointer + total frame size). + */ + public static StackSlot get(LIRKind kind, int offset, boolean addFrameSize) { + assert addFrameSize || offset >= 0; + return new StackSlot(kind, offset, addFrameSize); + } + + /** + * Private constructor to enforce use of {@link #get(LIRKind, int, boolean)} so that a cache can + * be used. + */ + private StackSlot(LIRKind kind, int offset, boolean addFrameSize) { + super(kind); + this.offset = offset; + this.addFrameSize = addFrameSize; + } + + /** + * Gets the offset of this stack slot, relative to the stack pointer. + * + * @return The offset of this slot (in bytes). + */ + public int getOffset(int totalFrameSize) { + assert totalFrameSize > 0 || !addFrameSize; + int result = offset + (addFrameSize ? totalFrameSize : 0); + assert result >= 0; + return result; + } + + public boolean isInCallerFrame() { + return addFrameSize && offset >= 0; + } + + public int getRawOffset() { + return offset; + } + + public boolean getRawAddFrameSize() { + return addFrameSize; + } + + @Override + public String toString() { + if (!addFrameSize) { + return "out:" + offset + getKindSuffix(); + } else if (offset >= 0) { + return "in:" + offset + getKindSuffix(); + } else { + return "stack:" + (-offset) + getKindSuffix(); + } + } + + /** + * Gets this stack slot used to pass an argument from the perspective of a caller. + */ + public StackSlot asOutArg() { + assert offset >= 0; + if (addFrameSize) { + return get(getLIRKind(), offset, false); + } + return this; + } + + /** + * Gets this stack slot used to pass an argument from the perspective of a callee. + */ + public StackSlot asInArg() { + assert offset >= 0; + if (!addFrameSize) { + return get(getLIRKind(), offset, true); + } + return this; + } + + @Override + public int hashCode() { + final int prime = 37; + int result = super.hashCode(); + result = prime * result + (addFrameSize ? 1231 : 1237); + result = prime * result + offset; + return result; + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof StackSlot) { + StackSlot other = (StackSlot) obj; + return super.equals(obj) && addFrameSize == other.addFrameSize && offset == other.offset; + } + return false; + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.code/src/com/oracle/jvmci/code/StackSlotValue.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.code/src/com/oracle/jvmci/code/StackSlotValue.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,38 @@ +/* + * 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.code; + +import com.oracle.jvmci.meta.AllocatableValue; +import com.oracle.jvmci.meta.LIRKind; + +/** + * Common base class for {@linkplain StackSlot real} and {@linkplain VirtualStackSlot virtual} stack + * slots. + */ +public abstract class StackSlotValue extends AllocatableValue { + + public StackSlotValue(LIRKind lirKind) { + super(lirKind); + } + +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.code/src/com/oracle/jvmci/code/TargetDescription.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.code/src/com/oracle/jvmci/code/TargetDescription.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,143 @@ +/* + * Copyright (c) 2009, 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.code; + +import com.oracle.jvmci.meta.Kind; +import com.oracle.jvmci.meta.PlatformKind; +import com.oracle.jvmci.meta.LIRKind; +import static com.oracle.jvmci.meta.MetaUtil.*; + +/** + * Represents the target machine for a compiler, including the CPU architecture, the size of + * pointers and references, alignment of stacks, caches, etc. + */ +public abstract class TargetDescription { + + public final Architecture arch; + + /** + * Specifies if this is a multi-processor system. + */ + public final boolean isMP; + + /** + * Specifies if this target supports encoding objects inline in the machine code. + */ + public final boolean inlineObjects; + + /** + * The machine word size on this target. + */ + public final int wordSize; + + /** + * The kind to be used for representing raw pointers and CPU registers. + */ + public final Kind wordKind; + + /** + * The stack alignment requirement of the platform. For example, from Appendix D of Intel 64 and IA-32 Architectures + * Optimization Reference Manual: + * + *
      +     *     "It is important to ensure that the stack frame is aligned to a
      +     *      16-byte boundary upon function entry to keep local __m128 data,
      +     *      parameters, and XMM register spill locations aligned throughout
      +     *      a function invocation."
      +     * 
      + */ + public final int stackAlignment; + + /** + * Maximum constant displacement at which a memory access can no longer be an implicit null + * check. + */ + public final int implicitNullCheckLimit; + + public TargetDescription(Architecture arch, boolean isMP, int stackAlignment, int implicitNullCheckLimit, boolean inlineObjects) { + this.arch = arch; + this.isMP = isMP; + this.wordSize = arch.getWordSize(); + this.wordKind = Kind.fromWordSize(wordSize); + this.stackAlignment = stackAlignment; + this.implicitNullCheckLimit = implicitNullCheckLimit; + this.inlineObjects = inlineObjects; + } + + @Override + public final int hashCode() { + throw new UnsupportedOperationException(); + } + + @Override + public final boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof TargetDescription) { + TargetDescription that = (TargetDescription) obj; + // @formatter:off + if (this.implicitNullCheckLimit == that.implicitNullCheckLimit && + this.inlineObjects == that.inlineObjects && + this.isMP == that.isMP && + this.stackAlignment == that.stackAlignment && + this.wordKind.equals(that.wordKind) && + this.wordSize == that.wordSize && + this.arch.equals(that.arch)) { + return true; + } + // @formatter:on + } + return false; + } + + @Override + public String toString() { + return identityHashCodeString(this); + } + + public int getSizeInBytes(PlatformKind kind) { + return arch.getSizeInBytes(kind); + } + + public LIRKind getLIRKind(Kind javaKind) { + switch (javaKind) { + case Boolean: + case Byte: + case Short: + case Char: + case Int: + case Long: + case Float: + case Double: + return LIRKind.value(javaKind); + case Object: + return LIRKind.reference(javaKind); + default: + return LIRKind.Illegal; + } + } + + public abstract ReferenceMap createReferenceMap(boolean hasRegisters, int stackSlotCount); +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.code/src/com/oracle/jvmci/code/TypeCheckHints.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.code/src/com/oracle/jvmci/code/TypeCheckHints.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,160 @@ +/* + * 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.code; + +import com.oracle.jvmci.meta.JavaTypeProfile; +import com.oracle.jvmci.meta.ResolvedJavaType; +import com.oracle.jvmci.meta.Assumptions; +import java.util.*; + +import com.oracle.jvmci.meta.Assumptions.AssumptionResult; +import com.oracle.jvmci.meta.JavaTypeProfile.ProfiledType; + +/** + * Utility for deriving hint types for a type check instruction (e.g. checkcast or instanceof) based + * on the target type of the check and any profiling information available for the instruction. + */ +public class TypeCheckHints { + + /** + * A receiver type profiled in a type check instruction. + */ + public static class Hint { + + /** + * A type seen while profiling a type check instruction. + */ + public final ResolvedJavaType type; + + /** + * Specifies if {@link #type} is a sub-type of the checked type. + */ + public final boolean positive; + + Hint(ResolvedJavaType type, boolean positive) { + this.type = type; + this.positive = positive; + } + } + + private static final Hint[] NO_HINTS = {}; + + /** + * If non-null, then this is the only type that could pass the type check because the target of + * the type check is a final class or has been speculated to be a final class and this value is + * the only concrete subclass of the target type. + */ + public final ResolvedJavaType exact; + + /** + * The most likely types that the type check instruction will see. + */ + public final Hint[] hints; + + /** + * The profile from which this information was derived. + */ + public final JavaTypeProfile profile; + + /** + * The total probability that the type check will hit one of the types in {@link #hints}. + */ + public final double hintHitProbability; + + /** + * Derives hint information for use when generating the code for a type check instruction. + * + * @param targetType the target type of the type check + * @param profile the profiling information available for the instruction (if any) + * @param assumptions the object in which speculations are recorded. This is null if + * speculations are not supported. + * @param minHintHitProbability if the probability that the type check will hit one of the + * profiled types (up to {@code maxHints}) is below this value, then {@link #hints} + * will be null + * @param maxHints the maximum length of {@link #hints} + */ + public TypeCheckHints(ResolvedJavaType targetType, JavaTypeProfile profile, Assumptions assumptions, double minHintHitProbability, int maxHints) { + this.profile = profile; + if (targetType != null && !canHaveSubtype(targetType)) { + exact = targetType; + } else { + if (assumptions != null) { + AssumptionResult leafConcreteSubtype = targetType == null ? null : targetType.findLeafConcreteSubtype(); + if (leafConcreteSubtype != null) { + assumptions.record(leafConcreteSubtype); + exact = leafConcreteSubtype.getResult(); + } else { + exact = null; + } + } else { + exact = null; + } + } + Double[] hitProbability = {null}; + this.hints = makeHints(targetType, profile, minHintHitProbability, maxHints, hitProbability); + this.hintHitProbability = hitProbability[0]; + } + + private static Hint[] makeHints(ResolvedJavaType targetType, JavaTypeProfile profile, double minHintHitProbability, int maxHints, Double[] hitProbability) { + double hitProb = 0.0d; + Hint[] hintsBuf = NO_HINTS; + if (profile != null) { + double notRecordedTypes = profile.getNotRecordedProbability(); + ProfiledType[] ptypes = profile.getTypes(); + if (notRecordedTypes < (1D - minHintHitProbability) && ptypes != null && ptypes.length > 0) { + hintsBuf = new Hint[ptypes.length]; + int hintCount = 0; + for (ProfiledType ptype : ptypes) { + if (targetType != null) { + ResolvedJavaType hintType = ptype.getType(); + hintsBuf[hintCount++] = new Hint(hintType, targetType.isAssignableFrom(hintType)); + hitProb += ptype.getProbability(); + } + if (hintCount == maxHints) { + break; + } + } + if (hitProb >= minHintHitProbability) { + if (hintsBuf.length != hintCount || hintCount > maxHints) { + hintsBuf = Arrays.copyOf(hintsBuf, Math.min(maxHints, hintCount)); + } + } else { + hintsBuf = NO_HINTS; + hitProb = 0.0d; + } + } + } + hitProbability[0] = hitProb; + return hintsBuf; + } + + /** + * Determines if a given type can have subtypes other than itself. This analysis is purely + * static; no assumptions are made. + * + * @return true if {@code type} can have subtypes + */ + public static boolean canHaveSubtype(ResolvedJavaType type) { + return !type.getElementalType().isFinal(); + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.code/src/com/oracle/jvmci/code/UnsignedMath.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.code/src/com/oracle/jvmci/code/UnsignedMath.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,124 @@ +/* + * Copyright (c) 2011, 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.code; + +import java.math.*; + +//JaCoCo Exclude + +/** + * Utilities for unsigned comparisons. All methods have correct, but slow, standard Java + * implementations so that they can be used with compilers not supporting the intrinsics. + */ +public class UnsignedMath { + + private static final long MASK = 0xffffffffL; + + /** + * Unsigned comparison aboveThan for two numbers. + */ + public static boolean aboveThan(int a, int b) { + return (a & MASK) > (b & MASK); + } + + /** + * Unsigned comparison aboveOrEqual for two numbers. + */ + public static boolean aboveOrEqual(int a, int b) { + return (a & MASK) >= (b & MASK); + } + + /** + * Unsigned comparison belowThan for two numbers. + */ + public static boolean belowThan(int a, int b) { + return (a & MASK) < (b & MASK); + } + + /** + * Unsigned comparison belowOrEqual for two numbers. + */ + public static boolean belowOrEqual(int a, int b) { + return (a & MASK) <= (b & MASK); + } + + /** + * Unsigned comparison aboveThan for two numbers. + */ + public static boolean aboveThan(long a, long b) { + return (a > b) ^ ((a < 0) != (b < 0)); + } + + /** + * Unsigned comparison aboveOrEqual for two numbers. + */ + public static boolean aboveOrEqual(long a, long b) { + return (a >= b) ^ ((a < 0) != (b < 0)); + } + + /** + * Unsigned comparison belowThan for two numbers. + */ + public static boolean belowThan(long a, long b) { + return (a < b) ^ ((a < 0) != (b < 0)); + } + + /** + * Unsigned comparison belowOrEqual for two numbers. + */ + public static boolean belowOrEqual(long a, long b) { + return (a <= b) ^ ((a < 0) != (b < 0)); + } + + /** + * Unsigned division for two numbers. + */ + public static int divide(int a, int b) { + return (int) ((a & MASK) / (b & MASK)); + } + + /** + * Unsigned remainder for two numbers. + */ + public static int remainder(int a, int b) { + return (int) ((a & MASK) % (b & MASK)); + } + + /** + * Unsigned division for two numbers. + */ + public static long divide(long a, long b) { + return bi(a).divide(bi(b)).longValue(); + } + + /** + * Unsigned remainder for two numbers. + */ + public static long remainder(long a, long b) { + return bi(a).remainder(bi(b)).longValue(); + } + + private static BigInteger bi(long unsigned) { + return unsigned >= 0 ? BigInteger.valueOf(unsigned) : BigInteger.valueOf(unsigned & 0x7fffffffffffffffL).setBit(63); + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.code/src/com/oracle/jvmci/code/ValueUtil.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.code/src/com/oracle/jvmci/code/ValueUtil.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,189 @@ +/* + * 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.code; + +import com.oracle.jvmci.meta.Kind; +import com.oracle.jvmci.meta.Value; +import com.oracle.jvmci.meta.AllocatableValue; +import com.oracle.jvmci.meta.JavaConstant; +import java.util.*; + +/** + * Utility class for working with the {@link Value} class and its subclasses. + */ +public final class ValueUtil { + + public static boolean isIllegal(Value value) { + assert value != null; + return Value.ILLEGAL.equals(value); + } + + public static boolean isLegal(Value value) { + return !isIllegal(value); + } + + public static boolean isVirtualObject(Value value) { + assert value != null; + return value instanceof VirtualObject; + } + + public static VirtualObject asVirtualObject(Value value) { + assert value != null; + return (VirtualObject) value; + } + + public static boolean isConstant(Value value) { + assert value != null; + return value instanceof JavaConstant; + } + + public static JavaConstant asConstant(Value value) { + assert value != null; + return (JavaConstant) value; + } + + public static boolean isAllocatableValue(Value value) { + assert value != null; + return value instanceof AllocatableValue; + } + + public static AllocatableValue asAllocatableValue(Value value) { + assert value != null; + return (AllocatableValue) value; + } + + public static boolean isStackSlot(Value value) { + assert value != null; + return value instanceof StackSlot; + } + + public static StackSlot asStackSlot(Value value) { + assert value != null; + return (StackSlot) value; + } + + public static boolean isStackSlotValue(Value value) { + assert value != null; + return value instanceof StackSlotValue; + } + + public static StackSlotValue asStackSlotValue(Value value) { + assert value != null; + return (StackSlotValue) value; + } + + public static boolean isVirtualStackSlot(Value value) { + assert value != null; + return value instanceof VirtualStackSlot; + } + + public static VirtualStackSlot asVirtualStackSlot(Value value) { + assert value != null; + return (VirtualStackSlot) value; + } + + public static boolean isRegister(Value value) { + assert value != null; + return value instanceof RegisterValue; + } + + public static Register asRegister(Value value) { + assert value != null; + return ((RegisterValue) value).getRegister(); + } + + public static Register asIntReg(Value value) { + if (value.getKind().getStackKind() != Kind.Int) { + throw new InternalError("needed Int got: " + value.getKind()); + } else { + return asRegister(value); + } + } + + public static Register asLongReg(Value value) { + if (value.getKind() != Kind.Long) { + throw new InternalError("needed Long got: " + value.getKind()); + } else { + return asRegister(value); + } + } + + public static Register asObjectReg(Value value) { + assert value.getKind() == Kind.Object : value.getKind(); + return asRegister(value); + } + + public static Register asFloatReg(Value value) { + assert value.getKind() == Kind.Float : value.getKind(); + return asRegister(value); + } + + public static Register asDoubleReg(Value value) { + assert value.getKind() == Kind.Double : value.getKind(); + return asRegister(value); + } + + public static boolean sameRegister(Value v1, Value v2) { + return isRegister(v1) && isRegister(v2) && asRegister(v1).equals(asRegister(v2)); + } + + public static boolean sameRegister(Value v1, Value v2, Value v3) { + return sameRegister(v1, v2) && sameRegister(v1, v3); + } + + /** + * Checks if all the provided values are different physical registers. The parameters can be + * either {@link Register registers}, {@link Value values} or arrays of them. All values that + * are not {@link RegisterValue registers} are ignored. + */ + public static boolean differentRegisters(Object... values) { + List registers = collectRegisters(values, new ArrayList()); + for (int i = 1; i < registers.size(); i++) { + Register r1 = registers.get(i); + for (int j = 0; j < i; j++) { + Register r2 = registers.get(j); + if (r1.equals(r2)) { + return false; + } + } + } + return true; + } + + private static List collectRegisters(Object[] values, List registers) { + for (Object o : values) { + if (o instanceof Register) { + registers.add((Register) o); + } else if (o instanceof Value) { + if (isRegister((Value) o)) { + registers.add(asRegister((Value) o)); + } + } else if (o instanceof Object[]) { + collectRegisters((Object[]) o, registers); + } else { + throw new IllegalArgumentException("Not a Register or Value: " + o); + } + } + return registers; + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.code/src/com/oracle/jvmci/code/VirtualObject.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.code/src/com/oracle/jvmci/code/VirtualObject.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,218 @@ +/* + * Copyright (c) 2010, 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.code; + +import com.oracle.jvmci.meta.ResolvedJavaField; +import com.oracle.jvmci.meta.JavaValue; +import com.oracle.jvmci.meta.Kind; +import com.oracle.jvmci.meta.AbstractValue; +import com.oracle.jvmci.meta.Value; +import com.oracle.jvmci.meta.ResolvedJavaType; +import com.oracle.jvmci.meta.LIRKind; +import java.util.*; + +/** + * An instance of this class represents an object whose allocation was removed by escape analysis. + * The information stored in the {@link VirtualObject} is used during deoptimization to recreate the + * object. + */ +public final class VirtualObject extends AbstractValue implements JavaValue { + + private final ResolvedJavaType type; + private Value[] values; + private final int id; + + /** + * Creates a new {@link VirtualObject} for the given type, with the given fields. If + * {@code type} is an instance class then {@code values} provides the values for the fields + * returned by {@link ResolvedJavaType#getInstanceFields(boolean) getInstanceFields(true)}. If + * {@code type} is an array then the length of the values array determines the reallocated array + * length. + * + * @param type the type of the object whose allocation was removed during compilation. This can + * be either an instance of an array type. + * @param values an array containing all the values to be stored into the object when it is + * recreated + * @param id a unique id that identifies the object within the debug information for one + * position in the compiled code. + * @return a new {@link VirtualObject} instance. + */ + public static VirtualObject get(ResolvedJavaType type, Value[] values, int id) { + return new VirtualObject(type, values, id); + } + + private VirtualObject(ResolvedJavaType type, Value[] values, int id) { + super(LIRKind.reference(Kind.Object)); + this.type = type; + this.values = values; + this.id = id; + } + + private static StringBuilder appendValue(StringBuilder buf, Value value, Set visited) { + if (value instanceof VirtualObject) { + VirtualObject vo = (VirtualObject) value; + buf.append("vobject:").append(vo.type.toJavaName(false)).append(':').append(vo.id); + if (!visited.contains(vo)) { + visited.add(vo); + buf.append('{'); + if (vo.values == null) { + buf.append(""); + } else { + if (vo.type.isArray()) { + for (int i = 0; i < vo.values.length; i++) { + if (i != 0) { + buf.append(','); + } + buf.append(i).append('='); + appendValue(buf, vo.values[i], visited); + } + } else { + ResolvedJavaField[] fields = vo.type.getInstanceFields(true); + assert fields.length == vo.values.length : vo.type + ", fields=" + Arrays.toString(fields) + ", values=" + Arrays.toString(vo.values); + for (int i = 0; i < vo.values.length; i++) { + if (i != 0) { + buf.append(','); + } + buf.append(fields[i].getName()).append('='); + appendValue(buf, vo.values[i], visited); + } + } + } + buf.append('}'); + } + } else { + buf.append(value); + } + return buf; + } + + @Override + public String toString() { + Set visited = Collections.newSetFromMap(new IdentityHashMap()); + return appendValue(new StringBuilder(), this, visited).toString(); + } + + /** + * Returns the type of the object whose allocation was removed during compilation. This can be + * either an instance of an array type. + */ + public ResolvedJavaType getType() { + return type; + } + + /** + * Returns an array containing all the values to be stored into the object when it is recreated. + */ + public Value[] getValues() { + return values; + } + + /** + * Returns the unique id that identifies the object within the debug information for one + * position in the compiled code. + */ + public int getId() { + return id; + } + + private static boolean checkValues(ResolvedJavaType type, Value[] values) { + if (values != null) { + if (!type.isArray()) { + ResolvedJavaField[] fields = type.getInstanceFields(true); + int fieldIndex = 0; + for (int i = 0; i < values.length; i++) { + ResolvedJavaField field = fields[fieldIndex++]; + Kind valKind = values[i].getKind().getStackKind(); + if (field.getKind() == Kind.Object) { + assert values[i].getLIRKind().isReference(0) : field + ": " + valKind + " != " + field.getKind(); + } else { + if ((valKind == Kind.Double || valKind == Kind.Long) && field.getKind() == Kind.Int) { + assert fields[fieldIndex].getKind() == Kind.Int; + fieldIndex++; + } else { + assert valKind == field.getKind().getStackKind() : field + ": " + valKind + " != " + field.getKind(); + } + } + } + assert fields.length == fieldIndex : type + ": fields=" + Arrays.toString(fields) + ", field values=" + Arrays.toString(values); + } else { + Kind componentKind = type.getComponentType().getKind().getStackKind(); + if (componentKind == Kind.Object) { + for (int i = 0; i < values.length; i++) { + assert values[i].getLIRKind().isReference(0) : values[i].getKind() + " != " + componentKind; + } + } else { + for (int i = 0; i < values.length; i++) { + assert values[i].getKind() == componentKind || componentKind.getBitCount() >= values[i].getKind().getBitCount() || + (componentKind == Kind.Int && values[i].getKind().getBitCount() >= Kind.Int.getBitCount()) : values[i].getKind() + " != " + componentKind; + } + } + } + } + return true; + } + + /** + * Overwrites the current set of values with a new one. + * + * @param values an array containing all the values to be stored into the object when it is + * recreated. + */ + public void setValues(Value[] values) { + assert checkValues(type, values); + this.values = values; + } + + @Override + public int hashCode() { + return getLIRKind().hashCode() + type.hashCode(); + } + + @Override + public boolean equals(Object o) { + if (o == this) { + return true; + } + if (o instanceof VirtualObject) { + VirtualObject l = (VirtualObject) o; + if (!l.type.equals(type) || l.values.length != values.length) { + return false; + } + for (int i = 0; i < values.length; i++) { + /* + * Virtual objects can form cycles. Calling equals() could therefore lead to + * infinite recursion. + */ + if (!same(values[i], l.values[i])) { + return false; + } + } + return true; + } + return false; + } + + private static boolean same(Object o1, Object o2) { + return o1 == o2; + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.code/src/com/oracle/jvmci/code/VirtualStackSlot.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.code/src/com/oracle/jvmci/code/VirtualStackSlot.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,75 @@ +/* + * 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.code; + +import com.oracle.jvmci.meta.LIRKind; + +/** + * {@link VirtualStackSlot}s are stack slots that are not yet fixed to specific frame offset. They + * are replaced by real {@link StackSlot}s with a fixed position in the frame before code emission. + */ +public abstract class VirtualStackSlot extends StackSlotValue { + + private final int id; + + public VirtualStackSlot(int id, LIRKind lirKind) { + super(lirKind); + this.id = id; + } + + public int getId() { + return id; + } + + @Override + public String toString() { + return "vstack:" + id + getKindSuffix(); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + id; + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (!super.equals(obj)) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + VirtualStackSlot other = (VirtualStackSlot) obj; + if (id != other.id) { + return false; + } + return true; + } + +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.code/src/com/oracle/jvmci/code/package-info.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.code/src/com/oracle/jvmci/code/package-info.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2010, 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 that defines the interface between a Java application that wants to install code and the runtime. + * The runtime provides in implementation of the {@link com.oracle.jvmci.code.CodeCacheProvider} interface. + * The method {@link com.oracle.jvmci.code.CodeCacheProvider#addMethod(com.oracle.jvmci.meta.ResolvedJavaMethod, CompilationResult, com.oracle.jvmci.meta.SpeculationLog, InstalledCode)} + * can be used to install code for a given method. + */ +package com.oracle.jvmci.code; + diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.code/src/com/oracle/jvmci/code/stack/InspectedFrame.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.code/src/com/oracle/jvmci/code/stack/InspectedFrame.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,69 @@ +/* + * 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.code.stack; + +import com.oracle.jvmci.meta.ResolvedJavaMethod; + +public interface InspectedFrame { + + /** + * Returns the value of the local at the given index. Currently only works for object values. + * This value is a copy iff {@link #isVirtual(int)} is true. + */ + Object getLocal(int index); + + /** + * Returns whether the local at the given index is a virtual object, and therefore the object + * returned by {@link #getLocal(int)} is a copy. + */ + boolean isVirtual(int index); + + /** + * Returns true if the stack frame is a compiled stack frame and there are virtual objects + * anywhere in the current state of the compiled method. This can return true even if + * {@link #isVirtual(int)} return false for all locals. + */ + boolean hasVirtualObjects(); + + /** + * This method will materialize all virtual objects, deoptimize the stack frame and make sure + * that subsequent execution of the deoptimized frame uses the materialized values. + */ + void materializeVirtualObjects(boolean invalidateCode); + + /** + * @return the current bytecode index + */ + int getBytecodeIndex(); + + /** + * @return the current method + */ + ResolvedJavaMethod getMethod(); + + /** + * Checks if the current method is equal to the given method. This is semantically equivalent to + * {@code method.equals(getMethod())}, but can be implemented more efficiently. + */ + boolean isMethod(ResolvedJavaMethod method); +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.code/src/com/oracle/jvmci/code/stack/InspectedFrameVisitor.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.code/src/com/oracle/jvmci/code/stack/InspectedFrameVisitor.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,34 @@ +/* + * 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.code.stack; + +/** + * Callback interface for {@link StackIntrospection#iterateFrames}. Implementations of + * {@link #visitFrame} return null to indicate that frame iteration should continue and the next + * caller frame should be visited; and return any non-null value to indicate that frame iteration + * should stop. + */ +public interface InspectedFrameVisitor { + + T visitFrame(InspectedFrame frame); +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.code/src/com/oracle/jvmci/code/stack/StackIntrospection.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.code/src/com/oracle/jvmci/code/stack/StackIntrospection.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,45 @@ +/* + * 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.code.stack; + +import com.oracle.jvmci.meta.ResolvedJavaMethod; + +public interface StackIntrospection { + + /** + * Accesses the current stack, providing {@link InspectedFrame}s to the visitor that can be used + * to inspect the stack frames' contents. Iteration continues as long as + * {@link InspectedFrameVisitor#visitFrame}, which is invoked for every {@link InspectedFrame}, + * returns null. Any non-null result of the visitor indicates that frame iteration should stop. + * + * @param initialMethods if this is non-{@code null}, then the stack trace will start at these + * methods + * @param matchingMethods if this is non-{@code null}, then only matching stack frames are + * returned + * @param initialSkip the number of matching methods to skip (including the initial method) + * @param visitor the visitor that is called for every matching method + * @return the last result returned by the visitor (which is non-null to indicate that iteration + * should stop), or null if the whole stack was iterated. + */ + T iterateFrames(ResolvedJavaMethod[] initialMethods, ResolvedJavaMethod[] matchingMethods, int initialSkip, InspectedFrameVisitor visitor); +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.common/src/com/oracle/jvmci/common/JVMCIError.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.common/src/com/oracle/jvmci/common/JVMCIError.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,139 @@ +/* + * Copyright (c) 2011, 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.common; + +import java.util.*; + +/** + * Indicates a condition in JVMCI related code that should never occur during normal operation. + */ +public class JVMCIError extends Error { + + private static final long serialVersionUID = 531632331813456233L; + private final ArrayList context = new ArrayList<>(); + + public static RuntimeException unimplemented() { + throw new JVMCIError("unimplemented"); + } + + public static RuntimeException unimplemented(String msg) { + throw new JVMCIError("unimplemented: %s", msg); + } + + public static RuntimeException shouldNotReachHere() { + throw new JVMCIError("should not reach here"); + } + + public static RuntimeException shouldNotReachHere(String msg) { + throw new JVMCIError("should not reach here: %s", msg); + } + + public static RuntimeException shouldNotReachHere(Throwable cause) { + throw new JVMCIError(cause); + } + + /** + * Checks a given condition and throws a {@link JVMCIError} if it is false. Guarantees are + * stronger than assertions in that they are always checked. Error messages for guarantee + * violations should clearly indicate the nature of the problem as well as a suggested solution + * if possible. + * + * @param condition the condition to check + * @param msg the message that will be associated with the error, in + * {@link String#format(String, Object...)} syntax + * @param args arguments to the format string + */ + public static void guarantee(boolean condition, String msg, Object... args) { + if (!condition) { + throw new JVMCIError("failed guarantee: " + msg, args); + } + } + + /** + * This constructor creates a {@link JVMCIError} with a message assembled via + * {@link String#format(String, Object...)}. It always uses the ENGLISH locale in order to + * always generate the same output. + * + * @param msg the message that will be associated with the error, in String.format syntax + * @param args parameters to String.format - parameters that implement {@link Iterable} will be + * expanded into a [x, x, ...] representation. + */ + public JVMCIError(String msg, Object... args) { + super(format(msg, args)); + } + + /** + * This constructor creates a {@link JVMCIError} for a given causing Throwable instance. + * + * @param cause the original exception that contains additional information on this error + */ + public JVMCIError(Throwable cause) { + super(cause); + } + + /** + * This constructor creates a {@link JVMCIError} and adds all the + * {@linkplain #addContext(String) context} of another {@link JVMCIError}. + * + * @param e the original {@link JVMCIError} + */ + public JVMCIError(JVMCIError e) { + super(e); + context.addAll(e.context); + } + + @Override + public String toString() { + StringBuilder str = new StringBuilder(); + str.append(super.toString()); + for (String s : context) { + str.append("\n\tat ").append(s); + } + return str.toString(); + } + + private static String format(String msg, Object... args) { + if (args != null) { + // expand Iterable parameters into a list representation + for (int i = 0; i < args.length; i++) { + if (args[i] instanceof Iterable) { + ArrayList list = new ArrayList<>(); + for (Object o : (Iterable) args[i]) { + list.add(o); + } + args[i] = list.toString(); + } + } + } + return String.format(Locale.ENGLISH, msg, args); + } + + public JVMCIError addContext(String newContext) { + this.context.add(newContext); + return this; + } + + public JVMCIError addContext(String name, Object obj) { + return addContext(format("%s: %s", name, obj)); + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.common/src/com/oracle/jvmci/common/UnsafeAccess.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.common/src/com/oracle/jvmci/common/UnsafeAccess.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2012, 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.common; + +import java.lang.reflect.*; + +import sun.misc.*; + +public class UnsafeAccess { + + /** + * An instance of {@link Unsafe} for use within JVMCI. + */ + public static final Unsafe unsafe; + + static { + try { + Field theUnsafeInstance = Unsafe.class.getDeclaredField("theUnsafe"); + theUnsafeInstance.setAccessible(true); + unsafe = (Unsafe) theUnsafeInstance.get(Unsafe.class); + } catch (Exception e) { + throw new RuntimeException("exception while trying to get Unsafe", e); + } + } + + /** + * Copies the contents of a {@link String} to a native memory buffer as a {@code '\0'} + * terminated C string. The native memory buffer is allocated via + * {@link Unsafe#allocateMemory(long)}. The caller is responsible for releasing the buffer when + * it is no longer needed via {@link Unsafe#freeMemory(long)}. + * + * @return the native memory pointer of the C string created from {@code s} + */ + public static long createCString(String s) { + return writeCString(s, unsafe.allocateMemory(s.length() + 1)); + } + + /** + * Reads a {@code '\0'} terminated C string from native memory and converts it to a + * {@link String}. + * + * @return a Java string + */ + public static String readCString(long address) { + if (address == 0) { + return null; + } + StringBuilder sb = new StringBuilder(); + for (int i = 0;; i++) { + char c = (char) unsafe.getByte(address + i); + if (c == 0) { + break; + } + sb.append(c); + } + return sb.toString(); + } + + /** + * Writes the contents of a {@link String} to a native memory buffer as a {@code '\0'} + * terminated C string. The caller is responsible for ensuring the buffer is at least + * {@code s.length() + 1} bytes long. The caller is also responsible for releasing the buffer + * when it is no longer. + * + * @return the value of {@code buf} + */ + public static long writeCString(String s, long buf) { + int size = s.length(); + for (int i = 0; i < size; i++) { + unsafe.putByte(buf + i, (byte) s.charAt(i)); + } + unsafe.putByte(buf + size, (byte) '\0'); + return buf; + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.compiler/src/com/oracle/jvmci/compiler/Compiler.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.compiler/src/com/oracle/jvmci/compiler/Compiler.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,42 @@ +/* + * 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.jvmci.compiler; + +import com.oracle.jvmci.code.*; +import com.oracle.jvmci.meta.*; +import com.oracle.jvmci.options.*; +import com.oracle.jvmci.service.*; + +public interface Compiler extends Service { + int INVOCATION_ENTRY_BCI = -1; + + @Option(help = "", type = OptionType.Debug) OptionValue PrintFilter = new OptionValue<>(null); + @Option(help = "", type = OptionType.Debug) OptionValue PrintCompilation = new OptionValue<>(false); + @Option(help = "", type = OptionType.Debug) OptionValue PrintAfterCompilation = new OptionValue<>(false); + @Option(help = "", type = OptionType.Debug) OptionValue PrintBailout = new OptionValue<>(false); + @Option(help = "", type = OptionType.Debug) OptionValue ExitVMOnBailout = new OptionValue<>(false); + @Option(help = "", type = OptionType.Debug) OptionValue ExitVMOnException = new OptionValue<>(true); + @Option(help = "", type = OptionType.Debug) OptionValue PrintStackTraceOnException = new OptionValue<>(false); + + CompilationResult compile(ResolvedJavaMethod method, int entryBCI, boolean mustRecordMethodInlining); +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.compiler/src/com/oracle/jvmci/compiler/CompilerThread.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.compiler/src/com/oracle/jvmci/compiler/CompilerThread.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,61 @@ +/* + * 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.compiler; + +import com.oracle.jvmci.compiler.CompilerThreadFactory.*; +import com.oracle.jvmci.debug.*; + +/** + * A compiler thread is a daemon thread that runs at {@link Thread#MAX_PRIORITY} and executes in the + * context of a thread-local {@linkplain JVMCIDebugConfig debug configuration}. + */ +public class CompilerThread extends Thread { + + private final DebugConfigAccess debugConfigAccess; + + public CompilerThread(Runnable r, String namePrefix, DebugConfigAccess debugConfigAccess) { + super(r); + this.setName(namePrefix + "-" + this.getId()); + this.setPriority(Thread.MAX_PRIORITY); + this.setDaemon(true); + this.debugConfigAccess = debugConfigAccess; + } + + @Override + public void run() { + JVMCIDebugConfig debugConfig = debugConfigAccess.getDebugConfig(); + setContextClassLoader(getClass().getClassLoader()); + try { + super.run(); + } finally { + if (debugConfig != null) { + for (DebugDumpHandler dumpHandler : debugConfig.dumpHandlers()) { + try { + dumpHandler.close(); + } catch (Throwable t) { + } + } + } + } + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.compiler/src/com/oracle/jvmci/compiler/CompilerThreadFactory.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.compiler/src/com/oracle/jvmci/compiler/CompilerThreadFactory.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,56 @@ +/* + * 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.compiler; + +import java.util.concurrent.*; + +import com.oracle.jvmci.debug.*; + +/** + * Facility for creating {@linkplain CompilerThread compiler threads}. + */ +public class CompilerThreadFactory implements ThreadFactory { + + /** + * Capability to get a thread-local debug configuration for the current thread. + */ + public interface DebugConfigAccess { + /** + * Get a thread-local debug configuration for the current thread. This will be null if + * debugging is {@linkplain Debug#isEnabled() disabled}. + */ + JVMCIDebugConfig getDebugConfig(); + } + + protected final String threadNamePrefix; + protected final DebugConfigAccess debugConfigAccess; + + public CompilerThreadFactory(String threadNamePrefix, DebugConfigAccess debugConfigAccess) { + this.threadNamePrefix = threadNamePrefix; + this.debugConfigAccess = debugConfigAccess; + } + + public Thread newThread(Runnable r) { + return new CompilerThread(r, threadNamePrefix, debugConfigAccess); + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.debug.test/src/com/oracle/jvmci/debug/test/DebugHistogramTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.debug.test/src/com/oracle/jvmci/debug/test/DebugHistogramTest.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,123 @@ +/* + * Copyright (c) 2013, 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.debug.test; + +import java.io.*; + +import org.junit.*; + +import com.oracle.jvmci.debug.*; +import com.oracle.jvmci.debug.internal.*; + +public class DebugHistogramTest { + + @Test + public void testEmptyHistogram() { + DebugHistogram histogram = Debug.createHistogram("TestHistogram"); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + + new DebugHistogramAsciiPrinter(new PrintStream(outputStream)).print(histogram); + String line = outputStream.toString().split("\r?\n")[0]; + Assert.assertEquals("TestHistogram is empty.", line); + + outputStream.reset(); + new DebugHistogramRPrinter(new PrintStream(outputStream)).print(histogram); + Assert.assertEquals("", outputStream.toString()); + } + + @Test + public void testSingleEntryHistogram() { + DebugHistogram histogram = Debug.createHistogram("TestHistogram"); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + histogram.add(new Integer(1)); + histogram.add(new Integer(1)); + new DebugHistogramAsciiPrinter(new PrintStream(outputStream)).print(histogram); + String[] lines = outputStream.toString().split("\r?\n"); + // @formatter:off + String[] expected = { + "TestHistogram has 1 unique elements and 2 total elements:", + "--------------------------------------------------------------------------------------------------------------------------------------------------------------------------", + "| 1 | 2 | ==================================================================================================== |", + "--------------------------------------------------------------------------------------------------------------------------------------------------------------------------" + }; + // @formatter:on + Assert.assertArrayEquals(expected, lines); + + outputStream.reset(); + new DebugHistogramRPrinter(new PrintStream(outputStream)).print(histogram); + lines = outputStream.toString().split("\r?\n"); + // @formatter:off + expected = new String[] { + "TestHistogram <- c(2);", + "names(TestHistogram) <- c(\"1\");" + }; + // @formatter:on + Assert.assertArrayEquals(expected, lines); + } + + @Test + public void testMultipleEntryHistogram() { + DebugHistogram histogram = Debug.createHistogram("TestHistogram"); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + histogram.add(new Integer(1)); + histogram.add(new Integer(2)); + histogram.add(new Integer(2)); + new DebugHistogramAsciiPrinter(new PrintStream(outputStream)).print(histogram); + String[] lines = outputStream.toString().split("\r?\n"); + // @formatter:off + String[] expected = new String[] { + "TestHistogram has 2 unique elements and 3 total elements:", + "--------------------------------------------------------------------------------------------------------------------------------------------------------------------------", + "| 2 | 2 | ==================================================================================================== |", + "| 1 | 1 | ================================================== |", + "--------------------------------------------------------------------------------------------------------------------------------------------------------------------------" + }; + // @formatter:on + Assert.assertArrayEquals(expected, lines); + + outputStream.reset(); + new DebugHistogramRPrinter(new PrintStream(outputStream)).print(histogram); + lines = outputStream.toString().split("\r?\n"); + // @formatter:off + expected = new String[] { + "TestHistogram <- c(2, 1);", + "names(TestHistogram) <- c(\"2\", \"1\");" + }; + // @formatter:on + Assert.assertArrayEquals(expected, lines); + } + + @Test + public void testTooLongValueString() { + DebugHistogram histogram = Debug.createHistogram("TestHistogram"); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + histogram.add("MyCustomValue"); + new DebugHistogramAsciiPrinter(new PrintStream(outputStream), Integer.MAX_VALUE, 10, 10, 1).print(histogram); + String[] lines = outputStream.toString().split("\r?\n"); + Assert.assertEquals(4, lines.length); + Assert.assertEquals("TestHistogram has 1 unique elements and 1 total elements:", lines[0]); + Assert.assertEquals("----------------------------------------", lines[1]); + Assert.assertEquals("| MyCusto... | 1 | ========== |", lines[2]); + Assert.assertEquals("----------------------------------------", lines[3]); + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.debug.test/src/com/oracle/jvmci/debug/test/DebugTimerTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.debug.test/src/com/oracle/jvmci/debug/test/DebugTimerTest.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,137 @@ +/* + * Copyright (c) 2013, 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.debug.test; + +import static org.junit.Assert.*; + +import java.lang.management.*; + +import org.junit.*; + +import com.oracle.jvmci.debug.*; + +public class DebugTimerTest { + + private static final ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean(); + + /** + * Actively spins the current thread for at least a given number of milliseconds in such a way + * that timers for the current thread keep ticking over. + * + * @return the number of milliseconds actually spent spinning which is guaranteed to be >= + * {@code ms} + */ + private static long spin(long ms) { + long start = threadMXBean.getCurrentThreadCpuTime(); + do { + long durationMS = (threadMXBean.getCurrentThreadCpuTime() - start) / 1000; + if (durationMS >= ms) { + return durationMS; + } + } while (true); + } + + @Test + public void test1() { + DebugConfig debugConfig = Debug.fixedConfig(0, 0, false, false, true, false, null, null, System.out); + try (DebugConfigScope dcs = new DebugConfigScope(debugConfig); Debug.Scope s = Debug.scope("DebugTimerTest")) { + + DebugTimer timerA = Debug.timer("TimerA"); + DebugTimer timerB = Debug.timer("TimerB"); + + long spinA; + long spinB; + + try (DebugCloseable a1 = timerA.start()) { + spinA = spin(50); + try (DebugCloseable b1 = timerB.start()) { + spinB = spin(50); + } + } + + Assert.assertTrue(timerB.getCurrentValue() < timerA.getCurrentValue()); + if (timerA.getFlat() != null && timerB.getFlat() != null) { + assertTrue(spinB >= spinA || timerB.getFlat().getCurrentValue() < timerA.getFlat().getCurrentValue()); + assertEquals(timerA.getFlat().getCurrentValue(), timerA.getCurrentValue() - timerB.getFlat().getCurrentValue(), 10D); + } + } + } + + @Test + public void test2() { + DebugConfig debugConfig = Debug.fixedConfig(0, 0, false, false, true, false, null, null, System.out); + try (DebugConfigScope dcs = new DebugConfigScope(debugConfig); Debug.Scope s = Debug.scope("DebugTimerTest")) { + DebugTimer timerC = Debug.timer("TimerC"); + try (DebugCloseable c1 = timerC.start()) { + spin(50); + try (DebugCloseable c2 = timerC.start()) { + spin(50); + try (DebugCloseable c3 = timerC.start()) { + spin(50); + try (DebugCloseable c4 = timerC.start()) { + spin(50); + try (DebugCloseable c5 = timerC.start()) { + spin(50); + } + } + } + } + } + if (timerC.getFlat() != null) { + assertEquals(timerC.getFlat().getCurrentValue(), timerC.getCurrentValue()); + } + } + } + + @Test + public void test3() { + DebugConfig debugConfig = Debug.fixedConfig(0, 0, false, false, true, false, null, null, System.out); + try (DebugConfigScope dcs = new DebugConfigScope(debugConfig); Debug.Scope s = Debug.scope("DebugTimerTest")) { + + DebugTimer timerD = Debug.timer("TimerD"); + DebugTimer timerE = Debug.timer("TimerE"); + + long spinD1; + long spinE; + + try (DebugCloseable d1 = timerD.start()) { + spinD1 = spin(50); + try (DebugCloseable e1 = timerE.start()) { + spinE = spin(50); + try (DebugCloseable d2 = timerD.start()) { + spin(50); + try (DebugCloseable d3 = timerD.start()) { + spin(50); + } + } + } + } + + Assert.assertTrue(timerE.getCurrentValue() < timerD.getCurrentValue()); + if (timerD.getFlat() != null && timerE.getFlat() != null) { + assertTrue(spinE >= spinD1 || timerE.getFlat().getCurrentValue() < timerD.getFlat().getCurrentValue()); + assertEquals(timerD.getFlat().getCurrentValue(), timerD.getCurrentValue() - timerE.getFlat().getCurrentValue(), 10D); + } + } + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.debug/overview.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.debug/overview.html Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,36 @@ + + + + + + + + +Documentation for the com.oracle.jvmci.debug project. + + + diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/AnsiColor.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/AnsiColor.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,88 @@ +/* + * 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.debug; + +/** + * Ansi terminal color escape codes. + */ +public final class AnsiColor { + /** Foreground black. */ + public static final String BLACK = "\u001b[30m"; + /** Foreground red. */ + public static final String RED = "\u001b[31m"; + /** Foreground green. */ + public static final String GREEN = "\u001b[32m"; + /** Foreground yellow. */ + public static final String YELLOW = "\u001b[33m"; + /** Foreground blue. */ + public static final String BLUE = "\u001b[34m"; + /** Foreground magenta. */ + public static final String MAGENTA = "\u001b[35m"; + /** Foreground cyan. */ + public static final String CYAN = "\u001b[36m"; + /** Foreground white. */ + public static final String WHITE = "\u001b[37m"; + + /** Foreground bold black. */ + public static final String BOLD_BLACK = "\u001b[30;1m"; + /** Foreground bold red. */ + public static final String BOLD_RED = "\u001b[31;1m"; + /** Foreground bold green. */ + public static final String BOLD_GREEN = "\u001b[32;1m"; + /** Foreground bold yellow. */ + public static final String BOLD_YELLOW = "\u001b[33;1m"; + /** Foreground bold blue. */ + public static final String BOLD_BLUE = "\u001b[34;1m"; + /** Foreground bold magenta. */ + public static final String BOLD_MAGENTA = "\u001b[35;1m"; + /** Foreground bold cyan. */ + public static final String BOLD_CYAN = "\u001b[36;1m"; + /** Foreground bold white. */ + public static final String BOLD_WHITE = "\u001b[37;1m"; + + /** Background black. */ + public static final String BG_BLACK = "\u001b[40m"; + /** Background red. */ + public static final String BG_RED = "\u001b[41m"; + /** Background green. */ + public static final String BG_GREEN = "\u001b[42m"; + /** Background yellow. */ + public static final String BG_YELLOW = "\u001b[43m"; + /** Background blue. */ + public static final String BG_BLUE = "\u001b[44m"; + /** Background magenta. */ + public static final String BG_MAGENTA = "\u001b[45m"; + /** Background cyan. */ + public static final String BG_CYAN = "\u001b[46m"; + /** Background white. */ + public static final String BG_WHITE = "\u001b[47m"; + + /** Reset. */ + public static final String RESET = "\u001b[0m"; + /** Underline. */ + public static final String UNDERLINED = "\u001b[4m"; + + /** Prevent instantiation. */ + private AnsiColor() { + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/Debug.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/Debug.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,1551 @@ +/* + * 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.debug; + +import static com.oracle.jvmci.debug.Debug.Initialization.*; +import static com.oracle.jvmci.debug.DelegatingDebugConfig.Feature.*; +import static java.util.FormattableFlags.*; + +import java.io.*; +import java.util.*; +import java.util.concurrent.*; + +import com.oracle.jvmci.debug.DelegatingDebugConfig.Level; +import com.oracle.jvmci.debug.internal.*; +import com.oracle.jvmci.service.*; + +/** + * Scope based debugging facility. This facility is {@link #isEnabled()} if assertions are enabled + * for the {@link Debug} class or the {@value Initialization#INITIALIZER_PROPERTY_NAME} system + * property is {@code "true"} when {@link Debug} is initialized. + */ +public class Debug { + + static { + for (DebugInitializationPropertyProvider p : Services.load(DebugInitializationPropertyProvider.class)) { + p.apply(); + } + } + + /** + * Class to assist with initialization of {@link Debug}. + */ + public static class Initialization { + + public static final String INITIALIZER_PROPERTY_NAME = "jvmci.debug.enable"; + + private static boolean initialized; + + /** + * Determines if {@link Debug} has been initialized. + */ + public static boolean isDebugInitialized() { + return initialized; + } + + } + + @SuppressWarnings("all") + private static boolean initialize() { + boolean assertionsEnabled = false; + assert assertionsEnabled = true; + Initialization.initialized = true; + return assertionsEnabled || Boolean.getBoolean(INITIALIZER_PROPERTY_NAME); + } + + private static final boolean ENABLED = initialize(); + + public static boolean isEnabled() { + return ENABLED; + } + + public static boolean isDumpEnabledForMethod() { + if (!ENABLED) { + return false; + } + DebugConfig config = DebugScope.getConfig(); + if (config == null) { + return false; + } + return config.isDumpEnabledForMethod(); + } + + public static final int DEFAULT_LOG_LEVEL = 2; + + public static boolean isDumpEnabled() { + return isDumpEnabled(DEFAULT_LOG_LEVEL); + } + + public static boolean isDumpEnabled(int dumpLevel) { + return ENABLED && DebugScope.getInstance().isDumpEnabled(dumpLevel); + } + + /** + * Determines if verification is enabled in the current method, regardless of the + * {@linkplain Debug#currentScope() current debug scope}. + * + * @see Debug#verify(Object, String) + */ + public static boolean isVerifyEnabledForMethod() { + if (!ENABLED) { + return false; + } + DebugConfig config = DebugScope.getConfig(); + if (config == null) { + return false; + } + return config.isVerifyEnabledForMethod(); + } + + /** + * Determines if verification is enabled in the {@linkplain Debug#currentScope() current debug + * scope}. + * + * @see Debug#verify(Object, String) + */ + public static boolean isVerifyEnabled() { + return ENABLED && DebugScope.getInstance().isVerifyEnabled(); + } + + public static boolean isMeterEnabled() { + return ENABLED && DebugScope.getInstance().isMeterEnabled(); + } + + public static boolean isTimeEnabled() { + return ENABLED && DebugScope.getInstance().isTimeEnabled(); + } + + public static boolean isMemUseTrackingEnabled() { + return ENABLED && DebugScope.getInstance().isMemUseTrackingEnabled(); + } + + public static boolean isLogEnabledForMethod() { + if (!ENABLED) { + return false; + } + DebugConfig config = DebugScope.getConfig(); + if (config == null) { + return false; + } + return config.isLogEnabledForMethod(); + } + + public static boolean isLogEnabled() { + return isLogEnabled(DEFAULT_LOG_LEVEL); + } + + public static boolean isLogEnabled(int logLevel) { + return ENABLED && DebugScope.getInstance().isLogEnabled(logLevel); + } + + @SuppressWarnings("unused") + public static Runnable decorateDebugRoot(Runnable runnable, String name, DebugConfig config) { + return runnable; + } + + @SuppressWarnings("unused") + public static Callable decorateDebugRoot(Callable callable, String name, DebugConfig config) { + return callable; + } + + @SuppressWarnings("unused") + public static Runnable decorateScope(Runnable runnable, String name, Object... context) { + return runnable; + } + + @SuppressWarnings("unused") + public static Callable decorateScope(Callable callable, String name, Object... context) { + return callable; + } + + /** + * Gets a string composed of the names in the current nesting of debug + * {@linkplain #scope(Object) scopes} separated by {@code '.'}. + */ + public static String currentScope() { + if (ENABLED) { + return DebugScope.getInstance().getQualifiedName(); + } else { + return ""; + } + } + + /** + * Represents a debug scope entered by {@link Debug#scope(Object)} or + * {@link Debug#sandbox(CharSequence, DebugConfig, Object...)}. Leaving the scope is achieved + * via {@link #close()}. + */ + public interface Scope extends AutoCloseable { + void close(); + } + + /** + * Creates and enters a new debug scope which will be a child of the current debug scope. + *

      + * It is recommended to use the try-with-resource statement for managing entering and leaving + * debug scopes. For example: + * + *

      +     * try (Scope s = Debug.scope("InliningGraph", inlineeGraph)) {
      +     *     ...
      +     * } catch (Throwable e) {
      +     *     throw Debug.handle(e);
      +     * }
      +     * 
      + * + * The {@code name} argument is subject to the following type based conversion before having + * {@link Object#toString()} called on it: + * + *
      +     *     Type          | Conversion
      +     * ------------------+-----------------
      +     *  java.lang.Class  | arg.getSimpleName()
      +     *                   |
      +     * 
      + * + * @param name the name of the new scope + * @param contextObjects an array of object to be appended to the {@linkplain #context() + * current} debug context + * @throws Throwable used to enforce a catch block. + * @return the scope entered by this method which will be exited when its {@link Scope#close()} + * method is called + */ + public static Scope scope(Object name, Object[] contextObjects) throws Throwable { + if (ENABLED) { + return DebugScope.getInstance().scope(convertFormatArg(name).toString(), null, contextObjects); + } else { + return null; + } + } + + /** + * Similar to {@link #scope(Object, Object[])} but without context objects. Therefore the catch + * block can be omitted. + * + * @see #scope(Object, Object[]) + */ + public static Scope scope(Object name) { + if (ENABLED) { + return DebugScope.getInstance().scope(convertFormatArg(name).toString(), null); + } else { + return null; + } + } + + /** + * @see #scope(Object, Object[]) + * @param context an object to be appended to the {@linkplain #context() current} debug context + */ + public static Scope scope(Object name, Object context) throws Throwable { + if (ENABLED) { + return DebugScope.getInstance().scope(convertFormatArg(name).toString(), null, context); + } else { + return null; + } + } + + /** + * @see #scope(Object, Object[]) + * @param context1 first object to be appended to the {@linkplain #context() current} debug + * context + * @param context2 second object to be appended to the {@linkplain #context() current} debug + * context + */ + public static Scope scope(Object name, Object context1, Object context2) throws Throwable { + if (ENABLED) { + return DebugScope.getInstance().scope(convertFormatArg(name).toString(), null, context1, context2); + } else { + return null; + } + } + + /** + * @see #scope(Object, Object[]) + * @param context1 first object to be appended to the {@linkplain #context() current} debug + * context + * @param context2 second object to be appended to the {@linkplain #context() current} debug + * context + * @param context3 third object to be appended to the {@linkplain #context() current} debug + * context + */ + public static Scope scope(Object name, Object context1, Object context2, Object context3) throws Throwable { + if (ENABLED) { + return DebugScope.getInstance().scope(convertFormatArg(name).toString(), null, context1, context2, context3); + } else { + return null; + } + } + + /** + * Creates and enters a new debug scope which will be disjoint from the current debug scope. + *

      + * It is recommended to use the try-with-resource statement for managing entering and leaving + * debug scopes. For example: + * + *

      +     * try (Scope s = Debug.sandbox("CompilingStub", null, stubGraph)) {
      +     *     ...
      +     * } catch (Throwable e) {
      +     *     throw Debug.handle(e);
      +     * }
      +     * 
      + * + * @param name the name of the new scope + * @param config the debug configuration to use for the new scope + * @param context objects to be appended to the {@linkplain #context() current} debug context + * @return the scope entered by this method which will be exited when its {@link Scope#close()} + * method is called + */ + public static Scope sandbox(CharSequence name, DebugConfig config, Object... context) throws Throwable { + if (ENABLED) { + DebugConfig sandboxConfig = config == null ? silentConfig() : config; + return DebugScope.getInstance().scope(name, sandboxConfig, context); + } else { + return null; + } + } + + public static Scope forceLog() throws Throwable { + ArrayList context = new ArrayList<>(); + for (Object obj : context()) { + context.add(obj); + } + return Debug.sandbox("forceLog", new DelegatingDebugConfig().override(Level.LOG, Integer.MAX_VALUE).enable(LOG_METHOD), context.toArray()); + } + + /** + * Opens a scope in which exception {@linkplain DebugConfig#interceptException(Throwable) + * interception} is disabled. It is recommended to use the try-with-resource statement for + * managing entering and leaving such scopes: + * + *
      +     * try (DebugConfigScope s = Debug.disableIntercept()) {
      +     *     ...
      +     * }
      +     * 
      + * + * This is particularly useful to suppress extraneous output in JUnit tests that are expected to + * throw an exception. + */ + public static DebugConfigScope disableIntercept() { + return Debug.setConfig(new DelegatingDebugConfig().disable(INTERCEPT)); + } + + /** + * Handles an exception in the context of the debug scope just exited. The just exited scope + * must have the current scope as its parent which will be the case if the try-with-resource + * pattern recommended by {@link #scope(Object)} and + * {@link #sandbox(CharSequence, DebugConfig, Object...)} is used + * + * @see #scope(Object, Object[]) + * @see #sandbox(CharSequence, DebugConfig, Object...) + */ + public static RuntimeException handle(Throwable exception) { + if (ENABLED) { + return DebugScope.getInstance().handle(exception); + } else { + if (exception instanceof Error) { + throw (Error) exception; + } + if (exception instanceof RuntimeException) { + throw (RuntimeException) exception; + } + throw new RuntimeException(exception); + } + } + + public static void log(String msg) { + log(DEFAULT_LOG_LEVEL, msg); + } + + /** + * Prints a message to the current debug scope's logging stream if logging is enabled. + * + * @param msg the message to log + */ + public static void log(int logLevel, String msg) { + if (ENABLED) { + DebugScope.getInstance().log(logLevel, msg); + } + } + + public static void log(String format, Object arg) { + log(DEFAULT_LOG_LEVEL, format, arg); + } + + /** + * Prints a message to the current debug scope's logging stream if logging is enabled. + * + * @param format a format string + * @param arg the argument referenced by the format specifiers in {@code format} + */ + public static void log(int logLevel, String format, Object arg) { + if (ENABLED) { + DebugScope.getInstance().log(logLevel, format, arg); + } + } + + public static void log(String format, int arg) { + log(DEFAULT_LOG_LEVEL, format, arg); + } + + /** + * Prints a message to the current debug scope's logging stream if logging is enabled. + * + * @param format a format string + * @param arg the argument referenced by the format specifiers in {@code format} + */ + public static void log(int logLevel, String format, int arg) { + if (ENABLED) { + DebugScope.getInstance().log(logLevel, format, arg); + } + } + + public static void log(String format, Object arg1, Object arg2) { + log(DEFAULT_LOG_LEVEL, format, arg1, arg2); + } + + /** + * @see #log(int, String, Object) + */ + public static void log(int logLevel, String format, Object arg1, Object arg2) { + if (ENABLED) { + DebugScope.getInstance().log(logLevel, format, arg1, arg2); + } + } + + public static void log(String format, int arg1, Object arg2) { + log(DEFAULT_LOG_LEVEL, format, arg1, arg2); + } + + /** + * @see #log(int, String, Object) + */ + public static void log(int logLevel, String format, int arg1, Object arg2) { + if (ENABLED) { + DebugScope.getInstance().log(logLevel, format, arg1, arg2); + } + } + + public static void log(String format, Object arg1, int arg2) { + log(DEFAULT_LOG_LEVEL, format, arg1, arg2); + } + + /** + * @see #log(int, String, Object) + */ + public static void log(int logLevel, String format, Object arg1, int arg2) { + if (ENABLED) { + DebugScope.getInstance().log(logLevel, format, arg1, arg2); + } + } + + public static void log(String format, int arg1, int arg2) { + log(DEFAULT_LOG_LEVEL, format, arg1, arg2); + } + + /** + * @see #log(int, String, Object) + */ + public static void log(int logLevel, String format, int arg1, int arg2) { + if (ENABLED) { + DebugScope.getInstance().log(logLevel, format, arg1, arg2); + } + } + + public static void log(String format, Object arg1, Object arg2, Object arg3) { + log(DEFAULT_LOG_LEVEL, format, arg1, arg2, arg3); + } + + /** + * @see #log(int, String, Object) + */ + public static void log(int logLevel, String format, Object arg1, Object arg2, Object arg3) { + if (ENABLED) { + DebugScope.getInstance().log(logLevel, format, arg1, arg2, arg3); + } + } + + public static void log(String format, int arg1, int arg2, int arg3) { + log(DEFAULT_LOG_LEVEL, format, arg1, arg2, arg3); + } + + /** + * @see #log(int, String, Object) + */ + public static void log(int logLevel, String format, int arg1, int arg2, int arg3) { + if (ENABLED) { + DebugScope.getInstance().log(logLevel, format, arg1, arg2, arg3); + } + } + + public static void log(String format, Object arg1, Object arg2, Object arg3, Object arg4) { + log(DEFAULT_LOG_LEVEL, format, arg1, arg2, arg3, arg4); + } + + /** + * @see #log(int, String, Object) + */ + public static void log(int logLevel, String format, Object arg1, Object arg2, Object arg3, Object arg4) { + if (ENABLED) { + DebugScope.getInstance().log(logLevel, format, arg1, arg2, arg3, arg4); + } + } + + public static void log(String format, Object arg1, Object arg2, Object arg3, Object arg4, Object arg5) { + log(DEFAULT_LOG_LEVEL, format, arg1, arg2, arg3, arg4, arg5); + } + + /** + * @see #log(int, String, Object) + */ + public static void log(int logLevel, String format, Object arg1, Object arg2, Object arg3, Object arg4, Object arg5) { + if (ENABLED) { + DebugScope.getInstance().log(logLevel, format, arg1, arg2, arg3, arg4, arg5); + } + } + + public static void log(String format, Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6) { + log(DEFAULT_LOG_LEVEL, format, arg1, arg2, arg3, arg4, arg5, arg6); + } + + /** + * @see #log(int, String, Object) + */ + public static void log(int logLevel, String format, Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6) { + if (ENABLED) { + DebugScope.getInstance().log(logLevel, format, arg1, arg2, arg3, arg4, arg5, arg6); + } + } + + public static void log(String format, Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7) { + log(DEFAULT_LOG_LEVEL, format, arg1, arg2, arg3, arg4, arg5, arg6, arg7); + } + + public static void log(String format, Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, Object arg8) { + log(DEFAULT_LOG_LEVEL, format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8); + } + + /** + * @see #log(int, String, Object) + */ + public static void log(int logLevel, String format, Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7) { + if (ENABLED) { + DebugScope.getInstance().log(logLevel, format, arg1, arg2, arg3, arg4, arg5, arg6, arg7); + } + } + + public static void log(int logLevel, String format, Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, Object arg8) { + if (ENABLED) { + DebugScope.getInstance().log(logLevel, format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8); + } + } + + public static void logv(String format, Object... args) { + logv(DEFAULT_LOG_LEVEL, format, args); + } + + /** + * Prints a message to the current debug scope's logging stream. This method must only be called + * if debugging is {@linkplain Debug#isEnabled() enabled} as it incurs allocation at the call + * site. If possible, call one of the other {@code log()} methods in this class that take a + * fixed number of parameters. + * + * @param format a format string + * @param args the arguments referenced by the format specifiers in {@code format} + */ + public static void logv(int logLevel, String format, Object... args) { + if (!ENABLED) { + throw new InternalError("Use of Debug.logv() must be guarded by a test of Debug.isEnabled()"); + } + DebugScope.getInstance().log(logLevel, format, args); + } + + /** + * This override exists to catch cases when {@link #log(String, Object)} is called with one + * argument bound to a varargs method parameter. It will bind to this method instead of the + * single arg variant and produce a deprecation warning instead of silently wrapping the + * Object[] inside of another Object[]. + */ + @Deprecated + public static void log(String format, Object[] args) { + assert false : "shouldn't use this"; + log(DEFAULT_LOG_LEVEL, format, args); + } + + /** + * This override exists to catch cases when {@link #log(int, String, Object)} is called with one + * argument bound to a varargs method parameter. It will bind to this method instead of the + * single arg variant and produce a deprecation warning instead of silently wrapping the + * Object[] inside of another Object[]. + */ + @Deprecated + public static void log(int logLevel, String format, Object[] args) { + assert false : "shouldn't use this"; + logv(logLevel, format, args); + } + + public static void dump(Object object, String msg) { + dump(DEFAULT_LOG_LEVEL, object, msg); + } + + public static void dump(int dumpLevel, Object object, String msg) { + if (ENABLED && DebugScope.getInstance().isDumpEnabled(dumpLevel)) { + DebugScope.getInstance().dump(dumpLevel, object, msg); + } + } + + public static void dump(Object object, String format, Object arg) { + dump(DEFAULT_LOG_LEVEL, object, format, arg); + } + + public static void dump(int dumpLevel, Object object, String format, Object arg) { + if (ENABLED && DebugScope.getInstance().isDumpEnabled(dumpLevel)) { + DebugScope.getInstance().dump(dumpLevel, object, format, arg); + } + } + + public static void dump(Object object, String format, Object arg1, Object arg2) { + dump(DEFAULT_LOG_LEVEL, object, format, arg1, arg2); + } + + public static void dump(int dumpLevel, Object object, String format, Object arg1, Object arg2) { + if (ENABLED && DebugScope.getInstance().isDumpEnabled(dumpLevel)) { + DebugScope.getInstance().dump(dumpLevel, object, format, arg1, arg2); + } + } + + public static void dump(Object object, String format, Object arg1, Object arg2, Object arg3) { + dump(DEFAULT_LOG_LEVEL, object, format, arg1, arg2, arg3); + } + + public static void dump(int dumpLevel, Object object, String format, Object arg1, Object arg2, Object arg3) { + if (ENABLED && DebugScope.getInstance().isDumpEnabled(dumpLevel)) { + DebugScope.getInstance().dump(dumpLevel, object, format, arg1, arg2, arg3); + } + } + + /** + * This override exists to catch cases when {@link #dump(Object, String, Object)} is called with + * one argument bound to a varargs method parameter. It will bind to this method instead of the + * single arg variant and produce a deprecation warning instead of silently wrapping the + * Object[] inside of another Object[]. + */ + @Deprecated + public static void dump(Object object, String format, Object[] args) { + assert false : "shouldn't use this"; + dump(DEFAULT_LOG_LEVEL, object, format, args); + } + + /** + * This override exists to catch cases when {@link #dump(int, Object, String, Object)} is called + * with one argument bound to a varargs method parameter. It will bind to this method instead of + * the single arg variant and produce a deprecation warning instead of silently wrapping the + * Object[] inside of another Object[]. + */ + @Deprecated + public static void dump(int dumpLevel, Object object, String format, Object[] args) { + assert false : "shouldn't use this"; + if (ENABLED && DebugScope.getInstance().isDumpEnabled(dumpLevel)) { + DebugScope.getInstance().dump(dumpLevel, object, format, args); + } + } + + /** + * Calls all {@link DebugVerifyHandler}s in the current {@linkplain DebugScope#getConfig() + * config} to perform verification on a given object. + * + * @param object object to verify + * @param message description of verification context + * + * @see DebugVerifyHandler#verify(Object, String) + */ + public static void verify(Object object, String message) { + if (ENABLED && DebugScope.getInstance().isVerifyEnabled()) { + DebugScope.getInstance().verify(object, message); + } + } + + /** + * Calls all {@link DebugVerifyHandler}s in the current {@linkplain DebugScope#getConfig() + * config} to perform verification on a given object. + * + * @param object object to verify + * @param format a format string for the description of the verification context + * @param arg the argument referenced by the format specifiers in {@code format} + * + * @see DebugVerifyHandler#verify(Object, String) + */ + public static void verify(Object object, String format, Object arg) { + if (ENABLED && DebugScope.getInstance().isVerifyEnabled()) { + DebugScope.getInstance().verify(object, format, arg); + } + } + + /** + * This override exists to catch cases when {@link #verify(Object, String, Object)} is called + * with one argument bound to a varargs method parameter. It will bind to this method instead of + * the single arg variant and produce a deprecation warning instead of silently wrapping the + * Object[] inside of another Object[]. + */ + @Deprecated + public static void verify(Object object, String format, Object[] args) { + assert false : "shouldn't use this"; + if (ENABLED && DebugScope.getInstance().isVerifyEnabled()) { + DebugScope.getInstance().verify(object, format, args); + } + } + + /** + * Opens a new indentation level (by adding some spaces) based on the current indentation level. + * This should be used in a {@linkplain Indent try-with-resources} pattern. + * + * @return an object that reverts to the current indentation level when + * {@linkplain Indent#close() closed} or null if debugging is disabled + * @see #logAndIndent(int, String) + * @see #logAndIndent(int, String, Object) + */ + public static Indent indent() { + if (ENABLED) { + DebugScope scope = DebugScope.getInstance(); + return scope.pushIndentLogger(); + } + return null; + } + + public static Indent logAndIndent(String msg) { + return logAndIndent(DEFAULT_LOG_LEVEL, msg); + } + + /** + * A convenience function which combines {@link #log(String)} and {@link #indent()}. + * + * @param msg the message to log + * @return an object that reverts to the current indentation level when + * {@linkplain Indent#close() closed} or null if debugging is disabled + */ + public static Indent logAndIndent(int logLevel, String msg) { + if (ENABLED && Debug.isLogEnabled(logLevel)) { + return logvAndIndentInternal(logLevel, msg); + } + return null; + } + + public static Indent logAndIndent(String format, Object arg) { + return logAndIndent(DEFAULT_LOG_LEVEL, format, arg); + } + + /** + * A convenience function which combines {@link #log(String, Object)} and {@link #indent()}. + * + * @param format a format string + * @param arg the argument referenced by the format specifiers in {@code format} + * @return an object that reverts to the current indentation level when + * {@linkplain Indent#close() closed} or null if debugging is disabled + */ + public static Indent logAndIndent(int logLevel, String format, Object arg) { + if (ENABLED && Debug.isLogEnabled(logLevel)) { + return logvAndIndentInternal(logLevel, format, arg); + } + return null; + } + + public static Indent logAndIndent(String format, int arg) { + return logAndIndent(DEFAULT_LOG_LEVEL, format, arg); + } + + /** + * A convenience function which combines {@link #log(String, Object)} and {@link #indent()}. + * + * @param format a format string + * @param arg the argument referenced by the format specifiers in {@code format} + * @return an object that reverts to the current indentation level when + * {@linkplain Indent#close() closed} or null if debugging is disabled + */ + public static Indent logAndIndent(int logLevel, String format, int arg) { + if (ENABLED && Debug.isLogEnabled(logLevel)) { + return logvAndIndentInternal(logLevel, format, arg); + } + return null; + } + + public static Indent logAndIndent(String format, int arg1, Object arg2) { + return logAndIndent(DEFAULT_LOG_LEVEL, format, arg1, arg2); + } + + /** + * @see #logAndIndent(int, String, Object) + */ + public static Indent logAndIndent(int logLevel, String format, int arg1, Object arg2) { + if (ENABLED && Debug.isLogEnabled(logLevel)) { + return logvAndIndentInternal(logLevel, format, arg1, arg2); + } + return null; + } + + public static Indent logAndIndent(String format, Object arg1, int arg2) { + return logAndIndent(DEFAULT_LOG_LEVEL, format, arg1, arg2); + } + + /** + * @see #logAndIndent(int, String, Object) + */ + public static Indent logAndIndent(int logLevel, String format, Object arg1, int arg2) { + if (ENABLED && Debug.isLogEnabled(logLevel)) { + return logvAndIndentInternal(logLevel, format, arg1, arg2); + } + return null; + } + + public static Indent logAndIndent(String format, int arg1, int arg2) { + return logAndIndent(DEFAULT_LOG_LEVEL, format, arg1, arg2); + } + + /** + * @see #logAndIndent(int, String, Object) + */ + public static Indent logAndIndent(int logLevel, String format, int arg1, int arg2) { + if (ENABLED && Debug.isLogEnabled(logLevel)) { + return logvAndIndentInternal(logLevel, format, arg1, arg2); + } + return null; + } + + public static Indent logAndIndent(String format, Object arg1, Object arg2) { + return logAndIndent(DEFAULT_LOG_LEVEL, format, arg1, arg2); + } + + /** + * @see #logAndIndent(int, String, Object) + */ + public static Indent logAndIndent(int logLevel, String format, Object arg1, Object arg2) { + if (ENABLED && Debug.isLogEnabled(logLevel)) { + return logvAndIndentInternal(logLevel, format, arg1, arg2); + } + return null; + } + + public static Indent logAndIndent(String format, Object arg1, Object arg2, Object arg3) { + return logAndIndent(DEFAULT_LOG_LEVEL, format, arg1, arg2, arg3); + } + + /** + * @see #logAndIndent(int, String, Object) + */ + public static Indent logAndIndent(int logLevel, String format, Object arg1, Object arg2, Object arg3) { + if (ENABLED && Debug.isLogEnabled(logLevel)) { + return logvAndIndentInternal(logLevel, format, arg1, arg2, arg3); + } + return null; + } + + public static Indent logAndIndent(String format, int arg1, int arg2, int arg3) { + return logAndIndent(DEFAULT_LOG_LEVEL, format, arg1, arg2, arg3); + } + + /** + * @see #logAndIndent(int, String, Object) + */ + public static Indent logAndIndent(int logLevel, String format, int arg1, int arg2, int arg3) { + if (ENABLED && Debug.isLogEnabled(logLevel)) { + return logvAndIndentInternal(logLevel, format, arg1, arg2, arg3); + } + return null; + } + + public static Indent logAndIndent(String format, Object arg1, int arg2, int arg3) { + return logAndIndent(DEFAULT_LOG_LEVEL, format, arg1, arg2, arg3); + } + + /** + * @see #logAndIndent(int, String, Object) + */ + public static Indent logAndIndent(int logLevel, String format, Object arg1, int arg2, int arg3) { + if (ENABLED && Debug.isLogEnabled(logLevel)) { + return logvAndIndentInternal(logLevel, format, arg1, arg2, arg3); + } + return null; + } + + public static Indent logAndIndent(String format, Object arg1, Object arg2, Object arg3, Object arg4) { + return logAndIndent(DEFAULT_LOG_LEVEL, format, arg1, arg2, arg3, arg4); + } + + /** + * @see #logAndIndent(int, String, Object) + */ + public static Indent logAndIndent(int logLevel, String format, Object arg1, Object arg2, Object arg3, Object arg4) { + if (ENABLED && Debug.isLogEnabled(logLevel)) { + return logvAndIndentInternal(logLevel, format, arg1, arg2, arg3, arg4); + } + return null; + } + + public static Indent logAndIndent(String format, Object arg1, Object arg2, Object arg3, Object arg4, Object arg5) { + return logAndIndent(DEFAULT_LOG_LEVEL, format, arg1, arg2, arg3, arg4, arg5); + } + + /** + * @see #logAndIndent(int, String, Object) + */ + public static Indent logAndIndent(int logLevel, String format, Object arg1, Object arg2, Object arg3, Object arg4, Object arg5) { + if (ENABLED && Debug.isLogEnabled(logLevel)) { + return logvAndIndentInternal(logLevel, format, arg1, arg2, arg3, arg4, arg5); + } + return null; + } + + public static Indent logAndIndent(String format, Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6) { + return logAndIndent(DEFAULT_LOG_LEVEL, format, arg1, arg2, arg3, arg4, arg5, arg6); + } + + /** + * @see #logAndIndent(int, String, Object) + */ + public static Indent logAndIndent(int logLevel, String format, Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6) { + if (ENABLED && Debug.isLogEnabled(logLevel)) { + return logvAndIndentInternal(logLevel, format, arg1, arg2, arg3, arg4, arg5, arg6); + } + return null; + } + + /** + * A convenience function which combines {@link #logv(int, String, Object...)} and + * {@link #indent()}. + * + * @param format a format string + * @param args the arguments referenced by the format specifiers in {@code format} + * @return an object that reverts to the current indentation level when + * {@linkplain Indent#close() closed} or null if debugging is disabled + */ + public static Indent logvAndIndent(int logLevel, String format, Object... args) { + if (ENABLED) { + if (Debug.isLogEnabled(logLevel)) { + return logvAndIndentInternal(logLevel, format, args); + } + return null; + } + throw new InternalError("Use of Debug.logvAndIndent() must be guarded by a test of Debug.isEnabled()"); + } + + private static Indent logvAndIndentInternal(int logLevel, String format, Object... args) { + assert ENABLED && Debug.isLogEnabled(logLevel) : "must have checked Debug.isLogEnabled()"; + DebugScope scope = DebugScope.getInstance(); + scope.log(logLevel, format, args); + return scope.pushIndentLogger(); + } + + /** + * This override exists to catch cases when {@link #logAndIndent(String, Object)} is called with + * one argument bound to a varargs method parameter. It will bind to this method instead of the + * single arg variant and produce a deprecation warning instead of silently wrapping the + * Object[] inside of another Object[]. + */ + @Deprecated + public static void logAndIndent(String format, Object[] args) { + assert false : "shouldn't use this"; + logAndIndent(DEFAULT_LOG_LEVEL, format, args); + } + + /** + * This override exists to catch cases when {@link #logAndIndent(int, String, Object)} is called + * with one argument bound to a varargs method parameter. It will bind to this method instead of + * the single arg variant and produce a deprecation warning instead of silently wrapping the + * Object[] inside of another Object[]. + */ + @Deprecated + public static void logAndIndent(int logLevel, String format, Object[] args) { + assert false : "shouldn't use this"; + logvAndIndent(logLevel, format, args); + } + + public static Iterable context() { + if (ENABLED) { + return DebugScope.getInstance().getCurrentContext(); + } else { + return Collections.emptyList(); + } + } + + @SuppressWarnings("unchecked") + public static List contextSnapshot(Class clazz) { + if (ENABLED) { + List result = new ArrayList<>(); + for (Object o : context()) { + if (clazz.isInstance(o)) { + result.add((T) o); + } + } + return result; + } else { + return Collections.emptyList(); + } + } + + /** + * Searches the current debug scope, bottom up, for a context object that is an instance of a + * given type. The first such object found is returned. + */ + @SuppressWarnings("unchecked") + public static T contextLookup(Class clazz) { + if (ENABLED) { + for (Object o : context()) { + if (clazz.isInstance(o)) { + return ((T) o); + } + } + } + return null; + } + + /** + * Creates a {@linkplain DebugMemUseTracker memory use tracker} that is enabled iff debugging is + * {@linkplain #isEnabled() enabled}. + *

      + * A disabled tracker has virtually no overhead. + */ + public static DebugMemUseTracker memUseTracker(CharSequence name) { + if (!isUnconditionalMemUseTrackingEnabled && !ENABLED) { + return VOID_MEM_USE_TRACKER; + } + return createMemUseTracker("%s", name, null); + } + + /** + * Creates a debug memory use tracker. Invoking this method is equivalent to: + * + *

      +     * Debug.memUseTracker(format, arg, null)
      +     * 
      + * + * except that the string formatting only happens if metering is enabled. + * + * @see #metric(String, Object, Object) + */ + public static DebugMemUseTracker memUseTracker(String format, Object arg) { + if (!isUnconditionalMemUseTrackingEnabled && !ENABLED) { + return VOID_MEM_USE_TRACKER; + } + return createMemUseTracker(format, arg, null); + } + + /** + * Creates a debug memory use tracker. Invoking this method is equivalent to: + * + *
      +     * Debug.memUseTracker(String.format(format, arg1, arg2))
      +     * 
      + * + * except that the string formatting only happens if memory use tracking is enabled. In + * addition, each argument is subject to the following type based conversion before being passed + * as an argument to {@link String#format(String, Object...)}: + * + *
      +     *     Type          | Conversion
      +     * ------------------+-----------------
      +     *  java.lang.Class  | arg.getSimpleName()
      +     *                   |
      +     * 
      + * + * @see #memUseTracker(CharSequence) + */ + public static DebugMemUseTracker memUseTracker(String format, Object arg1, Object arg2) { + if (!isUnconditionalMemUseTrackingEnabled && !ENABLED) { + return VOID_MEM_USE_TRACKER; + } + return createMemUseTracker(format, arg1, arg2); + } + + private static DebugMemUseTracker createMemUseTracker(String format, Object arg1, Object arg2) { + String name = formatDebugName(format, arg1, arg2); + return new MemUseTrackerImpl(name, !isUnconditionalMemUseTrackingEnabled); + } + + /** + * Creates a {@linkplain DebugMetric metric} that is enabled iff debugging is + * {@linkplain #isEnabled() enabled} or the system property whose name is formed by adding to + * {@value #ENABLE_METRIC_PROPERTY_NAME_PREFIX} to {@code name} is + * {@linkplain Boolean#getBoolean(String) true}. If the latter condition is true, then the + * returned metric is {@linkplain DebugMetric#isConditional() unconditional} otherwise it is + * conditional. + *

      + * A disabled metric has virtually no overhead. + */ + public static DebugMetric metric(CharSequence name) { + if (!areUnconditionalMetricsEnabled() && !ENABLED) { + return VOID_METRIC; + } + return createMetric("%s", name, null); + } + + public static String applyFormattingFlagsAndWidth(String s, int flags, int width) { + if (flags == 0 && width < 0) { + return s; + } + StringBuilder sb = new StringBuilder(s); + + // apply width and justification + int len = sb.length(); + if (len < width) { + for (int i = 0; i < width - len; i++) { + if ((flags & LEFT_JUSTIFY) == LEFT_JUSTIFY) { + sb.append(' '); + } else { + sb.insert(0, ' '); + } + } + } + + String res = sb.toString(); + if ((flags & UPPERCASE) == UPPERCASE) { + res = res.toUpperCase(); + } + return res; + } + + /** + * Creates a debug metric. Invoking this method is equivalent to: + * + *

      +     * Debug.metric(format, arg, null)
      +     * 
      + * + * except that the string formatting only happens if metering is enabled. + * + * @see #metric(String, Object, Object) + */ + public static DebugMetric metric(String format, Object arg) { + if (!areUnconditionalMetricsEnabled() && !ENABLED) { + return VOID_METRIC; + } + return createMetric(format, arg, null); + } + + /** + * Creates a debug metric. Invoking this method is equivalent to: + * + *
      +     * Debug.metric(String.format(format, arg1, arg2))
      +     * 
      + * + * except that the string formatting only happens if metering is enabled. In addition, each + * argument is subject to the following type based conversion before being passed as an argument + * to {@link String#format(String, Object...)}: + * + *
      +     *     Type          | Conversion
      +     * ------------------+-----------------
      +     *  java.lang.Class  | arg.getSimpleName()
      +     *                   |
      +     * 
      + * + * @see #metric(CharSequence) + */ + public static DebugMetric metric(String format, Object arg1, Object arg2) { + if (!areUnconditionalMetricsEnabled() && !ENABLED) { + return VOID_METRIC; + } + return createMetric(format, arg1, arg2); + } + + private static DebugMetric createMetric(String format, Object arg1, Object arg2) { + String name = formatDebugName(format, arg1, arg2); + boolean conditional = enabledMetrics == null || !findMatch(enabledMetrics, enabledMetricsSubstrings, name); + if (!ENABLED && conditional) { + return VOID_METRIC; + } + return new MetricImpl(name, conditional); + } + + /** + * Changes the debug configuration for the current thread. + * + * @param config new configuration to use for the current thread + * @return an object that when {@linkplain DebugConfigScope#close() closed} will restore the + * debug configuration for the current thread to what it was before this method was + * called + */ + public static DebugConfigScope setConfig(DebugConfig config) { + if (ENABLED) { + return new DebugConfigScope(config); + } else { + return null; + } + } + + /** + * Creates an object for counting value frequencies. + */ + public static DebugHistogram createHistogram(String name) { + return new DebugHistogramImpl(name); + } + + public static DebugConfig silentConfig() { + return fixedConfig(0, 0, false, false, false, false, Collections. emptyList(), Collections. emptyList(), null); + } + + public static DebugConfig fixedConfig(final int logLevel, final int dumpLevel, final boolean isMeterEnabled, final boolean isMemUseTrackingEnabled, final boolean isTimerEnabled, + final boolean isVerifyEnabled, final Collection dumpHandlers, final Collection verifyHandlers, final PrintStream output) { + return new DebugConfig() { + + @Override + public int getLogLevel() { + return logLevel; + } + + public boolean isLogEnabledForMethod() { + return logLevel > 0; + } + + @Override + public boolean isMeterEnabled() { + return isMeterEnabled; + } + + @Override + public boolean isMemUseTrackingEnabled() { + return isMemUseTrackingEnabled; + } + + @Override + public int getDumpLevel() { + return dumpLevel; + } + + public boolean isDumpEnabledForMethod() { + return dumpLevel > 0; + } + + @Override + public boolean isVerifyEnabled() { + return isVerifyEnabled; + } + + public boolean isVerifyEnabledForMethod() { + return isVerifyEnabled; + } + + @Override + public boolean isTimeEnabled() { + return isTimerEnabled; + } + + @Override + public RuntimeException interceptException(Throwable e) { + return null; + } + + @Override + public Collection dumpHandlers() { + return dumpHandlers; + } + + @Override + public Collection verifyHandlers() { + return verifyHandlers; + } + + @Override + public PrintStream output() { + return output; + } + + @Override + public void addToContext(Object o) { + } + + @Override + public void removeFromContext(Object o) { + } + }; + } + + private static final DebugMetric VOID_METRIC = new DebugMetric() { + + public void increment() { + } + + public void add(long value) { + } + + public void setConditional(boolean flag) { + throw new InternalError("Cannot make void metric conditional"); + } + + public boolean isConditional() { + return false; + } + + public long getCurrentValue() { + return 0L; + } + }; + + private static final DebugMemUseTracker VOID_MEM_USE_TRACKER = new DebugMemUseTracker() { + + public DebugCloseable start() { + return DebugCloseable.VOID_CLOSEABLE; + } + + public long getCurrentValue() { + return 0; + } + }; + + public static final String ENABLE_UNSCOPED_TIMERS_PROPERTY_NAME = "jvmci.debug.unscopedTimers"; + public static final String ENABLE_UNSCOPED_METRICS_PROPERTY_NAME = "jvmci.debug.unscopedMetrics"; + public static final String ENABLE_UNSCOPED_MEM_USE_TRACKERS_PROPERTY_NAME = "jvmci.debug.unscopedMemUseTrackers"; + + /** + * @see #timer(CharSequence) + */ + public static final String ENABLE_TIMER_PROPERTY_NAME_PREFIX = "jvmci.debug.timer."; + + /** + * @see #metric(CharSequence) + */ + public static final String ENABLE_METRIC_PROPERTY_NAME_PREFIX = "jvmci.debug.metric."; + + /** + * Set of unconditionally enabled metrics. Possible values and their meanings: + *
        + *
      • {@code null}: no unconditionally enabled metrics
      • + *
      • {@code isEmpty()}: all metrics are unconditionally enabled
      • + *
      • {@code !isEmpty()}: use {@link #findMatch(Set, Set, String)} on this set and + * {@link #enabledMetricsSubstrings} to determine which metrics are unconditionally enabled
      • + *
      + */ + private static final Set enabledMetrics; + + /** + * Set of unconditionally enabled timers. Same interpretation of values as for + * {@link #enabledMetrics}. + */ + private static final Set enabledTimers; + + private static final Set enabledMetricsSubstrings = new HashSet<>(); + private static final Set enabledTimersSubstrings = new HashSet<>(); + + /** + * Specifies if all mem use trackers are unconditionally enabled. + */ + private static final boolean isUnconditionalMemUseTrackingEnabled; + + static { + Set metrics = new HashSet<>(); + Set timers = new HashSet<>(); + parseMetricAndTimerSystemProperties(metrics, timers, enabledMetricsSubstrings, enabledTimersSubstrings); + metrics = metrics.isEmpty() && enabledMetricsSubstrings.isEmpty() ? null : metrics; + timers = timers.isEmpty() && enabledTimersSubstrings.isEmpty() ? null : timers; + if (metrics == null && Boolean.getBoolean(ENABLE_UNSCOPED_METRICS_PROPERTY_NAME)) { + metrics = Collections.emptySet(); + } + if (timers == null && Boolean.getBoolean(ENABLE_UNSCOPED_TIMERS_PROPERTY_NAME)) { + timers = Collections.emptySet(); + } + enabledMetrics = metrics; + enabledTimers = timers; + isUnconditionalMemUseTrackingEnabled = Boolean.getBoolean(ENABLE_UNSCOPED_MEM_USE_TRACKERS_PROPERTY_NAME); + } + + private static boolean findMatch(Set haystack, Set haystackSubstrings, String needle) { + if (haystack.isEmpty()) { + // Empty haystack means match all + return true; + } + if (haystack.contains(needle)) { + return true; + } + if (!haystackSubstrings.isEmpty()) { + for (String h : haystackSubstrings) { + if (needle.startsWith(h)) { + return true; + } + } + } + return false; + } + + public static boolean areUnconditionalTimersEnabled() { + return enabledTimers != null; + } + + public static boolean areUnconditionalMetricsEnabled() { + return enabledMetrics != null; + } + + protected static void parseMetricAndTimerSystemProperties(Set metrics, Set timers, Set metricsSubstrings, Set timersSubstrings) { + do { + try { + for (Map.Entry e : System.getProperties().entrySet()) { + String name = e.getKey().toString(); + if (name.startsWith(ENABLE_METRIC_PROPERTY_NAME_PREFIX) && Boolean.parseBoolean(e.getValue().toString())) { + if (name.endsWith("*")) { + metricsSubstrings.add(name.substring(ENABLE_METRIC_PROPERTY_NAME_PREFIX.length(), name.length() - 1)); + } else { + metrics.add(name.substring(ENABLE_METRIC_PROPERTY_NAME_PREFIX.length())); + } + } + if (name.startsWith(ENABLE_TIMER_PROPERTY_NAME_PREFIX) && Boolean.parseBoolean(e.getValue().toString())) { + if (name.endsWith("*")) { + timersSubstrings.add(name.substring(ENABLE_TIMER_PROPERTY_NAME_PREFIX.length(), name.length() - 1)); + } else { + timers.add(name.substring(ENABLE_TIMER_PROPERTY_NAME_PREFIX.length())); + } + } + } + return; + } catch (ConcurrentModificationException e) { + // Iterating over the system properties may race with another thread that is + // updating the system properties. Simply try again in this case. + } + } while (true); + } + + /** + * Creates a {@linkplain DebugTimer timer} that is enabled iff debugging is + * {@linkplain #isEnabled() enabled} or the system property whose name is formed by adding to + * {@value #ENABLE_TIMER_PROPERTY_NAME_PREFIX} to {@code name} is + * {@linkplain Boolean#getBoolean(String) true}. If the latter condition is true, then the + * returned timer is {@linkplain DebugMetric#isConditional() unconditional} otherwise it is + * conditional. + *

      + * A disabled timer has virtually no overhead. + */ + public static DebugTimer timer(CharSequence name) { + if (!areUnconditionalTimersEnabled() && !ENABLED) { + return VOID_TIMER; + } + return createTimer("%s", name, null); + } + + /** + * Creates a debug timer. Invoking this method is equivalent to: + * + *

      +     * Debug.timer(format, arg, null)
      +     * 
      + * + * except that the string formatting only happens if timing is enabled. + * + * @see #timer(String, Object, Object) + */ + public static DebugTimer timer(String format, Object arg) { + if (!areUnconditionalTimersEnabled() && !ENABLED) { + return VOID_TIMER; + } + return createTimer(format, arg, null); + } + + /** + * Creates a debug timer. Invoking this method is equivalent to: + * + *
      +     * Debug.timer(String.format(format, arg1, arg2))
      +     * 
      + * + * except that the string formatting only happens if timing is enabled. In addition, each + * argument is subject to the following type based conversion before being passed as an argument + * to {@link String#format(String, Object...)}: + * + *
      +     *     Type          | Conversion
      +     * ------------------+-----------------
      +     *  java.lang.Class  | arg.getSimpleName()
      +     *                   |
      +     * 
      + * + * @see #timer(CharSequence) + */ + public static DebugTimer timer(String format, Object arg1, Object arg2) { + if (!areUnconditionalTimersEnabled() && !ENABLED) { + return VOID_TIMER; + } + return createTimer(format, arg1, arg2); + } + + /** + * There are paths where construction of formatted class names are common and the code below is + * surprisingly expensive, so compute it once and cache it. + */ + private static final ClassValue formattedClassName = new ClassValue() { + @Override + protected String computeValue(Class c) { + final String simpleName = c.getSimpleName(); + Class enclosingClass = c.getEnclosingClass(); + if (enclosingClass != null) { + String prefix = ""; + while (enclosingClass != null) { + prefix = enclosingClass.getSimpleName() + "_" + prefix; + enclosingClass = enclosingClass.getEnclosingClass(); + } + return prefix + simpleName; + } else { + return simpleName; + } + } + }; + + public static Object convertFormatArg(Object arg) { + if (arg instanceof Class) { + return formattedClassName.get((Class) arg); + } + return arg; + } + + private static String formatDebugName(String format, Object arg1, Object arg2) { + return String.format(format, convertFormatArg(arg1), convertFormatArg(arg2)); + } + + private static DebugTimer createTimer(String format, Object arg1, Object arg2) { + String name = formatDebugName(format, arg1, arg2); + boolean conditional = enabledTimers == null || !findMatch(enabledTimers, enabledTimersSubstrings, name); + if (!ENABLED && conditional) { + return VOID_TIMER; + } + return new TimerImpl(name, conditional); + } + + private static final DebugTimer VOID_TIMER = new DebugTimer() { + + public DebugCloseable start() { + return DebugCloseable.VOID_CLOSEABLE; + } + + public void setConditional(boolean flag) { + throw new InternalError("Cannot make void timer conditional"); + } + + public boolean isConditional() { + return false; + } + + public long getCurrentValue() { + return 0L; + } + + public TimeUnit getTimeUnit() { + return null; + } + }; +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/DebugCloseable.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/DebugCloseable.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,39 @@ +/* + * 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.debug; + +/** + * An object returned by {@link DebugTimer#start()} that when closed, stops the associated timer and + * adds the elapsed time since {@code start()} to the total for the timer. + */ +public interface DebugCloseable extends AutoCloseable { + + DebugCloseable VOID_CLOSEABLE = new DebugCloseable() { + + @Override + public void close() { + } + }; + + void close(); +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/DebugConfig.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/DebugConfig.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,116 @@ +/* + * 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.debug; + +import java.io.*; +import java.util.*; + +public interface DebugConfig { + + /** + * Determines the current log level in the {@linkplain Debug#currentScope() current debug scope} + * . + */ + int getLogLevel(); + + /** + * Determines the current dump level in the {@linkplain Debug#currentScope() current debug + * scope}. + */ + int getDumpLevel(); + + /** + * Determines if logging can be enabled in the current method, regardless of the + * {@linkplain Debug#currentScope() current debug scope}. + */ + boolean isLogEnabledForMethod(); + + /** + * Determines if metering is enabled in the {@linkplain Debug#currentScope() current debug + * scope}. + * + * @see Debug#metric(CharSequence) + */ + boolean isMeterEnabled(); + + /** + * Determines if memory use tracking is enabled in the {@linkplain Debug#currentScope() current + * debug scope}. + * + * @see Debug#memUseTracker(CharSequence) + */ + boolean isMemUseTrackingEnabled(); + + /** + * Determines if dumping can be enabled in the current method, regardless of the + * {@linkplain Debug#currentScope() current debug scope}. + */ + boolean isDumpEnabledForMethod(); + + /** + * @see Debug#isVerifyEnabled() + */ + boolean isVerifyEnabled(); + + /** + * @see Debug#isVerifyEnabledForMethod() + */ + boolean isVerifyEnabledForMethod(); + + /** + * Adds an object the context used by this configuration to do filtering. + */ + void addToContext(Object o); + + /** + * Removes an object the context used by this configuration to do filtering. + * + * This should only removes extra context added by {@link #addToContext(Object)}. + */ + void removeFromContext(Object o); + + /** + * @see Debug#timer(CharSequence) + */ + boolean isTimeEnabled(); + + /** + * Handles notification of an exception occurring within a debug scope. + * + * @return the exception object that is to be propagated to parent scope. A value of + * {@code null} indicates that {@code e} is to be propagated. + */ + RuntimeException interceptException(Throwable e); + + /** + * Gets the modifiable collection of dump handlers registered with this configuration. + */ + Collection dumpHandlers(); + + PrintStream output(); + + /** + * Gets the modifiable collection of verify handlers registered with this configuration. + */ + Collection verifyHandlers(); +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/DebugConfigCustomizer.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/DebugConfigCustomizer.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,29 @@ +/* + * 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.jvmci.debug; + +import com.oracle.jvmci.service.*; + +public interface DebugConfigCustomizer extends Service { + void customize(DebugConfig config); +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/DebugConfigScope.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/DebugConfigScope.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,55 @@ +/* + * 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.debug; + +import com.oracle.jvmci.debug.internal.*; + +/** + * A utility for scoping a change to the current debug + * {@linkplain DebugScope#setConfig(DebugConfig) configuration}. For example: + * + *
      + *     DebugConfig config = ...;
      + *     try (DebugConfigScope s = new DebugConfigScope(config)) {
      + *         // ...
      + *     }
      + * 
      + */ +public class DebugConfigScope implements AutoCloseable { + + private final DebugConfig current; + + /** + * Sets the current debug {@linkplain DebugScope#setConfig(DebugConfig) configuration} to a + * given value and creates an object that when {@linkplain #close() closed} resets the + * configuration to the {@linkplain DebugScope#getConfig() current} configuration. + */ + public DebugConfigScope(DebugConfig config) { + this.current = DebugScope.getConfig(); + DebugScope.getInstance().setConfig(config); + } + + public void close() { + DebugScope.getInstance().setConfig(current); + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/DebugDumpHandler.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/DebugDumpHandler.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,38 @@ +/* + * 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.debug; + +import java.io.*; + +public interface DebugDumpHandler extends Closeable { + + void dump(Object object, String message); + + /** + * Flushes and releases resources managed by this dump handler. A subsequent call to + * {@link #dump(Object, String)} will create and open new resources. That is, this method can be + * used to reset the handler. + */ + @Override + void close(); +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/DebugDumpScope.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/DebugDumpScope.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,49 @@ +/* + * 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.debug; + +public class DebugDumpScope { + + public final String name; + + /** + * Specifies if this scope decorates an inner scope. A hierarchical or tree representation of + * nested scopes may choose to represent a decorator scope at the same level as the scope it + * decorates. + */ + public final boolean decorator; + + public DebugDumpScope(String name) { + this(name, false); + } + + public DebugDumpScope(String name, boolean decorator) { + this.name = name; + this.decorator = decorator; + } + + @Override + public String toString() { + return "DebugDumpScope[" + name + "]"; + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/DebugEnvironment.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/DebugEnvironment.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,52 @@ +/* + * 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.debug; + +import static com.oracle.jvmci.debug.JVMCIDebugConfig.*; + +import java.io.*; +import java.util.*; + +import com.oracle.jvmci.service.*; + +public class DebugEnvironment { + + public static JVMCIDebugConfig initialize(PrintStream log) { + + if (!Debug.isEnabled()) { + log.println("WARNING: Scope debugging needs to be enabled with -esa or -D" + Debug.Initialization.INITIALIZER_PROPERTY_NAME + "=true"); + return null; + } + List dumpHandlers = new ArrayList<>(); + List verifyHandlers = new ArrayList<>(); + JVMCIDebugConfig debugConfig = new JVMCIDebugConfig(Log.getValue(), Meter.getValue(), TrackMemUse.getValue(), Time.getValue(), Dump.getValue(), Verify.getValue(), MethodFilter.getValue(), + log, dumpHandlers, verifyHandlers); + + for (DebugConfigCustomizer customizer : Services.load(DebugConfigCustomizer.class)) { + customizer.customize(debugConfig); + } + + Debug.setConfig(debugConfig); + return debugConfig; + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/DebugFilter.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/DebugFilter.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,185 @@ +/* + * 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.debug; + +import java.util.*; +import java.util.regex.*; + +import com.oracle.jvmci.debug.internal.*; + +/** + * Implements the filter specified by the {@link JVMCIDebugConfig#Dump}, + * {@link JVMCIDebugConfig#Log}, {@link JVMCIDebugConfig#Meter} and {@link JVMCIDebugConfig#Time} + * options. + *

      + * These options enable the associated debug facility if their filter matches the + * {@linkplain DebugScope#getQualifiedName() name} of the {@linkplain Debug#currentScope() current + * scope}. For the {@link JVMCIDebugConfig#Dump} and {@link JVMCIDebugConfig#Log} options, the log + * or dump level is set. The {@link JVMCIDebugConfig#Meter} and {@link JVMCIDebugConfig#Time} + * options don't have a level, for them {@code level = 0} means disabled and a {@code level > 0} + * means enabled. + *

      + * A filter is a list of comma-separated terms of the form {@code [:]}. + * {@code } is interpreted as a glob pattern if it contains a "*" or "?" character. + * Otherwise, it is interpreted as a substring. If {@code } is empty, it matches every + * scope. If {@code :} is omitted, it defaults to {@link Debug#DEFAULT_LOG_LEVEL}. The term + * {@code ~} is a shorthand for {@code :0} to disable a debug facility for a + * pattern. + *

      + * The resulting log level of a scope is determined by the last matching term. If no term + * matches, the log level is 0 (disabled). A filter with no terms matches every scope with a log + * level of {@link Debug#DEFAULT_LOG_LEVEL}. + * + *

      Examples of filters

      + * + *
        + *
      • (empty string)
        + * Matches any scope with log level {@link Debug#DEFAULT_LOG_LEVEL}. + * + *
      • {@code :1}
        + * Matches any scope with log level 1. + * + *
      • {@code *}
        + * Matches any scope with log level {@link Debug#DEFAULT_LOG_LEVEL}. + * + *
      • {@code CodeGen,CodeInstall}
        + * Matches scopes containing "CodeGen" or "CodeInstall", both with log level + * {@link Debug#DEFAULT_LOG_LEVEL}. + * + *
      • {@code CodeGen:2,CodeInstall:1}
        + * Matches scopes containing "CodeGen" with log level 2, or "CodeInstall" with log level 1. + * + *
      • {@code :1,Dead:2}
        + * Matches scopes containing "Dead" with log level 2, and all other scopes with log level 1. + * + *
      • {@code :1,Dead:0}
        + * Matches all scopes with log level 1, except those containing "Dead". + * + *
      • {@code Code*}
        + * Matches scopes starting with "Code" with log level {@link Debug#DEFAULT_LOG_LEVEL}. + * + *
      • {@code Code,~Dead}
        + * Matches scopes containing "Code" but not "Dead", with log level {@link Debug#DEFAULT_LOG_LEVEL}. + *
      + */ +final class DebugFilter { + + public static DebugFilter parse(String spec) { + if (spec == null) { + return null; + } + return new DebugFilter(spec.split(",")); + } + + private final Term[] terms; + + private DebugFilter(String[] terms) { + if (terms.length == 0) { + this.terms = null; + } else { + this.terms = new Term[terms.length]; + for (int i = 0; i < terms.length; i++) { + String t = terms[i]; + int idx = t.indexOf(':'); + + String pattern; + int level; + if (idx < 0) { + if (t.startsWith("~")) { + pattern = t.substring(1); + level = 0; + } else { + pattern = t; + level = Debug.DEFAULT_LOG_LEVEL; + } + } else { + pattern = t.substring(0, idx); + if (idx + 1 < t.length()) { + level = Integer.parseInt(t.substring(idx + 1)); + } else { + level = Debug.DEFAULT_LOG_LEVEL; + } + } + + this.terms[i] = new Term(pattern, level); + } + } + } + + /** + * Check whether a given input is matched by this filter, and determine the log level. + */ + public int matchLevel(String input) { + if (terms == null) { + return Debug.DEFAULT_LOG_LEVEL; + } else { + int level = 0; + for (Term t : terms) { + if (t.matches(input)) { + level = t.level; + } + } + return level; + } + } + + @Override + public String toString() { + StringBuilder buf = new StringBuilder("DebugFilter"); + if (terms != null) { + buf.append(Arrays.toString(terms)); + } else { + buf.append("[]"); + } + return buf.toString(); + } + + private static class Term { + + private final Pattern pattern; + public final int level; + + public Term(String filter, int level) { + this.level = level; + if (filter.isEmpty()) { + this.pattern = null; + } else if (filter.contains("*") || filter.contains("?")) { + this.pattern = Pattern.compile(MethodFilter.createGlobString(filter)); + } else { + this.pattern = Pattern.compile(".*" + MethodFilter.createGlobString(filter) + ".*"); + } + } + + /** + * Determines if a given input is matched by this filter. + */ + public boolean matches(String input) { + return pattern == null || pattern.matcher(input).matches(); + } + + @Override + public String toString() { + return (pattern == null ? ".*" : pattern.toString()) + ":" + level; + } + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/DebugHistogram.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/DebugHistogram.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,102 @@ +/* + * 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.debug; + +import java.util.*; + +/** + * Facility for recording value frequencies. + */ +public interface DebugHistogram { + + /** + * Gets the name specified when this objected was {@linkplain Debug#createHistogram(String) + * created}. + */ + String getName(); + + /** + * Increments the count for a given value. + */ + void add(Object value); + + void add(Object value, long count); + + /** + * A value and a frequency. The ordering imposed by {@link #compareTo(CountedValue)} places + * values with higher frequencies first. + */ + public class CountedValue implements Comparable { + + private long count; + private final Object value; + + public CountedValue(long count, Object value) { + this.count = count; + this.value = value; + } + + public int compareTo(CountedValue o) { + if (count < o.count) { + return 1; + } else if (count > o.count) { + return -1; + } + return 0; + } + + @Override + public String toString() { + return count + " -> " + value; + } + + public void inc() { + count++; + } + + public void add(long n) { + count += n; + } + + public long getCount() { + return count; + } + + public Object getValue() { + return value; + } + } + + /** + * Gets a list of the counted values, sorted in descending order of frequency. + */ + List getValues(); + + /** + * Interface for a service that can render a visualization of a histogram. + */ + public interface Printer { + + void print(DebugHistogram histogram); + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/DebugInitializationPropertyProvider.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/DebugInitializationPropertyProvider.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,32 @@ +/* + * 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.jvmci.debug; + +import com.oracle.jvmci.service.*; + +/** + * Sets one or more system properties used during initialization of the {@link Debug} class. + */ +public interface DebugInitializationPropertyProvider extends Service { + void apply(); +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/DebugMemUseTracker.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/DebugMemUseTracker.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,52 @@ +/* + * 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.debug; + +import com.sun.management.*; + +/** + * Tracks memory usage within a scope using {@link ThreadMXBean}. This facility should be employed + * using the try-with-resources pattern: + * + *
      + * try (DebugMemUseTracker.Closeable a = memUseTracker.start()) {
      + *     // the code to measure
      + * }
      + * 
      + */ +public interface DebugMemUseTracker { + + /** + * Creates a point from which memory usage will be recorded if memory use tracking is + * {@linkplain Debug#isMemUseTrackingEnabled() enabled}. + * + * @return an object that must be closed once the activity has completed to add the memory used + * since this call to the total for this tracker + */ + DebugCloseable start(); + + /** + * Gets the current value of this tracker. + */ + long getCurrentValue(); +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/DebugMetric.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/DebugMetric.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,65 @@ +/* + * 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.debug; + +/** + * A counter for some value of interest. + */ +public interface DebugMetric { + + /** + * Adds 1 to this counter if metering is {@link Debug#isMeterEnabled() enabled} or this is an + * {@linkplain #isConditional() unconditional} metric. + */ + void increment(); + + /** + * Adds {@code value} to this counter if metering is {@link Debug#isMeterEnabled() enabled} or + * this is an {@linkplain #isConditional() unconditional} metric. + */ + void add(long value); + + /** + * Sets a flag determining if this counter is only enabled if metering is + * {@link Debug#isMeterEnabled() enabled}. + */ + void setConditional(boolean flag); + + /** + * Determines if this counter is only enabled if metering is {@link Debug#isMeterEnabled() + * enabled}. + */ + boolean isConditional(); + + /** + * Gets the current value of this metric. + */ + long getCurrentValue(); + + /** + * Determines if this counter is enabled (either conditionally or unconditionally). + */ + default boolean isEnabled() { + return !isConditional() || Debug.isMeterEnabled(); + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/DebugTimer.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/DebugTimer.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,78 @@ +/* + * 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.debug; + +import java.util.concurrent.*; + +/** + * A timer for some activity of interest. A timer should be deployed using the try-with-resources + * pattern: + * + *
      + * try (TimerCloseable a = timer.start()) {
      + *     // the code to time
      + * }
      + * 
      + */ +public interface DebugTimer { + + /** + * Starts this timer if timing is {@linkplain Debug#isTimeEnabled() enabled} or this is an + * {@linkplain #isConditional() unconditional} timer. + * + * @return an object that must be closed once the activity has completed to add the elapsed time + * since this call to the total for this timer + */ + DebugCloseable start(); + + /** + * Sets a flag determining if this timer is only enabled if timing is + * {@link Debug#isTimeEnabled() enabled}. + */ + void setConditional(boolean flag); + + /** + * Determines if this timer is only enabled if timing is {@link Debug#isTimeEnabled() enabled}. + */ + boolean isConditional(); + + /** + * Gets the current value of this timer. + */ + long getCurrentValue(); + + /** + * Gets the time unit of this timer. + */ + TimeUnit getTimeUnit(); + + /** + * Gets the timer recording the amount time spent within a timed scope minus the time spent in + * any nested timed scopes. + * + * @return null if this timer does not support flat timing + */ + default DebugTimer getFlat() { + return null; + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/DebugVerifyHandler.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/DebugVerifyHandler.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,37 @@ +/* + * 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.debug; + +/** + * Performs some kind of verification on an object. + */ +public interface DebugVerifyHandler { + + /** + * Verifies that a given object satisfies some invariants. + * + * @param object object to verify + * @param message description of verification context + */ + void verify(Object object, String message); +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/DelegatingDebugConfig.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/DelegatingDebugConfig.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,238 @@ +/* + * 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.debug; + +import java.io.*; +import java.util.*; + +import com.oracle.jvmci.debug.internal.*; + +public class DelegatingDebugConfig implements DebugConfig { + + protected final DebugConfig delegate; + + /** + * The features of a {@link DelegatingDebugConfig} that can be force + * {@linkplain DelegatingDebugConfig#enable(Feature) enabled}/ + * {@linkplain DelegatingDebugConfig#disable(Feature) disabled} or + * {@linkplain DelegatingDebugConfig#delegate(Feature) delegated}. + */ + public enum Feature { + /** + * @see Debug#isLogEnabledForMethod() + */ + LOG_METHOD, + /** + * @see Debug#isDumpEnabledForMethod() + */ + DUMP_METHOD, + /** + * @see Debug#isVerifyEnabled() + */ + VERIFY, + /** + * @see Debug#isVerifyEnabledForMethod() + */ + VERIFY_METHOD, + /** + * @see Debug#isMeterEnabled() + */ + METER, + /** + * @see Debug#isMemUseTrackingEnabled() + */ + TRACK_MEM_USE, + /** + * @see Debug#isTimeEnabled() + */ + TIME, + /** + * @see DebugConfig#interceptException(Throwable) + */ + INTERCEPT + } + + private final Map featureState = new EnumMap<>(Feature.class); + + /** + * The debug levels of a {@link DelegatingDebugConfig} than can be + * {@linkplain DelegatingDebugConfig#override(Level, int) overridden} or + * {@linkplain DelegatingDebugConfig#delegate(Level) delegated}. + */ + public enum Level { + LOG, + DUMP + } + + private final Map levelState = new EnumMap<>(Level.class); + + /** + * Creates a config that delegates to the {@link DebugScope#getConfig() current config}. + */ + public DelegatingDebugConfig() { + this(DebugScope.getConfig()); + } + + /** + * Creates a config that delegates to a given config. + */ + public DelegatingDebugConfig(DebugConfig delegate) { + this.delegate = delegate; + } + + public DelegatingDebugConfig enable(Feature feature) { + featureState.put(feature, Boolean.TRUE); + return this; + } + + public DelegatingDebugConfig disable(Feature feature) { + featureState.put(feature, Boolean.FALSE); + return this; + } + + public DelegatingDebugConfig override(Level level, int newLevel) { + levelState.put(level, newLevel); + return this; + } + + public DelegatingDebugConfig delegate(Feature feature) { + featureState.put(feature, null); + return this; + } + + public DelegatingDebugConfig delegate(Level level) { + levelState.put(level, null); + return this; + } + + @Override + public int getLogLevel() { + Integer ls = levelState.get(Level.LOG); + if (ls == null) { + return delegate.getLogLevel(); + } + return ls.intValue(); + } + + public boolean isLogEnabledForMethod() { + Boolean fs = featureState.get(Feature.LOG_METHOD); + if (fs == null) { + return delegate.isLogEnabledForMethod(); + } + return fs.booleanValue(); + } + + @Override + public boolean isMeterEnabled() { + Boolean fs = featureState.get(Feature.METER); + if (fs == null) { + return delegate.isMeterEnabled(); + } + return fs.booleanValue(); + } + + public boolean isMemUseTrackingEnabled() { + Boolean fs = featureState.get(Feature.TRACK_MEM_USE); + if (fs == null) { + return delegate.isMemUseTrackingEnabled(); + } + return fs.booleanValue(); + } + + @Override + public int getDumpLevel() { + Integer ls = levelState.get(Level.DUMP); + if (ls == null) { + return delegate.getDumpLevel(); + } + return ls.intValue(); + } + + public boolean isDumpEnabledForMethod() { + Boolean fs = featureState.get(Feature.DUMP_METHOD); + if (fs == null) { + return delegate.isDumpEnabledForMethod(); + } + return fs.booleanValue(); + } + + @Override + public boolean isVerifyEnabled() { + Boolean fs = featureState.get(Feature.VERIFY); + if (fs == null) { + return delegate.isVerifyEnabled(); + } + return fs.booleanValue(); + } + + public boolean isVerifyEnabledForMethod() { + Boolean fs = featureState.get(Feature.VERIFY_METHOD); + if (fs == null) { + return delegate.isVerifyEnabledForMethod(); + } + return fs.booleanValue(); + } + + @Override + public boolean isTimeEnabled() { + Boolean fs = featureState.get(Feature.TIME); + if (fs == null) { + return delegate.isTimeEnabled(); + } + return fs.booleanValue(); + } + + @Override + public RuntimeException interceptException(Throwable e) { + Boolean fs = featureState.get(Feature.INTERCEPT); + if (fs == null || fs) { + return delegate.interceptException(e); + } + return null; + } + + @Override + public Collection dumpHandlers() { + return delegate.dumpHandlers(); + } + + @Override + public Collection verifyHandlers() { + return delegate.verifyHandlers(); + } + + @Override + public PrintStream output() { + return delegate.output(); + } + + @Override + public void addToContext(Object o) { + delegate.addToContext(o); + } + + @Override + public void removeFromContext(Object o) { + delegate.removeFromContext(o); + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/Fingerprint.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/Fingerprint.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,145 @@ +/* + * 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.jvmci.debug; + +import java.util.*; +import java.util.stream.*; + +/** + * Facility for fingerprinting execution. + */ +public class Fingerprint implements AutoCloseable { + + public static final String ENABLED_PROPERTY_NAME = "jvmci.fingerprint"; + + /** + * Determines whether fingerprinting is enabled. This is set by the + * {@value #ENABLED_PROPERTY_NAME} system property when this class is initialized. + */ + public static final boolean ENABLED = Boolean.getBoolean(ENABLED_PROPERTY_NAME); + + private static final ThreadLocal current = ENABLED ? new ThreadLocal<>() : null; + + private final List events; + private int index; + + /** + * Creates an object to record a fingerprint. + */ + public Fingerprint() { + events = new ArrayList<>(); + index = -1; + } + + /** + * Creates an object to verify execution matches a given fingerprint. + * + * @param toVerifyAgainst the fingerprint events to verify against + */ + public Fingerprint(List toVerifyAgainst) { + this.events = toVerifyAgainst; + index = 0; + } + + /** + * Creates an object to verify execution matches a given fingerprint. + * + * @param toVerifyAgainst the fingerprint to verify against + */ + public Fingerprint(Fingerprint toVerifyAgainst) { + this(toVerifyAgainst.events); + } + + public Collection getEvents() { + return Collections.unmodifiableCollection(events); + } + + /** + * Starts fingerprint recording or verification for the current thread. At most one fingerprint + * object can be active for any thread. + */ + public Fingerprint open() { + if (ENABLED) { + assert current.get() == null; + current.set(this); + return this; + } + return null; + } + + /** + * Finishes fingerprint recording or verification for the current thread. + */ + public void close() { + if (ENABLED) { + assert current.get() == this; + current.set(null); + } + } + + private static final int BREAKPOINT_EVENT = Integer.getInteger(ENABLED_PROPERTY_NAME + ".breakpointEvent", -1); + + /** + * Submits an execution event for the purpose of recording or verifying a fingerprint. This must + * only be called if {@link #ENABLED} is {@code true}. + */ + public static void submit(String format, Object... args) { + assert ENABLED : "fingerprinting must be enabled (-D" + ENABLED_PROPERTY_NAME + "=true)"; + Fingerprint fingerprint = current.get(); + if (fingerprint != null) { + int eventId = fingerprint.nextEventId(); + if (eventId == BREAKPOINT_EVENT) { + // Set IDE breakpoint on the following line and set the relevant + // system property to debug a fingerprint verification error. + System.console(); + } + fingerprint.event(String.format(eventId + ": " + format, args)); + } + } + + private int nextEventId() { + return index == -1 ? events.size() : index; + } + + private static final int MAX_EVENT_TAIL_IN_ERROR_MESSAGE = Integer.getInteger("jvmci.fingerprint.errorEventTailLength", 50); + + private String tail() { + int start = Math.max(index - MAX_EVENT_TAIL_IN_ERROR_MESSAGE, 0); + return events.subList(start, index).stream().collect(Collectors.joining(String.format("%n"))); + } + + private void event(String entry) { + if (index == -1) { + events.add(entry); + } else { + if (index > events.size()) { + throw new InternalError(String.format("%s%nOriginal fingerprint limit reached", tail())); + } + String l = events.get(index); + if (!l.equals(entry)) { + throw new InternalError(String.format("%s%nFingerprint differs at event %d%nexpected: %s%n actual: %s", tail(), index, l, entry)); + } + index++; + } + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/Indent.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/Indent.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,51 @@ +/* + * 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.debug; + +/** + * Object used to close a debug {@link Debug#indent() indentation} scope. + *

      + * Example usage: + * + *

      + *
      + *      try (Indent i1 = Debug.logAndIndent("header message")) {
      + *          ...
      + *          Debug.log("message");
      + *          ...
      + *          try (Indent i2 = Debug.logAndIndent(sub-header message")) {
      + *              ...
      + *              Debug.log("inner message");
      + *              ...
      + *          }
      + *      }
      + *
      + * 
      + */ +public interface Indent extends AutoCloseable { + + /** + * Closes the current indentation scope. + */ + void close(); +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/JVMCIDebugConfig.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/JVMCIDebugConfig.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,303 @@ +/* + * 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.debug; + +import java.io.*; +import java.util.*; + +import com.oracle.jvmci.code.*; +import com.oracle.jvmci.meta.*; +import com.oracle.jvmci.options.*; + +public class JVMCIDebugConfig implements DebugConfig { + @SuppressWarnings("all") + private static boolean assertionsEnabled() { + boolean assertionsEnabled = false; + assert assertionsEnabled = true; + return assertionsEnabled; + } + + // @formatter:off + @Option(help = "Pattern for scope(s) in which dumping is enabled (see DebugFilter and Debug.dump)", type = OptionType.Debug) + public static final OptionValue Dump = new OptionValue<>(null); + @Option(help = "Pattern for scope(s) in which metering is enabled (see DebugFilter and Debug.metric). " + + "An empty value enables all metrics unconditionally.", type = OptionType.Debug) + public static final OptionValue Meter = new OptionValue<>(null); + @Option(help = "Pattern for scope(s) in which verification is enabled (see DebugFilter and Debug.verify).", type = OptionType.Debug) + public static final OptionValue Verify = new OptionValue() { + @Override + protected String defaultValue() { + return assertionsEnabled() ? "" : null; + } + }; + @Option(help = "Pattern for scope(s) in which memory use tracking is enabled (see DebugFilter and Debug.metric). " + + "An empty value enables all memory use trackers unconditionally.", type = OptionType.Debug) + public static final OptionValue TrackMemUse = new OptionValue<>(null); + @Option(help = "Pattern for scope(s) in which timing is enabled (see DebugFilter and Debug.timer). " + + "An empty value enables all timers unconditionally.", type = OptionType.Debug) + public static final OptionValue Time = new OptionValue<>(null); + @Option(help = "Pattern for scope(s) in which logging is enabled (see DebugFilter and Debug.log)", type = OptionType.Debug) + public static final OptionValue Log = new OptionValue<>(null); + @Option(help = "Pattern for filtering debug scope output based on method context (see MethodFilter)", type = OptionType.Debug) + public static final OptionValue MethodFilter = new OptionValue<>(null); + @Option(help = "Only check MethodFilter against the root method in the context if true, otherwise check all methods", type = OptionType.Debug) + public static final OptionValue MethodFilterRootOnly = new OptionValue<>(false); + + @Option(help = "How to print metric and timing values:%n" + + "Name - aggregate by unqualified name%n" + + "Partial - aggregate by partially qualified name (e.g., A.B.C.D.Counter and X.Y.Z.D.Counter will be merged to D.Counter)%n" + + "Complete - aggregate by qualified name%n" + + "Thread - aggregate by qualified name and thread", type = OptionType.Debug) + public static final OptionValue DebugValueSummary = new OptionValue<>("Name"); + @Option(help = "Omit reporting 0-value metrics", type = OptionType.Debug) + public static final OptionValue SuppressZeroDebugValues = new OptionValue<>(true); + @Option(help = "Only report debug values for maps which match the regular expression.", type = OptionType.Debug) + public static final OptionValue DebugValueThreadFilter = new OptionValue<>(null); + @Option(help = "Send JVMCI compiler IR to dump handlers on error", type = OptionType.Debug) + public static final OptionValue DumpOnError = new OptionValue<>(false); + @Option(help = "Intercept also bailout exceptions", type = OptionType.Debug) + public static final OptionValue InterceptBailout = new OptionValue<>(false); + @Option(help = "Enable more verbose log output when available", type = OptionType.Debug) + public static final OptionValue LogVerbose = new OptionValue<>(false); + // @formatter:on + + static boolean isNotEmpty(OptionValue option) { + return option.getValue() != null && !option.getValue().isEmpty(); + } + + public static boolean areDebugScopePatternsEnabled() { + return DumpOnError.getValue() || Dump.getValue() != null || Log.getValue() != null || areScopedMetricsOrTimersEnabled(); + } + + /** + * Determines if any of {@link #Meter}, {@link #Time} or {@link #TrackMemUse} has a non-null, + * non-empty value. + */ + public static boolean areScopedMetricsOrTimersEnabled() { + return isNotEmpty(Meter) || isNotEmpty(Time) || isNotEmpty(TrackMemUse); + } + + private final DebugFilter logFilter; + private final DebugFilter meterFilter; + private final DebugFilter trackMemUseFilter; + private final DebugFilter timerFilter; + private final DebugFilter dumpFilter; + private final DebugFilter verifyFilter; + private final MethodFilter[] methodFilter; + private final List dumpHandlers; + private final List verifyHandlers; + private final PrintStream output; + private final Set extraFilters = new HashSet<>(); + + public JVMCIDebugConfig(String logFilter, String meterFilter, String trackMemUseFilter, String timerFilter, String dumpFilter, String verifyFilter, String methodFilter, PrintStream output, + List dumpHandlers, List verifyHandlers) { + this.logFilter = DebugFilter.parse(logFilter); + this.meterFilter = DebugFilter.parse(meterFilter); + this.trackMemUseFilter = DebugFilter.parse(trackMemUseFilter); + this.timerFilter = DebugFilter.parse(timerFilter); + this.dumpFilter = DebugFilter.parse(dumpFilter); + this.verifyFilter = DebugFilter.parse(verifyFilter); + if (methodFilter == null || methodFilter.isEmpty()) { + this.methodFilter = null; + } else { + this.methodFilter = com.oracle.jvmci.debug.MethodFilter.parse(methodFilter); + } + + // Report the filters that have been configured so the user can verify it's what they expect + if (logFilter != null || meterFilter != null || timerFilter != null || dumpFilter != null || methodFilter != null) { + // TTY.println(Thread.currentThread().getName() + ": " + toString()); + } + this.dumpHandlers = dumpHandlers; + this.verifyHandlers = verifyHandlers; + this.output = output; + } + + public int getLogLevel() { + return getLevel(logFilter); + } + + public boolean isLogEnabledForMethod() { + return isEnabledForMethod(logFilter); + } + + public boolean isMeterEnabled() { + return isEnabled(meterFilter); + } + + public boolean isMemUseTrackingEnabled() { + return isEnabled(trackMemUseFilter); + } + + public int getDumpLevel() { + return getLevel(dumpFilter); + } + + public boolean isDumpEnabledForMethod() { + return isEnabledForMethod(dumpFilter); + } + + public boolean isVerifyEnabled() { + return isEnabled(verifyFilter); + } + + public boolean isVerifyEnabledForMethod() { + return isEnabledForMethod(verifyFilter); + } + + public boolean isTimeEnabled() { + return isEnabled(timerFilter); + } + + public PrintStream output() { + return output; + } + + private boolean isEnabled(DebugFilter filter) { + return getLevel(filter) > 0; + } + + private int getLevel(DebugFilter filter) { + int level; + if (filter == null) { + level = 0; + } else { + level = filter.matchLevel(Debug.currentScope()); + } + if (level > 0 && !checkMethodFilter()) { + level = 0; + } + return level; + } + + private boolean isEnabledForMethod(DebugFilter filter) { + return filter != null && checkMethodFilter(); + } + + /** + * Extracts a {@link JavaMethod} from an opaque debug context. + * + * @return the {@link JavaMethod} represented by {@code context} or null + */ + public static JavaMethod asJavaMethod(Object context) { + if (context instanceof JavaMethodContex) { + return ((JavaMethodContex) context).asJavaMethod(); + } + return null; + } + + private boolean checkMethodFilter() { + if (methodFilter == null && extraFilters.isEmpty()) { + return true; + } else { + JavaMethod lastMethod = null; + for (Object o : Debug.context()) { + if (extraFilters.contains(o)) { + return true; + } else if (methodFilter != null) { + JavaMethod method = asJavaMethod(o); + if (method != null) { + if (!MethodFilterRootOnly.getValue()) { + if (com.oracle.jvmci.debug.MethodFilter.matches(methodFilter, method)) { + return true; + } + } else { + /* + * The context values operate as a stack so if we want MethodFilter to + * only apply to the root method we have to check only the last method + * seen. + */ + lastMethod = method; + } + } + } + } + if (lastMethod != null && com.oracle.jvmci.debug.MethodFilter.matches(methodFilter, lastMethod)) { + return true; + } + return false; + } + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("Debug config:"); + add(sb, "Log", logFilter); + add(sb, "Meter", meterFilter); + add(sb, "Time", timerFilter); + add(sb, "Dump", dumpFilter); + add(sb, "MethodFilter", methodFilter); + return sb.toString(); + } + + private static void add(StringBuilder sb, String name, Object filter) { + if (filter != null) { + sb.append(' '); + sb.append(name); + sb.append('='); + if (filter instanceof Object[]) { + sb.append(Arrays.toString((Object[]) filter)); + } else { + sb.append(String.valueOf(filter)); + } + } + } + + @Override + public RuntimeException interceptException(Throwable e) { + if (e instanceof BailoutException && !InterceptBailout.getValue()) { + return null; + } + Debug.setConfig(Debug.fixedConfig(Debug.DEFAULT_LOG_LEVEL, Debug.DEFAULT_LOG_LEVEL, false, false, false, false, dumpHandlers, verifyHandlers, output)); + Debug.log(String.format("Exception occurred in scope: %s", Debug.currentScope())); + for (Object o : Debug.context()) { + if (DumpOnError.getValue()) { + Debug.dump(o, "Exception"); + } else { + Debug.log("Context obj %s", o); + } + + } + return null; + } + + @Override + public Collection dumpHandlers() { + return dumpHandlers; + } + + @Override + public Collection verifyHandlers() { + return verifyHandlers; + } + + @Override + public void addToContext(Object o) { + extraFilters.add(o); + } + + @Override + public void removeFromContext(Object o) { + extraFilters.remove(o); + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/JavaMethodContex.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/JavaMethodContex.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,33 @@ +/* + * 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.jvmci.debug; + +import com.oracle.jvmci.meta.*; + +/** + * Interface for objects used in Debug {@linkplain Debug#context() context} that can provide a + * {@link JavaMethod}. + */ +public interface JavaMethodContex { + JavaMethod asJavaMethod(); +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/LogStream.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/LogStream.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,477 @@ +/* + * 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.debug; + +import java.io.*; + +/** + * A utility for printing compiler debug and informational output to an output stream. + * + * A {@link LogStream} instance maintains an internal buffer that is flushed to the underlying + * output stream every time one of the {@code println} methods is invoked, or a newline character ( + * {@code '\n'}) is written. + * + * All of the {@code print} and {@code println} methods return the {code LogStream} instance on + * which they were invoked. This allows chaining of these calls to mitigate use of String + * concatenation by the caller. + * + * A {@code LogStream} maintains a current {@linkplain #indentationLevel() indentation} level. Each + * line of output written to this stream has {@code n} spaces prefixed to it where {@code n} is the + * value that would be returned by {@link #indentationLevel()} when the first character of a new + * line is written. + * + * A {@code LogStream} maintains a current {@linkplain #position() position} for the current line + * being written. This position can be advanced to a specified position by + * {@linkplain #fillTo(int, char) filling} this stream with a given character. + */ +public class LogStream { + + /** + * Null output stream that simply swallows any output sent to it. + */ + public static final LogStream SINK = new LogStream(); + + private static final PrintStream SINK_PS = new PrintStream(new OutputStream() { + + @Override + public void write(int b) throws IOException { + } + }); + + private LogStream() { + this.ps = null; + this.lineBuffer = null; + } + + /** + * The output stream to which this log stream writes. + */ + private final PrintStream ps; + + private final StringBuilder lineBuffer; + private int indentationLevel; + private char indentation = ' '; + private boolean indentationDisabled; + + public final PrintStream out() { + if (ps == null) { + return SINK_PS; + } + return ps; + } + + /** + * The system dependent line separator. + */ + public static final String LINE_SEPARATOR = System.getProperty("line.separator"); + + /** + * Creates a new log stream. + * + * @param os the underlying output stream to which prints are sent + */ + public LogStream(OutputStream os) { + ps = os instanceof PrintStream ? (PrintStream) os : new PrintStream(os); + lineBuffer = new StringBuilder(100); + } + + /** + * Creates a new log stream that shares the same {@linkplain #ps output stream} as a given + * {@link LogStream}. + * + * @param log a LogStream whose output stream is shared with this one + */ + public LogStream(LogStream log) { + ps = log.ps; + lineBuffer = new StringBuilder(100); + } + + /** + * Prepends {@link #indentation} to the current output line until its write position is equal to + * the current {@linkplain #indentationLevel()} level. + */ + private void indent() { + if (ps != null) { + if (!indentationDisabled && indentationLevel != 0) { + while (lineBuffer.length() < indentationLevel) { + lineBuffer.append(indentation); + } + } + } + } + + private LogStream flushLine(boolean withNewline) { + if (ps != null) { + if (withNewline) { + lineBuffer.append(LINE_SEPARATOR); + } + ps.print(lineBuffer.toString()); + ps.flush(); + lineBuffer.setLength(0); + } + return this; + } + + /** + * Flushes the stream. This is done by terminating the current line if it is not at position 0 + * and then flushing the underlying output stream. + */ + public void flush() { + if (ps != null) { + if (lineBuffer.length() != 0) { + flushLine(false); + } + ps.flush(); + } + } + + /** + * Gets the current column position of this log stream. + * + * @return the current column position of this log stream + */ + public int position() { + return lineBuffer == null ? 0 : lineBuffer.length(); + + } + + /** + * Gets the current indentation level for this log stream. + * + * @return the current indentation level for this log stream. + */ + public int indentationLevel() { + return indentationLevel; + } + + /** + * Adjusts the current indentation level of this log stream. + * + * @param delta + */ + public void adjustIndentation(int delta) { + if (delta < 0) { + indentationLevel = Math.max(0, indentationLevel + delta); + } else { + indentationLevel += delta; + } + } + + /** + * Gets the current indentation character of this log stream. + */ + public char indentation() { + return indentation; + } + + public void disableIndentation() { + indentationDisabled = true; + } + + public void enableIndentation() { + indentationDisabled = false; + } + + /** + * Sets the character used for indentation. + */ + public void setIndentation(char c) { + indentation = c; + } + + /** + * Advances this stream's {@linkplain #position() position} to a given position by repeatedly + * appending a given character as necessary. + * + * @param position the position to which this stream's position will be advanced + * @param filler the character used to pad the stream + */ + public LogStream fillTo(int position, char filler) { + if (ps != null) { + indent(); + while (lineBuffer.length() < position) { + lineBuffer.append(filler); + } + } + return this; + } + + /** + * Writes a boolean value to this stream as {@code "true"} or {@code "false"}. + * + * @param b the value to be printed + * @return this {@link LogStream} instance + */ + public LogStream print(boolean b) { + if (ps != null) { + indent(); + lineBuffer.append(b); + } + return this; + } + + /** + * Writes a boolean value to this stream followed by a {@linkplain #LINE_SEPARATOR line + * separator}. + * + * @param b the value to be printed + * @return this {@link LogStream} instance + */ + public LogStream println(boolean b) { + if (ps != null) { + indent(); + lineBuffer.append(b); + return flushLine(true); + } + return this; + } + + /** + * Writes a character value to this stream. + * + * @param c the value to be printed + * @return this {@link LogStream} instance + */ + public LogStream print(char c) { + if (ps != null) { + indent(); + lineBuffer.append(c); + if (c == '\n') { + if (lineBuffer.indexOf(LINE_SEPARATOR, lineBuffer.length() - LINE_SEPARATOR.length()) != -1) { + flushLine(false); + } + } + } + return this; + } + + /** + * Writes a character value to this stream followed by a {@linkplain #LINE_SEPARATOR line + * separator}. + * + * @param c the value to be printed + * @return this {@link LogStream} instance + */ + public LogStream println(char c) { + if (ps != null) { + indent(); + lineBuffer.append(c); + flushLine(true); + } + return this; + } + + /** + * Prints an int value. + * + * @param i the value to be printed + * @return this {@link LogStream} instance + */ + public LogStream print(int i) { + if (ps != null) { + indent(); + lineBuffer.append(i); + } + return this; + } + + /** + * Writes an int value to this stream followed by a {@linkplain #LINE_SEPARATOR line separator}. + * + * @param i the value to be printed + * @return this {@link LogStream} instance + */ + public LogStream println(int i) { + if (ps != null) { + indent(); + lineBuffer.append(i); + return flushLine(true); + } + return this; + } + + /** + * Writes a float value to this stream. + * + * @param f the value to be printed + * @return this {@link LogStream} instance + */ + public LogStream print(float f) { + if (ps != null) { + indent(); + lineBuffer.append(f); + } + return this; + } + + /** + * Writes a float value to this stream followed by a {@linkplain #LINE_SEPARATOR line separator} + * . + * + * @param f the value to be printed + * @return this {@link LogStream} instance + */ + public LogStream println(float f) { + if (ps != null) { + indent(); + lineBuffer.append(f); + return flushLine(true); + } + return this; + } + + /** + * Writes a long value to this stream. + * + * @param l the value to be printed + * @return this {@link LogStream} instance + */ + public LogStream print(long l) { + if (ps != null) { + indent(); + lineBuffer.append(l); + } + return this; + } + + /** + * Writes a long value to this stream followed by a {@linkplain #LINE_SEPARATOR line separator}. + * + * @param l the value to be printed + * @return this {@link LogStream} instance + */ + public LogStream println(long l) { + if (ps != null) { + indent(); + lineBuffer.append(l); + return flushLine(true); + } + return this; + } + + /** + * Writes a double value to this stream. + * + * @param d the value to be printed + * @return this {@link LogStream} instance + */ + public LogStream print(double d) { + if (ps != null) { + indent(); + lineBuffer.append(d); + } + return this; + } + + /** + * Writes a double value to this stream followed by a {@linkplain #LINE_SEPARATOR line + * separator}. + * + * @param d the value to be printed + * @return this {@link LogStream} instance + */ + public LogStream println(double d) { + if (ps != null) { + indent(); + lineBuffer.append(d); + return flushLine(true); + } + return this; + } + + /** + * Writes a {@code String} value to this stream. This method ensures that the + * {@linkplain #position() position} of this stream is updated correctly with respect to any + * {@linkplain #LINE_SEPARATOR line separators} present in {@code s}. + * + * @param s the value to be printed + * @return this {@link LogStream} instance + */ + public LogStream print(String s) { + if (ps != null) { + if (s == null) { + indent(); + lineBuffer.append(s); + return this; + } + + int index = 0; + int next = s.indexOf(LINE_SEPARATOR, index); + while (index < s.length()) { + indent(); + if (next > index) { + lineBuffer.append(s.substring(index, next)); + flushLine(true); + index = next + LINE_SEPARATOR.length(); + next = s.indexOf(LINE_SEPARATOR, index); + } else { + lineBuffer.append(s.substring(index)); + break; + } + } + } + return this; + } + + /** + * Writes a {@code String} value to this stream followed by a {@linkplain #LINE_SEPARATOR line + * separator}. + * + * @param s the value to be printed + * @return this {@link LogStream} instance + */ + public LogStream println(String s) { + if (ps != null) { + print(s); + flushLine(true); + } + return this; + } + + /** + * Writes a formatted string to this stream. + * + * @param format a format string as described in {@link String#format(String, Object...)} + * @param args the arguments to be formatted + * @return this {@link LogStream} instance + */ + public LogStream printf(String format, Object... args) { + if (ps != null) { + print(String.format(format, args)); + } + return this; + } + + /** + * Writes a {@linkplain #LINE_SEPARATOR line separator} to this stream. + * + * @return this {@code LogStream} instance + */ + public LogStream println() { + if (ps != null) { + indent(); + flushLine(true); + } + return this; + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/MethodFilter.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/MethodFilter.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,231 @@ +/* + * 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.debug; + +import com.oracle.jvmci.meta.JavaType; +import com.oracle.jvmci.meta.JavaMethod; +import com.oracle.jvmci.meta.Signature; +import java.util.*; +import java.util.regex.*; + +/** + * This class implements a method filter that can filter based on class name, method name and + * parameters. The syntax for the source pattern that is passed to the constructor is as follows: + * + *
      + * SourcePatterns = SourcePattern ["," SourcePatterns] .
      + * SourcePattern = [ Class "." ] method [ "(" [ Parameter { ";" Parameter } ] ")" ] .
      + * Parameter = Class | "int" | "long" | "float" | "double" | "short" | "char" | "boolean" .
      + * Class = { package "." } class .
      + * 
      + * + * + * Glob pattern matching (*, ?) is allowed in all parts of the source pattern. Examples for valid + * filters are: + * + *
        + *
      • + * + *
        + * visit(Argument;BlockScope)
        + * 
        + * + * Matches all methods named "visit", with the first parameter of type "Argument", and the second + * parameter of type "BlockScope". The packages of the parameter types are irrelevant.
      • + *
      • + * + *
        + * arraycopy(Object;;;;)
        + * 
        + * + * Matches all methods named "arraycopy", with the first parameter of type "Object", and four more + * parameters of any type. The packages of the parameter types are irrelevant.
      • + *
      • + * + *
        + * com.oracle.graal.compiler.graph.PostOrderNodeIterator.*
        + * 
        + * + * Matches all methods in the class "com.oracle.graal.compiler.graph.PostOrderNodeIterator".
      • + *
      • + * + *
        + * *
        + * 
        + * + * Matches all methods in all classes
      • + *
      • + * + *
        + * com.oracle.graal.compiler.graph.*.visit
        + * 
        + * + * Matches all methods named "visit" in classes in the package "com.oracle.graal.compiler.graph". + *
      • + * + *
        + * arraycopy,toString
        + * 
        + * + * Matches all methods named "arraycopy" or "toString", meaning that ',' acts as an or + * operator.
      • + *
      + */ +public class MethodFilter { + + private final Pattern clazz; + private final Pattern methodName; + private final Pattern[] signature; + + /** + * Parses a string containing list of comma separated filter patterns into an array of + * {@link MethodFilter}s. + */ + public static MethodFilter[] parse(String commaSeparatedPatterns) { + String[] filters = commaSeparatedPatterns.split(","); + MethodFilter[] methodFilters = new MethodFilter[filters.length]; + for (int i = 0; i < filters.length; i++) { + methodFilters[i] = new MethodFilter(filters[i]); + } + return methodFilters; + } + + /** + * Determines if a given method is matched by a given array of filters. + */ + public static boolean matches(MethodFilter[] filters, JavaMethod method) { + for (MethodFilter filter : filters) { + if (filter.matches(method)) { + return true; + } + } + return false; + } + + /** + * Determines if a given class name is matched by a given array of filters. + */ + public static boolean matchesClassName(MethodFilter[] filters, String className) { + for (MethodFilter filter : filters) { + if (filter.matchesClassName(className)) { + return true; + } + } + return false; + } + + public MethodFilter(String sourcePattern) { + String pattern = sourcePattern.trim(); + + // extract parameter part + int pos = pattern.indexOf('('); + if (pos != -1) { + if (pattern.charAt(pattern.length() - 1) != ')') { + throw new IllegalArgumentException("missing ')' at end of method filter pattern: " + pattern); + } + String[] signatureClasses = pattern.substring(pos + 1, pattern.length() - 1).split(";", -1); + signature = new Pattern[signatureClasses.length]; + for (int i = 0; i < signatureClasses.length; i++) { + signature[i] = createClassGlobPattern(signatureClasses[i].trim()); + } + pattern = pattern.substring(0, pos); + } else { + signature = null; + } + + // If there is at least one "." then everything before the last "." is the class name. + // Otherwise, the pattern contains only the method name. + pos = pattern.lastIndexOf('.'); + if (pos != -1) { + clazz = createClassGlobPattern(pattern.substring(0, pos)); + methodName = Pattern.compile(createGlobString(pattern.substring(pos + 1))); + } else { + clazz = null; + methodName = Pattern.compile(createGlobString(pattern)); + } + } + + static String createGlobString(String pattern) { + return Pattern.quote(pattern).replace("?", "\\E.\\Q").replace("*", "\\E.*\\Q"); + } + + private static Pattern createClassGlobPattern(String pattern) { + if (pattern.length() == 0) { + return null; + } else if (pattern.contains(".")) { + return Pattern.compile(createGlobString(pattern)); + } else { + return Pattern.compile("([^\\.\\$]*[\\.\\$])*" + createGlobString(pattern)); + } + } + + /** + * Determines if the class part of this filter matches a given class name. + */ + public boolean matchesClassName(String className) { + return clazz == null || clazz.matcher(className).matches(); + } + + public boolean matches(JavaMethod o) { + // check method name first, since MetaUtil.toJavaName is expensive + if (methodName != null && !methodName.matcher(o.getName()).matches()) { + return false; + } + if (clazz != null && !clazz.matcher(o.getDeclaringClass().toJavaName()).matches()) { + return false; + } + if (signature != null) { + Signature sig = o.getSignature(); + if (sig.getParameterCount(false) != signature.length) { + return false; + } + for (int i = 0; i < signature.length; i++) { + JavaType type = sig.getParameterType(i, null); + String javaName = type.toJavaName(); + if (signature[i] != null && !signature[i].matcher(javaName).matches()) { + return false; + } + } + } + return true; + } + + @Override + public String toString() { + StringBuilder buf = new StringBuilder("MethodFilter["); + String sep = ""; + if (clazz != null) { + buf.append(sep).append("clazz=").append(clazz); + sep = ", "; + } + if (methodName != null) { + buf.append(sep).append("methodName=").append(methodName); + sep = ", "; + } + if (signature != null) { + buf.append(sep).append("signature=").append(Arrays.toString(signature)); + sep = ", "; + } + return buf.append("]").toString(); + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/TTY.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/TTY.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,305 @@ +/* + * 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.debug; + +import java.io.*; +import java.lang.reflect.*; +import java.util.*; +import java.util.regex.*; + +/** + * A collection of static methods for printing debug and informational output to a global + * {@link LogStream}. The output can be (temporarily) suppressed per thread through use of a + * {@linkplain Filter filter}. + */ +public class TTY { + + /** + * Support for thread-local suppression of {@link TTY}. + */ + public static class Filter { + + private LogStream previous; + private final Thread thread = Thread.currentThread(); + + /** + * Creates an object that will suppress {@link TTY} for the current thread if the given + * filter does not match the given object. To revert the suppression state to how it was + * before this call, the {@link #remove()} method must be called on the suppression object. + * + * @param filter the pattern for matching. If {@code null}, then the match is successful. If + * it starts with "~", then a regular expression + * {@linkplain Pattern#matches(String, CharSequence) match} is performed where + * the regular expression is specified by {@code filter} without the "~" prefix. + * Otherwise, a simple {@linkplain String#contains(CharSequence) substring} match + * is performed where {@code filter} is the substring used. + * @param object an object whose {@linkplain Object#toString() string} value is matched + * against {@code filter} + */ + public Filter(String filter, Object object) { + boolean suppressed = false; + if (filter != null) { + String input = object.toString(); + if (filter.startsWith("~")) { + suppressed = !Pattern.matches(filter.substring(1), input); + } else { + suppressed = !input.contains(filter); + } + if (suppressed) { + previous = out(); + out.set(LogStream.SINK); + } + } + } + + /** + * Creates an object that will suppress {@link TTY} for the current thread. To revert the + * suppression state to how it was before this call, the {@link #remove()} method must be + * called on this filter object. + */ + public Filter() { + previous = out(); + out.set(LogStream.SINK); + } + + /** + * Reverts the suppression state of {@link TTY} to how it was before this object was + * constructed. + */ + public void remove() { + assert thread == Thread.currentThread(); + if (previous != null) { + out.set(previous); + } + } + } + + public static PrintStream cachedOut; + + public static void initialize(PrintStream ps) { + cachedOut = ps; + } + + private static LogStream createLog() { + if (cachedOut == null) { + // In case initialize() was not called. + cachedOut = System.out; + } + return new LogStream(cachedOut); + } + + private static final ThreadLocal out = new ThreadLocal() { + + @Override + protected LogStream initialValue() { + return createLog(); + } + }; + + public static boolean isSuppressed() { + return out.get() == LogStream.SINK; + } + + /** + * Gets the thread-local log stream to which the static methods of this class send their output. + * This will either be a global log stream or the global {@linkplain LogStream#SINK sink} + * depending on whether any suppression {@linkplain Filter filters} are in effect for the + * current thread. + */ + public static LogStream out() { + return out.get(); + } + + /** + * @see LogStream#print(String) + */ + public static void print(String s) { + out().print(s); + } + + /** + * @see LogStream#print(int) + */ + public static void print(int i) { + out().print(i); + } + + /** + * @see LogStream#print(long) + */ + public static void print(long i) { + out().print(i); + } + + /** + * @see LogStream#print(char) + */ + public static void print(char c) { + out().print(c); + } + + /** + * @see LogStream#print(boolean) + */ + public static void print(boolean b) { + out().print(b); + } + + /** + * @see LogStream#print(double) + */ + public static void print(double d) { + out().print(d); + } + + /** + * @see LogStream#print(float) + */ + public static void print(float f) { + out().print(f); + } + + /** + * @see LogStream#println(String) + */ + public static void println(String s) { + out().println(s); + } + + /** + * @see LogStream#println() + */ + public static void println() { + out().println(); + } + + /** + * @see LogStream#println(int) + */ + public static void println(int i) { + out().println(i); + } + + /** + * @see LogStream#println(long) + */ + public static void println(long l) { + out().println(l); + } + + /** + * @see LogStream#println(char) + */ + public static void println(char c) { + out().println(c); + } + + /** + * @see LogStream#println(boolean) + */ + public static void println(boolean b) { + out().println(b); + } + + /** + * @see LogStream#println(double) + */ + public static void println(double d) { + out().println(d); + } + + /** + * @see LogStream#println(float) + */ + public static void println(float f) { + out().println(f); + } + + public static void print(String format, Object... args) { + out().printf(format, args); + } + + public static void println(String format, Object... args) { + out().printf(format + "%n", args); + } + + public static void fillTo(int i) { + out().fillTo(i, ' '); + } + + public static void printFields(Class javaClass) { + final String className = javaClass.getSimpleName(); + TTY.println(className + " {"); + for (final Field field : javaClass.getFields()) { + printField(field, false); + } + TTY.println("}"); + } + + public static void printField(final Field field, boolean tabbed) { + final String fieldName = String.format("%35s", field.getName()); + try { + String prefix = tabbed ? "" : " " + fieldName + " = "; + String postfix = tabbed ? "\t" : "\n"; + if (field.getType() == int.class) { + TTY.print(prefix + field.getInt(null) + postfix); + } else if (field.getType() == boolean.class) { + TTY.print(prefix + field.getBoolean(null) + postfix); + } else if (field.getType() == float.class) { + TTY.print(prefix + field.getFloat(null) + postfix); + } else if (field.getType() == String.class) { + TTY.print(prefix + field.get(null) + postfix); + } else if (field.getType() == Map.class) { + Map m = (Map) field.get(null); + TTY.print(prefix + printMap(m) + postfix); + } else { + TTY.print(prefix + field.get(null) + postfix); + } + } catch (IllegalAccessException e) { + // do nothing. + } + } + + private static String printMap(Map m) { + StringBuilder sb = new StringBuilder(); + + List keys = new ArrayList<>(); + for (Object key : m.keySet()) { + keys.add((String) key); + } + Collections.sort(keys); + + for (String key : keys) { + sb.append(key); + sb.append("\t"); + sb.append(m.get(key)); + sb.append("\n"); + } + + return sb.toString(); + } + + public static void flush() { + out().flush(); + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/TopLevelDebugConfig.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/TopLevelDebugConfig.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,31 @@ +/* + * 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.debug; + +/** + * A marker class for a scoped debug configuration covering a compilation region. Useful for + * programmatically enabling debug config features. + * + */ +public class TopLevelDebugConfig extends DelegatingDebugConfig { +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/internal/AccumulatedDebugValue.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/internal/AccumulatedDebugValue.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,32 @@ +/* + * 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.jvmci.debug.internal; + +public abstract class AccumulatedDebugValue extends DebugValue { + protected final DebugValue flat; + + public AccumulatedDebugValue(String name, boolean conditional, DebugValue flat) { + super(name + "_Accm", conditional); + this.flat = flat; + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/internal/CloseableCounterImpl.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/internal/CloseableCounterImpl.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,70 @@ +/* + * 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.jvmci.debug.internal; + +import com.oracle.jvmci.debug.*; + +/** + * A helper class for DebugValues that can nest and need to split out accumulated and flat values + * for some kind of counter-like measurement. + */ +abstract class CloseableCounterImpl implements DebugCloseable { + + protected final CloseableCounterImpl parent; + protected final AccumulatedDebugValue counter; + protected final long start; + protected long nestedAmountToSubtract; + + CloseableCounterImpl(CloseableCounterImpl parent, AccumulatedDebugValue counter) { + this.parent = parent; + this.start = getCounterValue(); + this.counter = counter; + } + + @Override + public void close() { + long end = getCounterValue(); + long difference = end - start; + if (parent != null) { + if (!counter.getName().equals(parent.counter.getName())) { + parent.nestedAmountToSubtract += difference; + + // Look for our counter in an outer scope and fix up + // the adjustment to the flat count + CloseableCounterImpl ancestor = parent.parent; + while (ancestor != null) { + if (ancestor.counter.getName().equals(counter.getName())) { + ancestor.nestedAmountToSubtract -= difference; + break; + } + ancestor = ancestor.parent; + } + } + } + long flatAmount = difference - nestedAmountToSubtract; + counter.addToCurrentValue(difference); + counter.flat.addToCurrentValue(flatAmount); + } + + abstract long getCounterValue(); +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/internal/DebugHistogramAsciiPrinter.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/internal/DebugHistogramAsciiPrinter.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,103 @@ +/* + * 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.debug.internal; + +import java.io.*; +import java.util.*; + +import com.oracle.jvmci.debug.*; +import com.oracle.jvmci.debug.DebugHistogram.CountedValue; +import com.oracle.jvmci.debug.DebugHistogram.Printer; + +/** + * Renders a textual representation of a histogram to a given print stream. + */ +public class DebugHistogramAsciiPrinter implements Printer { + + public static final int NumberSize = 10; + public static final int DefaultNameSize = 50; + public static final int DefaultBarSize = 100; + public static final int DefaultScale = 1; + + private final PrintStream os; + private final int limit; + private final int nameSize; + private final int barSize; + private final int scale; + + public DebugHistogramAsciiPrinter(PrintStream os) { + this(os, Integer.MAX_VALUE, DefaultNameSize, DefaultBarSize, DefaultScale); + } + + /** + * @param os where to print + * @param limit limits printing to the {@code limit} most frequent values + * @param nameSize the width of the value names column + * @param barSize the width of the value frequency column + * @param scale a factor by which every result is divided + */ + public DebugHistogramAsciiPrinter(PrintStream os, int limit, int nameSize, int barSize, int scale) { + this.os = os; + this.limit = limit; + this.nameSize = nameSize; + this.barSize = barSize; + this.scale = scale; + } + + public void print(DebugHistogram histogram) { + List list = histogram.getValues(); + if (list.isEmpty()) { + os.printf("%s is empty.%n", histogram.getName()); + return; + } + + // Sum up the total number of elements. + long total = list.stream().mapToLong(CountedValue::getCount).sum(); + + // Print header. + os.printf("%s has %d unique elements and %d total elements:%n", histogram.getName(), list.size(), total / scale); + + long max = list.get(0).getCount() / scale; + final int lineSize = nameSize + NumberSize + barSize + 10; + printLine(os, '-', lineSize); + String formatString = "| %-" + nameSize + "s | %-" + NumberSize + "d | %-" + barSize + "s |\n"; + for (int i = 0; i < list.size() && i < limit; ++i) { + CountedValue cv = list.get(i); + long value = cv.getCount() / scale; + char[] bar = new char[(int) (((double) value / (double) max) * barSize)]; + Arrays.fill(bar, '='); + String objectString = String.valueOf(cv.getValue()); + if (objectString.length() > nameSize) { + objectString = objectString.substring(0, nameSize - 3) + "..."; + } + os.printf(formatString, objectString, value, new String(bar)); + } + printLine(os, '-', lineSize); + } + + private static void printLine(PrintStream printStream, char c, int lineSize) { + char[] charArr = new char[lineSize]; + Arrays.fill(charArr, c); + printStream.printf("%s%n", new String(charArr)); + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/internal/DebugHistogramImpl.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/internal/DebugHistogramImpl.java Tue Jun 09 00:22:49 2015 +0200 @@ -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.jvmci.debug.internal; + +import java.util.*; + +import com.oracle.jvmci.debug.*; + +public class DebugHistogramImpl implements DebugHistogram { + + private final String name; + private HashMap map = new HashMap<>(); + + public DebugHistogramImpl(String name) { + this.name = name; + } + + public void add(Object value) { + CountedValue cv = map.get(value); + if (cv == null) { + map.put(value, new CountedValue(1, value)); + } else { + cv.inc(); + } + } + + public void add(Object value, long count) { + CountedValue cv = map.get(value); + if (cv == null) { + map.put(value, new CountedValue(count, value)); + } else { + cv.add(count); + } + } + + @Override + public String getName() { + return name; + } + + public List getValues() { + ArrayList res = new ArrayList<>(map.values()); + Collections.sort(res); + return res; + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/internal/DebugHistogramRPrinter.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/internal/DebugHistogramRPrinter.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,81 @@ +/* + * 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.debug.internal; + +import java.io.*; +import java.util.*; + +import com.oracle.jvmci.debug.*; +import com.oracle.jvmci.debug.DebugHistogram.CountedValue; +import com.oracle.jvmci.debug.DebugHistogram.Printer; + +/** + * Renders a histogram as an R script to a given print stream. The R script emitted for a histogram + * is a simple set of statements for defining a vector of named objects. + */ +public class DebugHistogramRPrinter implements Printer { + + private PrintStream os; + private int limit; + + public DebugHistogramRPrinter(PrintStream os) { + this(os, Integer.MAX_VALUE); + } + + /** + * @param os where to print + * @param limit limits printing to the {@code limit} most frequent values + */ + public DebugHistogramRPrinter(PrintStream os, int limit) { + this.os = os; + this.limit = limit; + } + + public void print(DebugHistogram histogram) { + List list = histogram.getValues(); + if (list.isEmpty()) { + return; + } + + String var = histogram.getName().replace('-', '.').replace(' ', '_'); + os.print(var + " <- c("); + for (int i = 0; i < list.size() && i < limit; ++i) { + CountedValue cv = list.get(i); + if (i != 0) { + os.print(", "); + } + os.print(cv.getCount()); + } + os.println(");"); + + os.print("names(" + var + ") <- c("); + for (int i = 0; i < list.size() && i < limit; ++i) { + CountedValue cv = list.get(i); + if (i != 0) { + os.print(", "); + } + os.print("\"" + cv.getValue() + "\""); + } + os.println(");"); + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/internal/DebugScope.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/internal/DebugScope.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,489 @@ +/* + * 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.debug.internal; + +import java.io.*; +import java.util.*; +import java.util.concurrent.*; + +import com.oracle.jvmci.debug.*; + +public final class DebugScope implements Debug.Scope { + + private final class IndentImpl implements Indent { + + private static final String INDENTATION_INCREMENT = " "; + + final String indent; + final IndentImpl parentIndent; + + IndentImpl(IndentImpl parentIndent) { + this.parentIndent = parentIndent; + this.indent = (parentIndent == null ? "" : parentIndent.indent + INDENTATION_INCREMENT); + } + + private void printScopeName(StringBuilder str) { + if (logScopeName) { + if (parentIndent != null) { + parentIndent.printScopeName(str); + } + str.append(indent).append("[thread:").append(Thread.currentThread().getId()).append("] scope: ").append(getQualifiedName()).append(System.lineSeparator()); + logScopeName = false; + } + } + + public void log(int logLevel, String msg, Object... args) { + if (isLogEnabled(logLevel)) { + StringBuilder str = new StringBuilder(); + printScopeName(str); + str.append(indent); + String result = args.length == 0 ? msg : String.format(msg, args); + String lineSep = System.lineSeparator(); + str.append(result.replace(lineSep, lineSep.concat(indent))); + str.append(lineSep); + output.append(str); + lastUsedIndent = this; + } + } + + IndentImpl indent() { + lastUsedIndent = new IndentImpl(this); + return lastUsedIndent; + } + + @Override + public void close() { + if (parentIndent != null) { + lastUsedIndent = parentIndent; + } + } + } + + private static final ThreadLocal instanceTL = new ThreadLocal<>(); + private static final ThreadLocal lastClosedTL = new ThreadLocal<>(); + private static final ThreadLocal configTL = new ThreadLocal<>(); + private static final ThreadLocal lastExceptionThrownTL = new ThreadLocal<>(); + + private final DebugScope parent; + private final DebugConfig parentConfig; + private final boolean sandbox; + private IndentImpl lastUsedIndent; + private boolean logScopeName; + + private final Object[] context; + + private DebugValueMap valueMap; + + private String qualifiedName; + private final String unqualifiedName; + + private static final char SCOPE_SEP = '.'; + + private boolean meterEnabled; + private boolean timeEnabled; + private boolean memUseTrackingEnabled; + private boolean verifyEnabled; + + private int currentDumpLevel; + private int currentLogLevel; + + private PrintStream output; + + public static DebugScope getInstance() { + DebugScope result = instanceTL.get(); + if (result == null) { + DebugScope topLevelDebugScope = new DebugScope(Thread.currentThread()); + instanceTL.set(topLevelDebugScope); + return topLevelDebugScope; + } else { + return result; + } + } + + public static DebugConfig getConfig() { + return configTL.get(); + } + + static final Object[] EMPTY_CONTEXT = new Object[0]; + + private DebugScope(Thread thread) { + this(thread.getName(), null, false); + computeValueMap(thread.getName()); + DebugValueMap.registerTopLevel(getValueMap()); + } + + private DebugScope(String unqualifiedName, DebugScope parent, boolean sandbox, Object... context) { + this.parent = parent; + this.sandbox = sandbox; + this.parentConfig = getConfig(); + this.context = context; + this.unqualifiedName = unqualifiedName; + if (parent != null) { + logScopeName = !unqualifiedName.equals(""); + } else { + logScopeName = true; + } + + // Be pragmatic: provide a default log stream to prevent a crash if the stream is not + // set while logging + this.output = TTY.cachedOut; + assert context != null; + } + + private void computeValueMap(String name) { + if (parent != null) { + for (DebugValueMap child : parent.getValueMap().getChildren()) { + if (child.getName().equals(name)) { + this.valueMap = child; + return; + } + } + this.valueMap = new DebugValueMap(name); + parent.getValueMap().addChild(this.valueMap); + } else { + this.valueMap = new DebugValueMap(name); + } + } + + public void close() { + instanceTL.set(parent); + configTL.set(parentConfig); + lastClosedTL.set(this); + } + + public boolean isDumpEnabled(int dumpLevel) { + assert dumpLevel > 0; + return currentDumpLevel >= dumpLevel; + } + + /** + * Enable dumping at the new {@code dumpLevel} for the remainder of enclosing scopes. This only + * works if a {@link TopLevelDebugConfig} was installed at a higher scope. + * + * @param dumpLevel + */ + public static void setDumpLevel(int dumpLevel) { + TopLevelDebugConfig config = fetchTopLevelDebugConfig("setDebugLevel"); + if (config != null) { + config.override(DelegatingDebugConfig.Level.DUMP, dumpLevel); + recursiveUpdateFlags(); + } + } + + /** + * Enable logging at the new {@code logLevel} for the remainder of enclosing scopes. This only + * works if a {@link TopLevelDebugConfig} was installed at a higher scope. + * + * @param logLevel + */ + public static void setLogLevel(int logLevel) { + TopLevelDebugConfig config = fetchTopLevelDebugConfig("setLogLevel"); + if (config != null) { + config.override(DelegatingDebugConfig.Level.LOG, logLevel); + config.delegate(DelegatingDebugConfig.Feature.LOG_METHOD); + recursiveUpdateFlags(); + } + } + + private static void recursiveUpdateFlags() { + DebugScope c = DebugScope.getInstance(); + while (c != null) { + c.updateFlags(); + c = c.parent; + } + } + + private static TopLevelDebugConfig fetchTopLevelDebugConfig(String msg) { + DebugConfig config = getConfig(); + if (config instanceof TopLevelDebugConfig) { + return (TopLevelDebugConfig) config; + } else { + if (config == null) { + TTY.println("DebugScope.%s ignored because debugging is disabled", msg); + } else { + TTY.println("DebugScope.%s ignored because top level delegate config missing", msg); + } + return null; + } + } + + public boolean isVerifyEnabled() { + return verifyEnabled; + } + + public boolean isLogEnabled(int logLevel) { + assert logLevel > 0; + return currentLogLevel >= logLevel; + } + + public boolean isMeterEnabled() { + return meterEnabled; + } + + public boolean isTimeEnabled() { + return timeEnabled; + } + + public boolean isMemUseTrackingEnabled() { + return memUseTrackingEnabled; + } + + public void log(int logLevel, String msg, Object... args) { + if (isLogEnabled(logLevel)) { + getLastUsedIndent().log(logLevel, msg, args); + } + } + + public void dump(int dumpLevel, Object object, String formatString, Object... args) { + if (isDumpEnabled(dumpLevel)) { + DebugConfig config = getConfig(); + if (config != null) { + String message = String.format(formatString, args); + for (DebugDumpHandler dumpHandler : config.dumpHandlers()) { + dumpHandler.dump(object, message); + } + } + } + } + + /** + * This method exists mainly to allow a debugger (e.g., Eclipse) to force dump a graph. + */ + public static void forceDump(Object object, String format, Object... args) { + DebugConfig config = getConfig(); + if (config != null) { + String message = String.format(format, args); + for (DebugDumpHandler dumpHandler : config.dumpHandlers()) { + dumpHandler.dump(object, message); + } + } else { + TTY.println("Forced dump ignored because debugging is disabled - use -G:Dump=xxx option"); + } + } + + /** + * @see Debug#verify(Object, String) + */ + public void verify(Object object, String formatString, Object... args) { + if (isVerifyEnabled()) { + DebugConfig config = getConfig(); + if (config != null) { + String message = String.format(formatString, args); + for (DebugVerifyHandler handler : config.verifyHandlers()) { + handler.verify(object, message); + } + } + } + } + + /** + * Creates and enters a new debug scope which is either a child of the current scope or a + * disjoint top level scope. + * + * @param name the name of the new scope + * @param sandboxConfig the configuration to use for a new top level scope, or null if the new + * scope should be a child scope + * @param newContextObjects objects to be appended to the debug context + * @return the new scope which will be exited when its {@link #close()} method is called + */ + public DebugScope scope(CharSequence name, DebugConfig sandboxConfig, Object... newContextObjects) { + DebugScope newScope = null; + if (sandboxConfig != null) { + newScope = new DebugScope(name.toString(), this, true, newContextObjects); + configTL.set(sandboxConfig); + } else { + newScope = this.createChild(name.toString(), newContextObjects); + } + instanceTL.set(newScope); + newScope.updateFlags(); + return newScope; + } + + public RuntimeException handle(Throwable e) { + DebugScope lastClosed = lastClosedTL.get(); + assert lastClosed.parent == this : "Debug.handle() used with no matching Debug.scope(...) or Debug.sandbox(...)"; + if (e != lastExceptionThrownTL.get()) { + RuntimeException newException = null; + instanceTL.set(lastClosed); + try (DebugScope s = lastClosed) { + newException = s.interceptException(e); + } + assert instanceTL.get() == this; + assert lastClosed == lastClosedTL.get(); + if (newException == null) { + lastExceptionThrownTL.set(e); + } else { + lastExceptionThrownTL.set(newException); + throw newException; + } + } + if (e instanceof Error) { + throw (Error) e; + } + if (e instanceof RuntimeException) { + throw (RuntimeException) e; + } + throw new RuntimeException(e); + } + + private void updateFlags() { + DebugConfig config = getConfig(); + if (config == null) { + meterEnabled = false; + memUseTrackingEnabled = false; + timeEnabled = false; + verifyEnabled = false; + + currentDumpLevel = 0; + + // Be pragmatic: provide a default log stream to prevent a crash if the stream is not + // set while logging + output = TTY.cachedOut; + } else { + meterEnabled = config.isMeterEnabled(); + memUseTrackingEnabled = config.isMemUseTrackingEnabled(); + timeEnabled = config.isTimeEnabled(); + verifyEnabled = config.isVerifyEnabled(); + output = config.output(); + currentDumpLevel = config.getDumpLevel(); + currentLogLevel = config.getLogLevel(); + } + } + + private RuntimeException interceptException(final Throwable e) { + final DebugConfig config = getConfig(); + if (config != null) { + try (DebugScope s = scope("InterceptException", null, e)) { + return config.interceptException(e); + } catch (Throwable t) { + return new RuntimeException("Exception while intercepting exception", t); + } + } + return null; + } + + private DebugValueMap getValueMap() { + if (valueMap == null) { + computeValueMap(unqualifiedName); + } + return valueMap; + } + + long getCurrentValue(int index) { + return getValueMap().getCurrentValue(index); + } + + void setCurrentValue(int index, long l) { + getValueMap().setCurrentValue(index, l); + } + + private DebugScope createChild(String newName, Object[] newContext) { + return new DebugScope(newName, this, false, newContext); + } + + public Iterable getCurrentContext() { + final DebugScope scope = this; + return new Iterable() { + + @Override + public Iterator iterator() { + return new Iterator() { + + DebugScope currentScope = scope; + int objectIndex; + + @Override + public boolean hasNext() { + selectScope(); + return currentScope != null; + } + + private void selectScope() { + while (currentScope != null && currentScope.context.length <= objectIndex) { + currentScope = currentScope.sandbox ? null : currentScope.parent; + objectIndex = 0; + } + } + + @Override + public Object next() { + selectScope(); + if (currentScope != null) { + return currentScope.context[objectIndex++]; + } + throw new IllegalStateException("May only be called if there is a next element."); + } + + @Override + public void remove() { + throw new UnsupportedOperationException("This iterator is read only."); + } + }; + } + }; + } + + public static T call(Callable callable) { + try { + return callable.call(); + } catch (Exception e) { + if (e instanceof RuntimeException) { + throw (RuntimeException) e; + } else { + throw new RuntimeException(e); + } + } + } + + public void setConfig(DebugConfig newConfig) { + configTL.set(newConfig); + updateFlags(); + } + + public String getQualifiedName() { + if (qualifiedName == null) { + if (parent == null) { + qualifiedName = unqualifiedName; + } else { + qualifiedName = parent.getQualifiedName() + SCOPE_SEP + unqualifiedName; + } + } + return qualifiedName; + } + + public Indent pushIndentLogger() { + lastUsedIndent = getLastUsedIndent().indent(); + return lastUsedIndent; + } + + public IndentImpl getLastUsedIndent() { + if (lastUsedIndent == null) { + if (parent != null) { + lastUsedIndent = new IndentImpl(parent.getLastUsedIndent()); + } else { + lastUsedIndent = new IndentImpl(null); + } + } + return lastUsedIndent; + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/internal/DebugValue.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/internal/DebugValue.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,94 @@ +/* + * 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.debug.internal; + +/** + * A name and index for a value managed in a thread local value map. All access to the value is made + * via a {@link DebugValue} instance. + */ +public abstract class DebugValue implements Comparable { + + private final String name; + private int index; + private boolean conditional; + + protected DebugValue(String name, boolean conditional) { + this.name = name; + this.index = -1; + this.conditional = conditional; + } + + public long getCurrentValue() { + ensureInitialized(); + return DebugScope.getInstance().getCurrentValue(index); + } + + protected void setCurrentValue(long l) { + ensureInitialized(); + DebugScope.getInstance().setCurrentValue(index, l); + } + + public void setConditional(boolean flag) { + conditional = flag; + } + + public boolean isConditional() { + return conditional; + } + + private void ensureInitialized() { + if (index == -1) { + index = KeyRegistry.register(this); + } + } + + protected void addToCurrentValue(long value) { + setCurrentValue(getCurrentValue() + value); + } + + /** + * Gets the globally unique index for the value represented by this object. + */ + public int getIndex() { + ensureInitialized(); + return index; + } + + /** + * Gets the globally unique name for the value represented by this object. + */ + public String getName() { + return name; + } + + public int compareTo(DebugValue o) { + return name.compareTo(o.name); + } + + @Override + public String toString() { + return name + "@" + index; + } + + public abstract String toString(long value); +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/internal/DebugValueMap.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/internal/DebugValueMap.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,171 @@ +/* + * 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.debug.internal; + +import java.util.*; + +/** + * A node in a tree of {@link DebugValue}s. + */ +public class DebugValueMap { + + private static final List topLevelMaps = new ArrayList<>(); + + private long[] values; + private List children; + private String name; + + public DebugValueMap(String name) { + this.name = name; + } + + public void setCurrentValue(int index, long l) { + ensureSize(index); + values[index] = l; + } + + public long getCurrentValue(int index) { + ensureSize(index); + return values[index]; + } + + public void clearChildren() { + if (children != null) { + children.clear(); + } + } + + public void reset() { + if (values != null) { + Arrays.fill(values, 0L); + } + if (children != null) { + for (DebugValueMap child : children) { + child.reset(); + } + } + } + + private void ensureSize(int index) { + if (values == null) { + values = new long[index + 1]; + } + if (values.length <= index) { + values = Arrays.copyOf(values, index + 1); + } + } + + private int capacity() { + return (values == null) ? 0 : values.length; + } + + public void addChild(DebugValueMap map) { + if (children == null) { + children = new ArrayList<>(4); + } + children.add(map); + } + + public List getChildren() { + if (children == null) { + return Collections.emptyList(); + } else { + return Collections.unmodifiableList(children); + } + } + + public boolean hasChildren() { + return children != null && !children.isEmpty(); + } + + public String getName() { + return this.name; + } + + @Override + public String toString() { + return "DebugValueMap<" + getName() + ">"; + } + + public static synchronized void registerTopLevel(DebugValueMap map) { + topLevelMaps.add(map); + } + + public static synchronized List getTopLevelMaps() { + return topLevelMaps; + } + + public void normalize() { + if (hasChildren()) { + Map occurred = new HashMap<>(); + for (DebugValueMap map : children) { + String mapName = map.getName(); + if (!occurred.containsKey(mapName)) { + occurred.put(mapName, map); + map.normalize(); + } else { + occurred.get(mapName).mergeWith(map); + occurred.get(mapName).normalize(); + } + } + + if (occurred.values().size() < children.size()) { + // At least one duplicate was found. + children.clear(); + for (DebugValueMap map : occurred.values()) { + addChild(map); + map.normalize(); + } + } + } + } + + private void mergeWith(DebugValueMap map) { + if (map.hasChildren()) { + if (hasChildren()) { + children.addAll(map.children); + } else { + children = map.children; + } + map.children = null; + } + + int size = Math.max(this.capacity(), map.capacity()); + ensureSize(size); + for (int i = 0; i < size; ++i) { + long curValue = getCurrentValue(i); + long otherValue = map.getCurrentValue(i); + setCurrentValue(i, curValue + otherValue); + } + } + + public void group() { + if (this.hasChildren()) { + List oldChildren = new ArrayList<>(this.children); + this.children.clear(); + for (DebugValueMap map : oldChildren) { + mergeWith(map); + } + } + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/internal/KeyRegistry.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/internal/KeyRegistry.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,57 @@ +/* + * 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.debug.internal; + +import java.util.*; + +/** + * Registry for allocating a globally unique integer id to each {@link DebugValue}. + */ +public class KeyRegistry { + + private static final Map keyMap = new HashMap<>(); + private static final List debugValues = new ArrayList<>(); + + /** + * Ensures a given debug value is registered. + * + * @return the globally unique id for {@code value} + */ + public static synchronized int register(DebugValue value) { + String name = value.getName(); + if (!keyMap.containsKey(name)) { + keyMap.put(name, debugValues.size()); + debugValues.add(value); + } + return keyMap.get(name); + } + + /** + * Gets a immutable view of the registered debug values. + * + * @return a list where {@code get(i).getIndex() == i} + */ + public static synchronized List getDebugValues() { + return Collections.unmodifiableList(debugValues); + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/internal/MemUseTrackerImpl.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/internal/MemUseTrackerImpl.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,98 @@ +/* + * 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.debug.internal; + +import static com.oracle.jvmci.debug.DebugCloseable.*; +import static java.lang.Thread.*; + +import java.lang.management.*; + +import com.oracle.jvmci.debug.*; +import com.sun.management.ThreadMXBean; + +public final class MemUseTrackerImpl extends AccumulatedDebugValue implements DebugMemUseTracker { + + private static final ThreadMXBean threadMXBean = (ThreadMXBean) ManagementFactory.getThreadMXBean(); + + /** + * The amount of memory allocated by {@link ThreadMXBean#getThreadAllocatedBytes(long)} itself. + */ + private static final long threadMXBeanOverhead = -getCurrentThreadAllocatedBytes() + getCurrentThreadAllocatedBytes(); + + public static long getCurrentThreadAllocatedBytes() { + return threadMXBean.getThreadAllocatedBytes(currentThread().getId()) - threadMXBeanOverhead; + } + + /** + * Records the most recent active tracker. + */ + private static final ThreadLocal currentTracker = new ThreadLocal<>(); + + public MemUseTrackerImpl(String name, boolean conditional) { + super(name, conditional, new DebugValue(name + "_Flat", conditional) { + + @Override + public String toString(long value) { + return valueToString(value); + } + }); + } + + @Override + public DebugCloseable start() { + if (!isConditional() || Debug.isMemUseTrackingEnabled()) { + MemUseCloseableCounterImpl result = new MemUseCloseableCounterImpl(this); + currentTracker.set(result); + return result; + } else { + return VOID_CLOSEABLE; + } + } + + public static String valueToString(long value) { + return String.format("%d bytes", value); + } + + @Override + public String toString(long value) { + return valueToString(value); + } + + private static final class MemUseCloseableCounterImpl extends CloseableCounterImpl implements DebugCloseable { + + private MemUseCloseableCounterImpl(AccumulatedDebugValue counter) { + super(currentTracker.get(), counter); + } + + @Override + long getCounterValue() { + return getCurrentThreadAllocatedBytes(); + } + + @Override + public void close() { + super.close(); + currentTracker.set(parent); + } + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/internal/MetricImpl.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/internal/MetricImpl.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,51 @@ +/* + * 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.debug.internal; + +import com.oracle.jvmci.debug.*; + +public final class MetricImpl extends DebugValue implements DebugMetric { + + public MetricImpl(String name, boolean conditional) { + super(name, conditional); + if (isEnabled()) { + // Allows for zero-count metrics to be shown + getCurrentValue(); + } + } + + public void increment() { + add(1); + } + + public void add(long value) { + if (isEnabled()) { + super.addToCurrentValue(value); + } + } + + @Override + public String toString(long value) { + return Long.toString(value); + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/internal/TimerImpl.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/internal/TimerImpl.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,136 @@ +/* + * 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.debug.internal; + +import static com.oracle.jvmci.debug.DebugCloseable.*; + +import java.lang.management.*; +import java.util.concurrent.*; + +import com.oracle.jvmci.debug.*; + +public final class TimerImpl extends AccumulatedDebugValue implements DebugTimer { + + private static final ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean(); + + /** + * Records the most recent active timer. + */ + private static final ThreadLocal currentTimer = new ThreadLocal<>(); + + static class FlatTimer extends DebugValue implements DebugTimer { + private TimerImpl accm; + + public FlatTimer(String name, boolean conditional) { + super(name + "_Flat", conditional); + } + + @Override + public String toString(long value) { + return valueToString(value); + } + + public TimeUnit getTimeUnit() { + return accm.getTimeUnit(); + } + + public DebugCloseable start() { + return accm.start(); + } + } + + public TimerImpl(String name, boolean conditional) { + super(name, conditional, new FlatTimer(name, conditional)); + ((FlatTimer) flat).accm = this; + } + + @Override + public DebugCloseable start() { + if (!isConditional() || Debug.isTimeEnabled()) { + AbstractTimer result; + if (threadMXBean.isCurrentThreadCpuTimeSupported()) { + result = new CpuTimeTimer(this); + } else { + result = new SystemNanosTimer(this); + } + currentTimer.set(result); + return result; + } else { + return VOID_CLOSEABLE; + } + } + + public static String valueToString(long value) { + return String.format("%d.%d ms", value / 1000000, (value / 100000) % 10); + } + + public DebugTimer getFlat() { + return (FlatTimer) flat; + } + + @Override + public String toString(long value) { + return valueToString(value); + } + + public TimeUnit getTimeUnit() { + return TimeUnit.NANOSECONDS; + } + + private abstract static class AbstractTimer extends CloseableCounterImpl implements DebugCloseable { + + private AbstractTimer(AccumulatedDebugValue counter) { + super(currentTimer.get(), counter); + } + + @Override + public void close() { + super.close(); + currentTimer.set(parent); + } + } + + private final class SystemNanosTimer extends AbstractTimer { + + public SystemNanosTimer(TimerImpl timer) { + super(timer); + } + + @Override + protected long getCounterValue() { + return System.nanoTime(); + } + } + + private final class CpuTimeTimer extends AbstractTimer { + + public CpuTimeTimer(TimerImpl timer) { + super(timer); + } + + @Override + protected long getCounterValue() { + return threadMXBean.getCurrentThreadCpuTime(); + } + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.hotspot.amd64/src/com/oracle/jvmci/hotspot/amd64/AMD64HotSpotJVMCIBackendFactory.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.hotspot.amd64/src/com/oracle/jvmci/hotspot/amd64/AMD64HotSpotJVMCIBackendFactory.java Tue Jun 09 00:22:49 2015 +0200 @@ -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 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.hotspot.amd64/src/com/oracle/jvmci/hotspot/amd64/AMD64HotSpotRegisterConfig.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.hotspot.amd64/src/com/oracle/jvmci/hotspot/amd64/AMD64HotSpotRegisterConfig.java Tue Jun 09 00:22:49 2015 +0200 @@ -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 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.hotspot.jfr/src/com/oracle/jvmci/hotspot/jfr/events/JFREventProvider.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.hotspot.jfr/src/com/oracle/jvmci/hotspot/jfr/events/JFREventProvider.java Tue Jun 09 00:22:49 2015 +0200 @@ -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.hotspot.jfr.events; + +import java.net.*; + +import com.oracle.jrockit.jfr.*; +import com.oracle.jvmci.hotspot.*; +import com.oracle.jvmci.hotspot.events.*; +import com.oracle.jvmci.hotspot.events.EmptyEventProvider.EmptyCompilerFailureEvent; +import com.oracle.jvmci.hotspot.events.EmptyEventProvider.EmptyCompilationEvent; +import com.oracle.jvmci.service.*; + +/** + * A JFR implementation for {@link EventProvider}. This implementation is used when Flight Recorder + * is turned on. + */ +@ServiceProvider(EventProvider.class) +public final class JFREventProvider implements EventProvider { + + private final boolean enabled; + + @SuppressWarnings("deprecation") + public JFREventProvider() { + enabled = HotSpotJVMCIRuntime.runtime().getConfig().flightRecorder; + if (enabled) { + try { + /* + * The "HotSpot JVM" producer is a native producer and we cannot use it. So we + * create our own. This has the downside that Mission Control is confused and + * doesn't show JVMCI events in the "Code" tab. There are plans to revise the JFR + * code for JDK 9. + */ + Producer producer = new Producer("HotSpot JVM", "Oracle Hotspot JVM", "http://www.oracle.com/hotspot/jvm/"); + producer.register(); + // Register event classes with Producer. + for (Class c : JFREventProvider.class.getDeclaredClasses()) { + if (c.isAnnotationPresent(EventDefinition.class)) { + assert com.oracle.jrockit.jfr.InstantEvent.class.isAssignableFrom(c) : c; + registerEvent(producer, c); + } + } + } catch (URISyntaxException e) { + throw new InternalError(e); + } + } + } + + /** + * Register an event class with the {@link Producer}. + * + * @param c event class + * @return the {@link EventToken event token} + */ + @SuppressWarnings({"deprecation", "javadoc", "unchecked"}) + private static EventToken registerEvent(Producer producer, Class c) { + try { + return producer.addEvent((Class) c); + } catch (InvalidEventDefinitionException | InvalidValueException e) { + throw new InternalError(e); + } + } + + public CompilationEvent newCompilationEvent() { + if (enabled) { + return new JFRCompilationEvent(); + } + return new EmptyCompilationEvent(); + } + + /** + * A JFR compilation event. + * + *

      + * See: event {@code Compilation} in {@code src/share/vm/trace/trace.xml} + */ + @SuppressWarnings("deprecation") + @EventDefinition(name = "Compilation", path = "vm/compiler/compilation") + public static class JFRCompilationEvent extends com.oracle.jrockit.jfr.DurationEvent implements CompilationEvent { + + /* + * FIXME method should be a Method* but we can't express that in Java. + */ + @ValueDefinition(name = "Java Method") public String method; + @ValueDefinition(name = "Compilation ID", relationKey = "COMP_ID") public int compileId; + @ValueDefinition(name = "Compilation Level") public short compileLevel; + @ValueDefinition(name = "Succeeded") public boolean succeeded; + @ValueDefinition(name = "On Stack Replacement") public boolean isOsr; + @ValueDefinition(name = "Compiled Code Size", contentType = ContentType.Bytes) public int codeSize; + @ValueDefinition(name = "Inlined Code Size", contentType = ContentType.Bytes) public int inlinedBytes; + + public void setMethod(String method) { + this.method = method; + } + + public void setCompileId(int id) { + this.compileId = id; + } + + public void setCompileLevel(int compileLevel) { + this.compileLevel = (short) compileLevel; + } + + public void setSucceeded(boolean succeeded) { + this.succeeded = succeeded; + } + + public void setIsOsr(boolean isOsr) { + this.isOsr = isOsr; + } + + public void setCodeSize(int codeSize) { + this.codeSize = codeSize; + } + + public void setInlinedBytes(int inlinedBytes) { + this.inlinedBytes = inlinedBytes; + } + } + + public CompilerFailureEvent newCompilerFailureEvent() { + if (enabled) { + return new JFRCompilerFailureEvent(); + } + return new EmptyCompilerFailureEvent(); + } + + /** + * A JFR compiler failure event. + * + *

      + * See: event {@code CompilerFailure} in {@code src/share/vm/trace/trace.xml} + */ + @SuppressWarnings("deprecation") + @EventDefinition(name = "Compilation Failure", path = "vm/compiler/failure") + public static class JFRCompilerFailureEvent extends com.oracle.jrockit.jfr.InstantEvent implements CompilerFailureEvent { + + @ValueDefinition(name = "Compilation ID", relationKey = "COMP_ID") public int compileId; + @ValueDefinition(name = "Message", description = "The failure message") public String failure; + + public void setCompileId(int id) { + this.compileId = id; + } + + public void setMessage(String message) { + this.failure = message; + } + } + +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.hotspot.sparc/src/com/oracle/jvmci/hotspot/sparc/SPARCHotSpotJVMCIBackendFactory.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.hotspot.sparc/src/com/oracle/jvmci/hotspot/sparc/SPARCHotSpotJVMCIBackendFactory.java Tue Jun 09 00:22:49 2015 +0200 @@ -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 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.hotspot.sparc/src/com/oracle/jvmci/hotspot/sparc/SPARCHotSpotRegisterConfig.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.hotspot.sparc/src/com/oracle/jvmci/hotspot/sparc/SPARCHotSpotRegisterConfig.java Tue Jun 09 00:22:49 2015 +0200 @@ -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 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/CompilationStatistics.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/CompilationStatistics.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,212 @@ +/* + * 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.hotspot; + +import static java.lang.Thread.*; + +import java.io.*; +import java.lang.annotation.*; +import java.lang.management.*; +import java.lang.reflect.*; +import java.util.*; +import java.util.concurrent.*; + +import com.sun.management.ThreadMXBean; + +@SuppressWarnings("unused") +public final class CompilationStatistics { + + private static final long RESOLUTION = 100000000; + private static final boolean ENABLED = Boolean.getBoolean("jvmci.comp.stats"); + + private static final CompilationStatistics DUMMY = new CompilationStatistics(null, false); + + private static ConcurrentLinkedDeque list = new ConcurrentLinkedDeque<>(); + + private static final ThreadLocal> current = new ThreadLocal>() { + + @Override + protected Deque initialValue() { + return new ArrayDeque<>(); + } + }; + + @Retention(RetentionPolicy.RUNTIME) + @Target(ElementType.FIELD) + private static @interface NotReported { + } + + @Retention(RetentionPolicy.RUNTIME) + @Target(ElementType.FIELD) + private static @interface TimeValue { + } + + private static long zeroTime = System.nanoTime(); + + private static long getThreadAllocatedBytes() { + ThreadMXBean thread = (ThreadMXBean) ManagementFactory.getThreadMXBean(); + return thread.getThreadAllocatedBytes(currentThread().getId()); + } + + @NotReported private final long startTime; + @NotReported private long threadAllocatedBytesStart; + + private int bytecodeCount; + private int codeSize; + @TimeValue private long duration; + private long memoryUsed; + private final boolean osr; + private final String holder; + private final String name; + private final String signature; + + private CompilationStatistics(HotSpotResolvedJavaMethod method, boolean osr) { + this.osr = osr; + if (method != null) { + holder = method.getDeclaringClass().getName(); + name = method.getName(); + signature = method.getSignature().toMethodDescriptor(); + startTime = System.nanoTime(); + bytecodeCount = method.getCodeSize(); + threadAllocatedBytesStart = getThreadAllocatedBytes(); + } else { + holder = ""; + name = ""; + signature = ""; + startTime = 0; + } + } + + public void finish(HotSpotResolvedJavaMethod method, HotSpotInstalledCode code) { + if (ENABLED) { + duration = System.nanoTime() - startTime; + codeSize = (int) code.getCodeSize(); + memoryUsed = getThreadAllocatedBytes() - threadAllocatedBytesStart; + if (current.get().getLast() != this) { + throw new RuntimeException("mismatch in finish()"); + } + current.get().removeLast(); + } + } + + public static CompilationStatistics current() { + return current.get().isEmpty() ? null : current.get().getLast(); + } + + public static CompilationStatistics create(HotSpotResolvedJavaMethod method, boolean isOSR) { + if (ENABLED) { + CompilationStatistics stats = new CompilationStatistics(method, isOSR); + list.add(stats); + current.get().addLast(stats); + return stats; + } else { + return DUMMY; + } + } + + @SuppressWarnings("deprecation") + public static void clear(String dumpName) { + if (!ENABLED) { + return; + } + try { + ConcurrentLinkedDeque snapshot = list; + long snapshotZeroTime = zeroTime; + + list = new ConcurrentLinkedDeque<>(); + zeroTime = System.nanoTime(); + + Date now = new Date(); + String dateString = (now.getYear() + 1900) + "-" + (now.getMonth() + 1) + "-" + now.getDate() + "-" + now.getHours() + "" + now.getMinutes(); + + dumpCompilations(snapshot, dumpName, dateString); + + try (FileOutputStream fos = new FileOutputStream("timeline_" + dateString + "_" + dumpName + ".csv", true); PrintStream out = new PrintStream(fos)) { + + long[] timeSpent = new long[10000]; + int maxTick = 0; + for (CompilationStatistics stats : snapshot) { + long start = stats.startTime - snapshotZeroTime; + long duration = stats.duration; + if (start < 0) { + duration -= -start; + start = 0; + } + + int tick = (int) (start / RESOLUTION); + long timeLeft = RESOLUTION - (start % RESOLUTION); + + while (tick < timeSpent.length && duration > 0) { + if (tick > maxTick) { + maxTick = tick; + } + timeSpent[tick] += Math.min(timeLeft, duration); + duration -= timeLeft; + tick++; + timeLeft = RESOLUTION; + } + } + String timelineName = System.getProperty("stats.timeline.name"); + if (timelineName != null && !timelineName.isEmpty()) { + out.print(timelineName + "\t"); + } + for (int i = 0; i <= maxTick; i++) { + out.print((timeSpent[i] * 100 / RESOLUTION) + "\t"); + } + out.println(); + } + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + protected static void dumpCompilations(ConcurrentLinkedDeque snapshot, String dumpName, String dateString) throws IllegalAccessException, FileNotFoundException { + String fileName = "compilations_" + dateString + "_" + dumpName + ".csv"; + try (PrintStream out = new PrintStream(fileName)) { + // output the list of all compilations + + Field[] declaredFields = CompilationStatistics.class.getDeclaredFields(); + ArrayList fields = new ArrayList<>(); + for (Field field : declaredFields) { + if (!Modifier.isStatic(field.getModifiers()) && !field.isAnnotationPresent(NotReported.class)) { + fields.add(field); + } + } + for (Field field : fields) { + out.print(field.getName() + "\t"); + } + out.println(); + for (CompilationStatistics stats : snapshot) { + for (Field field : fields) { + if (field.isAnnotationPresent(TimeValue.class)) { + double value = field.getLong(stats) / 1000000d; + out.print(String.format(Locale.ENGLISH, "%.3f", value) + "\t"); + } else { + out.print(field.get(stats) + "\t"); + } + } + out.println(); + } + } + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/CompilationTask.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/CompilationTask.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,293 @@ +/* + * 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; + +import static com.oracle.jvmci.common.UnsafeAccess.*; +import static com.oracle.jvmci.debug.Debug.*; +import static com.oracle.jvmci.compiler.Compiler.*; + +import java.lang.management.*; +import java.util.concurrent.*; + +import com.oracle.jvmci.code.*; +import com.oracle.jvmci.compiler.Compiler; +import com.oracle.jvmci.debug.*; +import com.oracle.jvmci.debug.Debug.Scope; +import com.oracle.jvmci.debug.internal.*; +import com.oracle.jvmci.hotspot.events.*; +import com.oracle.jvmci.hotspot.events.EventProvider.CompilationEvent; +import com.oracle.jvmci.hotspot.events.EventProvider.CompilerFailureEvent; +import com.oracle.jvmci.meta.*; +import com.oracle.jvmci.service.*; + +//JaCoCo Exclude + +public class CompilationTask { + + private static final DebugMetric BAILOUTS = Debug.metric("Bailouts"); + + private static final EventProvider eventProvider; + static { + EventProvider provider = Services.loadSingle(EventProvider.class, false); + if (provider == null) { + eventProvider = new EmptyEventProvider(); + } else { + eventProvider = provider; + } + } + private static final Compiler compiler = Services.loadSingle(Compiler.class, true); + + private final HotSpotResolvedJavaMethod method; + private final int entryBCI; + private final int id; + + /** + * Specifies whether the compilation result is installed as the + * {@linkplain HotSpotNmethod#isDefault() default} nmethod for the compiled method. + */ + private final boolean installAsDefault; + + /** + * A {@link com.sun.management.ThreadMXBean} to be able to query some information about the + * current compiler thread, e.g. total allocated bytes. + */ + private static final com.sun.management.ThreadMXBean threadMXBean = (com.sun.management.ThreadMXBean) ManagementFactory.getThreadMXBean(); + + /** + * The address of the JVMCIEnv associated with this compilation or 0L if no such object exists. + */ + private final long jvmciEnv; + + public CompilationTask(HotSpotResolvedJavaMethod method, int entryBCI, long jvmciEnv, int id, boolean installAsDefault) { + this.method = method; + this.entryBCI = entryBCI; + this.id = id; + this.jvmciEnv = jvmciEnv; + this.installAsDefault = installAsDefault; + } + + public ResolvedJavaMethod getMethod() { + return method; + } + + /** + * Returns the compilation id of this task. + * + * @return compile id + */ + public int getId() { + return id; + } + + public int getEntryBCI() { + return entryBCI; + } + + /** + * Time spent in compilation. + */ + private static final DebugTimer CompilationTime = Debug.timer("CompilationTime"); + + /** + * Meters the {@linkplain CompilationResult#getBytecodeSize() bytecodes} compiled. + */ + private static final DebugMetric CompiledBytecodes = Debug.metric("CompiledBytecodes"); + + public static final DebugTimer CodeInstallationTime = Debug.timer("CodeInstallation"); + + public void runCompilation() { + HotSpotVMConfig config = HotSpotJVMCIRuntime.runtime().getConfig(); + final long threadId = Thread.currentThread().getId(); + long startCompilationTime = System.nanoTime(); + HotSpotInstalledCode installedCode = null; + final boolean isOSR = entryBCI != Compiler.INVOCATION_ENTRY_BCI; + + // Log a compilation event. + CompilationEvent compilationEvent = eventProvider.newCompilationEvent(); + + // If there is already compiled code for this method on our level we simply return. + // JVMCI compiles are always at the highest compile level, even in non-tiered mode so we + // only need to check for that value. + if (method.hasCodeAtLevel(entryBCI, config.compilationLevelFullOptimization)) { + return; + } + + CompilationResult result = null; + try (DebugCloseable a = CompilationTime.start()) { + CompilationStatistics stats = CompilationStatistics.create(method, isOSR); + final boolean printCompilation = PrintCompilation.getValue() && !TTY.isSuppressed(); + if (printCompilation) { + TTY.println(getMethodDescription() + "..."); + } + + TTY.Filter filter = new TTY.Filter(PrintFilter.getValue(), method); + final long start = System.currentTimeMillis(); + final long allocatedBytesBefore = threadMXBean.getThreadAllocatedBytes(threadId); + + try (Scope s = Debug.scope("Compiling", new DebugDumpScope(String.valueOf(id), true))) { + // Begin the compilation event. + compilationEvent.begin(); + + result = compiler.compile(method, entryBCI, mustRecordMethodInlining(config)); + + result.setId(getId()); + } catch (Throwable e) { + throw Debug.handle(e); + } finally { + // End the compilation event. + compilationEvent.end(); + + filter.remove(); + final boolean printAfterCompilation = PrintAfterCompilation.getValue() && !TTY.isSuppressed(); + + if (printAfterCompilation || printCompilation) { + final long stop = System.currentTimeMillis(); + final int targetCodeSize = result != null ? result.getTargetCodeSize() : -1; + final long allocatedBytesAfter = threadMXBean.getThreadAllocatedBytes(threadId); + final long allocatedBytes = (allocatedBytesAfter - allocatedBytesBefore) / 1024; + + if (printAfterCompilation) { + TTY.println(getMethodDescription() + String.format(" | %4dms %5dB %5dkB", stop - start, targetCodeSize, allocatedBytes)); + } else if (printCompilation) { + TTY.println(String.format("%-6d JVMCI %-70s %-45s %-50s | %4dms %5dB %5dkB", id, "", "", "", stop - start, targetCodeSize, allocatedBytes)); + } + } + } + + try (DebugCloseable b = CodeInstallationTime.start()) { + installedCode = (HotSpotInstalledCode) installMethod(result); + } + stats.finish(method, installedCode); + } catch (BailoutException bailout) { + BAILOUTS.increment(); + if (ExitVMOnBailout.getValue()) { + TTY.cachedOut.println(method.format("Bailout in %H.%n(%p)")); + bailout.printStackTrace(TTY.cachedOut); + System.exit(-1); + } else if (PrintBailout.getValue()) { + TTY.cachedOut.println(method.format("Bailout in %H.%n(%p)")); + bailout.printStackTrace(TTY.cachedOut); + } + } catch (Throwable t) { + if (PrintStackTraceOnException.getValue() || ExitVMOnException.getValue()) { + t.printStackTrace(TTY.cachedOut); + } + + // Log a failure event. + CompilerFailureEvent event = eventProvider.newCompilerFailureEvent(); + if (event.shouldWrite()) { + event.setCompileId(getId()); + event.setMessage(t.getMessage()); + event.commit(); + } + + if (ExitVMOnException.getValue()) { + System.exit(-1); + } + } finally { + int compiledBytecodes = 0; + int codeSize = 0; + if (result != null) { + compiledBytecodes = result.getBytecodeSize(); + } + if (installedCode != null) { + codeSize = installedCode.getSize(); + } + CompiledBytecodes.add(compiledBytecodes); + + // Log a compilation event. + if (compilationEvent.shouldWrite()) { + compilationEvent.setMethod(method.format("%H.%n(%p)")); + compilationEvent.setCompileId(getId()); + compilationEvent.setCompileLevel(config.compilationLevelFullOptimization); + compilationEvent.setSucceeded(result != null && installedCode != null); + compilationEvent.setIsOsr(isOSR); + compilationEvent.setCodeSize(codeSize); + compilationEvent.setInlinedBytes(compiledBytecodes); + compilationEvent.commit(); + } + + if (jvmciEnv != 0) { + long ctask = unsafe.getAddress(jvmciEnv + config.jvmciEnvTaskOffset); + assert ctask != 0L; + unsafe.putInt(ctask + config.compileTaskNumInlinedBytecodesOffset, compiledBytecodes); + } + long compilationTime = System.nanoTime() - startCompilationTime; + if ((config.ciTime || config.ciTimeEach) && installedCode != null) { + long timeUnitsPerSecond = TimeUnit.NANOSECONDS.convert(1, TimeUnit.SECONDS); + CompilerToVM c2vm = HotSpotJVMCIRuntime.runtime().getCompilerToVM(); + c2vm.notifyCompilationStatistics(id, method, entryBCI != Compiler.INVOCATION_ENTRY_BCI, compiledBytecodes, compilationTime, timeUnitsPerSecond, installedCode); + } + } + } + + /** + * Determines whether to disable method inlining recording for the method being compiled. + */ + private boolean mustRecordMethodInlining(HotSpotVMConfig config) { + if (config.ciTime || config.ciTimeEach || CompiledBytecodes.isEnabled()) { + return true; + } + if (jvmciEnv == 0 || unsafe.getByte(jvmciEnv + config.jvmciEnvJvmtiCanHotswapOrPostBreakpointOffset) != 0) { + return true; + } + return false; + } + + private String getMethodDescription() { + return String.format("%-6d JVMCI %-70s %-45s %-50s %s", id, method.getDeclaringClass().getName(), method.getName(), method.getSignature().toMethodDescriptor(), + entryBCI == Compiler.INVOCATION_ENTRY_BCI ? "" : "(OSR@" + entryBCI + ") "); + } + + private InstalledCode installMethod(final CompilationResult compResult) { + final HotSpotCodeCacheProvider codeCache = (HotSpotCodeCacheProvider) HotSpotJVMCIRuntime.runtime().getHostJVMCIBackend().getCodeCache(); + InstalledCode installedCode = null; + try (Scope s = Debug.scope("CodeInstall", new DebugDumpScope(String.valueOf(id), true), codeCache, method)) { + installedCode = codeCache.installMethod(method, compResult, jvmciEnv, installAsDefault); + } catch (Throwable e) { + throw Debug.handle(e); + } + return installedCode; + } + + @Override + public String toString() { + return "Compilation[id=" + id + ", " + method.format("%H.%n(%p)") + (entryBCI == Compiler.INVOCATION_ENTRY_BCI ? "" : "@" + entryBCI) + "]"; + } + + /** + * Compiles a method to machine code. + */ + public static void compileMethod(HotSpotResolvedJavaMethod method, int entryBCI, long jvmciEnv, int id) { + // Ensure a debug configuration for this thread is initialized + if (Debug.isEnabled() && DebugScope.getConfig() == null) { + DebugEnvironment.initialize(TTY.cachedOut); + } + + CompilationTask task = new CompilationTask(method, entryBCI, jvmciEnv, id, true); + try (DebugConfigScope dcs = setConfig(new TopLevelDebugConfig())) { + task.runCompilation(); + } + return; + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/CompileTheWorld.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/CompileTheWorld.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,503 @@ +/* + * 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.hotspot; + +import static com.oracle.jvmci.compiler.Compiler.*; +import static com.oracle.jvmci.debug.internal.MemUseTrackerImpl.*; + +import java.io.*; +import java.lang.annotation.*; +import java.lang.reflect.*; +import java.net.*; +import java.util.*; +import java.util.concurrent.*; +import java.util.concurrent.atomic.*; +import java.util.jar.*; +import java.util.stream.*; + +import com.oracle.jvmci.compiler.*; +import com.oracle.jvmci.compiler.CompilerThreadFactory.DebugConfigAccess; +import com.oracle.jvmci.compiler.Compiler; +import com.oracle.jvmci.debug.*; +import com.oracle.jvmci.debug.internal.*; +import com.oracle.jvmci.meta.*; +import com.oracle.jvmci.options.*; +import com.oracle.jvmci.options.OptionUtils.OptionConsumer; +import com.oracle.jvmci.options.OptionValue.OverrideScope; +import com.oracle.jvmci.runtime.*; + +/** + * This class implements compile-the-world functionality with JVMCI. + */ +public final class CompileTheWorld { + + /** + * Magic token to trigger reading files from the boot class path. + */ + public static final String SUN_BOOT_CLASS_PATH = "sun.boot.class.path"; + + public static class Options { + // @formatter:off + @Option(help = "Compile all methods in all classes on given class path", type = OptionType.Debug) + public static final OptionValue CompileTheWorldClasspath = new OptionValue<>(SUN_BOOT_CLASS_PATH); + @Option(help = "Verbose CompileTheWorld operation", type = OptionType.Debug) + public static final OptionValue CompileTheWorldVerbose = new OptionValue<>(true); + @Option(help = "The number of CompileTheWorld iterations to perform", type = OptionType.Debug) + public static final OptionValue CompileTheWorldIterations = new OptionValue<>(1); + @Option(help = "Only compile methods matching this filter", type = OptionType.Debug) + public static final OptionValue CompileTheWorldMethodFilter = new OptionValue<>(null); + @Option(help = "Exclude methods matching this filter from compilation", type = OptionType.Debug) + public static final OptionValue CompileTheWorldExcludeMethodFilter = new OptionValue<>(null); + @Option(help = "First class to consider when using -XX:+CompileTheWorld", type = OptionType.Debug) + public static final OptionValue CompileTheWorldStartAt = new OptionValue<>(1); + @Option(help = "Last class to consider when using -XX:+CompileTheWorld", type = OptionType.Debug) + public static final OptionValue CompileTheWorldStopAt = new OptionValue<>(Integer.MAX_VALUE); + @Option(help = "Option value overrides to use during compile the world. For example, " + + "to disable inlining and partial escape analysis specify '-PartialEscapeAnalysis -Inline'. " + + "The format for each option is the same as on the command line just without the '-G:' prefix.", type = OptionType.Debug) + public static final OptionValue CompileTheWorldConfig = new OptionValue<>(null); + + @Option(help = "Run CTW using as many threads as there are processors on the system", type = OptionType.Debug) + public static final OptionValue CompileTheWorldMultiThreaded = new OptionValue<>(false); + @Option(help = "Number of threads to use for multithreaded CTW. Defaults to Runtime.getRuntime().availableProcessors()", type = OptionType.Debug) + public static final OptionValue CompileTheWorldThreads = new OptionValue<>(0); + // @formatter:on + + /** + * Overrides {@link #CompileTheWorldStartAt} and {@link #CompileTheWorldStopAt} from + * {@code -XX} HotSpot options of the same name if the latter have non-default values. + */ + public static void overrideWithNativeOptions(HotSpotVMConfig c) { + if (c.compileTheWorldStartAt != 1) { + CompileTheWorldStartAt.setValue(c.compileTheWorldStartAt); + } + if (c.compileTheWorldStopAt != Integer.MAX_VALUE) { + CompileTheWorldStopAt.setValue(c.compileTheWorldStopAt); + } + } + } + + /** + * A mechanism for overriding JVMCI options that affect compilation. A {@link Config} object + * should be used in a try-with-resources statement to ensure overriding of options is scoped + * properly. For example: + * + *

      +     *     Config config = ...;
      +     *     try (AutoCloseable s = config == null ? null : config.apply()) {
      +     *         // perform a JVMCI compilation
      +     *     }
      +     * 
      + */ + @SuppressWarnings("serial") + public static class Config extends HashMap, Object> implements OptionConsumer { + /** + * Creates a {@link Config} object by parsing a set of space separated override options. + * + * @param options a space separated set of option value settings with each option setting in + * a format compatible with + * {@link OptionUtils#parseOption(String, OptionConsumer)}. Ignored if null. + */ + public Config(String options) { + if (options != null) { + for (String option : options.split("\\s+")) { + OptionUtils.parseOption(option, this); + } + } + } + + /** + * Applies the overrides represented by this object. The overrides are in effect until + * {@link OverrideScope#close()} is called on the returned object. + */ + OverrideScope apply() { + return OptionValue.override(this); + } + + public void set(OptionDescriptor desc, Object value) { + put(desc.getOptionValue(), value); + } + } + + /** List of Zip/Jar files to compile (see {@link Options#CompileTheWorldClasspath}). */ + private final String files; + + /** Class index to start compilation at (see {@link Options#CompileTheWorldStartAt}). */ + private final int startAt; + + /** Class index to stop compilation at (see {@link Options#CompileTheWorldStopAt}). */ + private final int stopAt; + + /** Only compile methods matching one of the filters in this array if the array is non-null. */ + private final MethodFilter[] methodFilters; + + /** Exclude methods matching one of the filters in this array if the array is non-null. */ + private final MethodFilter[] excludeMethodFilters; + + // Counters + private int classFileCounter = 0; + private AtomicLong compiledMethodsCounter = new AtomicLong(); + private AtomicLong compileTime = new AtomicLong(); + private AtomicLong memoryUsed = new AtomicLong(); + + private boolean verbose; + private final Config config; + + /** + * Signal that the threads should start compiling in multithreaded mode. + */ + private boolean running; + + private ThreadPoolExecutor threadPool; + + /** + * Creates a compile-the-world instance. + * + * @param files {@link File#pathSeparator} separated list of Zip/Jar files to compile + * @param startAt index of the class file to start compilation at + * @param stopAt index of the class file to stop compilation at + * @param methodFilters + * @param excludeMethodFilters + */ + public CompileTheWorld(String files, Config config, int startAt, int stopAt, String methodFilters, String excludeMethodFilters, boolean verbose) { + this.files = files; + this.startAt = startAt; + this.stopAt = stopAt; + this.methodFilters = methodFilters == null || methodFilters.isEmpty() ? null : MethodFilter.parse(methodFilters); + this.excludeMethodFilters = excludeMethodFilters == null || excludeMethodFilters.isEmpty() ? null : MethodFilter.parse(excludeMethodFilters); + this.verbose = verbose; + this.config = config; + + // We don't want the VM to exit when a method fails to compile... + config.putIfAbsent(ExitVMOnException, false); + + // ...but we want to see exceptions. + config.putIfAbsent(PrintBailout, true); + config.putIfAbsent(PrintStackTraceOnException, true); + config.putIfAbsent(HotSpotResolvedJavaMethodImpl.Options.UseProfilingInformation, false); + } + + /** + * Compiles all methods in all classes in the Zip/Jar archive files in + * {@link Options#CompileTheWorldClasspath}. If {@link Options#CompileTheWorldClasspath} + * contains the magic token {@link #SUN_BOOT_CLASS_PATH} passed up from HotSpot we take the + * files from the boot class path. + */ + public void compile() throws Throwable { + // By default only report statistics for the CTW threads themselves + if (JVMCIDebugConfig.DebugValueThreadFilter.hasDefaultValue()) { + JVMCIDebugConfig.DebugValueThreadFilter.setValue("^CompileTheWorld"); + } + + if (SUN_BOOT_CLASS_PATH.equals(files)) { + final String[] entries = System.getProperty(SUN_BOOT_CLASS_PATH).split(File.pathSeparator); + String bcpFiles = ""; + for (int i = 0; i < entries.length; i++) { + final String entry = entries[i]; + + // We stop at rt.jar, unless it is the first boot class path entry. + if (entry.endsWith("rt.jar") && (i > 0)) { + break; + } + if (i > 0) { + bcpFiles += File.pathSeparator; + } + bcpFiles += entry; + } + compile(bcpFiles); + } else { + compile(files); + } + } + + public void println() { + println(""); + } + + public void println(String format, Object... args) { + println(String.format(format, args)); + } + + public void println(String s) { + if (verbose) { + TTY.println(s); + } + } + + @SuppressWarnings("unused") + private static void dummy() { + } + + /** + * Compiles all methods in all classes in the Zip/Jar files passed. + * + * @param fileList {@link File#pathSeparator} separated list of Zip/Jar files to compile + * @throws IOException + */ + private void compile(String fileList) throws IOException { + final String[] entries = fileList.split(File.pathSeparator); + long start = System.currentTimeMillis(); + + CompilerThreadFactory factory = new CompilerThreadFactory("CompileTheWorld", new DebugConfigAccess() { + public JVMCIDebugConfig getDebugConfig() { + if (Debug.isEnabled() && DebugScope.getConfig() == null) { + return DebugEnvironment.initialize(System.out); + } + return null; + } + }); + + try { + // compile dummy method to get compiler initilized outside of the config debug override. + HotSpotResolvedJavaMethod dummyMethod = (HotSpotResolvedJavaMethod) JVMCI.getRuntime().getHostJVMCIBackend().getMetaAccess().lookupJavaMethod( + CompileTheWorld.class.getDeclaredMethod("dummy")); + CompilationTask task = new CompilationTask(dummyMethod, Compiler.INVOCATION_ENTRY_BCI, 0L, dummyMethod.allocateCompileId(Compiler.INVOCATION_ENTRY_BCI), false); + task.runCompilation(); + } catch (NoSuchMethodException | SecurityException e1) { + e1.printStackTrace(); + } + + /* + * Always use a thread pool, even for single threaded mode since it simplifies the use of + * DebugValueThreadFilter to filter on the thread names. + */ + int threadCount = 1; + if (Options.CompileTheWorldMultiThreaded.getValue()) { + threadCount = Options.CompileTheWorldThreads.getValue(); + if (threadCount == 0) { + threadCount = Runtime.getRuntime().availableProcessors(); + } + } else { + running = true; + } + threadPool = new ThreadPoolExecutor(threadCount, threadCount, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue(), factory); + + try (OverrideScope s = config.apply()) { + for (int i = 0; i < entries.length; i++) { + final String entry = entries[i]; + + // For now we only compile all methods in all classes in zip/jar files. + if (!entry.endsWith(".zip") && !entry.endsWith(".jar")) { + println("CompileTheWorld : Skipped classes in " + entry); + println(); + continue; + } + + if (methodFilters == null || methodFilters.length == 0) { + println("CompileTheWorld : Compiling all classes in " + entry); + } else { + String include = Arrays.asList(methodFilters).stream().map(MethodFilter::toString).collect(Collectors.joining(", ")); + println("CompileTheWorld : Compiling all methods in " + entry + " matching one of the following filters: " + include); + } + if (excludeMethodFilters != null && excludeMethodFilters.length > 0) { + String exclude = Arrays.asList(excludeMethodFilters).stream().map(MethodFilter::toString).collect(Collectors.joining(", ")); + println("CompileTheWorld : Excluding all methods matching one of the following filters: " + exclude); + } + println(); + + URL url = new URL("jar", "", "file:" + entry + "!/"); + ClassLoader loader = new URLClassLoader(new URL[]{url}); + + JarFile jarFile = new JarFile(entry); + Enumeration e = jarFile.entries(); + + while (e.hasMoreElements()) { + JarEntry je = e.nextElement(); + if (je.isDirectory() || !je.getName().endsWith(".class")) { + continue; + } + + // Are we done? + if (classFileCounter >= stopAt) { + break; + } + + String className = je.getName().substring(0, je.getName().length() - ".class".length()); + String dottedClassName = className.replace('/', '.'); + classFileCounter++; + + if (methodFilters != null && !MethodFilter.matchesClassName(methodFilters, dottedClassName)) { + continue; + } + if (excludeMethodFilters != null && MethodFilter.matchesClassName(excludeMethodFilters, dottedClassName)) { + continue; + } + + if (dottedClassName.startsWith("jdk.management.") || dottedClassName.startsWith("jdk.internal.cmm.*")) { + continue; + } + + try { + // Load and initialize class + Class javaClass = Class.forName(dottedClassName, true, loader); + + // Pre-load all classes in the constant pool. + try { + HotSpotResolvedObjectType objectType = HotSpotResolvedObjectTypeImpl.fromObjectClass(javaClass); + ConstantPool constantPool = objectType.constantPool(); + for (int cpi = 1; cpi < constantPool.length(); cpi++) { + constantPool.loadReferencedType(cpi, HotSpotConstantPool.Bytecodes.LDC); + } + } catch (Throwable t) { + // If something went wrong during pre-loading we just ignore it. + println("Preloading failed for (%d) %s: %s", classFileCounter, className, t); + } + + // Are we compiling this class? + MetaAccessProvider metaAccess = JVMCI.getRuntime().getHostJVMCIBackend().getMetaAccess(); + if (classFileCounter >= startAt) { + println("CompileTheWorld (%d) : %s", classFileCounter, className); + + // Compile each constructor/method in the class. + for (Constructor constructor : javaClass.getDeclaredConstructors()) { + HotSpotResolvedJavaMethod javaMethod = (HotSpotResolvedJavaMethod) metaAccess.lookupJavaMethod(constructor); + if (canBeCompiled(javaMethod, constructor.getModifiers())) { + compileMethod(javaMethod); + } + } + for (Method method : javaClass.getDeclaredMethods()) { + HotSpotResolvedJavaMethod javaMethod = (HotSpotResolvedJavaMethod) metaAccess.lookupJavaMethod(method); + if (canBeCompiled(javaMethod, method.getModifiers())) { + compileMethod(javaMethod); + } + } + } + } catch (Throwable t) { + println("CompileTheWorld (%d) : Skipping %s %s", classFileCounter, className, t.toString()); + t.printStackTrace(); + } + } + jarFile.close(); + } + } + + if (!running) { + startThreads(); + } + int wakeups = 0; + while (threadPool.getCompletedTaskCount() != threadPool.getTaskCount()) { + if (wakeups % 15 == 0) { + TTY.println("CompileTheWorld : Waiting for " + (threadPool.getTaskCount() - threadPool.getCompletedTaskCount()) + " compiles"); + } + try { + threadPool.awaitTermination(1, TimeUnit.SECONDS); + wakeups++; + } catch (InterruptedException e) { + } + } + threadPool = null; + + long elapsedTime = System.currentTimeMillis() - start; + + println(); + if (Options.CompileTheWorldMultiThreaded.getValue()) { + TTY.println("CompileTheWorld : Done (%d classes, %d methods, %d ms elapsed, %d ms compile time, %d bytes of memory used)", classFileCounter, compiledMethodsCounter.get(), elapsedTime, + compileTime.get(), memoryUsed.get()); + } else { + TTY.println("CompileTheWorld : Done (%d classes, %d methods, %d ms, %d bytes of memory used)", classFileCounter, compiledMethodsCounter.get(), compileTime.get(), memoryUsed.get()); + } + } + + private synchronized void startThreads() { + running = true; + // Wake up any waiting threads + notifyAll(); + } + + private synchronized void waitToRun() { + while (!running) { + try { + wait(); + } catch (InterruptedException e) { + } + } + } + + private void compileMethod(HotSpotResolvedJavaMethod method) throws InterruptedException, ExecutionException { + if (methodFilters != null && !MethodFilter.matches(methodFilters, method)) { + return; + } + if (excludeMethodFilters != null && MethodFilter.matches(excludeMethodFilters, method)) { + return; + } + Future task = threadPool.submit(new Runnable() { + public void run() { + waitToRun(); + try (OverrideScope s = config.apply()) { + compileMethod(method, classFileCounter); + } + } + }); + if (threadPool.getCorePoolSize() == 1) { + task.get(); + } + } + + /** + * Compiles a method and gathers some statistics. + */ + private void compileMethod(HotSpotResolvedJavaMethod method, int counter) { + try { + long start = System.currentTimeMillis(); + long allocatedAtStart = getCurrentThreadAllocatedBytes(); + + CompilationTask task = new CompilationTask(method, Compiler.INVOCATION_ENTRY_BCI, 0L, method.allocateCompileId(Compiler.INVOCATION_ENTRY_BCI), false); + task.runCompilation(); + + memoryUsed.getAndAdd(getCurrentThreadAllocatedBytes() - allocatedAtStart); + compileTime.getAndAdd(System.currentTimeMillis() - start); + compiledMethodsCounter.incrementAndGet(); + } catch (Throwable t) { + // Catch everything and print a message + println("CompileTheWorld (%d) : Error compiling method: %s", counter, method.format("%H.%n(%p):%r")); + t.printStackTrace(TTY.cachedOut); + } + } + + /** + * Determines if a method should be compiled (Cf. CompilationPolicy::can_be_compiled). + * + * @return true if it can be compiled, false otherwise + */ + private static boolean canBeCompiled(HotSpotResolvedJavaMethod javaMethod, int modifiers) { + if (Modifier.isAbstract(modifiers) || Modifier.isNative(modifiers)) { + return false; + } + HotSpotVMConfig c = HotSpotJVMCIRuntime.runtime().getConfig(); + if (c.dontCompileHugeMethods && javaMethod.getCodeSize() > c.hugeMethodLimit) { + return false; + } + // Allow use of -XX:CompileCommand=dontinline to exclude problematic methods + if (!javaMethod.canBeInlined()) { + return false; + } + // Skip @Snippets for now + for (Annotation annotation : javaMethod.getAnnotations()) { + if (annotation.annotationType().getName().equals("com.oracle.graal.replacements.Snippet")) { + return false; + } + } + return true; + } + +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/CompilerToVM.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/CompilerToVM.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,342 @@ +/* + * Copyright (c) 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 sun.misc.*; + +import com.oracle.jvmci.code.*; +import com.oracle.jvmci.hotspotvmconfig.*; +import com.oracle.jvmci.meta.*; + +/** + * Calls from Java into HotSpot. + */ +public interface CompilerToVM { + + /** + * Copies the original bytecode of a given method into a new byte array and returns it. + * + * @param metaspaceMethod the metaspace Method object + * @return a new byte array containing the original bytecode + */ + byte[] getBytecode(long metaspaceMethod); + + int exceptionTableLength(long metaspaceMethod); + + long exceptionTableStart(long metaspaceMethod); + + /** + * Determines if a given metaspace Method object has balanced monitors. + * + * @param metaspaceMethod the metaspace Method object to query + * @return true if the method has balanced monitors + */ + boolean hasBalancedMonitors(long metaspaceMethod); + + /** + * Determines if a given metaspace Method can be inlined. A method may not be inlinable for a + * number of reasons such as: + *
        + *
      • a CompileOracle directive may prevent inlining or compilation of methods
      • + *
      • the method may have a bytecode breakpoint set
      • + *
      • the method may have other bytecode features that require special handling by the VM
      • + *
      + * + * @param metaspaceMethod the metaspace Method object to query + * @return true if the method can be inlined + */ + boolean canInlineMethod(long metaspaceMethod); + + /** + * Determines if a given metaspace Method should be inlined at any cost. This could be because: + *
        + *
      • a CompileOracle directive may forces inlining of this methods
      • + *
      • an annotation forces inlining of this method
      • + *
      + * + * @param metaspaceMethod the metaspace Method object to query + * @return true if the method should be inlined + */ + boolean shouldInlineMethod(long metaspaceMethod); + + /** + * Used to implement {@link ResolvedJavaType#findUniqueConcreteMethod(ResolvedJavaMethod)}. + * + * @param metaspaceMethod the metaspace Method on which to based the search + * @param actualHolderMetaspaceKlass the best known type of receiver + * @return the metaspace Method result or 0 is there is no unique concrete method for + * {@code metaspaceMethod} + */ + long findUniqueConcreteMethod(long actualHolderMetaspaceKlass, long metaspaceMethod); + + /** + * Returns the implementor for the given interface class, if there is a single implementor. + * + * @param metaspaceKlass the metaspace klass to get the implementor for + * @return the implementor as metaspace klass pointer if there is a single implementor, null if + * there is no implementor, or the input metaspace klass pointer ({@code metaspaceKlass} + * ) itself if there is more than one implementor. + */ + long getKlassImplementor(long metaspaceKlass); + + /** + * Determines if a given metaspace method is ignored by security stack walks. + * + * @param metaspaceMethod the metaspace Method object + * @return true if the method is ignored + */ + boolean methodIsIgnoredBySecurityStackWalk(long metaspaceMethod); + + /** + * Converts a name to a metaspace klass. + * + * @param name a well formed Java type in {@linkplain JavaType#getName() internal} format + * @param accessingClass the context of resolution (must not be null) + * @param resolve force resolution to a {@link ResolvedJavaType}. If true, this method will + * either return a {@link ResolvedJavaType} or throw an exception + * @return a metaspace klass for {@code name} + * @throws LinkageError if {@code resolve == true} and the resolution failed + */ + long lookupType(String name, Class accessingClass, boolean resolve); + + Object resolveConstantInPool(long metaspaceConstantPool, int cpi); + + Object resolvePossiblyCachedConstantInPool(long metaspaceConstantPool, int cpi); + + int lookupNameAndTypeRefIndexInPool(long metaspaceConstantPool, int cpi); + + String lookupNameRefInPool(long metaspaceConstantPool, int cpi); + + String lookupSignatureRefInPool(long metaspaceConstantPool, int cpi); + + int lookupKlassRefIndexInPool(long metaspaceConstantPool, int cpi); + + long constantPoolKlassAt(long metaspaceConstantPool, int cpi); + + /** + * Looks up a class entry in a constant pool. + * + * @param metaspaceConstantPool metaspace constant pool pointer + * @param cpi constant pool index + * @return a metaspace Klass for a resolved method entry, a metaspace Symbol otherwise (with + * tagging) + */ + long lookupKlassInPool(long metaspaceConstantPool, int cpi); + + /** + * Looks up a method entry in a constant pool. + * + * @param metaspaceConstantPool metaspace constant pool pointer + * @param cpi constant pool index + * @return a metaspace Method for a resolved method entry, 0 otherwise + */ + long lookupMethodInPool(long metaspaceConstantPool, int cpi, byte opcode); + + /** + * Looks up a field entry in a constant pool and attempts to resolve it. The values returned in + * {@code info} are: + * + *
      +     *     [(int) flags,   // only valid if field is resolved
      +     *      (int) offset]  // only valid if field is resolved
      +     * 
      + * + * @param metaspaceConstantPool metaspace constant pool pointer + * @param cpi constant pool index + * @param info an array in which the details of the field are returned + * @return true if the field is resolved + */ + long resolveField(long metaspaceConstantPool, int cpi, byte opcode, long[] info); + + int constantPoolRemapInstructionOperandFromCache(long metaspaceConstantPool, int cpi); + + Object lookupAppendixInPool(long metaspaceConstantPool, int cpi); + + /** + * Installs the result of a compilation into the code cache. + * + * @param compiledCode the result of a compilation + * @param code the details of the installed CodeBlob are written to this object + * @return the outcome of the installation which will be one of + * {@link HotSpotVMConfig#codeInstallResultOk}, + * {@link HotSpotVMConfig#codeInstallResultCacheFull}, + * {@link HotSpotVMConfig#codeInstallResultCodeTooLarge}, + * {@link HotSpotVMConfig#codeInstallResultDependenciesFailed} or + * {@link HotSpotVMConfig#codeInstallResultDependenciesInvalid}. + */ + int installCode(HotSpotCompiledCode compiledCode, InstalledCode code, SpeculationLog speculationLog); + + /** + * Notifies the VM of statistics for a completed compilation. + * + * @param id the identifier of the compilation + * @param method the method compiled + * @param osr specifies if the compilation was for on-stack-replacement + * @param processedBytecodes the number of bytecodes processed during the compilation, including + * the bytecodes of all inlined methods + * @param time the amount time spent compiling {@code method} + * @param timeUnitsPerSecond the granularity of the units for the {@code time} value + * @param installedCode the nmethod installed as a result of the compilation + */ + void notifyCompilationStatistics(int id, HotSpotResolvedJavaMethod method, boolean osr, int processedBytecodes, long time, long timeUnitsPerSecond, InstalledCode installedCode); + + void resetCompilationStatistics(); + + void initializeConfiguration(HotSpotVMConfig config); + + long resolveMethod(long metaspaceKlassExactReceiver, long metaspaceMethod, long metaspaceKlassCaller); + + long getClassInitializer(long metaspaceKlass); + + boolean hasFinalizableSubclass(long metaspaceKlass); + + /** + * Gets the metaspace Method object corresponding to a given {@link Class} object and slot + * number. + * + * @param holder method holder + * @param slot slot number of the method + * @return the metaspace Method + */ + long getMetaspaceMethod(Class holder, int slot); + + long getMaxCallTargetOffset(long address); + + String disassembleCodeBlob(long codeBlob); + + StackTraceElement getStackTraceElement(long metaspaceMethod, int bci); + + Object executeCompiledMethod(Object arg1, Object arg2, Object arg3, InstalledCode hotspotInstalledCode) throws InvalidInstalledCodeException; + + Object executeCompiledMethodVarargs(Object[] args, InstalledCode hotspotInstalledCode) throws InvalidInstalledCodeException; + + long[] getLineNumberTable(long metaspaceMethod); + + long getLocalVariableTableStart(long metaspaceMethod); + + int getLocalVariableTableLength(long metaspaceMethod); + + String getFileName(HotSpotResolvedJavaType method); + + Class getJavaMirror(long metaspaceKlass); + + long readUnsafeKlassPointer(Object o); + + /** + * Reads an object pointer within a VM data structure. That is, any {@link HotSpotVMField} whose + * {@link HotSpotVMField#type() type} is {@code "oop"} (e.g., + * {@code ArrayKlass::_component_mirror}, {@code Klass::_java_mirror}, + * {@code JavaThread::_threadObj}). + * + * Note that {@link Unsafe#getObject(Object, long)} cannot be used for this since it does a + * {@code narrowOop} read if the VM is using compressed oops whereas oops within VM data + * structures are (currently) always uncompressed. + * + * @param address address of an oop field within a VM data structure + */ + Object readUncompressedOop(long address); + + void doNotInlineOrCompile(long metaspaceMethod); + + /** + * Invalidates the profiling information and restarts profiling upon the next invocation. + * + * @param metaspaceMethod the metaspace Method object + */ + void reprofile(long metaspaceMethod); + + void invalidateInstalledCode(InstalledCode hotspotInstalledCode); + + /** + * Collects the current values of all JVMCI benchmark counters, summed up over all threads. + */ + long[] collectCounters(); + + boolean isMature(long metaspaceMethodData); + + /** + * Generate a unique id to identify the result of the compile. + */ + int allocateCompileId(long metaspaceMethod, int entryBCI); + + /** + * Gets the names of the supported GPU architectures. + * + * @return a comma separated list of names + */ + String getGPUs(); + + /** + * + * @param metaspaceMethod the method to check + * @param entryBCI + * @param level the compilation level + * @return true if the {@code metaspaceMethod} has code for {@code level} + */ + boolean hasCompiledCodeForOSR(long metaspaceMethod, int entryBCI, int level); + + /** + * Fetch the time stamp used for printing inside hotspot. It's relative to VM start to that all + * events can be ordered. + * + * @return milliseconds since VM start + */ + long getTimeStamp(); + + /** + * Gets the value of a metaspace {@code Symbol} as a String. + * + * @param metaspaceSymbol + */ + String getSymbol(long metaspaceSymbol); + + /** + * Looks for the next Java stack frame with the given method. + * + * @param frame the starting point of the search, where {@code null} refers to the topmost frame + * @param methods the metaspace methods to look for, where {@code null} means that any frame is + * returned + * @return the frame, or {@code null} if the end of the stack was reached during the search + */ + HotSpotStackFrameReference getNextStackFrame(HotSpotStackFrameReference frame, long[] methods, int initialSkip); + + /** + * Materialized all virtual objects within the given stack frame and update the locals within + * the given stackFrame object. + * + * @param invalidate if {@code true}, the compiled method for the stack frame will be + * invalidated. + */ + void materializeVirtualObjects(HotSpotStackFrameReference stackFrame, boolean invalidate); + + void resolveInvokeDynamic(long metaspaceConstantPool, int index); + + int getVtableIndexForInterface(long metaspaceKlass, long metaspaceMethod); + + boolean shouldDebugNonSafepoints(); + + void writeDebugOutput(byte[] bytes, int offset, int length); + + void flushDebugOutput(); +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/CompilerToVMImpl.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/CompilerToVMImpl.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,206 @@ +/* + * Copyright (c) 2011, 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; + +import static com.oracle.jvmci.hotspot.InitTimer.*; + +import com.oracle.jvmci.code.*; +import com.oracle.jvmci.meta.*; + +/** + * Entries into the HotSpot VM from Java code. + */ +public class CompilerToVMImpl implements CompilerToVM { + + /** + * Initializes the native part of the JVMCI runtime. + */ + private static native void init(); + + static { + try (InitTimer t = timer("CompilerToVMImpl.init")) { + init(); + } + } + + @Override + public native int installCode(HotSpotCompiledCode compiledCode, InstalledCode code, SpeculationLog speculationLog); + + @Override + public native long getMetaspaceMethod(Class holder, int slot); + + @Override + public native byte[] getBytecode(long metaspaceMethod); + + @Override + public native int exceptionTableLength(long metaspaceMethod); + + @Override + public native long exceptionTableStart(long metaspaceMethod); + + @Override + public native boolean hasBalancedMonitors(long metaspaceMethod); + + @Override + public native long findUniqueConcreteMethod(long actualHolderMetaspaceKlass, long metaspaceMethod); + + @Override + public native long getKlassImplementor(long metaspaceKlass); + + @Override + public native long lookupType(String name, Class accessingClass, boolean eagerResolve); + + public native Object resolveConstantInPool(long metaspaceConstantPool, int cpi); + + public native Object resolvePossiblyCachedConstantInPool(long metaspaceConstantPool, int cpi); + + @Override + public native int lookupNameAndTypeRefIndexInPool(long metaspaceConstantPool, int cpi); + + @Override + public native String lookupNameRefInPool(long metaspaceConstantPool, int cpi); + + @Override + public native String lookupSignatureRefInPool(long metaspaceConstantPool, int cpi); + + @Override + public native int lookupKlassRefIndexInPool(long metaspaceConstantPool, int cpi); + + public native long constantPoolKlassAt(long metaspaceConstantPool, int cpi); + + @Override + public native long lookupKlassInPool(long metaspaceConstantPool, int cpi); + + @Override + public native long lookupMethodInPool(long metaspaceConstantPool, int cpi, byte opcode); + + @Override + public native long resolveField(long metaspaceConstantPool, int cpi, byte opcode, long[] info); + + public native int constantPoolRemapInstructionOperandFromCache(long metaspaceConstantPool, int cpi); + + @Override + public native Object lookupAppendixInPool(long metaspaceConstantPool, int cpi); + + @Override + public native void initializeConfiguration(HotSpotVMConfig config); + + @Override + public native long resolveMethod(long metaspaceKlassExactReceiver, long metaspaceMethod, long metaspaceKlassCaller); + + @Override + public native boolean hasFinalizableSubclass(long metaspaceKlass); + + public native boolean methodIsIgnoredBySecurityStackWalk(long metaspaceMethod); + + @Override + public native long getClassInitializer(long metaspaceKlass); + + @Override + public native long getMaxCallTargetOffset(long address); + + // The HotSpot disassembler seems not to be thread safe so it's better to synchronize its usage + @Override + public synchronized native String disassembleCodeBlob(long codeBlob); + + @Override + public native StackTraceElement getStackTraceElement(long metaspaceMethod, int bci); + + @Override + public native Object executeCompiledMethodVarargs(Object[] args, InstalledCode hotspotInstalledCode); + + @Override + public native long[] getLineNumberTable(long metaspaceMethod); + + @Override + public native long getLocalVariableTableStart(long metaspaceMethod); + + @Override + public native int getLocalVariableTableLength(long metaspaceMethod); + + @Override + public native String getFileName(HotSpotResolvedJavaType method); + + @Override + public native void reprofile(long metaspaceMethod); + + @Override + public native void invalidateInstalledCode(InstalledCode hotspotInstalledCode); + + @Override + public native Class getJavaMirror(long metaspaceKlass); + + @Override + public native long readUnsafeKlassPointer(Object o); + + @Override + public native Object readUncompressedOop(long address); + + @Override + public native void doNotInlineOrCompile(long metaspaceMethod); + + @Override + public Object executeCompiledMethod(Object arg1, Object arg2, Object arg3, InstalledCode hotspotInstalledCode) throws InvalidInstalledCodeException { + return executeCompiledMethodVarargs(new Object[]{arg1, arg2, arg3}, hotspotInstalledCode); + } + + public synchronized native void notifyCompilationStatistics(int id, HotSpotResolvedJavaMethod method, boolean osr, int processedBytecodes, long time, long timeUnitsPerSecond, + InstalledCode installedCode); + + public native void resetCompilationStatistics(); + + public native long[] collectCounters(); + + public native boolean isMature(long method); + + public native int allocateCompileId(long metaspaceMethod, int entryBCI); + + public String getGPUs() { + return ""; + } + + public native boolean canInlineMethod(long metaspaceMethod); + + public native boolean shouldInlineMethod(long metaspaceMethod); + + public native boolean hasCompiledCodeForOSR(long metaspaceMethod, int entryBCI, int level); + + public native HotSpotStackFrameReference getNextStackFrame(HotSpotStackFrameReference frame, long[] methods, int initialSkip); + + public native void materializeVirtualObjects(HotSpotStackFrameReference stackFrame, boolean invalidate); + + public native long getTimeStamp(); + + public native String getSymbol(long metaspaceSymbol); + + public native void resolveInvokeDynamic(long metaspaceConstantPool, int index); + + public native int getVtableIndexForInterface(long metaspaceKlass, long metaspaceMethod); + + public native boolean shouldDebugNonSafepoints(); + + public native void writeDebugOutput(byte[] bytes, int offset, int length); + + public native void flushDebugOutput(); +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotCodeCacheProvider.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotCodeCacheProvider.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,242 @@ +/* + * 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.jvmci.hotspot; + +import static com.oracle.jvmci.hotspot.HotSpotCompressedNullConstant.*; + +import java.lang.reflect.*; + +import com.oracle.jvmci.code.*; +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.Mark; +import com.oracle.jvmci.code.DataSection.Data; +import com.oracle.jvmci.code.DataSection.DataBuilder; +import com.oracle.jvmci.common.*; +import com.oracle.jvmci.debug.*; +import com.oracle.jvmci.meta.*; + +/** + * HotSpot implementation of {@link CodeCacheProvider}. + */ +public class HotSpotCodeCacheProvider implements CodeCacheProvider { + + protected final HotSpotJVMCIRuntimeProvider runtime; + public final HotSpotVMConfig config; + protected final TargetDescription target; + protected final RegisterConfig regConfig; + + public HotSpotCodeCacheProvider(HotSpotJVMCIRuntimeProvider runtime, HotSpotVMConfig config, TargetDescription target, RegisterConfig regConfig) { + this.runtime = runtime; + this.config = config; + this.target = target; + this.regConfig = regConfig; + } + + @Override + 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_")) { + f.setAccessible(true); + try { + if (f.getInt(runtime.getConfig()) == markId) { + return f.getName(); + } + } catch (Exception e) { + } + } + } + return CodeCacheProvider.super.getMarkName(mark); + } + + /** + * Decodes a call target to a mnemonic if possible. + */ + @Override + public String getTargetName(Call call) { + Field[] fields = runtime.getConfig().getClass().getDeclaredFields(); + for (Field f : fields) { + if (f.getName().endsWith("Stub")) { + f.setAccessible(true); + try { + Object address = f.get(runtime.getConfig()); + if (address.equals(call.target)) { + return f.getName() + ":0x" + Long.toHexString((Long) address); + } + } catch (Exception e) { + } + } + } + return CodeCacheProvider.super.getTargetName(call); + } + + @Override + public RegisterConfig getRegisterConfig() { + return regConfig; + } + + @Override + public int getMinimumOutgoingSize() { + return runtime.getConfig().runtimeCallStackSize; + } + + public InstalledCode logOrDump(InstalledCode installedCode, CompilationResult compResult) { + if (Debug.isDumpEnabled()) { + Debug.dump(new Object[]{compResult, installedCode}, "After code installation"); + } + if (Debug.isLogEnabled()) { + Debug.log("%s", disassemble(installedCode)); + } + return installedCode; + } + + public InstalledCode installMethod(HotSpotResolvedJavaMethod method, CompilationResult compResult, long jvmciEnv, boolean isDefault) { + if (compResult.getId() == -1) { + compResult.setId(method.allocateCompileId(compResult.getEntryBCI())); + } + HotSpotInstalledCode installedCode = new HotSpotNmethod(method, compResult.getName(), isDefault); + runtime.getCompilerToVM().installCode(new HotSpotCompiledNmethod(method, compResult, jvmciEnv), installedCode, method.getSpeculationLog()); + return logOrDump(installedCode, compResult); + } + + @Override + public InstalledCode addMethod(ResolvedJavaMethod method, CompilationResult compResult, SpeculationLog log, InstalledCode predefinedInstalledCode) { + HotSpotResolvedJavaMethod hotspotMethod = (HotSpotResolvedJavaMethod) method; + if (compResult.getId() == -1) { + compResult.setId(hotspotMethod.allocateCompileId(compResult.getEntryBCI())); + } + InstalledCode installedCode = predefinedInstalledCode; + if (installedCode == null) { + HotSpotInstalledCode code = new HotSpotNmethod(hotspotMethod, compResult.getName(), false); + installedCode = code; + } + HotSpotCompiledNmethod compiledCode = new HotSpotCompiledNmethod(hotspotMethod, compResult); + int result = runtime.getCompilerToVM().installCode(compiledCode, installedCode, log); + if (result != config.codeInstallResultOk) { + String msg = compiledCode.getInstallationFailureMessage(); + String resultDesc = config.getCodeInstallResultDescription(result); + if (msg != null) { + msg = String.format("Code installation failed: %s%n%s", resultDesc, msg); + } else { + msg = String.format("Code installation failed: %s", resultDesc); + } + if (result == config.codeInstallResultDependenciesInvalid) { + throw new AssertionError(resultDesc + " " + msg); + } + throw new BailoutException(result != config.codeInstallResultDependenciesFailed, msg); + } + return logOrDump(installedCode, compResult); + } + + @Override + public InstalledCode setDefaultMethod(ResolvedJavaMethod method, CompilationResult compResult) { + HotSpotResolvedJavaMethod hotspotMethod = (HotSpotResolvedJavaMethod) method; + return installMethod(hotspotMethod, compResult, 0L, true); + } + + public HotSpotNmethod addExternalMethod(ResolvedJavaMethod method, CompilationResult compResult) { + HotSpotResolvedJavaMethod javaMethod = (HotSpotResolvedJavaMethod) method; + if (compResult.getId() == -1) { + compResult.setId(javaMethod.allocateCompileId(compResult.getEntryBCI())); + } + HotSpotNmethod code = new HotSpotNmethod(javaMethod, compResult.getName(), false, true); + HotSpotCompiledNmethod compiled = new HotSpotCompiledNmethod(javaMethod, compResult); + CompilerToVM vm = runtime.getCompilerToVM(); + int result = vm.installCode(compiled, code, null); + if (result != runtime.getConfig().codeInstallResultOk) { + return null; + } + return code; + } + + public boolean needsDataPatch(JavaConstant constant) { + return constant instanceof HotSpotMetaspaceConstant; + } + + public Data createDataItem(Constant constant) { + int size; + DataBuilder builder; + if (constant instanceof VMConstant) { + VMConstant vmConstant = (VMConstant) constant; + boolean compressed; + long raw; + if (constant instanceof HotSpotObjectConstant) { + HotSpotObjectConstant c = (HotSpotObjectConstant) vmConstant; + compressed = c.isCompressed(); + raw = 0xDEADDEADDEADDEADL; + } else if (constant instanceof HotSpotMetaspaceConstant) { + HotSpotMetaspaceConstant meta = (HotSpotMetaspaceConstant) constant; + compressed = meta.isCompressed(); + raw = meta.rawValue(); + } else { + throw new JVMCIError(String.valueOf(constant)); + } + + size = target.getSizeInBytes(compressed ? Kind.Int : target.wordKind); + if (size == 4) { + builder = (buffer, patch) -> { + patch.accept(new DataPatch(buffer.position(), new ConstantReference(vmConstant))); + buffer.putInt((int) raw); + }; + } else { + assert size == 8; + builder = (buffer, patch) -> { + patch.accept(new DataPatch(buffer.position(), new ConstantReference(vmConstant))); + buffer.putLong(raw); + }; + } + } else if (JavaConstant.isNull(constant)) { + boolean compressed = COMPRESSED_NULL.equals(constant); + size = target.getSizeInBytes(compressed ? Kind.Int : target.wordKind); + builder = DataBuilder.zero(size); + } else if (constant instanceof SerializableConstant) { + SerializableConstant s = (SerializableConstant) constant; + size = s.getSerializedSize(); + builder = DataBuilder.serializable(s); + } else { + throw new JVMCIError(String.valueOf(constant)); + } + + return new Data(size, size, builder); + } + + @Override + public TargetDescription getTarget() { + return target; + } + + public String disassemble(InstalledCode code) { + if (code.isValid()) { + long codeBlob = code.getAddress(); + return runtime.getCompilerToVM().disassembleCodeBlob(codeBlob); + } + return null; + } + + public SpeculationLog createSpeculationLog() { + return new HotSpotSpeculationLog(); + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotCompiledCode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotCompiledCode.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,174 @@ +/* + * Copyright (c) 2011, 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 java.nio.*; +import java.util.*; +import java.util.stream.*; +import java.util.stream.Stream.Builder; + +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.DataPatch; +import com.oracle.jvmci.code.CompilationResult.ExceptionHandler; +import com.oracle.jvmci.code.CompilationResult.Infopoint; +import com.oracle.jvmci.code.CompilationResult.JumpTable; +import com.oracle.jvmci.code.CompilationResult.Mark; +import com.oracle.jvmci.code.CompilationResult.Site; +import com.oracle.jvmci.meta.Assumptions.Assumption; +import com.oracle.jvmci.meta.*; + +/** + * A {@link CompilationResult} with additional HotSpot-specific information required for installing + * the code in HotSpot's code cache. + */ +public abstract class HotSpotCompiledCode { + + public final String name; + public final Site[] sites; + public final ExceptionHandler[] exceptionHandlers; + public final Comment[] comments; + public final Assumption[] assumptions; + + public final byte[] targetCode; + public final int targetCodeSize; + + public final byte[] dataSection; + public final int dataSectionAlignment; + public final DataPatch[] dataSectionPatches; + + public final int totalFrameSize; + public final int customStackAreaOffset; + + /** + * The list of the methods whose bytecodes were used as input to the compilation. If + * {@code null}, then the compilation did not record method dependencies. Otherwise, the first + * element of this array is the root method of the compilation. + */ + public final ResolvedJavaMethod[] methods; + + public static class Comment { + + public final String text; + public final int pcOffset; + + public Comment(int pcOffset, String text) { + this.text = text; + this.pcOffset = pcOffset; + } + } + + public HotSpotCompiledCode(CompilationResult compResult) { + name = compResult.getName(); + sites = getSortedSites(compResult); + if (compResult.getExceptionHandlers().isEmpty()) { + exceptionHandlers = null; + } else { + exceptionHandlers = compResult.getExceptionHandlers().toArray(new ExceptionHandler[compResult.getExceptionHandlers().size()]); + } + List annotations = compResult.getAnnotations(); + comments = new Comment[annotations.size()]; + if (!annotations.isEmpty()) { + for (int i = 0; i < comments.length; i++) { + CodeAnnotation annotation = annotations.get(i); + String text; + if (annotation instanceof CodeComment) { + CodeComment codeComment = (CodeComment) annotation; + text = codeComment.value; + } else if (annotation instanceof JumpTable) { + JumpTable jumpTable = (JumpTable) annotation; + text = "JumpTable [" + jumpTable.low + " .. " + jumpTable.high + "]"; + } else { + text = annotation.toString(); + } + comments[i] = new Comment(annotation.position, text); + } + } + assumptions = compResult.getAssumptions(); + assert validateFrames(); + + targetCode = compResult.getTargetCode(); + targetCodeSize = compResult.getTargetCodeSize(); + + DataSection data = compResult.getDataSection(); + data.finalizeLayout(); + dataSection = new byte[data.getSectionSize()]; + + ByteBuffer buffer = ByteBuffer.wrap(dataSection).order(ByteOrder.nativeOrder()); + Builder patchBuilder = Stream.builder(); + data.buildDataSection(buffer, patchBuilder); + + dataSectionAlignment = data.getSectionAlignment(); + dataSectionPatches = patchBuilder.build().toArray(len -> new DataPatch[len]); + + totalFrameSize = compResult.getTotalFrameSize(); + customStackAreaOffset = compResult.getCustomStackAreaOffset(); + + methods = compResult.getMethods(); + } + + /** + * Ensure that all the frames passed into HotSpot are properly formatted with an empty or + * illegal slot following double word slots. + */ + private boolean validateFrames() { + for (Site site : sites) { + if (site instanceof Infopoint) { + Infopoint info = (Infopoint) site; + if (info.debugInfo != null) { + BytecodeFrame frame = info.debugInfo.frame(); + assert frame == null || frame.validateFormat(false); + } + } + } + return true; + } + + static class SiteComparator implements Comparator { + + public int compare(Site s1, Site s2) { + if (s1.pcOffset == s2.pcOffset && (s1 instanceof Mark ^ s2 instanceof Mark)) { + return s1 instanceof Mark ? -1 : 1; + } + return s1.pcOffset - s2.pcOffset; + } + } + + private static Site[] getSortedSites(CompilationResult target) { + List[] lists = new List[]{target.getInfopoints(), target.getDataPatches(), target.getMarks()}; + int count = 0; + for (List list : lists) { + count += list.size(); + } + Site[] result = new Site[count]; + int pos = 0; + for (List list : lists) { + for (Object elem : list) { + result[pos++] = (Site) elem; + } + } + Arrays.sort(result, new SiteComparator()); + return result; + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotCompiledNmethod.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotCompiledNmethod.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2011, 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.*; + +import edu.umd.cs.findbugs.annotations.*; + +/** + * {@link HotSpotCompiledCode} destined for installation as an nmethod. + */ +public final class HotSpotCompiledNmethod extends HotSpotCompiledCode { + + public final HotSpotResolvedJavaMethod method; + public final int entryBCI; + public final int id; + public final long jvmciEnv; + + /** + * May be set by VM if code installation fails. It will describe in more detail why installation + * failed (e.g., exactly which dependency failed). + */ + @SuppressFBWarnings("UWF_UNWRITTEN_FIELD") private String installationFailureMessage; + + public HotSpotCompiledNmethod(HotSpotResolvedJavaMethod method, CompilationResult compResult) { + this(method, compResult, 0L); + } + + public HotSpotCompiledNmethod(HotSpotResolvedJavaMethod method, CompilationResult compResult, long jvmciEnv) { + super(compResult); + this.method = method; + this.entryBCI = compResult.getEntryBCI(); + this.id = compResult.getId(); + this.jvmciEnv = jvmciEnv; + } + + @Override + public String toString() { + return getClass().getSimpleName() + "[" + id + ":" + method.format("%H.%n(%p)%r@") + entryBCI + "]"; + } + + public String getInstallationFailureMessage() { + return installationFailureMessage; + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotCompressedNullConstant.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotCompressedNullConstant.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,102 @@ +/* + * 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 + * 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.meta.*; + +/** + * The compressed representation of the {@link JavaConstant#NULL_POINTER null constant}. + */ +public final class HotSpotCompressedNullConstant extends AbstractValue implements JavaConstant, HotSpotConstant { + + public static final JavaConstant COMPRESSED_NULL = new HotSpotCompressedNullConstant(); + + private HotSpotCompressedNullConstant() { + super(LIRKind.reference(Kind.Int)); + } + + @Override + public boolean isNull() { + return true; + } + + @Override + public boolean isCompressed() { + return true; + } + + @Override + public boolean isDefaultForKind() { + return true; + } + + @Override + public Object asBoxedPrimitive() { + throw new IllegalArgumentException(); + } + + @Override + public int asInt() { + throw new IllegalArgumentException(); + } + + @Override + public boolean asBoolean() { + throw new IllegalArgumentException(); + } + + @Override + public long asLong() { + throw new IllegalArgumentException(); + } + + @Override + public float asFloat() { + throw new IllegalArgumentException(); + } + + @Override + public double asDouble() { + throw new IllegalArgumentException(); + } + + @Override + public String toString() { + return JavaConstant.toString(this); + } + + @Override + public String toValueString() { + return "null"; + } + + @Override + public int hashCode() { + return System.identityHashCode(this); + } + + @Override + public boolean equals(Object o) { + return o instanceof HotSpotCompressedNullConstant; + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotConstant.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotConstant.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,33 @@ +/* + * 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 + * 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.meta.*; + +/** + * Marker interface for hotspot specific constants. + */ +public interface HotSpotConstant extends Constant { + + boolean isCompressed(); +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotConstantPool.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotConstantPool.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,653 @@ +/* + * Copyright (c) 2011, 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; + +import static com.oracle.jvmci.common.UnsafeAccess.*; +import static com.oracle.jvmci.hotspot.HotSpotJVMCIRuntime.*; + +import java.lang.invoke.*; + +import com.oracle.jvmci.common.*; +import com.oracle.jvmci.meta.*; + +/** + * Implementation of {@link ConstantPool} for HotSpot. + */ +public class HotSpotConstantPool implements ConstantPool, HotSpotProxified { + + /** + * Subset of JVM bytecode opcodes used by {@link HotSpotConstantPool}. + */ + public static class Bytecodes { + public static final int LDC = 18; // 0x12 + public static final int LDC_W = 19; // 0x13 + public static final int LDC2_W = 20; // 0x14 + public static final int GETSTATIC = 178; // 0xB2 + public static final int PUTSTATIC = 179; // 0xB3 + public static final int GETFIELD = 180; // 0xB4 + public static final int PUTFIELD = 181; // 0xB5 + public static final int INVOKEVIRTUAL = 182; // 0xB6 + public static final int INVOKESPECIAL = 183; // 0xB7 + public static final int INVOKESTATIC = 184; // 0xB8 + public static final int INVOKEINTERFACE = 185; // 0xB9 + public static final int INVOKEDYNAMIC = 186; // 0xBA + public static final int NEW = 187; // 0xBB + public static final int NEWARRAY = 188; // 0xBC + public static final int ANEWARRAY = 189; // 0xBD + public static final int CHECKCAST = 192; // 0xC0 + public static final int INSTANCEOF = 193; // 0xC1 + public static final int MULTIANEWARRAY = 197; // 0xC5 + + static boolean isInvoke(int opcode) { + switch (opcode) { + case INVOKEVIRTUAL: + case INVOKESPECIAL: + case INVOKESTATIC: + case INVOKEINTERFACE: + case INVOKEDYNAMIC: + return true; + default: + return false; + } + } + } + + /** + * Enum of all {@code JVM_CONSTANT} constants used in the VM. This includes the public and + * internal ones. + */ + private enum JVM_CONSTANT { + // @formatter:off + Utf8(config().jvmConstantUtf8), + Integer(config().jvmConstantInteger), + Long(config().jvmConstantLong), + Float(config().jvmConstantFloat), + Double(config().jvmConstantDouble), + Class(config().jvmConstantClass), + UnresolvedClass(config().jvmConstantUnresolvedClass), + UnresolvedClassInError(config().jvmConstantUnresolvedClassInError), + String(config().jvmConstantString), + Fieldref(config().jvmConstantFieldref), + MethodRef(config().jvmConstantMethodref), + InterfaceMethodref(config().jvmConstantInterfaceMethodref), + NameAndType(config().jvmConstantNameAndType), + MethodHandle(config().jvmConstantMethodHandle), + MethodHandleInError(config().jvmConstantMethodHandleInError), + MethodType(config().jvmConstantMethodType), + MethodTypeInError(config().jvmConstantMethodTypeInError), + InvokeDynamic(config().jvmConstantInvokeDynamic); + // @formatter:on + + private final int tag; + + private static final int ExternalMax = config().jvmConstantExternalMax; + private static final int InternalMin = config().jvmConstantInternalMin; + private static final int InternalMax = config().jvmConstantInternalMax; + + private JVM_CONSTANT(int tag) { + this.tag = tag; + } + + private static HotSpotVMConfig config() { + return runtime().getConfig(); + } + + /** + * Maps JVM_CONSTANT tags to {@link JVM_CONSTANT} values. Using a separate class for lazy + * initialization. + */ + static class TagValueMap { + private static final JVM_CONSTANT[] table = new JVM_CONSTANT[ExternalMax + 1 + (InternalMax - InternalMin) + 1]; + static { + assert InternalMin > ExternalMax; + for (JVM_CONSTANT e : values()) { + table[indexOf(e.tag)] = e; + } + } + + private static int indexOf(int tag) { + if (tag >= InternalMin) { + return tag - InternalMin + ExternalMax + 1; + } else { + assert tag <= ExternalMax; + } + return tag; + } + + static JVM_CONSTANT get(int tag) { + JVM_CONSTANT res = table[indexOf(tag)]; + if (res != null) { + return res; + } + throw new JVMCIError("Unknown JVM_CONSTANT tag %s", tag); + } + } + + public static JVM_CONSTANT getEnum(int tag) { + return TagValueMap.get(tag); + } + } + + private static class LookupTypeCacheElement { + int lastCpi = Integer.MIN_VALUE; + JavaType javaType; + + public LookupTypeCacheElement(int lastCpi, JavaType javaType) { + super(); + this.lastCpi = lastCpi; + this.javaType = javaType; + } + } + + /** + * Reference to the C++ ConstantPool object. + */ + private final long metaspaceConstantPool; + private final Object[] cache; + private volatile LookupTypeCacheElement lastLookupType; + + public HotSpotConstantPool(long metaspaceConstantPool) { + this.metaspaceConstantPool = metaspaceConstantPool; + cache = new Object[length()]; + } + + /** + * Gets the holder for this constant pool as {@link HotSpotResolvedObjectTypeImpl}. + * + * @return holder for this constant pool + */ + private HotSpotResolvedObjectType getHolder() { + final long metaspaceKlass = unsafe.getAddress(metaspaceConstantPool + runtime().getConfig().constantPoolHolderOffset); + return HotSpotResolvedObjectTypeImpl.fromMetaspaceKlass(metaspaceKlass); + } + + /** + * Converts a raw index from the bytecodes to a constant pool index by adding a + * {@link HotSpotVMConfig#constantPoolCpCacheIndexTag constant}. + * + * @param rawIndex index from the bytecode + * @param opcode bytecode to convert the index for + * @return constant pool index + */ + private static int toConstantPoolIndex(int rawIndex, int opcode) { + int index; + if (opcode == Bytecodes.INVOKEDYNAMIC) { + index = rawIndex; + // See: ConstantPool::is_invokedynamic_index + assert index < 0 : "not an invokedynamic constant pool index " + index; + } else { + assert opcode == Bytecodes.GETFIELD || opcode == Bytecodes.PUTFIELD || opcode == Bytecodes.GETSTATIC || opcode == Bytecodes.PUTSTATIC || opcode == Bytecodes.INVOKEINTERFACE || + opcode == Bytecodes.INVOKEVIRTUAL || opcode == Bytecodes.INVOKESPECIAL || opcode == Bytecodes.INVOKESTATIC : "unexpected invoke opcode " + opcode; + index = rawIndex + runtime().getConfig().constantPoolCpCacheIndexTag; + } + return index; + } + + /** + * Decode a constant pool cache index to a constant pool index. + * + * See {@code ConstantPool::decode_cpcache_index}. + * + * @param index constant pool cache index + * @return decoded index + */ + private static int decodeConstantPoolCacheIndex(int index) { + if (isInvokedynamicIndex(index)) { + return decodeInvokedynamicIndex(index); + } else { + return index - runtime().getConfig().constantPoolCpCacheIndexTag; + } + } + + /** + * See {@code ConstantPool::is_invokedynamic_index}. + */ + private static boolean isInvokedynamicIndex(int index) { + return index < 0; + } + + /** + * See {@code ConstantPool::decode_invokedynamic_index}. + */ + private static int decodeInvokedynamicIndex(int i) { + assert isInvokedynamicIndex(i) : i; + return ~i; + } + + /** + * Gets the constant pool tag at index {@code index}. + * + * @param index constant pool index + * @return constant pool tag + */ + private JVM_CONSTANT getTagAt(int index) { + assertBounds(index); + HotSpotVMConfig config = runtime().getConfig(); + final long metaspaceConstantPoolTags = unsafe.getAddress(metaspaceConstantPool + config.constantPoolTagsOffset); + final int tag = unsafe.getByteVolatile(null, metaspaceConstantPoolTags + config.arrayU1DataOffset + index); + if (tag == 0) { + return null; + } + return JVM_CONSTANT.getEnum(tag); + } + + /** + * Gets the constant pool entry at index {@code index}. + * + * @param index constant pool index + * @return constant pool entry + */ + private long getEntryAt(int index) { + assertBounds(index); + return unsafe.getAddress(metaspaceConstantPool + runtime().getConfig().constantPoolSize + index * runtime().getHostJVMCIBackend().getTarget().wordSize); + } + + /** + * Gets the integer constant pool entry at index {@code index}. + * + * @param index constant pool index + * @return integer constant pool entry at index + */ + private int getIntAt(int index) { + assertTag(index, JVM_CONSTANT.Integer); + return unsafe.getInt(metaspaceConstantPool + runtime().getConfig().constantPoolSize + index * runtime().getHostJVMCIBackend().getTarget().wordSize); + } + + /** + * Gets the long constant pool entry at index {@code index}. + * + * @param index constant pool index + * @return long constant pool entry + */ + private long getLongAt(int index) { + assertTag(index, JVM_CONSTANT.Long); + return unsafe.getLong(metaspaceConstantPool + runtime().getConfig().constantPoolSize + index * runtime().getHostJVMCIBackend().getTarget().wordSize); + } + + /** + * Gets the float constant pool entry at index {@code index}. + * + * @param index constant pool index + * @return float constant pool entry + */ + private float getFloatAt(int index) { + assertTag(index, JVM_CONSTANT.Float); + return unsafe.getFloat(metaspaceConstantPool + runtime().getConfig().constantPoolSize + index * runtime().getHostJVMCIBackend().getTarget().wordSize); + } + + /** + * Gets the double constant pool entry at index {@code index}. + * + * @param index constant pool index + * @return float constant pool entry + */ + private double getDoubleAt(int index) { + assertTag(index, JVM_CONSTANT.Double); + return unsafe.getDouble(metaspaceConstantPool + runtime().getConfig().constantPoolSize + index * runtime().getHostJVMCIBackend().getTarget().wordSize); + } + + /** + * Gets the {@code JVM_CONSTANT_NameAndType} constant pool entry at index {@code index}. + * + * @param index constant pool index + * @return {@code JVM_CONSTANT_NameAndType} constant pool entry + */ + private int getNameAndTypeAt(int index) { + assertTag(index, JVM_CONSTANT.NameAndType); + return unsafe.getInt(metaspaceConstantPool + runtime().getConfig().constantPoolSize + index * runtime().getHostJVMCIBackend().getTarget().wordSize); + } + + /** + * Gets the {@code JVM_CONSTANT_NameAndType} reference index constant pool entry at index + * {@code index}. + * + * @param index constant pool index + * @return {@code JVM_CONSTANT_NameAndType} reference constant pool entry + */ + private int getNameAndTypeRefIndexAt(int index) { + return runtime().getCompilerToVM().lookupNameAndTypeRefIndexInPool(metaspaceConstantPool, index); + } + + /** + * Gets the name of a {@code JVM_CONSTANT_NameAndType} constant pool entry at index + * {@code index}. + * + * @param index constant pool index + * @return name as {@link String} + */ + private String getNameRefAt(int index) { + return runtime().getCompilerToVM().lookupNameRefInPool(metaspaceConstantPool, index); + } + + /** + * Gets the name reference index of a {@code JVM_CONSTANT_NameAndType} constant pool entry at + * index {@code index}. + * + * @param index constant pool index + * @return name reference index + */ + private int getNameRefIndexAt(int index) { + final int refIndex = getNameAndTypeAt(index); + // name ref index is in the low 16-bits. + return refIndex & 0xFFFF; + } + + /** + * Gets the signature of a {@code JVM_CONSTANT_NameAndType} constant pool entry at index + * {@code index}. + * + * @param index constant pool index + * @return signature as {@link String} + */ + private String getSignatureRefAt(int index) { + return runtime().getCompilerToVM().lookupSignatureRefInPool(metaspaceConstantPool, index); + } + + /** + * Gets the signature reference index of a {@code JVM_CONSTANT_NameAndType} constant pool entry + * at index {@code index}. + * + * @param index constant pool index + * @return signature reference index + */ + private int getSignatureRefIndexAt(int index) { + final int refIndex = getNameAndTypeAt(index); + // signature ref index is in the high 16-bits. + return refIndex >>> 16; + } + + /** + * Gets the klass reference index constant pool entry at index {@code index}. + * + * @param index constant pool index + * @return klass reference index + */ + private int getKlassRefIndexAt(int index) { + return runtime().getCompilerToVM().lookupKlassRefIndexInPool(metaspaceConstantPool, index); + } + + /** + * Gets the uncached klass reference index constant pool entry at index {@code index}. See: + * {@code ConstantPool::uncached_klass_ref_index_at}. + * + * @param index constant pool index + * @return klass reference index + */ + private int getUncachedKlassRefIndexAt(int index) { + assert getTagAt(index) == JVM_CONSTANT.Fieldref || getTagAt(index) == JVM_CONSTANT.MethodRef || getTagAt(index) == JVM_CONSTANT.InterfaceMethodref; + final int refIndex = unsafe.getInt(metaspaceConstantPool + runtime().getConfig().constantPoolSize + index * runtime().getHostJVMCIBackend().getTarget().wordSize); + // klass ref index is in the low 16-bits. + return refIndex & 0xFFFF; + } + + /** + * Asserts that the constant pool index {@code index} is in the bounds of the constant pool. + * + * @param index constant pool index + */ + private void assertBounds(int index) { + assert 0 <= index && index < length() : "index " + index + " not between 0 and " + length(); + } + + /** + * Asserts that the constant pool tag at index {@code index} is equal to {@code tag}. + * + * @param index constant pool index + * @param tag expected tag + */ + private void assertTag(int index, JVM_CONSTANT tag) { + assert getTagAt(index) == tag : "constant pool tag at index " + index + " is " + getTagAt(index) + " but expected " + tag; + } + + @Override + public int length() { + return unsafe.getInt(metaspaceConstantPool + runtime().getConfig().constantPoolLengthOffset); + } + + @Override + public Object lookupConstant(int cpi) { + assert cpi != 0; + final JVM_CONSTANT tag = getTagAt(cpi); + switch (tag) { + case Integer: + return JavaConstant.forInt(getIntAt(cpi)); + case Long: + return JavaConstant.forLong(getLongAt(cpi)); + case Float: + return JavaConstant.forFloat(getFloatAt(cpi)); + case Double: + return JavaConstant.forDouble(getDoubleAt(cpi)); + case Class: + case UnresolvedClass: + case UnresolvedClassInError: + final int opcode = -1; // opcode is not used + return lookupType(cpi, opcode); + case String: + Object string = runtime().getCompilerToVM().resolvePossiblyCachedConstantInPool(metaspaceConstantPool, cpi); + return HotSpotObjectConstantImpl.forObject(string); + case MethodHandle: + case MethodHandleInError: + case MethodType: + case MethodTypeInError: + Object obj = runtime().getCompilerToVM().resolveConstantInPool(metaspaceConstantPool, cpi); + return HotSpotObjectConstantImpl.forObject(obj); + default: + throw new JVMCIError("Unknown constant pool tag %s", tag); + } + } + + @Override + public String lookupUtf8(int cpi) { + assertTag(cpi, JVM_CONSTANT.Utf8); + return runtime().getCompilerToVM().getSymbol(getEntryAt(cpi)); + } + + @Override + public Signature lookupSignature(int cpi) { + return new HotSpotSignature(runtime(), lookupUtf8(cpi)); + } + + @Override + public JavaConstant lookupAppendix(int cpi, int opcode) { + assert Bytecodes.isInvoke(opcode); + final int index = toConstantPoolIndex(cpi, opcode); + Object result = runtime().getCompilerToVM().lookupAppendixInPool(metaspaceConstantPool, index); + if (result == null) { + return null; + } else { + return HotSpotObjectConstantImpl.forObject(result); + } + } + + /** + * Gets a {@link JavaType} corresponding a given metaspace Klass or a metaspace Symbol depending + * on the {@link HotSpotVMConfig#compilerToVMKlassTag tag}. + * + * @param metaspacePointer either a metaspace Klass or a metaspace Symbol + */ + private static JavaType getJavaType(final long metaspacePointer) { + HotSpotJVMCIRuntime runtime = runtime(); + HotSpotVMConfig config = runtime.getConfig(); + if ((metaspacePointer & config.compilerToVMSymbolTag) != 0) { + final long metaspaceSymbol = metaspacePointer & ~config.compilerToVMSymbolTag; + String name = runtime.getCompilerToVM().getSymbol(metaspaceSymbol); + return HotSpotUnresolvedJavaType.create(runtime(), "L" + name + ";"); + } else { + assert (metaspacePointer & config.compilerToVMKlassTag) == 0; + return HotSpotResolvedObjectTypeImpl.fromMetaspaceKlass(metaspacePointer); + } + } + + @Override + public JavaMethod lookupMethod(int cpi, int opcode) { + if (opcode != Bytecodes.INVOKEDYNAMIC) { + Object result = cache[cpi]; + if (result != null) { + return (ResolvedJavaMethod) result; + } + } + final int index = toConstantPoolIndex(cpi, opcode); + final long metaspaceMethod = runtime().getCompilerToVM().lookupMethodInPool(metaspaceConstantPool, index, (byte) opcode); + if (metaspaceMethod != 0L) { + HotSpotResolvedJavaMethod result = HotSpotResolvedJavaMethodImpl.fromMetaspace(metaspaceMethod); + if (opcode != Bytecodes.INVOKEDYNAMIC) { + cache[cpi] = result; + } + return result; + } else { + // Get the method's name and signature. + String name = getNameRefAt(index); + HotSpotSignature signature = new HotSpotSignature(runtime(), getSignatureRefAt(index)); + if (opcode == Bytecodes.INVOKEDYNAMIC) { + HotSpotResolvedObjectType holder = HotSpotResolvedObjectTypeImpl.fromObjectClass(MethodHandle.class); + return new HotSpotMethodUnresolved(name, signature, holder); + } else { + final int klassIndex = getKlassRefIndexAt(index); + final long metaspacePointer = runtime().getCompilerToVM().lookupKlassInPool(metaspaceConstantPool, klassIndex); + JavaType holder = getJavaType(metaspacePointer); + return new HotSpotMethodUnresolved(name, signature, holder); + } + } + } + + @Override + public JavaType lookupType(int cpi, int opcode) { + final LookupTypeCacheElement elem = this.lastLookupType; + if (elem != null && elem.lastCpi == cpi) { + return elem.javaType; + } else { + final long metaspacePointer = runtime().getCompilerToVM().lookupKlassInPool(metaspaceConstantPool, cpi); + JavaType result = getJavaType(metaspacePointer); + if (result instanceof ResolvedJavaType) { + this.lastLookupType = new LookupTypeCacheElement(cpi, result); + } + return result; + } + } + + @Override + public JavaField lookupField(int cpi, int opcode) { + Object resolvedJavaField = cache[cpi]; + if (resolvedJavaField != null) { + return (ResolvedJavaField) resolvedJavaField; + } + final int index = toConstantPoolIndex(cpi, opcode); + final int nameAndTypeIndex = getNameAndTypeRefIndexAt(index); + final int nameIndex = getNameRefIndexAt(nameAndTypeIndex); + String name = lookupUtf8(nameIndex); + final int typeIndex = getSignatureRefIndexAt(nameAndTypeIndex); + String typeName = lookupUtf8(typeIndex); + JavaType type = runtime().lookupType(typeName, getHolder(), false); + + final int holderIndex = getKlassRefIndexAt(index); + JavaType holder = lookupType(holderIndex, opcode); + + if (holder instanceof HotSpotResolvedObjectTypeImpl) { + long[] info = new long[2]; + long metaspaceKlass; + try { + metaspaceKlass = runtime().getCompilerToVM().resolveField(metaspaceConstantPool, index, (byte) opcode, info); + } catch (Throwable t) { + /* + * If there was an exception resolving the field we give up and return an unresolved + * field. + */ + return new HotSpotUnresolvedField(holder, name, type); + } + HotSpotResolvedObjectTypeImpl resolvedHolder = HotSpotResolvedObjectTypeImpl.fromMetaspaceKlass(metaspaceKlass); + final int flags = (int) info[0]; + final long offset = info[1]; + HotSpotResolvedJavaField result = resolvedHolder.createField(name, type, offset, flags); + if (type instanceof ResolvedJavaType) { + cache[cpi] = result; + } + return result; + } else { + return new HotSpotUnresolvedField(holder, name, type); + } + } + + @Override + public void loadReferencedType(int cpi, int opcode) { + int index; + switch (opcode) { + case Bytecodes.CHECKCAST: + case Bytecodes.INSTANCEOF: + case Bytecodes.NEW: + case Bytecodes.ANEWARRAY: + case Bytecodes.MULTIANEWARRAY: + case Bytecodes.LDC: + case Bytecodes.LDC_W: + case Bytecodes.LDC2_W: + index = cpi; + break; + case Bytecodes.INVOKEDYNAMIC: + // invokedynamic instructions point to a constant pool cache entry. + index = decodeConstantPoolCacheIndex(cpi) + runtime().getConfig().constantPoolCpCacheIndexTag; + index = runtime().getCompilerToVM().constantPoolRemapInstructionOperandFromCache(metaspaceConstantPool, index); + break; + default: + index = toConstantPoolIndex(cpi, opcode); + index = runtime().getCompilerToVM().constantPoolRemapInstructionOperandFromCache(metaspaceConstantPool, index); + } + + JVM_CONSTANT tag = getTagAt(index); + if (tag == null) { + assert getTagAt(index - 1) == JVM_CONSTANT.Double || getTagAt(index - 1) == JVM_CONSTANT.Long; + return; + } + switch (tag) { + case Fieldref: + case MethodRef: + case InterfaceMethodref: + index = getUncachedKlassRefIndexAt(index); + tag = getTagAt(index); + assert tag == JVM_CONSTANT.Class || tag == JVM_CONSTANT.UnresolvedClass || tag == JVM_CONSTANT.UnresolvedClassInError : tag; + // fall through + case Class: + case UnresolvedClass: + case UnresolvedClassInError: + final long metaspaceKlass = runtime().getCompilerToVM().constantPoolKlassAt(metaspaceConstantPool, index); + HotSpotResolvedObjectTypeImpl type = HotSpotResolvedObjectTypeImpl.fromMetaspaceKlass(metaspaceKlass); + Class klass = type.mirror(); + if (!klass.isPrimitive() && !klass.isArray()) { + unsafe.ensureClassInitialized(klass); + } + break; + case InvokeDynamic: + if (isInvokedynamicIndex(cpi)) { + runtime().getCompilerToVM().resolveInvokeDynamic(metaspaceConstantPool, cpi); + } + break; + default: + // nothing + break; + } + } + + @Override + public String toString() { + HotSpotResolvedObjectType holder = getHolder(); + return "HotSpotConstantPool<" + holder.toJavaName() + ">"; + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotConstantReflectionProvider.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotConstantReflectionProvider.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,364 @@ +/* + * Copyright (c) 2011, 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; + +import static com.oracle.jvmci.hotspot.HotSpotConstantReflectionProvider.Options.*; + +import java.lang.reflect.*; + +import com.oracle.jvmci.meta.*; +import com.oracle.jvmci.options.*; + +/** + * HotSpot implementation of {@link ConstantReflectionProvider}. + */ +public class HotSpotConstantReflectionProvider implements ConstantReflectionProvider, HotSpotProxified { + + static class Options { + //@formatter:off + @Option(help = "Constant fold final fields with default values.", type = OptionType.Debug) + public static final OptionValue TrustFinalDefaultFields = new OptionValue<>(true); + //@formatter:on + } + + protected final HotSpotJVMCIRuntimeProvider runtime; + protected final HotSpotMethodHandleAccessProvider methodHandleAccess; + protected final HotSpotMemoryAccessProviderImpl memoryAccess; + + public HotSpotConstantReflectionProvider(HotSpotJVMCIRuntimeProvider runtime) { + this.runtime = runtime; + this.methodHandleAccess = new HotSpotMethodHandleAccessProvider(this); + this.memoryAccess = new HotSpotMemoryAccessProviderImpl(runtime); + } + + public MethodHandleAccessProvider getMethodHandleAccess() { + return methodHandleAccess; + } + + @Override + public MemoryAccessProvider getMemoryAccessProvider() { + return memoryAccess; + } + + @Override + public Boolean constantEquals(Constant x, Constant y) { + if (x == y) { + return true; + } else if (x instanceof HotSpotObjectConstantImpl) { + return y instanceof HotSpotObjectConstantImpl && ((HotSpotObjectConstantImpl) x).object() == ((HotSpotObjectConstantImpl) y).object(); + } else { + return x.equals(y); + } + } + + @Override + public Integer readArrayLength(JavaConstant array) { + if (array.getKind() != Kind.Object || array.isNull()) { + return null; + } + + Object arrayObject = ((HotSpotObjectConstantImpl) array).object(); + if (!arrayObject.getClass().isArray()) { + return null; + } + return Array.getLength(arrayObject); + } + + public JavaConstant readConstantArrayElement(JavaConstant array, int index) { + if (array instanceof HotSpotObjectConstantImpl && ((HotSpotObjectConstantImpl) array).getStableDimension() > 0) { + JavaConstant element = readArrayElement(array, index); + if (element != null && (((HotSpotObjectConstantImpl) array).isDefaultStable() || !element.isDefaultForKind())) { + return element; + } + } + return null; + } + + /** + * Try to convert {@code offset} into an an index into {@code array}. + * + * @return the computed index or -1 if the offset isn't within the array + */ + private int indexForOffset(JavaConstant array, long offset) { + if (array.getKind() != Kind.Object || array.isNull()) { + return -1; + } + Class componentType = ((HotSpotObjectConstantImpl) array).object().getClass().getComponentType(); + Kind kind = runtime.getHostJVMCIBackend().getMetaAccess().lookupJavaType(componentType).getKind(); + int arraybase = runtime.getArrayBaseOffset(kind); + int scale = runtime.getArrayIndexScale(kind); + if (offset < arraybase) { + return -1; + } + long index = offset - arraybase; + if (index % scale != 0) { + return -1; + } + long result = index / scale; + if (result >= Integer.MAX_VALUE) { + return -1; + } + return (int) result; + } + + public JavaConstant readConstantArrayElementForOffset(JavaConstant array, long offset) { + if (array instanceof HotSpotObjectConstantImpl && ((HotSpotObjectConstantImpl) array).getStableDimension() > 0) { + return readConstantArrayElement(array, indexForOffset(array, offset)); + } + return null; + } + + @Override + public JavaConstant readArrayElement(JavaConstant array, int index) { + if (array.getKind() != Kind.Object || array.isNull()) { + return null; + } + Object a = ((HotSpotObjectConstantImpl) array).object(); + + if (index < 0 || index >= Array.getLength(a)) { + return null; + } + + if (a instanceof Object[]) { + Object element = ((Object[]) a)[index]; + if (((HotSpotObjectConstantImpl) array).getStableDimension() > 1) { + return HotSpotObjectConstantImpl.forStableArray(element, ((HotSpotObjectConstantImpl) array).getStableDimension() - 1, ((HotSpotObjectConstantImpl) array).isDefaultStable()); + } else { + return HotSpotObjectConstantImpl.forObject(element); + } + } else { + return JavaConstant.forBoxedPrimitive(Array.get(a, index)); + } + } + + /** + * Check if the constant is a boxed value that is guaranteed to be cached by the platform. + * Otherwise the generated code might be the only reference to the boxed value and since object + * references from nmethods are weak this can cause GC problems. + * + * @param source + * @return true if the box is cached + */ + private static boolean isBoxCached(JavaConstant source) { + switch (source.getKind()) { + case Boolean: + return true; + case Char: + return source.asInt() <= 127; + case Byte: + case Short: + case Int: + return source.asInt() >= -128 && source.asInt() <= 127; + case Long: + return source.asLong() >= -128 && source.asLong() <= 127; + case Float: + case Double: + return false; + default: + throw new IllegalArgumentException("unexpected kind " + source.getKind()); + } + } + + @Override + public JavaConstant boxPrimitive(JavaConstant source) { + if (!source.getKind().isPrimitive() || !isBoxCached(source)) { + return null; + } + return HotSpotObjectConstantImpl.forObject(source.asBoxedPrimitive()); + } + + @Override + public JavaConstant unboxPrimitive(JavaConstant source) { + if (!source.getKind().isObject()) { + return null; + } + if (source.isNull()) { + return null; + } + return JavaConstant.forBoxedPrimitive(((HotSpotObjectConstantImpl) source).object()); + } + + public JavaConstant forString(String value) { + return HotSpotObjectConstantImpl.forObject(value); + } + + @Override + public ResolvedJavaType asJavaType(Constant constant) { + if (constant instanceof HotSpotObjectConstant) { + Object obj = ((HotSpotObjectConstantImpl) constant).object(); + if (obj instanceof Class) { + return runtime.getHostJVMCIBackend().getMetaAccess().lookupJavaType((Class) obj); + } + } + if (constant instanceof HotSpotMetaspaceConstant) { + Object obj = HotSpotMetaspaceConstantImpl.getMetaspaceObject(constant); + if (obj instanceof HotSpotResolvedObjectTypeImpl) { + return (ResolvedJavaType) obj; + } + } + return null; + } + + private static final String SystemClassName = "Ljava/lang/System;"; + + /** + * Determines if a static field is constant for the purpose of + * {@link #readConstantFieldValue(JavaField, JavaConstant)}. + */ + protected boolean isStaticFieldConstant(HotSpotResolvedJavaField staticField) { + if (staticField.isFinal() || staticField.isStable()) { + ResolvedJavaType holder = staticField.getDeclaringClass(); + if (holder.isInitialized() && !holder.getName().equals(SystemClassName)) { + return true; + } + } + return false; + } + + /** + * Determines if a value read from a {@code final} instance field is considered constant. The + * implementation in {@link HotSpotConstantReflectionProvider} returns true if {@code value} is + * not the {@link JavaConstant#isDefaultForKind default value} for its kind or if + * {@link Options#TrustFinalDefaultFields} is true. + * + * @param value a value read from a {@code final} instance field + * @param receiverClass the {@link Object#getClass() class} of object from which the + * {@code value} was read + */ + protected boolean isFinalInstanceFieldValueConstant(JavaConstant value, Class receiverClass) { + return !value.isDefaultForKind() || TrustFinalDefaultFields.getValue(); + } + + /** + * Determines if a value read from a {@link Stable} instance field is considered constant. The + * implementation in {@link HotSpotConstantReflectionProvider} returns true if {@code value} is + * not the {@link JavaConstant#isDefaultForKind default value} for its kind. + * + * @param value a value read from a {@link Stable} field + * @param receiverClass the {@link Object#getClass() class} of object from which the + * {@code value} was read + */ + protected boolean isStableInstanceFieldValueConstant(JavaConstant value, Class receiverClass) { + return !value.isDefaultForKind(); + } + + /** + * {@inheritDoc} + *

      + * The {@code value} field in {@link OptionValue} is considered constant if the type of + * {@code receiver} is (assignable to) {@link StableOptionValue}. + */ + public JavaConstant readConstantFieldValue(JavaField field, JavaConstant receiver) { + HotSpotResolvedJavaField hotspotField = (HotSpotResolvedJavaField) field; + + if (hotspotField.isStatic()) { + if (isStaticFieldConstant(hotspotField)) { + JavaConstant value = readFieldValue(field, receiver); + if (hotspotField.isFinal() || !value.isDefaultForKind()) { + return value; + } + } + } else { + /* + * for non-static final fields, we must assume that they are only initialized if they + * have a non-default value. + */ + Object object = receiver.isNull() ? null : ((HotSpotObjectConstantImpl) receiver).object(); + + // Canonicalization may attempt to process an unsafe read before + // processing a guard (e.g. a null check or a type check) for this read + // so we need to check the object being read + if (object != null) { + if (hotspotField.isFinal()) { + if (hotspotField.isInObject(object)) { + JavaConstant value = readFieldValue(field, receiver); + if (isFinalInstanceFieldValueConstant(value, object.getClass())) { + return value; + } + } + } else if (hotspotField.isStable()) { + if (hotspotField.isInObject(object)) { + JavaConstant value = readFieldValue(field, receiver); + if (isStableInstanceFieldValueConstant(value, object.getClass())) { + return value; + } + } + } else { + Class clazz = object.getClass(); + if (StableOptionValue.class.isAssignableFrom(clazz)) { + if (hotspotField.isInObject(object) && hotspotField.getName().equals("value")) { + StableOptionValue option = (StableOptionValue) object; + return HotSpotObjectConstantImpl.forObject(option.getValue()); + } + } + } + } + } + return null; + } + + public JavaConstant readFieldValue(JavaField field, JavaConstant receiver) { + HotSpotResolvedJavaField hotspotField = (HotSpotResolvedJavaField) field; + if (!hotspotField.isStable()) { + return readNonStableFieldValue(field, receiver); + } else { + return readStableFieldValue(field, receiver, false); + } + } + + private JavaConstant readNonStableFieldValue(JavaField field, JavaConstant receiver) { + HotSpotResolvedJavaField hotspotField = (HotSpotResolvedJavaField) field; + if (hotspotField.isStatic()) { + HotSpotResolvedJavaType holder = (HotSpotResolvedJavaType) hotspotField.getDeclaringClass(); + if (holder.isInitialized()) { + return memoryAccess.readUnsafeConstant(hotspotField.getKind(), HotSpotObjectConstantImpl.forObject(holder.mirror()), hotspotField.offset()); + } + } else { + if (receiver.isNonNull() && hotspotField.isInObject(((HotSpotObjectConstantImpl) receiver).object())) { + return memoryAccess.readUnsafeConstant(hotspotField.getKind(), receiver, hotspotField.offset()); + } + } + return null; + } + + public JavaConstant readStableFieldValue(JavaField field, JavaConstant receiver, boolean isDefaultStable) { + JavaConstant fieldValue = readNonStableFieldValue(field, receiver); + if (fieldValue.isNonNull()) { + JavaType declaredType = field.getType(); + if (declaredType.getComponentType() != null) { + int stableDimension = getArrayDimension(declaredType); + return HotSpotObjectConstantImpl.forStableArray(((HotSpotObjectConstantImpl) fieldValue).object(), stableDimension, isDefaultStable); + } + } + return fieldValue; + } + + private static int getArrayDimension(JavaType type) { + int dimensions = 0; + JavaType componentType = type; + while ((componentType = componentType.getComponentType()) != null) { + dimensions++; + } + return dimensions; + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotForeignCallTarget.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotForeignCallTarget.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,42 @@ +/* + * 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.jvmci.hotspot; + +import com.oracle.jvmci.meta.*; + +public class HotSpotForeignCallTarget { + /** + * The descriptor of the call. + */ + protected final ForeignCallDescriptor descriptor; + + /** + * The entry point address of this call's target. + */ + protected long address; + + public HotSpotForeignCallTarget(ForeignCallDescriptor descriptor, long address) { + this.descriptor = descriptor; + this.address = address; + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotInstalledCode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotInstalledCode.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,97 @@ +/* + * Copyright (c) 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 static com.oracle.jvmci.common.UnsafeAccess.*; +import sun.misc.*; + +import com.oracle.jvmci.code.*; + +import edu.umd.cs.findbugs.annotations.*; + +/** + * Implementation of {@link InstalledCode} for HotSpot. + */ +public abstract class HotSpotInstalledCode extends InstalledCode { + + /** + * Total size of the code blob. + */ + @SuppressFBWarnings(value = "UWF_UNWRITTEN_FIELD", justification = "field is set by the native part") private int size; + + /** + * Start address of the code. + */ + @SuppressFBWarnings(value = "UWF_UNWRITTEN_FIELD", justification = "field is set by the native part") private long codeStart; + + /** + * Size of the code. + */ + @SuppressFBWarnings(value = "UWF_UNWRITTEN_FIELD", justification = "field is set by the native part") private int codeSize; + + public HotSpotInstalledCode(String name) { + super(name); + } + + /** + * @return the total size of this code blob + */ + public int getSize() { + return size; + } + + /** + * @return a copy of this code blob if it is {@linkplain #isValid() valid}, null otherwise. + */ + public byte[] getBlob() { + if (!isValid()) { + return null; + } + byte[] blob = new byte[size]; + unsafe.copyMemory(null, getAddress(), blob, Unsafe.ARRAY_BYTE_BASE_OFFSET, size); + return blob; + } + + @Override + public abstract String toString(); + + @Override + public long getStart() { + return codeStart; + } + + @Override + public long getCodeSize() { + return codeSize; + } + + @Override + public byte[] getCode() { + if (!isValid()) { + return null; + } + byte[] code = new byte[codeSize]; + unsafe.copyMemory(null, codeStart, code, Unsafe.ARRAY_BYTE_BASE_OFFSET, codeSize); + return code; + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotJVMCIBackendFactory.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotJVMCIBackendFactory.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,38 @@ +/* + * 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.jvmci.hotspot; + +import com.oracle.jvmci.runtime.*; +import com.oracle.jvmci.service.*; + +public interface HotSpotJVMCIBackendFactory extends Service { + + JVMCIBackend createJVMCIBackend(HotSpotJVMCIRuntimeProvider runtime, JVMCIBackend host); + + /** + * Gets the CPU architecture of this backend. + */ + String getArchitecture(); + + String getJVMCIRuntimeName(); +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotJVMCIRuntime.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotJVMCIRuntime.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,328 @@ +/* + * 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.jvmci.hotspot; + +import static com.oracle.jvmci.common.UnsafeAccess.*; +import static com.oracle.jvmci.hotspot.InitTimer.*; + +import java.lang.reflect.*; +import java.util.*; + +import com.oracle.jvmci.code.*; +import com.oracle.jvmci.common.*; +import com.oracle.jvmci.debug.*; +import com.oracle.jvmci.hotspot.logging.*; +import com.oracle.jvmci.meta.*; +import com.oracle.jvmci.options.*; +import com.oracle.jvmci.runtime.*; +import com.oracle.jvmci.service.*; + +//JaCoCo Exclude + +public final class HotSpotJVMCIRuntime implements HotSpotJVMCIRuntimeProvider, HotSpotProxified { + + private static final HotSpotJVMCIRuntime instance; + + static { + try (InitTimer t0 = timer("HotSpotJVMCIRuntime.")) { + try (InitTimer t = timer("HotSpotJVMCIRuntime.")) { + instance = new HotSpotJVMCIRuntime(); + } + + try (InitTimer t = timer("HotSpotJVMCIRuntime.completeInitialization")) { + // Why deferred initialization? See comment in completeInitialization(). + instance.completeInitialization(); + } + } + } + + /** + * Gets the singleton {@link HotSpotJVMCIRuntime} object. + */ + public static HotSpotJVMCIRuntime runtime() { + assert instance != null; + return instance; + } + + /** + * Do deferred initialization. + */ + public void completeInitialization() { + TTY.initialize(Options.LogFile.getStream(compilerToVm)); + + // Proxies for the VM/Compiler interfaces cannot be initialized + // in the constructor as proxy creation causes static + // initializers to be executed for all the types involved in the + // proxied methods. Some of these static initializers (e.g. in + // HotSpotMethodData) rely on the static 'instance' field being set + // to retrieve configuration details. + CompilerToVM toVM = this.compilerToVm; + + if (CountingProxy.ENABLED) { + toVM = CountingProxy.getProxy(CompilerToVM.class, toVM); + } + if (Logger.ENABLED) { + toVM = LoggingProxy.getProxy(CompilerToVM.class, toVM); + } + + this.compilerToVm = toVM; + } + + public static class Options { + + // @formatter:off + @Option(help = "The JVMCI runtime configuration to use", type = OptionType.Expert) + public static final OptionValue JVMCIRuntime = new OptionValue<>(""); + + @Option(help = "File to which logging is sent. A %p in the name will be replaced with a string identifying the process, usually the process id.", type = OptionType.Expert) + public static final PrintStreamOption LogFile = new PrintStreamOption(); + // @formatter:on + } + + public static HotSpotJVMCIBackendFactory findFactory(String architecture) { + HotSpotJVMCIBackendFactory basic = null; + HotSpotJVMCIBackendFactory selected = null; + HotSpotJVMCIBackendFactory nonBasic = null; + int nonBasicCount = 0; + + for (HotSpotJVMCIBackendFactory factory : Services.load(HotSpotJVMCIBackendFactory.class)) { + if (factory.getArchitecture().equalsIgnoreCase(architecture)) { + if (factory.getJVMCIRuntimeName().equals(Options.JVMCIRuntime.getValue())) { + assert selected == null || checkFactoryOverriding(selected, factory); + selected = factory; + } + if (factory.getJVMCIRuntimeName().equals("basic")) { + assert basic == null || checkFactoryOverriding(basic, factory); + basic = factory; + } else { + nonBasic = factory; + nonBasicCount++; + } + } + } + + if (selected != null) { + return selected; + } else { + if (!Options.JVMCIRuntime.getValue().equals("")) { + // Fail fast if a non-default value for JVMCIRuntime was specified + // and the corresponding factory is not available + throw new JVMCIError("Specified runtime \"%s\" not available for the %s architecture", Options.JVMCIRuntime.getValue(), architecture); + } else if (nonBasicCount == 1) { + // If there is exactly one non-basic runtime, select this one. + return nonBasic; + } else { + return basic; + } + } + } + + /** + * Checks that a factory overriding is valid. A factory B can only override/replace a factory A + * if the B.getClass() is a subclass of A.getClass(). This models the assumption that B is + * extends the behavior of A and has therefore understood the behavior expected of A. + * + * @param baseFactory + * @param overridingFactory + */ + private static boolean checkFactoryOverriding(HotSpotJVMCIBackendFactory baseFactory, HotSpotJVMCIBackendFactory overridingFactory) { + return baseFactory.getClass().isAssignableFrom(overridingFactory.getClass()); + } + + /** + * Gets the kind of a word value on the {@linkplain #getHostJVMCIBackend() host} backend. + */ + public static Kind getHostWordKind() { + return instance.getHostJVMCIBackend().getCodeCache().getTarget().wordKind; + } + + /** + * Reads a klass pointer from a constant object. + */ + public static long unsafeReadKlassPointer(Object object) { + return instance.getCompilerToVM().readUnsafeKlassPointer(object); + } + + /** + * Reads a word value from a given object. + */ + public static long unsafeReadWord(Object object, long offset) { + if (getHostWordKind() == Kind.Long) { + return unsafe.getLong(object, offset); + } + return unsafe.getInt(object, offset) & 0xFFFFFFFFL; + } + + protected/* final */CompilerToVM compilerToVm; + + protected final HotSpotVMConfig config; + private final JVMCIBackend hostBackend; + + /** + * JVMCI mirrors are stored as a {@link ClassValue} associated with the {@link Class} of the + * type. This data structure stores both {@link HotSpotResolvedObjectType} and + * {@link HotSpotResolvedPrimitiveType} types. + */ + private final ClassValue jvmciMirrors = new ClassValue() { + @Override + protected ResolvedJavaType computeValue(Class javaClass) { + if (javaClass.isPrimitive()) { + Kind kind = Kind.fromJavaClass(javaClass); + return new HotSpotResolvedPrimitiveType(kind); + } else { + return new HotSpotResolvedObjectTypeImpl(javaClass); + } + } + }; + + private final Map, JVMCIBackend> backends = new HashMap<>(); + + private final Iterable vmEventListeners; + + private HotSpotJVMCIRuntime() { + CompilerToVM toVM = new CompilerToVMImpl(); + compilerToVm = toVM; + try (InitTimer t = timer("HotSpotVMConfig")) { + config = new HotSpotVMConfig(compilerToVm); + } + + if (Boolean.valueOf(System.getProperty("jvmci.printconfig"))) { + printConfig(config); + } + + String hostArchitecture = config.getHostArchitectureName(); + + HotSpotJVMCIBackendFactory factory; + try (InitTimer t = timer("find factory:", hostArchitecture)) { + factory = findFactory(hostArchitecture); + } + try (InitTimer t = timer("create JVMCI backend:", hostArchitecture)) { + hostBackend = registerBackend(factory.createJVMCIBackend(this, null)); + } + + Iterable listeners = Services.load(HotSpotVMEventListener.class); + if (!listeners.iterator().hasNext()) { + listeners = Arrays.asList(new HotSpotVMEventListener() { + }); + } + vmEventListeners = listeners; + } + + private JVMCIBackend registerBackend(JVMCIBackend backend) { + Class arch = backend.getCodeCache().getTarget().arch.getClass(); + JVMCIBackend oldValue = backends.put(arch, backend); + assert oldValue == null : "cannot overwrite existing backend for architecture " + arch.getSimpleName(); + return backend; + } + + public ResolvedJavaType fromClass(Class javaClass) { + return jvmciMirrors.get(javaClass); + } + + private static void printConfig(HotSpotVMConfig config) { + Field[] fields = config.getClass().getDeclaredFields(); + Map sortedFields = new TreeMap<>(); + for (Field f : fields) { + f.setAccessible(true); + sortedFields.put(f.getName(), f); + } + for (Field f : sortedFields.values()) { + try { + Logger.info(String.format("%9s %-40s = %s", f.getType().getSimpleName(), f.getName(), Logger.pretty(f.get(config)))); + } catch (Exception e) { + } + } + } + + public HotSpotVMConfig getConfig() { + return config; + } + + public CompilerToVM getCompilerToVM() { + return compilerToVm; + } + + public JavaType lookupType(String name, HotSpotResolvedObjectType accessingType, boolean resolve) { + Objects.requireNonNull(accessingType, "cannot resolve type without an accessing class"); + // If the name represents a primitive type we can short-circuit the lookup. + if (name.length() == 1) { + Kind kind = Kind.fromPrimitiveOrVoidTypeChar(name.charAt(0)); + return fromClass(kind.toJavaClass()); + } + + // Resolve non-primitive types in the VM. + HotSpotResolvedObjectTypeImpl hsAccessingType = (HotSpotResolvedObjectTypeImpl) accessingType; + final long metaspaceKlass = compilerToVm.lookupType(name, hsAccessingType.mirror(), resolve); + + if (metaspaceKlass == 0L) { + assert resolve == false; + return HotSpotUnresolvedJavaType.create(this, name); + } + return HotSpotResolvedObjectTypeImpl.fromMetaspaceKlass(metaspaceKlass); + } + + public JVMCIBackend getHostJVMCIBackend() { + return hostBackend; + } + + public JVMCIBackend getJVMCIBackend(Class arch) { + assert arch != Architecture.class; + return backends.get(arch); + } + + public Map, JVMCIBackend> getBackends() { + return Collections.unmodifiableMap(backends); + } + + /** + * Called from the VM. + */ + @SuppressWarnings({"unused"}) + private void compileMetaspaceMethod(long metaspaceMethod, int entryBCI, long jvmciEnv, int id) { + for (HotSpotVMEventListener vmEventListener : vmEventListeners) { + vmEventListener.compileMetaspaceMethod(metaspaceMethod, entryBCI, jvmciEnv, id); + } + } + + /** + * Called from the VM. + */ + @SuppressWarnings({"unused"}) + private void compileTheWorld() throws Throwable { + for (HotSpotVMEventListener vmEventListener : vmEventListeners) { + vmEventListener.notifyCompileTheWorld(); + } + } + + /** + * Shuts down the runtime. + * + * Called from the VM. + */ + @SuppressWarnings({"unused"}) + private void shutdown() throws Exception { + for (HotSpotVMEventListener vmEventListener : vmEventListeners) { + vmEventListener.notifyShutdown(); + } + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotJVMCIRuntimeProvider.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotJVMCIRuntimeProvider.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,123 @@ +/* + * 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.jvmci.hotspot; + +import sun.misc.*; + +import com.oracle.jvmci.common.*; +import com.oracle.jvmci.meta.*; +import com.oracle.jvmci.runtime.*; + +//JaCoCo Exclude + +/** + * Configuration information for the HotSpot JVMCI runtime. + */ +public interface HotSpotJVMCIRuntimeProvider extends JVMCIRuntime { + + HotSpotVMConfig getConfig(); + + CompilerToVM getCompilerToVM(); + + /** + * Converts a name to a Java type. This method attempts to resolve {@code name} to a + * {@link ResolvedJavaType}. + * + * @param name a well formed Java type in {@linkplain JavaType#getName() internal} format + * @param accessingType the context of resolution which must be non-null + * @param resolve specifies whether resolution failure results in an unresolved type being + * return or a {@link LinkageError} being thrown + * @return a Java type for {@code name} which is guaranteed to be of type + * {@link ResolvedJavaType} if {@code resolve == true} + * @throws LinkageError if {@code resolve == true} and the resolution failed + * @throws NullPointerException if {@code accessingClass} is {@code null} + */ + JavaType lookupType(String name, HotSpotResolvedObjectType accessingType, boolean resolve); + + /** + * Gets the JVMCI mirror for a {@link Class} object. + * + * @return the {@link ResolvedJavaType} corresponding to {@code javaClass} + */ + ResolvedJavaType fromClass(Class clazz); + + /** + * The offset from the origin of an array to the first element. + * + * @return the offset in bytes + */ + default int getArrayBaseOffset(Kind kind) { + switch (kind) { + case Boolean: + return Unsafe.ARRAY_BOOLEAN_BASE_OFFSET; + case Byte: + return Unsafe.ARRAY_BYTE_BASE_OFFSET; + case Char: + return Unsafe.ARRAY_CHAR_BASE_OFFSET; + case Short: + return Unsafe.ARRAY_SHORT_BASE_OFFSET; + case Int: + return Unsafe.ARRAY_INT_BASE_OFFSET; + case Long: + return Unsafe.ARRAY_LONG_BASE_OFFSET; + case Float: + return Unsafe.ARRAY_FLOAT_BASE_OFFSET; + case Double: + return Unsafe.ARRAY_DOUBLE_BASE_OFFSET; + case Object: + return Unsafe.ARRAY_OBJECT_BASE_OFFSET; + default: + throw new JVMCIError("%s", kind); + } + } + + /** + * The scale used for the index when accessing elements of an array of this kind. + * + * @return the scale in order to convert the index into a byte offset + */ + default int getArrayIndexScale(Kind kind) { + switch (kind) { + case Boolean: + return Unsafe.ARRAY_BOOLEAN_INDEX_SCALE; + case Byte: + return Unsafe.ARRAY_BYTE_INDEX_SCALE; + case Char: + return Unsafe.ARRAY_CHAR_INDEX_SCALE; + case Short: + return Unsafe.ARRAY_SHORT_INDEX_SCALE; + case Int: + return Unsafe.ARRAY_INT_INDEX_SCALE; + case Long: + return Unsafe.ARRAY_LONG_INDEX_SCALE; + case Float: + return Unsafe.ARRAY_FLOAT_INDEX_SCALE; + case Double: + return Unsafe.ARRAY_DOUBLE_INDEX_SCALE; + case Object: + return Unsafe.ARRAY_OBJECT_INDEX_SCALE; + default: + throw new JVMCIError("%s", kind); + } + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotJVMCIVMEventListener.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotJVMCIVMEventListener.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,58 @@ +/* + * 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.jvmci.hotspot; + +import static com.oracle.jvmci.hotspot.CompileTheWorld.Options.*; + +import com.oracle.jvmci.debug.*; +import com.oracle.jvmci.hotspot.CompileTheWorld.Config; +import com.oracle.jvmci.service.*; + +@ServiceProvider(HotSpotVMEventListener.class) +public class HotSpotJVMCIVMEventListener implements HotSpotVMEventListener { + + @Override + public void notifyCompileTheWorld() throws Throwable { + CompilerToVM compilerToVM = HotSpotJVMCIRuntime.runtime().getCompilerToVM(); + int iterations = CompileTheWorld.Options.CompileTheWorldIterations.getValue(); + for (int i = 0; i < iterations; i++) { + compilerToVM.resetCompilationStatistics(); + TTY.println("CompileTheWorld : iteration " + i); + CompileTheWorld ctw = new CompileTheWorld(CompileTheWorldClasspath.getValue(), new Config(CompileTheWorldConfig.getValue()), CompileTheWorldStartAt.getValue(), + CompileTheWorldStopAt.getValue(), CompileTheWorldMethodFilter.getValue(), CompileTheWorldExcludeMethodFilter.getValue(), CompileTheWorldVerbose.getValue()); + ctw.compile(); + } + System.exit(0); + } + + @Override + public void notifyShutdown() { + // nothing to do + } + + @Override + public void compileMetaspaceMethod(long metaspaceMethod, int entryBCI, long jvmciEnv, int id) { + HotSpotResolvedJavaMethod method = HotSpotResolvedJavaMethodImpl.fromMetaspace(metaspaceMethod); + CompilationTask.compileMethod(method, entryBCI, jvmciEnv, id); + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotJavaType.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotJavaType.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,42 @@ +/* + * Copyright (c) 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 com.oracle.jvmci.meta.*; + +/** + * Common base class for all HotSpot {@link JavaType} implementations. + */ +public abstract class HotSpotJavaType implements JavaType { + + private final String name; + + public HotSpotJavaType(String name) { + this.name = name; + } + + @Override + public final String getName() { + return name; + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotMemoryAccessProvider.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotMemoryAccessProvider.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,40 @@ +/* + * 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.hotspot; + +import com.oracle.jvmci.hotspot.HotSpotVMConfig.CompressEncoding; +import com.oracle.jvmci.meta.*; + +/** + * HotSpot specific extension of {@link MemoryAccessProvider}. + */ +public interface HotSpotMemoryAccessProvider extends MemoryAccessProvider { + + JavaConstant readNarrowOopConstant(Constant base, long displacement, CompressEncoding encoding); + + Constant readKlassPointerConstant(Constant base, long displacement); + + Constant readNarrowKlassPointerConstant(Constant base, long displacement, CompressEncoding encoding); + + Constant readMethodPointerConstant(Constant base, long displacement); +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotMemoryAccessProviderImpl.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotMemoryAccessProviderImpl.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,232 @@ +/* + * Copyright (c) 2011, 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; + +import static com.oracle.jvmci.common.UnsafeAccess.*; + +import com.oracle.jvmci.code.*; +import com.oracle.jvmci.common.*; +import com.oracle.jvmci.hotspot.HotSpotVMConfig.CompressEncoding; +import com.oracle.jvmci.meta.*; + +/** + * HotSpot implementation of {@link MemoryAccessProvider}. + */ +public class HotSpotMemoryAccessProviderImpl implements HotSpotMemoryAccessProvider, HotSpotProxified { + + protected final HotSpotJVMCIRuntimeProvider runtime; + + public HotSpotMemoryAccessProviderImpl(HotSpotJVMCIRuntimeProvider runtime) { + this.runtime = runtime; + } + + private static Object asObject(Constant base) { + if (base instanceof HotSpotObjectConstantImpl) { + return ((HotSpotObjectConstantImpl) base).object(); + } else { + return null; + } + } + + private boolean isValidObjectFieldDisplacement(Constant base, long displacement) { + if (base instanceof HotSpotMetaspaceConstant) { + Object metaspaceObject = HotSpotMetaspaceConstantImpl.getMetaspaceObject(base); + if (metaspaceObject instanceof HotSpotResolvedObjectTypeImpl) { + if (displacement == runtime.getConfig().classMirrorOffset) { + // Klass::_java_mirror is valid for all Klass* values + return true; + } else if (displacement == runtime.getConfig().arrayKlassComponentMirrorOffset) { + // ArrayKlass::_component_mirror is only valid for all ArrayKlass* values + return ((HotSpotResolvedObjectTypeImpl) metaspaceObject).mirror().isArray(); + } + } else { + throw new JVMCIError("%s", metaspaceObject); + } + } + return false; + } + + private static long asRawPointer(Constant base) { + if (base instanceof HotSpotMetaspaceConstant) { + return ((HotSpotMetaspaceConstant) base).rawValue(); + } else if (base instanceof PrimitiveConstant) { + PrimitiveConstant prim = (PrimitiveConstant) base; + if (prim.getKind().isNumericInteger()) { + return prim.asLong(); + } + } + throw new JVMCIError("%s", base); + } + + private static long readRawValue(Constant baseConstant, long displacement, int bits) { + Object base = asObject(baseConstant); + if (base != null) { + switch (bits) { + case 8: + return unsafe.getByte(base, displacement); + case 16: + return unsafe.getShort(base, displacement); + case 32: + return unsafe.getInt(base, displacement); + case 64: + return unsafe.getLong(base, displacement); + default: + throw new JVMCIError("%d", bits); + } + } else { + long pointer = asRawPointer(baseConstant); + switch (bits) { + case 8: + return unsafe.getByte(pointer + displacement); + case 16: + return unsafe.getShort(pointer + displacement); + case 32: + return unsafe.getInt(pointer + displacement); + case 64: + return unsafe.getLong(pointer + displacement); + default: + throw new JVMCIError("%d", bits); + } + } + } + + private boolean verifyReadRawObject(Object expected, Constant base, long displacement, boolean compressed) { + if (compressed == runtime.getConfig().useCompressedOops) { + Object obj = asObject(base); + if (obj != null) { + assert expected == unsafe.getObject(obj, displacement) : "readUnsafeOop doesn't agree with unsafe.getObject"; + } + } + if (base instanceof HotSpotMetaspaceConstant) { + Object metaspaceObject = HotSpotMetaspaceConstantImpl.getMetaspaceObject(base); + if (metaspaceObject instanceof HotSpotResolvedObjectTypeImpl) { + if (displacement == runtime.getConfig().classMirrorOffset) { + assert expected == ((HotSpotResolvedObjectTypeImpl) metaspaceObject).mirror(); + } else if (displacement == runtime.getConfig().arrayKlassComponentMirrorOffset) { + assert expected == ((HotSpotResolvedObjectTypeImpl) metaspaceObject).mirror().getComponentType(); + } + } + } + return true; + } + + private Object readRawObject(Constant baseConstant, long initialDisplacement, boolean compressed) { + long displacement = initialDisplacement; + + Object ret; + Object base = asObject(baseConstant); + if (base == null) { + assert !compressed; + displacement += asRawPointer(baseConstant); + ret = runtime.getCompilerToVM().readUncompressedOop(displacement); + } else { + assert runtime.getConfig().useCompressedOops == compressed; + ret = unsafe.getObject(base, displacement); + } + assert verifyReadRawObject(ret, baseConstant, initialDisplacement, compressed); + return ret; + } + + @Override + public JavaConstant readUnsafeConstant(Kind kind, JavaConstant baseConstant, long displacement) { + if (kind == Kind.Object) { + Object o = readRawObject(baseConstant, displacement, runtime.getConfig().useCompressedOops); + return HotSpotObjectConstantImpl.forObject(o); + } else { + return readPrimitiveConstant(kind, baseConstant, displacement, kind.getByteCount() * 8); + } + } + + @Override + public JavaConstant readPrimitiveConstant(Kind kind, Constant baseConstant, long initialDisplacement, int bits) { + try { + long rawValue = readRawValue(baseConstant, initialDisplacement, bits); + switch (kind) { + case Boolean: + return JavaConstant.forBoolean(rawValue != 0); + case Byte: + return JavaConstant.forByte((byte) rawValue); + case Char: + return JavaConstant.forChar((char) rawValue); + case Short: + return JavaConstant.forShort((short) rawValue); + case Int: + return JavaConstant.forInt((int) rawValue); + case Long: + return JavaConstant.forLong(rawValue); + case Float: + return JavaConstant.forFloat(Float.intBitsToFloat((int) rawValue)); + case Double: + return JavaConstant.forDouble(Double.longBitsToDouble(rawValue)); + default: + throw new JVMCIError("Unsupported kind: %s", kind); + } + } catch (NullPointerException e) { + return null; + } + } + + @Override + public JavaConstant readObjectConstant(Constant base, long displacement) { + if (!isValidObjectFieldDisplacement(base, displacement)) { + return null; + } + return HotSpotObjectConstantImpl.forObject(readRawObject(base, displacement, false)); + } + + @Override + public JavaConstant readNarrowOopConstant(Constant base, long displacement, CompressEncoding encoding) { + assert encoding.equals(runtime.getConfig().getOopEncoding()) : "unexpected oop encoding: " + encoding + " != " + runtime.getConfig().getOopEncoding(); + return HotSpotObjectConstantImpl.forObject(readRawObject(base, displacement, true), true); + } + + @Override + public Constant readKlassPointerConstant(Constant base, long displacement) { + TargetDescription target = runtime.getHostJVMCIBackend().getCodeCache().getTarget(); + long klass = readRawValue(base, displacement, target.wordSize * 8); + if (klass == 0) { + return JavaConstant.NULL_POINTER; + } + HotSpotResolvedObjectType metaKlass = HotSpotResolvedObjectTypeImpl.fromMetaspaceKlass(klass); + return HotSpotMetaspaceConstantImpl.forMetaspaceObject(target.wordKind, klass, metaKlass, false); + } + + @Override + public Constant readNarrowKlassPointerConstant(Constant base, long displacement, CompressEncoding encoding) { + int compressed = (int) readRawValue(base, displacement, 32); + long klass = encoding.uncompress(compressed); + if (klass == 0) { + return HotSpotCompressedNullConstant.COMPRESSED_NULL; + } + HotSpotResolvedObjectType metaKlass = HotSpotResolvedObjectTypeImpl.fromMetaspaceKlass(klass); + return HotSpotMetaspaceConstantImpl.forMetaspaceObject(Kind.Int, compressed, metaKlass, true); + } + + @Override + public Constant readMethodPointerConstant(Constant base, long displacement) { + TargetDescription target = runtime.getHostJVMCIBackend().getCodeCache().getTarget(); + long method = readRawValue(base, displacement, target.wordSize * 8); + HotSpotResolvedJavaMethod metaMethod = HotSpotResolvedJavaMethodImpl.fromMetaspace(method); + return HotSpotMetaspaceConstantImpl.forMetaspaceObject(target.wordKind, method, metaMethod, false); + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotMetaAccessProvider.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotMetaAccessProvider.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,326 @@ +/* + * Copyright (c) 2011, 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; + +import static com.oracle.jvmci.common.UnsafeAccess.*; +import static com.oracle.jvmci.hotspot.HotSpotResolvedJavaType.*; +import static com.oracle.jvmci.hotspot.HotSpotResolvedObjectTypeImpl.*; + +import java.lang.reflect.*; + +import com.oracle.jvmci.code.*; +import com.oracle.jvmci.common.*; +import com.oracle.jvmci.meta.*; + +// JaCoCo Exclude + +/** + * HotSpot implementation of {@link MetaAccessProvider}. + */ +public class HotSpotMetaAccessProvider implements MetaAccessProvider, HotSpotProxified { + + protected final HotSpotJVMCIRuntimeProvider runtime; + + public HotSpotMetaAccessProvider(HotSpotJVMCIRuntimeProvider runtime) { + this.runtime = runtime; + } + + public ResolvedJavaType lookupJavaType(Class clazz) { + if (clazz == null) { + throw new IllegalArgumentException("Class parameter was null"); + } + return runtime.fromClass(clazz); + } + + public HotSpotResolvedObjectType lookupJavaType(JavaConstant constant) { + if (constant.isNull() || !(constant instanceof HotSpotObjectConstant)) { + return null; + } + return ((HotSpotObjectConstant) constant).getType(); + } + + public Signature parseMethodDescriptor(String signature) { + return new HotSpotSignature(runtime, signature); + } + + /** + * {@link Field} object of {@link Method#slot}. + */ + @SuppressWarnings("javadoc") private Field reflectionMethodSlot = getReflectionSlotField(Method.class); + + /** + * {@link Field} object of {@link Constructor#slot}. + */ + @SuppressWarnings("javadoc") private Field reflectionConstructorSlot = getReflectionSlotField(Constructor.class); + + private static Field getReflectionSlotField(Class reflectionClass) { + try { + Field field = reflectionClass.getDeclaredField("slot"); + field.setAccessible(true); + return field; + } catch (NoSuchFieldException | SecurityException e) { + throw new JVMCIError(e); + } + } + + public ResolvedJavaMethod lookupJavaMethod(Executable reflectionMethod) { + try { + Class holder = reflectionMethod.getDeclaringClass(); + Field slotField = reflectionMethod instanceof Constructor ? reflectionConstructorSlot : reflectionMethodSlot; + final int slot = slotField.getInt(reflectionMethod); + final long metaspaceMethod = runtime.getCompilerToVM().getMetaspaceMethod(holder, slot); + return HotSpotResolvedJavaMethodImpl.fromMetaspace(metaspaceMethod); + } catch (IllegalArgumentException | IllegalAccessException e) { + throw new JVMCIError(e); + } + } + + public ResolvedJavaField lookupJavaField(Field reflectionField) { + String name = reflectionField.getName(); + Class fieldHolder = reflectionField.getDeclaringClass(); + Class fieldType = reflectionField.getType(); + // java.lang.reflect.Field's modifiers should be enough here since VM internal modifier bits + // are not used (yet). + final int modifiers = reflectionField.getModifiers(); + final long offset = Modifier.isStatic(modifiers) ? unsafe.staticFieldOffset(reflectionField) : unsafe.objectFieldOffset(reflectionField); + + HotSpotResolvedObjectType holder = fromObjectClass(fieldHolder); + JavaType type = fromClass(fieldType); + + if (offset != -1) { + HotSpotResolvedObjectType resolved = holder; + return resolved.createField(name, type, offset, modifiers); + } else { + throw new JVMCIError("unresolved field %s", reflectionField); + } + } + + private static int intMaskRight(int n) { + assert n <= 32; + return n == 32 ? -1 : (1 << n) - 1; + } + + @Override + public JavaConstant encodeDeoptActionAndReason(DeoptimizationAction action, DeoptimizationReason reason, int debugId) { + HotSpotVMConfig config = runtime.getConfig(); + int actionValue = convertDeoptAction(action); + int reasonValue = convertDeoptReason(reason); + int debugValue = debugId & intMaskRight(config.deoptimizationDebugIdBits); + JavaConstant c = JavaConstant.forInt(~((debugValue << config.deoptimizationDebugIdShift) | (reasonValue << config.deoptimizationReasonShift) | (actionValue << config.deoptimizationActionShift))); + assert c.asInt() < 0; + return c; + } + + public DeoptimizationReason decodeDeoptReason(JavaConstant constant) { + HotSpotVMConfig config = runtime.getConfig(); + int reasonValue = ((~constant.asInt()) >> config.deoptimizationReasonShift) & intMaskRight(config.deoptimizationReasonBits); + DeoptimizationReason reason = convertDeoptReason(reasonValue); + return reason; + } + + public DeoptimizationAction decodeDeoptAction(JavaConstant constant) { + HotSpotVMConfig config = runtime.getConfig(); + int actionValue = ((~constant.asInt()) >> config.deoptimizationActionShift) & intMaskRight(config.deoptimizationActionBits); + DeoptimizationAction action = convertDeoptAction(actionValue); + return action; + } + + public int decodeDebugId(JavaConstant constant) { + HotSpotVMConfig config = runtime.getConfig(); + return ((~constant.asInt()) >> config.deoptimizationDebugIdShift) & intMaskRight(config.deoptimizationDebugIdBits); + } + + public int convertDeoptAction(DeoptimizationAction action) { + HotSpotVMConfig config = runtime.getConfig(); + switch (action) { + case None: + return config.deoptActionNone; + case RecompileIfTooManyDeopts: + return config.deoptActionMaybeRecompile; + case InvalidateReprofile: + return config.deoptActionReinterpret; + case InvalidateRecompile: + return config.deoptActionMakeNotEntrant; + case InvalidateStopCompiling: + return config.deoptActionMakeNotCompilable; + default: + throw new JVMCIError("%s", action); + } + } + + public DeoptimizationAction convertDeoptAction(int action) { + HotSpotVMConfig config = runtime.getConfig(); + if (action == config.deoptActionNone) { + return DeoptimizationAction.None; + } + if (action == config.deoptActionMaybeRecompile) { + return DeoptimizationAction.RecompileIfTooManyDeopts; + } + if (action == config.deoptActionReinterpret) { + return DeoptimizationAction.InvalidateReprofile; + } + if (action == config.deoptActionMakeNotEntrant) { + return DeoptimizationAction.InvalidateRecompile; + } + if (action == config.deoptActionMakeNotCompilable) { + return DeoptimizationAction.InvalidateStopCompiling; + } + throw new JVMCIError("%d", action); + } + + public int convertDeoptReason(DeoptimizationReason reason) { + HotSpotVMConfig config = runtime.getConfig(); + switch (reason) { + case None: + return config.deoptReasonNone; + case NullCheckException: + return config.deoptReasonNullCheck; + case BoundsCheckException: + return config.deoptReasonRangeCheck; + case ClassCastException: + return config.deoptReasonClassCheck; + case ArrayStoreException: + return config.deoptReasonArrayCheck; + case UnreachedCode: + return config.deoptReasonUnreached0; + case TypeCheckedInliningViolated: + return config.deoptReasonTypeCheckInlining; + case OptimizedTypeCheckViolated: + return config.deoptReasonOptimizedTypeCheck; + case NotCompiledExceptionHandler: + return config.deoptReasonNotCompiledExceptionHandler; + case Unresolved: + return config.deoptReasonUnresolved; + case JavaSubroutineMismatch: + return config.deoptReasonJsrMismatch; + case ArithmeticException: + return config.deoptReasonDiv0Check; + case RuntimeConstraint: + return config.deoptReasonConstraint; + case LoopLimitCheck: + return config.deoptReasonLoopLimitCheck; + case Aliasing: + return config.deoptReasonAliasing; + case TransferToInterpreter: + return config.deoptReasonTransferToInterpreter; + default: + throw new JVMCIError("%s", reason); + } + } + + public DeoptimizationReason convertDeoptReason(int reason) { + HotSpotVMConfig config = runtime.getConfig(); + if (reason == config.deoptReasonNone) { + return DeoptimizationReason.None; + } + if (reason == config.deoptReasonNullCheck) { + return DeoptimizationReason.NullCheckException; + } + if (reason == config.deoptReasonRangeCheck) { + return DeoptimizationReason.BoundsCheckException; + } + if (reason == config.deoptReasonClassCheck) { + return DeoptimizationReason.ClassCastException; + } + if (reason == config.deoptReasonArrayCheck) { + return DeoptimizationReason.ArrayStoreException; + } + if (reason == config.deoptReasonUnreached0) { + return DeoptimizationReason.UnreachedCode; + } + if (reason == config.deoptReasonTypeCheckInlining) { + return DeoptimizationReason.TypeCheckedInliningViolated; + } + if (reason == config.deoptReasonOptimizedTypeCheck) { + return DeoptimizationReason.OptimizedTypeCheckViolated; + } + if (reason == config.deoptReasonNotCompiledExceptionHandler) { + return DeoptimizationReason.NotCompiledExceptionHandler; + } + if (reason == config.deoptReasonUnresolved) { + return DeoptimizationReason.Unresolved; + } + if (reason == config.deoptReasonJsrMismatch) { + return DeoptimizationReason.JavaSubroutineMismatch; + } + if (reason == config.deoptReasonDiv0Check) { + return DeoptimizationReason.ArithmeticException; + } + if (reason == config.deoptReasonConstraint) { + return DeoptimizationReason.RuntimeConstraint; + } + if (reason == config.deoptReasonLoopLimitCheck) { + return DeoptimizationReason.LoopLimitCheck; + } + if (reason == config.deoptReasonAliasing) { + return DeoptimizationReason.Aliasing; + } + if (reason == config.deoptReasonTransferToInterpreter) { + return DeoptimizationReason.TransferToInterpreter; + } + throw new JVMCIError("%x", reason); + } + + @Override + public long getMemorySize(JavaConstant constant) { + if (constant.getKind() == Kind.Object) { + HotSpotResolvedObjectType lookupJavaType = lookupJavaType(constant); + + if (lookupJavaType == null) { + return 0; + } else { + if (lookupJavaType.isArray()) { + // TODO(tw): Add compressed pointer support. + int length = Array.getLength(((HotSpotObjectConstantImpl) constant).object()); + ResolvedJavaType elementType = lookupJavaType.getComponentType(); + Kind elementKind = elementType.getKind(); + final int headerSize = runtime.getArrayBaseOffset(elementKind); + TargetDescription target = runtime.getHostJVMCIBackend().getTarget(); + int sizeOfElement = target.getSizeInBytes(elementKind); + int alignment = target.wordSize; + int log2ElementSize = CodeUtil.log2(sizeOfElement); + return computeArrayAllocationSize(length, alignment, headerSize, log2ElementSize); + } + return lookupJavaType.instanceSize(); + } + } else { + return constant.getKind().getByteCount(); + } + } + + /** + * Computes the size of the memory chunk allocated for an array. This size accounts for the + * array header size, body size and any padding after the last element to satisfy object + * alignment requirements. + * + * @param length the number of elements in the array + * @param alignment the object alignment requirement + * @param headerSize the size of the array header + * @param log2ElementSize log2 of the size of an element in the array + */ + public static int computeArrayAllocationSize(int length, int alignment, int headerSize, int log2ElementSize) { + int size = (length << log2ElementSize) + headerSize + (alignment - 1); + int mask = ~(alignment - 1); + return size & mask; + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotMetaspaceConstant.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotMetaspaceConstant.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,37 @@ +/* + * 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 + * 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.hotspot.HotSpotVMConfig.CompressEncoding; +import com.oracle.jvmci.meta.*; + +public interface HotSpotMetaspaceConstant extends HotSpotConstant, VMConstant { + + Constant compress(CompressEncoding encoding); + + Constant uncompress(CompressEncoding encoding); + + HotSpotResolvedObjectType asResolvedJavaType(); + + long rawValue(); +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotMetaspaceConstantImpl.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotMetaspaceConstantImpl.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,92 @@ +/* + * 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.hotspot; + +import java.util.*; + +import com.oracle.jvmci.hotspot.HotSpotVMConfig.CompressEncoding; +import com.oracle.jvmci.meta.*; + +public final class HotSpotMetaspaceConstantImpl extends PrimitiveConstant implements HotSpotMetaspaceConstant, VMConstant, HotSpotProxified { + + static HotSpotMetaspaceConstantImpl forMetaspaceObject(Kind kind, long primitive, Object metaspaceObject, boolean compressed) { + return new HotSpotMetaspaceConstantImpl(kind, primitive, metaspaceObject, compressed); + } + + static Object getMetaspaceObject(Constant constant) { + return ((HotSpotMetaspaceConstantImpl) constant).metaspaceObject; + } + + private final Object metaspaceObject; + private final boolean compressed; + + private HotSpotMetaspaceConstantImpl(Kind kind, long primitive, Object metaspaceObject, boolean compressed) { + super(kind, primitive); + this.metaspaceObject = metaspaceObject; + this.compressed = compressed; + } + + @Override + public int hashCode() { + return super.hashCode() ^ System.identityHashCode(metaspaceObject); + } + + @Override + public boolean equals(Object o) { + return o == this || (o instanceof HotSpotMetaspaceConstantImpl && super.equals(o) && Objects.equals(metaspaceObject, ((HotSpotMetaspaceConstantImpl) o).metaspaceObject)); + } + + @Override + public String toString() { + return super.toString() + "{" + metaspaceObject + (compressed ? ";compressed}" : "}"); + } + + public boolean isCompressed() { + return compressed; + } + + public JavaConstant compress(CompressEncoding encoding) { + assert !isCompressed(); + HotSpotMetaspaceConstantImpl res = HotSpotMetaspaceConstantImpl.forMetaspaceObject(Kind.Int, encoding.compress(asLong()), metaspaceObject, true); + assert res.isCompressed(); + return res; + } + + public JavaConstant uncompress(CompressEncoding encoding) { + assert isCompressed(); + HotSpotMetaspaceConstantImpl res = HotSpotMetaspaceConstantImpl.forMetaspaceObject(Kind.Long, encoding.uncompress(asInt()), metaspaceObject, false); + assert !res.isCompressed(); + return res; + } + + public HotSpotResolvedObjectType asResolvedJavaType() { + if (metaspaceObject instanceof HotSpotResolvedObjectType) { + return (HotSpotResolvedObjectType) metaspaceObject; + } + return null; + } + + public long rawValue() { + return asLong(); + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotMethod.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotMethod.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,68 @@ +/* + * Copyright (c) 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 static com.oracle.jvmci.debug.Debug.*; +import static java.util.FormattableFlags.*; + +import java.util.*; + +import com.oracle.jvmci.debug.*; +import com.oracle.jvmci.meta.*; + +public abstract class HotSpotMethod implements JavaMethod, Formattable, JavaMethodContex { + + protected String name; + + /** + * Controls whether {@link #toString()} includes the qualified or simple name of the class in + * which the method is declared. + */ + public static final boolean FULLY_QUALIFIED_METHOD_NAME = false; + + protected HotSpotMethod(String name) { + this.name = name; + } + + @Override + public final String getName() { + return name; + } + + @Override + public final String toString() { + char h = FULLY_QUALIFIED_METHOD_NAME ? 'H' : 'h'; + String suffix = this instanceof ResolvedJavaMethod ? "" : ", unresolved"; + String fmt = String.format("HotSpotMethod<%%%c.%%n(%%p)%s>", h, suffix); + return format(fmt); + } + + public void formatTo(Formatter formatter, int flags, int width, int precision) { + String base = (flags & ALTERNATE) == ALTERNATE ? getName() : toString(); + formatter.format(applyFormattingFlagsAndWidth(base, flags & ~ALTERNATE, width)); + } + + public JavaMethod asJavaMethod() { + return this; + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotMethodData.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotMethodData.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,858 @@ +/* + * 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.hotspot; + +import static com.oracle.jvmci.common.UnsafeAccess.*; +import static com.oracle.jvmci.hotspot.HotSpotJVMCIRuntime.*; +import static java.lang.String.*; + +import java.util.*; + +import sun.misc.*; + +import com.oracle.jvmci.hotspot.HotSpotMethodDataAccessor.Tag; +import com.oracle.jvmci.meta.*; +import com.oracle.jvmci.meta.JavaMethodProfile.ProfiledMethod; +import com.oracle.jvmci.meta.JavaTypeProfile.ProfiledType; + +/** + * Access to a HotSpot MethodData structure (defined in methodData.hpp). + */ +public final class HotSpotMethodData { + + private static final HotSpotVMConfig config = runtime().getConfig(); + private static final HotSpotMethodDataAccessor NO_DATA_NO_EXCEPTION_ACCESSOR = new NoMethodData(TriState.FALSE); + private static final HotSpotMethodDataAccessor NO_DATA_EXCEPTION_POSSIBLY_NOT_RECORDED_ACCESSOR = new NoMethodData(TriState.UNKNOWN); + + // sorted by tag + // @formatter:off + private static final HotSpotMethodDataAccessor[] PROFILE_DATA_ACCESSORS = { + null, + new BitData(), + new CounterData(), + new JumpData(), + new TypeCheckData(), + new VirtualCallData(), + new RetData(), + new BranchData(), + new MultiBranchData(), + new ArgInfoData(), + null, // call_type_data_tag + null, // virtual_call_type_data_tag + null, // parameters_type_data_tag + null, // speculative_trap_data_tag + }; + // @formatter:on + + /** + * Reference to the C++ MethodData object. + */ + private final long metaspaceMethodData; + + public HotSpotMethodData(long metaspaceMethodData) { + this.metaspaceMethodData = metaspaceMethodData; + } + + /** + * @return value of the MethodData::_data_size field + */ + private int normalDataSize() { + return unsafe.getInt(metaspaceMethodData + config.methodDataDataSize); + } + + /** + * Returns the size of the extra data records. This method does the same calculation as + * MethodData::extra_data_size(). + * + * @return size of extra data records + */ + private int extraDataSize() { + final int extraDataBase = config.methodDataOopDataOffset + normalDataSize(); + final int extraDataLimit = unsafe.getInt(metaspaceMethodData + config.methodDataSize); + return extraDataLimit - extraDataBase; + } + + public boolean hasNormalData() { + return normalDataSize() > 0; + } + + public boolean hasExtraData() { + return extraDataSize() > 0; + } + + public int getExtraDataBeginOffset() { + return normalDataSize(); + } + + public boolean isWithin(int position) { + return position >= 0 && position < normalDataSize() + extraDataSize(); + } + + public int getDeoptimizationCount(DeoptimizationReason reason) { + HotSpotMetaAccessProvider metaAccess = (HotSpotMetaAccessProvider) runtime().getHostJVMCIBackend().getMetaAccess(); + int reasonIndex = metaAccess.convertDeoptReason(reason); + return unsafe.getByte(metaspaceMethodData + config.methodDataOopTrapHistoryOffset + reasonIndex) & 0xFF; + } + + public int getOSRDeoptimizationCount(DeoptimizationReason reason) { + HotSpotMetaAccessProvider metaAccess = (HotSpotMetaAccessProvider) runtime().getHostJVMCIBackend().getMetaAccess(); + int reasonIndex = metaAccess.convertDeoptReason(reason); + return unsafe.getByte(metaspaceMethodData + config.methodDataOopTrapHistoryOffset + config.deoptReasonOSROffset + reasonIndex) & 0xFF; + } + + public HotSpotMethodDataAccessor getNormalData(int position) { + if (position >= normalDataSize()) { + return null; + } + + HotSpotMethodDataAccessor result = getData(position); + assert result != null : "NO_DATA tag is not allowed"; + return result; + } + + public HotSpotMethodDataAccessor getExtraData(int position) { + if (position >= normalDataSize() + extraDataSize()) { + return null; + } + HotSpotMethodDataAccessor data = getData(position); + if (data != null) { + return data; + } + return data; + } + + public static HotSpotMethodDataAccessor getNoDataAccessor(boolean exceptionPossiblyNotRecorded) { + if (exceptionPossiblyNotRecorded) { + return NO_DATA_EXCEPTION_POSSIBLY_NOT_RECORDED_ACCESSOR; + } else { + return NO_DATA_NO_EXCEPTION_ACCESSOR; + } + } + + private HotSpotMethodDataAccessor getData(int position) { + assert position >= 0 : "out of bounds"; + final Tag tag = AbstractMethodData.readTag(this, position); + HotSpotMethodDataAccessor accessor = PROFILE_DATA_ACCESSORS[tag.getValue()]; + assert accessor == null || accessor.getTag() == tag : "wrong data accessor " + accessor + " for tag " + tag; + return accessor; + } + + private int readUnsignedByte(int position, int offsetInBytes) { + long fullOffsetInBytes = computeFullOffset(position, offsetInBytes); + return unsafe.getByte(metaspaceMethodData + fullOffsetInBytes) & 0xFF; + } + + private int readUnsignedShort(int position, int offsetInBytes) { + long fullOffsetInBytes = computeFullOffset(position, offsetInBytes); + return unsafe.getShort(metaspaceMethodData + fullOffsetInBytes) & 0xFFFF; + } + + /** + * Since the values are stored in cells (platform words) this method uses + * {@link Unsafe#getAddress} to read the right value on both little and big endian machines. + */ + private long readUnsignedInt(int position, int offsetInBytes) { + long fullOffsetInBytes = computeFullOffset(position, offsetInBytes); + return unsafe.getAddress(metaspaceMethodData + fullOffsetInBytes) & 0xFFFFFFFFL; + } + + private int readUnsignedIntAsSignedInt(int position, int offsetInBytes) { + long value = readUnsignedInt(position, offsetInBytes); + return truncateLongToInt(value); + } + + /** + * Since the values are stored in cells (platform words) this method uses + * {@link Unsafe#getAddress} to read the right value on both little and big endian machines. + */ + private int readInt(int position, int offsetInBytes) { + long fullOffsetInBytes = computeFullOffset(position, offsetInBytes); + return (int) unsafe.getAddress(metaspaceMethodData + fullOffsetInBytes); + } + + private long readWord(int position, int offsetInBytes) { + long fullOffsetInBytes = computeFullOffset(position, offsetInBytes); + return unsafe.getAddress(metaspaceMethodData + fullOffsetInBytes); + } + + private static int truncateLongToInt(long value) { + return value > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) value; + } + + private static int computeFullOffset(int position, int offsetInBytes) { + return config.methodDataOopDataOffset + position + offsetInBytes; + } + + private static int cellIndexToOffset(int cells) { + return config.dataLayoutHeaderSize + cellsToBytes(cells); + } + + private static int cellsToBytes(int cells) { + return cells * config.dataLayoutCellSize; + } + + /** + * Returns whether profiling ran long enough that the profile information is mature. Other + * informational data will still be valid even if the profile isn't mature. + */ + public boolean isProfileMature() { + return runtime().getCompilerToVM().isMature(metaspaceMethodData); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + String nl = String.format("%n"); + String nlIndent = String.format("%n%38s", ""); + if (hasNormalData()) { + int pos = 0; + HotSpotMethodDataAccessor data; + while ((data = getNormalData(pos)) != null) { + if (pos != 0) { + sb.append(nl); + } + int bci = data.getBCI(this, pos); + sb.append(String.format("%-6d bci: %-6d%-20s", pos, bci, data.getClass().getSimpleName())); + sb.append(data.appendTo(new StringBuilder(), this, pos).toString().replace(nl, nlIndent)); + pos = pos + data.getSize(this, pos); + } + } + + if (hasExtraData()) { + int pos = getExtraDataBeginOffset(); + HotSpotMethodDataAccessor data; + while ((data = getExtraData(pos)) != null) { + if (pos == getExtraDataBeginOffset()) { + sb.append(nl).append("--- Extra data:"); + } + int bci = data.getBCI(this, pos); + sb.append(String.format("%n%-6d bci: %-6d%-20s", pos, bci, data.getClass().getSimpleName())); + sb.append(data.appendTo(new StringBuilder(), this, pos).toString().replace(nl, nlIndent)); + pos = pos + data.getSize(this, pos); + } + + } + return sb.toString(); + } + + private abstract static class AbstractMethodData implements HotSpotMethodDataAccessor { + + /** + * Corresponds to {@code exception_seen_flag}. + */ + private static final int EXCEPTIONS_MASK = 0x2; + + private final Tag tag; + private final int staticSize; + + protected AbstractMethodData(Tag tag, int staticSize) { + this.tag = tag; + this.staticSize = staticSize; + } + + public Tag getTag() { + return tag; + } + + public static Tag readTag(HotSpotMethodData data, int position) { + final int tag = data.readUnsignedByte(position, config.dataLayoutTagOffset); + return Tag.getEnum(tag); + } + + @Override + public int getBCI(HotSpotMethodData data, int position) { + return data.readUnsignedShort(position, config.dataLayoutBCIOffset); + } + + @Override + public int getSize(HotSpotMethodData data, int position) { + return staticSize + getDynamicSize(data, position); + } + + @Override + public TriState getExceptionSeen(HotSpotMethodData data, int position) { + return TriState.get((getFlags(data, position) & EXCEPTIONS_MASK) != 0); + } + + @Override + public JavaTypeProfile getTypeProfile(HotSpotMethodData data, int position) { + return null; + } + + @Override + public JavaMethodProfile getMethodProfile(HotSpotMethodData data, int position) { + return null; + } + + @Override + public double getBranchTakenProbability(HotSpotMethodData data, int position) { + return -1; + } + + @Override + public double[] getSwitchProbabilities(HotSpotMethodData data, int position) { + return null; + } + + @Override + public int getExecutionCount(HotSpotMethodData data, int position) { + return -1; + } + + @Override + public TriState getNullSeen(HotSpotMethodData data, int position) { + return TriState.UNKNOWN; + } + + protected int getFlags(HotSpotMethodData data, int position) { + return data.readUnsignedByte(position, config.dataLayoutFlagsOffset); + } + + /** + * @param data + * @param position + */ + protected int getDynamicSize(HotSpotMethodData data, int position) { + return 0; + } + + public abstract StringBuilder appendTo(StringBuilder sb, HotSpotMethodData data, int pos); + } + + private static class NoMethodData extends AbstractMethodData { + + private static final int NO_DATA_SIZE = cellIndexToOffset(0); + + private final TriState exceptionSeen; + + protected NoMethodData(TriState exceptionSeen) { + super(Tag.No, NO_DATA_SIZE); + this.exceptionSeen = exceptionSeen; + } + + @Override + public int getBCI(HotSpotMethodData data, int position) { + return -1; + } + + @Override + public TriState getExceptionSeen(HotSpotMethodData data, int position) { + return exceptionSeen; + } + + @Override + public StringBuilder appendTo(StringBuilder sb, HotSpotMethodData data, int pos) { + return sb; + } + } + + private static class BitData extends AbstractMethodData { + + private static final int BIT_DATA_SIZE = cellIndexToOffset(0); + private static final int BIT_DATA_NULL_SEEN_FLAG = 0x01; + + private BitData() { + super(Tag.BitData, BIT_DATA_SIZE); + } + + protected BitData(Tag tag, int staticSize) { + super(tag, staticSize); + } + + @Override + public TriState getNullSeen(HotSpotMethodData data, int position) { + return TriState.get((getFlags(data, position) & BIT_DATA_NULL_SEEN_FLAG) != 0); + } + + @Override + public StringBuilder appendTo(StringBuilder sb, HotSpotMethodData data, int pos) { + return sb.append(format("exception_seen(%s)", getExceptionSeen(data, pos))); + } + } + + private static class CounterData extends BitData { + + private static final int COUNTER_DATA_SIZE = cellIndexToOffset(1); + private static final int COUNTER_DATA_COUNT_OFFSET = cellIndexToOffset(0); + + public CounterData() { + super(Tag.CounterData, COUNTER_DATA_SIZE); + } + + protected CounterData(Tag tag, int staticSize) { + super(tag, staticSize); + } + + @Override + public int getExecutionCount(HotSpotMethodData data, int position) { + return getCounterValue(data, position); + } + + protected int getCounterValue(HotSpotMethodData data, int position) { + return data.readUnsignedIntAsSignedInt(position, COUNTER_DATA_COUNT_OFFSET); + } + + @Override + public StringBuilder appendTo(StringBuilder sb, HotSpotMethodData data, int pos) { + return sb.append(format("count(%d) null_seen(%s) exception_seen(%s)", getCounterValue(data, pos), getNullSeen(data, pos), getExceptionSeen(data, pos))); + } + } + + private static class JumpData extends AbstractMethodData { + + private static final int JUMP_DATA_SIZE = cellIndexToOffset(2); + protected static final int TAKEN_COUNT_OFFSET = cellIndexToOffset(0); + protected static final int TAKEN_DISPLACEMENT_OFFSET = cellIndexToOffset(1); + + public JumpData() { + super(Tag.JumpData, JUMP_DATA_SIZE); + } + + protected JumpData(Tag tag, int staticSize) { + super(tag, staticSize); + } + + @Override + public double getBranchTakenProbability(HotSpotMethodData data, int position) { + return getExecutionCount(data, position) != 0 ? 1 : 0; + } + + @Override + public int getExecutionCount(HotSpotMethodData data, int position) { + return data.readUnsignedIntAsSignedInt(position, TAKEN_COUNT_OFFSET); + } + + public int getTakenDisplacement(HotSpotMethodData data, int position) { + return data.readInt(position, TAKEN_DISPLACEMENT_OFFSET); + } + + @Override + public StringBuilder appendTo(StringBuilder sb, HotSpotMethodData data, int pos) { + return sb.append(format("taken(%d) displacement(%d)", getExecutionCount(data, pos), getTakenDisplacement(data, pos))); + } + } + + static class RawItemProfile { + final int entries; + final T[] items; + final long[] counts; + final long totalCount; + + public RawItemProfile(int entries, T[] items, long[] counts, long totalCount) { + this.entries = entries; + this.items = items; + this.counts = counts; + this.totalCount = totalCount; + } + } + + private abstract static class AbstractTypeData extends CounterData { + + protected static final int TYPE_DATA_ROW_SIZE = cellsToBytes(2); + + protected static final int NONPROFILED_COUNT_OFFSET = cellIndexToOffset(1); + protected static final int TYPE_DATA_FIRST_TYPE_OFFSET = cellIndexToOffset(2); + protected static final int TYPE_DATA_FIRST_TYPE_COUNT_OFFSET = cellIndexToOffset(3); + + protected AbstractTypeData(Tag tag, int staticSize) { + super(tag, staticSize); + } + + @Override + public JavaTypeProfile getTypeProfile(HotSpotMethodData data, int position) { + return createTypeProfile(getNullSeen(data, position), getRawTypeProfile(data, position)); + } + + private RawItemProfile getRawTypeProfile(HotSpotMethodData data, int position) { + int typeProfileWidth = config.typeProfileWidth; + + ResolvedJavaType[] types = new ResolvedJavaType[typeProfileWidth]; + long[] counts = new long[typeProfileWidth]; + long totalCount = 0; + int entries = 0; + + outer: for (int i = 0; i < typeProfileWidth; i++) { + long receiverKlass = data.readWord(position, getTypeOffset(i)); + if (receiverKlass != 0) { + HotSpotResolvedObjectTypeImpl klass = HotSpotResolvedObjectTypeImpl.fromMetaspaceKlass(receiverKlass); + long count = data.readUnsignedInt(position, getTypeCountOffset(i)); + /* + * Because of races in the profile collection machinery it's possible for a + * class to appear multiple times so merge them to make the profile look + * rational. + */ + for (int j = 0; j < entries; j++) { + if (types[j].equals(klass)) { + totalCount += count; + counts[j] += count; + continue outer; + } + } + types[entries] = klass; + totalCount += count; + counts[entries] = count; + entries++; + } + } + + totalCount += getTypesNotRecordedExecutionCount(data, position); + return new RawItemProfile<>(entries, types, counts, totalCount); + } + + protected abstract long getTypesNotRecordedExecutionCount(HotSpotMethodData data, int position); + + private static JavaTypeProfile createTypeProfile(TriState nullSeen, RawItemProfile profile) { + if (profile.entries <= 0 || profile.totalCount <= 0) { + return null; + } + + ProfiledType[] ptypes = new ProfiledType[profile.entries]; + double totalProbability = 0.0; + for (int i = 0; i < profile.entries; i++) { + double p = profile.counts[i]; + p = p / profile.totalCount; + totalProbability += p; + ptypes[i] = new ProfiledType(profile.items[i], p); + } + + Arrays.sort(ptypes); + + double notRecordedTypeProbability = profile.entries < config.typeProfileWidth ? 0.0 : Math.min(1.0, Math.max(0.0, 1.0 - totalProbability)); + assert notRecordedTypeProbability == 0 || profile.entries == config.typeProfileWidth; + return new JavaTypeProfile(nullSeen, notRecordedTypeProbability, ptypes); + } + + private static int getTypeOffset(int row) { + return TYPE_DATA_FIRST_TYPE_OFFSET + row * TYPE_DATA_ROW_SIZE; + } + + protected static int getTypeCountOffset(int row) { + return TYPE_DATA_FIRST_TYPE_COUNT_OFFSET + row * TYPE_DATA_ROW_SIZE; + } + + @Override + public StringBuilder appendTo(StringBuilder sb, HotSpotMethodData data, int pos) { + RawItemProfile profile = getRawTypeProfile(data, pos); + TriState nullSeen = getNullSeen(data, pos); + TriState exceptionSeen = getExceptionSeen(data, pos); + sb.append(format("count(%d) null_seen(%s) exception_seen(%s) nonprofiled_count(%d) entries(%d)", getCounterValue(data, pos), nullSeen, exceptionSeen, + getTypesNotRecordedExecutionCount(data, pos), profile.entries)); + for (int i = 0; i < profile.entries; i++) { + long count = profile.counts[i]; + sb.append(format("%n %s (%d, %4.2f)", profile.items[i].toJavaName(), count, (double) count / profile.totalCount)); + } + return sb; + } + } + + private static class TypeCheckData extends AbstractTypeData { + + private static final int TYPE_CHECK_DATA_SIZE = cellIndexToOffset(2) + TYPE_DATA_ROW_SIZE * config.typeProfileWidth; + + public TypeCheckData() { + super(Tag.ReceiverTypeData, TYPE_CHECK_DATA_SIZE); + } + + @Override + public int getExecutionCount(HotSpotMethodData data, int position) { + return -1; + } + + @Override + protected long getTypesNotRecordedExecutionCount(HotSpotMethodData data, int position) { + return data.readUnsignedIntAsSignedInt(position, NONPROFILED_COUNT_OFFSET); + } + } + + private static class VirtualCallData extends AbstractTypeData { + + private static final int VIRTUAL_CALL_DATA_SIZE = cellIndexToOffset(2) + TYPE_DATA_ROW_SIZE * (config.typeProfileWidth + config.methodProfileWidth); + private static final int VIRTUAL_CALL_DATA_FIRST_METHOD_OFFSET = TYPE_DATA_FIRST_TYPE_OFFSET + TYPE_DATA_ROW_SIZE * config.typeProfileWidth; + private static final int VIRTUAL_CALL_DATA_FIRST_METHOD_COUNT_OFFSET = TYPE_DATA_FIRST_TYPE_COUNT_OFFSET + TYPE_DATA_ROW_SIZE * config.typeProfileWidth; + + public VirtualCallData() { + super(Tag.VirtualCallData, VIRTUAL_CALL_DATA_SIZE); + } + + @Override + public int getExecutionCount(HotSpotMethodData data, int position) { + final int typeProfileWidth = config.typeProfileWidth; + + long total = 0; + for (int i = 0; i < typeProfileWidth; i++) { + total += data.readUnsignedInt(position, getTypeCountOffset(i)); + } + + total += getCounterValue(data, position); + return truncateLongToInt(total); + } + + @Override + protected long getTypesNotRecordedExecutionCount(HotSpotMethodData data, int position) { + return getCounterValue(data, position); + } + + private static long getMethodsNotRecordedExecutionCount(HotSpotMethodData data, int position) { + return data.readUnsignedIntAsSignedInt(position, NONPROFILED_COUNT_OFFSET); + } + + @Override + public JavaMethodProfile getMethodProfile(HotSpotMethodData data, int position) { + return createMethodProfile(getRawMethodProfile(data, position)); + } + + private static RawItemProfile getRawMethodProfile(HotSpotMethodData data, int position) { + int profileWidth = config.methodProfileWidth; + + ResolvedJavaMethod[] methods = new ResolvedJavaMethod[profileWidth]; + long[] counts = new long[profileWidth]; + long totalCount = 0; + int entries = 0; + + for (int i = 0; i < profileWidth; i++) { + long method = data.readWord(position, getMethodOffset(i)); + if (method != 0) { + methods[entries] = HotSpotResolvedJavaMethodImpl.fromMetaspace(method); + long count = data.readUnsignedInt(position, getMethodCountOffset(i)); + totalCount += count; + counts[entries] = count; + + entries++; + } + } + + totalCount += getMethodsNotRecordedExecutionCount(data, position); + return new RawItemProfile<>(entries, methods, counts, totalCount); + } + + private static JavaMethodProfile createMethodProfile(RawItemProfile profile) { + if (profile.entries <= 0 || profile.totalCount <= 0) { + return null; + } + + ProfiledMethod[] pmethods = new ProfiledMethod[profile.entries]; + double totalProbability = 0.0; + for (int i = 0; i < profile.entries; i++) { + double p = profile.counts[i]; + p = p / profile.totalCount; + totalProbability += p; + pmethods[i] = new ProfiledMethod(profile.items[i], p); + } + + Arrays.sort(pmethods); + + double notRecordedMethodProbability = profile.entries < config.methodProfileWidth ? 0.0 : Math.min(1.0, Math.max(0.0, 1.0 - totalProbability)); + assert notRecordedMethodProbability == 0 || profile.entries == config.methodProfileWidth; + return new JavaMethodProfile(notRecordedMethodProbability, pmethods); + } + + private static int getMethodOffset(int row) { + return VIRTUAL_CALL_DATA_FIRST_METHOD_OFFSET + row * TYPE_DATA_ROW_SIZE; + } + + private static int getMethodCountOffset(int row) { + return VIRTUAL_CALL_DATA_FIRST_METHOD_COUNT_OFFSET + row * TYPE_DATA_ROW_SIZE; + } + + @Override + public StringBuilder appendTo(StringBuilder sb, HotSpotMethodData data, int pos) { + RawItemProfile profile = getRawMethodProfile(data, pos); + super.appendTo(sb.append(format("exception_seen(%s) ", getExceptionSeen(data, pos))), data, pos).append(format("%nmethod_entries(%d)", profile.entries)); + for (int i = 0; i < profile.entries; i++) { + long count = profile.counts[i]; + sb.append(format("%n %s (%d, %4.2f)", profile.items[i].format("%H.%n(%p)"), count, (double) count / profile.totalCount)); + } + return sb; + } + } + + private static class RetData extends CounterData { + + private static final int RET_DATA_ROW_SIZE = cellsToBytes(3); + private static final int RET_DATA_SIZE = cellIndexToOffset(1) + RET_DATA_ROW_SIZE * config.bciProfileWidth; + + public RetData() { + super(Tag.RetData, RET_DATA_SIZE); + } + } + + private static class BranchData extends JumpData { + + private static final int BRANCH_DATA_SIZE = cellIndexToOffset(3); + private static final int NOT_TAKEN_COUNT_OFFSET = cellIndexToOffset(2); + + public BranchData() { + super(Tag.BranchData, BRANCH_DATA_SIZE); + } + + @Override + public double getBranchTakenProbability(HotSpotMethodData data, int position) { + long takenCount = data.readUnsignedInt(position, TAKEN_COUNT_OFFSET); + long notTakenCount = data.readUnsignedInt(position, NOT_TAKEN_COUNT_OFFSET); + long total = takenCount + notTakenCount; + + return total <= 0 ? -1 : takenCount / (double) total; + } + + @Override + public int getExecutionCount(HotSpotMethodData data, int position) { + long count = data.readUnsignedInt(position, TAKEN_COUNT_OFFSET) + data.readUnsignedInt(position, NOT_TAKEN_COUNT_OFFSET); + return truncateLongToInt(count); + } + + @Override + public StringBuilder appendTo(StringBuilder sb, HotSpotMethodData data, int pos) { + long taken = data.readUnsignedInt(pos, TAKEN_COUNT_OFFSET); + long notTaken = data.readUnsignedInt(pos, NOT_TAKEN_COUNT_OFFSET); + double takenProbability = getBranchTakenProbability(data, pos); + return sb.append(format("taken(%d, %4.2f) not_taken(%d, %4.2f) displacement(%d)", taken, takenProbability, notTaken, 1.0D - takenProbability, getTakenDisplacement(data, pos))); + } + } + + private static class ArrayData extends AbstractMethodData { + + private static final int ARRAY_DATA_LENGTH_OFFSET = cellIndexToOffset(0); + protected static final int ARRAY_DATA_START_OFFSET = cellIndexToOffset(1); + + public ArrayData(Tag tag, int staticSize) { + super(tag, staticSize); + } + + @Override + protected int getDynamicSize(HotSpotMethodData data, int position) { + return cellsToBytes(getLength(data, position)); + } + + protected static int getLength(HotSpotMethodData data, int position) { + return data.readInt(position, ARRAY_DATA_LENGTH_OFFSET); + } + + @Override + public StringBuilder appendTo(StringBuilder sb, HotSpotMethodData data, int pos) { + return sb.append(format("length(%d)", getLength(data, pos))); + } + } + + private static class MultiBranchData extends ArrayData { + + private static final int MULTI_BRANCH_DATA_SIZE = cellIndexToOffset(1); + private static final int MULTI_BRANCH_DATA_ROW_SIZE_IN_CELLS = 2; + private static final int MULTI_BRANCH_DATA_ROW_SIZE = cellsToBytes(MULTI_BRANCH_DATA_ROW_SIZE_IN_CELLS); + private static final int MULTI_BRANCH_DATA_FIRST_COUNT_OFFSET = ARRAY_DATA_START_OFFSET + cellsToBytes(0); + private static final int MULTI_BRANCH_DATA_FIRST_DISPLACEMENT_OFFSET = ARRAY_DATA_START_OFFSET + cellsToBytes(1); + + public MultiBranchData() { + super(Tag.MultiBranchData, MULTI_BRANCH_DATA_SIZE); + } + + @Override + public double[] getSwitchProbabilities(HotSpotMethodData data, int position) { + int arrayLength = getLength(data, position); + assert arrayLength > 0 : "switch must have at least the default case"; + assert arrayLength % MULTI_BRANCH_DATA_ROW_SIZE_IN_CELLS == 0 : "array must have full rows"; + + int length = arrayLength / MULTI_BRANCH_DATA_ROW_SIZE_IN_CELLS; + long totalCount = 0; + double[] result = new double[length]; + + // default case is first in HotSpot but last for the compiler + long count = readCount(data, position, 0); + totalCount += count; + result[length - 1] = count; + + for (int i = 1; i < length; i++) { + count = readCount(data, position, i); + totalCount += count; + result[i - 1] = count; + } + + if (totalCount <= 0) { + return null; + } else { + for (int i = 0; i < length; i++) { + result[i] = result[i] / totalCount; + } + return result; + } + } + + private static long readCount(HotSpotMethodData data, int position, int i) { + int offset; + long count; + offset = getCountOffset(i); + count = data.readUnsignedInt(position, offset); + return count; + } + + @Override + public int getExecutionCount(HotSpotMethodData data, int position) { + int arrayLength = getLength(data, position); + assert arrayLength > 0 : "switch must have at least the default case"; + assert arrayLength % MULTI_BRANCH_DATA_ROW_SIZE_IN_CELLS == 0 : "array must have full rows"; + + int length = arrayLength / MULTI_BRANCH_DATA_ROW_SIZE_IN_CELLS; + long totalCount = 0; + for (int i = 0; i < length; i++) { + int offset = getCountOffset(i); + totalCount += data.readUnsignedInt(position, offset); + } + + return truncateLongToInt(totalCount); + } + + private static int getCountOffset(int index) { + return MULTI_BRANCH_DATA_FIRST_COUNT_OFFSET + index * MULTI_BRANCH_DATA_ROW_SIZE; + } + + private static int getDisplacementOffset(int index) { + return MULTI_BRANCH_DATA_FIRST_DISPLACEMENT_OFFSET + index * MULTI_BRANCH_DATA_ROW_SIZE; + } + + @Override + public StringBuilder appendTo(StringBuilder sb, HotSpotMethodData data, int pos) { + int entries = getLength(data, pos) / MULTI_BRANCH_DATA_ROW_SIZE_IN_CELLS; + sb.append(format("entries(%d)", entries)); + for (int i = 0; i < entries; i++) { + sb.append(format("%n %d: count(%d) displacement(%d)", i, data.readUnsignedInt(pos, getCountOffset(i)), data.readUnsignedInt(pos, getDisplacementOffset(i)))); + } + return sb; + } + } + + private static class ArgInfoData extends ArrayData { + + private static final int ARG_INFO_DATA_SIZE = cellIndexToOffset(1); + + public ArgInfoData() { + super(Tag.ArgInfoData, ARG_INFO_DATA_SIZE); + } + } + + public void setCompiledIRSize(int size) { + unsafe.putInt(metaspaceMethodData + config.methodDataIRSizeOffset, size); + } + + public int getCompiledIRSize() { + return unsafe.getInt(metaspaceMethodData + config.methodDataIRSizeOffset); + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotMethodDataAccessor.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotMethodDataAccessor.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,112 @@ +/* + * Copyright (c) 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 static com.oracle.jvmci.hotspot.HotSpotJVMCIRuntime.*; + +import com.oracle.jvmci.meta.*; + +/** + * Interface for accessor objects that encapsulate the logic for accessing the different kinds of + * data in a HotSpot methodDataOop. This interface is similar to the interface {@link ProfilingInfo} + * , but most methods require a MethodDataObject and the exact position within the methodData. + */ +public interface HotSpotMethodDataAccessor { + + /** + * {@code DataLayout} tag values. + */ + enum Tag { + No(config().dataLayoutNoTag), + BitData(config().dataLayoutBitDataTag), + CounterData(config().dataLayoutCounterDataTag), + JumpData(config().dataLayoutJumpDataTag), + ReceiverTypeData(config().dataLayoutReceiverTypeDataTag), + VirtualCallData(config().dataLayoutVirtualCallDataTag), + RetData(config().dataLayoutRetDataTag), + BranchData(config().dataLayoutBranchDataTag), + MultiBranchData(config().dataLayoutMultiBranchDataTag), + ArgInfoData(config().dataLayoutArgInfoDataTag), + CallTypeData(config().dataLayoutCallTypeDataTag), + VirtualCallTypeData(config().dataLayoutVirtualCallTypeDataTag), + ParametersTypeData(config().dataLayoutParametersTypeDataTag), + SpeculativeTrapData(config().dataLayoutSpeculativeTrapDataTag); + + private final int value; + + private Tag(int value) { + this.value = value; + } + + public int getValue() { + return value; + } + + private static HotSpotVMConfig config() { + return runtime().getConfig(); + } + + public static Tag getEnum(int value) { + Tag result = values()[value]; + assert value == result.value; + return result; + } + } + + /** + * Returns the {@link Tag} stored in the LayoutData header. + * + * @return tag stored in the LayoutData header + */ + Tag getTag(); + + /** + * Returns the BCI stored in the LayoutData header. + * + * @return An integer ≥ 0 and ≤ Short.MAX_VALUE, or -1 if not supported. + */ + int getBCI(HotSpotMethodData data, int position); + + /** + * Computes the size for the specific data at the given position. + * + * @return An integer > 0. + */ + int getSize(HotSpotMethodData data, int position); + + JavaTypeProfile getTypeProfile(HotSpotMethodData data, int position); + + JavaMethodProfile getMethodProfile(HotSpotMethodData data, int position); + + double getBranchTakenProbability(HotSpotMethodData data, int position); + + double[] getSwitchProbabilities(HotSpotMethodData data, int position); + + TriState getExceptionSeen(HotSpotMethodData data, int position); + + TriState getNullSeen(HotSpotMethodData data, int position); + + int getExecutionCount(HotSpotMethodData data, int position); + + StringBuilder appendTo(StringBuilder sb, HotSpotMethodData data, int pos); +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotMethodHandleAccessProvider.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotMethodHandleAccessProvider.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,162 @@ +/* + * 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.hotspot; + +import static com.oracle.jvmci.hotspot.HotSpotJVMCIRuntime.*; +import static com.oracle.jvmci.hotspot.HotSpotResolvedJavaType.*; +import static com.oracle.jvmci.hotspot.HotSpotResolvedObjectTypeImpl.*; + +import com.oracle.jvmci.common.*; +import com.oracle.jvmci.meta.*; + +public class HotSpotMethodHandleAccessProvider implements MethodHandleAccessProvider, HotSpotProxified { + + private final ConstantReflectionProvider constantReflection; + + public HotSpotMethodHandleAccessProvider(ConstantReflectionProvider constantReflection) { + this.constantReflection = constantReflection; + } + + /** + * Lazy initialization to break class initialization cycle. Field and method lookup is only + * possible after the {@link HotSpotJVMCIRuntime} is fully initialized. + */ + static class LazyInitialization { + static final ResolvedJavaField methodHandleFormField; + static final ResolvedJavaField lambdaFormVmentryField; + static final ResolvedJavaMethod lambdaFormCompileToBytecodeMethod; + static final ResolvedJavaField memberNameVmtargetField; + + /** + * Search for an instance field with the given name in a class. + * + * @param className name of the class to search in + * @param fieldName name of the field to be searched + * @return resolved java field + * @throws ClassNotFoundException + */ + private static ResolvedJavaField findFieldInClass(String className, String fieldName) throws ClassNotFoundException { + Class clazz = Class.forName(className); + ResolvedJavaType type = fromClass(clazz); + ResolvedJavaField[] fields = type.getInstanceFields(false); + for (ResolvedJavaField field : fields) { + if (field.getName().equals(fieldName)) { + return field; + } + } + return null; + } + + private static ResolvedJavaMethod findMethodInClass(String className, String methodName) throws ClassNotFoundException { + Class clazz = Class.forName(className); + HotSpotResolvedObjectTypeImpl type = fromObjectClass(clazz); + ResolvedJavaMethod result = null; + for (ResolvedJavaMethod method : type.getDeclaredMethods()) { + if (method.getName().equals(methodName)) { + assert result == null : "more than one method found: " + className + "." + methodName; + result = method; + } + } + assert result != null : "method not found: " + className + "." + methodName; + return result; + } + + static { + try { + methodHandleFormField = findFieldInClass("java.lang.invoke.MethodHandle", "form"); + lambdaFormVmentryField = findFieldInClass("java.lang.invoke.LambdaForm", "vmentry"); + lambdaFormCompileToBytecodeMethod = findMethodInClass("java.lang.invoke.LambdaForm", "compileToBytecode"); + memberNameVmtargetField = findFieldInClass("java.lang.invoke.MemberName", "vmtarget"); + } catch (Throwable ex) { + throw new JVMCIError(ex); + } + } + } + + @Override + public IntrinsicMethod lookupMethodHandleIntrinsic(ResolvedJavaMethod method) { + int intrinsicId = ((HotSpotResolvedJavaMethodImpl) method).intrinsicId(); + if (intrinsicId != 0) { + return getMethodHandleIntrinsic(intrinsicId); + } + return null; + } + + public static IntrinsicMethod getMethodHandleIntrinsic(int intrinsicId) { + HotSpotVMConfig config = runtime().getConfig(); + if (intrinsicId == config.vmIntrinsicInvokeBasic) { + return IntrinsicMethod.INVOKE_BASIC; + } else if (intrinsicId == config.vmIntrinsicLinkToInterface) { + return IntrinsicMethod.LINK_TO_INTERFACE; + } else if (intrinsicId == config.vmIntrinsicLinkToSpecial) { + return IntrinsicMethod.LINK_TO_SPECIAL; + } else if (intrinsicId == config.vmIntrinsicLinkToStatic) { + return IntrinsicMethod.LINK_TO_STATIC; + } else if (intrinsicId == config.vmIntrinsicLinkToVirtual) { + return IntrinsicMethod.LINK_TO_VIRTUAL; + } + return null; + } + + @Override + public ResolvedJavaMethod resolveInvokeBasicTarget(JavaConstant methodHandle, boolean forceBytecodeGeneration) { + if (methodHandle.isNull()) { + return null; + } + + /* Load non-public field: LambdaForm MethodHandle.form */ + JavaConstant lambdaForm = constantReflection.readFieldValue(LazyInitialization.methodHandleFormField, methodHandle); + if (lambdaForm.isNull()) { + return null; + } + + JavaConstant memberName; + if (forceBytecodeGeneration) { + /* Invoke non-public method: MemberName LambdaForm.compileToBytecode() */ + memberName = LazyInitialization.lambdaFormCompileToBytecodeMethod.invoke(lambdaForm, new JavaConstant[0]); + } else { + /* Load non-public field: MemberName LambdaForm.vmentry */ + memberName = constantReflection.readFieldValue(LazyInitialization.lambdaFormVmentryField, lambdaForm); + } + return getTargetMethod(memberName); + } + + @Override + public ResolvedJavaMethod resolveLinkToTarget(JavaConstant memberName) { + return getTargetMethod(memberName); + } + + /** + * Returns the {@link ResolvedJavaMethod} for the vmtarget of a java.lang.invoke.MemberName. + */ + private ResolvedJavaMethod getTargetMethod(JavaConstant memberName) { + if (memberName.isNull()) { + return null; + } + + /* Load injected field: JVM_Method* MemberName.vmtarget */ + JavaConstant vmtarget = constantReflection.readFieldValue(LazyInitialization.memberNameVmtargetField, memberName); + /* Create a method from the vmtarget method pointer. */ + return HotSpotResolvedJavaMethodImpl.fromMetaspace(vmtarget.asLong()); + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotMethodUnresolved.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotMethodUnresolved.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2011, 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; + +import com.oracle.jvmci.meta.*; + +/** + * Implementation of {@link JavaMethod} for unresolved HotSpot methods. + */ +public final class HotSpotMethodUnresolved extends HotSpotMethod { + + private final Signature signature; + protected JavaType holder; + + public HotSpotMethodUnresolved(String name, Signature signature, JavaType holder) { + super(name); + this.holder = holder; + this.signature = signature; + } + + @Override + public Signature getSignature() { + return signature; + } + + @Override + public JavaType getDeclaringClass() { + return holder; + } + + @Override + public int hashCode() { + return super.hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null || !(obj instanceof HotSpotMethodUnresolved)) { + return false; + } + HotSpotMethodUnresolved that = (HotSpotMethodUnresolved) obj; + return this.name.equals(that.name) && this.signature.equals(that.signature) && this.holder.equals(that.holder); + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotNmethod.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotNmethod.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,116 @@ +/* + * Copyright (c) 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 static com.oracle.jvmci.hotspot.HotSpotJVMCIRuntime.*; + +import com.oracle.jvmci.code.*; +import com.oracle.jvmci.meta.*; + +/** + * Implementation of {@link InstalledCode} for code installed as an nmethod. The nmethod stores a + * weak reference to an instance of this class. This is necessary to keep the nmethod from being + * unloaded while the associated {@link HotSpotNmethod} instance is alive. + *

      + * Note that there is no (current) way for the reference from an nmethod to a {@link HotSpotNmethod} + * instance to be anything but weak. This is due to the fact that HotSpot does not treat nmethods as + * strong GC roots. + */ +public class HotSpotNmethod extends HotSpotInstalledCode { + + /** + * This (indirect) Method* reference is safe since class redefinition preserves all methods + * associated with nmethods in the code cache. + */ + private final HotSpotResolvedJavaMethod method; + + private final boolean isDefault; + private final boolean isExternal; + + public HotSpotNmethod(HotSpotResolvedJavaMethod method, String name, boolean isDefault) { + this(method, name, isDefault, false); + } + + public HotSpotNmethod(HotSpotResolvedJavaMethod method, String name, boolean isDefault, boolean isExternal) { + super(name); + this.method = method; + this.isDefault = isDefault; + this.isExternal = isExternal; + } + + public boolean isDefault() { + return isDefault; + } + + public boolean isExternal() { + return isExternal; + } + + public ResolvedJavaMethod getMethod() { + return method; + } + + @Override + public void invalidate() { + runtime().getCompilerToVM().invalidateInstalledCode(this); + } + + @Override + public String toString() { + return String.format("InstalledNmethod[method=%s, codeBlob=0x%x, isDefault=%b, name=%s]", method, getAddress(), isDefault, name); + } + + protected boolean checkThreeObjectArgs() { + assert method.getSignature().getParameterCount(!method.isStatic()) == 3; + assert method.getSignature().getParameterKind(0) == Kind.Object; + assert method.getSignature().getParameterKind(1) == Kind.Object; + assert !method.isStatic() || method.getSignature().getParameterKind(2) == Kind.Object; + return true; + } + + private boolean checkArgs(Object... args) { + JavaType[] sig = method.toParameterTypes(); + assert args.length == sig.length : method.format("%H.%n(%p): expected ") + sig.length + " args, got " + args.length; + for (int i = 0; i < sig.length; i++) { + Object arg = args[i]; + if (arg == null) { + assert sig[i].getKind() == Kind.Object : method.format("%H.%n(%p): expected arg ") + i + " to be Object, not " + sig[i]; + } else if (sig[i].getKind() != Kind.Object) { + assert sig[i].getKind().toBoxedJavaClass() == arg.getClass() : method.format("%H.%n(%p): expected arg ") + i + " to be " + sig[i] + ", not " + arg.getClass(); + } + } + return true; + } + + @Override + public Object executeVarargs(Object... args) throws InvalidInstalledCodeException { + assert checkArgs(args); + assert !isExternal(); + return runtime().getCompilerToVM().executeCompiledMethodVarargs(args, this); + } + + @Override + public long getStart() { + return isValid() ? super.getStart() : 0; + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotObjectConstant.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotObjectConstant.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2009, 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; + +import java.lang.invoke.*; +import java.util.*; + +import com.oracle.jvmci.meta.*; + +/** + * Represents a constant non-{@code null} object reference, within the compiler and across the + * compiler/runtime interface. + */ +public interface HotSpotObjectConstant extends JavaConstant, HotSpotConstant, VMConstant { + + JavaConstant compress(); + + JavaConstant uncompress(); + + /** + * Gets the resolved Java type of the object represented by this constant. + */ + HotSpotResolvedObjectType getType(); + + /** + * Gets the result of {@link Class#getClassLoader()} for the {@link Class} object represented by + * this constant. + * + * @return {@code null} if this constant does not represent a {@link Class} object + */ + JavaConstant getClassLoader(); + + /** + * Gets the {@linkplain System#identityHashCode(Object) identity} has code for the object + * represented by this constant. + */ + int getIdentityHashCode(); + + /** + * Gets the result of {@link Class#getComponentType()} for the {@link Class} object represented + * by this constant. + * + * @return {@code null} if this constant does not represent a {@link Class} object + */ + JavaConstant getComponentType(); + + /** + * Gets the result of {@link Class#getSuperclass()} for the {@link Class} object represented by + * this constant. + * + * @return {@code null} if this constant does not represent a {@link Class} object + */ + JavaConstant getSuperclass(); + + /** + * Gets the result of {@link CallSite#getTarget()} for the {@link CallSite} object represented + * by this constant. + * + * @param assumptions used to register an assumption that the {@link CallSite}'s target does not + * change + * @return {@code null} if this constant does not represent a {@link CallSite} object + */ + JavaConstant getCallSiteTarget(Assumptions assumptions); + + /** + * Determines if this constant represents an {@linkplain String#intern() interned} string. + */ + boolean isInternedString(); + + /** + * Gets the object represented by this constant represents if it is of a given type. + * + * @param type the expected type of the object represented by this constant. If the object is + * required to be of this type, then wrap the call to this method in + * {@link Objects#requireNonNull(Object)}. + * @return the object value represented by this constant if it is an + * {@link ResolvedJavaType#isInstance(JavaConstant) instance of} {@code type} otherwise + * {@code null} + */ + T asObject(Class type); + + /** + * Gets the object represented by this constant represents if it is of a given type. + * + * @param type the expected type of the object represented by this constant. If the object is + * required to be of this type, then wrap the call to this method in + * {@link Objects#requireNonNull(Object)}. + * @return the object value represented by this constant if it is an + * {@link ResolvedJavaType#isInstance(JavaConstant) instance of} {@code type} otherwise + * {@code null} + */ + Object asObject(ResolvedJavaType type); +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotObjectConstantImpl.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotObjectConstantImpl.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,290 @@ +/* + * Copyright (c) 2009, 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 static com.oracle.jvmci.hotspot.HotSpotResolvedObjectTypeImpl.*; + +import java.lang.invoke.*; + +import com.oracle.jvmci.meta.*; + +import edu.umd.cs.findbugs.annotations.*; + +/** + * Represents a constant non-{@code null} object reference, within the compiler and across the + * compiler/runtime interface. + */ +public final class HotSpotObjectConstantImpl extends AbstractValue implements HotSpotObjectConstant, HotSpotProxified { + + public static JavaConstant forObject(Object object) { + return forObject(object, false); + } + + static JavaConstant forObject(Object object, boolean compressed) { + if (object == null) { + return compressed ? HotSpotCompressedNullConstant.COMPRESSED_NULL : JavaConstant.NULL_POINTER; + } else { + return new HotSpotObjectConstantImpl(object, compressed); + } + } + + static JavaConstant forStableArray(Object object, int stableDimension, boolean isDefaultStable) { + if (object == null) { + return JavaConstant.NULL_POINTER; + } else { + assert object.getClass().isArray(); + return new HotSpotObjectConstantImpl(object, false, stableDimension, isDefaultStable); + } + } + + public static JavaConstant forBoxedValue(Kind kind, Object value) { + if (kind == Kind.Object) { + return HotSpotObjectConstantImpl.forObject(value); + } else { + return JavaConstant.forBoxedPrimitive(value); + } + } + + static Object asBoxedValue(Constant constant) { + if (JavaConstant.isNull(constant)) { + return null; + } else if (constant instanceof HotSpotObjectConstantImpl) { + return ((HotSpotObjectConstantImpl) constant).object; + } else { + return ((JavaConstant) constant).asBoxedPrimitive(); + } + } + + private final Object object; + private final boolean compressed; + private final byte stableDimension; + private final boolean isDefaultStable; + + private HotSpotObjectConstantImpl(Object object, boolean compressed, int stableDimension, boolean isDefaultStable) { + super(LIRKind.reference(compressed ? Kind.Int : Kind.Object)); + this.object = object; + this.compressed = compressed; + this.stableDimension = (byte) stableDimension; + this.isDefaultStable = isDefaultStable; + assert object != null; + assert stableDimension == 0 || (object != null && object.getClass().isArray()); + assert stableDimension >= 0 && stableDimension <= 255; + assert !isDefaultStable || stableDimension > 0; + } + + private HotSpotObjectConstantImpl(Object object, boolean compressed) { + this(object, compressed, 0, false); + } + + /** + * Package-private accessor for the object represented by this constant. + */ + Object object() { + return object; + } + + /** + * Determines if the object represented by this constant is {@link Object#equals(Object) equal} + * to a given object. + */ + public boolean isEqualTo(Object obj) { + return object.equals(obj); + } + + /** + * Gets the class of the object represented by this constant. + */ + public Class getObjectClass() { + return object.getClass(); + } + + public boolean isCompressed() { + return compressed; + } + + public JavaConstant compress() { + assert !compressed; + return new HotSpotObjectConstantImpl(object, true, stableDimension, isDefaultStable); + } + + public JavaConstant uncompress() { + assert compressed; + return new HotSpotObjectConstantImpl(object, false, stableDimension, isDefaultStable); + } + + public HotSpotResolvedObjectType getType() { + return fromObjectClass(object.getClass()); + } + + public JavaConstant getClassLoader() { + if (object instanceof Class) { + /* + * This is an intrinsic for getClassLoader0, which occurs after any security checks. We + * can't call that directly so just call getClassLoader. + */ + return HotSpotObjectConstantImpl.forObject(((Class) object).getClassLoader()); + } + return null; + } + + public int getIdentityHashCode() { + return System.identityHashCode(object); + } + + public JavaConstant getComponentType() { + if (object instanceof Class) { + return HotSpotObjectConstantImpl.forObject(((Class) object).getComponentType()); + } + return null; + } + + public JavaConstant getSuperclass() { + if (object instanceof Class) { + return HotSpotObjectConstantImpl.forObject(((Class) object).getSuperclass()); + } + return null; + } + + public JavaConstant getCallSiteTarget(Assumptions assumptions) { + if (object instanceof CallSite) { + CallSite callSite = (CallSite) object; + MethodHandle target = callSite.getTarget(); + if (!(callSite instanceof ConstantCallSite)) { + if (assumptions == null) { + return null; + } + assumptions.record(new Assumptions.CallSiteTargetValue(callSite, target)); + } + return HotSpotObjectConstantImpl.forObject(target); + } + return null; + } + + @SuppressFBWarnings(value = "ES_COMPARING_STRINGS_WITH_EQ", justification = "reference equality is what we want") + public boolean isInternedString() { + if (object instanceof String) { + String s = (String) object; + return s.intern() == s; + } + return false; + } + + public T asObject(Class type) { + if (type.isInstance(object)) { + return type.cast(object); + } + return null; + } + + public Object asObject(ResolvedJavaType type) { + if (type.isInstance(this)) { + return object; + } + return null; + } + + @Override + public boolean isNull() { + return false; + } + + @Override + public boolean isDefaultForKind() { + return false; + } + + @Override + public Object asBoxedPrimitive() { + throw new IllegalArgumentException(); + } + + @Override + public int asInt() { + throw new IllegalArgumentException(); + } + + @Override + public boolean asBoolean() { + throw new IllegalArgumentException(); + } + + @Override + public long asLong() { + throw new IllegalArgumentException(); + } + + @Override + public float asFloat() { + throw new IllegalArgumentException(); + } + + @Override + public double asDouble() { + throw new IllegalArgumentException(); + } + + @Override + public int hashCode() { + return System.identityHashCode(object); + } + + @Override + public boolean equals(Object o) { + if (o == this) { + return true; + } else if (o instanceof HotSpotObjectConstantImpl) { + HotSpotObjectConstantImpl other = (HotSpotObjectConstantImpl) o; + return super.equals(o) && object == other.object && compressed == other.compressed && stableDimension == other.stableDimension && isDefaultStable == other.isDefaultStable; + } + return false; + } + + @Override + public String toValueString() { + if (object instanceof String) { + return (String) object; + } else { + return Kind.Object.format(object); + } + } + + @Override + public String toString() { + return (compressed ? "NarrowOop" : getKind().getJavaName()) + "[" + Kind.Object.format(object) + "]"; + } + + /** + * Number of stable dimensions if this constant is a stable array. + */ + public int getStableDimension() { + return stableDimension & 0xff; + } + + /** + * Returns {@code true} if this is a stable array constant and its elements should be considered + * as stable regardless of whether they are default values. + */ + public boolean isDefaultStable() { + return isDefaultStable; + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotOptions.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotOptions.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,55 @@ +/* + * Copyright (c) 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.util.*; + +import com.oracle.jvmci.options.*; + +//JaCoCo Exclude + +/** + * Sets JVMCI options from the HotSpot command line. Such options are distinguished by the + * {@link #JVMCI_OPTION_PREFIX} prefix. + */ +public class HotSpotOptions { + + private static final String JVMCI_OPTION_PREFIX = "-G:"; + + /** + * Called from VM. + */ + static void printFlags() { + SortedMap options = new TreeMap<>(); + + for (Options opts : ServiceLoader.load(Options.class, HotSpotOptions.class.getClassLoader())) { + for (OptionDescriptor desc : opts) { + String name = desc.getName(); + OptionDescriptor existing = options.put(name, desc); + assert existing == null : "Option named \"" + name + "\" has multiple definitions: " + existing.getLocation() + " and " + desc.getLocation(); + } + } + + OptionUtils.printFlags(options, JVMCI_OPTION_PREFIX); + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotProfilingInfo.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotProfilingInfo.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,237 @@ +/* + * 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.hotspot; + +import com.oracle.jvmci.debug.*; +import com.oracle.jvmci.meta.*; + +public final class HotSpotProfilingInfo implements ProfilingInfo, HotSpotProxified { + + private static final DebugMetric metricInsufficentSpace = Debug.metric("InsufficientSpaceForProfilingData"); + + private final HotSpotMethodData methodData; + private final HotSpotResolvedJavaMethod method; + + private boolean isMature; + private int position; + private int hintPosition; + private int hintBCI; + private HotSpotMethodDataAccessor dataAccessor; + + private boolean includeNormal; + private boolean includeOSR; + + public HotSpotProfilingInfo(HotSpotMethodData methodData, HotSpotResolvedJavaMethod method, boolean includeNormal, boolean includeOSR) { + this.methodData = methodData; + this.method = method; + this.includeNormal = includeNormal; + this.includeOSR = includeOSR; + this.isMature = methodData.isProfileMature(); + hintPosition = 0; + hintBCI = -1; + } + + @Override + public int getCodeSize() { + return method.getCodeSize(); + } + + @Override + public JavaTypeProfile getTypeProfile(int bci) { + if (!isMature) { + return null; + } + findBCI(bci, false); + return dataAccessor.getTypeProfile(methodData, position); + } + + @Override + public JavaMethodProfile getMethodProfile(int bci) { + if (!isMature) { + return null; + } + findBCI(bci, false); + return dataAccessor.getMethodProfile(methodData, position); + } + + @Override + public double getBranchTakenProbability(int bci) { + if (!isMature) { + return -1; + } + findBCI(bci, false); + return dataAccessor.getBranchTakenProbability(methodData, position); + } + + @Override + public double[] getSwitchProbabilities(int bci) { + if (!isMature) { + return null; + } + findBCI(bci, false); + return dataAccessor.getSwitchProbabilities(methodData, position); + } + + @Override + public TriState getExceptionSeen(int bci) { + findBCI(bci, true); + return dataAccessor.getExceptionSeen(methodData, position); + } + + @Override + public TriState getNullSeen(int bci) { + findBCI(bci, false); + return dataAccessor.getNullSeen(methodData, position); + } + + @Override + public int getExecutionCount(int bci) { + if (!isMature) { + return -1; + } + findBCI(bci, false); + return dataAccessor.getExecutionCount(methodData, position); + } + + @Override + public int getDeoptimizationCount(DeoptimizationReason reason) { + int count = 0; + if (includeNormal) { + count += methodData.getDeoptimizationCount(reason); + } + if (includeOSR) { + count += methodData.getOSRDeoptimizationCount(reason); + } + return count; + } + + private void findBCI(int targetBCI, boolean searchExtraData) { + assert targetBCI >= 0 : "invalid BCI"; + + if (methodData.hasNormalData()) { + int currentPosition = targetBCI < hintBCI ? 0 : hintPosition; + HotSpotMethodDataAccessor currentAccessor; + while ((currentAccessor = methodData.getNormalData(currentPosition)) != null) { + int currentBCI = currentAccessor.getBCI(methodData, currentPosition); + if (currentBCI == targetBCI) { + normalDataFound(currentAccessor, currentPosition, currentBCI); + return; + } else if (currentBCI > targetBCI) { + break; + } + currentPosition = currentPosition + currentAccessor.getSize(methodData, currentPosition); + } + } + + boolean exceptionPossiblyNotRecorded = false; + if (searchExtraData && methodData.hasExtraData()) { + int currentPosition = methodData.getExtraDataBeginOffset(); + HotSpotMethodDataAccessor currentAccessor; + while ((currentAccessor = methodData.getExtraData(currentPosition)) != null) { + int currentBCI = currentAccessor.getBCI(methodData, currentPosition); + if (currentBCI == targetBCI) { + extraDataFound(currentAccessor, currentPosition); + return; + } + currentPosition = currentPosition + currentAccessor.getSize(methodData, currentPosition); + } + + if (!methodData.isWithin(currentPosition)) { + exceptionPossiblyNotRecorded = true; + metricInsufficentSpace.increment(); + } + } + + noDataFound(exceptionPossiblyNotRecorded); + } + + private void normalDataFound(HotSpotMethodDataAccessor data, int pos, int bci) { + setCurrentData(data, pos); + this.hintPosition = position; + this.hintBCI = bci; + } + + private void extraDataFound(HotSpotMethodDataAccessor data, int pos) { + setCurrentData(data, pos); + } + + private void noDataFound(boolean exceptionPossiblyNotRecorded) { + HotSpotMethodDataAccessor accessor = HotSpotMethodData.getNoDataAccessor(exceptionPossiblyNotRecorded); + setCurrentData(accessor, -1); + } + + private void setCurrentData(HotSpotMethodDataAccessor dataAccessor, int position) { + this.dataAccessor = dataAccessor; + this.position = position; + } + + @Override + public boolean isMature() { + return isMature; + } + + public void ignoreMature() { + isMature = true; + } + + @Override + public String toString() { + return "HotSpotProfilingInfo<" + this.toString(null, "; ") + ">"; + } + + @Override + public void setMature() { + isMature = true; + } + + /** + * {@code MethodData::_jvmci_ir_size} (currently) supports at most one JVMCI compiler IR type + * which will be determined by the first JVMCI compiler that calls + * {@link #setCompilerIRSize(Class, int)}. + */ + private static volatile Class supportedCompilerIRType; + + @Override + public boolean setCompilerIRSize(Class irType, int size) { + if (supportedCompilerIRType == null) { + synchronized (HotSpotProfilingInfo.class) { + if (supportedCompilerIRType == null) { + supportedCompilerIRType = irType; + } + } + } + if (supportedCompilerIRType != irType) { + return false; + } + methodData.setCompiledIRSize(size); + return true; + } + + @Override + public int getCompilerIRSize(Class irType) { + if (irType == supportedCompilerIRType) { + return methodData.getCompiledIRSize(); + } + return -1; + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotProxified.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotProxified.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,29 @@ +/* + * 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; + +/** + * Marker interface for classes whose values are proxied during replay compilation capture. + */ +public interface HotSpotProxified { +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotReferenceMap.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotReferenceMap.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2009, 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 static com.oracle.jvmci.code.ValueUtil.*; + +import java.util.*; + +import com.oracle.jvmci.code.*; +import com.oracle.jvmci.meta.*; + +public final class HotSpotReferenceMap extends ReferenceMap { + + private Value[] objects; + private int[] bytesPerElement; + private int maxRegisterSize; + private ArrayList objectValues; + + private final TargetDescription target; + + public HotSpotReferenceMap(TargetDescription target) { + this.target = target; + this.objects = Value.NO_VALUES; + } + + @Override + public void reset() { + objectValues = new ArrayList<>(); + objects = Value.NO_VALUES; + bytesPerElement = null; + maxRegisterSize = 0; + } + + @Override + public void addLiveValue(Value v) { + if (isConstant(v)) { + return; + } + LIRKind lirKind = v.getLIRKind(); + if (!lirKind.isValue()) { + objectValues.add(v); + } + if (isRegister(v)) { + int size = target.getSizeInBytes(lirKind.getPlatformKind()); + if (size > maxRegisterSize) { + maxRegisterSize = size; + } + } + } + + @Override + public void finish() { + objects = objectValues.toArray(new Value[objectValues.size()]); + this.bytesPerElement = new int[objects.length]; + for (int i = 0; i < objects.length; i++) { + bytesPerElement[i] = bytesPerElement(objects[i].getLIRKind()); + } + objectValues = null; + } + + private int bytesPerElement(LIRKind kind) { + PlatformKind platformKind = kind.getPlatformKind(); + return target.getSizeInBytes(platformKind) / platformKind.getVectorLength(); + } + + @Override + public int hashCode() { + throw new UnsupportedOperationException(); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof HotSpotReferenceMap) { + HotSpotReferenceMap that = (HotSpotReferenceMap) obj; + if (Arrays.equals(objects, that.objects) && this.target.equals(that.target)) { + return true; + } + } + return false; + } + + @Override + public String toString() { + return Arrays.toString(objects); + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotResolvedJavaField.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotResolvedJavaField.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2011, 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.meta.*; + +/** + * Represents a field in a HotSpot type. + */ +public interface HotSpotResolvedJavaField extends ResolvedJavaField { + + /** + * Determines if a given object contains this field. + * + * @return true iff this is a non-static field and its declaring class is assignable from + * {@code object}'s class + */ + boolean isInObject(Object object); + + int offset(); + + /** + * Checks if this field has the {@link Stable} annotation. + * + * @return true if field has {@link Stable} annotation, false otherwise + */ + boolean isStable(); +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotResolvedJavaFieldImpl.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotResolvedJavaFieldImpl.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,289 @@ +/* + * Copyright (c) 2011, 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 static com.oracle.jvmci.hotspot.HotSpotJVMCIRuntime.*; +import static com.oracle.jvmci.hotspot.HotSpotResolvedJavaFieldImpl.Options.*; +import static com.oracle.jvmci.hotspot.HotSpotResolvedObjectTypeImpl.*; + +import java.lang.annotation.*; +import java.lang.reflect.*; + +import com.oracle.jvmci.common.*; +import com.oracle.jvmci.meta.*; +import com.oracle.jvmci.options.*; + +/** + * Represents a field in a HotSpot type. + */ +public class HotSpotResolvedJavaFieldImpl implements HotSpotResolvedJavaField, HotSpotProxified { + + static class Options { + //@formatter:off + @Option(help = "Mark well-known stable fields as such.", type = OptionType.Debug) + public static final OptionValue ImplicitStableValues = new OptionValue<>(true); + //@formatter:on + } + + private final HotSpotResolvedObjectTypeImpl holder; + private final String name; + private JavaType type; + private final int offset; + + /** + * This value contains all flags as stored in the VM including internal ones. + */ + private final int modifiers; + private final LocationIdentity locationIdentity = new FieldLocationIdentity(this); + + public static class FieldLocationIdentity extends LocationIdentity { + HotSpotResolvedJavaField inner; + + public FieldLocationIdentity(HotSpotResolvedJavaFieldImpl inner) { + this.inner = inner; + } + + @Override + public boolean isImmutable() { + return false; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof FieldLocationIdentity) { + FieldLocationIdentity fieldLocationIdentity = (FieldLocationIdentity) obj; + return inner.equals(fieldLocationIdentity.inner); + + } + return false; + } + + @Override + public int hashCode() { + return inner.hashCode(); + } + + @Override + public String toString() { + return inner.getName(); + } + } + + public HotSpotResolvedJavaFieldImpl(HotSpotResolvedObjectTypeImpl holder, String name, JavaType type, long offset, int modifiers) { + this.holder = holder; + this.name = name; + this.type = type; + assert offset != -1; + assert offset == (int) offset : "offset larger than int"; + this.offset = (int) offset; + this.modifiers = modifiers; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof HotSpotResolvedJavaField) { + HotSpotResolvedJavaFieldImpl that = (HotSpotResolvedJavaFieldImpl) obj; + if (that.offset != this.offset || that.isStatic() != this.isStatic()) { + return false; + } else if (this.holder.equals(that.holder)) { + assert this.name.equals(that.name) && this.type.equals(that.type); + return true; + } + } + return false; + } + + @Override + public int hashCode() { + return name.hashCode(); + } + + @Override + public int getModifiers() { + return modifiers & getReflectionFieldModifiers(); + } + + @Override + public boolean isInternal() { + return (modifiers & runtime().getConfig().jvmAccFieldInternal) != 0; + } + + /** + * Determines if a given object contains this field. + * + * @return true iff this is a non-static field and its declaring class is assignable from + * {@code object}'s class + */ + public boolean isInObject(Object object) { + if (isStatic()) { + return false; + } + return getDeclaringClass().isAssignableFrom(HotSpotResolvedObjectTypeImpl.fromObjectClass(object.getClass())); + } + + @Override + public HotSpotResolvedObjectTypeImpl getDeclaringClass() { + return holder; + } + + @Override + public String getName() { + return name; + } + + @Override + public JavaType getType() { + // Pull field into local variable to prevent a race causing + // a ClassCastException below + JavaType currentType = type; + if (currentType instanceof HotSpotUnresolvedJavaType) { + // Don't allow unresolved types to hang around forever + HotSpotUnresolvedJavaType unresolvedType = (HotSpotUnresolvedJavaType) currentType; + ResolvedJavaType resolved = unresolvedType.reresolve(holder); + if (resolved != null) { + type = resolved; + } + } + return type; + } + + public int offset() { + return offset; + } + + @Override + public String toString() { + return format("HotSpotField<%H.%n %t:") + offset + ">"; + } + + @Override + public boolean isSynthetic() { + return (runtime().getConfig().syntheticFlag & modifiers) != 0; + } + + /** + * Checks if this field has the {@link Stable} annotation. + * + * @return true if field has {@link Stable} annotation, false otherwise + */ + public boolean isStable() { + if ((runtime().getConfig().jvmAccFieldStable & modifiers) != 0) { + return true; + } + assert getAnnotation(Stable.class) == null; + if (ImplicitStableValues.getValue() && isImplicitStableField()) { + return true; + } + return false; + } + + @Override + public T getAnnotation(Class annotationClass) { + Field javaField = toJava(); + if (javaField != null) { + return javaField.getAnnotation(annotationClass); + } + return null; + } + + private Field toJavaCache; + + private Field toJava() { + if (toJavaCache != null) { + return toJavaCache; + } + + if (isInternal()) { + return null; + } + try { + return toJavaCache = holder.mirror().getDeclaredField(name); + } catch (NoSuchFieldException | NoClassDefFoundError e) { + return null; + } + } + + private boolean isArray() { + JavaType fieldType = getType(); + return fieldType instanceof ResolvedJavaType && ((ResolvedJavaType) fieldType).isArray(); + } + + private boolean isImplicitStableField() { + if (isSynthetic()) { + if (isSyntheticImplicitStableField()) { + return true; + } + } else if (isWellKnownImplicitStableField()) { + return true; + } + return false; + } + + private boolean isSyntheticImplicitStableField() { + assert this.isSynthetic(); + if (isStatic() && isArray()) { + if (isFinal() && name.equals("$VALUES") || name.equals("ENUM$VALUES")) { + // generated int[] field for EnumClass::values() + return true; + } else if (name.startsWith("$SwitchMap$") || name.startsWith("$SWITCH_TABLE$")) { + // javac and ecj generate a static field in an inner class for a switch on an enum + // named $SwitchMap$p$k$g$EnumClass and $SWITCH_TABLE$p$k$g$EnumClass, respectively + return true; + } + } + return false; + } + + private boolean isWellKnownImplicitStableField() { + return WellKnownImplicitStableField.test(this); + } + + static class WellKnownImplicitStableField { + /** + * @return {@code true} if the field is a well-known stable field. + */ + public static boolean test(HotSpotResolvedJavaField field) { + return field.equals(STRING_VALUE_FIELD); + } + + private static final ResolvedJavaField STRING_VALUE_FIELD; + static { + try { + MetaAccessProvider metaAccess = runtime().getHostJVMCIBackend().getMetaAccess(); + STRING_VALUE_FIELD = metaAccess.lookupJavaField(String.class.getDeclaredField("value")); + } catch (SecurityException | NoSuchFieldException e) { + throw new JVMCIError(e); + } + } + } + + public LocationIdentity getLocationIdentity() { + return locationIdentity; + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotResolvedJavaMethod.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotResolvedJavaMethod.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2011, 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 java.lang.reflect.*; + +import com.oracle.jvmci.meta.*; + +/** + * Implementation of {@link JavaMethod} for resolved HotSpot methods. + */ +public interface HotSpotResolvedJavaMethod extends ResolvedJavaMethod { + + /** + * Returns true if this method has a {@code CallerSensitive} annotation. + * + * @return true if CallerSensitive annotation present, false otherwise + */ + boolean isCallerSensitive(); + + HotSpotResolvedObjectType getDeclaringClass(); + + /** + * Returns true if this method has a {@code ForceInline} annotation. + * + * @return true if ForceInline annotation present, false otherwise + */ + boolean isForceInline(); + + /** + * Returns true if this method has a {@code DontInline} annotation. + * + * @return true if DontInline annotation present, false otherwise + */ + boolean isDontInline(); + + /** + * Manually adds a DontInline annotation to this method. + */ + void setNotInlineable(); + + /** + * Returns true if this method is one of the special methods that is ignored by security stack + * walks. + * + * @return true if special method ignored by security stack walks, false otherwise + */ + boolean ignoredBySecurityStackWalk(); + + boolean hasBalancedMonitors(); + + ResolvedJavaMethod uniqueConcreteMethod(HotSpotResolvedObjectType receiver); + + /** + * Returns whether this method has compiled code. + * + * @return true if this method has compiled code, false otherwise + */ + boolean hasCompiledCode(); + + /** + * @param level + * @return true if the currently installed code was generated at {@code level}. + */ + boolean hasCompiledCodeAtLevel(int level); + + default boolean isDefault() { + if (isConstructor()) { + return false; + } + // Copied from java.lang.Method.isDefault() + int mask = Modifier.ABSTRACT | Modifier.PUBLIC | Modifier.STATIC; + return ((getModifiers() & mask) == Modifier.PUBLIC) && getDeclaringClass().isInterface(); + } + + /** + * Returns the offset of this method into the v-table. The method must have a v-table entry as + * indicated by {@link #isInVirtualMethodTable(ResolvedJavaType)}, otherwise an exception is + * thrown. + * + * @return the offset of this method into the v-table + */ + int vtableEntryOffset(ResolvedJavaType resolved); + + int intrinsicId(); + + /** + * Allocates a compile id for this method by asking the VM for one. + * + * @param entryBCI entry bci + * @return compile id + */ + int allocateCompileId(int entryBCI); + + boolean hasCodeAtLevel(int entryBCI, int level); +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotResolvedJavaMethodImpl.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotResolvedJavaMethodImpl.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,750 @@ +/* + * Copyright (c) 2011, 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 static com.oracle.jvmci.common.UnsafeAccess.*; +import static com.oracle.jvmci.hotspot.HotSpotJVMCIRuntime.*; +import static com.oracle.jvmci.hotspot.HotSpotResolvedJavaMethodImpl.Options.*; + +import java.lang.annotation.*; +import java.lang.reflect.*; +import java.util.*; + +import com.oracle.jvmci.common.*; +import com.oracle.jvmci.debug.*; +import com.oracle.jvmci.meta.*; +import com.oracle.jvmci.options.*; + +/** + * Implementation of {@link JavaMethod} for resolved HotSpot methods. + */ +public final class HotSpotResolvedJavaMethodImpl extends HotSpotMethod implements HotSpotResolvedJavaMethod, HotSpotProxified, MethodIdHolder { + + static class Options { + // @formatter:off + @Option(help = "", type = OptionType.Debug) + public static final OptionValue UseProfilingInformation = new OptionValue<>(true); + // @formatter:on + } + + /** + * Reference to metaspace Method object. + */ + private final long metaspaceMethod; + + private final HotSpotResolvedObjectTypeImpl holder; + private final HotSpotConstantPool constantPool; + private final HotSpotSignature signature; + private HotSpotMethodData methodData; + private byte[] code; + private Member toJavaCache; + + /** + * Gets the holder of a HotSpot metaspace method native object. + * + * @param metaspaceMethod a metaspace Method object + * @return the {@link ResolvedJavaType} corresponding to the holder of the + * {@code metaspaceMethod} + */ + public static HotSpotResolvedObjectTypeImpl getHolder(long metaspaceMethod) { + HotSpotVMConfig config = runtime().getConfig(); + final long metaspaceConstMethod = unsafe.getAddress(metaspaceMethod + config.methodConstMethodOffset); + final long metaspaceConstantPool = unsafe.getAddress(metaspaceConstMethod + config.constMethodConstantsOffset); + final long metaspaceKlass = unsafe.getAddress(metaspaceConstantPool + config.constantPoolHolderOffset); + return HotSpotResolvedObjectTypeImpl.fromMetaspaceKlass(metaspaceKlass); + } + + /** + * Gets the {@link ResolvedJavaMethod} for a HotSpot metaspace method native object. + * + * @param metaspaceMethod a metaspace Method object + * @return the {@link ResolvedJavaMethod} corresponding to {@code metaspaceMethod} + */ + public static HotSpotResolvedJavaMethod fromMetaspace(long metaspaceMethod) { + HotSpotResolvedObjectTypeImpl holder = getHolder(metaspaceMethod); + return holder.createMethod(metaspaceMethod); + } + + public HotSpotResolvedJavaMethodImpl(HotSpotResolvedObjectTypeImpl holder, long metaspaceMethod) { + // It would be too much work to get the method name here so we fill it in later. + super(null); + this.metaspaceMethod = metaspaceMethod; + this.holder = holder; + + HotSpotVMConfig config = runtime().getConfig(); + final long constMethod = getConstMethod(); + + /* + * Get the constant pool from the metaspace method. Some methods (e.g. intrinsics for + * signature-polymorphic method handle methods) have their own constant pool instead of the + * one from their holder. + */ + final long metaspaceConstantPool = unsafe.getAddress(constMethod + config.constMethodConstantsOffset); + this.constantPool = new HotSpotConstantPool(metaspaceConstantPool); + + final int nameIndex = unsafe.getChar(constMethod + config.constMethodNameIndexOffset); + this.name = constantPool.lookupUtf8(nameIndex); + + final int signatureIndex = unsafe.getChar(constMethod + config.constMethodSignatureIndexOffset); + this.signature = (HotSpotSignature) constantPool.lookupSignature(signatureIndex); + } + + /** + * Returns a pointer to this method's constant method data structure ( + * {@code Method::_constMethod}). + * + * @return pointer to this method's ConstMethod + */ + private long getConstMethod() { + assert metaspaceMethod != 0; + return unsafe.getAddress(metaspaceMethod + runtime().getConfig().methodConstMethodOffset); + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof HotSpotResolvedJavaMethodImpl) { + HotSpotResolvedJavaMethodImpl that = (HotSpotResolvedJavaMethodImpl) obj; + return that.metaspaceMethod == metaspaceMethod; + } + return false; + } + + @Override + public int hashCode() { + return (int) metaspaceMethod; + } + + /** + * Returns this method's flags ({@code Method::_flags}). + * + * @return flags of this method + */ + private int getFlags() { + return unsafe.getByte(metaspaceMethod + runtime().getConfig().methodFlagsOffset); + } + + /** + * Returns this method's constant method flags ({@code ConstMethod::_flags}). + * + * @return flags of this method's ConstMethod + */ + private int getConstMethodFlags() { + return unsafe.getChar(getConstMethod() + runtime().getConfig().constMethodFlagsOffset); + } + + @Override + public HotSpotResolvedObjectTypeImpl getDeclaringClass() { + return holder; + } + + /** + * Gets the address of the C++ Method object for this method. + */ + public JavaConstant getMetaspaceMethodConstant() { + return HotSpotMetaspaceConstantImpl.forMetaspaceObject(getHostWordKind(), metaspaceMethod, this, false); + } + + public long getMetaspaceMethod() { + return metaspaceMethod; + } + + @Override + public JavaConstant getEncoding() { + return getMetaspaceMethodConstant(); + } + + /** + * Gets the complete set of modifiers for this method which includes the JVM specification + * modifiers as well as the HotSpot internal modifiers. + */ + public int getAllModifiers() { + return unsafe.getInt(metaspaceMethod + runtime().getConfig().methodAccessFlagsOffset); + } + + @Override + public int getModifiers() { + return getAllModifiers() & Modifier.methodModifiers(); + } + + @Override + public boolean canBeStaticallyBound() { + return (isFinal() || isPrivate() || isStatic() || holder.isFinal()) && isConcrete(); + } + + @Override + public byte[] getCode() { + if (getCodeSize() == 0) { + return null; + } + if (code == null && holder.isLinked()) { + code = runtime().getCompilerToVM().getBytecode(metaspaceMethod); + assert code.length == getCodeSize() : "expected: " + getCodeSize() + ", actual: " + code.length; + } + return code; + } + + @Override + public int getCodeSize() { + return unsafe.getChar(getConstMethod() + runtime().getConfig().constMethodCodeSizeOffset); + } + + @Override + public ExceptionHandler[] getExceptionHandlers() { + final boolean hasExceptionTable = (getConstMethodFlags() & runtime().getConfig().constMethodHasExceptionTable) != 0; + if (!hasExceptionTable) { + return new ExceptionHandler[0]; + } + + HotSpotVMConfig config = runtime().getConfig(); + final int exceptionTableLength = runtime().getCompilerToVM().exceptionTableLength(metaspaceMethod); + ExceptionHandler[] handlers = new ExceptionHandler[exceptionTableLength]; + long exceptionTableElement = runtime().getCompilerToVM().exceptionTableStart(metaspaceMethod); + + for (int i = 0; i < exceptionTableLength; i++) { + final int startPc = unsafe.getChar(exceptionTableElement + config.exceptionTableElementStartPcOffset); + final int endPc = unsafe.getChar(exceptionTableElement + config.exceptionTableElementEndPcOffset); + final int handlerPc = unsafe.getChar(exceptionTableElement + config.exceptionTableElementHandlerPcOffset); + int catchTypeIndex = unsafe.getChar(exceptionTableElement + config.exceptionTableElementCatchTypeIndexOffset); + + JavaType catchType; + if (catchTypeIndex == 0) { + catchType = null; + } else { + final int opcode = -1; // opcode is not used + catchType = constantPool.lookupType(catchTypeIndex, opcode); + + // Check for Throwable which catches everything. + if (catchType instanceof HotSpotResolvedObjectTypeImpl) { + HotSpotResolvedObjectTypeImpl resolvedType = (HotSpotResolvedObjectTypeImpl) catchType; + if (resolvedType.mirror() == Throwable.class) { + catchTypeIndex = 0; + catchType = null; + } + } + } + handlers[i] = new ExceptionHandler(startPc, endPc, handlerPc, catchTypeIndex, catchType); + + // Go to the next ExceptionTableElement + exceptionTableElement += config.exceptionTableElementSize; + } + + return handlers; + } + + /** + * Returns true if this method has a {@code CallerSensitive} annotation. + * + * @return true if CallerSensitive annotation present, false otherwise + */ + public boolean isCallerSensitive() { + return (getFlags() & runtime().getConfig().methodFlagsCallerSensitive) != 0; + } + + /** + * Returns true if this method has a {@code ForceInline} annotation. + * + * @return true if ForceInline annotation present, false otherwise + */ + public boolean isForceInline() { + return (getFlags() & runtime().getConfig().methodFlagsForceInline) != 0; + } + + /** + * Returns true if this method has a {@code DontInline} annotation. + * + * @return true if DontInline annotation present, false otherwise + */ + public boolean isDontInline() { + return (getFlags() & runtime().getConfig().methodFlagsDontInline) != 0; + } + + /** + * Manually adds a DontInline annotation to this method. + */ + public void setNotInlineable() { + runtime().getCompilerToVM().doNotInlineOrCompile(metaspaceMethod); + } + + /** + * Returns true if this method is one of the special methods that is ignored by security stack + * walks. + * + * @return true if special method ignored by security stack walks, false otherwise + */ + public boolean ignoredBySecurityStackWalk() { + return runtime().getCompilerToVM().methodIsIgnoredBySecurityStackWalk(metaspaceMethod); + } + + public boolean hasBalancedMonitors() { + HotSpotVMConfig config = runtime().getConfig(); + final int modifiers = getAllModifiers(); + + // Method has no monitorenter/exit bytecodes. + if ((modifiers & config.jvmAccHasMonitorBytecodes) == 0) { + return false; + } + + // Check to see if a previous compilation computed the monitor-matching analysis. + if ((modifiers & config.jvmAccMonitorMatch) != 0) { + return true; + } + + // This either happens only once if monitors are balanced or very rarely multiple-times. + return runtime().getCompilerToVM().hasBalancedMonitors(metaspaceMethod); + } + + @Override + public boolean isClassInitializer() { + return "".equals(name) && isStatic(); + } + + @Override + public boolean isConstructor() { + return "".equals(name) && !isStatic(); + } + + @Override + public int getMaxLocals() { + if (isAbstract() || isNative()) { + return 0; + } + HotSpotVMConfig config = runtime().getConfig(); + return unsafe.getChar(getConstMethod() + config.methodMaxLocalsOffset); + } + + @Override + public int getMaxStackSize() { + if (isAbstract() || isNative()) { + return 0; + } + HotSpotVMConfig config = runtime().getConfig(); + return config.extraStackEntries + unsafe.getChar(getConstMethod() + config.constMethodMaxStackOffset); + } + + @Override + public StackTraceElement asStackTraceElement(int bci) { + if (bci < 0 || bci >= getCodeSize()) { + // HotSpot code can only construct stack trace elements for valid bcis + StackTraceElement ste = runtime().getCompilerToVM().getStackTraceElement(metaspaceMethod, 0); + return new StackTraceElement(ste.getClassName(), ste.getMethodName(), ste.getFileName(), -1); + } + return runtime().getCompilerToVM().getStackTraceElement(metaspaceMethod, bci); + } + + public ResolvedJavaMethod uniqueConcreteMethod(HotSpotResolvedObjectType receiver) { + if (receiver.isInterface()) { + // Cannot trust interfaces. Because of: + // interface I { void foo(); } + // class A { public void foo() {} } + // class B extends A implements I { } + // class C extends B { public void foo() { } } + // class D extends B { } + // Would lead to identify C.foo() as the unique concrete method for I.foo() without + // seeing A.foo(). + return null; + } + long metaspaceKlass = ((HotSpotResolvedObjectTypeImpl) receiver).getMetaspaceKlass(); + final long uniqueConcreteMethod = runtime().getCompilerToVM().findUniqueConcreteMethod(metaspaceKlass, metaspaceMethod); + if (uniqueConcreteMethod == 0) { + return null; + } + return fromMetaspace(uniqueConcreteMethod); + } + + @Override + public HotSpotSignature getSignature() { + return signature; + } + + /** + * Gets the value of {@code Method::_code}. + * + * @return the value of {@code Method::_code} + */ + private long getCompiledCode() { + HotSpotVMConfig config = runtime().getConfig(); + return unsafe.getAddress(metaspaceMethod + config.methodCodeOffset); + } + + /** + * Returns whether this method has compiled code. + * + * @return true if this method has compiled code, false otherwise + */ + public boolean hasCompiledCode() { + return getCompiledCode() != 0L; + } + + /** + * @param level + * @return true if the currently installed code was generated at {@code level}. + */ + public boolean hasCompiledCodeAtLevel(int level) { + long compiledCode = getCompiledCode(); + if (compiledCode != 0) { + return unsafe.getInt(compiledCode + runtime().getConfig().nmethodCompLevelOffset) == level; + } + return false; + } + + private static final String TraceMethodDataFilter = System.getProperty("jvmci.traceMethodDataFilter"); + + @Override + public ProfilingInfo getProfilingInfo(boolean includeNormal, boolean includeOSR) { + ProfilingInfo info; + + if (UseProfilingInformation.getValue() && methodData == null) { + long metaspaceMethodData = unsafe.getAddress(metaspaceMethod + runtime().getConfig().methodDataOffset); + if (metaspaceMethodData != 0) { + methodData = new HotSpotMethodData(metaspaceMethodData); + if (TraceMethodDataFilter != null && this.format("%H.%n").contains(TraceMethodDataFilter)) { + TTY.println("Raw method data for " + this.format("%H.%n(%p)") + ":"); + TTY.println(methodData.toString()); + } + } + } + + if (methodData == null || (!methodData.hasNormalData() && !methodData.hasExtraData())) { + // Be optimistic and return false for exceptionSeen. A methodDataOop is allocated in + // case of a deoptimization. + info = DefaultProfilingInfo.get(TriState.FALSE); + } else { + info = new HotSpotProfilingInfo(methodData, this, includeNormal, includeOSR); + } + return info; + } + + @Override + public void reprofile() { + runtime().getCompilerToVM().reprofile(metaspaceMethod); + } + + @Override + public ConstantPool getConstantPool() { + return constantPool; + } + + @Override + public Annotation[][] getParameterAnnotations() { + if (isConstructor()) { + Constructor javaConstructor = toJavaConstructor(); + return javaConstructor == null ? null : javaConstructor.getParameterAnnotations(); + } + Method javaMethod = toJava(); + return javaMethod == null ? null : javaMethod.getParameterAnnotations(); + } + + @Override + public Annotation[] getAnnotations() { + if (isConstructor()) { + Constructor javaConstructor = toJavaConstructor(); + return javaConstructor == null ? new Annotation[0] : javaConstructor.getAnnotations(); + } + Method javaMethod = toJava(); + return javaMethod == null ? new Annotation[0] : javaMethod.getAnnotations(); + } + + @Override + public T getAnnotation(Class annotationClass) { + if (isConstructor()) { + Constructor javaConstructor = toJavaConstructor(); + return javaConstructor == null ? null : javaConstructor.getAnnotation(annotationClass); + } + Method javaMethod = toJava(); + return javaMethod == null ? null : javaMethod.getAnnotation(annotationClass); + } + + @Override + public boolean isSynthetic() { + int modifiers = getAllModifiers(); + return (runtime().getConfig().syntheticFlag & modifiers) != 0; + } + + public boolean isDefault() { + if (isConstructor()) { + return false; + } + // Copied from java.lang.Method.isDefault() + int mask = Modifier.ABSTRACT | Modifier.PUBLIC | Modifier.STATIC; + return ((getModifiers() & mask) == Modifier.PUBLIC) && getDeclaringClass().isInterface(); + } + + @Override + public Type[] getGenericParameterTypes() { + if (isConstructor()) { + Constructor javaConstructor = toJavaConstructor(); + return javaConstructor == null ? null : javaConstructor.getGenericParameterTypes(); + } + Method javaMethod = toJava(); + return javaMethod == null ? null : javaMethod.getGenericParameterTypes(); + } + + public Class[] signatureToTypes() { + Signature sig = getSignature(); + int count = sig.getParameterCount(false); + Class[] result = new Class[count]; + for (int i = 0; i < result.length; ++i) { + JavaType parameterType = sig.getParameterType(i, holder); + HotSpotResolvedJavaType resolvedParameterType = (HotSpotResolvedJavaType) parameterType.resolve(holder); + result[i] = resolvedParameterType.mirror(); + } + return result; + } + + private Method toJava() { + if (toJavaCache != null) { + return (Method) toJavaCache; + } + try { + Method result = holder.mirror().getDeclaredMethod(name, signatureToTypes()); + toJavaCache = result; + return result; + } catch (NoSuchMethodException | NoClassDefFoundError e) { + return null; + } + } + + private Constructor toJavaConstructor() { + if (toJavaCache != null) { + return (Constructor) toJavaCache; + } + try { + Constructor result = holder.mirror().getDeclaredConstructor(signatureToTypes()); + toJavaCache = result; + return result; + } catch (NoSuchMethodException | NoClassDefFoundError e) { + return null; + } + } + + @Override + public boolean canBeInlined() { + if (isDontInline()) { + return false; + } + return runtime().getCompilerToVM().canInlineMethod(metaspaceMethod); + } + + @Override + public boolean shouldBeInlined() { + if (isForceInline()) { + return true; + } + return runtime().getCompilerToVM().shouldInlineMethod(metaspaceMethod); + } + + @Override + public LineNumberTable getLineNumberTable() { + final boolean hasLineNumberTable = (getConstMethodFlags() & runtime().getConfig().constMethodHasLineNumberTable) != 0; + if (!hasLineNumberTable) { + return null; + } + + long[] values = runtime().getCompilerToVM().getLineNumberTable(metaspaceMethod); + if (values.length == 0) { + // Empty table so treat is as non-existent + return null; + } + assert values.length % 2 == 0; + int[] bci = new int[values.length / 2]; + int[] line = new int[values.length / 2]; + + for (int i = 0; i < values.length / 2; i++) { + bci[i] = (int) values[i * 2]; + line[i] = (int) values[i * 2 + 1]; + } + + return new LineNumberTableImpl(line, bci); + } + + @Override + public LocalVariableTable getLocalVariableTable() { + final boolean hasLocalVariableTable = (getConstMethodFlags() & runtime().getConfig().constMethodHasLocalVariableTable) != 0; + if (!hasLocalVariableTable) { + return null; + } + + HotSpotVMConfig config = runtime().getConfig(); + long localVariableTableElement = runtime().getCompilerToVM().getLocalVariableTableStart(metaspaceMethod); + final int localVariableTableLength = runtime().getCompilerToVM().getLocalVariableTableLength(metaspaceMethod); + Local[] locals = new Local[localVariableTableLength]; + + for (int i = 0; i < localVariableTableLength; i++) { + final int startBci = unsafe.getChar(localVariableTableElement + config.localVariableTableElementStartBciOffset); + final int endBci = startBci + unsafe.getChar(localVariableTableElement + config.localVariableTableElementLengthOffset); + final int nameCpIndex = unsafe.getChar(localVariableTableElement + config.localVariableTableElementNameCpIndexOffset); + final int typeCpIndex = unsafe.getChar(localVariableTableElement + config.localVariableTableElementDescriptorCpIndexOffset); + final int slot = unsafe.getChar(localVariableTableElement + config.localVariableTableElementSlotOffset); + + String localName = getConstantPool().lookupUtf8(nameCpIndex); + String localType = getConstantPool().lookupUtf8(typeCpIndex); + + locals[i] = new LocalImpl(localName, runtime().lookupType(localType, holder, false), startBci, endBci, slot); + + // Go to the next LocalVariableTableElement + localVariableTableElement += config.localVariableTableElementSize; + } + + return new LocalVariableTableImpl(locals); + } + + /** + * Returns the offset of this method into the v-table. The method must have a v-table entry as + * indicated by {@link #isInVirtualMethodTable(ResolvedJavaType)}, otherwise an exception is + * thrown. + * + * @return the offset of this method into the v-table + */ + public int vtableEntryOffset(ResolvedJavaType resolved) { + if (!isInVirtualMethodTable(resolved)) { + throw new JVMCIError("%s does not have a vtable entry", this); + } + HotSpotVMConfig config = runtime().getConfig(); + final int vtableIndex = getVtableIndex((HotSpotResolvedObjectTypeImpl) resolved); + return config.instanceKlassVtableStartOffset + vtableIndex * config.vtableEntrySize + config.vtableEntryMethodOffset; + } + + @Override + public boolean isInVirtualMethodTable(ResolvedJavaType resolved) { + if (resolved instanceof HotSpotResolvedObjectTypeImpl) { + HotSpotResolvedObjectTypeImpl hotspotResolved = (HotSpotResolvedObjectTypeImpl) resolved; + int vtableIndex = getVtableIndex(hotspotResolved); + return vtableIndex >= 0 && vtableIndex < hotspotResolved.getVtableLength(); + } + return false; + } + + private int getVtableIndex(HotSpotResolvedObjectTypeImpl resolved) { + if (!holder.isLinked()) { + return runtime().getConfig().invalidVtableIndex; + } + if (holder.isInterface()) { + if (resolved.isInterface()) { + return runtime().getConfig().invalidVtableIndex; + } + return getVtableIndexForInterface(resolved); + } + return getVtableIndex(); + } + + /** + * Returns this method's virtual table index. + * + * @return virtual table index + */ + private int getVtableIndex() { + assert !holder.isInterface(); + HotSpotVMConfig config = runtime().getConfig(); + int result = unsafe.getInt(metaspaceMethod + config.methodVtableIndexOffset); + assert result >= config.nonvirtualVtableIndex : "must be linked"; + return result; + } + + private int getVtableIndexForInterface(ResolvedJavaType resolved) { + HotSpotResolvedObjectTypeImpl hotspotType = (HotSpotResolvedObjectTypeImpl) resolved; + return runtime().getCompilerToVM().getVtableIndexForInterface(hotspotType.getMetaspaceKlass(), getMetaspaceMethod()); + } + + /** + * The {@link SpeculationLog} for methods compiled by JVMCI hang off this per-declaring-type + * {@link ClassValue}. The raw Method* value is safe to use as a key in the map as a) it is + * never moves and b) we never read from it. + *

      + * One implication is that we will preserve {@link SpeculationLog}s for methods that have been + * redefined via class redefinition. It's tempting to periodically flush such logs but we cannot + * read the JVM_ACC_IS_OBSOLETE bit (or anything else) via the raw pointer as obsoleted methods + * are subject to clean up and deletion (see InstanceKlass::purge_previous_versions_internal). + */ + private static final ClassValue> SpeculationLogs = new ClassValue>() { + @Override + protected Map computeValue(java.lang.Class type) { + return new HashMap<>(4); + } + }; + + public SpeculationLog getSpeculationLog() { + Map map = SpeculationLogs.get(holder.mirror()); + synchronized (map) { + SpeculationLog log = map.get(this.metaspaceMethod); + if (log == null) { + log = new HotSpotSpeculationLog(); + map.put(metaspaceMethod, log); + } + return log; + } + } + + public int intrinsicId() { + HotSpotVMConfig config = runtime().getConfig(); + return unsafe.getByte(metaspaceMethod + config.methodIntrinsicIdOffset) & 0xff; + } + + @Override + public JavaConstant invoke(JavaConstant receiver, JavaConstant[] arguments) { + assert !isConstructor(); + Method javaMethod = toJava(); + javaMethod.setAccessible(true); + + Object[] objArguments = new Object[arguments.length]; + for (int i = 0; i < arguments.length; i++) { + objArguments[i] = HotSpotObjectConstantImpl.asBoxedValue(arguments[i]); + } + Object objReceiver = receiver != null && !receiver.isNull() ? ((HotSpotObjectConstantImpl) receiver).object() : null; + + try { + Object objResult = javaMethod.invoke(objReceiver, objArguments); + return javaMethod.getReturnType() == void.class ? null : HotSpotObjectConstantImpl.forBoxedValue(getSignature().getReturnKind(), objResult); + + } catch (IllegalAccessException | InvocationTargetException ex) { + throw new IllegalArgumentException(ex); + } + } + + /** + * Allocates a compile id for this method by asking the VM for one. + * + * @param entryBCI entry bci + * @return compile id + */ + public int allocateCompileId(int entryBCI) { + return runtime().getCompilerToVM().allocateCompileId(metaspaceMethod, entryBCI); + } + + public boolean hasCodeAtLevel(int entryBCI, int level) { + if (entryBCI == runtime().getConfig().invocationEntryBci) { + return hasCompiledCodeAtLevel(level); + } + return runtime().getCompilerToVM().hasCompiledCodeForOSR(metaspaceMethod, entryBCI, level); + } + + private int methodId; + + public void setMethodId(int id) { + assert methodId == 0; + methodId = id; + } + + public int getMethodId() { + return methodId; + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotResolvedJavaType.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotResolvedJavaType.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2012, 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.hotspot; + +import static com.oracle.jvmci.hotspot.HotSpotJVMCIRuntime.*; + +import com.oracle.jvmci.meta.*; + +public abstract class HotSpotResolvedJavaType extends HotSpotJavaType implements ResolvedJavaType { + + /** + * Gets the JVMCI mirror for a {@link Class} object. + * + * @return the {@link HotSpotResolvedJavaType} corresponding to {@code javaClass} + */ + public static ResolvedJavaType fromClass(Class javaClass) { + return runtime().fromClass(javaClass); + } + + public HotSpotResolvedJavaType(String name) { + super(name); + } + + public abstract Class mirror(); + + @Override + public final boolean equals(Object obj) { + if (!(obj instanceof HotSpotResolvedJavaType)) { + return false; + } + HotSpotResolvedJavaType that = (HotSpotResolvedJavaType) obj; + return this.mirror().equals(that.mirror()); + } + + @Override + public final int hashCode() { + return getName().hashCode(); + } + +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotResolvedObjectType.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotResolvedObjectType.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2011, 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; + +import com.oracle.jvmci.meta.Assumptions.AssumptionResult; +import com.oracle.jvmci.meta.*; + +/** + * Implementation of {@link JavaType} for resolved non-primitive HotSpot classes. + */ +public interface HotSpotResolvedObjectType extends ResolvedJavaType { + + HotSpotResolvedObjectType getArrayClass(); + + ResolvedJavaType getComponentType(); + + AssumptionResult findLeafConcreteSubtype(); + + HotSpotResolvedObjectType getSuperclass(); + + HotSpotResolvedObjectType[] getInterfaces(); + + HotSpotResolvedObjectType getSupertype(); + + HotSpotResolvedObjectType findLeastCommonAncestor(ResolvedJavaType otherType); + + HotSpotResolvedObjectType asExactType(); + + default boolean isPrimitive() { + return false; + } + + default Kind getKind() { + return Kind.Object; + } + + ConstantPool constantPool(); + + /** + * Gets the instance size of this type. If an instance of this type cannot be fast path + * allocated, then the returned value is negative (its absolute value gives the size). Must not + * be called if this is an array or interface type. + */ + int instanceSize(); + + int getVtableLength(); + + @Override + AssumptionResult findUniqueConcreteMethod(ResolvedJavaMethod method); + + /** + * Performs a fast-path check that this type is resolved in the context of a given accessing + * class. A negative result does not mean this type is not resolved with respect to + * {@code accessingClass}. That can only be determined by + * {@linkplain HotSpotJVMCIRuntime#lookupType(String, HotSpotResolvedObjectType, boolean) + * re-resolving} the type. + */ + boolean isDefinitelyResolvedWithRespectTo(ResolvedJavaType accessingClass); + + /** + * Gets the metaspace Klass boxed in a {@link JavaConstant}. + */ + Constant klass(); + + boolean isPrimaryType(); + + int superCheckOffset(); + + long prototypeMarkWord(); + + HotSpotResolvedObjectType getEnclosingType(); + + ResolvedJavaMethod getClassInitializer(); + + ResolvedJavaField createField(String name, JavaType type, long offset, int modifiers); +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotResolvedObjectTypeImpl.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotResolvedObjectTypeImpl.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,902 @@ +/* + * Copyright (c) 2011, 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; + +import static com.oracle.jvmci.common.UnsafeAccess.*; +import static com.oracle.jvmci.hotspot.HotSpotJVMCIRuntime.*; +import static java.util.Objects.*; + +import java.lang.annotation.*; +import java.lang.reflect.*; +import java.net.*; +import java.nio.*; +import java.util.*; + +import com.oracle.jvmci.common.*; +import com.oracle.jvmci.meta.Assumptions.AssumptionResult; +import com.oracle.jvmci.meta.Assumptions.ConcreteMethod; +import com.oracle.jvmci.meta.Assumptions.ConcreteSubtype; +import com.oracle.jvmci.meta.Assumptions.LeafType; +import com.oracle.jvmci.meta.Assumptions.NoFinalizableSubclass; +import com.oracle.jvmci.meta.*; + +/** + * Implementation of {@link JavaType} for resolved non-primitive HotSpot classes. + */ +public final class HotSpotResolvedObjectTypeImpl extends HotSpotResolvedJavaType implements HotSpotResolvedObjectType, HotSpotProxified { + + /** + * The Java class this type represents. + */ + private final Class javaClass; + + private HashMap fieldCache; + private HashMap methodCache; + private HotSpotResolvedJavaField[] instanceFields; + private HotSpotResolvedObjectTypeImpl[] interfaces; + private ConstantPool constantPool; + private HotSpotResolvedObjectType arrayOfType; + + /** + * Gets the JVMCI mirror for a {@link Class} object. + * + * @return the {@link HotSpotResolvedJavaType} corresponding to {@code javaClass} + */ + public static HotSpotResolvedObjectTypeImpl fromObjectClass(Class javaClass) { + return (HotSpotResolvedObjectTypeImpl) runtime().fromClass(javaClass); + } + + /** + * Gets the JVMCI mirror from a HotSpot metaspace Klass native object. + * + * @param metaspaceKlass a metaspace Klass object + * @return the {@link ResolvedJavaType} corresponding to {@code metaspaceKlass} + */ + public static HotSpotResolvedObjectTypeImpl fromMetaspaceKlass(long metaspaceKlass) { + assert metaspaceKlass != 0; + Class javaClass = runtime().getCompilerToVM().getJavaMirror(metaspaceKlass); + assert javaClass != null; + return fromObjectClass(javaClass); + } + + /** + * Creates the JVMCI mirror for a {@link Class} object. + * + *

      + * NOTE: Creating an instance of this class does not install the mirror for the + * {@link Class} type. Use {@link #fromObjectClass(Class)} or {@link #fromMetaspaceKlass(long)} + * instead. + *

      + * + * @param javaClass the Class to create the mirror for + */ + public HotSpotResolvedObjectTypeImpl(Class javaClass) { + super(getSignatureName(javaClass)); + this.javaClass = javaClass; + assert getName().charAt(0) != '[' || isArray() : getName(); + } + + /** + * Returns the name of this type as it would appear in a signature. + */ + private static String getSignatureName(Class javaClass) { + if (javaClass.isArray()) { + return javaClass.getName().replace('.', '/'); + } + return "L" + javaClass.getName().replace('.', '/') + ";"; + } + + /** + * Gets the metaspace Klass for this type. + */ + public long getMetaspaceKlass() { + if (HotSpotJVMCIRuntime.getHostWordKind() == Kind.Long) { + return unsafe.getLong(javaClass, (long) runtime().getConfig().klassOffset); + } + return unsafe.getInt(javaClass, (long) runtime().getConfig().klassOffset) & 0xFFFFFFFFL; + } + + @Override + public int getModifiers() { + return mirror().getModifiers(); + } + + public int getAccessFlags() { + HotSpotVMConfig config = runtime().getConfig(); + return unsafe.getInt(getMetaspaceKlass() + config.klassAccessFlagsOffset); + } + + @Override + public HotSpotResolvedObjectType getArrayClass() { + if (arrayOfType == null) { + arrayOfType = fromObjectClass(Array.newInstance(mirror(), 0).getClass()); + } + return arrayOfType; + } + + @Override + public ResolvedJavaType getComponentType() { + Class javaComponentType = mirror().getComponentType(); + return javaComponentType == null ? null : fromClass(javaComponentType); + } + + @Override + public AssumptionResult findLeafConcreteSubtype() { + HotSpotVMConfig config = runtime().getConfig(); + if (isArray()) { + return getElementalType().isFinal() ? new AssumptionResult<>(this) : null; + } else if (isInterface()) { + HotSpotResolvedObjectTypeImpl implementor = getSingleImplementor(); + /* + * If the implementor field contains itself that indicates that the interface has more + * than one implementors (see: InstanceKlass::add_implementor). + */ + if (implementor == null || implementor.equals(this)) { + return null; + } + + assert !implementor.isInterface(); + if (implementor.isAbstract() || !implementor.isLeafClass()) { + AssumptionResult leafConcreteSubtype = implementor.findLeafConcreteSubtype(); + if (leafConcreteSubtype != null) { + assert !leafConcreteSubtype.getResult().equals(implementor); + AssumptionResult newResult = new AssumptionResult<>(leafConcreteSubtype.getResult(), new ConcreteSubtype(this, implementor)); + // Accumulate leaf assumptions and return the combined result. + newResult.add(leafConcreteSubtype); + return newResult; + } + return null; + } + + return new AssumptionResult<>(implementor, new LeafType(implementor), new ConcreteSubtype(this, implementor)); + } else { + HotSpotResolvedObjectTypeImpl type = this; + while (type.isAbstract()) { + long subklass = type.getSubklass(); + if (subklass == 0 || unsafe.getAddress(subklass + config.nextSiblingOffset) != 0) { + return null; + } + type = fromMetaspaceKlass(subklass); + } + if (type.isAbstract() || type.isInterface() || !type.isLeafClass()) { + return null; + } + if (this.isAbstract()) { + return new AssumptionResult<>(type, new LeafType(type), new ConcreteSubtype(this, type)); + } else { + assert this.equals(type); + return new AssumptionResult<>(type, new LeafType(type)); + } + } + } + + /** + * Returns if type {@code type} is a leaf class. This is the case if the + * {@code Klass::_subklass} field of the underlying class is zero. + * + * @return true if the type is a leaf class + */ + private boolean isLeafClass() { + return getSubklass() == 0; + } + + /** + * Returns the {@code Klass::_subklass} field of the underlying metaspace klass for the given + * type {@code type}. + * + * @return value of the subklass field as metaspace klass pointer + */ + private long getSubklass() { + return unsafe.getAddress(getMetaspaceKlass() + runtime().getConfig().subklassOffset); + } + + @Override + public HotSpotResolvedObjectTypeImpl getSuperclass() { + Class javaSuperclass = mirror().getSuperclass(); + return javaSuperclass == null ? null : (HotSpotResolvedObjectTypeImpl) fromObjectClass(javaSuperclass); + } + + @Override + public HotSpotResolvedObjectTypeImpl[] getInterfaces() { + if (interfaces == null) { + Class[] javaInterfaces = mirror().getInterfaces(); + HotSpotResolvedObjectTypeImpl[] result = new HotSpotResolvedObjectTypeImpl[javaInterfaces.length]; + for (int i = 0; i < javaInterfaces.length; i++) { + result[i] = fromObjectClass(javaInterfaces[i]); + } + interfaces = result; + } + return interfaces; + } + + @Override + public HotSpotResolvedObjectTypeImpl getSingleImplementor() { + if (!isInterface()) { + throw new JVMCIError("Cannot call getSingleImplementor() on a non-interface type: %s", this); + } + final long implementorMetaspaceKlass = runtime().getCompilerToVM().getKlassImplementor(getMetaspaceKlass()); + + // No implementor. + if (implementorMetaspaceKlass == 0) { + return null; + } + + return fromMetaspaceKlass(implementorMetaspaceKlass); + } + + public HotSpotResolvedObjectTypeImpl getSupertype() { + if (isArray()) { + ResolvedJavaType componentType = getComponentType(); + if (mirror() == Object[].class || componentType.isPrimitive()) { + return fromObjectClass(Object.class); + } + return (HotSpotResolvedObjectTypeImpl) ((HotSpotResolvedObjectTypeImpl) componentType).getSupertype().getArrayClass(); + } + if (isInterface()) { + return fromObjectClass(Object.class); + } + return getSuperclass(); + } + + @Override + public HotSpotResolvedObjectType findLeastCommonAncestor(ResolvedJavaType otherType) { + if (otherType.isPrimitive()) { + return null; + } else { + HotSpotResolvedObjectTypeImpl t1 = this; + HotSpotResolvedObjectTypeImpl t2 = (HotSpotResolvedObjectTypeImpl) otherType; + while (true) { + if (t1.isAssignableFrom(t2)) { + return t1; + } + if (t2.isAssignableFrom(t1)) { + return t2; + } + t1 = t1.getSupertype(); + t2 = t2.getSupertype(); + } + } + } + + @Override + public HotSpotResolvedObjectType asExactType() { + if (isArray()) { + return getComponentType().asExactType() != null ? this : null; + } + return isFinal() ? this : null; + } + + @Override + public JavaConstant getJavaClass() { + return HotSpotObjectConstantImpl.forObject(mirror()); + } + + @Override + public JavaConstant getObjectHub() { + return klass(); + } + + @Override + public AssumptionResult hasFinalizableSubclass() { + assert !isArray(); + if (!runtime().getCompilerToVM().hasFinalizableSubclass(getMetaspaceKlass())) { + return new AssumptionResult<>(false, new NoFinalizableSubclass(this)); + } + return new AssumptionResult<>(true); + } + + @Override + public boolean hasFinalizer() { + HotSpotVMConfig config = runtime().getConfig(); + return (getAccessFlags() & config.klassHasFinalizerFlag) != 0; + } + + @Override + public boolean isPrimitive() { + return false; + } + + @Override + public boolean isArray() { + return mirror().isArray(); + } + + @Override + public boolean isInitialized() { + return isArray() ? true : getInitState() == runtime().getConfig().instanceKlassStateFullyInitialized; + } + + @Override + public boolean isLinked() { + return isArray() ? true : getInitState() >= runtime().getConfig().instanceKlassStateLinked; + } + + /** + * Returns the value of the state field {@code InstanceKlass::_init_state} of the metaspace + * klass. + * + * @return state field value of this type + */ + private int getInitState() { + assert !isArray() : "_init_state only exists in InstanceKlass"; + return unsafe.getByte(getMetaspaceKlass() + runtime().getConfig().instanceKlassInitStateOffset) & 0xFF; + } + + @Override + public void initialize() { + if (!isInitialized()) { + unsafe.ensureClassInitialized(mirror()); + assert isInitialized(); + } + } + + @Override + public boolean isInstance(JavaConstant obj) { + if (obj.getKind() == Kind.Object && !obj.isNull()) { + return mirror().isInstance(((HotSpotObjectConstantImpl) obj).object()); + } + return false; + } + + @Override + public boolean isInstanceClass() { + return !isArray() && !isInterface(); + } + + @Override + public boolean isInterface() { + return mirror().isInterface(); + } + + @Override + public boolean isAssignableFrom(ResolvedJavaType other) { + assert other != null; + if (other instanceof HotSpotResolvedObjectTypeImpl) { + HotSpotResolvedObjectTypeImpl otherType = (HotSpotResolvedObjectTypeImpl) other; + return mirror().isAssignableFrom(otherType.mirror()); + } + return false; + } + + @Override + public boolean isJavaLangObject() { + return javaClass.equals(Object.class); + } + + @Override + public Kind getKind() { + return Kind.Object; + } + + @Override + public ResolvedJavaMethod resolveConcreteMethod(ResolvedJavaMethod method, ResolvedJavaType callerType) { + ResolvedJavaMethod resolvedMethod = resolveMethod(method, callerType, true); + if (resolvedMethod == null || resolvedMethod.isAbstract()) { + return null; + } + return resolvedMethod; + } + + @Override + public ResolvedJavaMethod resolveMethod(ResolvedJavaMethod method, ResolvedJavaType callerType, boolean includeAbstract) { + if (!includeAbstract) { + return resolveConcreteMethod(method, callerType); + } + assert !callerType.isArray(); + if (method.isConcrete() && method.getDeclaringClass().equals(this) && method.isPublic()) { + return method; + } + if (!method.getDeclaringClass().isAssignableFrom(this)) { + return null; + } + HotSpotResolvedJavaMethodImpl hotSpotMethod = (HotSpotResolvedJavaMethodImpl) method; + HotSpotResolvedObjectTypeImpl hotSpotCallerType = (HotSpotResolvedObjectTypeImpl) callerType; + final long resolvedMetaspaceMethod = runtime().getCompilerToVM().resolveMethod(getMetaspaceKlass(), hotSpotMethod.getMetaspaceMethod(), hotSpotCallerType.getMetaspaceKlass()); + if (resolvedMetaspaceMethod == 0) { + return null; + } + return HotSpotResolvedJavaMethodImpl.fromMetaspace(resolvedMetaspaceMethod); + } + + public ConstantPool constantPool() { + if (constantPool == null) { + final long metaspaceConstantPool = unsafe.getAddress(getMetaspaceKlass() + runtime().getConfig().instanceKlassConstantsOffset); + constantPool = new HotSpotConstantPool(metaspaceConstantPool); + } + return constantPool; + } + + /** + * Gets the instance size of this type. If an instance of this type cannot be fast path + * allocated, then the returned value is negative (its absolute value gives the size). Must not + * be called if this is an array or interface type. + */ + public int instanceSize() { + assert !isArray(); + assert !isInterface(); + + HotSpotVMConfig config = runtime().getConfig(); + final int layoutHelper = unsafe.getInt(getMetaspaceKlass() + config.klassLayoutHelperOffset); + assert layoutHelper > config.klassLayoutHelperNeutralValue : "must be instance"; + + // See: Klass::layout_helper_size_in_bytes + int size = layoutHelper & ~config.klassLayoutHelperInstanceSlowPathBit; + + // See: Klass::layout_helper_needs_slow_path + boolean needsSlowPath = (layoutHelper & config.klassLayoutHelperInstanceSlowPathBit) != 0; + + return needsSlowPath ? -size : size; + } + + public synchronized HotSpotResolvedJavaMethod createMethod(long metaspaceMethod) { + HotSpotResolvedJavaMethod method = null; + if (methodCache == null) { + methodCache = new HashMap<>(8); + } else { + method = methodCache.get(metaspaceMethod); + } + if (method == null) { + method = new HotSpotResolvedJavaMethodImpl(this, metaspaceMethod); + methodCache.put(metaspaceMethod, method); + } + return method; + } + + public int getVtableLength() { + HotSpotVMConfig config = runtime().getConfig(); + if (isInterface() || isArray()) { + /* Everything has the core vtable of java.lang.Object */ + return config.baseVtableLength; + } + int result = unsafe.getInt(getMetaspaceKlass() + config.instanceKlassVtableLengthOffset) / (config.vtableEntrySize / config.heapWordSize); + assert result >= config.baseVtableLength : unsafe.getInt(getMetaspaceKlass() + config.instanceKlassVtableLengthOffset) + " " + config.vtableEntrySize; + return result; + } + + /** + * Gets the mask used to filter out HotSpot internal flags for fields when a {@link Field} + * object is created. This is the value of {@code JVM_RECOGNIZED_FIELD_MODIFIERS} in + * {@code jvm.h}, not {@link Modifier#fieldModifiers()}. + */ + public static int getReflectionFieldModifiers() { + return runtime().getConfig().recognizedFieldModifiers; + } + + public synchronized HotSpotResolvedJavaField createField(String fieldName, JavaType type, long offset, int rawFlags) { + HotSpotResolvedJavaField result = null; + + final int flags = rawFlags & getReflectionFieldModifiers(); + + final long id = offset + ((long) flags << 32); + + // (thomaswue) Must cache the fields, because the local load elimination only works if the + // objects from two field lookups are identical. + if (fieldCache == null) { + fieldCache = new HashMap<>(8); + } else { + result = fieldCache.get(id); + } + + if (result == null) { + result = new HotSpotResolvedJavaFieldImpl(this, fieldName, type, offset, rawFlags); + fieldCache.put(id, result); + } else { + assert result.getName().equals(fieldName); + // assert result.getType().equals(type); + assert result.offset() == offset; + assert result.getModifiers() == flags; + } + + return result; + } + + @Override + public AssumptionResult findUniqueConcreteMethod(ResolvedJavaMethod method) { + HotSpotResolvedJavaMethod hmethod = (HotSpotResolvedJavaMethod) method; + HotSpotResolvedObjectType declaredHolder = hmethod.getDeclaringClass(); + /* + * Sometimes the receiver type in the graph hasn't stabilized to a subtype of declared + * holder, usually because of phis, so make sure that the type is related to the declared + * type before using it for lookup. Unlinked types should also be ignored because we can't + * resolve the proper method to invoke. Generally unlinked types in invokes should result in + * a deopt instead since they can't really be used if they aren't linked yet. + */ + if (!declaredHolder.isAssignableFrom(this) || this.isArray() || this.equals(declaredHolder) || !isLinked() || isInterface()) { + ResolvedJavaMethod result = hmethod.uniqueConcreteMethod(declaredHolder); + if (result != null) { + return new AssumptionResult<>(result, new ConcreteMethod(method, declaredHolder, result)); + } + return null; + } + /* + * The holder may be a subtype of the declaredHolder so make sure to resolve the method to + * the correct method for the subtype. + */ + HotSpotResolvedJavaMethod resolvedMethod = (HotSpotResolvedJavaMethod) resolveMethod(hmethod, this, true); + if (resolvedMethod == null) { + // The type isn't known to implement the method. + return null; + } + + ResolvedJavaMethod result = resolvedMethod.uniqueConcreteMethod(this); + if (result != null) { + return new AssumptionResult<>(result, new ConcreteMethod(method, this, result)); + } + return null; + } + + /** + * This class represents the field information for one field contained in the fields array of an + * {@code InstanceKlass}. The implementation is similar to the native {@code FieldInfo} class. + */ + private class FieldInfo { + /** + * Native pointer into the array of Java shorts. + */ + private final long metaspaceData; + + /** + * Creates a field info for the field in the fields array at index {@code index}. + * + * @param index index to the fields array + */ + public FieldInfo(int index) { + HotSpotVMConfig config = runtime().getConfig(); + // Get Klass::_fields + final long metaspaceFields = unsafe.getAddress(getMetaspaceKlass() + config.instanceKlassFieldsOffset); + assert config.fieldInfoFieldSlots == 6 : "revisit the field parsing code"; + metaspaceData = metaspaceFields + config.arrayU2DataOffset + config.fieldInfoFieldSlots * Short.BYTES * index; + } + + private int getAccessFlags() { + return readFieldSlot(runtime().getConfig().fieldInfoAccessFlagsOffset); + } + + private int getNameIndex() { + return readFieldSlot(runtime().getConfig().fieldInfoNameIndexOffset); + } + + private int getSignatureIndex() { + return readFieldSlot(runtime().getConfig().fieldInfoSignatureIndexOffset); + } + + public int getOffset() { + HotSpotVMConfig config = runtime().getConfig(); + final int lowPacked = readFieldSlot(config.fieldInfoLowPackedOffset); + final int highPacked = readFieldSlot(config.fieldInfoHighPackedOffset); + final int offset = ((highPacked << Short.SIZE) | lowPacked) >> config.fieldInfoTagSize; + return offset; + } + + /** + * Helper method to read an entry (slot) from the field array. Currently field info is laid + * on top an array of Java shorts. + */ + private int readFieldSlot(int index) { + return unsafe.getChar(metaspaceData + Short.BYTES * index); + } + + /** + * Returns the name of this field as a {@link String}. If the field is an internal field the + * name index is pointing into the vmSymbols table. + */ + public String getName() { + final int nameIndex = getNameIndex(); + return isInternal() ? HotSpotVmSymbols.symbolAt(nameIndex) : constantPool().lookupUtf8(nameIndex); + } + + /** + * Returns the signature of this field as {@link String}. If the field is an internal field + * the signature index is pointing into the vmSymbols table. + */ + public String getSignature() { + final int signatureIndex = getSignatureIndex(); + return isInternal() ? HotSpotVmSymbols.symbolAt(signatureIndex) : constantPool().lookupUtf8(signatureIndex); + } + + public JavaType getType() { + String signature = getSignature(); + return runtime().lookupType(signature, HotSpotResolvedObjectTypeImpl.this, false); + } + + private boolean isInternal() { + return (getAccessFlags() & runtime().getConfig().jvmAccFieldInternal) != 0; + } + + public boolean isStatic() { + return Modifier.isStatic(getAccessFlags()); + } + + public boolean hasGenericSignature() { + return (getAccessFlags() & runtime().getConfig().jvmAccFieldHasGenericSignature) != 0; + } + } + + private static class OffsetComparator implements java.util.Comparator { + @Override + public int compare(HotSpotResolvedJavaField o1, HotSpotResolvedJavaField o2) { + return o1.offset() - o2.offset(); + } + } + + @Override + public ResolvedJavaField[] getInstanceFields(boolean includeSuperclasses) { + if (instanceFields == null) { + if (isArray() || isInterface()) { + instanceFields = new HotSpotResolvedJavaField[0]; + } else { + final int fieldCount = getFieldCount(); + ArrayList fieldsArray = new ArrayList<>(fieldCount); + + for (int i = 0; i < fieldCount; i++) { + FieldInfo field = new FieldInfo(i); + + // We are only interested in instance fields. + if (!field.isStatic()) { + HotSpotResolvedJavaField resolvedJavaField = createField(field.getName(), field.getType(), field.getOffset(), field.getAccessFlags()); + fieldsArray.add(resolvedJavaField); + } + } + + fieldsArray.sort(new OffsetComparator()); + + HotSpotResolvedJavaField[] myFields = fieldsArray.toArray(new HotSpotResolvedJavaField[0]); + + if (mirror() != Object.class) { + HotSpotResolvedJavaField[] superFields = (HotSpotResolvedJavaField[]) getSuperclass().getInstanceFields(true); + HotSpotResolvedJavaField[] fields = Arrays.copyOf(superFields, superFields.length + myFields.length); + System.arraycopy(myFields, 0, fields, superFields.length, myFields.length); + instanceFields = fields; + } else { + assert myFields.length == 0 : "java.lang.Object has fields!"; + instanceFields = myFields; + } + + } + } + if (!includeSuperclasses) { + int myFieldsStart = 0; + while (myFieldsStart < instanceFields.length && !instanceFields[myFieldsStart].getDeclaringClass().equals(this)) { + myFieldsStart++; + } + if (myFieldsStart == 0) { + return instanceFields; + } + if (myFieldsStart == instanceFields.length) { + return new HotSpotResolvedJavaField[0]; + } + return Arrays.copyOfRange(instanceFields, myFieldsStart, instanceFields.length); + } + return instanceFields; + } + + @Override + public ResolvedJavaField[] getStaticFields() { + if (isArray()) { + return new HotSpotResolvedJavaField[0]; + } else { + final int fieldCount = getFieldCount(); + ArrayList fieldsArray = new ArrayList<>(fieldCount); + + for (int i = 0; i < fieldCount; i++) { + FieldInfo field = new FieldInfo(i); + + // We are only interested in static fields. + if (field.isStatic()) { + HotSpotResolvedJavaField resolvedJavaField = createField(field.getName(), field.getType(), field.getOffset(), field.getAccessFlags()); + fieldsArray.add(resolvedJavaField); + } + } + + fieldsArray.sort(new OffsetComparator()); + return fieldsArray.toArray(new HotSpotResolvedJavaField[fieldsArray.size()]); + } + } + + /** + * Returns the actual field count of this class's internal {@code InstanceKlass::_fields} array + * by walking the array and discounting the generic signature slots at the end of the array. + * + *

      + * See {@code FieldStreamBase::init_generic_signature_start_slot} + */ + private int getFieldCount() { + HotSpotVMConfig config = runtime().getConfig(); + final long metaspaceFields = unsafe.getAddress(getMetaspaceKlass() + config.instanceKlassFieldsOffset); + int metaspaceFieldsLength = unsafe.getInt(metaspaceFields + config.arrayU1LengthOffset); + int fieldCount = 0; + + for (int i = 0, index = 0; i < metaspaceFieldsLength; i += config.fieldInfoFieldSlots, index++) { + FieldInfo field = new FieldInfo(index); + if (field.hasGenericSignature()) { + metaspaceFieldsLength--; + } + fieldCount++; + } + return fieldCount; + } + + @Override + public Class mirror() { + return javaClass; + } + + @Override + public String getSourceFileName() { + HotSpotVMConfig config = runtime().getConfig(); + final int sourceFileNameIndex = unsafe.getChar(getMetaspaceKlass() + config.instanceKlassSourceFileNameIndexOffset); + if (sourceFileNameIndex == 0) { + return null; + } + return constantPool().lookupUtf8(sourceFileNameIndex); + } + + @Override + public T getAnnotation(Class annotationClass) { + return mirror().getAnnotation(annotationClass); + } + + /** + * Performs a fast-path check that this type is resolved in the context of a given accessing + * class. A negative result does not mean this type is not resolved with respect to + * {@code accessingClass}. That can only be determined by + * {@linkplain HotSpotJVMCIRuntime#lookupType(String, HotSpotResolvedObjectType, boolean) + * re-resolving} the type. + */ + public boolean isDefinitelyResolvedWithRespectTo(ResolvedJavaType accessingClass) { + assert accessingClass != null; + ResolvedJavaType elementType = getElementalType(); + if (elementType.isPrimitive()) { + // Primitive type resolution is context free. + return true; + } + if (elementType.getName().startsWith("Ljava/")) { + // Classes in a java.* package can only be defined by the + // boot class loader. This is enforced by ClassLoader.preDefineClass() + assert mirror().getClassLoader() == null; + return true; + } + ClassLoader thisCl = mirror().getClassLoader(); + ClassLoader accessingClassCl = ((HotSpotResolvedObjectTypeImpl) accessingClass).mirror().getClassLoader(); + return thisCl == accessingClassCl; + } + + @Override + public ResolvedJavaType resolve(ResolvedJavaType accessingClass) { + if (isDefinitelyResolvedWithRespectTo(requireNonNull(accessingClass))) { + return this; + } + HotSpotResolvedObjectTypeImpl accessingType = (HotSpotResolvedObjectTypeImpl) accessingClass; + return (ResolvedJavaType) runtime().lookupType(getName(), accessingType, true); + } + + /** + * Gets the metaspace Klass boxed in a {@link JavaConstant}. + */ + public JavaConstant klass() { + return HotSpotMetaspaceConstantImpl.forMetaspaceObject(runtime().getHostJVMCIBackend().getTarget().wordKind, getMetaspaceKlass(), this, false); + } + + public boolean isPrimaryType() { + return runtime().getConfig().secondarySuperCacheOffset != superCheckOffset(); + } + + public int superCheckOffset() { + HotSpotVMConfig config = runtime().getConfig(); + return unsafe.getInt(getMetaspaceKlass() + config.superCheckOffsetOffset); + } + + public long prototypeMarkWord() { + HotSpotVMConfig config = runtime().getConfig(); + if (isArray()) { + return config.arrayPrototypeMarkWord(); + } else { + return unsafe.getAddress(getMetaspaceKlass() + config.prototypeMarkWordOffset); + } + } + + @Override + public ResolvedJavaField findInstanceFieldWithOffset(long offset, Kind expectedEntryKind) { + ResolvedJavaField[] declaredFields = getInstanceFields(true); + for (ResolvedJavaField field : declaredFields) { + HotSpotResolvedJavaField resolvedField = (HotSpotResolvedJavaField) field; + long resolvedFieldOffset = resolvedField.offset(); + // @formatter:off + if (ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN && + expectedEntryKind.isPrimitive() && + !expectedEntryKind.equals(Kind.Void) && + resolvedField.getKind().isPrimitive()) { + resolvedFieldOffset += + resolvedField.getKind().getByteCount() - + Math.min(resolvedField.getKind().getByteCount(), 4 + expectedEntryKind.getByteCount()); + } + if (resolvedFieldOffset == offset) { + return field; + } + // @formatter:on + } + return null; + } + + @Override + public URL getClassFilePath() { + Class cls = mirror(); + return cls.getResource(MetaUtil.getSimpleName(cls, true).replace('.', '$') + ".class"); + } + + @Override + public boolean isLocal() { + return mirror().isLocalClass(); + } + + @Override + public boolean isMember() { + return mirror().isMemberClass(); + } + + @Override + public HotSpotResolvedObjectTypeImpl getEnclosingType() { + final Class encl = mirror().getEnclosingClass(); + return encl == null ? null : fromObjectClass(encl); + } + + @Override + public ResolvedJavaMethod[] getDeclaredConstructors() { + Constructor[] constructors = mirror().getDeclaredConstructors(); + ResolvedJavaMethod[] result = new ResolvedJavaMethod[constructors.length]; + for (int i = 0; i < constructors.length; i++) { + result[i] = runtime().getHostJVMCIBackend().getMetaAccess().lookupJavaMethod(constructors[i]); + assert result[i].isConstructor(); + } + return result; + } + + @Override + public ResolvedJavaMethod[] getDeclaredMethods() { + Method[] methods = mirror().getDeclaredMethods(); + ResolvedJavaMethod[] result = new ResolvedJavaMethod[methods.length]; + for (int i = 0; i < methods.length; i++) { + result[i] = runtime().getHostJVMCIBackend().getMetaAccess().lookupJavaMethod(methods[i]); + assert !result[i].isConstructor(); + } + return result; + } + + public ResolvedJavaMethod getClassInitializer() { + final long metaspaceMethod = runtime().getCompilerToVM().getClassInitializer(getMetaspaceKlass()); + if (metaspaceMethod != 0L) { + return createMethod(metaspaceMethod); + } + return null; + } + + @Override + public String toString() { + return "HotSpotType<" + getName() + ", resolved>"; + } + + @Override + public boolean isTrustedInterfaceType() { + return TrustedInterface.class.isAssignableFrom(mirror()); + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotResolvedPrimitiveType.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotResolvedPrimitiveType.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,280 @@ +/* + * Copyright (c) 2011, 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 static java.util.Objects.*; + +import java.lang.annotation.*; +import java.lang.reflect.*; +import java.net.*; + +import com.oracle.jvmci.common.*; +import com.oracle.jvmci.meta.Assumptions.AssumptionResult; +import com.oracle.jvmci.meta.*; + +/** + * Implementation of {@link JavaType} for primitive HotSpot types. + */ +public final class HotSpotResolvedPrimitiveType extends HotSpotResolvedJavaType implements HotSpotProxified { + + private final Kind kind; + + /** + * Creates the JVMCI mirror for a primitive {@link Kind}. + * + *

      + * NOTE: Creating an instance of this class does not install the mirror for the + * {@link Class} type. Use {@link #fromClass(Class)} instead. + *

      + * + * @param kind the Kind to create the mirror for + */ + public HotSpotResolvedPrimitiveType(Kind kind) { + super(String.valueOf(Character.toUpperCase(kind.getTypeChar()))); + this.kind = kind; + assert mirror().isPrimitive() : mirror() + " not a primitive type"; + } + + @Override + public int getModifiers() { + return Modifier.ABSTRACT | Modifier.FINAL | Modifier.PUBLIC; + } + + @Override + public HotSpotResolvedObjectTypeImpl getArrayClass() { + if (kind == Kind.Void) { + return null; + } + Class javaArrayMirror = Array.newInstance(mirror(), 0).getClass(); + return HotSpotResolvedObjectTypeImpl.fromObjectClass(javaArrayMirror); + } + + public ResolvedJavaType getElementalType() { + return this; + } + + @Override + public ResolvedJavaType getComponentType() { + return null; + } + + @Override + public ResolvedJavaType asExactType() { + return this; + } + + @Override + public ResolvedJavaType getSuperclass() { + return null; + } + + @Override + public ResolvedJavaType[] getInterfaces() { + return new ResolvedJavaType[0]; + } + + @Override + public ResolvedJavaType getSingleImplementor() { + throw new JVMCIError("Cannot call getSingleImplementor() on a non-interface type: %s", this); + } + + @Override + public ResolvedJavaType findLeastCommonAncestor(ResolvedJavaType otherType) { + return null; + } + + @Override + public JavaConstant getObjectHub() { + throw JVMCIError.unimplemented(); + } + + @Override + public JavaConstant getJavaClass() { + throw JVMCIError.unimplemented(); + } + + @Override + public AssumptionResult hasFinalizableSubclass() { + return new AssumptionResult<>(false); + } + + @Override + public boolean hasFinalizer() { + return false; + } + + @Override + public boolean isArray() { + return false; + } + + @Override + public boolean isPrimitive() { + return true; + } + + @Override + public boolean isInitialized() { + return true; + } + + public boolean isLinked() { + return true; + } + + @Override + public boolean isInstance(JavaConstant obj) { + return false; + } + + @Override + public boolean isInstanceClass() { + return false; + } + + @Override + public boolean isInterface() { + return false; + } + + @Override + public boolean isAssignableFrom(ResolvedJavaType other) { + assert other != null; + return other.equals(this); + } + + @Override + public Kind getKind() { + return kind; + } + + @Override + public boolean isJavaLangObject() { + return false; + } + + @Override + public ResolvedJavaMethod resolveConcreteMethod(ResolvedJavaMethod method, ResolvedJavaType callerType) { + return null; + } + + @Override + public ResolvedJavaMethod resolveMethod(ResolvedJavaMethod method, ResolvedJavaType callerType, boolean includeAbstract) { + return null; + } + + @Override + public String toString() { + return "HotSpotResolvedPrimitiveType<" + kind + ">"; + } + + @Override + public AssumptionResult findLeafConcreteSubtype() { + return new AssumptionResult<>(this); + } + + @Override + public AssumptionResult findUniqueConcreteMethod(ResolvedJavaMethod method) { + return null; + } + + @Override + public ResolvedJavaField[] getInstanceFields(boolean includeSuperclasses) { + return new ResolvedJavaField[0]; + } + + @Override + public ResolvedJavaField[] getStaticFields() { + return new ResolvedJavaField[0]; + } + + @Override + public T getAnnotation(Class annotationClass) { + return null; + } + + @Override + public ResolvedJavaType resolve(ResolvedJavaType accessingClass) { + requireNonNull(accessingClass); + return this; + } + + @Override + public void initialize() { + } + + @Override + public ResolvedJavaField findInstanceFieldWithOffset(long offset, Kind expectedType) { + return null; + } + + @Override + public String getSourceFileName() { + throw JVMCIError.unimplemented(); + } + + @Override + public Class mirror() { + return kind.toJavaClass(); + } + + @Override + public URL getClassFilePath() { + return null; + } + + @Override + public boolean isLocal() { + return false; + } + + @Override + public boolean isMember() { + return false; + } + + @Override + public ResolvedJavaType getEnclosingType() { + return null; + } + + @Override + public ResolvedJavaMethod[] getDeclaredConstructors() { + return new ResolvedJavaMethod[0]; + } + + @Override + public ResolvedJavaMethod[] getDeclaredMethods() { + return new ResolvedJavaMethod[0]; + } + + @Override + public ResolvedJavaMethod getClassInitializer() { + return null; + } + + @Override + public boolean isTrustedInterfaceType() { + return false; + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotSignature.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotSignature.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,212 @@ +/* + * Copyright (c) 2011, 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; + +import java.util.*; + +import com.oracle.jvmci.common.*; +import com.oracle.jvmci.meta.*; + +/** + * Represents a method signature. + */ +public class HotSpotSignature implements Signature { + + private final List parameters = new ArrayList<>(); + private final String returnType; + private final String originalString; + private ResolvedJavaType[] parameterTypes; + private ResolvedJavaType returnTypeCache; + private final HotSpotJVMCIRuntimeProvider runtime; + + public HotSpotSignature(HotSpotJVMCIRuntimeProvider runtime, String signature) { + this.runtime = runtime; + assert signature.length() > 0; + this.originalString = signature; + + if (signature.charAt(0) == '(') { + int cur = 1; + while (cur < signature.length() && signature.charAt(cur) != ')') { + int nextCur = parseSignature(signature, cur); + parameters.add(signature.substring(cur, nextCur)); + cur = nextCur; + } + + cur++; + int nextCur = parseSignature(signature, cur); + returnType = signature.substring(cur, nextCur); + assert nextCur == signature.length(); + } else { + returnType = null; + } + } + + public HotSpotSignature(HotSpotJVMCIRuntimeProvider runtime, ResolvedJavaType returnType, ResolvedJavaType... parameterTypes) { + this.runtime = runtime; + this.parameterTypes = parameterTypes.clone(); + this.returnTypeCache = returnType; + this.returnType = returnType.getName(); + StringBuilder sb = new StringBuilder("("); + for (JavaType type : parameterTypes) { + parameters.add(type.getName()); + sb.append(type.getName()); + } + sb.append(")").append(returnType.getName()); + this.originalString = sb.toString(); + assert new HotSpotSignature(runtime, originalString).equals(this); + } + + private static int parseSignature(String signature, int start) { + int cur = start; + char first; + do { + first = signature.charAt(cur++); + } while (first == '['); + + switch (first) { + case 'L': + while (signature.charAt(cur) != ';') { + cur++; + } + cur++; + break; + case 'V': + case 'I': + case 'B': + case 'C': + case 'D': + case 'F': + case 'J': + case 'S': + case 'Z': + break; + default: + throw new JVMCIError("Invalid character at index %d in signature: %s", cur, signature); + } + return cur; + } + + @Override + public int getParameterCount(boolean withReceiver) { + return parameters.size() + (withReceiver ? 1 : 0); + } + + @Override + public Kind getParameterKind(int index) { + return Kind.fromTypeString(parameters.get(index)); + } + + private static boolean checkValidCache(ResolvedJavaType type, ResolvedJavaType accessingClass) { + assert accessingClass != null; + if (type == null) { + return false; + } else if (type instanceof HotSpotResolvedObjectTypeImpl) { + return ((HotSpotResolvedObjectTypeImpl) type).isDefinitelyResolvedWithRespectTo(accessingClass); + } + return true; + } + + private static JavaType getUnresolvedOrPrimitiveType(HotSpotJVMCIRuntimeProvider runtime, String name) { + if (name.length() == 1) { + Kind kind = Kind.fromPrimitiveOrVoidTypeChar(name.charAt(0)); + return runtime.getHostJVMCIBackend().getMetaAccess().lookupJavaType(kind.toJavaClass()); + } + return new HotSpotUnresolvedJavaType(name, runtime); + } + + @Override + public JavaType getParameterType(int index, ResolvedJavaType accessingClass) { + if (accessingClass == null) { + // Caller doesn't care about resolution context so return an unresolved + // or primitive type (primitive type resolution is context free) + return getUnresolvedOrPrimitiveType(runtime, parameters.get(index)); + } + if (parameterTypes == null) { + parameterTypes = new ResolvedJavaType[parameters.size()]; + } + + ResolvedJavaType type = parameterTypes[index]; + if (!checkValidCache(type, accessingClass)) { + JavaType result = runtime.lookupType(parameters.get(index), (HotSpotResolvedObjectType) accessingClass, false); + if (result instanceof ResolvedJavaType) { + type = (ResolvedJavaType) result; + parameterTypes[index] = type; + } else { + return result; + } + } + return type; + } + + @Override + public String toMethodDescriptor() { + assert originalString.equals(Signature.super.toMethodDescriptor()); + return originalString; + } + + @Override + public Kind getReturnKind() { + return Kind.fromTypeString(returnType); + } + + @Override + public JavaType getReturnType(ResolvedJavaType accessingClass) { + if (accessingClass == null) { + // Caller doesn't care about resolution context so return an unresolved + // or primitive type (primitive type resolution is context free) + return getUnresolvedOrPrimitiveType(runtime, returnType); + } + if (!checkValidCache(returnTypeCache, accessingClass)) { + JavaType result = runtime.lookupType(returnType, (HotSpotResolvedObjectType) accessingClass, false); + if (result instanceof ResolvedJavaType) { + returnTypeCache = (ResolvedJavaType) result; + } else { + return result; + } + } + return returnTypeCache; + } + + @Override + public String toString() { + return "HotSpotSignature<" + originalString + ">"; + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof HotSpotSignature) { + HotSpotSignature other = (HotSpotSignature) obj; + if (other.originalString.equals(originalString)) { + assert other.parameters.equals(parameters); + assert other.returnType.equals(returnType); + return true; + } + } + return false; + } + + @Override + public int hashCode() { + return originalString.hashCode(); + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotSpeculationLog.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotSpeculationLog.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,34 @@ +/* + * 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.hotspot; + +import com.oracle.jvmci.meta.*; + +public class HotSpotSpeculationLog extends SpeculationLog { + + @Override + public JavaConstant speculate(Object reason) { + addSpeculation(reason); + return HotSpotObjectConstantImpl.forObject(reason); + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotStackFrameReference.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotStackFrameReference.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,92 @@ +/* + * 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 java.util.*; + +import com.oracle.jvmci.code.stack.*; +import com.oracle.jvmci.meta.*; + +public class HotSpotStackFrameReference implements InspectedFrame { + + private CompilerToVM compilerToVM; + + // information used to find the stack frame + private long stackPointer; + private int frameNumber; + + // information about the stack frame's contents + private int bci; + private long metaspaceMethod; + private Object[] locals; + private boolean[] localIsVirtual; + + public long getStackPointer() { + return stackPointer; + } + + public int getFrameNumber() { + return frameNumber; + } + + @Override + public Object getLocal(int index) { + return locals[index]; + } + + @Override + public boolean isVirtual(int index) { + return localIsVirtual == null ? false : localIsVirtual[index]; + } + + @Override + public void materializeVirtualObjects(boolean invalidateCode) { + compilerToVM.materializeVirtualObjects(this, invalidateCode); + } + + @Override + public int getBytecodeIndex() { + return bci; + } + + @Override + public ResolvedJavaMethod getMethod() { + return HotSpotResolvedJavaMethodImpl.fromMetaspace(metaspaceMethod); + } + + @Override + public boolean isMethod(ResolvedJavaMethod method) { + return metaspaceMethod == ((HotSpotResolvedJavaMethodImpl) method).getMetaspaceMethod(); + } + + @Override + public boolean hasVirtualObjects() { + return localIsVirtual != null; + } + + @Override + public String toString() { + return "HotSpotStackFrameReference [stackPointer=" + stackPointer + ", frameNumber=" + frameNumber + ", bci=" + bci + ", method=" + getMethod() + ", locals=" + Arrays.toString(locals) + + ", localIsVirtual=" + Arrays.toString(localIsVirtual) + "]"; + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotTargetDescription.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotTargetDescription.java Tue Jun 09 00:22:49 2015 +0200 @@ -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 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotUnresolvedField.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotUnresolvedField.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,78 @@ +/* + * 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 com.oracle.jvmci.meta.*; + +/** + * A implementation of {@link JavaField} for an unresolved field. + */ +public class HotSpotUnresolvedField implements JavaField { + + private final String name; + private final JavaType holder; + private final JavaType type; + + public HotSpotUnresolvedField(JavaType holder, String name, JavaType type) { + this.name = name; + this.type = type; + this.holder = holder; + } + + public String getName() { + return name; + } + + public JavaType getType() { + return type; + } + + public JavaType getDeclaringClass() { + return holder; + } + + @Override + public int hashCode() { + return super.hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null || !(obj instanceof HotSpotUnresolvedField)) { + return false; + } + HotSpotUnresolvedField that = (HotSpotUnresolvedField) obj; + return this.holder.equals(that.holder) && this.name.equals(that.name) && this.type.equals(that.type); + } + + /** + * Converts this compiler interface field to a string. + */ + @Override + public String toString() { + return format("HotSpotField<%H.%n %t, unresolved>"); + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotUnresolvedJavaType.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotUnresolvedJavaType.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2011, 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; + +import com.oracle.jvmci.meta.*; + +/** + * Implementation of {@link JavaType} for unresolved HotSpot classes. + */ +public class HotSpotUnresolvedJavaType extends HotSpotJavaType { + + private final HotSpotJVMCIRuntimeProvider runtime; + + public HotSpotUnresolvedJavaType(String name, HotSpotJVMCIRuntimeProvider runtime) { + super(name); + assert name.charAt(0) == '[' || name.charAt(name.length() - 1) == ';' : name; + this.runtime = runtime; + } + + /** + * Creates an unresolved type for a valid {@link JavaType#getName() type name}. + */ + public static HotSpotUnresolvedJavaType create(HotSpotJVMCIRuntimeProvider runtime, String name) { + return new HotSpotUnresolvedJavaType(name, runtime); + } + + @Override + public JavaType getComponentType() { + assert getName().charAt(0) == '[' : "no array class" + getName(); + return new HotSpotUnresolvedJavaType(getName().substring(1), runtime); + } + + @Override + public JavaType getArrayClass() { + return new HotSpotUnresolvedJavaType('[' + getName(), runtime); + } + + @Override + public Kind getKind() { + return Kind.Object; + } + + @Override + public int hashCode() { + return getName().hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null || !(obj instanceof HotSpotUnresolvedJavaType)) { + return false; + } + HotSpotUnresolvedJavaType that = (HotSpotUnresolvedJavaType) obj; + return this.getName().equals(that.getName()); + } + + @Override + public String toString() { + return "HotSpotType<" + getName() + ", unresolved>"; + } + + @Override + public ResolvedJavaType resolve(ResolvedJavaType accessingClass) { + return (ResolvedJavaType) runtime.lookupType(getName(), (HotSpotResolvedObjectType) accessingClass, true); + } + + /** + * Try to find a loaded version of this class. + * + * @param accessingClass + * @return the resolved class or null. + */ + ResolvedJavaType reresolve(HotSpotResolvedObjectType accessingClass) { + JavaType type = runtime.lookupType(getName(), accessingClass, false); + if (type instanceof ResolvedJavaType) { + return (ResolvedJavaType) type; + } + return null; + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotVMConfig.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotVMConfig.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,1663 @@ +/* + * Copyright (c) 2011, 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; + +import static com.oracle.jvmci.common.UnsafeAccess.*; + +import java.lang.reflect.*; +import java.util.*; + +import com.oracle.jvmci.common.*; +import com.oracle.jvmci.hotspotvmconfig.*; + +//JaCoCo Exclude + +/** + * Used to access native configuration details. + * + * All non-static, public fields in this class are so that they can be compiled as constants. + */ +public class HotSpotVMConfig { + + /** + * Determines if the current architecture is included in a given architecture set specification. + * + * @param currentArch + * @param archsSpecification specifies a set of architectures. A zero length value implies all + * architectures. + */ + private static boolean isRequired(String currentArch, String[] archsSpecification) { + if (archsSpecification.length == 0) { + return true; + } + for (String arch : archsSpecification) { + if (arch.equals(currentArch)) { + return true; + } + } + return false; + } + + /** + * Maximum allowed size of allocated area for a frame. + */ + public final int maxFrameSize = 16 * 1024; + + @Override + public String toString() { + return getClass().getSimpleName(); + } + + public HotSpotVMConfig(CompilerToVM compilerToVm) { + compilerToVm.initializeConfiguration(this); + assert verifyInitialization(); + + oopEncoding = new CompressEncoding(narrowOopBase, narrowOopShift, logMinObjAlignment()); + klassEncoding = new CompressEncoding(narrowKlassBase, narrowKlassShift, logKlassAlignment); + + codeCacheLowBoundary = unsafe.getAddress(codeCacheHeap + codeHeapMemoryOffset + virtualSpaceLowBoundaryOffset); + codeCacheHighBoundary = unsafe.getAddress(codeCacheHeap + codeHeapMemoryOffset + virtualSpaceHighBoundaryOffset); + + final long barrierSetAddress = unsafe.getAddress(universeCollectedHeap + collectedHeapBarrierSetOffset); + final int kind = unsafe.getInt(barrierSetAddress + barrierSetKindOffset); + if ((kind == barrierSetCardTableModRef) || (kind == barrierSetCardTableExtension) || (kind == barrierSetG1SATBCT) || (kind == barrierSetG1SATBCTLogging)) { + final long base = unsafe.getAddress(barrierSetAddress + cardTableModRefBSByteMapBaseOffset); + assert base != 0 : "unexpected byte_map_base: " + base; + cardtableStartAddress = base; + cardtableShift = cardTableModRefBSCardShift; + } else if ((kind == barrierSetModRef) || (kind == barrierSetOther)) { + // No post barriers + cardtableStartAddress = 0; + cardtableShift = 0; + } else { + cardtableStartAddress = -1; + cardtableShift = -1; + } + + inlineCacheMissStub = inlineCacheMissBlob + unsafe.getInt(inlineCacheMissBlob + codeBlobCodeOffsetOffset); + + assert check(); + assert HotSpotVMConfigVerifier.check(); + } + + /** + * Check that the initialization produces the same result as the values captured through + * vmStructs. + */ + private boolean verifyInitialization() { + /** These fields are set in {@link CompilerToVM#initializeConfiguration}. */ + assert gHotSpotVMStructs != 0; + assert gHotSpotVMTypes != 0; + assert gHotSpotVMIntConstants != 0; + assert gHotSpotVMLongConstants != 0; + + // Fill the VM fields hash map. + HashMap vmFields = new HashMap<>(); + for (VMFields.Field e : new VMFields(gHotSpotVMStructs)) { + vmFields.put(e.getName(), e); + } + + // Fill the VM types hash map. + HashMap vmTypes = new HashMap<>(); + for (VMTypes.Type e : new VMTypes(gHotSpotVMTypes)) { + vmTypes.put(e.getTypeName(), e); + } + + // Fill the VM constants hash map. + HashMap vmConstants = new HashMap<>(); + for (AbstractConstant e : new VMIntConstants(gHotSpotVMIntConstants)) { + vmConstants.put(e.getName(), e); + } + for (AbstractConstant e : new VMLongConstants(gHotSpotVMLongConstants)) { + vmConstants.put(e.getName(), e); + } + + // Fill the flags hash map. + HashMap flags = new HashMap<>(); + for (Flags.Flag e : new Flags(vmFields, vmTypes)) { + flags.put(e.getName(), e); + } + + String currentArch = getHostArchitectureName(); + + for (Field f : HotSpotVMConfig.class.getDeclaredFields()) { + if (f.isAnnotationPresent(HotSpotVMField.class)) { + HotSpotVMField annotation = f.getAnnotation(HotSpotVMField.class); + String name = annotation.name(); + String type = annotation.type(); + VMFields.Field entry = vmFields.get(name); + if (entry == null) { + if (!isRequired(currentArch, annotation.archs())) { + continue; + } + throw new IllegalArgumentException("field not found: " + name); + } + + // Make sure the native type is still the type we expect. + if (!type.equals("")) { + if (!type.equals(entry.getTypeString())) { + throw new IllegalArgumentException("compiler expects type " + type + " but field " + name + " is of type " + entry.getTypeString()); + } + } + + switch (annotation.get()) { + case OFFSET: + checkField(f, entry.getOffset()); + break; + case ADDRESS: + checkField(f, entry.getAddress()); + break; + case VALUE: + checkField(f, entry.getValue()); + break; + default: + throw new JVMCIError("unknown kind %s", annotation.get()); + } + } else if (f.isAnnotationPresent(HotSpotVMType.class)) { + HotSpotVMType annotation = f.getAnnotation(HotSpotVMType.class); + String name = annotation.name(); + VMTypes.Type entry = vmTypes.get(name); + if (entry == null) { + throw new IllegalArgumentException("type not found: " + name); + } + switch (annotation.get()) { + case SIZE: + checkField(f, entry.getSize()); + break; + default: + throw new JVMCIError("unknown kind %s", annotation.get()); + } + } else if (f.isAnnotationPresent(HotSpotVMConstant.class)) { + HotSpotVMConstant annotation = f.getAnnotation(HotSpotVMConstant.class); + String name = annotation.name(); + AbstractConstant entry = vmConstants.get(name); + if (entry == null) { + if (!isRequired(currentArch, annotation.archs())) { + continue; + } + throw new IllegalArgumentException("constant not found: " + name); + } + checkField(f, entry.getValue()); + } else if (f.isAnnotationPresent(HotSpotVMFlag.class)) { + HotSpotVMFlag annotation = f.getAnnotation(HotSpotVMFlag.class); + String name = annotation.name(); + Flags.Flag entry = flags.get(name); + if (entry == null) { + if (annotation.optional() || !isRequired(currentArch, annotation.archs())) { + continue; + } + throw new IllegalArgumentException("flag not found: " + name); + + } + checkField(f, entry.getValue()); + } + } + return true; + } + + private final CompressEncoding oopEncoding; + private final CompressEncoding klassEncoding; + + public CompressEncoding getOopEncoding() { + return oopEncoding; + } + + public CompressEncoding getKlassEncoding() { + return klassEncoding; + } + + private void checkField(Field field, Object value) { + try { + Class fieldType = field.getType(); + if (fieldType == boolean.class) { + if (value instanceof String) { + assert field.getBoolean(this) == Boolean.valueOf((String) value) : field + " " + value + " " + field.getBoolean(this); + } else if (value instanceof Boolean) { + assert field.getBoolean(this) == (boolean) value : field + " " + value + " " + field.getBoolean(this); + } else if (value instanceof Long) { + assert field.getBoolean(this) == (((long) value) != 0) : field + " " + value + " " + field.getBoolean(this); + } else { + throw new JVMCIError(value.getClass().getSimpleName()); + } + } else if (fieldType == int.class) { + if (value instanceof Integer) { + assert field.getInt(this) == (int) value : field + " " + value + " " + field.getInt(this); + } else if (value instanceof Long) { + assert field.getInt(this) == (int) (long) value : field + " " + value + " " + field.getInt(this); + } else { + throw new JVMCIError(value.getClass().getSimpleName()); + } + } else if (fieldType == long.class) { + assert field.getLong(this) == (long) value : field + " " + value + " " + field.getLong(this); + } else { + throw new JVMCIError(field.toString()); + } + } catch (IllegalAccessException e) { + throw new JVMCIError("%s: %s", field, e); + } + } + + /** + * Gets the host architecture name for the purpose of finding the corresponding + * {@linkplain HotSpotJVMCIBackendFactory backend}. + */ + public String getHostArchitectureName() { + String arch = System.getProperty("os.arch"); + switch (arch) { + case "x86_64": + arch = "amd64"; + break; + case "sparcv9": + arch = "sparc"; + break; + } + return arch; + } + + /** + * VMStructEntry (see vmStructs.hpp). + */ + @HotSpotVMValue(expression = "gHotSpotVMStructs", get = HotSpotVMValue.Type.ADDRESS) @Stable private long gHotSpotVMStructs; + @HotSpotVMValue(expression = "gHotSpotVMStructEntryTypeNameOffset") @Stable private long gHotSpotVMStructEntryTypeNameOffset; + @HotSpotVMValue(expression = "gHotSpotVMStructEntryFieldNameOffset") @Stable private long gHotSpotVMStructEntryFieldNameOffset; + @HotSpotVMValue(expression = "gHotSpotVMStructEntryTypeStringOffset") @Stable private long gHotSpotVMStructEntryTypeStringOffset; + @HotSpotVMValue(expression = "gHotSpotVMStructEntryIsStaticOffset") @Stable private long gHotSpotVMStructEntryIsStaticOffset; + @HotSpotVMValue(expression = "gHotSpotVMStructEntryOffsetOffset") @Stable private long gHotSpotVMStructEntryOffsetOffset; + @HotSpotVMValue(expression = "gHotSpotVMStructEntryAddressOffset") @Stable private long gHotSpotVMStructEntryAddressOffset; + @HotSpotVMValue(expression = "gHotSpotVMStructEntryArrayStride") @Stable private long gHotSpotVMStructEntryArrayStride; + + class VMFields implements Iterable { + + private long address; + + public VMFields(long address) { + this.address = address; + } + + public Iterator iterator() { + return new Iterator() { + + private int index = 0; + + private Field current() { + return new Field(address + gHotSpotVMStructEntryArrayStride * index); + } + + /** + * The last entry is identified by a NULL fieldName. + */ + public boolean hasNext() { + Field entry = current(); + return entry.getFieldName() != null; + } + + public Field next() { + Field entry = current(); + index++; + return entry; + } + }; + } + + class Field { + + private long entryAddress; + + Field(long address) { + this.entryAddress = address; + } + + public String getTypeName() { + long typeNameAddress = unsafe.getAddress(entryAddress + gHotSpotVMStructEntryTypeNameOffset); + return readCString(typeNameAddress); + } + + public String getFieldName() { + long fieldNameAddress = unsafe.getAddress(entryAddress + gHotSpotVMStructEntryFieldNameOffset); + return readCString(fieldNameAddress); + } + + public String getTypeString() { + long typeStringAddress = unsafe.getAddress(entryAddress + gHotSpotVMStructEntryTypeStringOffset); + return readCString(typeStringAddress); + } + + public boolean isStatic() { + return unsafe.getInt(entryAddress + gHotSpotVMStructEntryIsStaticOffset) != 0; + } + + public long getOffset() { + return unsafe.getLong(entryAddress + gHotSpotVMStructEntryOffsetOffset); + } + + public long getAddress() { + return unsafe.getAddress(entryAddress + gHotSpotVMStructEntryAddressOffset); + } + + public String getName() { + String typeName = getTypeName(); + String fieldName = getFieldName(); + return typeName + "::" + fieldName; + } + + public long getValue() { + String type = getTypeString(); + switch (type) { + case "int": + return unsafe.getInt(getAddress()); + case "address": + case "intptr_t": + return unsafe.getAddress(getAddress()); + default: + // All foo* types are addresses. + if (type.endsWith("*")) { + return unsafe.getAddress(getAddress()); + } + throw new JVMCIError(type); + } + } + + @Override + public String toString() { + return String.format("Field[typeName=%s, fieldName=%s, typeString=%s, isStatic=%b, offset=%d, address=0x%x]", getTypeName(), getFieldName(), getTypeString(), isStatic(), getOffset(), + getAddress()); + } + } + } + + /** + * VMTypeEntry (see vmStructs.hpp). + */ + @HotSpotVMValue(expression = "gHotSpotVMTypes", get = HotSpotVMValue.Type.ADDRESS) @Stable private long gHotSpotVMTypes; + @HotSpotVMValue(expression = "gHotSpotVMTypeEntryTypeNameOffset") @Stable private long gHotSpotVMTypeEntryTypeNameOffset; + @HotSpotVMValue(expression = "gHotSpotVMTypeEntrySuperclassNameOffset") @Stable private long gHotSpotVMTypeEntrySuperclassNameOffset; + @HotSpotVMValue(expression = "gHotSpotVMTypeEntryIsOopTypeOffset") @Stable private long gHotSpotVMTypeEntryIsOopTypeOffset; + @HotSpotVMValue(expression = "gHotSpotVMTypeEntryIsIntegerTypeOffset") @Stable private long gHotSpotVMTypeEntryIsIntegerTypeOffset; + @HotSpotVMValue(expression = "gHotSpotVMTypeEntryIsUnsignedOffset") @Stable private long gHotSpotVMTypeEntryIsUnsignedOffset; + @HotSpotVMValue(expression = "gHotSpotVMTypeEntrySizeOffset") @Stable private long gHotSpotVMTypeEntrySizeOffset; + @HotSpotVMValue(expression = "gHotSpotVMTypeEntryArrayStride") @Stable private long gHotSpotVMTypeEntryArrayStride; + + class VMTypes implements Iterable { + + private long address; + + public VMTypes(long address) { + this.address = address; + } + + public Iterator iterator() { + return new Iterator() { + + private int index = 0; + + private Type current() { + return new Type(address + gHotSpotVMTypeEntryArrayStride * index); + } + + /** + * The last entry is identified by a NULL type name. + */ + public boolean hasNext() { + Type entry = current(); + return entry.getTypeName() != null; + } + + public Type next() { + Type entry = current(); + index++; + return entry; + } + }; + } + + class Type { + + private long entryAddress; + + Type(long address) { + this.entryAddress = address; + } + + public String getTypeName() { + long typeNameAddress = unsafe.getAddress(entryAddress + gHotSpotVMTypeEntryTypeNameOffset); + return readCString(typeNameAddress); + } + + public String getSuperclassName() { + long superclassNameAddress = unsafe.getAddress(entryAddress + gHotSpotVMTypeEntrySuperclassNameOffset); + return readCString(superclassNameAddress); + } + + public boolean isOopType() { + return unsafe.getInt(entryAddress + gHotSpotVMTypeEntryIsOopTypeOffset) != 0; + } + + public boolean isIntegerType() { + return unsafe.getInt(entryAddress + gHotSpotVMTypeEntryIsIntegerTypeOffset) != 0; + } + + public boolean isUnsigned() { + return unsafe.getInt(entryAddress + gHotSpotVMTypeEntryIsUnsignedOffset) != 0; + } + + public long getSize() { + return unsafe.getLong(entryAddress + gHotSpotVMTypeEntrySizeOffset); + } + + @Override + public String toString() { + return String.format("Type[typeName=%s, superclassName=%s, isOopType=%b, isIntegerType=%b, isUnsigned=%b, size=%d]", getTypeName(), getSuperclassName(), isOopType(), isIntegerType(), + isUnsigned(), getSize()); + } + } + } + + public abstract class AbstractConstant { + + protected long address; + protected long nameOffset; + protected long valueOffset; + + AbstractConstant(long address, long nameOffset, long valueOffset) { + this.address = address; + this.nameOffset = nameOffset; + this.valueOffset = valueOffset; + } + + public String getName() { + long nameAddress = unsafe.getAddress(address + nameOffset); + return readCString(nameAddress); + } + + public abstract long getValue(); + } + + /** + * VMIntConstantEntry (see vmStructs.hpp). + */ + @HotSpotVMValue(expression = "gHotSpotVMIntConstants", get = HotSpotVMValue.Type.ADDRESS) @Stable private long gHotSpotVMIntConstants; + @HotSpotVMValue(expression = "gHotSpotVMIntConstantEntryNameOffset") @Stable private long gHotSpotVMIntConstantEntryNameOffset; + @HotSpotVMValue(expression = "gHotSpotVMIntConstantEntryValueOffset") @Stable private long gHotSpotVMIntConstantEntryValueOffset; + @HotSpotVMValue(expression = "gHotSpotVMIntConstantEntryArrayStride") @Stable private long gHotSpotVMIntConstantEntryArrayStride; + + class VMIntConstants implements Iterable { + + private long address; + + public VMIntConstants(long address) { + this.address = address; + } + + public Iterator iterator() { + return new Iterator() { + + private int index = 0; + + private Constant current() { + return new Constant(address + gHotSpotVMIntConstantEntryArrayStride * index); + } + + /** + * The last entry is identified by a NULL name. + */ + public boolean hasNext() { + Constant entry = current(); + return entry.getName() != null; + } + + public Constant next() { + Constant entry = current(); + index++; + return entry; + } + }; + } + + class Constant extends AbstractConstant { + + Constant(long address) { + super(address, gHotSpotVMIntConstantEntryNameOffset, gHotSpotVMIntConstantEntryValueOffset); + } + + @Override + public long getValue() { + return unsafe.getInt(address + valueOffset); + } + + @Override + public String toString() { + return String.format("IntConstant[name=%s, value=%d (0x%x)]", getName(), getValue(), getValue()); + } + } + } + + /** + * VMLongConstantEntry (see vmStructs.hpp). + */ + @HotSpotVMValue(expression = "gHotSpotVMLongConstants", get = HotSpotVMValue.Type.ADDRESS) @Stable private long gHotSpotVMLongConstants; + @HotSpotVMValue(expression = "gHotSpotVMLongConstantEntryNameOffset") @Stable private long gHotSpotVMLongConstantEntryNameOffset; + @HotSpotVMValue(expression = "gHotSpotVMLongConstantEntryValueOffset") @Stable private long gHotSpotVMLongConstantEntryValueOffset; + @HotSpotVMValue(expression = "gHotSpotVMLongConstantEntryArrayStride") @Stable private long gHotSpotVMLongConstantEntryArrayStride; + + class VMLongConstants implements Iterable { + + private long address; + + public VMLongConstants(long address) { + this.address = address; + } + + public Iterator iterator() { + return new Iterator() { + + private int index = 0; + + private Constant currentEntry() { + return new Constant(address + gHotSpotVMLongConstantEntryArrayStride * index); + } + + /** + * The last entry is identified by a NULL name. + */ + public boolean hasNext() { + Constant entry = currentEntry(); + return entry.getName() != null; + } + + public Constant next() { + Constant entry = currentEntry(); + index++; + return entry; + } + }; + } + + class Constant extends AbstractConstant { + + Constant(long address) { + super(address, gHotSpotVMLongConstantEntryNameOffset, gHotSpotVMLongConstantEntryValueOffset); + } + + @Override + public long getValue() { + return unsafe.getLong(address + valueOffset); + } + + @Override + public String toString() { + return String.format("LongConstant[name=%s, value=%d (0x%x)]", getName(), getValue(), getValue()); + } + } + } + + class Flags implements Iterable { + + private long address; + private long entrySize; + private long typeOffset; + private long nameOffset; + private long addrOffset; + + public Flags(HashMap vmStructs, HashMap vmTypes) { + address = vmStructs.get("Flag::flags").getValue(); + entrySize = vmTypes.get("Flag").getSize(); + typeOffset = vmStructs.get("Flag::_type").getOffset(); + nameOffset = vmStructs.get("Flag::_name").getOffset(); + addrOffset = vmStructs.get("Flag::_addr").getOffset(); + + assert vmTypes.get("bool").getSize() == Byte.BYTES; + assert vmTypes.get("intx").getSize() == Long.BYTES; + assert vmTypes.get("uintx").getSize() == Long.BYTES; + } + + public Iterator iterator() { + return new Iterator() { + + private int index = 0; + + private Flag current() { + return new Flag(address + entrySize * index); + } + + /** + * The last entry is identified by a NULL name. + */ + public boolean hasNext() { + Flag entry = current(); + return entry.getName() != null; + } + + public Flag next() { + Flag entry = current(); + index++; + return entry; + } + }; + } + + class Flag { + + private long entryAddress; + + Flag(long address) { + this.entryAddress = address; + } + + public String getType() { + long typeAddress = unsafe.getAddress(entryAddress + typeOffset); + return readCString(typeAddress); + } + + public String getName() { + long nameAddress = unsafe.getAddress(entryAddress + nameOffset); + return readCString(nameAddress); + } + + public long getAddr() { + return unsafe.getAddress(entryAddress + addrOffset); + } + + public Object getValue() { + switch (getType()) { + case "bool": + return Boolean.valueOf(unsafe.getByte(getAddr()) != 0); + case "intx": + case "uintx": + case "uint64_t": + return Long.valueOf(unsafe.getLong(getAddr())); + case "double": + return Double.valueOf(unsafe.getDouble(getAddr())); + case "ccstr": + case "ccstrlist": + return readCString(getAddr()); + default: + throw new JVMCIError(getType()); + } + } + + @Override + public String toString() { + return String.format("Flag[type=%s, name=%s, value=%s]", getType(), getName(), getValue()); + } + } + } + + // os information, register layout, code generation, ... + @HotSpotVMValue(expression = "DEBUG_ONLY(1) NOT_DEBUG(0)") @Stable public boolean cAssertions; + public final boolean windowsOs = System.getProperty("os.name", "").startsWith("Windows"); + + @HotSpotVMFlag(name = "CodeEntryAlignment") @Stable public int codeEntryAlignment; + @HotSpotVMFlag(name = "VerifyOops") @Stable public boolean verifyOops; + @HotSpotVMFlag(name = "CITime") @Stable public boolean ciTime; + @HotSpotVMFlag(name = "CITimeEach") @Stable public boolean ciTimeEach; + @HotSpotVMFlag(name = "CompileTheWorldStartAt", optional = true) @Stable public int compileTheWorldStartAt; + @HotSpotVMFlag(name = "CompileTheWorldStopAt", optional = true) @Stable public int compileTheWorldStopAt; + @HotSpotVMFlag(name = "DontCompileHugeMethods") @Stable public boolean dontCompileHugeMethods; + @HotSpotVMFlag(name = "HugeMethodLimit") @Stable public int hugeMethodLimit; + @HotSpotVMFlag(name = "PrintInlining") @Stable public boolean printInlining; + @HotSpotVMFlag(name = "JVMCIUseFastLocking") @Stable public boolean useFastLocking; + @HotSpotVMFlag(name = "ForceUnreachable") @Stable public boolean forceUnreachable; + + @HotSpotVMFlag(name = "UseTLAB") @Stable public boolean useTLAB; + @HotSpotVMFlag(name = "UseBiasedLocking") @Stable public boolean useBiasedLocking; + @HotSpotVMFlag(name = "UsePopCountInstruction") @Stable public boolean usePopCountInstruction; + @HotSpotVMFlag(name = "UseCountLeadingZerosInstruction", archs = {"amd64"}) @Stable public boolean useCountLeadingZerosInstruction; + @HotSpotVMFlag(name = "UseCountTrailingZerosInstruction", archs = {"amd64"}) @Stable public boolean useCountTrailingZerosInstruction; + @HotSpotVMFlag(name = "UseAESIntrinsics") @Stable public boolean useAESIntrinsics; + @HotSpotVMFlag(name = "UseCRC32Intrinsics") @Stable public boolean useCRC32Intrinsics; + @HotSpotVMFlag(name = "UseG1GC") @Stable public boolean useG1GC; + @HotSpotVMFlag(name = "UseConcMarkSweepGC") @Stable public boolean useCMSGC; + + @HotSpotVMFlag(name = "AllocatePrefetchStyle") @Stable public int allocatePrefetchStyle; + @HotSpotVMFlag(name = "AllocatePrefetchInstr") @Stable public int allocatePrefetchInstr; + @HotSpotVMFlag(name = "AllocatePrefetchLines") @Stable public int allocatePrefetchLines; + @HotSpotVMFlag(name = "AllocateInstancePrefetchLines") @Stable public int allocateInstancePrefetchLines; + @HotSpotVMFlag(name = "AllocatePrefetchStepSize") @Stable public int allocatePrefetchStepSize; + @HotSpotVMFlag(name = "AllocatePrefetchDistance") @Stable public int allocatePrefetchDistance; + + @HotSpotVMFlag(name = "FlightRecorder", optional = true) @Stable public boolean flightRecorder; + + @HotSpotVMField(name = "Universe::_collectedHeap", type = "CollectedHeap*", get = HotSpotVMField.Type.VALUE) @Stable private long universeCollectedHeap; + @HotSpotVMField(name = "CollectedHeap::_total_collections", type = "unsigned int", get = HotSpotVMField.Type.OFFSET) @Stable private int collectedHeapTotalCollectionsOffset; + + public long gcTotalCollectionsAddress() { + return universeCollectedHeap + collectedHeapTotalCollectionsOffset; + } + + @HotSpotVMFlag(name = "JVMCIDeferredInitBarriers") @Stable public boolean useDeferredInitBarriers; + @HotSpotVMFlag(name = "JVMCIHProfEnabled") @Stable public boolean useHeapProfiler; + + // Compressed Oops related values. + @HotSpotVMFlag(name = "UseCompressedOops") @Stable public boolean useCompressedOops; + @HotSpotVMFlag(name = "UseCompressedClassPointers") @Stable public boolean useCompressedClassPointers; + + @HotSpotVMField(name = "Universe::_narrow_oop._base", type = "address", get = HotSpotVMField.Type.VALUE) @Stable public long narrowOopBase; + @HotSpotVMField(name = "Universe::_narrow_oop._shift", type = "int", get = HotSpotVMField.Type.VALUE) @Stable public int narrowOopShift; + @HotSpotVMFlag(name = "ObjectAlignmentInBytes") @Stable public int objectAlignment; + + public int logMinObjAlignment() { + return (int) (Math.log(objectAlignment) / Math.log(2)); + } + + @HotSpotVMField(name = "Universe::_narrow_klass._base", type = "address", get = HotSpotVMField.Type.VALUE) @Stable public long narrowKlassBase; + @HotSpotVMField(name = "Universe::_narrow_klass._shift", type = "int", get = HotSpotVMField.Type.VALUE) @Stable public int narrowKlassShift; + @HotSpotVMConstant(name = "LogKlassAlignmentInBytes") @Stable public int logKlassAlignment; + + // CPU capabilities + @HotSpotVMFlag(name = "UseSSE") @Stable public int useSSE; + @HotSpotVMFlag(name = "UseAVX", archs = {"amd64"}) @Stable public int useAVX; + + // X86 specific values + @HotSpotVMField(name = "VM_Version::_cpuFeatures", type = "int", get = HotSpotVMField.Type.VALUE, archs = {"amd64"}) @Stable public int x86CPUFeatures; + @HotSpotVMConstant(name = "VM_Version::CPU_CX8", archs = {"amd64"}) @Stable public int cpuCX8; + @HotSpotVMConstant(name = "VM_Version::CPU_CMOV", archs = {"amd64"}) @Stable public int cpuCMOV; + @HotSpotVMConstant(name = "VM_Version::CPU_FXSR", archs = {"amd64"}) @Stable public int cpuFXSR; + @HotSpotVMConstant(name = "VM_Version::CPU_HT", archs = {"amd64"}) @Stable public int cpuHT; + @HotSpotVMConstant(name = "VM_Version::CPU_MMX", archs = {"amd64"}) @Stable public int cpuMMX; + @HotSpotVMConstant(name = "VM_Version::CPU_3DNOW_PREFETCH", archs = {"amd64"}) @Stable public int cpu3DNOWPREFETCH; + @HotSpotVMConstant(name = "VM_Version::CPU_SSE", archs = {"amd64"}) @Stable public int cpuSSE; + @HotSpotVMConstant(name = "VM_Version::CPU_SSE2", archs = {"amd64"}) @Stable public int cpuSSE2; + @HotSpotVMConstant(name = "VM_Version::CPU_SSE3", archs = {"amd64"}) @Stable public int cpuSSE3; + @HotSpotVMConstant(name = "VM_Version::CPU_SSSE3", archs = {"amd64"}) @Stable public int cpuSSSE3; + @HotSpotVMConstant(name = "VM_Version::CPU_SSE4A", archs = {"amd64"}) @Stable public int cpuSSE4A; + @HotSpotVMConstant(name = "VM_Version::CPU_SSE4_1", archs = {"amd64"}) @Stable public int cpuSSE41; + @HotSpotVMConstant(name = "VM_Version::CPU_SSE4_2", archs = {"amd64"}) @Stable public int cpuSSE42; + @HotSpotVMConstant(name = "VM_Version::CPU_POPCNT", archs = {"amd64"}) @Stable public int cpuPOPCNT; + @HotSpotVMConstant(name = "VM_Version::CPU_LZCNT", archs = {"amd64"}) @Stable public int cpuLZCNT; + @HotSpotVMConstant(name = "VM_Version::CPU_TSC", archs = {"amd64"}) @Stable public int cpuTSC; + @HotSpotVMConstant(name = "VM_Version::CPU_TSCINV", archs = {"amd64"}) @Stable public int cpuTSCINV; + @HotSpotVMConstant(name = "VM_Version::CPU_AVX", archs = {"amd64"}) @Stable public int cpuAVX; + @HotSpotVMConstant(name = "VM_Version::CPU_AVX2", archs = {"amd64"}) @Stable public int cpuAVX2; + @HotSpotVMConstant(name = "VM_Version::CPU_AES", archs = {"amd64"}) @Stable public int cpuAES; + @HotSpotVMConstant(name = "VM_Version::CPU_ERMS", archs = {"amd64"}) @Stable public int cpuERMS; + @HotSpotVMConstant(name = "VM_Version::CPU_CLMUL", archs = {"amd64"}) @Stable public int cpuCLMUL; + @HotSpotVMConstant(name = "VM_Version::CPU_BMI1", archs = {"amd64"}) @Stable public int cpuBMI1; + + // SPARC specific values + @HotSpotVMField(name = "VM_Version::_features", type = "int", get = HotSpotVMField.Type.VALUE, archs = {"sparc"}) @Stable public int sparcFeatures; + @HotSpotVMConstant(name = "VM_Version::vis3_instructions_m", archs = {"sparc"}) @Stable public int vis3Instructions; + @HotSpotVMConstant(name = "VM_Version::vis2_instructions_m", archs = {"sparc"}) @Stable public int vis2Instructions; + @HotSpotVMConstant(name = "VM_Version::vis1_instructions_m", archs = {"sparc"}) @Stable public int vis1Instructions; + @HotSpotVMConstant(name = "VM_Version::cbcond_instructions_m", archs = {"sparc"}) @Stable public int cbcondInstructions; + + // offsets, ... + @HotSpotVMFlag(name = "StackShadowPages") @Stable public int stackShadowPages; + @HotSpotVMFlag(name = "UseStackBanging") @Stable public boolean useStackBanging; + @HotSpotVMConstant(name = "STACK_BIAS") @Stable public int stackBias; + + @HotSpotVMField(name = "oopDesc::_mark", type = "markOop", get = HotSpotVMField.Type.OFFSET) @Stable public int markOffset; + @HotSpotVMField(name = "oopDesc::_metadata._klass", type = "Klass*", get = HotSpotVMField.Type.OFFSET) @Stable public int hubOffset; + + @HotSpotVMField(name = "Klass::_prototype_header", type = "markOop", get = HotSpotVMField.Type.OFFSET) @Stable public int prototypeMarkWordOffset; + @HotSpotVMField(name = "Klass::_subklass", type = "Klass*", get = HotSpotVMField.Type.OFFSET) @Stable public int subklassOffset; + @HotSpotVMField(name = "Klass::_next_sibling", type = "Klass*", get = HotSpotVMField.Type.OFFSET) @Stable public int nextSiblingOffset; + @HotSpotVMField(name = "Klass::_super_check_offset", type = "juint", get = HotSpotVMField.Type.OFFSET) @Stable public int superCheckOffsetOffset; + @HotSpotVMField(name = "Klass::_secondary_super_cache", type = "Klass*", get = HotSpotVMField.Type.OFFSET) @Stable public int secondarySuperCacheOffset; + @HotSpotVMField(name = "Klass::_secondary_supers", type = "Array*", get = HotSpotVMField.Type.OFFSET) @Stable public int secondarySupersOffset; + + /** + * The offset of the _java_mirror field (of type {@link Class}) in a Klass. + */ + @HotSpotVMField(name = "Klass::_java_mirror", type = "oop", get = HotSpotVMField.Type.OFFSET) @Stable public int classMirrorOffset; + + @HotSpotVMField(name = "Klass::_super", type = "Klass*", get = HotSpotVMField.Type.OFFSET) @Stable public int klassSuperKlassOffset; + @HotSpotVMField(name = "Klass::_modifier_flags", type = "jint", get = HotSpotVMField.Type.OFFSET) @Stable public int klassModifierFlagsOffset; + @HotSpotVMField(name = "Klass::_access_flags", type = "AccessFlags", get = HotSpotVMField.Type.OFFSET) @Stable public int klassAccessFlagsOffset; + @HotSpotVMField(name = "Klass::_layout_helper", type = "jint", get = HotSpotVMField.Type.OFFSET) @Stable public int klassLayoutHelperOffset; + + @HotSpotVMConstant(name = "Klass::_lh_neutral_value") @Stable public int klassLayoutHelperNeutralValue; + @HotSpotVMConstant(name = "Klass::_lh_instance_slow_path_bit") @Stable public int klassLayoutHelperInstanceSlowPathBit; + @HotSpotVMConstant(name = "Klass::_lh_log2_element_size_shift") @Stable public int layoutHelperLog2ElementSizeShift; + @HotSpotVMConstant(name = "Klass::_lh_log2_element_size_mask") @Stable public int layoutHelperLog2ElementSizeMask; + @HotSpotVMConstant(name = "Klass::_lh_element_type_shift") @Stable public int layoutHelperElementTypeShift; + @HotSpotVMConstant(name = "Klass::_lh_element_type_mask") @Stable public int layoutHelperElementTypeMask; + @HotSpotVMConstant(name = "Klass::_lh_header_size_shift") @Stable public int layoutHelperHeaderSizeShift; + @HotSpotVMConstant(name = "Klass::_lh_header_size_mask") @Stable public int layoutHelperHeaderSizeMask; + @HotSpotVMConstant(name = "Klass::_lh_array_tag_shift") @Stable public int layoutHelperArrayTagShift; + @HotSpotVMConstant(name = "Klass::_lh_array_tag_type_value") @Stable public int layoutHelperArrayTagTypeValue; + @HotSpotVMConstant(name = "Klass::_lh_array_tag_obj_value") @Stable public int layoutHelperArrayTagObjectValue; + + /** + * This filters out the bit that differentiates a type array from an object array. + */ + public int layoutHelperElementTypePrimitiveInPlace() { + return (layoutHelperArrayTagTypeValue & ~layoutHelperArrayTagObjectValue) << layoutHelperArrayTagShift; + } + + /** + * Bit pattern in the klass layout helper that can be used to identify arrays. + */ + public final int arrayKlassLayoutHelperIdentifier = 0x80000000; + + @HotSpotVMField(name = "ArrayKlass::_component_mirror", type = "oop", get = HotSpotVMField.Type.OFFSET) @Stable public int arrayKlassComponentMirrorOffset; + + @HotSpotVMType(name = "vtableEntry", get = HotSpotVMType.Type.SIZE) @Stable public int vtableEntrySize; + @HotSpotVMField(name = "vtableEntry::_method", type = "Method*", get = HotSpotVMField.Type.OFFSET) @Stable public int vtableEntryMethodOffset; + @HotSpotVMValue(expression = "InstanceKlass::vtable_start_offset() * HeapWordSize") @Stable public int instanceKlassVtableStartOffset; + @HotSpotVMValue(expression = "InstanceKlass::vtable_length_offset() * HeapWordSize") @Stable public int instanceKlassVtableLengthOffset; + @HotSpotVMValue(expression = "Universe::base_vtable_size() / vtableEntry::size()") @Stable public int baseVtableLength; + + /** + * The offset of the array length word in an array object's header. + */ + @HotSpotVMValue(expression = "arrayOopDesc::length_offset_in_bytes()") @Stable public int arrayLengthOffset; + + @HotSpotVMField(name = "Array::_length", type = "int", get = HotSpotVMField.Type.OFFSET) @Stable public int arrayU1LengthOffset; + @HotSpotVMField(name = "Array::_data", type = "", get = HotSpotVMField.Type.OFFSET) @Stable public int arrayU1DataOffset; + @HotSpotVMField(name = "Array::_data", type = "", get = HotSpotVMField.Type.OFFSET) @Stable public int arrayU2DataOffset; + @HotSpotVMField(name = "Array::_length", type = "int", get = HotSpotVMField.Type.OFFSET) @Stable public int metaspaceArrayLengthOffset; + @HotSpotVMField(name = "Array::_data[0]", type = "Klass*", get = HotSpotVMField.Type.OFFSET) @Stable public int metaspaceArrayBaseOffset; + + @HotSpotVMField(name = "InstanceKlass::_source_file_name_index", type = "u2", get = HotSpotVMField.Type.OFFSET) @Stable public int instanceKlassSourceFileNameIndexOffset; + @HotSpotVMField(name = "InstanceKlass::_init_state", type = "u1", get = HotSpotVMField.Type.OFFSET) @Stable public int instanceKlassInitStateOffset; + @HotSpotVMField(name = "InstanceKlass::_constants", type = "ConstantPool*", get = HotSpotVMField.Type.OFFSET) @Stable public int instanceKlassConstantsOffset; + @HotSpotVMField(name = "InstanceKlass::_fields", type = "Array*", get = HotSpotVMField.Type.OFFSET) @Stable public int instanceKlassFieldsOffset; + + @HotSpotVMConstant(name = "InstanceKlass::linked") @Stable public int instanceKlassStateLinked; + @HotSpotVMConstant(name = "InstanceKlass::fully_initialized") @Stable public int instanceKlassStateFullyInitialized; + + @HotSpotVMField(name = "ObjArrayKlass::_element_klass", type = "Klass*", get = HotSpotVMField.Type.OFFSET) @Stable public int arrayClassElementOffset; + + @HotSpotVMConstant(name = "FieldInfo::access_flags_offset") @Stable public int fieldInfoAccessFlagsOffset; + @HotSpotVMConstant(name = "FieldInfo::name_index_offset") @Stable public int fieldInfoNameIndexOffset; + @HotSpotVMConstant(name = "FieldInfo::signature_index_offset") @Stable public int fieldInfoSignatureIndexOffset; + @HotSpotVMConstant(name = "FieldInfo::initval_index_offset") @Stable public int fieldInfoInitvalIndexOffset; + @HotSpotVMConstant(name = "FieldInfo::low_packed_offset") @Stable public int fieldInfoLowPackedOffset; + @HotSpotVMConstant(name = "FieldInfo::high_packed_offset") @Stable public int fieldInfoHighPackedOffset; + @HotSpotVMConstant(name = "FieldInfo::field_slots") @Stable public int fieldInfoFieldSlots; + + @HotSpotVMConstant(name = "FIELDINFO_TAG_SIZE") @Stable public int fieldInfoTagSize; + + @HotSpotVMConstant(name = "JVM_ACC_FIELD_INTERNAL") @Stable public int jvmAccFieldInternal; + @HotSpotVMConstant(name = "JVM_ACC_FIELD_STABLE") @Stable public int jvmAccFieldStable; + @HotSpotVMConstant(name = "JVM_ACC_FIELD_HAS_GENERIC_SIGNATURE") @Stable public int jvmAccFieldHasGenericSignature; + @HotSpotVMConstant(name = "JVM_ACC_WRITTEN_FLAGS") @Stable public int jvmAccWrittenFlags; + + @HotSpotVMField(name = "Thread::_tlab", type = "ThreadLocalAllocBuffer", get = HotSpotVMField.Type.OFFSET) @Stable public int threadTlabOffset; + + @HotSpotVMField(name = "JavaThread::_anchor", type = "JavaFrameAnchor", get = HotSpotVMField.Type.OFFSET) @Stable public int javaThreadAnchorOffset; + @HotSpotVMField(name = "JavaThread::_threadObj", type = "oop", get = HotSpotVMField.Type.OFFSET) @Stable public int threadObjectOffset; + @HotSpotVMField(name = "JavaThread::_osthread", type = "OSThread*", get = HotSpotVMField.Type.OFFSET) @Stable public int osThreadOffset; + @HotSpotVMField(name = "JavaThread::_dirty_card_queue", type = "DirtyCardQueue", get = HotSpotVMField.Type.OFFSET) @Stable public int javaThreadDirtyCardQueueOffset; + @HotSpotVMField(name = "JavaThread::_is_method_handle_return", type = "int", get = HotSpotVMField.Type.OFFSET) @Stable public int threadIsMethodHandleReturnOffset; + @HotSpotVMField(name = "JavaThread::_satb_mark_queue", type = "ObjPtrQueue", get = HotSpotVMField.Type.OFFSET) @Stable public int javaThreadSatbMarkQueueOffset; + @HotSpotVMField(name = "JavaThread::_vm_result", type = "oop", get = HotSpotVMField.Type.OFFSET) @Stable public int threadObjectResultOffset; + @HotSpotVMValue(expression = "in_bytes(JavaThread::jvmci_counters_offset())") @Stable public int jvmciCountersThreadOffset; + + /** + * An invalid value for {@link #rtldDefault}. + */ + public static final long INVALID_RTLD_DEFAULT_HANDLE = 0xDEADFACE; + + /** + * Address of the library lookup routine. The C signature of this routine is: + * + *
      +     *     void* (const char *filename, char *ebuf, int ebuflen)
      +     * 
      + */ + @HotSpotVMValue(expression = "os::dll_load", get = HotSpotVMValue.Type.ADDRESS) @Stable public long dllLoad; + + /** + * Address of the library lookup routine. The C signature of this routine is: + * + *
      +     *     void* (void* handle, const char* name)
      +     * 
      + */ + @HotSpotVMValue(expression = "os::dll_lookup", get = HotSpotVMValue.Type.ADDRESS) @Stable public long dllLookup; + + /** + * A pseudo-handle which when used as the first argument to {@link #dllLookup} means lookup will + * return the first occurrence of the desired symbol using the default library search order. If + * this field is {@value #INVALID_RTLD_DEFAULT_HANDLE}, then this capability is not supported on + * the current platform. + */ + @HotSpotVMValue(expression = "RTLD_DEFAULT", defines = {"TARGET_OS_FAMILY_bsd", "TARGET_OS_FAMILY_linux"}, get = HotSpotVMValue.Type.ADDRESS) @Stable public long rtldDefault = INVALID_RTLD_DEFAULT_HANDLE; + + /** + * This field is used to pass exception objects into and out of the runtime system during + * exception handling for compiled code. + *

      + * NOTE: This is not the same as {@link #pendingExceptionOffset}. + */ + @HotSpotVMField(name = "JavaThread::_exception_oop", type = "oop", get = HotSpotVMField.Type.OFFSET) @Stable public int threadExceptionOopOffset; + @HotSpotVMField(name = "JavaThread::_exception_pc", type = "address", get = HotSpotVMField.Type.OFFSET) @Stable public int threadExceptionPcOffset; + + @HotSpotVMField(name = "JavaFrameAnchor::_last_Java_sp", type = "intptr_t*", get = HotSpotVMField.Type.OFFSET) @Stable private int javaFrameAnchorLastJavaSpOffset; + @HotSpotVMField(name = "JavaFrameAnchor::_last_Java_pc", type = "address", get = HotSpotVMField.Type.OFFSET) @Stable private int javaFrameAnchorLastJavaPcOffset; + @HotSpotVMField(name = "JavaFrameAnchor::_last_Java_fp", type = "intptr_t*", get = HotSpotVMField.Type.OFFSET, archs = {"amd64"}) @Stable private int javaFrameAnchorLastJavaFpOffset; + @HotSpotVMField(name = "JavaFrameAnchor::_flags", type = "int", get = HotSpotVMField.Type.OFFSET, archs = {"sparc"}) @Stable private int javaFrameAnchorFlagsOffset; + + public int threadLastJavaSpOffset() { + return javaThreadAnchorOffset + javaFrameAnchorLastJavaSpOffset; + } + + public int threadLastJavaPcOffset() { + return javaThreadAnchorOffset + javaFrameAnchorLastJavaPcOffset; + } + + /** + * This value is only valid on AMD64. + */ + public int threadLastJavaFpOffset() { + // TODO add an assert for AMD64 + return javaThreadAnchorOffset + javaFrameAnchorLastJavaFpOffset; + } + + /** + * This value is only valid on SPARC. + */ + public int threadJavaFrameAnchorFlagsOffset() { + // TODO add an assert for SPARC + return javaThreadAnchorOffset + javaFrameAnchorFlagsOffset; + } + + // These are only valid on AMD64. + @HotSpotVMConstant(name = "frame::arg_reg_save_area_bytes", archs = {"amd64"}) @Stable public int runtimeCallStackSize; + @HotSpotVMConstant(name = "frame::interpreter_frame_sender_sp_offset", archs = {"amd64"}) @Stable public int frameInterpreterFrameSenderSpOffset; + @HotSpotVMConstant(name = "frame::interpreter_frame_last_sp_offset", archs = {"amd64"}) @Stable public int frameInterpreterFrameLastSpOffset; + + @HotSpotVMField(name = "PtrQueue::_active", type = "bool", get = HotSpotVMField.Type.OFFSET) @Stable public int ptrQueueActiveOffset; + @HotSpotVMField(name = "PtrQueue::_buf", type = "void**", get = HotSpotVMField.Type.OFFSET) @Stable public int ptrQueueBufferOffset; + @HotSpotVMField(name = "PtrQueue::_index", type = "size_t", get = HotSpotVMField.Type.OFFSET) @Stable public int ptrQueueIndexOffset; + + @HotSpotVMField(name = "OSThread::_interrupted", type = "jint", get = HotSpotVMField.Type.OFFSET) @Stable public int osThreadInterruptedOffset; + + @HotSpotVMConstant(name = "markOopDesc::unlocked_value") @Stable public int unlockedMask; + @HotSpotVMConstant(name = "markOopDesc::biased_lock_mask_in_place") @Stable public int biasedLockMaskInPlace; + @HotSpotVMConstant(name = "markOopDesc::age_mask_in_place") @Stable public int ageMaskInPlace; + @HotSpotVMConstant(name = "markOopDesc::epoch_mask_in_place") @Stable public int epochMaskInPlace; + + @HotSpotVMConstant(name = "markOopDesc::hash_shift") @Stable public long markOopDescHashShift; + @HotSpotVMConstant(name = "markOopDesc::hash_mask") @Stable public long markOopDescHashMask; + @HotSpotVMConstant(name = "markOopDesc::hash_mask_in_place") @Stable public long markOopDescHashMaskInPlace; + + @HotSpotVMConstant(name = "markOopDesc::biased_lock_pattern") @Stable public int biasedLockPattern; + @HotSpotVMConstant(name = "markOopDesc::no_hash_in_place") @Stable public int markWordNoHashInPlace; + @HotSpotVMConstant(name = "markOopDesc::no_lock_in_place") @Stable public int markWordNoLockInPlace; + + /** + * See markOopDesc::prototype(). + */ + public long arrayPrototypeMarkWord() { + return markWordNoHashInPlace | markWordNoLockInPlace; + } + + /** + * See markOopDesc::copy_set_hash(). + */ + public long tlabIntArrayMarkWord() { + long tmp = arrayPrototypeMarkWord() & (~markOopDescHashMaskInPlace); + tmp |= ((0x2 & markOopDescHashMask) << markOopDescHashShift); + return tmp; + } + + /** + * Offset of the _pending_exception field in ThreadShadow (defined in exceptions.hpp). This + * field is used to propagate exceptions through C/C++ calls. + *

      + * NOTE: This is not the same as {@link #threadExceptionOopOffset}. + */ + @HotSpotVMField(name = "ThreadShadow::_pending_exception", type = "oop", get = HotSpotVMField.Type.OFFSET) @Stable public int pendingExceptionOffset; + @HotSpotVMField(name = "ThreadShadow::_pending_deoptimization", type = "int", get = HotSpotVMField.Type.OFFSET) @Stable public int pendingDeoptimizationOffset; + @HotSpotVMField(name = "ThreadShadow::_pending_failed_speculation", type = "oop", get = HotSpotVMField.Type.OFFSET) @Stable public int pendingFailedSpeculationOffset; + @HotSpotVMField(name = "ThreadShadow::_pending_transfer_to_interpreter", type = "bool", get = HotSpotVMField.Type.OFFSET) @Stable public int pendingTransferToInterpreterOffset; + + /** + * Mark word right shift to get identity hash code. + */ + @HotSpotVMConstant(name = "markOopDesc::hash_shift") @Stable public int identityHashCodeShift; + + /** + * Identity hash code value when uninitialized. + */ + @HotSpotVMConstant(name = "markOopDesc::no_hash") @Stable public int uninitializedIdentityHashCodeValue; + + @HotSpotVMField(name = "Method::_access_flags", type = "AccessFlags", get = HotSpotVMField.Type.OFFSET) @Stable public int methodAccessFlagsOffset; + @HotSpotVMField(name = "Method::_constMethod", type = "ConstMethod*", get = HotSpotVMField.Type.OFFSET) @Stable public int methodConstMethodOffset; + @HotSpotVMField(name = "Method::_intrinsic_id", type = "u1", get = HotSpotVMField.Type.OFFSET) @Stable public int methodIntrinsicIdOffset; + @HotSpotVMField(name = "Method::_flags", type = "u1", get = HotSpotVMField.Type.OFFSET) @Stable public int methodFlagsOffset; + @HotSpotVMField(name = "Method::_vtable_index", type = "int", get = HotSpotVMField.Type.OFFSET) @Stable public int methodVtableIndexOffset; + + @HotSpotVMConstant(name = "Method::_jfr_towrite") @Stable public int methodFlagsJfrTowrite; + @HotSpotVMConstant(name = "Method::_caller_sensitive") @Stable public int methodFlagsCallerSensitive; + @HotSpotVMConstant(name = "Method::_force_inline") @Stable public int methodFlagsForceInline; + @HotSpotVMConstant(name = "Method::_dont_inline") @Stable public int methodFlagsDontInline; + @HotSpotVMConstant(name = "Method::_hidden") @Stable public int methodFlagsHidden; + @HotSpotVMConstant(name = "Method::nonvirtual_vtable_index") @Stable public int nonvirtualVtableIndex; + @HotSpotVMConstant(name = "Method::invalid_vtable_index") @Stable public int invalidVtableIndex; + + @HotSpotVMConstant(name = "InvocationEntryBci") @Stable public int invocationEntryBci; + + @HotSpotVMConstant(name = "JVM_ACC_MONITOR_MATCH") @Stable public int jvmAccMonitorMatch; + @HotSpotVMConstant(name = "JVM_ACC_HAS_MONITOR_BYTECODES") @Stable public int jvmAccHasMonitorBytecodes; + + @HotSpotVMField(name = "JVMCIEnv::_task", type = "CompileTask*", get = HotSpotVMField.Type.OFFSET) @Stable public int jvmciEnvTaskOffset; + @HotSpotVMField(name = "JVMCIEnv::_jvmti_can_hotswap_or_post_breakpoint", type = "bool", get = HotSpotVMField.Type.OFFSET) @Stable public int jvmciEnvJvmtiCanHotswapOrPostBreakpointOffset; + @HotSpotVMField(name = "CompileTask::_num_inlined_bytecodes", type = "int", get = HotSpotVMField.Type.OFFSET) @Stable public int compileTaskNumInlinedBytecodesOffset; + + /** + * Value of Method::extra_stack_entries(). + */ + @HotSpotVMValue(expression = "Method::extra_stack_entries()") @Stable public int extraStackEntries; + + @HotSpotVMField(name = "ConstMethod::_constants", type = "ConstantPool*", get = HotSpotVMField.Type.OFFSET) @Stable public int constMethodConstantsOffset; + @HotSpotVMField(name = "ConstMethod::_flags", type = "u2", get = HotSpotVMField.Type.OFFSET) @Stable public int constMethodFlagsOffset; + @HotSpotVMField(name = "ConstMethod::_code_size", type = "u2", get = HotSpotVMField.Type.OFFSET) @Stable public int constMethodCodeSizeOffset; + @HotSpotVMField(name = "ConstMethod::_name_index", type = "u2", get = HotSpotVMField.Type.OFFSET) @Stable public int constMethodNameIndexOffset; + @HotSpotVMField(name = "ConstMethod::_signature_index", type = "u2", get = HotSpotVMField.Type.OFFSET) @Stable public int constMethodSignatureIndexOffset; + @HotSpotVMField(name = "ConstMethod::_max_stack", type = "u2", get = HotSpotVMField.Type.OFFSET) @Stable public int constMethodMaxStackOffset; + @HotSpotVMField(name = "ConstMethod::_max_locals", type = "u2", get = HotSpotVMField.Type.OFFSET) @Stable public int methodMaxLocalsOffset; + + @HotSpotVMConstant(name = "ConstMethod::_has_linenumber_table") @Stable public int constMethodHasLineNumberTable; + @HotSpotVMConstant(name = "ConstMethod::_has_localvariable_table") @Stable public int constMethodHasLocalVariableTable; + @HotSpotVMConstant(name = "ConstMethod::_has_exception_table") @Stable public int constMethodHasExceptionTable; + + @HotSpotVMType(name = "ExceptionTableElement", get = HotSpotVMType.Type.SIZE) @Stable public int exceptionTableElementSize; + @HotSpotVMField(name = "ExceptionTableElement::start_pc", type = "u2", get = HotSpotVMField.Type.OFFSET) @Stable public int exceptionTableElementStartPcOffset; + @HotSpotVMField(name = "ExceptionTableElement::end_pc", type = "u2", get = HotSpotVMField.Type.OFFSET) @Stable public int exceptionTableElementEndPcOffset; + @HotSpotVMField(name = "ExceptionTableElement::handler_pc", type = "u2", get = HotSpotVMField.Type.OFFSET) @Stable public int exceptionTableElementHandlerPcOffset; + @HotSpotVMField(name = "ExceptionTableElement::catch_type_index", type = "u2", get = HotSpotVMField.Type.OFFSET) @Stable public int exceptionTableElementCatchTypeIndexOffset; + + @HotSpotVMType(name = "LocalVariableTableElement", get = HotSpotVMType.Type.SIZE) @Stable public int localVariableTableElementSize; + @HotSpotVMField(name = "LocalVariableTableElement::start_bci", type = "u2", get = HotSpotVMField.Type.OFFSET) @Stable public int localVariableTableElementStartBciOffset; + @HotSpotVMField(name = "LocalVariableTableElement::length", type = "u2", get = HotSpotVMField.Type.OFFSET) @Stable public int localVariableTableElementLengthOffset; + @HotSpotVMField(name = "LocalVariableTableElement::name_cp_index", type = "u2", get = HotSpotVMField.Type.OFFSET) @Stable public int localVariableTableElementNameCpIndexOffset; + @HotSpotVMField(name = "LocalVariableTableElement::descriptor_cp_index", type = "u2", get = HotSpotVMField.Type.OFFSET) @Stable public int localVariableTableElementDescriptorCpIndexOffset; + @HotSpotVMField(name = "LocalVariableTableElement::signature_cp_index", type = "u2", get = HotSpotVMField.Type.OFFSET) @Stable public int localVariableTableElementSignatureCpIndexOffset; + @HotSpotVMField(name = "LocalVariableTableElement::slot", type = "u2", get = HotSpotVMField.Type.OFFSET) @Stable public int localVariableTableElementSlotOffset; + + @HotSpotVMType(name = "ConstantPool", get = HotSpotVMType.Type.SIZE) @Stable public int constantPoolSize; + @HotSpotVMField(name = "ConstantPool::_tags", type = "Array*", get = HotSpotVMField.Type.OFFSET) @Stable public int constantPoolTagsOffset; + @HotSpotVMField(name = "ConstantPool::_pool_holder", type = "InstanceKlass*", get = HotSpotVMField.Type.OFFSET) @Stable public int constantPoolHolderOffset; + @HotSpotVMField(name = "ConstantPool::_length", type = "int", get = HotSpotVMField.Type.OFFSET) @Stable public int constantPoolLengthOffset; + + @HotSpotVMConstant(name = "ConstantPool::CPCACHE_INDEX_TAG") @Stable public int constantPoolCpCacheIndexTag; + + @HotSpotVMConstant(name = "JVM_CONSTANT_Utf8") @Stable public int jvmConstantUtf8; + @HotSpotVMConstant(name = "JVM_CONSTANT_Integer") @Stable public int jvmConstantInteger; + @HotSpotVMConstant(name = "JVM_CONSTANT_Long") @Stable public int jvmConstantLong; + @HotSpotVMConstant(name = "JVM_CONSTANT_Float") @Stable public int jvmConstantFloat; + @HotSpotVMConstant(name = "JVM_CONSTANT_Double") @Stable public int jvmConstantDouble; + @HotSpotVMConstant(name = "JVM_CONSTANT_Class") @Stable public int jvmConstantClass; + @HotSpotVMConstant(name = "JVM_CONSTANT_UnresolvedClass") @Stable public int jvmConstantUnresolvedClass; + @HotSpotVMConstant(name = "JVM_CONSTANT_UnresolvedClassInError") @Stable public int jvmConstantUnresolvedClassInError; + @HotSpotVMConstant(name = "JVM_CONSTANT_String") @Stable public int jvmConstantString; + @HotSpotVMConstant(name = "JVM_CONSTANT_Fieldref") @Stable public int jvmConstantFieldref; + @HotSpotVMConstant(name = "JVM_CONSTANT_Methodref") @Stable public int jvmConstantMethodref; + @HotSpotVMConstant(name = "JVM_CONSTANT_InterfaceMethodref") @Stable public int jvmConstantInterfaceMethodref; + @HotSpotVMConstant(name = "JVM_CONSTANT_NameAndType") @Stable public int jvmConstantNameAndType; + @HotSpotVMConstant(name = "JVM_CONSTANT_MethodHandle") @Stable public int jvmConstantMethodHandle; + @HotSpotVMConstant(name = "JVM_CONSTANT_MethodHandleInError") @Stable public int jvmConstantMethodHandleInError; + @HotSpotVMConstant(name = "JVM_CONSTANT_MethodType") @Stable public int jvmConstantMethodType; + @HotSpotVMConstant(name = "JVM_CONSTANT_MethodTypeInError") @Stable public int jvmConstantMethodTypeInError; + @HotSpotVMConstant(name = "JVM_CONSTANT_InvokeDynamic") @Stable public int jvmConstantInvokeDynamic; + + @HotSpotVMConstant(name = "JVM_CONSTANT_ExternalMax") @Stable public int jvmConstantExternalMax; + @HotSpotVMConstant(name = "JVM_CONSTANT_InternalMin") @Stable public int jvmConstantInternalMin; + @HotSpotVMConstant(name = "JVM_CONSTANT_InternalMax") @Stable public int jvmConstantInternalMax; + + @HotSpotVMConstant(name = "HeapWordSize") @Stable public int heapWordSize; + + @HotSpotVMType(name = "Symbol*", get = HotSpotVMType.Type.SIZE) @Stable public int symbolPointerSize; + @HotSpotVMField(name = "Symbol::_length", type = "unsigned short", get = HotSpotVMField.Type.OFFSET) @Stable public int symbolLengthOffset; + @HotSpotVMField(name = "Symbol::_body[0]", type = "jbyte", get = HotSpotVMField.Type.OFFSET) @Stable public int symbolBodyOffset; + + @HotSpotVMField(name = "vmSymbols::_symbols[0]", type = "Symbol*", get = HotSpotVMField.Type.ADDRESS) @Stable public long vmSymbolsSymbols; + @HotSpotVMConstant(name = "vmSymbols::FIRST_SID") @Stable public int vmSymbolsFirstSID; + @HotSpotVMConstant(name = "vmSymbols::SID_LIMIT") @Stable public int vmSymbolsSIDLimit; + + @HotSpotVMConstant(name = "JVM_ACC_HAS_FINALIZER") @Stable public int klassHasFinalizerFlag; + + // Modifier.SYNTHETIC is not public so we get it via vmStructs. + @HotSpotVMConstant(name = "JVM_ACC_SYNTHETIC") @Stable public int syntheticFlag; + + /** + * @see HotSpotResolvedObjectTypeImpl#createField + */ + @HotSpotVMConstant(name = "JVM_RECOGNIZED_FIELD_MODIFIERS") @Stable public int recognizedFieldModifiers; + + /** + * Bit pattern that represents a non-oop. Neither the high bits nor the low bits of this value + * are allowed to look like (respectively) the high or low bits of a real oop. + */ + @HotSpotVMField(name = "Universe::_non_oop_bits", type = "intptr_t", get = HotSpotVMField.Type.VALUE) @Stable public long nonOopBits; + + @HotSpotVMField(name = "StubRoutines::_verify_oop_count", type = "jint", get = HotSpotVMField.Type.ADDRESS) @Stable public long verifyOopCounterAddress; + @HotSpotVMValue(expression = "Universe::verify_oop_mask()") @Stable public long verifyOopMask; + @HotSpotVMValue(expression = "Universe::verify_oop_bits()") @Stable public long verifyOopBits; + + @HotSpotVMField(name = "CollectedHeap::_barrier_set", type = "BarrierSet*", get = HotSpotVMField.Type.OFFSET) @Stable public int collectedHeapBarrierSetOffset; + + @HotSpotVMField(name = "HeapRegion::LogOfHRGrainBytes", type = "int", get = HotSpotVMField.Type.VALUE) @Stable public int logOfHRGrainBytes; + + @HotSpotVMField(name = "BarrierSet::_kind", type = "BarrierSet::Name", get = HotSpotVMField.Type.OFFSET) @Stable private int barrierSetKindOffset; + @HotSpotVMConstant(name = "BarrierSet::CardTableModRef") @Stable public int barrierSetCardTableModRef; + @HotSpotVMConstant(name = "BarrierSet::CardTableExtension") @Stable public int barrierSetCardTableExtension; + @HotSpotVMConstant(name = "BarrierSet::G1SATBCT") @Stable public int barrierSetG1SATBCT; + @HotSpotVMConstant(name = "BarrierSet::G1SATBCTLogging") @Stable public int barrierSetG1SATBCTLogging; + @HotSpotVMConstant(name = "BarrierSet::ModRef") @Stable public int barrierSetModRef; + @HotSpotVMConstant(name = "BarrierSet::Other") @Stable public int barrierSetOther; + + @HotSpotVMField(name = "CardTableModRefBS::byte_map_base", type = "jbyte*", get = HotSpotVMField.Type.OFFSET) @Stable private int cardTableModRefBSByteMapBaseOffset; + @HotSpotVMConstant(name = "CardTableModRefBS::card_shift") @Stable public int cardTableModRefBSCardShift; + + @HotSpotVMValue(expression = "(jbyte)CardTableModRefBS::dirty_card_val()") @Stable public byte dirtyCardValue; + @HotSpotVMValue(expression = "(jbyte)G1SATBCardTableModRefBS::g1_young_card_val()") @Stable public byte g1YoungCardValue; + + private final long cardtableStartAddress; + private final int cardtableShift; + + public long cardtableStartAddress() { + if (cardtableStartAddress == -1) { + throw JVMCIError.shouldNotReachHere(); + } + return cardtableStartAddress; + } + + public int cardtableShift() { + if (cardtableShift == -1) { + throw JVMCIError.shouldNotReachHere(); + } + return cardtableShift; + } + + @HotSpotVMField(name = "os::_polling_page", type = "address", get = HotSpotVMField.Type.VALUE) @Stable public long safepointPollingAddress; + + // G1 Collector Related Values. + + public int g1CardQueueIndexOffset() { + return javaThreadDirtyCardQueueOffset + ptrQueueIndexOffset; + } + + public int g1CardQueueBufferOffset() { + return javaThreadDirtyCardQueueOffset + ptrQueueBufferOffset; + } + + public int g1SATBQueueMarkingOffset() { + return javaThreadSatbMarkQueueOffset + ptrQueueActiveOffset; + } + + public int g1SATBQueueIndexOffset() { + return javaThreadSatbMarkQueueOffset + ptrQueueIndexOffset; + } + + public int g1SATBQueueBufferOffset() { + return javaThreadSatbMarkQueueOffset + ptrQueueBufferOffset; + } + + @HotSpotVMField(name = "java_lang_Class::_klass_offset", type = "int", get = HotSpotVMField.Type.VALUE) @Stable public int klassOffset; + @HotSpotVMField(name = "java_lang_Class::_array_klass_offset", type = "int", get = HotSpotVMField.Type.VALUE) @Stable public int arrayKlassOffset; + + @HotSpotVMField(name = "Method::_method_data", type = "MethodData*", get = HotSpotVMField.Type.OFFSET) @Stable public int methodDataOffset; + @HotSpotVMField(name = "Method::_from_compiled_entry", type = "address", get = HotSpotVMField.Type.OFFSET) @Stable public int methodCompiledEntryOffset; + @HotSpotVMField(name = "Method::_code", type = "nmethod*", get = HotSpotVMField.Type.OFFSET) @Stable public int methodCodeOffset; + + @HotSpotVMField(name = "MethodData::_size", type = "int", get = HotSpotVMField.Type.OFFSET) @Stable public int methodDataSize; + @HotSpotVMField(name = "MethodData::_data_size", type = "int", get = HotSpotVMField.Type.OFFSET) @Stable public int methodDataDataSize; + @HotSpotVMField(name = "MethodData::_data[0]", type = "intptr_t", get = HotSpotVMField.Type.OFFSET) @Stable public int methodDataOopDataOffset; + @HotSpotVMField(name = "MethodData::_trap_hist._array[0]", type = "u1", get = HotSpotVMField.Type.OFFSET) @Stable public int methodDataOopTrapHistoryOffset; + @HotSpotVMField(name = "MethodData::_jvmci_ir_size", type = "int", get = HotSpotVMField.Type.OFFSET) @Stable public int methodDataIRSizeOffset; + + @HotSpotVMField(name = "nmethod::_verified_entry_point", type = "address", get = HotSpotVMField.Type.OFFSET) @Stable public int nmethodEntryOffset; + @HotSpotVMField(name = "nmethod::_comp_level", type = "int", get = HotSpotVMField.Type.OFFSET) @Stable public int nmethodCompLevelOffset; + + @HotSpotVMConstant(name = "CompLevel_full_optimization") @Stable public int compilationLevelFullOptimization; + + @HotSpotVMType(name = "BasicLock", get = HotSpotVMType.Type.SIZE) @Stable public int basicLockSize; + @HotSpotVMField(name = "BasicLock::_displaced_header", type = "markOop", get = HotSpotVMField.Type.OFFSET) @Stable public int basicLockDisplacedHeaderOffset; + + @HotSpotVMValue(expression = "Universe::heap()->supports_inline_contig_alloc() ? Universe::heap()->end_addr() : (HeapWord**)-1", get = HotSpotVMValue.Type.ADDRESS) @Stable public long heapEndAddress; + @HotSpotVMValue(expression = "Universe::heap()->supports_inline_contig_alloc() ? Universe::heap()->top_addr() : (HeapWord**)-1", get = HotSpotVMValue.Type.ADDRESS) @Stable public long heapTopAddress; + + @HotSpotVMField(name = "Thread::_allocated_bytes", type = "jlong", get = HotSpotVMField.Type.OFFSET) @Stable public int threadAllocatedBytesOffset; + + @HotSpotVMFlag(name = "TLABWasteIncrement") @Stable public int tlabRefillWasteIncrement; + @HotSpotVMValue(expression = "ThreadLocalAllocBuffer::alignment_reserve()") @Stable public int tlabAlignmentReserve; + + @HotSpotVMField(name = "ThreadLocalAllocBuffer::_start", type = "HeapWord*", get = HotSpotVMField.Type.OFFSET) @Stable private int threadLocalAllocBufferStartOffset; + @HotSpotVMField(name = "ThreadLocalAllocBuffer::_end", type = "HeapWord*", get = HotSpotVMField.Type.OFFSET) @Stable private int threadLocalAllocBufferEndOffset; + @HotSpotVMField(name = "ThreadLocalAllocBuffer::_top", type = "HeapWord*", get = HotSpotVMField.Type.OFFSET) @Stable private int threadLocalAllocBufferTopOffset; + @HotSpotVMField(name = "ThreadLocalAllocBuffer::_pf_top", type = "HeapWord*", get = HotSpotVMField.Type.OFFSET) @Stable private int threadLocalAllocBufferPfTopOffset; + @HotSpotVMField(name = "ThreadLocalAllocBuffer::_slow_allocations", type = "unsigned", get = HotSpotVMField.Type.OFFSET) @Stable private int threadLocalAllocBufferSlowAllocationsOffset; + @HotSpotVMField(name = "ThreadLocalAllocBuffer::_fast_refill_waste", type = "unsigned", get = HotSpotVMField.Type.OFFSET) @Stable private int threadLocalAllocBufferFastRefillWasteOffset; + @HotSpotVMField(name = "ThreadLocalAllocBuffer::_number_of_refills", type = "unsigned", get = HotSpotVMField.Type.OFFSET) @Stable private int threadLocalAllocBufferNumberOfRefillsOffset; + @HotSpotVMField(name = "ThreadLocalAllocBuffer::_refill_waste_limit", type = "size_t", get = HotSpotVMField.Type.OFFSET) @Stable private int threadLocalAllocBufferRefillWasteLimitOffset; + @HotSpotVMField(name = "ThreadLocalAllocBuffer::_desired_size", type = "size_t", get = HotSpotVMField.Type.OFFSET) @Stable private int threadLocalAllocBufferDesiredSizeOffset; + + public int tlabSlowAllocationsOffset() { + return threadTlabOffset + threadLocalAllocBufferSlowAllocationsOffset; + } + + public int tlabFastRefillWasteOffset() { + return threadTlabOffset + threadLocalAllocBufferFastRefillWasteOffset; + } + + public int tlabNumberOfRefillsOffset() { + return threadTlabOffset + threadLocalAllocBufferNumberOfRefillsOffset; + } + + public int tlabRefillWasteLimitOffset() { + return threadTlabOffset + threadLocalAllocBufferRefillWasteLimitOffset; + } + + public int threadTlabSizeOffset() { + return threadTlabOffset + threadLocalAllocBufferDesiredSizeOffset; + } + + public int threadTlabStartOffset() { + return threadTlabOffset + threadLocalAllocBufferStartOffset; + } + + public int threadTlabEndOffset() { + return threadTlabOffset + threadLocalAllocBufferEndOffset; + } + + public int threadTlabTopOffset() { + return threadTlabOffset + threadLocalAllocBufferTopOffset; + } + + public int threadTlabPfTopOffset() { + return threadTlabOffset + threadLocalAllocBufferPfTopOffset; + } + + @HotSpotVMFlag(name = "TLABStats") @Stable public boolean tlabStats; + @HotSpotVMValue(expression = " !CMSIncrementalMode && Universe::heap()->supports_inline_contig_alloc()") @Stable public boolean inlineContiguousAllocationSupported; + + /** + * The DataLayout header size is the same as the cell size. + */ + @HotSpotVMConstant(name = "DataLayout::cell_size") @Stable public int dataLayoutHeaderSize; + @HotSpotVMField(name = "DataLayout::_header._struct._tag", type = "u1", get = HotSpotVMField.Type.OFFSET) @Stable public int dataLayoutTagOffset; + @HotSpotVMField(name = "DataLayout::_header._struct._flags", type = "u1", get = HotSpotVMField.Type.OFFSET) @Stable public int dataLayoutFlagsOffset; + @HotSpotVMField(name = "DataLayout::_header._struct._bci", type = "u2", get = HotSpotVMField.Type.OFFSET) @Stable public int dataLayoutBCIOffset; + @HotSpotVMField(name = "DataLayout::_cells[0]", type = "intptr_t", get = HotSpotVMField.Type.OFFSET) @Stable public int dataLayoutCellsOffset; + @HotSpotVMConstant(name = "DataLayout::cell_size") @Stable public int dataLayoutCellSize; + + @HotSpotVMConstant(name = "DataLayout::no_tag") @Stable public int dataLayoutNoTag; + @HotSpotVMConstant(name = "DataLayout::bit_data_tag") @Stable public int dataLayoutBitDataTag; + @HotSpotVMConstant(name = "DataLayout::counter_data_tag") @Stable public int dataLayoutCounterDataTag; + @HotSpotVMConstant(name = "DataLayout::jump_data_tag") @Stable public int dataLayoutJumpDataTag; + @HotSpotVMConstant(name = "DataLayout::receiver_type_data_tag") @Stable public int dataLayoutReceiverTypeDataTag; + @HotSpotVMConstant(name = "DataLayout::virtual_call_data_tag") @Stable public int dataLayoutVirtualCallDataTag; + @HotSpotVMConstant(name = "DataLayout::ret_data_tag") @Stable public int dataLayoutRetDataTag; + @HotSpotVMConstant(name = "DataLayout::branch_data_tag") @Stable public int dataLayoutBranchDataTag; + @HotSpotVMConstant(name = "DataLayout::multi_branch_data_tag") @Stable public int dataLayoutMultiBranchDataTag; + @HotSpotVMConstant(name = "DataLayout::arg_info_data_tag") @Stable public int dataLayoutArgInfoDataTag; + @HotSpotVMConstant(name = "DataLayout::call_type_data_tag") @Stable public int dataLayoutCallTypeDataTag; + @HotSpotVMConstant(name = "DataLayout::virtual_call_type_data_tag") @Stable public int dataLayoutVirtualCallTypeDataTag; + @HotSpotVMConstant(name = "DataLayout::parameters_type_data_tag") @Stable public int dataLayoutParametersTypeDataTag; + @HotSpotVMConstant(name = "DataLayout::speculative_trap_data_tag") @Stable public int dataLayoutSpeculativeTrapDataTag; + + @HotSpotVMFlag(name = "BciProfileWidth") @Stable public int bciProfileWidth; + @HotSpotVMFlag(name = "TypeProfileWidth") @Stable public int typeProfileWidth; + @HotSpotVMFlag(name = "MethodProfileWidth") @Stable public int methodProfileWidth; + + @HotSpotVMField(name = "CodeBlob::_code_offset", type = "int", get = HotSpotVMField.Type.OFFSET) @Stable private int codeBlobCodeOffsetOffset; + @HotSpotVMField(name = "SharedRuntime::_ic_miss_blob", type = "RuntimeStub*", get = HotSpotVMField.Type.VALUE) @Stable private long inlineCacheMissBlob; + + @HotSpotVMValue(expression = "SharedRuntime::deopt_blob()->unpack()", get = HotSpotVMValue.Type.ADDRESS) @Stable public long handleDeoptStub; + @HotSpotVMValue(expression = "SharedRuntime::deopt_blob()->uncommon_trap()", get = HotSpotVMValue.Type.ADDRESS) @Stable public long uncommonTrapStub; + + private final long inlineCacheMissStub; + + public long inlineCacheMissStub() { + return inlineCacheMissStub; + } + + @HotSpotVMField(name = "CodeCache::_heap", type = "CodeHeap*", get = HotSpotVMField.Type.VALUE) @Stable private long codeCacheHeap; + @HotSpotVMField(name = "CodeHeap::_memory", type = "VirtualSpace", get = HotSpotVMField.Type.OFFSET) @Stable private int codeHeapMemoryOffset; + @HotSpotVMField(name = "VirtualSpace::_low_boundary", type = "char*", get = HotSpotVMField.Type.OFFSET) @Stable private int virtualSpaceLowBoundaryOffset; + @HotSpotVMField(name = "VirtualSpace::_high_boundary", type = "char*", get = HotSpotVMField.Type.OFFSET) @Stable private int virtualSpaceHighBoundaryOffset; + + private final long codeCacheLowBoundary; + private final long codeCacheHighBoundary; + + /** + * @return CodeCache::_heap->_memory._low_boundary + */ + public long codeCacheLowBoundary() { + return codeCacheLowBoundary; + } + + /** + * @return CodeCache::_heap->_memory._high_boundary + */ + public long codeCacheHighBoundary() { + return codeCacheHighBoundary; + } + + @HotSpotVMField(name = "StubRoutines::_aescrypt_encryptBlock", type = "address", get = HotSpotVMField.Type.VALUE) @Stable public long aescryptEncryptBlockStub; + @HotSpotVMField(name = "StubRoutines::_aescrypt_decryptBlock", type = "address", get = HotSpotVMField.Type.VALUE) @Stable public long aescryptDecryptBlockStub; + @HotSpotVMField(name = "StubRoutines::_cipherBlockChaining_encryptAESCrypt", type = "address", get = HotSpotVMField.Type.VALUE) @Stable public long cipherBlockChainingEncryptAESCryptStub; + @HotSpotVMField(name = "StubRoutines::_cipherBlockChaining_decryptAESCrypt", type = "address", get = HotSpotVMField.Type.VALUE) @Stable public long cipherBlockChainingDecryptAESCryptStub; + @HotSpotVMField(name = "StubRoutines::_updateBytesCRC32", type = "address", get = HotSpotVMField.Type.VALUE) @Stable public long updateBytesCRC32Stub; + @HotSpotVMField(name = "StubRoutines::_crc_table_adr", type = "address", get = HotSpotVMField.Type.VALUE) @Stable public long crcTableAddress; + + @HotSpotVMField(name = "StubRoutines::_jbyte_arraycopy", type = "address", get = HotSpotVMField.Type.VALUE) @Stable public long jbyteArraycopy; + @HotSpotVMField(name = "StubRoutines::_jshort_arraycopy", type = "address", get = HotSpotVMField.Type.VALUE) @Stable public long jshortArraycopy; + @HotSpotVMField(name = "StubRoutines::_jint_arraycopy", type = "address", get = HotSpotVMField.Type.VALUE) @Stable public long jintArraycopy; + @HotSpotVMField(name = "StubRoutines::_jlong_arraycopy", type = "address", get = HotSpotVMField.Type.VALUE) @Stable public long jlongArraycopy; + @HotSpotVMField(name = "StubRoutines::_oop_arraycopy", type = "address", get = HotSpotVMField.Type.VALUE) @Stable public long oopArraycopy; + @HotSpotVMField(name = "StubRoutines::_oop_arraycopy_uninit", type = "address", get = HotSpotVMField.Type.VALUE) @Stable public long oopArraycopyUninit; + @HotSpotVMField(name = "StubRoutines::_jbyte_disjoint_arraycopy", type = "address", get = HotSpotVMField.Type.VALUE) @Stable public long jbyteDisjointArraycopy; + @HotSpotVMField(name = "StubRoutines::_jshort_disjoint_arraycopy", type = "address", get = HotSpotVMField.Type.VALUE) @Stable public long jshortDisjointArraycopy; + @HotSpotVMField(name = "StubRoutines::_jint_disjoint_arraycopy", type = "address", get = HotSpotVMField.Type.VALUE) @Stable public long jintDisjointArraycopy; + @HotSpotVMField(name = "StubRoutines::_jlong_disjoint_arraycopy", type = "address", get = HotSpotVMField.Type.VALUE) @Stable public long jlongDisjointArraycopy; + @HotSpotVMField(name = "StubRoutines::_oop_disjoint_arraycopy", type = "address", get = HotSpotVMField.Type.VALUE) @Stable public long oopDisjointArraycopy; + @HotSpotVMField(name = "StubRoutines::_oop_disjoint_arraycopy_uninit", type = "address", get = HotSpotVMField.Type.VALUE) @Stable public long oopDisjointArraycopyUninit; + @HotSpotVMField(name = "StubRoutines::_arrayof_jbyte_arraycopy", type = "address", get = HotSpotVMField.Type.VALUE) @Stable public long jbyteAlignedArraycopy; + @HotSpotVMField(name = "StubRoutines::_arrayof_jshort_arraycopy", type = "address", get = HotSpotVMField.Type.VALUE) @Stable public long jshortAlignedArraycopy; + @HotSpotVMField(name = "StubRoutines::_arrayof_jint_arraycopy", type = "address", get = HotSpotVMField.Type.VALUE) @Stable public long jintAlignedArraycopy; + @HotSpotVMField(name = "StubRoutines::_arrayof_jlong_arraycopy", type = "address", get = HotSpotVMField.Type.VALUE) @Stable public long jlongAlignedArraycopy; + @HotSpotVMField(name = "StubRoutines::_arrayof_oop_arraycopy", type = "address", get = HotSpotVMField.Type.VALUE) @Stable public long oopAlignedArraycopy; + @HotSpotVMField(name = "StubRoutines::_arrayof_oop_arraycopy_uninit", type = "address", get = HotSpotVMField.Type.VALUE) @Stable public long oopAlignedArraycopyUninit; + @HotSpotVMField(name = "StubRoutines::_arrayof_jbyte_disjoint_arraycopy", type = "address", get = HotSpotVMField.Type.VALUE) @Stable public long jbyteAlignedDisjointArraycopy; + @HotSpotVMField(name = "StubRoutines::_arrayof_jshort_disjoint_arraycopy", type = "address", get = HotSpotVMField.Type.VALUE) @Stable public long jshortAlignedDisjointArraycopy; + @HotSpotVMField(name = "StubRoutines::_arrayof_jint_disjoint_arraycopy", type = "address", get = HotSpotVMField.Type.VALUE) @Stable public long jintAlignedDisjointArraycopy; + @HotSpotVMField(name = "StubRoutines::_arrayof_jlong_disjoint_arraycopy", type = "address", get = HotSpotVMField.Type.VALUE) @Stable public long jlongAlignedDisjointArraycopy; + @HotSpotVMField(name = "StubRoutines::_arrayof_oop_disjoint_arraycopy", type = "address", get = HotSpotVMField.Type.VALUE) @Stable public long oopAlignedDisjointArraycopy; + @HotSpotVMField(name = "StubRoutines::_arrayof_oop_disjoint_arraycopy_uninit", type = "address", get = HotSpotVMField.Type.VALUE) @Stable public long oopAlignedDisjointArraycopyUninit; + @HotSpotVMField(name = "StubRoutines::_checkcast_arraycopy", type = "address", get = HotSpotVMField.Type.VALUE) @Stable public long checkcastArraycopy; + @HotSpotVMField(name = "StubRoutines::_checkcast_arraycopy_uninit", type = "address", get = HotSpotVMField.Type.VALUE) @Stable public long checkcastArraycopyUninit; + @HotSpotVMField(name = "StubRoutines::_unsafe_arraycopy", type = "address", get = HotSpotVMField.Type.VALUE) @Stable public long unsafeArraycopy; + @HotSpotVMField(name = "StubRoutines::_generic_arraycopy", type = "address", get = HotSpotVMField.Type.VALUE) @Stable public long genericArraycopy; + + @HotSpotVMValue(expression = "JVMCIRuntime::new_instance", get = HotSpotVMValue.Type.ADDRESS) @Stable public long newInstanceAddress; + @HotSpotVMValue(expression = "JVMCIRuntime::new_array", get = HotSpotVMValue.Type.ADDRESS) @Stable public long newArrayAddress; + @HotSpotVMValue(expression = "JVMCIRuntime::new_multi_array", get = HotSpotVMValue.Type.ADDRESS) @Stable public long newMultiArrayAddress; + @HotSpotVMValue(expression = "JVMCIRuntime::dynamic_new_array", get = HotSpotVMValue.Type.ADDRESS) @Stable public long dynamicNewArrayAddress; + @HotSpotVMValue(expression = "JVMCIRuntime::dynamic_new_instance", get = HotSpotVMValue.Type.ADDRESS) @Stable public long dynamicNewInstanceAddress; + @HotSpotVMValue(expression = "JVMCIRuntime::thread_is_interrupted", get = HotSpotVMValue.Type.ADDRESS) @Stable public long threadIsInterruptedAddress; + @HotSpotVMValue(expression = "JVMCIRuntime::vm_message", signature = "(unsigned char, long, long, long, long)", get = HotSpotVMValue.Type.ADDRESS) @Stable public long vmMessageAddress; + @HotSpotVMValue(expression = "JVMCIRuntime::identity_hash_code", get = HotSpotVMValue.Type.ADDRESS) @Stable public long identityHashCodeAddress; + @HotSpotVMValue(expression = "JVMCIRuntime::exception_handler_for_pc", signature = "(JavaThread*)", get = HotSpotVMValue.Type.ADDRESS) @Stable public long exceptionHandlerForPcAddress; + @HotSpotVMValue(expression = "JVMCIRuntime::monitorenter", get = HotSpotVMValue.Type.ADDRESS) @Stable public long monitorenterAddress; + @HotSpotVMValue(expression = "JVMCIRuntime::monitorexit", get = HotSpotVMValue.Type.ADDRESS) @Stable public long monitorexitAddress; + @HotSpotVMValue(expression = "JVMCIRuntime::create_null_exception", get = HotSpotVMValue.Type.ADDRESS) @Stable public long createNullPointerExceptionAddress; + @HotSpotVMValue(expression = "JVMCIRuntime::create_out_of_bounds_exception", get = HotSpotVMValue.Type.ADDRESS) @Stable public long createOutOfBoundsExceptionAddress; + @HotSpotVMValue(expression = "JVMCIRuntime::log_primitive", get = HotSpotVMValue.Type.ADDRESS) @Stable public long logPrimitiveAddress; + @HotSpotVMValue(expression = "JVMCIRuntime::log_object", get = HotSpotVMValue.Type.ADDRESS) @Stable public long logObjectAddress; + @HotSpotVMValue(expression = "JVMCIRuntime::log_printf", get = HotSpotVMValue.Type.ADDRESS) @Stable public long logPrintfAddress; + @HotSpotVMValue(expression = "JVMCIRuntime::vm_error", get = HotSpotVMValue.Type.ADDRESS) @Stable public long vmErrorAddress; + @HotSpotVMValue(expression = "JVMCIRuntime::load_and_clear_exception", get = HotSpotVMValue.Type.ADDRESS) @Stable public long loadAndClearExceptionAddress; + @HotSpotVMValue(expression = "JVMCIRuntime::write_barrier_pre", get = HotSpotVMValue.Type.ADDRESS) @Stable public long writeBarrierPreAddress; + @HotSpotVMValue(expression = "JVMCIRuntime::write_barrier_post", get = HotSpotVMValue.Type.ADDRESS) @Stable public long writeBarrierPostAddress; + @HotSpotVMValue(expression = "JVMCIRuntime::validate_object", get = HotSpotVMValue.Type.ADDRESS) @Stable public long validateObject; + + @HotSpotVMValue(expression = "JVMCIRuntime::test_deoptimize_call_int", get = HotSpotVMValue.Type.ADDRESS) @Stable public long testDeoptimizeCallInt; + + @HotSpotVMValue(expression = "SharedRuntime::register_finalizer", get = HotSpotVMValue.Type.ADDRESS) @Stable public long registerFinalizerAddress; + @HotSpotVMValue(expression = "SharedRuntime::exception_handler_for_return_address", get = HotSpotVMValue.Type.ADDRESS) @Stable public long exceptionHandlerForReturnAddressAddress; + @HotSpotVMValue(expression = "SharedRuntime::OSR_migration_end", get = HotSpotVMValue.Type.ADDRESS) @Stable public long osrMigrationEndAddress; + + @HotSpotVMValue(expression = "os::javaTimeMillis", get = HotSpotVMValue.Type.ADDRESS) @Stable public long javaTimeMillisAddress; + @HotSpotVMValue(expression = "os::javaTimeNanos", get = HotSpotVMValue.Type.ADDRESS) @Stable public long javaTimeNanosAddress; + @HotSpotVMValue(expression = "SharedRuntime::dsin", get = HotSpotVMValue.Type.ADDRESS) @Stable public long arithmeticSinAddress; + @HotSpotVMValue(expression = "SharedRuntime::dcos", get = HotSpotVMValue.Type.ADDRESS) @Stable public long arithmeticCosAddress; + @HotSpotVMValue(expression = "SharedRuntime::dtan", get = HotSpotVMValue.Type.ADDRESS) @Stable public long arithmeticTanAddress; + @HotSpotVMValue(expression = "SharedRuntime::dexp", get = HotSpotVMValue.Type.ADDRESS) @Stable public long arithmeticExpAddress; + @HotSpotVMValue(expression = "SharedRuntime::dlog", get = HotSpotVMValue.Type.ADDRESS) @Stable public long arithmeticLogAddress; + @HotSpotVMValue(expression = "SharedRuntime::dlog10", get = HotSpotVMValue.Type.ADDRESS) @Stable public long arithmeticLog10Address; + @HotSpotVMValue(expression = "SharedRuntime::dpow", get = HotSpotVMValue.Type.ADDRESS) @Stable public long arithmeticPowAddress; + + @HotSpotVMValue(expression = "(jint) JVMCICounterSize") @Stable public int jvmciCountersSize; + + @HotSpotVMValue(expression = "Deoptimization::fetch_unroll_info", signature = "(JavaThread*)", get = HotSpotVMValue.Type.ADDRESS) @Stable public long deoptimizationFetchUnrollInfo; + @HotSpotVMValue(expression = "Deoptimization::uncommon_trap", get = HotSpotVMValue.Type.ADDRESS) @Stable public long deoptimizationUncommonTrap; + @HotSpotVMValue(expression = "Deoptimization::unpack_frames", signature = "(JavaThread*, int)", get = HotSpotVMValue.Type.ADDRESS) @Stable public long deoptimizationUnpackFrames; + + @HotSpotVMConstant(name = "Deoptimization::Reason_none") @Stable public int deoptReasonNone; + @HotSpotVMConstant(name = "Deoptimization::Reason_null_check") @Stable public int deoptReasonNullCheck; + @HotSpotVMConstant(name = "Deoptimization::Reason_range_check") @Stable public int deoptReasonRangeCheck; + @HotSpotVMConstant(name = "Deoptimization::Reason_class_check") @Stable public int deoptReasonClassCheck; + @HotSpotVMConstant(name = "Deoptimization::Reason_array_check") @Stable public int deoptReasonArrayCheck; + @HotSpotVMConstant(name = "Deoptimization::Reason_unreached0") @Stable public int deoptReasonUnreached0; + @HotSpotVMConstant(name = "Deoptimization::Reason_type_checked_inlining") @Stable public int deoptReasonTypeCheckInlining; + @HotSpotVMConstant(name = "Deoptimization::Reason_optimized_type_check") @Stable public int deoptReasonOptimizedTypeCheck; + @HotSpotVMConstant(name = "Deoptimization::Reason_not_compiled_exception_handler") @Stable public int deoptReasonNotCompiledExceptionHandler; + @HotSpotVMConstant(name = "Deoptimization::Reason_unresolved") @Stable public int deoptReasonUnresolved; + @HotSpotVMConstant(name = "Deoptimization::Reason_jsr_mismatch") @Stable public int deoptReasonJsrMismatch; + @HotSpotVMConstant(name = "Deoptimization::Reason_div0_check") @Stable public int deoptReasonDiv0Check; + @HotSpotVMConstant(name = "Deoptimization::Reason_constraint") @Stable public int deoptReasonConstraint; + @HotSpotVMConstant(name = "Deoptimization::Reason_loop_limit_check") @Stable public int deoptReasonLoopLimitCheck; + @HotSpotVMConstant(name = "Deoptimization::Reason_aliasing") @Stable public int deoptReasonAliasing; + @HotSpotVMConstant(name = "Deoptimization::Reason_transfer_to_interpreter") @Stable public int deoptReasonTransferToInterpreter; + @HotSpotVMConstant(name = "Deoptimization::Reason_LIMIT") @Stable public int deoptReasonOSROffset; + + @HotSpotVMConstant(name = "Deoptimization::Action_none") @Stable public int deoptActionNone; + @HotSpotVMConstant(name = "Deoptimization::Action_maybe_recompile") @Stable public int deoptActionMaybeRecompile; + @HotSpotVMConstant(name = "Deoptimization::Action_reinterpret") @Stable public int deoptActionReinterpret; + @HotSpotVMConstant(name = "Deoptimization::Action_make_not_entrant") @Stable public int deoptActionMakeNotEntrant; + @HotSpotVMConstant(name = "Deoptimization::Action_make_not_compilable") @Stable public int deoptActionMakeNotCompilable; + + @HotSpotVMConstant(name = "Deoptimization::_action_bits") @Stable public int deoptimizationActionBits; + @HotSpotVMConstant(name = "Deoptimization::_reason_bits") @Stable public int deoptimizationReasonBits; + @HotSpotVMConstant(name = "Deoptimization::_debug_id_bits") @Stable public int deoptimizationDebugIdBits; + @HotSpotVMConstant(name = "Deoptimization::_action_shift") @Stable public int deoptimizationActionShift; + @HotSpotVMConstant(name = "Deoptimization::_reason_shift") @Stable public int deoptimizationReasonShift; + @HotSpotVMConstant(name = "Deoptimization::_debug_id_shift") @Stable public int deoptimizationDebugIdShift; + + @HotSpotVMConstant(name = "Deoptimization::Unpack_deopt") @Stable public int deoptimizationUnpackDeopt; + @HotSpotVMConstant(name = "Deoptimization::Unpack_exception") @Stable public int deoptimizationUnpackException; + @HotSpotVMConstant(name = "Deoptimization::Unpack_uncommon_trap") @Stable public int deoptimizationUnpackUncommonTrap; + @HotSpotVMConstant(name = "Deoptimization::Unpack_reexecute") @Stable public int deoptimizationUnpackReexecute; + + @HotSpotVMField(name = "Deoptimization::UnrollBlock::_size_of_deoptimized_frame", type = "int", get = HotSpotVMField.Type.OFFSET) @Stable public int deoptimizationUnrollBlockSizeOfDeoptimizedFrameOffset; + @HotSpotVMField(name = "Deoptimization::UnrollBlock::_caller_adjustment", type = "int", get = HotSpotVMField.Type.OFFSET) @Stable public int deoptimizationUnrollBlockCallerAdjustmentOffset; + @HotSpotVMField(name = "Deoptimization::UnrollBlock::_number_of_frames", type = "int", get = HotSpotVMField.Type.OFFSET) @Stable public int deoptimizationUnrollBlockNumberOfFramesOffset; + @HotSpotVMField(name = "Deoptimization::UnrollBlock::_total_frame_sizes", type = "int", get = HotSpotVMField.Type.OFFSET) @Stable public int deoptimizationUnrollBlockTotalFrameSizesOffset; + @HotSpotVMField(name = "Deoptimization::UnrollBlock::_frame_sizes", type = "intptr_t*", get = HotSpotVMField.Type.OFFSET) @Stable public int deoptimizationUnrollBlockFrameSizesOffset; + @HotSpotVMField(name = "Deoptimization::UnrollBlock::_frame_pcs", type = "address*", get = HotSpotVMField.Type.OFFSET) @Stable public int deoptimizationUnrollBlockFramePcsOffset; + @HotSpotVMField(name = "Deoptimization::UnrollBlock::_initial_info", type = "intptr_t", get = HotSpotVMField.Type.OFFSET) @Stable public int deoptimizationUnrollBlockInitialInfoOffset; + + @HotSpotVMConstant(name = "vmIntrinsics::_invokeBasic") @Stable public int vmIntrinsicInvokeBasic; + @HotSpotVMConstant(name = "vmIntrinsics::_linkToVirtual") @Stable public int vmIntrinsicLinkToVirtual; + @HotSpotVMConstant(name = "vmIntrinsics::_linkToStatic") @Stable public int vmIntrinsicLinkToStatic; + @HotSpotVMConstant(name = "vmIntrinsics::_linkToSpecial") @Stable public int vmIntrinsicLinkToSpecial; + @HotSpotVMConstant(name = "vmIntrinsics::_linkToInterface") @Stable public int vmIntrinsicLinkToInterface; + + @HotSpotVMConstant(name = "JVMCIEnv::ok") @Stable public int codeInstallResultOk; + @HotSpotVMConstant(name = "JVMCIEnv::dependencies_failed") @Stable public int codeInstallResultDependenciesFailed; + @HotSpotVMConstant(name = "JVMCIEnv::dependencies_invalid") @Stable public int codeInstallResultDependenciesInvalid; + @HotSpotVMConstant(name = "JVMCIEnv::cache_full") @Stable public int codeInstallResultCacheFull; + @HotSpotVMConstant(name = "JVMCIEnv::code_too_large") @Stable public int codeInstallResultCodeTooLarge; + + public String getCodeInstallResultDescription(int codeInstallResult) { + if (codeInstallResult == codeInstallResultOk) { + return "ok"; + } + if (codeInstallResult == codeInstallResultDependenciesFailed) { + return "dependencies failed"; + } + if (codeInstallResult == codeInstallResultDependenciesInvalid) { + return "dependencies invalid"; + } + if (codeInstallResult == codeInstallResultCacheFull) { + return "code cache is full"; + } + if (codeInstallResult == codeInstallResultCodeTooLarge) { + return "code is too large"; + } + assert false : codeInstallResult; + return "unknown"; + } + + @HotSpotVMConstant(name = "CompilerToVM::KLASS_TAG") @Stable public int compilerToVMKlassTag; + @HotSpotVMConstant(name = "CompilerToVM::SYMBOL_TAG") @Stable public int compilerToVMSymbolTag; + + // Checkstyle: stop + @HotSpotVMConstant(name = "CodeInstaller::VERIFIED_ENTRY") @Stable public int MARKID_VERIFIED_ENTRY; + @HotSpotVMConstant(name = "CodeInstaller::UNVERIFIED_ENTRY") @Stable public int MARKID_UNVERIFIED_ENTRY; + @HotSpotVMConstant(name = "CodeInstaller::OSR_ENTRY") @Stable public int MARKID_OSR_ENTRY; + @HotSpotVMConstant(name = "CodeInstaller::EXCEPTION_HANDLER_ENTRY") @Stable public int MARKID_EXCEPTION_HANDLER_ENTRY; + @HotSpotVMConstant(name = "CodeInstaller::DEOPT_HANDLER_ENTRY") @Stable public int MARKID_DEOPT_HANDLER_ENTRY; + @HotSpotVMConstant(name = "CodeInstaller::INVOKEINTERFACE") @Stable public int MARKID_INVOKEINTERFACE; + @HotSpotVMConstant(name = "CodeInstaller::INVOKEVIRTUAL") @Stable public int MARKID_INVOKEVIRTUAL; + @HotSpotVMConstant(name = "CodeInstaller::INVOKESTATIC") @Stable public int MARKID_INVOKESTATIC; + @HotSpotVMConstant(name = "CodeInstaller::INVOKESPECIAL") @Stable public int MARKID_INVOKESPECIAL; + @HotSpotVMConstant(name = "CodeInstaller::INLINE_INVOKE") @Stable public int MARKID_INLINE_INVOKE; + @HotSpotVMConstant(name = "CodeInstaller::POLL_NEAR") @Stable public int MARKID_POLL_NEAR; + @HotSpotVMConstant(name = "CodeInstaller::POLL_RETURN_NEAR") @Stable public int MARKID_POLL_RETURN_NEAR; + @HotSpotVMConstant(name = "CodeInstaller::POLL_FAR") @Stable public int MARKID_POLL_FAR; + @HotSpotVMConstant(name = "CodeInstaller::POLL_RETURN_FAR") @Stable public int MARKID_POLL_RETURN_FAR; + @HotSpotVMConstant(name = "CodeInstaller::CARD_TABLE_SHIFT") @Stable public int MARKID_CARD_TABLE_SHIFT; + @HotSpotVMConstant(name = "CodeInstaller::CARD_TABLE_ADDRESS") @Stable public int MARKID_CARD_TABLE_ADDRESS; + @HotSpotVMConstant(name = "CodeInstaller::INVOKE_INVALID") @Stable public int MARKID_INVOKE_INVALID; + + // Checkstyle: resume + + public boolean check() { + for (Field f : getClass().getDeclaredFields()) { + int modifiers = f.getModifiers(); + if (Modifier.isPublic(modifiers) && !Modifier.isStatic(modifiers)) { + assert Modifier.isFinal(modifiers) || f.getAnnotation(Stable.class) != null : "field should either be final or @Stable: " + f; + } + } + + assert codeEntryAlignment > 0 : codeEntryAlignment; + assert (layoutHelperArrayTagObjectValue & (1 << (Integer.SIZE - 1))) != 0 : "object array must have first bit set"; + assert (layoutHelperArrayTagTypeValue & (1 << (Integer.SIZE - 1))) != 0 : "type array must have first bit set"; + + return true; + } + + /** + * A compact representation of the different encoding strategies for Objects and metadata. + */ + public static class CompressEncoding { + public final long base; + public final int shift; + public final int alignment; + + CompressEncoding(long base, int shift, int alignment) { + this.base = base; + this.shift = shift; + this.alignment = alignment; + } + + public int compress(long ptr) { + if (ptr == 0L) { + return 0; + } else { + return (int) ((ptr - base) >>> shift); + } + } + + public long uncompress(int ptr) { + if (ptr == 0) { + return 0L; + } else { + return ((ptr & 0xFFFFFFFFL) << shift) + base; + } + } + + @Override + public String toString() { + return "base: " + base + " shift: " + shift + " alignment: " + alignment; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + alignment; + result = prime * result + (int) (base ^ (base >>> 32)); + result = prime * result + shift; + return result; + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof CompressEncoding) { + CompressEncoding other = (CompressEncoding) obj; + return alignment == other.alignment && base == other.base && shift == other.shift; + } else { + return false; + } + } + } + + /** + * Returns the name of the C/C++ symbol that is associated (via HotSpotVMValue annotation) with + * the HotSpotVMConfig object's field containing {@code value}; returns null if no field holds + * the provided address. + * + * @param value value of the field + * @return C/C++ symbol name or null + */ + public String getVMValueCSymbol(long value) { + for (Field f : HotSpotVMConfig.class.getDeclaredFields()) { + if (f.isAnnotationPresent(HotSpotVMValue.class)) { + HotSpotVMValue annotation = f.getAnnotation(HotSpotVMValue.class); + + if (annotation.get() == HotSpotVMValue.Type.ADDRESS) { + try { + if (value == f.getLong(this)) { + return (annotation.expression() + annotation.signature()); + } + } catch (IllegalArgumentException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } catch (IllegalAccessException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + } + } + } + return null; + } + + /** + * Returns the name of the C/C++ symbol that is associated (via HotSpotVMField annotation) with + * the HotSpotVMConfig object's field containing {@code value}; returns null if no field holds + * the provided address. + * + * @param value value of the field + * @return C/C++ symbol name or null + */ + public String getVMFieldCSymbol(long value) { + for (Field f : HotSpotVMConfig.class.getDeclaredFields()) { + if (f.isAnnotationPresent(HotSpotVMField.class)) { + HotSpotVMField annotation = f.getAnnotation(HotSpotVMField.class); + + if (annotation.get() == HotSpotVMField.Type.VALUE) { + try { + if (value == f.getLong(this)) { + return (annotation.name()); + } + } catch (IllegalArgumentException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } catch (IllegalAccessException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + } + } + } + return null; + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotVMConfigVerifier.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotVMConfigVerifier.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,156 @@ +/* + * 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 static java.lang.String.*; + +import java.io.*; +import java.lang.reflect.*; +import java.util.*; + +import jdk.internal.org.objectweb.asm.*; +import jdk.internal.org.objectweb.asm.Type; +import sun.misc.*; + +import com.oracle.jvmci.common.*; + +/** + * A {@link ClassVisitor} that verifies {@link HotSpotVMConfig} does not access {@link Unsafe} from + * any of its non-static, non-constructor methods. This ensures that a deserialized + * {@link HotSpotVMConfig} object does not perform any unsafe reads on addresses that are only valid + * in the context in which the object was serialized. Note that this does not catch cases where a + * client uses an address stored in a {@link HotSpotVMConfig} field. + */ +final class HotSpotVMConfigVerifier extends ClassVisitor { + + public static boolean check() { + Class cls = HotSpotVMConfig.class; + String classFilePath = "/" + cls.getName().replace('.', '/') + ".class"; + try { + InputStream classfile = cls.getResourceAsStream(classFilePath); + ClassReader cr = new ClassReader(Objects.requireNonNull(classfile, "Could not find class file for " + cls.getName())); + ClassVisitor cv = new HotSpotVMConfigVerifier(); + cr.accept(cv, 0); + return true; + } catch (IOException e) { + throw new JVMCIError(e); + } + } + + /** + * Source file context for error reporting. + */ + String sourceFile = null; + + /** + * Line number for error reporting. + */ + int lineNo = -1; + + private static Class resolve(String name) { + try { + return Class.forName(name.replace('/', '.')); + } catch (ClassNotFoundException e) { + throw new JVMCIError(e); + } + } + + HotSpotVMConfigVerifier() { + super(Opcodes.ASM5); + } + + @Override + public void visitSource(String source, String debug) { + this.sourceFile = source; + } + + void verify(boolean condition, String message) { + if (!condition) { + error(message); + } + } + + void error(String message) { + String errorMessage = format("%s:%d: %s is not allowed in the context of compilation replay. The unsafe access should be moved into the %s constructor and the result cached in a field", + sourceFile, lineNo, message, HotSpotVMConfig.class.getSimpleName()); + throw new JVMCIError(errorMessage); + + } + + @Override + public MethodVisitor visitMethod(int access, String name, String d, String signature, String[] exceptions) { + if (!Modifier.isStatic(access) && Modifier.isPublic(access) && !name.equals("")) { + return new MethodVisitor(Opcodes.ASM5) { + + @Override + public void visitLineNumber(int line, Label start) { + lineNo = line; + } + + private Executable resolveMethod(String owner, String methodName, String methodDesc) { + Class declaringClass = resolve(owner); + while (declaringClass != null) { + if (methodName.equals("")) { + for (Constructor c : declaringClass.getDeclaredConstructors()) { + if (methodDesc.equals(Type.getConstructorDescriptor(c))) { + return c; + } + } + } else { + Type[] argumentTypes = Type.getArgumentTypes(methodDesc); + for (Method m : declaringClass.getDeclaredMethods()) { + if (m.getName().equals(methodName)) { + if (Arrays.equals(argumentTypes, Type.getArgumentTypes(m))) { + if (Type.getReturnType(methodDesc).equals(Type.getReturnType(m))) { + return m; + } + } + } + } + } + declaringClass = declaringClass.getSuperclass(); + } + throw new NoSuchMethodError(owner + "." + methodName + methodDesc); + } + + /** + * Checks whether a given method is allowed to be called. + */ + private boolean checkInvokeTarget(Executable method) { + if (method.getDeclaringClass().equals(Unsafe.class)) { + return false; + } + return true; + } + + @Override + public void visitMethodInsn(int opcode, String owner, String methodName, String methodDesc, boolean itf) { + Executable callee = resolveMethod(owner, methodName, methodDesc); + verify(checkInvokeTarget(callee), "invocation of " + callee); + } + }; + } else { + return null; + } + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotVMEventListener.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotVMEventListener.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,53 @@ +/* + * 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.jvmci.hotspot; + +import com.oracle.jvmci.service.*; + +public interface HotSpotVMEventListener extends Service { + + /** + * 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 + */ + 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. + */ + default void notifyCompileTheWorld() throws Throwable { + } + + /** + * Notifies this client that the VM is shutting down. + */ + default void notifyShutdown() { + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotVmSymbols.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotVmSymbols.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,48 @@ +/* + * 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 static com.oracle.jvmci.common.UnsafeAccess.*; +import static com.oracle.jvmci.hotspot.HotSpotJVMCIRuntime.*; +import sun.misc.*; + +/** + * Class to access the C++ {@code vmSymbols} table. + */ +public final class HotSpotVmSymbols { + + /** + * Returns the symbol in the {@code vmSymbols} table at position {@code index} as {@link String} + * . + * + * @param index position in the symbol table + * @return the symbol at position id + */ + public static String symbolAt(int index) { + HotSpotJVMCIRuntimeProvider runtime = runtime(); + HotSpotVMConfig config = runtime.getConfig(); + assert config.vmSymbolsFirstSID <= index && index < config.vmSymbolsSIDLimit : "index " + index + " is out of bounds"; + assert config.symbolPointerSize == Unsafe.ADDRESS_SIZE : "the following address read is broken"; + return runtime.getCompilerToVM().getSymbol(unsafe.getAddress(config.vmSymbolsSymbols + index * config.symbolPointerSize)); + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/InitTimer.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/InitTimer.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,82 @@ +/* + * 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 + * 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.debug.*; + +import edu.umd.cs.findbugs.annotations.*; + +/** + * A facility for timing a step in the runtime initialization sequence. This exists separate from + * {@link DebugTimer} as it must be independent from all other JVMCI code so as to not perturb the + * initialization sequence. + */ +public final class InitTimer implements AutoCloseable { + final String name; + final long start; + + private InitTimer(String name) { + this.name = name; + this.start = System.currentTimeMillis(); + System.out.println("START: " + SPACES.substring(0, timerDepth * 2) + name); + assert Thread.currentThread() == initializingThread : Thread.currentThread() + " != " + initializingThread; + timerDepth++; + } + + @SuppressFBWarnings(value = "ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD", justification = "only the initializing thread accesses this field") + public void close() { + final long end = System.currentTimeMillis(); + timerDepth--; + System.out.println(" DONE: " + SPACES.substring(0, timerDepth * 2) + name + " [" + (end - start) + " ms]"); + } + + public static InitTimer timer(String name) { + return ENABLED ? new InitTimer(name) : null; + } + + public static InitTimer timer(String name, Object suffix) { + return ENABLED ? new InitTimer(name + suffix) : null; + } + + /** + * Specifies if initialization timing is enabled. This can only be set via a system property as + * the timing facility is used to time initialization of {@link HotSpotOptions}. + */ + private static final boolean ENABLED = Boolean.getBoolean("jvmci.runtime.TimeInit"); + + public static int timerDepth = 0; + public static final String SPACES = " "; + + /** + * Used to assert the invariant that all initialization happens on the same thread. + */ + public static final Thread initializingThread; + static { + if (ENABLED) { + initializingThread = Thread.currentThread(); + System.out.println("INITIALIZING THREAD: " + initializingThread); + } else { + initializingThread = null; + } + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/PrintStreamOption.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/PrintStreamOption.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,137 @@ +/* + * 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 java.io.*; +import java.lang.management.*; + +import com.oracle.jvmci.options.*; + +/** + * An option that encapsulates and configures a print stream. + */ +public class PrintStreamOption extends OptionValue { + + public PrintStreamOption() { + super(null); + } + + /** + * The print stream to which output will be written. + * + * Declared {@code volatile} to enable safe use of double-checked locking in + * {@link #getStream(CompilerToVM)} and {@link #setValue(Object)}. + */ + private volatile PrintStream ps; + + /** + * Replace any instance of %p with a an identifying name. Try to get it from the RuntimeMXBean + * name. + * + * @return the name of the file to log to + */ + private String getFilename() { + String name = getValue(); + if (name.contains("%p")) { + String runtimeName = ManagementFactory.getRuntimeMXBean().getName(); + try { + int index = runtimeName.indexOf('@'); + if (index != -1) { + long pid = Long.parseLong(runtimeName.substring(0, index)); + runtimeName = Long.toString(pid); + } + name = name.replaceAll("%p", runtimeName); + } catch (NumberFormatException e) { + + } + } + return name; + } + + /** + * Gets the print stream configured by this option. If no file is configured, the print stream + * will output to {@link CompilerToVM#writeDebugOutput(byte[], int, int)}. + */ + public PrintStream getStream(final CompilerToVM compilerToVM) { + if (ps == null) { + if (getValue() != null) { + synchronized (this) { + if (ps == null) { + try { + final boolean enableAutoflush = true; + ps = new PrintStream(new FileOutputStream(getFilename()), enableAutoflush); + /* Add the JVM and Java arguments to the log file to help identity it. */ + String inputArguments = String.join(" ", ManagementFactory.getRuntimeMXBean().getInputArguments()); + ps.println("VM Arguments: " + inputArguments); + String cmd = System.getProperty("sun.java.command"); + if (cmd != null) { + ps.println("sun.java.command=" + cmd); + } + } catch (FileNotFoundException e) { + throw new RuntimeException("couldn't open file: " + getValue(), e); + } + } + } + } else { + OutputStream ttyOut = new OutputStream() { + @Override + public void write(byte[] b, int off, int len) throws IOException { + if (b == null) { + throw new NullPointerException(); + } else if (off < 0 || off > b.length || len < 0 || (off + len) > b.length || (off + len) < 0) { + throw new IndexOutOfBoundsException(); + } else if (len == 0) { + return; + } + compilerToVM.writeDebugOutput(b, off, len); + } + + @Override + public void write(int b) throws IOException { + write(new byte[]{(byte) b}, 0, 1); + } + + @Override + public void flush() throws IOException { + compilerToVM.flushDebugOutput(); + } + }; + ps = new PrintStream(ttyOut); + } + } + return ps; + } + + @Override + public void setValue(Object v) { + if (ps != null) { + synchronized (this) { + if (ps != null) { + ps.close(); + ps = null; + } + } + } + super.setValue(v); + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/Stable.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/Stable.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,35 @@ +/* + * 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.hotspot; + +import java.lang.annotation.*; + +/** + * This annotation functions as an alias for the sun.invoke.Stable annotation within JVMCI code. It + * is specially recognized during class file parsing in the same way as that annotation. + */ +@Target(ElementType.FIELD) +@Retention(RetentionPolicy.RUNTIME) +public @interface Stable { +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/events/EmptyEventProvider.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/events/EmptyEventProvider.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,105 @@ +/* + * 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.events; + +import com.oracle.jvmci.common.*; + +/** + * An empty implementation for {@link EventProvider}. This implementation is used when no logging is + * requested. + */ +public final class EmptyEventProvider implements EventProvider { + + public CompilationEvent newCompilationEvent() { + return new EmptyCompilationEvent(); + } + + public static class EmptyCompilationEvent implements CompilationEvent { + public void commit() { + throw JVMCIError.shouldNotReachHere(); + } + + public boolean shouldWrite() { + // Events of this class should never been written. + return false; + } + + public void begin() { + } + + public void end() { + } + + public void setMethod(String method) { + throw JVMCIError.shouldNotReachHere(); + } + + public void setCompileId(int compileId) { + throw JVMCIError.shouldNotReachHere(); + } + + public void setCompileLevel(int compileLevel) { + throw JVMCIError.shouldNotReachHere(); + } + + public void setSucceeded(boolean succeeded) { + throw JVMCIError.shouldNotReachHere(); + } + + public void setIsOsr(boolean isOsr) { + throw JVMCIError.shouldNotReachHere(); + } + + public void setCodeSize(int codeSize) { + throw JVMCIError.shouldNotReachHere(); + } + + public void setInlinedBytes(int inlinedBytes) { + throw JVMCIError.shouldNotReachHere(); + } + } + + public CompilerFailureEvent newCompilerFailureEvent() { + return new EmptyCompilerFailureEvent(); + } + + public static class EmptyCompilerFailureEvent implements CompilerFailureEvent { + public void commit() { + throw JVMCIError.shouldNotReachHere(); + } + + public boolean shouldWrite() { + // Events of this class should never been written. + return false; + } + + public void setCompileId(int compileId) { + throw JVMCIError.shouldNotReachHere(); + } + + public void setMessage(String message) { + throw JVMCIError.shouldNotReachHere(); + } + } + +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/events/EventProvider.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/events/EventProvider.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,107 @@ +/* + * 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.events; + +import com.oracle.jvmci.service.*; + +/** + * A provider that provides a specific implementation for events that can be logged in the compiler. + */ +public interface EventProvider extends Service { + + /** + * An instant event is an event that is not considered to have taken any time. + */ + interface InstantEvent { + /** + * Commits the event. + */ + void commit(); + + /** + * Determines if this particular event instance would be committed to the data stream right + * now if application called {@link #commit()}. This in turn depends on whether the event is + * enabled and possible other factors. + * + * @return if this event would be committed on a call to {@link #commit()}. + */ + boolean shouldWrite(); + } + + /** + * Timed events describe an operation that somehow consumes time. + */ + interface TimedEvent extends InstantEvent { + /** + * Starts the timing for this event. + */ + void begin(); + + /** + * Ends the timing period for this event. + */ + void end(); + } + + /** + * Creates a new {@link CompilationEvent}. + * + * @return a compilation event + */ + CompilationEvent newCompilationEvent(); + + /** + * A compilation event. + */ + interface CompilationEvent extends TimedEvent { + void setMethod(String method); + + void setCompileId(int compileId); + + void setCompileLevel(int compileLevel); + + void setSucceeded(boolean succeeded); + + void setIsOsr(boolean isOsr); + + void setCodeSize(int codeSize); + + void setInlinedBytes(int inlinedBytes); + } + + /** + * Creates a new {@link CompilerFailureEvent}. + * + * @return a compiler failure event + */ + CompilerFailureEvent newCompilerFailureEvent(); + + /** + * A compiler failure event. + */ + interface CompilerFailureEvent extends InstantEvent { + void setCompileId(int compileId); + + void setMessage(String message); + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/logging/CountingProxy.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/logging/CountingProxy.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2011, 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.logging; + +import java.lang.reflect.*; +import java.util.*; +import java.util.concurrent.*; +import java.util.concurrent.atomic.*; + +import com.oracle.jvmci.debug.*; + +/** + * A java.lang.reflect proxy that hierarchically logs all method invocations along with their + * parameters and return values. + */ +public class CountingProxy implements InvocationHandler { + + public static final boolean ENABLED = Boolean.valueOf(System.getProperty("jvmci.countcalls")); + + private T delegate; + + private ConcurrentHashMap calls = new ConcurrentHashMap<>(); + + public CountingProxy(T delegate) { + assert ENABLED; + TTY.println("Counting proxy for " + delegate.getClass().getSimpleName() + " created"); + this.delegate = delegate; + proxies.add(this); + } + + @Override + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + int argCount = args == null ? 0 : args.length; + if (method.getParameterTypes().length != argCount) { + throw new RuntimeException("wrong parameter count"); + } + final Object result; + if (!calls.containsKey(method)) { + calls.putIfAbsent(method, new AtomicLong(0)); + } + AtomicLong count = calls.get(method); + count.incrementAndGet(); + try { + if (args == null) { + result = method.invoke(delegate); + } else { + result = method.invoke(delegate, args); + } + } catch (InvocationTargetException e) { + throw e.getCause(); + } + return result; + } + + public static T getProxy(Class interf, T delegate) { + Class[] interfaces = ProxyUtil.getAllInterfaces(delegate.getClass()); + Object obj = Proxy.newProxyInstance(interf.getClassLoader(), interfaces, new CountingProxy<>(delegate)); + return interf.cast(obj); + } + + private static ArrayList> proxies = new ArrayList<>(); + + static { + if (ENABLED) { + Runtime.getRuntime().addShutdownHook(new Thread() { + + @Override + public void run() { + for (CountingProxy proxy : proxies) { + proxy.print(); + } + } + }); + } + } + + protected void print() { + long sum = 0; + for (Map.Entry entry : calls.entrySet()) { + Method method = entry.getKey(); + long count = entry.getValue().get(); + sum += count; + TTY.println(delegate.getClass().getSimpleName() + "." + method.getName() + ": " + count); + } + TTY.println(delegate.getClass().getSimpleName() + " calls: " + sum); + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/logging/Logger.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/logging/Logger.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,199 @@ +/* + * Copyright (c) 2011, 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.logging; + +import java.io.*; +import java.lang.reflect.*; +import java.util.*; + +import com.oracle.jvmci.debug.*; +import com.oracle.jvmci.hotspot.*; + +/** + * Scoped logging class used to display the call hierarchy of {@link CompilerToVM} calls. + */ +public class Logger { + + public static final boolean ENABLED = Boolean.valueOf(System.getProperty("jvmci.debug")); + private static final int SPACING = 4; + private static final ThreadLocal loggerTL; + + private Deque openStack = new LinkedList<>(); + private boolean open = false; + private int level = 0; + + private static final PrintStream out; + + static { + if (ENABLED) { + loggerTL = new ThreadLocal() { + + @Override + protected Logger initialValue() { + return new Logger(); + } + }; + } else { + loggerTL = null; + } + + PrintStream ps = null; + String filename = System.getProperty("jvmci.info_file"); + if (filename != null && !"".equals(filename)) { + try { + ps = new PrintStream(new FileOutputStream(filename)); + } catch (FileNotFoundException e) { + e.printStackTrace(); + ps = null; + } + } + out = ps; + if (out != null) { + out.println("start: " + new Date()); + } + } + + public static void info(String message) { + if (ENABLED) { + log(message); + } else { + TTY.println(message); + } + if (out != null) { + out.println(message); + out.flush(); + } + } + + public static void log(String message) { + if (ENABLED) { + Logger logger = loggerTL.get(); + for (String line : message.split("\n")) { + if (logger.open) { + TTY.println("..."); + logger.open = false; + } + TTY.print(space(logger.level)); + TTY.println(line); + } + } + } + + public static void startScope(String message) { + if (ENABLED) { + Logger logger = loggerTL.get(); + if (logger.open) { + TTY.println("..."); + logger.open = false; + } + TTY.print(space(logger.level)); + TTY.print(message); + logger.openStack.push(logger.open); + logger.open = true; + logger.level++; + } + } + + public static void endScope(String message) { + if (ENABLED) { + Logger logger = loggerTL.get(); + logger.level--; + if (logger.open) { + TTY.println(message); + } else { + TTY.println(space(logger.level) + "..." + message); + } + logger.open = logger.openStack.pop(); + } + } + + private static String[] spaces = new String[50]; + + private static String space(int count) { + assert count >= 0; + String result; + if (count >= spaces.length || spaces[count] == null) { + StringBuilder str = new StringBuilder(); + for (int i = 0; i < count * SPACING; i++) { + str.append(' '); + } + result = str.toString(); + if (count < spaces.length) { + spaces[count] = result; + } + } else { + result = spaces[count]; + } + return result; + } + + public static String pretty(Object value) { + if (value == null) { + return "null"; + } + + Class klass = value.getClass(); + if (value instanceof Void) { + return "void"; + } else if (value instanceof String) { + return "\"" + value + "\""; + } else if (value instanceof Method) { + return "method \"" + ((Method) value).getName() + "\""; + } else if (value instanceof Class) { + return "class \"" + ((Class) value).getSimpleName() + "\""; + } else if (value instanceof Integer) { + if ((Integer) value < 10) { + return value.toString(); + } + return value + " (0x" + Integer.toHexString((Integer) value) + ")"; + } else if (value instanceof Long) { + if ((Long) value < 10 && (Long) value > -10) { + return value + "l"; + } + return value + "l (0x" + Long.toHexString((Long) value) + "l)"; + } else if (klass.isArray()) { + StringBuilder str = new StringBuilder(); + int dimensions = 0; + while (klass.isArray()) { + dimensions++; + klass = klass.getComponentType(); + } + int length = Array.getLength(value); + str.append(klass.getSimpleName()).append('[').append(length).append(']'); + for (int i = 1; i < dimensions; i++) { + str.append("[]"); + } + str.append(" {"); + for (int i = 0; i < length; i++) { + str.append(pretty(Array.get(value, i))); + if (i < length - 1) { + str.append(", "); + } + } + str.append('}'); + return str.toString(); + } + + return value.toString(); + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/logging/LoggingProxy.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/logging/LoggingProxy.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2011, 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.logging; + +import java.lang.reflect.*; + +/** + * A java.lang.reflect proxy that hierarchically logs all method invocations along with their + * parameters and return values. + */ +public class LoggingProxy implements InvocationHandler { + + private T delegate; + + public LoggingProxy(T delegate) { + this.delegate = delegate; + } + + @Override + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + int argCount = args == null ? 0 : args.length; + if (method.getParameterTypes().length != argCount) { + throw new RuntimeException("wrong parameter count"); + } + StringBuilder str = new StringBuilder(); + str.append(method.getReturnType().getSimpleName() + " " + method.getDeclaringClass().getSimpleName() + "." + method.getName() + "("); + for (int i = 0; i < argCount; i++) { + str.append(i == 0 ? "" : ", "); + str.append(Logger.pretty(args[i])); + } + str.append(")"); + Logger.startScope(str.toString()); + final Object result; + try { + if (args == null) { + result = method.invoke(delegate); + } else { + result = method.invoke(delegate, args); + } + } catch (InvocationTargetException e) { + Logger.endScope(" = Exception " + e.getMessage()); + throw e.getCause(); + } + Logger.endScope(" = " + Logger.pretty(result)); + return result; + } + + /** + * The object returned by this method will implement all interfaces that are implemented by + * delegate. + */ + public static T getProxy(Class interf, T delegate) { + Class[] interfaces = ProxyUtil.getAllInterfaces(delegate.getClass()); + Object obj = Proxy.newProxyInstance(interf.getClassLoader(), interfaces, new LoggingProxy<>(delegate)); + return interf.cast(obj); + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/logging/ProxyUtil.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/logging/ProxyUtil.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2011, 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.logging; + +import java.util.*; + +public final class ProxyUtil { + + public static Class[] getAllInterfaces(Class clazz) { + HashSet> interfaces = new HashSet<>(); + getAllInterfaces(clazz, interfaces); + return interfaces.toArray(new Class[interfaces.size()]); + } + + private static void getAllInterfaces(Class clazz, HashSet> interfaces) { + for (Class iface : clazz.getInterfaces()) { + if (!interfaces.contains(iface)) { + interfaces.add(iface); + getAllInterfaces(iface, interfaces); + } + } + if (clazz.getSuperclass() != null) { + getAllInterfaces(clazz.getSuperclass(), interfaces); + } + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/logging/package-info.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/logging/package-info.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2011, 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. + */ +/** + * Logging framework for the HotSpot CRI implementation. + */ +package com.oracle.jvmci.hotspot.logging; + diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.hotspotvmconfig.processor/src/META-INF/services/javax.annotation.processing.Processor --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.hotspotvmconfig.processor/src/META-INF/services/javax.annotation.processing.Processor Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,1 @@ +com.oracle.jvmci.hotspotvmconfig.processor.HotSpotVMConfigProcessor diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.hotspotvmconfig.processor/src/com/oracle/jvmci/hotspotvmconfig/processor/HotSpotVMConfigProcessor.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.hotspotvmconfig.processor/src/com/oracle/jvmci/hotspotvmconfig/processor/HotSpotVMConfigProcessor.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,430 @@ +/* + * 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.hotspotvmconfig.processor; + +import java.io.*; +import java.lang.annotation.*; +import java.util.*; +import java.util.Map.Entry; +import java.util.function.*; + +import javax.annotation.processing.*; +import javax.lang.model.*; +import javax.lang.model.element.*; +import javax.tools.Diagnostic.Kind; +import javax.tools.*; + +import com.oracle.jvmci.common.*; +import com.oracle.jvmci.hotspotvmconfig.*; + +@SupportedAnnotationTypes({ + // @formatter:off + "com.oracle.jvmci.hotspotvmconfig.HotSpotVMConstant", + "com.oracle.jvmci.hotspotvmconfig.HotSpotVMFlag", + "com.oracle.jvmci.hotspotvmconfig.HotSpotVMField", + "com.oracle.jvmci.hotspotvmconfig.HotSpotVMType", + "com.oracle.jvmci.hotspotvmconfig.HotSpotVMValue"}) + // @formatter:on +public class HotSpotVMConfigProcessor extends AbstractProcessor { + + public HotSpotVMConfigProcessor() { + } + + @Override + public SourceVersion getSupportedSourceVersion() { + return SourceVersion.latest(); + } + + /** + * Set to true to enable logging to a local file during annotation processing. There's no normal + * channel for any debug messages and debugging annotation processors requires some special + * setup. + */ + private static final boolean DEBUG = false; + + private PrintWriter log; + + /** + * Logging facility for debugging the annotation processor. + */ + + private PrintWriter getLog() { + if (log == null) { + try { + // Create the log file within the generated source directory so it's easy to find. + // /tmp isn't platform independent and java.io.tmpdir can map anywhere, particularly + // on the mac. + FileObject file = processingEnv.getFiler().createResource(StandardLocation.SOURCE_OUTPUT, "", getClass().getSimpleName() + "log"); + log = new PrintWriter(new FileWriter(file.toUri().getPath(), true)); + } catch (IOException e) { + // Do nothing + } + } + return log; + } + + private void logMessage(String format, Object... args) { + if (!DEBUG) { + return; + } + PrintWriter bw = getLog(); + if (bw != null) { + bw.printf(format, args); + bw.flush(); + } + } + + private void logException(Throwable t) { + if (!DEBUG) { + return; + } + PrintWriter bw = getLog(); + if (bw != null) { + t.printStackTrace(bw); + bw.flush(); + } + } + + /** + * Bugs in an annotation processor can cause silent failure so try to report any exception + * throws as errors. + */ + private void reportExceptionThrow(Element element, Throwable t) { + if (element != null) { + logMessage("throw for %s:\n", element); + } + logException(t); + errorMessage(element, "Exception throw during processing: %s %s", t, Arrays.toString(Arrays.copyOf(t.getStackTrace(), 4))); + } + + //@formatter:off + String[] prologue = new String[]{ + "// The normal wrappers CommandLineFlags::boolAt and CommandLineFlags::intxAt skip constant flags", + "static bool boolAt(char* name, bool* value) {", + " Flag* result = Flag::find_flag(name, strlen(name), true, true);", + " if (result == NULL) return false;", + " if (!result->is_bool()) return false;", + " *value = result->get_bool();", + " return true;", + "}", + "", + "static bool intxAt(char* name, intx* value) {", + " Flag* result = Flag::find_flag(name, strlen(name), true, true);", + " if (result == NULL) return false;", + " if (!result->is_intx()) return false;", + " *value = result->get_intx();", + " return true;", + "}", + "", + "#define set_boolean(name, value) vmconfig_oop->bool_field_put(fs.offset(), value)", + "#define set_byte(name, value) vmconfig_oop->byte_field_put(fs.offset(), (jbyte)(value))", + "#define set_short(name, value) vmconfig_oop->short_field_put(fs.offset(), (jshort)(value))", + "#define set_int(name, value) vmconfig_oop->int_field_put(fs.offset(), (int)(value))", + "#define set_long(name, value) vmconfig_oop->long_field_put(fs.offset(), value)", + "#define set_address(name, value) do { set_long(name, (jlong)(value)); } while (0)", + "", + "#define set_optional_boolean_flag(varName, flagName) do { bool flagValue; if (boolAt((char*) flagName, &flagValue)) { set_boolean(varName, flagValue); } } while (0)", + "#define set_optional_int_flag(varName, flagName) do { intx flagValue; if (intxAt((char*) flagName, &flagValue)) { set_int(varName, flagValue); } } while (0)", + "#define set_optional_long_flag(varName, flagName) do { intx flagValue; if (intxAt((char*) flagName, &flagValue)) { set_long(varName, flagValue); } } while (0)", + "", + "void VMStructs::initHotSpotVMConfig(oop vmconfig_oop) {", + " InstanceKlass* vmconfig_klass = InstanceKlass::cast(vmconfig_oop->klass());", + "", + }; + //@formatter:on + + String outputName = "HotSpotVMConfig.inline.hpp"; + String outputDirectory = "hotspot"; + + private void createFiles(Map annotations, Element element) { + + Filer filer = processingEnv.getFiler(); + try (PrintWriter out = createSourceFile(outputDirectory, outputName, filer, element)) { + + for (String line : prologue) { + out.println(line); + } + + Map expectedValues = new HashMap<>(); + for (VMConfigField value : annotations.values()) { + if (!value.optional) { + String key = value.define != null ? value.define : ""; + if (expectedValues.get(key) == null) { + expectedValues.put(key, 1); + } else { + expectedValues.put(key, expectedValues.get(key) + 1); + } + } + } + + out.printf(" int expected = %s;%n", expectedValues.get("")); + for (Entry entry : expectedValues.entrySet()) { + if (entry.getKey().equals("")) { + continue; + } + out.printf("#if %s%n", entry.getKey()); + out.printf(" expected += %s;%n", entry.getValue()); + out.printf("#endif%n"); + } + out.println(" int assigned = 0;"); + out.println(" for (JavaFieldStream fs(vmconfig_klass); !fs.done(); fs.next()) {"); + + Set fieldTypes = new HashSet<>(); + for (VMConfigField key : annotations.values()) { + fieldTypes.add(key.getType()); + } + // For each type of field, generate a switch on the length of the symbol and then do a + // direct compare. In general this reduces each operation to 2 tests plus a string + // compare. Being more perfect than that is probably not worth it. + for (String type : fieldTypes) { + String sigtype = type.equals("boolean") ? "bool" : type; + out.println(" if (fs.signature() == vmSymbols::" + sigtype + "_signature()) {"); + Set lengths = new HashSet<>(); + for (Entry entry : annotations.entrySet()) { + if (entry.getValue().getType().equals(type)) { + lengths.add(entry.getKey().length()); + } + } + out.println(" switch (fs.name()->utf8_length()) {"); + for (int len : lengths) { + out.println(" case " + len + ":"); + for (Entry entry : annotations.entrySet()) { + if (entry.getValue().getType().equals(type) && entry.getKey().length() == len) { + out.println(" if (fs.name()->equals(\"" + entry.getKey() + "\")) {"); + entry.getValue().emit(out); + out.println(" continue;"); + out.println(" }"); + } + } + out.println(" continue;"); + } + out.println(" } // switch"); + out.println(" continue;"); + out.println(" } // if"); + } + out.println(" } // for"); + out.println(" guarantee(assigned == expected, \"Didn't find all fields during init of HotSpotVMConfig. Maybe recompile?\");"); + out.println("}"); + } + } + + protected PrintWriter createSourceFile(String pkg, String relativeName, Filer filer, Element... originatingElements) { + try { + // Ensure Unix line endings to comply with code style guide checked by Checkstyle + FileObject sourceFile = filer.createResource(StandardLocation.SOURCE_OUTPUT, pkg, relativeName, originatingElements); + logMessage("%s\n", sourceFile); + return new PrintWriter(sourceFile.openWriter()) { + + @Override + public void println() { + print("\n"); + } + }; + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + static class VMConfigField { + final String setter; + final String define; + private boolean optional; + final VariableElement field; + + public VMConfigField(VariableElement field, HotSpotVMField value) { + this.field = field; + define = archDefines(value.archs()); + String type = field.asType().toString(); + String name = value.name(); + int i = name.lastIndexOf("::"); + switch (value.get()) { + case OFFSET: + setter = String.format("set_%s(\"%s\", offset_of(%s, %s));", type, field.getSimpleName(), name.substring(0, i), name.substring(i + 2)); + break; + case ADDRESS: + setter = String.format("set_address(\"%s\", &%s);", field.getSimpleName(), name); + break; + case VALUE: + setter = String.format("set_%s(\"%s\", (%s) (intptr_t) %s);", type, field.getSimpleName(), type, name); + break; + default: + throw new JVMCIError("unexpected type: " + value.get()); + } + } + + public VMConfigField(VariableElement field, HotSpotVMType value) { + this.field = field; + define = null; // ((HotSpotVMType) annotation).archs(); + String type = field.asType().toString(); + setter = String.format("set_%s(\"%s\", sizeof(%s));", type, field.getSimpleName(), value.name()); + } + + public VMConfigField(VariableElement field, HotSpotVMValue value) { + this.field = field; + String[] defines = value.defines(); + int length = defines.length; + if (length != 0) { + for (int i = 0; i < length; i++) { + defines[i] = "defined(" + defines[i] + ")"; + } + define = String.join(" || ", defines); + } else { + define = null; // ((HotSpotVMValue) annotation).archs(); + } + String type = field.asType().toString(); + if (value.get() == HotSpotVMValue.Type.ADDRESS) { + setter = String.format("set_address(\"%s\", %s);", field.getSimpleName(), value.expression()); + } else { + setter = String.format("set_%s(\"%s\", %s);", type, field.getSimpleName(), value.expression()); + } + } + + public VMConfigField(VariableElement field, HotSpotVMConstant value) { + this.field = field; + define = archDefines(value.archs()); + String type = field.asType().toString(); + setter = String.format("set_%s(\"%s\", %s);", type, field.getSimpleName(), value.name()); + } + + public VMConfigField(VariableElement field, HotSpotVMFlag value) { + this.field = field; + define = archDefines(value.archs()); + optional = value.optional(); + String type = field.asType().toString(); + if (value.optional()) { + setter = String.format("set_optional_%s_flag(\"%s\", \"%s\");", type, field.getSimpleName(), value.name()); + } else { + setter = String.format("set_%s(\"%s\", %s);", type, field.getSimpleName(), value.name()); + } + } + + public String getType() { + return field.asType().toString(); + } + + private static String archDefine(String arch) { + switch (arch) { + case "amd64": + return "defined(AMD64)"; + case "sparcv9": + return "(defined(SPARC) && defined(_LP64))"; + case "sparc": + return "defined(SPARC)"; + default: + throw new JVMCIError("unexpected arch: " + arch); + } + } + + private static String archDefines(String[] archs) { + if (archs == null || archs.length == 0) { + return null; + } + if (archs.length == 1) { + return archDefine(archs[0]); + } + String[] defs = new String[archs.length]; + int i = 0; + for (String arch : archs) { + defs[i++] = archDefine(arch); + } + return String.join(" || ", defs); + } + + public void emit(PrintWriter out) { + if (define != null) { + out.printf("#if %s\n", define); + } + out.printf(" %s%n", setter); + if (!optional) { + out.printf(" assigned++;%n"); + } + if (define != null) { + out.printf("#endif\n"); + } + } + + } + + @SuppressWarnings("unchecked") + private void collectAnnotations(RoundEnvironment roundEnv, Map annotationMap, Class annotationClass, + BiFunction builder) { + for (Element element : roundEnv.getElementsAnnotatedWith(annotationClass)) { + Annotation constant = element.getAnnotation(annotationClass); + if (element.getKind() != ElementKind.FIELD) { + errorMessage(element, "%s annotations may only be on fields", annotationClass.getSimpleName()); + } + if (annotationClass == HotSpotVMValue.class) { + HotSpotVMValue value = (HotSpotVMValue) constant; + if (value.get() == HotSpotVMValue.Type.ADDRESS && !element.asType().toString().equals("long")) { + errorMessage(element, "HotSpotVMValue with get == ADDRESS must be of type long, but found %s", element.asType()); + } + } + if (currentTypeElement == null) { + currentTypeElement = element.getEnclosingElement(); + } else { + if (!currentTypeElement.equals(element.getEnclosingElement())) { + errorMessage(element, "Multiple types encountered. Only HotSpotVMConfig is supported"); + } + } + annotationMap.put(element.getSimpleName().toString(), builder.apply((VariableElement) element, (T) constant)); + } + } + + private void errorMessage(Element element, String format, Object... args) { + processingEnv.getMessager().printMessage(Kind.ERROR, String.format(format, args), element); + } + + Element currentTypeElement = null; + + @Override + public boolean process(Set annotations, RoundEnvironment roundEnv) { + if (roundEnv.processingOver()) { + return true; + } + logMessage("Starting round %s %s\n", roundEnv, annotations); + try { + + currentTypeElement = null; + + // First collect all the annotations. + Map annotationMap = new HashMap<>(); + collectAnnotations(roundEnv, annotationMap, HotSpotVMConstant.class, (e, v) -> new VMConfigField(e, v)); + collectAnnotations(roundEnv, annotationMap, HotSpotVMFlag.class, (e, v) -> new VMConfigField(e, v)); + collectAnnotations(roundEnv, annotationMap, HotSpotVMField.class, (e, v) -> new VMConfigField(e, v)); + collectAnnotations(roundEnv, annotationMap, HotSpotVMType.class, (e, v) -> new VMConfigField(e, v)); + collectAnnotations(roundEnv, annotationMap, HotSpotVMValue.class, (e, v) -> new VMConfigField(e, v)); + + if (annotationMap.isEmpty()) { + return true; + } + + logMessage("type element %s\n", currentTypeElement); + createFiles(annotationMap, currentTypeElement); + + } catch (Throwable t) { + reportExceptionThrow(null, t); + } + + return true; + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.hotspotvmconfig/src/com/oracle/jvmci/hotspotvmconfig/HotSpotVMConstant.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.hotspotvmconfig/src/com/oracle/jvmci/hotspotvmconfig/HotSpotVMConstant.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,48 @@ +/* + * 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.hotspotvmconfig; + +import java.lang.annotation.*; + +/** + * Refers to a C++ constant in the VM. + */ +@Target(ElementType.FIELD) +@Retention(RetentionPolicy.RUNTIME) +public @interface HotSpotVMConstant { + + /** + * Returns the name of the constant. + * + * @return name of constant + */ + String name(); + + /** + * List of architectures where this constant is required. Names are derived from + * {@link HotSpotVMConfig#getHostArchitectureName()}. An empty list implies that the constant is + * required on all architectures. + */ + @SuppressWarnings("javadoc") + String[] archs() default {}; +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.hotspotvmconfig/src/com/oracle/jvmci/hotspotvmconfig/HotSpotVMField.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.hotspotvmconfig/src/com/oracle/jvmci/hotspotvmconfig/HotSpotVMField.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,82 @@ +/* + * 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.hotspotvmconfig; + +import java.lang.annotation.*; + +/** + * Refers to a C++ field in the VM. + */ +@Target(ElementType.FIELD) +@Retention(RetentionPolicy.RUNTIME) +public @interface HotSpotVMField { + + /** + * Types of information this annotation can return. + */ + enum Type { + /** + * Returns the offset of this field within the type. Only valid for instance fields. + */ + OFFSET, + + /** + * Returns the absolute address of this field. Only valid for static fields. + */ + ADDRESS, + + /** + * Returns the value of this field. Only valid for static fields. + */ + VALUE; + } + + /** + * Specifies what type of information to return. + * + * @see Type + */ + Type get(); + + /** + * Returns the type name containing this field. + * + * @return name of containing type + */ + String type(); + + /** + * Returns the name of this field. + * + * @return name of field + */ + String name(); + + /** + * List of architectures where this constant is required. Names are derived from + * {@link HotSpotVMConfig#getHostArchitectureName()}. An empty list implies that the constant is + * required on all architectures. + */ + @SuppressWarnings("javadoc") + String[] archs() default {}; +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.hotspotvmconfig/src/com/oracle/jvmci/hotspotvmconfig/HotSpotVMFlag.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.hotspotvmconfig/src/com/oracle/jvmci/hotspotvmconfig/HotSpotVMFlag.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,50 @@ +/* + * 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.hotspotvmconfig; + +import java.lang.annotation.*; + +/** + * Refers to a C++ flag in the VM. + */ +@Target(ElementType.FIELD) +@Retention(RetentionPolicy.RUNTIME) +public @interface HotSpotVMFlag { + + /** + * Returns the name of this flag. + * + * @return name of flag. + */ + String name(); + + /** + * List of architectures where this constant is required. Names are derived from + * {@link HotSpotVMConfig#getHostArchitectureName()}. An empty list implies that the constant is + * required on all architectures. + */ + @SuppressWarnings("javadoc") + String[] archs() default {}; + + boolean optional() default false; +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.hotspotvmconfig/src/com/oracle/jvmci/hotspotvmconfig/HotSpotVMType.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.hotspotvmconfig/src/com/oracle/jvmci/hotspotvmconfig/HotSpotVMType.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,57 @@ +/* + * 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.hotspotvmconfig; + +import java.lang.annotation.*; + +/** + * Refers to a C++ type in the VM. + */ +@Target(ElementType.FIELD) +@Retention(RetentionPolicy.RUNTIME) +public @interface HotSpotVMType { + + /** + * Types of information this annotation can return. + */ + enum Type { + /** + * Returns the size of the type (C++ {@code sizeof()}). + */ + SIZE; + } + + /** + * Specifies what type of information to return. + * + * @see Type + */ + Type get(); + + /** + * Returns the name of the type. + * + * @return name of type + */ + String name(); +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.hotspotvmconfig/src/com/oracle/jvmci/hotspotvmconfig/HotSpotVMValue.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.hotspotvmconfig/src/com/oracle/jvmci/hotspotvmconfig/HotSpotVMValue.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,62 @@ +/* + * 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.hotspotvmconfig; + +import java.lang.annotation.*; + +@Target(ElementType.FIELD) +@Retention(RetentionPolicy.RUNTIME) +public @interface HotSpotVMValue { + + /** + * A C++ expression to be evaluated and assigned to the field. + */ + String expression(); + + enum Type { + /** + * A C++ address which might require extra casts to be safely assigned to a Java field. + */ + ADDRESS, + + /** + * A simple value which can be assigned to a regular Java field. + */ + VALUE + } + + /** + * If {@link #expression} is a C++ function name, {@link #signature} represents the signature of + * the function. + * + */ + String signature() default ""; + + Type get() default Type.VALUE; + + /** + * List of preprocessor symbols that should guard initialization of this value. + */ + String[] defines() default {}; + +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.meta/overview.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.meta/overview.html Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,38 @@ + + + + + + + + +The com.oracle.jvmci.meta project provides an API to the runtime data structures +for various Java elements. Unlike standard Java reflection, it can model elements that are not yet loaded. +It can also expose profiling information collected by the runtime system. + + + diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/AbstractJavaProfile.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/AbstractJavaProfile.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,158 @@ +/* + * 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.meta; + +/** + * This object holds probability information for a set of items that were profiled at a specific + * BCI. The precision of the supplied values may vary, but a runtime that provides this information + * should be aware that it will be used to guide performance-critical decisions like speculative + * inlining, etc. + * + * @param a subclass of AbstractProfiledItem + * @param the class of the items that are profiled at the specific BCI and for which + * probabilities are stored. E.g., a ResolvedJavaType or a ResolvedJavaMethod. + */ +public abstract class AbstractJavaProfile, U> { + + private final double notRecordedProbability; + private final T[] pitems; + + public AbstractJavaProfile(double notRecordedProbability, T[] pitems) { + this.pitems = pitems; + assert !Double.isNaN(notRecordedProbability); + this.notRecordedProbability = notRecordedProbability; + assert isSorted(); + assert totalProbablility() >= 0 && totalProbablility() <= 1.0001 : totalProbablility() + " " + this; + } + + private double totalProbablility() { + double total = notRecordedProbability; + for (T item : pitems) { + total += item.probability; + } + return total; + } + + /** + * Determines if an array of profiled items are sorted in descending order of their + * probabilities. + */ + private boolean isSorted() { + for (int i = 1; i < pitems.length; i++) { + if (pitems[i - 1].getProbability() < pitems[i].getProbability()) { + return false; + } + } + return true; + } + + /** + * Returns the estimated probability of all types that could not be recorded due to profiling + * limitations. + * + * @return double value ≥ 0.0 and ≤ 1.0 + */ + public double getNotRecordedProbability() { + return notRecordedProbability; + } + + protected T[] getItems() { + return pitems; + } + + /** + * Searches for an entry of a given resolved Java type. + * + * @param type the type for which an entry should be searched + * @return the entry or null if no entry for this type can be found + */ + public T findEntry(ResolvedJavaType type) { + if (pitems != null) { + for (T pt : pitems) { + if (pt.getItem().equals(type)) { + return pt; + } + } + } + return null; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getName()); + builder.append("["); + if (pitems != null) { + for (T pt : pitems) { + builder.append(pt.toString()); + builder.append(", "); + } + } + builder.append(this.notRecordedProbability); + builder.append("]"); + return builder.toString(); + } + + public boolean isIncluded(U item) { + if (this.getNotRecordedProbability() > 0.0) { + return true; + } else { + for (int i = 0; i < getItems().length; i++) { + T pitem = getItems()[i]; + U curType = pitem.getItem(); + if (curType == item) { + return true; + } + } + } + return false; + } + + @Override + public boolean equals(Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof AbstractJavaProfile)) { + return false; + } + AbstractJavaProfile that = (AbstractJavaProfile) obj; + if (that.notRecordedProbability != notRecordedProbability) { + return false; + } + if (that.pitems.length != pitems.length) { + return false; + } + for (int i = 0; i < pitems.length; ++i) { + if (!pitems[i].equals(that.pitems[i])) { + return false; + } + } + return true; + } + + @Override + public int hashCode() { + return (int) Double.doubleToLongBits(notRecordedProbability) + pitems.length * 13; + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/AbstractProfiledItem.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/AbstractProfiledItem.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,95 @@ +/* + * 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.meta; + +/** + * A profiled type that has a probability. Profiled types are naturally sorted in descending order + * of their probabilities. + */ +public abstract class AbstractProfiledItem implements Comparable> { + + protected final T item; + protected final double probability; + + public AbstractProfiledItem(T item, double probability) { + assert item != null; + assert probability >= 0.0D && probability <= 1.0D; + this.item = item; + this.probability = probability; + } + + protected T getItem() { + return item; + } + + /** + * Returns the estimated probability of {@link #getItem()}. + * + * @return double value ≥ 0.0 and ≤ 1.0 + */ + public double getProbability() { + return probability; + } + + @Override + public int compareTo(AbstractProfiledItem o) { + if (getProbability() > o.getProbability()) { + return -1; + } else if (getProbability() < o.getProbability()) { + return 1; + } + return 0; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + long temp; + temp = Double.doubleToLongBits(probability); + result = prime * result + (int) (temp ^ (temp >>> 32)); + result = prime * result + item.hashCode(); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + AbstractProfiledItem other = (AbstractProfiledItem) obj; + if (Double.doubleToLongBits(probability) != Double.doubleToLongBits(other.probability)) { + return false; + } + return item.equals(other.item); + } + + @Override + public abstract String toString(); +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/AbstractValue.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/AbstractValue.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2009, 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; + +/** + * Abstract base class for values. + */ +public abstract class AbstractValue implements Value, KindProvider { + + public static final AllocatableValue ILLEGAL = Value.ILLEGAL; + + private final Kind kind; + private final LIRKind lirKind; + + /** + * Initializes a new value of the specified kind. + * + * @param lirKind the kind + */ + protected AbstractValue(LIRKind lirKind) { + this.lirKind = lirKind; + if (getPlatformKind() instanceof Kind) { + this.kind = (Kind) getPlatformKind(); + } else { + this.kind = Kind.Illegal; + } + } + + /** + * Returns a String representation of the kind, which should be the end of all + * {@link #toString()} implementation of subclasses. + */ + protected final String getKindSuffix() { + return "|" + getKind().getTypeChar(); + } + + /** + * Returns the kind of this value. + */ + public final Kind getKind() { + return kind; + } + + public final LIRKind getLIRKind() { + return lirKind; + } + + /** + * Returns the platform specific kind used to store this value. + */ + public final PlatformKind getPlatformKind() { + return lirKind.getPlatformKind(); + } + + @Override + public int hashCode() { + return 41 + lirKind.hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof AbstractValue) { + AbstractValue that = (AbstractValue) obj; + return kind.equals(that.kind) && lirKind.equals(that.lirKind); + } + return false; + } + + /** + * Checks if this value is identical to {@code other}. + * + * Warning: Use with caution! Usually equivalence {@link #equals(Object)} is sufficient and + * should be used. + */ + public final boolean identityEquals(AbstractValue other) { + return this == other; + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/AllocatableValue.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/AllocatableValue.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,36 @@ +/* + * 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.meta; + +/** + * Common base class for values that are stored in some location that's managed by the register + * allocator (e.g. register, stack slot). + */ +public abstract class AllocatableValue extends AbstractValue implements JavaValue, KindProvider { + + public static final AllocatableValue[] NONE = {}; + + public AllocatableValue(LIRKind lirKind) { + super(lirKind); + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/Assumptions.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/Assumptions.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,380 @@ +/* + * Copyright (c) 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.meta; + +import java.lang.invoke.*; +import java.util.*; + +/** + * Class for recording assumptions made during compilation. + */ +public final class Assumptions implements Iterable { + + /** + * Abstract base class for assumptions. An assumption assumes a property of the runtime that may + * be invalidated by subsequent execution (e.g., that a class has no subclasses implementing + * {@link NoFinalizableSubclass Object.finalize()}). + */ + public abstract static class Assumption { + } + + /** + * A class for providing information that is only valid in association with a set of + * {@link Assumption}s. + * + * @param + */ + public static class AssumptionResult { + Assumption[] assumptions; + final T result; + + private static final Assumption[] EMPTY = new Assumption[0]; + + public AssumptionResult(T result, Assumption... assumptions) { + this.result = result; + this.assumptions = assumptions; + } + + public AssumptionResult(T result) { + this(result, EMPTY); + } + + public T getResult() { + return result; + } + + public boolean isAssumptionFree() { + return assumptions.length == 0; + } + + public void add(AssumptionResult other) { + Assumption[] newAssumptions = Arrays.copyOf(this.assumptions, this.assumptions.length + other.assumptions.length); + System.arraycopy(other.assumptions, 0, newAssumptions, this.assumptions.length, other.assumptions.length); + this.assumptions = newAssumptions; + } + } + + /** + * An assumption that a given class has no subclasses implementing {@link Object#finalize()}). + */ + public static final class NoFinalizableSubclass extends Assumption { + + private ResolvedJavaType receiverType; + + public NoFinalizableSubclass(ResolvedJavaType receiverType) { + this.receiverType = receiverType; + } + + @Override + public int hashCode() { + return 31 + receiverType.hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof NoFinalizableSubclass) { + NoFinalizableSubclass other = (NoFinalizableSubclass) obj; + return other.receiverType.equals(receiverType); + } + return false; + } + + @Override + public String toString() { + return "NoFinalizableSubclass[receiverType=" + receiverType.toJavaName() + "]"; + } + + } + + /** + * An assumption that a given abstract or interface type has one direct concrete subtype. There + * is no requirement that the subtype is a leaf type. + */ + public static final class ConcreteSubtype extends Assumption { + + /** + * Type the assumption is made about. + */ + public final ResolvedJavaType context; + + /** + * Assumed concrete sub-type of the context type. + */ + public final ResolvedJavaType subtype; + + public ConcreteSubtype(ResolvedJavaType context, ResolvedJavaType subtype) { + this.context = context; + this.subtype = subtype; + assert context.isAbstract(); + assert subtype.isConcrete() || context.isInterface() : subtype.toString() + " : " + context.toString(); + assert !subtype.isArray() || subtype.getElementalType().isFinal() : subtype.toString() + " : " + context.toString(); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + context.hashCode(); + result = prime * result + subtype.hashCode(); + return result; + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof ConcreteSubtype) { + ConcreteSubtype other = (ConcreteSubtype) obj; + return other.context.equals(context) && other.subtype.equals(subtype); + } + return false; + } + + @Override + public String toString() { + return "ConcreteSubtype[context=" + context.toJavaName() + ", subtype=" + subtype.toJavaName() + "]"; + } + } + + /** + * An assumption that a given type has no subtypes. + */ + public static final class LeafType extends Assumption { + + /** + * Type the assumption is made about. + */ + public final ResolvedJavaType context; + + public LeafType(ResolvedJavaType context) { + this.context = context; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + context.hashCode(); + return result; + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof LeafType) { + LeafType other = (LeafType) obj; + return other.context.equals(context); + } + return false; + } + + @Override + public String toString() { + return "LeafSubtype[context=" + context.toJavaName() + "]"; + } + } + + /** + * An assumption that a given virtual method has a given unique implementation. + */ + public static final class ConcreteMethod extends Assumption { + + /** + * A virtual (or interface) method whose unique implementation for the receiver type in + * {@link #context} is {@link #impl}. + */ + public final ResolvedJavaMethod method; + + /** + * A receiver type. + */ + public final ResolvedJavaType context; + + /** + * The unique implementation of {@link #method} for {@link #context}. + */ + public final ResolvedJavaMethod impl; + + public ConcreteMethod(ResolvedJavaMethod method, ResolvedJavaType context, ResolvedJavaMethod impl) { + this.method = method; + this.context = context; + this.impl = impl; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + method.hashCode(); + result = prime * result + context.hashCode(); + result = prime * result + impl.hashCode(); + return result; + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof ConcreteMethod) { + ConcreteMethod other = (ConcreteMethod) obj; + return other.method.equals(method) && other.context.equals(context) && other.impl.equals(impl); + } + return false; + } + + @Override + public String toString() { + return "ConcreteMethod[method=" + method.format("%H.%n(%p)%r") + ", context=" + context.toJavaName() + ", impl=" + impl.format("%H.%n(%p)%r") + "]"; + } + } + + /** + * An assumption that a given call site's method handle did not change. + */ + public static final class CallSiteTargetValue extends Assumption { + + public final CallSite callSite; + public final MethodHandle methodHandle; + + public CallSiteTargetValue(CallSite callSite, MethodHandle methodHandle) { + this.callSite = callSite; + this.methodHandle = methodHandle; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + callSite.hashCode(); + result = prime * result + methodHandle.hashCode(); + return result; + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof CallSiteTargetValue) { + CallSiteTargetValue other = (CallSiteTargetValue) obj; + return callSite.equals(other.callSite) && methodHandle.equals(other.methodHandle); + } + return false; + } + + @Override + public String toString() { + return "CallSiteTargetValue[callSite=" + callSite + ", methodHandle=" + methodHandle + "]"; + } + } + + private final Set assumptions = new HashSet<>(); + + /** + * Returns whether any assumptions have been registered. + * + * @return {@code true} if at least one assumption has been registered, {@code false} otherwise. + */ + public boolean isEmpty() { + return assumptions.isEmpty(); + } + + @Override + public int hashCode() { + throw new UnsupportedOperationException("hashCode"); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof Assumptions) { + Assumptions that = (Assumptions) obj; + if (!this.assumptions.equals(that.assumptions)) { + return false; + } + return true; + } + return false; + } + + @Override + public Iterator iterator() { + return assumptions.iterator(); + } + + /** + * Records an assumption that the specified type has no finalizable subclasses. + * + * @param receiverType the type that is assumed to have no finalizable subclasses + */ + public void recordNoFinalizableSubclassAssumption(ResolvedJavaType receiverType) { + record(new NoFinalizableSubclass(receiverType)); + } + + /** + * Records that {@code subtype} is the only concrete subtype in the class hierarchy below + * {@code context}. + * + * @param context the root of the subtree of the class hierarchy that this assumptions is about + * @param subtype the one concrete subtype + */ + public void recordConcreteSubtype(ResolvedJavaType context, ResolvedJavaType subtype) { + record(new ConcreteSubtype(context, subtype)); + } + + /** + * Records that {@code impl} is the only possible concrete target for a virtual call to + * {@code method} with a receiver of type {@code context}. + * + * @param method a method that is the target of a virtual call + * @param context the receiver type of a call to {@code method} + * @param impl the concrete method that is the only possible target for the virtual call + */ + public void recordConcreteMethod(ResolvedJavaMethod method, ResolvedJavaType context, ResolvedJavaMethod impl) { + record(new ConcreteMethod(method, context, impl)); + } + + public void record(AssumptionResult result) { + for (Assumption assumption : result.assumptions) { + record(assumption); + } + } + + public void record(Assumption assumption) { + assumptions.add(assumption); + } + + /** + * Gets a copy of the assumptions recorded in this object as an array. + */ + public Assumption[] toArray() { + return assumptions.toArray(new Assumption[assumptions.size()]); + } + + /** + * Copies assumptions recorded by another {@link Assumptions} object into this object. + */ + public void record(Assumptions other) { + assert other != this; + assumptions.addAll(other.assumptions); + } + + @Override + public String toString() { + return "Assumptions[" + assumptions + "]"; + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/Constant.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/Constant.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,33 @@ +/* + * 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; + +/** + * Represents a compile-time constant (boxed) value within the compiler. + */ +public interface Constant { + + boolean isDefaultForKind(); + + String toValueString(); +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/ConstantPool.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/ConstantPool.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,121 @@ +/* + * Copyright (c) 2009, 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; + +/** + * Represents the runtime representation of the constant pool that is used by the compiler when + * parsing bytecode. Provides methods to look up a constant pool entry without performing + * resolution. They are used during compilation. + */ +public interface ConstantPool { + + /** + * Returns the number of entries the constant pool. + * + * @return number of entries in the constant pool + */ + int length(); + + /** + * Ensures that the type referenced by the specified constant pool entry is loaded and + * initialized. This can be used to compile time resolve a type. It works for field, method, or + * type constant pool entries. + * + * @param cpi the index of the constant pool entry that references the type + * @param opcode the opcode of the instruction that references the type + */ + void loadReferencedType(int cpi, int opcode); + + /** + * Looks up a reference to a field. If {@code opcode} is non-negative, then resolution checks + * specific to the bytecode it denotes are performed if the field is already resolved. Should + * any of these checks fail, an unresolved field reference is returned. + * + * @param cpi the constant pool index + * @param opcode the opcode of the instruction for which the lookup is being performed or + * {@code -1} + * @return a reference to the field at {@code cpi} in this pool + * @throws ClassFormatError if the entry at {@code cpi} is not a field + */ + JavaField lookupField(int cpi, int opcode); + + /** + * Looks up a reference to a method. If {@code opcode} is non-negative, then resolution checks + * specific to the bytecode it denotes are performed if the method is already resolved. Should + * any of these checks fail, an unresolved method reference is returned. + * + * @param cpi the constant pool index + * @param opcode the opcode of the instruction for which the lookup is being performed or + * {@code -1} + * @return a reference to the method at {@code cpi} in this pool + * @throws ClassFormatError if the entry at {@code cpi} is not a method + */ + JavaMethod lookupMethod(int cpi, int opcode); + + /** + * Looks up a reference to a type. If {@code opcode} is non-negative, then resolution checks + * specific to the bytecode it denotes are performed if the type is already resolved. Should any + * of these checks fail, an unresolved type reference is returned. + * + * @param cpi the constant pool index + * @param opcode the opcode of the instruction for which the lookup is being performed or + * {@code -1} + * @return a reference to the compiler interface type + */ + JavaType lookupType(int cpi, int opcode); + + /** + * Looks up an Utf8 string. + * + * @param cpi the constant pool index + * @return the Utf8 string at index {@code cpi} in this constant pool + */ + String lookupUtf8(int cpi); + + /** + * Looks up a method signature. + * + * @param cpi the constant pool index + * @return the method signature at index {@code cpi} in this constant pool + */ + Signature lookupSignature(int cpi); + + /** + * Looks up a constant at the specified index. + * + * @param cpi the constant pool index + * @return the {@code Constant} or {@code JavaType} instance representing the constant pool + * entry + */ + Object lookupConstant(int cpi); + + /** + * Looks up the appendix at the specified index. + * + * @param cpi the constant pool index + * @param opcode the opcode of the instruction for which the lookup is being performed or + * {@code -1} + * @return the appendix if it exists and is resolved or {@code null} + */ + JavaConstant lookupAppendix(int cpi, int opcode); +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/ConstantReflectionProvider.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/ConstantReflectionProvider.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,152 @@ +/* + * 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.meta; + +import java.lang.invoke.*; + +/** + * Reflection operations on values represented as {@linkplain JavaConstant constants}. All methods + * in this interface require the VM to access the actual object encapsulated in {@link Kind#Object + * object} constants. This access is not always possible, depending on kind of VM and the state that + * the VM is in. Therefore, all methods can return {@code null} at any time, to indicate that the + * result is not available at this point. The caller is responsible to check for {@code null} + * results and handle them properly, e.g., not perform an optimization. + */ +public interface ConstantReflectionProvider { + + /** + * Compares two constants for equality. The equality relationship is symmetric. Returns + * {@link Boolean#TRUE true} if the two constants represent the same run time value, + * {@link Boolean#FALSE false} if they are different. Returns {@code null} if the constants + * cannot be compared at this point. + */ + Boolean constantEquals(Constant x, Constant y); + + /** + * Returns the length of the array constant. Returns {@code null} if the constant is not an + * array, or if the array length is not available at this point. + */ + Integer readArrayLength(JavaConstant array); + + /** + * Reads a value from the given array at the given index. Returns {@code null} if the constant + * is not an array, if the index is out of bounds, or if the value is not available at this + * point. + */ + JavaConstant readArrayElement(JavaConstant array, int index); + + /** + * Reads a value from the given array at the given index if it is a stable array. Returns + * {@code null} if the constant is not a stable array, if it is a default value, if the index is + * out of bounds, or if the value is not available at this point. + */ + JavaConstant readConstantArrayElement(JavaConstant array, int index); + + /** + * Reads a value from the given array at the given offset if it is a stable array. The offset + * will be decoded relative to the platform addressing into an index into the array. Returns + * {@code null} if the constant is not a stable array, if it is a default value, if the offset + * is out of bounds, or if the value is not available at this point. + */ + JavaConstant readConstantArrayElementForOffset(JavaConstant array, long offset); + + /** + * Gets the constant value of this field. Note that a {@code static final} field may not be + * considered constant if its declaring class is not yet initialized or if it is a well known + * field that can be updated via other means (e.g., {@link System#setOut(java.io.PrintStream)}). + * + * @param receiver object from which this field's value is to be read. This value is ignored if + * this field is static. + * @return the constant value of this field or {@code null} if this field is not considered + * constant by the runtime + */ + JavaConstant readConstantFieldValue(JavaField field, JavaConstant receiver); + + /** + * Gets the current value of this field for a given object, if available. + * + * There is no guarantee that the same value will be returned by this method for a field unless + * the field is considered to be {@linkplain #readConstantFieldValue(JavaField, JavaConstant) + * constant} by the runtime. + * + * @param receiver object from which this field's value is to be read. This value is ignored if + * this field is static. + * @return the value of this field or {@code null} if the value is not available (e.g., because + * the field holder is not yet initialized). + */ + JavaConstant readFieldValue(JavaField field, JavaConstant receiver); + + /** + * Gets the current value of this field for a given object, if available. Like + * {@link #readFieldValue(JavaField, JavaConstant)} but treats array fields as stable. + * + * There is no guarantee that the same value will be returned by this method for a field unless + * the field is considered to be {@linkplain #readConstantFieldValue(JavaField, JavaConstant) + * constant} by the runtime. + * + * @param receiver object from which this field's value is to be read. This value is ignored if + * this field is static. + * @param isDefaultStable if {@code true}, default values are considered stable + * @return the value of this field or {@code null} if the value is not available (e.g., because + * the field holder is not yet initialized). + */ + JavaConstant readStableFieldValue(JavaField field, JavaConstant receiver, boolean isDefaultStable); + + /** + * Converts the given {@link Kind#isPrimitive() primitive} constant to a boxed + * {@link Kind#Object object} constant, according to the Java boxing rules. Returns {@code null} + * if the source is is not a primitive constant, or the boxed value is not available at this + * point. + */ + JavaConstant boxPrimitive(JavaConstant source); + + /** + * Converts the given {@link Kind#Object object} constant to a {@link Kind#isPrimitive() + * primitive} constant, according to the Java unboxing rules. Returns {@code null} if the source + * is is not an object constant that can be unboxed, or the unboxed value is not available at + * this point. + */ + JavaConstant unboxPrimitive(JavaConstant source); + + /** + * Gets a string as a {@link JavaConstant}. + */ + JavaConstant forString(String value); + + /** + * Returns the {@link ResolvedJavaType} for a {@link Class} object (or any other object regarded + * as a class by the VM) encapsulated in the given constant. Returns {@code null} if the + * constant does not encapsulate a class, or if the type is not available at this point. + */ + ResolvedJavaType asJavaType(Constant constant); + + /** + * Gets access to the internals of {@link MethodHandle}. + */ + MethodHandleAccessProvider getMethodHandleAccess(); + + /** + * Gets raw memory access. + */ + MemoryAccessProvider getMemoryAccessProvider(); +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/DefaultProfilingInfo.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/DefaultProfilingInfo.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,110 @@ +/* + * 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.meta; + +/** + * An implementation of {@link ProfilingInfo} that can used in the absence of real profile + * information. + */ +public final class DefaultProfilingInfo implements ProfilingInfo { + + private static final ProfilingInfo[] NO_PROFILING_INFO = new ProfilingInfo[]{new DefaultProfilingInfo(TriState.TRUE), new DefaultProfilingInfo(TriState.FALSE), + new DefaultProfilingInfo(TriState.UNKNOWN)}; + + private final TriState exceptionSeen; + + DefaultProfilingInfo(TriState exceptionSeen) { + this.exceptionSeen = exceptionSeen; + } + + @Override + public int getCodeSize() { + return 0; + } + + @Override + public JavaTypeProfile getTypeProfile(int bci) { + return null; + } + + @Override + public JavaMethodProfile getMethodProfile(int bci) { + return null; + } + + @Override + public double getBranchTakenProbability(int bci) { + return -1; + } + + @Override + public double[] getSwitchProbabilities(int bci) { + return null; + } + + @Override + public TriState getExceptionSeen(int bci) { + return exceptionSeen; + } + + @Override + public TriState getNullSeen(int bci) { + return TriState.UNKNOWN; + } + + @Override + public int getExecutionCount(int bci) { + return -1; + } + + public static ProfilingInfo get(TriState exceptionSeen) { + return NO_PROFILING_INFO[exceptionSeen.ordinal()]; + } + + @Override + public int getDeoptimizationCount(DeoptimizationReason reason) { + return 0; + } + + @Override + public boolean isMature() { + return false; + } + + @Override + public String toString() { + return "BaseProfilingInfo<" + this.toString(null, "; ") + ">"; + } + + public void setMature() { + // Do nothing + } + + public boolean setCompilerIRSize(Class irType, int nodeCount) { + return false; + } + + public int getCompilerIRSize(Class irType) { + return -1; + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/DeoptimizationAction.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/DeoptimizationAction.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,70 @@ +/* + * 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.meta; + +/** + * Specifies the action that should be taken by the runtime in case a certain deoptimization is + * triggered. + */ +public enum DeoptimizationAction { + /** + * Do not invalidate the machine code. This is typically used when deoptimizing at a point where + * it's highly likely nothing will change the likelihood of the deoptimization happening again. + * For example, a compiled array allocation where the size is negative. + */ + None(false), + + /** + * Do not invalidate the machine code, but schedule a recompilation if this deoptimization is + * triggered too often. + */ + RecompileIfTooManyDeopts(true), + + /** + * Invalidate the machine code and reset the profiling information. + */ + InvalidateReprofile(true), + + /** + * Invalidate the machine code and immediately schedule a recompilation. This is typically used + * when deoptimizing to resolve an unresolved symbol in which case extra profiling is not + * required to determine that the deoptimization will not re-occur. + */ + InvalidateRecompile(true), + + /** + * Invalidate the machine code and stop compiling the outermost method of this compilation. + */ + InvalidateStopCompiling(true); + + private final boolean invalidatesCompilation; + + private DeoptimizationAction(boolean invalidatesCompilation) { + this.invalidatesCompilation = invalidatesCompilation; + } + + public boolean doesInvalidateCompilation() { + return invalidatesCompilation; + } + +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/DeoptimizationReason.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/DeoptimizationReason.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2012, 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.meta; + +/** + * Enumeration of reasons for why a deoptimization is happening. + */ +public enum DeoptimizationReason { + None, + NullCheckException, + BoundsCheckException, + ClassCastException, + ArrayStoreException, + UnreachedCode, + TypeCheckedInliningViolated, + OptimizedTypeCheckViolated, + NotCompiledExceptionHandler, + Unresolved, + JavaSubroutineMismatch, + ArithmeticException, + RuntimeConstraint, + LoopLimitCheck, + Aliasing, + TransferToInterpreter, +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/ExceptionHandler.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/ExceptionHandler.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,121 @@ +/* + * Copyright (c) 2009, 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.meta; + +import java.util.*; + +/** + * Represents an exception handler within the bytecodes. + */ +public final class ExceptionHandler { + + private final int startBCI; + private final int endBCI; + private final int handlerBCI; + private final int catchTypeCPI; + private final JavaType catchType; + + /** + * Creates a new exception handler with the specified ranges. + * + * @param startBCI the start index of the protected range + * @param endBCI the end index of the protected range + * @param catchBCI the index of the handler + * @param catchTypeCPI the index of the throwable class in the constant pool + * @param catchType the type caught by this exception handler + */ + public ExceptionHandler(int startBCI, int endBCI, int catchBCI, int catchTypeCPI, JavaType catchType) { + this.startBCI = startBCI; + this.endBCI = endBCI; + this.handlerBCI = catchBCI; + this.catchTypeCPI = catchTypeCPI; + this.catchType = catchType; + } + + /** + * Returns the start bytecode index of the protected range of this handler. + */ + public int getStartBCI() { + return startBCI; + } + + /** + * Returns the end bytecode index of the protected range of this handler. + */ + public int getEndBCI() { + return endBCI; + } + + /** + * Returns the bytecode index of the handler block of this handler. + */ + public int getHandlerBCI() { + return handlerBCI; + } + + /** + * Returns the index into the constant pool representing the type of exception caught by this + * handler. + */ + public int catchTypeCPI() { + return catchTypeCPI; + } + + /** + * Checks whether this handler catches all exceptions. + * + * @return {@code true} if this handler catches all exceptions + */ + public boolean isCatchAll() { + return catchTypeCPI == 0; + } + + /** + * Returns the type of exception caught by this exception handler. + */ + public JavaType getCatchType() { + return catchType; + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof ExceptionHandler)) { + return false; + } + ExceptionHandler that = (ExceptionHandler) obj; + if (this.startBCI != that.startBCI || this.endBCI != that.endBCI || this.handlerBCI != that.handlerBCI || this.catchTypeCPI != that.catchTypeCPI) { + return false; + } + return Objects.equals(this.catchType, that.catchType); + } + + @Override + public String toString() { + return "ExceptionHandler"; + } + + @Override + public int hashCode() { + return catchTypeCPI ^ endBCI ^ handlerBCI; + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/ForeignCallDescriptor.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/ForeignCallDescriptor.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2009, 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.meta; + +import java.util.*; + +/** + * The name and signature of a foreign call. A foreign call differs from a normal compiled Java call + * in at least one of these aspects: + *

        + *
      • The call is to C/C++/assembler code.
      • + *
      • The call uses different conventions for passing parameters or returning values.
      • + *
      • The callee has different register saving semantics. For example, the callee may save all + * registers (apart from some specified temporaries) in which case the register allocator doesn't + * not need to spill all live registers around the call site.
      • + *
      • The call does not occur at an INVOKE* bytecode. Such a call could be transformed into a + * standard Java call if the foreign routine is a normal Java method and the runtime supports + * linking Java calls at arbitrary bytecodes.
      • + *
      + */ +public class ForeignCallDescriptor { + + private final String name; + private final Class resultType; + private final Class[] argumentTypes; + + public ForeignCallDescriptor(String name, Class resultType, Class... argumentTypes) { + this.name = name; + this.resultType = resultType; + this.argumentTypes = argumentTypes; + } + + /** + * Gets the name of this foreign call. + */ + public String getName() { + return name; + } + + /** + * Gets the return type of this foreign call. + */ + public Class getResultType() { + return resultType; + } + + /** + * Gets the argument types of this foreign call. + */ + public Class[] getArgumentTypes() { + return argumentTypes.clone(); + } + + @Override + public int hashCode() { + return name.hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof ForeignCallDescriptor) { + ForeignCallDescriptor other = (ForeignCallDescriptor) obj; + return other.name.equals(name) && other.resultType.equals(resultType) && Arrays.equals(other.argumentTypes, argumentTypes); + } + return false; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(name).append('('); + String sep = ""; + for (Class arg : argumentTypes) { + sb.append(sep).append(arg.getSimpleName()); + sep = ","; + } + return sb.append(')').append(resultType.getSimpleName()).toString(); + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/InvokeTarget.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/InvokeTarget.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2013, 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.meta; + +/** + * Represents the resolved target of an invocation. + */ +public interface InvokeTarget { +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/JavaConstant.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/JavaConstant.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,458 @@ +/* + * Copyright (c) 2009, 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; + +/** + * Represents a constant (boxed) value, such as an integer, floating point number, or object + * reference, within the compiler and across the compiler/runtime interface. Exports a set of + * {@code JavaConstant} instances that represent frequently used constant values, such as + * {@link #NULL_POINTER}. + */ +public interface JavaConstant extends Constant, JavaValue, Value { + + /* + * Using a larger cache for integers leads to only a slight increase in cache hit ratio which is + * not enough to justify the impact on startup time. + */ + JavaConstant NULL_POINTER = new NullConstant(); + PrimitiveConstant INT_MINUS_1 = new PrimitiveConstant(Kind.Int, -1); + PrimitiveConstant INT_0 = new PrimitiveConstant(Kind.Int, 0); + PrimitiveConstant INT_1 = new PrimitiveConstant(Kind.Int, 1); + PrimitiveConstant INT_2 = new PrimitiveConstant(Kind.Int, 2); + PrimitiveConstant LONG_0 = new PrimitiveConstant(Kind.Long, 0L); + PrimitiveConstant LONG_1 = new PrimitiveConstant(Kind.Long, 1L); + PrimitiveConstant FLOAT_0 = new PrimitiveConstant(Kind.Float, Float.floatToRawIntBits(0.0F)); + PrimitiveConstant FLOAT_1 = new PrimitiveConstant(Kind.Float, Float.floatToRawIntBits(1.0F)); + PrimitiveConstant DOUBLE_0 = new PrimitiveConstant(Kind.Double, Double.doubleToRawLongBits(0.0D)); + PrimitiveConstant DOUBLE_1 = new PrimitiveConstant(Kind.Double, Double.doubleToRawLongBits(1.0D)); + PrimitiveConstant TRUE = new PrimitiveConstant(Kind.Boolean, 1L); + PrimitiveConstant FALSE = new PrimitiveConstant(Kind.Boolean, 0L); + + /** + * Checks whether this constant is null. + * + * @return {@code true} if this constant is the null constant + */ + boolean isNull(); + + static boolean isNull(Constant c) { + if (c instanceof JavaConstant) { + return ((JavaConstant) c).isNull(); + } else { + return false; + } + } + + /** + * Checks whether this constant is non-null. + * + * @return {@code true} if this constant is a primitive, or an object constant that is not null + */ + default boolean isNonNull() { + return !isNull(); + } + + /** + * Checks whether this constant is the default value for its kind (null, 0, 0.0, false). + * + * @return {@code true} if this constant is the default value for its kind + */ + boolean isDefaultForKind(); + + /** + * Returns the value of this constant as a boxed Java value. + * + * @return the value of this constant + */ + Object asBoxedPrimitive(); + + /** + * Returns the primitive int value this constant represents. The constant must have a + * {@link Kind#getStackKind()} of {@link Kind#Int}. + * + * @return the constant value + */ + int asInt(); + + /** + * Returns the primitive boolean value this constant represents. The constant must have kind + * {@link Kind#Boolean}. + * + * @return the constant value + */ + boolean asBoolean(); + + /** + * Returns the primitive long value this constant represents. The constant must have kind + * {@link Kind#Long}, a {@link Kind#getStackKind()} of {@link Kind#Int}. + * + * @return the constant value + */ + long asLong(); + + /** + * Returns the primitive float value this constant represents. The constant must have kind + * {@link Kind#Float}. + * + * @return the constant value + */ + float asFloat(); + + /** + * Returns the primitive double value this constant represents. The constant must have kind + * {@link Kind#Double}. + * + * @return the constant value + */ + double asDouble(); + + default String toValueString() { + if (getKind() == Kind.Illegal) { + return "illegal"; + } else { + return getKind().format(asBoxedPrimitive()); + } + } + + static String toString(JavaConstant constant) { + if (constant.getKind() == Kind.Illegal) { + return "illegal"; + } else { + return constant.getKind().getJavaName() + "[" + constant.toValueString() + "]"; + } + } + + /** + * Creates a boxed double constant. + * + * @param d the double value to box + * @return a boxed copy of {@code value} + */ + static PrimitiveConstant forDouble(double d) { + if (Double.compare(0.0D, d) == 0) { + return DOUBLE_0; + } + if (Double.compare(d, 1.0D) == 0) { + return DOUBLE_1; + } + return new PrimitiveConstant(Kind.Double, Double.doubleToRawLongBits(d)); + } + + /** + * Creates a boxed float constant. + * + * @param f the float value to box + * @return a boxed copy of {@code value} + */ + static PrimitiveConstant forFloat(float f) { + if (Float.compare(f, 0.0F) == 0) { + return FLOAT_0; + } + if (Float.compare(f, 1.0F) == 0) { + return FLOAT_1; + } + return new PrimitiveConstant(Kind.Float, Float.floatToRawIntBits(f)); + } + + /** + * Creates a boxed long constant. + * + * @param i the long value to box + * @return a boxed copy of {@code value} + */ + static PrimitiveConstant forLong(long i) { + if (i == 0) { + return LONG_0; + } else if (i == 1) { + return LONG_1; + } else { + return new PrimitiveConstant(Kind.Long, i); + } + } + + /** + * Creates a boxed integer constant. + * + * @param i the integer value to box + * @return a boxed copy of {@code value} + */ + static PrimitiveConstant forInt(int i) { + switch (i) { + case -1: + return INT_MINUS_1; + case 0: + return INT_0; + case 1: + return INT_1; + case 2: + return INT_2; + default: + return new PrimitiveConstant(Kind.Int, i); + } + } + + /** + * Creates a boxed byte constant. + * + * @param i the byte value to box + * @return a boxed copy of {@code value} + */ + static PrimitiveConstant forByte(byte i) { + return new PrimitiveConstant(Kind.Byte, i); + } + + /** + * Creates a boxed boolean constant. + * + * @param i the boolean value to box + * @return a boxed copy of {@code value} + */ + static PrimitiveConstant forBoolean(boolean i) { + return i ? TRUE : FALSE; + } + + /** + * Creates a boxed char constant. + * + * @param i the char value to box + * @return a boxed copy of {@code value} + */ + static PrimitiveConstant forChar(char i) { + return new PrimitiveConstant(Kind.Char, i); + } + + /** + * Creates a boxed short constant. + * + * @param i the short value to box + * @return a boxed copy of {@code value} + */ + static PrimitiveConstant forShort(short i) { + return new PrimitiveConstant(Kind.Short, i); + } + + /** + * Creates a {@link JavaConstant} from a primitive integer of a certain kind. + */ + static PrimitiveConstant forIntegerKind(Kind kind, long i) { + switch (kind) { + case Boolean: + return forBoolean(i != 0); + case Byte: + return forByte((byte) i); + case Short: + return forShort((short) i); + case Char: + return forChar((char) i); + case Int: + return forInt((int) i); + case Long: + return forLong(i); + default: + throw new IllegalArgumentException("not an integer kind: " + kind); + } + } + + /** + * Creates a {@link JavaConstant} from a primitive integer of a certain width. + */ + static PrimitiveConstant forPrimitiveInt(int bits, long i) { + assert bits <= 64; + switch (bits) { + case 1: + return forBoolean(i != 0); + case 8: + return forByte((byte) i); + case 16: + return forShort((short) i); + case 32: + return forInt((int) i); + case 64: + return forLong(i); + default: + throw new IllegalArgumentException("unsupported integer width: " + bits); + } + } + + /** + * Creates a boxed constant for the given boxed primitive value. + * + * @param value the Java boxed value + * @return the primitive constant holding the {@code value} + */ + static PrimitiveConstant forBoxedPrimitive(Object value) { + if (value instanceof Boolean) { + return forBoolean((Boolean) value); + } else if (value instanceof Byte) { + return forByte((Byte) value); + } else if (value instanceof Character) { + return forChar((Character) value); + } else if (value instanceof Short) { + return forShort((Short) value); + } else if (value instanceof Integer) { + return forInt((Integer) value); + } else if (value instanceof Long) { + return forLong((Long) value); + } else if (value instanceof Float) { + return forFloat((Float) value); + } else if (value instanceof Double) { + return forDouble((Double) value); + } else { + return null; + } + } + + static PrimitiveConstant forIllegal() { + return new PrimitiveConstant(Kind.Illegal, 0); + } + + /** + * Returns a constant with the default value for the given kind. + */ + static JavaConstant defaultForKind(Kind kind) { + switch (kind) { + case Boolean: + return FALSE; + case Byte: + return forByte((byte) 0); + case Char: + return forChar((char) 0); + case Short: + return forShort((short) 0); + case Int: + return INT_0; + case Double: + return DOUBLE_0; + case Float: + return FLOAT_0; + case Long: + return LONG_0; + case Object: + return NULL_POINTER; + default: + throw new IllegalArgumentException(kind.toString()); + } + } + + /** + * Returns the zero value for a given numeric kind. + */ + static JavaConstant zero(Kind kind) { + switch (kind) { + case Boolean: + return FALSE; + case Byte: + return forByte((byte) 0); + case Char: + return forChar((char) 0); + case Double: + return DOUBLE_0; + case Float: + return FLOAT_0; + case Int: + return INT_0; + case Long: + return LONG_0; + case Short: + return forShort((short) 0); + default: + throw new IllegalArgumentException(kind.toString()); + } + } + + /** + * Returns the one value for a given numeric kind. + */ + static JavaConstant one(Kind kind) { + switch (kind) { + case Boolean: + return TRUE; + case Byte: + return forByte((byte) 1); + case Char: + return forChar((char) 1); + case Double: + return DOUBLE_1; + case Float: + return FLOAT_1; + case Int: + return INT_1; + case Long: + return LONG_1; + case Short: + return forShort((short) 1); + default: + throw new IllegalArgumentException(kind.toString()); + } + } + + /** + * Adds two numeric constants. + */ + static JavaConstant add(JavaConstant x, JavaConstant y) { + assert x.getKind() == y.getKind(); + switch (x.getKind()) { + case Byte: + return forByte((byte) (x.asInt() + y.asInt())); + case Char: + return forChar((char) (x.asInt() + y.asInt())); + case Double: + return forDouble(x.asDouble() + y.asDouble()); + case Float: + return forFloat(x.asFloat() + y.asFloat()); + case Int: + return forInt(x.asInt() + y.asInt()); + case Long: + return forLong(x.asLong() + y.asLong()); + case Short: + return forShort((short) (x.asInt() + y.asInt())); + default: + throw new IllegalArgumentException(x.getKind().toString()); + } + } + + /** + * Multiplies two numeric constants. + */ + static PrimitiveConstant mul(JavaConstant x, JavaConstant y) { + assert x.getKind() == y.getKind(); + switch (x.getKind()) { + case Byte: + return forByte((byte) (x.asInt() * y.asInt())); + case Char: + return forChar((char) (x.asInt() * y.asInt())); + case Double: + return forDouble(x.asDouble() * y.asDouble()); + case Float: + return forFloat(x.asFloat() * y.asFloat()); + case Int: + return forInt(x.asInt() * y.asInt()); + case Long: + return forLong(x.asLong() * y.asLong()); + case Short: + return forShort((short) (x.asInt() * y.asInt())); + default: + throw new IllegalArgumentException(x.getKind().toString()); + } + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/JavaField.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/JavaField.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,129 @@ +/* + * Copyright (c) 2009, 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.meta; + +import java.util.*; + +/** + * Represents a reference to a Java field, either resolved or unresolved fields. Fields, like + * methods and types, are resolved through {@link ConstantPool constant pools}. + */ +public interface JavaField extends TrustedInterface { + + /** + * Returns the name of this field. + */ + String getName(); + + /** + * Returns a {@link JavaType} object that identifies the declared type for this field. + */ + JavaType getType(); + + /** + * Returns the kind of this field. This is the same as calling {@link #getType}. + * {@link JavaType#getKind getKind}. + */ + default Kind getKind() { + return getType().getKind(); + } + + /** + * Returns the {@link JavaType} object representing the class or interface that declares this + * field. + */ + JavaType getDeclaringClass(); + + /** + * Gets a string for this field formatted according to a given format specification. A format + * specification is composed of characters that are to be copied verbatim to the result and + * specifiers that denote an attribute of this field that is to be copied to the result. A + * specifier is a single character preceded by a '%' character. The accepted specifiers and the + * field attributes they denote are described below: + * + *
      +     *     Specifier | Description                                          | Example(s)
      +     *     ----------+------------------------------------------------------------------------------------------
      +     *     'T'       | Qualified type                                       | "int" "java.lang.String"
      +     *     't'       | Unqualified type                                     | "int" "String"
      +     *     'H'       | Qualified holder                                     | "java.util.Map.Entry"
      +     *     'h'       | Unqualified holder                                   | "Entry"
      +     *     'n'       | Field name                                           | "age"
      +     *     'f'       | Indicator if field is unresolved, static or instance | "unresolved" "static" "instance"
      +     *     '%'       | A '%' character                                      | "%"
      +     * 
      + * + * @param format a format specification + * @return the result of formatting this field according to {@code format} + * @throws IllegalFormatException if an illegal specifier is encountered in {@code format} + */ + default String format(String format) throws IllegalFormatException { + StringBuilder sb = new StringBuilder(); + int index = 0; + JavaType type = getType(); + while (index < format.length()) { + char ch = format.charAt(index++); + if (ch == '%') { + if (index >= format.length()) { + throw new UnknownFormatConversionException("An unquoted '%' character cannot terminate a field format specification"); + } + char specifier = format.charAt(index++); + boolean qualified = false; + switch (specifier) { + case 'T': + qualified = true; + // fall through + case 't': { + sb.append(type.toJavaName(qualified)); + break; + } + case 'H': + qualified = true; + // fall through + case 'h': { + sb.append(getDeclaringClass().toJavaName(qualified)); + break; + } + case 'n': { + sb.append(getName()); + break; + } + case 'f': { + sb.append(!(this instanceof ResolvedJavaField) ? "unresolved" : ((ResolvedJavaField) this).isStatic() ? "static" : "instance"); + break; + } + case '%': { + sb.append('%'); + break; + } + default: { + throw new UnknownFormatConversionException(String.valueOf(specifier)); + } + } + } else { + sb.append(ch); + } + } + return sb.toString(); + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/JavaMethod.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/JavaMethod.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,141 @@ +/* + * Copyright (c) 2009, 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.meta; + +import java.util.*; + +/** + * Represents a reference to a Java method, either resolved or unresolved. Methods, like fields and + * types, are resolved through {@link ConstantPool constant pools}. + */ +public interface JavaMethod extends TrustedInterface { + + /** + * Returns the name of this method. + */ + String getName(); + + /** + * Returns the {@link JavaType} object representing the class or interface that declares this + * method. + */ + JavaType getDeclaringClass(); + + /** + * Returns the signature of this method. + */ + Signature getSignature(); + + /** + * Gets a string for this method formatted according to a given format specification. A format + * specification is composed of characters that are to be copied verbatim to the result and + * specifiers that denote an attribute of this method that is to be copied to the result. A + * specifier is a single character preceded by a '%' character. The accepted specifiers and the + * method attributes they denote are described below: + * + *
      +     *     Specifier | Description                                          | Example(s)
      +     *     ----------+------------------------------------------------------------------------------------------
      +     *     'R'       | Qualified return type                                | "int" "java.lang.String"
      +     *     'r'       | Unqualified return type                              | "int" "String"
      +     *     'H'       | Qualified holder                                     | "java.util.Map.Entry"
      +     *     'h'       | Unqualified holder                                   | "Entry"
      +     *     'n'       | Method name                                          | "add"
      +     *     'P'       | Qualified parameter types, separated by ', '         | "int, java.lang.String"
      +     *     'p'       | Unqualified parameter types, separated by ', '       | "int, String"
      +     *     'f'       | Indicator if method is unresolved, static or virtual | "unresolved" "static" "virtual"
      +     *     '%'       | A '%' character                                      | "%"
      +     * 
      + * + * @param format a format specification + * @return the result of formatting this method according to {@code format} + * @throws IllegalFormatException if an illegal specifier is encountered in {@code format} + */ + default String format(String format) throws IllegalFormatException { + StringBuilder sb = new StringBuilder(); + int index = 0; + Signature sig = null; + while (index < format.length()) { + char ch = format.charAt(index++); + if (ch == '%') { + if (index >= format.length()) { + throw new UnknownFormatConversionException("An unquoted '%' character cannot terminate a method format specification"); + } + char specifier = format.charAt(index++); + boolean qualified = false; + switch (specifier) { + case 'R': + qualified = true; + // fall through + case 'r': { + if (sig == null) { + sig = getSignature(); + } + sb.append(sig.getReturnType(null).toJavaName(qualified)); + break; + } + case 'H': + qualified = true; + // fall through + case 'h': { + sb.append(getDeclaringClass().toJavaName(qualified)); + break; + } + case 'n': { + sb.append(getName()); + break; + } + case 'P': + qualified = true; + // fall through + case 'p': { + if (sig == null) { + sig = getSignature(); + } + for (int i = 0; i < sig.getParameterCount(false); i++) { + if (i != 0) { + sb.append(", "); + } + sb.append(sig.getParameterType(i, null).toJavaName(qualified)); + } + break; + } + case 'f': { + sb.append(!(this instanceof ResolvedJavaMethod) ? "unresolved" : ((ResolvedJavaMethod) this).isStatic() ? "static" : "virtual"); + break; + } + case '%': { + sb.append('%'); + break; + } + default: { + throw new UnknownFormatConversionException(String.valueOf(specifier)); + } + } + } else { + sb.append(ch); + } + } + return sb.toString(); + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/JavaMethodProfile.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/JavaMethodProfile.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,60 @@ +/* + * 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.meta; + +import com.oracle.jvmci.meta.JavaMethodProfile.ProfiledMethod; + +/** + * This profile object represents the method profile at a specific BCI. The precision of the + * supplied values may vary, but a runtime that provides this information should be aware that it + * will be used to guide performance-critical decisions like speculative inlining, etc. + */ +public final class JavaMethodProfile extends AbstractJavaProfile { + + public JavaMethodProfile(double notRecordedProbability, ProfiledMethod[] pitems) { + super(notRecordedProbability, pitems); + } + + public ProfiledMethod[] getMethods() { + return super.getItems(); + } + + public static class ProfiledMethod extends AbstractProfiledItem { + + public ProfiledMethod(ResolvedJavaMethod method, double probability) { + super(method, probability); + } + + /** + * Returns the type for this profile entry. + */ + public ResolvedJavaMethod getMethod() { + return getItem(); + } + + @Override + public String toString() { + return "{" + item.getName() + ", " + probability + "}"; + } + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/JavaType.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/JavaType.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,153 @@ +/* + * Copyright (c) 2009, 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.meta; + +import static com.oracle.jvmci.meta.MetaUtil.*; + +/** + * Represents a resolved or unresolved type. Types include primitives, objects, {@code void}, and + * arrays thereof. + */ +public interface JavaType extends TrustedInterface { + + /** + * Returns the name of this type in internal form. The following are examples of strings + * returned by this method: + * + *
      +     *     "Ljava/lang/Object;"
      +     *     "I"
      +     *     "[[B"
      +     * 
      + */ + String getName(); + + /** + * Returns an unqualified name of this type. + * + *
      +     *     "Object"
      +     *     "Integer"
      +     * 
      + */ + default String getUnqualifiedName() { + String name = getName(); + if (name.indexOf('/') != -1) { + name = name.substring(name.lastIndexOf('/') + 1); + } + if (name.endsWith(";")) { + name = name.substring(0, name.length() - 1); + } + return name; + } + + /** + * For array types, gets the type of the components, or {@code null} if this is not an array + * type. This method is analogous to {@link Class#getComponentType()}. + */ + JavaType getComponentType(); + + /** + * Gets the elemental type for this given type. The elemental type is the corresponding zero + * dimensional type of an array type. For example, the elemental type of {@code int[][][]} is + * {@code int}. A non-array type is its own elemental type. + */ + default JavaType getElementalType() { + JavaType t = this; + while (t.getComponentType() != null) { + t = t.getComponentType(); + } + return t; + } + + /** + * Gets the array class type representing an array with elements of this type. + */ + JavaType getArrayClass(); + + /** + * Gets the kind of this type. + */ + Kind getKind(); + + /** + * Resolves this type to a {@link ResolvedJavaType}. + * + * @param accessingClass the context of resolution (must not be null) + * @return the resolved Java type + * @throws LinkageError if the resolution failed + * @throws NullPointerException if {@code accessingClass} is {@code null} + */ + ResolvedJavaType resolve(ResolvedJavaType accessingClass); + + /** + * Gets the Java programming language name for this type. The following are examples of strings + * returned by this method: + * + *
      +     *      java.lang.Object
      +     *      int
      +     *      boolean[][]
      +     * 
      + * + * @return the Java name corresponding to this type + */ + default String toJavaName() { + return internalNameToJava(getName(), true, false); + } + + /** + * Gets the Java programming language name for this type. The following are examples of strings + * returned by this method: + * + *
      +     *     qualified == true:
      +     *         java.lang.Object
      +     *         int
      +     *         boolean[][]
      +     *     qualified == false:
      +     *         Object
      +     *         int
      +     *         boolean[][]
      +     * 
      + * + * @param qualified specifies if the package prefix of this type should be included in the + * returned name + * @return the Java name corresponding to this type + */ + default String toJavaName(boolean qualified) { + Kind kind = getKind(); + if (kind == Kind.Object) { + return internalNameToJava(getName(), qualified, false); + } + return getKind().getJavaName(); + } + + /** + * Returns this type's name in the same format as {@link Class#getName()}. + */ + default String toClassName() { + return internalNameToJava(getName(), true, true); + } + +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/JavaTypeProfile.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/JavaTypeProfile.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,195 @@ +/* + * 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.meta; + +import java.util.*; + +import com.oracle.jvmci.meta.JavaTypeProfile.ProfiledType; + +/** + * This profile object represents the type profile at a specific BCI. The precision of the supplied + * values may vary, but a runtime that provides this information should be aware that it will be + * used to guide performance-critical decisions like speculative inlining, etc. + */ +public final class JavaTypeProfile extends AbstractJavaProfile { + + private static final ProfiledType[] EMPTY_ARRAY = new ProfiledType[0]; + + private final TriState nullSeen; + + public JavaTypeProfile(TriState nullSeen, double notRecordedProbability, ProfiledType[] pitems) { + super(notRecordedProbability, pitems); + this.nullSeen = nullSeen; + } + + /** + * Returns whether a null value was at the type check. + */ + public TriState getNullSeen() { + return nullSeen; + } + + /** + * A list of types for which the runtime has recorded probability information. Note that this + * includes both positive and negative types where a positive type is a subtype of the checked + * type and a negative type is not. + */ + public ProfiledType[] getTypes() { + return getItems(); + } + + public JavaTypeProfile restrict(JavaTypeProfile otherProfile) { + if (otherProfile.getNotRecordedProbability() > 0.0) { + // Not useful for restricting since there is an unknown set of types occurring. + return this; + } + + if (this.getNotRecordedProbability() > 0.0) { + // We are unrestricted, so the other profile is always a better estimate. + return otherProfile; + } + + ArrayList result = new ArrayList<>(); + for (int i = 0; i < getItems().length; i++) { + ProfiledType ptype = getItems()[i]; + ResolvedJavaType type = ptype.getItem(); + if (otherProfile.isIncluded(type)) { + result.add(ptype); + } + } + + TriState newNullSeen = (otherProfile.getNullSeen() == TriState.FALSE) ? TriState.FALSE : getNullSeen(); + double newNotRecorded = getNotRecordedProbability(); + return createAdjustedProfile(result, newNullSeen, newNotRecorded); + } + + public JavaTypeProfile restrict(ResolvedJavaType declaredType, boolean nonNull) { + ArrayList result = new ArrayList<>(); + for (int i = 0; i < getItems().length; i++) { + ProfiledType ptype = getItems()[i]; + ResolvedJavaType type = ptype.getItem(); + if (declaredType.isAssignableFrom(type)) { + result.add(ptype); + } + } + + TriState newNullSeen = (nonNull) ? TriState.FALSE : getNullSeen(); + double newNotRecorded = this.getNotRecordedProbability(); + // Assume for the types not recorded, the incompatibility rate is the same. + if (getItems().length != 0) { + newNotRecorded *= ((double) result.size() / (double) getItems().length); + } + return createAdjustedProfile(result, newNullSeen, newNotRecorded); + } + + private JavaTypeProfile createAdjustedProfile(ArrayList result, TriState newNullSeen, double newNotRecorded) { + if (result.size() != this.getItems().length || newNotRecorded != getNotRecordedProbability() || newNullSeen != getNullSeen()) { + if (result.size() == 0) { + return new JavaTypeProfile(newNullSeen, 1.0, EMPTY_ARRAY); + } + double factor; + if (result.size() == this.getItems().length) { + /* List of types did not change, no need to recompute probabilities. */ + factor = 1.0; + } else { + double probabilitySum = 0.0; + for (int i = 0; i < result.size(); i++) { + probabilitySum += result.get(i).getProbability(); + } + probabilitySum += newNotRecorded; + + factor = 1.0 / probabilitySum; // Normalize to 1.0 + assert factor >= 1.0; + } + ProfiledType[] newResult = new ProfiledType[result.size()]; + for (int i = 0; i < newResult.length; ++i) { + ProfiledType curType = result.get(i); + newResult[i] = new ProfiledType(curType.getItem(), Math.min(1.0, curType.getProbability() * factor)); + } + double newNotRecordedTypeProbability = Math.min(1.0, newNotRecorded * factor); + return new JavaTypeProfile(newNullSeen, newNotRecordedTypeProbability, newResult); + } + return this; + } + + @Override + public boolean equals(Object other) { + return super.equals(other) && nullSeen.equals(((JavaTypeProfile) other).nullSeen); + } + + @Override + public int hashCode() { + return nullSeen.hashCode() + super.hashCode(); + } + + public static class ProfiledType extends AbstractProfiledItem { + + public ProfiledType(ResolvedJavaType type, double probability) { + super(type, probability); + assert type.isArray() || type.isConcrete() : type; + } + + /** + * Returns the type for this profile entry. + */ + public ResolvedJavaType getType() { + return getItem(); + } + + @Override + public String toString() { + return String.format("%.6f#%s", probability, item); + } + } + + @Override + public String toString() { + StringBuilder buf = new StringBuilder("JavaTypeProfile", getNotRecordedProbability())).toString(); + } + + /** + * Returns {@code true} if all types seen at this location have been recorded in the profile. + */ + public boolean allTypesRecorded() { + return this.getNotRecordedProbability() == 0.0; + } + + /** + * Returns the single monormorphic type representing this profile or {@code null} if no such + * type exists. + */ + public ResolvedJavaType asSingleType() { + if (allTypesRecorded() && this.getTypes().length == 1) { + return getTypes()[0].getType(); + } + return null; + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/JavaValue.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/JavaValue.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,34 @@ +/* + * 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; + +/** + * Interface for things that represent a Java value. + */ +public interface JavaValue { + + /** + * Returns the kind of this value. + */ + Kind getKind(); +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/Kind.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/Kind.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,486 @@ +/* + * Copyright (c) 2009, 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.reflect.*; + +//JaCoCo Exclude + +/** + * Denotes the basic kinds of types in CRI, including the all the Java primitive types, for example, + * {@link Kind#Int} for {@code int} and {@link Kind#Object} for all object types. A kind has a + * single character short name, a Java name, and a set of flags further describing its behavior. + */ +public enum Kind implements PlatformKind { + /** The primitive boolean kind, represented as an int on the stack. */ + Boolean('z', "boolean", 1, true, java.lang.Boolean.TYPE, java.lang.Boolean.class), + + /** The primitive byte kind, represented as an int on the stack. */ + Byte('b', "byte", 1, true, java.lang.Byte.TYPE, java.lang.Byte.class), + + /** The primitive short kind, represented as an int on the stack. */ + Short('s', "short", 1, true, java.lang.Short.TYPE, java.lang.Short.class), + + /** The primitive char kind, represented as an int on the stack. */ + Char('c', "char", 1, true, java.lang.Character.TYPE, java.lang.Character.class), + + /** The primitive int kind, represented as an int on the stack. */ + Int('i', "int", 1, true, java.lang.Integer.TYPE, java.lang.Integer.class), + + /** The primitive float kind. */ + Float('f', "float", 1, false, java.lang.Float.TYPE, java.lang.Float.class), + + /** The primitive long kind. */ + Long('j', "long", 2, false, java.lang.Long.TYPE, java.lang.Long.class), + + /** The primitive double kind. */ + Double('d', "double", 2, false, java.lang.Double.TYPE, java.lang.Double.class), + + /** The Object kind, also used for arrays. */ + Object('a', "Object", 1, false, null, null), + + /** The void float kind. */ + Void('v', "void", 0, false, java.lang.Void.TYPE, java.lang.Void.class), + + /** The non-type. */ + Illegal('-', "illegal", 0, false, null, null); + + private final char typeChar; + private final String javaName; + private final boolean isStackInt; + private final Class primitiveJavaClass; + private final Class boxedJavaClass; + private final EnumKey key = new EnumKey(this); + private final int slotCount; + + private Kind(char typeChar, String javaName, int slotCount, boolean isStackInt, Class primitiveJavaClass, Class boxedJavaClass) { + this.typeChar = typeChar; + this.javaName = javaName; + this.slotCount = slotCount; + this.isStackInt = isStackInt; + this.primitiveJavaClass = primitiveJavaClass; + this.boxedJavaClass = boxedJavaClass; + assert primitiveJavaClass == null || javaName.equals(primitiveJavaClass.getName()); + } + + /** + * Returns the number of stack slots occupied by this kind according to the Java bytecodes + * specification. + */ + public int getSlotCount() { + return this.slotCount; + } + + /** + * Returns whether this kind occupied two stack slots. + */ + public boolean needsTwoSlots() { + return this.slotCount == 2; + } + + /** + * Returns the name of the kind as a single character. + */ + public char getTypeChar() { + return typeChar; + } + + /** + * Returns the name of this kind which will also be it Java programming language name if it is + * {@linkplain #isPrimitive() primitive} or {@code void}. + */ + public String getJavaName() { + return javaName; + } + + public Key getKey() { + return key; + } + + /** + * Checks whether this type is a Java primitive type. + * + * @return {@code true} if this is {@link #Boolean}, {@link #Byte}, {@link #Char}, + * {@link #Short}, {@link #Int}, {@link #Long}, {@link #Float}, {@link #Double}, or + * {@link #Void}. + */ + public boolean isPrimitive() { + return primitiveJavaClass != null; + } + + /** + * Returns the kind that represents this kind when on the Java operand stack. + * + * @return the kind used on the operand stack + */ + public Kind getStackKind() { + if (isStackInt) { + return Int; + } + return this; + } + + /** + * Checks whether this type is a Java primitive type representing an integer number. + * + * @return {@code true} if the stack kind is {@link #Int} or {@link #Long}. + */ + public boolean isNumericInteger() { + return isStackInt || this == Kind.Long; + } + + /** + * Checks whether this type is a Java primitive type representing an unsigned number. + * + * @return {@code true} if the kind is {@link #Boolean} or {@link #Char}. + */ + public boolean isUnsigned() { + return this == Kind.Boolean || this == Kind.Char; + } + + /** + * Checks whether this type is a Java primitive type representing a floating point number. + * + * @return {@code true} if this is {@link #Float} or {@link #Double}. + */ + public boolean isNumericFloat() { + return this == Kind.Float || this == Kind.Double; + } + + /** + * Checks whether this represent an Object of some sort. + * + * @return {@code true} if this is {@link #Object}. + */ + public boolean isObject() { + return this == Kind.Object; + } + + /** + * Returns the kind corresponding to the Java type string. + * + * @param typeString the Java type string + * @return the kind + */ + public static Kind fromTypeString(String typeString) { + assert typeString.length() > 0; + final char first = typeString.charAt(0); + if (first == '[' || first == 'L') { + return Kind.Object; + } + return Kind.fromPrimitiveOrVoidTypeChar(first); + } + + /** + * Returns the kind of a word given the size of a word in bytes. + * + * @param wordSizeInBytes the size of a word in bytes + * @return the kind representing a word value + */ + public static Kind fromWordSize(int wordSizeInBytes) { + if (wordSizeInBytes == 8) { + return Kind.Long; + } else { + assert wordSizeInBytes == 4 : "Unsupported word size!"; + return Kind.Int; + } + } + + /** + * Returns the kind from the character describing a primitive or void. + * + * @param ch the character + * @return the kind + */ + public static Kind fromPrimitiveOrVoidTypeChar(char ch) { + switch (ch) { + case 'Z': + return Boolean; + case 'C': + return Char; + case 'F': + return Float; + case 'D': + return Double; + case 'B': + return Byte; + case 'S': + return Short; + case 'I': + return Int; + case 'J': + return Long; + case 'V': + return Void; + } + throw new IllegalArgumentException("unknown primitive or void type character: " + ch); + } + + /** + * Returns the Kind representing the given Java class. + * + * @param klass the class + * @return the kind + */ + public static Kind fromJavaClass(Class klass) { + if (klass == Boolean.primitiveJavaClass) { + return Boolean; + } else if (klass == Byte.primitiveJavaClass) { + return Byte; + } else if (klass == Short.primitiveJavaClass) { + return Short; + } else if (klass == Char.primitiveJavaClass) { + return Char; + } else if (klass == Int.primitiveJavaClass) { + return Int; + } else if (klass == Long.primitiveJavaClass) { + return Long; + } else if (klass == Float.primitiveJavaClass) { + return Float; + } else if (klass == Double.primitiveJavaClass) { + return Double; + } else if (klass == Void.primitiveJavaClass) { + return Void; + } else { + return Object; + } + } + + /** + * Returns the Java class representing this kind. + * + * @return the Java class + */ + public Class toJavaClass() { + return primitiveJavaClass; + } + + /** + * Returns the Java class for instances of boxed values of this kind. + * + * @return the Java class + */ + public Class toBoxedJavaClass() { + return boxedJavaClass; + } + + /** + * Converts this value type to a string. + */ + @Override + public String toString() { + return javaName; + } + + /** + * Marker interface for types that should be {@linkplain Kind#format(Object) formatted} with + * their {@link Object#toString()} value. Calling {@link Object#toString()} on other objects + * poses a security risk because it can potentially call user code. + */ + public interface FormatWithToString { + } + + /** + * Classes for which invoking {@link Object#toString()} does not run user code. + */ + private static boolean isToStringSafe(Class c) { + return c == Boolean.class || c == Byte.class || c == Character.class || c == Short.class || c == Integer.class || c == Float.class || c == Long.class || c == Double.class; + } + + /** + * Gets a formatted string for a given value of this kind. + * + * @param value a value of this kind + * @return a formatted string for {@code value} based on this kind + */ + public String format(Object value) { + if (isPrimitive()) { + assert isToStringSafe(value.getClass()); + return value.toString(); + } else { + if (value == null) { + return "null"; + } else { + if (value instanceof String) { + String s = (String) value; + if (s.length() > 50) { + return "String:\"" + s.substring(0, 30) + "...\""; + } else { + return "String:\"" + s + '"'; + } + } else if (value instanceof JavaType) { + return "JavaType:" + ((JavaType) value).toJavaName(); + } else if (value instanceof Enum) { + return MetaUtil.getSimpleName(value.getClass(), true) + ":" + ((Enum) value).name(); + } else if (value instanceof FormatWithToString) { + return MetaUtil.getSimpleName(value.getClass(), true) + ":" + String.valueOf(value); + } else if (value instanceof Class) { + return "Class:" + ((Class) value).getName(); + } else if (isToStringSafe(value.getClass())) { + return value.toString(); + } else if (value.getClass().isArray()) { + return formatArray(value); + } else { + return MetaUtil.getSimpleName(value.getClass(), true) + "@" + System.identityHashCode(value); + } + } + } + } + + private static final int MAX_FORMAT_ARRAY_LENGTH = 5; + + private static String formatArray(Object array) { + Class componentType = array.getClass().getComponentType(); + assert componentType != null; + int arrayLength = Array.getLength(array); + StringBuilder buf = new StringBuilder(MetaUtil.getSimpleName(componentType, true)).append('[').append(arrayLength).append("]{"); + int length = Math.min(MAX_FORMAT_ARRAY_LENGTH, arrayLength); + boolean primitive = componentType.isPrimitive(); + for (int i = 0; i < length; i++) { + if (primitive) { + buf.append(Array.get(array, i)); + } else { + Object o = ((Object[]) array)[i]; + buf.append(Kind.Object.format(o)); + } + if (i != length - 1) { + buf.append(", "); + } + } + if (arrayLength != length) { + buf.append(", ..."); + } + return buf.append('}').toString(); + } + + /** + * The minimum value that can be represented as a value of this kind. + * + * @return the minimum value + */ + public long getMinValue() { + switch (this) { + case Boolean: + return 0; + case Byte: + return java.lang.Byte.MIN_VALUE; + case Char: + return java.lang.Character.MIN_VALUE; + case Short: + return java.lang.Short.MIN_VALUE; + case Int: + return java.lang.Integer.MIN_VALUE; + case Long: + return java.lang.Long.MIN_VALUE; + default: + throw new IllegalArgumentException("illegal call to minValue on " + this); + } + } + + /** + * The maximum value that can be represented as a value of this kind. + * + * @return the maximum value + */ + public long getMaxValue() { + switch (this) { + case Boolean: + return 1; + case Byte: + return java.lang.Byte.MAX_VALUE; + case Char: + return java.lang.Character.MAX_VALUE; + case Short: + return java.lang.Short.MAX_VALUE; + case Int: + return java.lang.Integer.MAX_VALUE; + case Long: + return java.lang.Long.MAX_VALUE; + default: + throw new IllegalArgumentException("illegal call to maxValue on " + this); + } + } + + /** + * Number of bytes that are necessary to represent a value of this kind. + * + * @return the number of bytes + */ + public int getByteCount() { + if (this == Boolean) { + return 1; + } else { + return getBitCount() >> 3; + } + } + + /** + * Number of bits that are necessary to represent a value of this kind. + * + * @return the number of bits + */ + public int getBitCount() { + switch (this) { + case Boolean: + return 1; + case Byte: + return 8; + case Char: + case Short: + return 16; + case Float: + return 32; + case Int: + return 32; + case Double: + return 64; + case Long: + return 64; + default: + throw new IllegalArgumentException("illegal call to bits on " + this); + } + } + + public JavaConstant getDefaultValue() { + switch (this) { + case Boolean: + return JavaConstant.FALSE; + case Int: + return JavaConstant.INT_0; + case Long: + return JavaConstant.LONG_0; + case Float: + return JavaConstant.FLOAT_0; + case Double: + return JavaConstant.DOUBLE_0; + case Object: + return JavaConstant.NULL_POINTER; + case Byte: + case Char: + case Short: + return new PrimitiveConstant(this, 0); + default: + throw new IllegalArgumentException("illegal call to getDefaultValue on " + this); + } + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/KindProvider.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/KindProvider.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,33 @@ +/* + * 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; + +/** + * Interface for classes which can be associated with a Kind. + */ +public interface KindProvider { + + Kind getKind(); + +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/LIRKind.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/LIRKind.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,349 @@ +/* + * 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.meta; + +import java.util.*; + +/** + * Represents the type of values in the LIR. It is composed of a {@link PlatformKind} that gives the + * low level representation of the value, and a {@link #referenceMask} that describes the location + * of object references in the value. + * + *

      Constructing {@link LIRKind} instances

      + * + * During LIR generation, every new {@link Value} should get a {@link LIRKind} of the correct + * {@link PlatformKind} that also contains the correct reference information. {@linkplain LIRKind + * LIRKinds} should be created as follows: + * + *

      + * If the result value is created from one or more input values, the {@link LIRKind} should be + * created with {@link LIRKind#derive}(inputs). If the result has a different {@link PlatformKind} + * than the inputs, {@link LIRKind#derive}(inputs).{@link #changeType}(resultKind) should be used. + *

      + * If the result is an exact copy of one of the inputs, {@link Value#getLIRKind()} can be used. Note + * that this is only correct for move-like operations, like conditional move or compare-and-swap. + * For convert operations, {@link LIRKind#derive} should be used. + *

      + * If it is known that the result will be a reference (e.g. pointer arithmetic where the end result + * is a valid oop), {@link LIRKind#reference} should be used. + *

      + * If it is known that the result will neither be a reference nor be derived from a reference, + * {@link LIRKind#value} can be used. If the operation producing this value has inputs, this is very + * likely wrong, and {@link LIRKind#derive} should be used instead. + *

      + * If it is known that the result is derived from a reference, {@link LIRKind#derivedReference} can + * be used. In most cases, {@link LIRKind#derive} should be used instead, since it is able to detect + * this automatically. + */ +public final class LIRKind { + + /** + * The non-type. This uses {@link #derivedReference}, so it can never be part of an oop map. + */ + public static final LIRKind Illegal = derivedReference(Kind.Illegal); + + private final PlatformKind platformKind; + private final int referenceMask; + + private static final int DERIVED_REFERENCE = -1; + + private LIRKind(PlatformKind platformKind, int referenceMask) { + this.platformKind = platformKind; + this.referenceMask = referenceMask; + } + + /** + * Create a {@link LIRKind} of type {@code platformKind} that contains a primitive value. Should + * be only used when it's guaranteed that the value is not even indirectly derived from a + * reference. Otherwise, {@link #derive(Value...)} should be used instead. + */ + public static LIRKind value(PlatformKind platformKind) { + assert platformKind != Kind.Object : "Object should always be used as reference type"; + return new LIRKind(platformKind, 0); + } + + /** + * Create a {@link LIRKind} of type {@code platformKind} that contains a single tracked oop + * reference. + */ + public static LIRKind reference(PlatformKind platformKind) { + int length = platformKind.getVectorLength(); + assert 0 < length && length < 32 : "vector of " + length + " references not supported"; + return new LIRKind(platformKind, (1 << length) - 1); + } + + /** + * Create a {@link LIRKind} of type {@code platformKind} that contains a value that is derived + * from a reference. Values of this {@link LIRKind} can not be live at safepoints. In most + * cases, this should not be called directly. {@link #derive} should be used instead to + * automatically propagate this information. + */ + public static LIRKind derivedReference(PlatformKind platformKind) { + return new LIRKind(platformKind, DERIVED_REFERENCE); + } + + /** + * Derive a new type from inputs. The result will have the {@link PlatformKind} of one of the + * inputs. If all inputs are values, the result is a value. Otherwise, the result is a derived + * reference. + * + * This method should be used to construct the result {@link LIRKind} of any operation that + * modifies values (e.g. arithmetics). + */ + public static LIRKind derive(Value... inputs) { + assert inputs.length > 0; + for (Value input : inputs) { + LIRKind kind = input.getLIRKind(); + if (kind.isDerivedReference()) { + return kind; + } else if (!kind.isValue()) { + return kind.makeDerivedReference(); + } + } + + // all inputs are values, just return one of them + return inputs[0].getLIRKind(); + } + + /** + * Merge the types of the inputs. The result will have the {@link PlatformKind} of one of the + * inputs. If all inputs are values (references), the result is a value (reference). Otherwise, + * the result is a derived reference. + * + * This method should be used to construct the result {@link LIRKind} of merge operation that do + * not modify values (e.g. phis). + */ + public static LIRKind merge(Value... inputs) { + assert inputs.length > 0; + ArrayList kinds = new ArrayList<>(inputs.length); + for (int i = 0; i < inputs.length; i++) { + kinds.add(inputs[i].getLIRKind()); + } + return merge(kinds); + } + + /** + * @see #merge(Value...) + */ + public static LIRKind merge(Iterable kinds) { + LIRKind mergeKind = null; + + for (LIRKind kind : kinds) { + + assert mergeKind == null || verifyMoveKinds(mergeKind, kind) : String.format("Input kinds do not match %s vs. %s", mergeKind, kind); + + if (kind.isDerivedReference()) { + /** + * Kind is a derived reference therefore the result can only be also a derived + * reference. + */ + return kind; + } + if (mergeKind == null) { + mergeKind = kind; + continue; + } + + if (kind.isValue()) { + /* Kind is a value. */ + if (mergeKind.referenceMask != 0) { + /* + * Inputs consists of values and references. Make the result a derived + * reference. + */ + return mergeKind.makeDerivedReference(); + } + /* Check that other inputs are also values. */ + } else { + /* Kind is a reference. */ + if (mergeKind.referenceMask != kind.referenceMask) { + /* + * Reference maps do not match so the result can only be a derived reference. + */ + return mergeKind.makeDerivedReference(); + } + } + + } + assert mergeKind != null; + + // all inputs are values or references, just return one of them + return mergeKind; + } + + /** + * Create a new {@link LIRKind} with the same reference information and a new + * {@linkplain #getPlatformKind platform kind}. If the new kind is a longer vector than this, + * the new elements are marked as untracked values. + */ + public LIRKind changeType(PlatformKind newPlatformKind) { + if (newPlatformKind == platformKind) { + return this; + } else if (isDerivedReference()) { + return derivedReference(newPlatformKind); + } else if (referenceMask == 0) { + // value type + return new LIRKind(newPlatformKind, 0); + } else { + // reference type + int newLength = Math.min(32, newPlatformKind.getVectorLength()); + int newReferenceMask = referenceMask & (0xFFFFFFFF >>> (32 - newLength)); + assert newReferenceMask != DERIVED_REFERENCE; + return new LIRKind(newPlatformKind, newReferenceMask); + } + } + + /** + * Create a new {@link LIRKind} with a new {@linkplain #getPlatformKind platform kind}. If the + * new kind is longer than this, the reference positions are repeated to fill the vector. + */ + public LIRKind repeat(PlatformKind newPlatformKind) { + if (isDerivedReference()) { + return derivedReference(newPlatformKind); + } else if (referenceMask == 0) { + // value type + return new LIRKind(newPlatformKind, 0); + } else { + // reference type + int oldLength = platformKind.getVectorLength(); + int newLength = newPlatformKind.getVectorLength(); + assert oldLength <= newLength && newLength < 32 && (newLength % oldLength) == 0; + + // repeat reference mask to fill new kind + int newReferenceMask = 0; + for (int i = 0; i < newLength; i += platformKind.getVectorLength()) { + newReferenceMask |= referenceMask << i; + } + + assert newReferenceMask != DERIVED_REFERENCE; + return new LIRKind(newPlatformKind, newReferenceMask); + } + } + + /** + * Create a new {@link LIRKind} with the same type, but marked as containing a derivedReference. + */ + public LIRKind makeDerivedReference() { + return new LIRKind(platformKind, DERIVED_REFERENCE); + } + + /** + * Get the low level type that is used in code generation. + */ + public PlatformKind getPlatformKind() { + return platformKind; + } + + /** + * Check whether this value is derived from a reference. If this returns {@code true}, this + * value must not be live at safepoints. + */ + public boolean isDerivedReference() { + return referenceMask == DERIVED_REFERENCE; + } + + /** + * Check whether the {@code idx}th part of this value is a reference that must be tracked at + * safepoints. + * + * @param idx The index into the vector if this is a vector kind. Must be 0 if this is a scalar + * kind. + */ + public boolean isReference(int idx) { + assert 0 <= idx && idx < platformKind.getVectorLength() : "invalid index " + idx + " in " + this; + return !isDerivedReference() && (referenceMask & 1 << idx) != 0; + } + + /** + * Check whether this kind is a value type that doesn't need to be tracked at safepoints. + */ + public boolean isValue() { + return referenceMask == 0; + } + + @Override + public String toString() { + if (isValue()) { + return platformKind.name(); + } else if (isDerivedReference()) { + return platformKind.name() + "[*]"; + } else { + StringBuilder ret = new StringBuilder(); + ret.append(platformKind.name()); + ret.append('['); + for (int i = 0; i < platformKind.getVectorLength(); i++) { + if (isReference(i)) { + ret.append('.'); + } else { + ret.append(' '); + } + } + ret.append(']'); + return ret.toString(); + } + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((platformKind == null) ? 0 : platformKind.hashCode()); + result = prime * result + referenceMask; + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (!(obj instanceof LIRKind)) { + return false; + } + + LIRKind other = (LIRKind) obj; + return platformKind == other.platformKind && referenceMask == other.referenceMask; + } + + public static boolean verifyMoveKinds(LIRKind dst, LIRKind src) { + if (src.equals(dst)) { + return true; + } + /* + * TODO(je,rs) What we actually want is toStackKind(src.getPlatformKind()).equals( + * dst.getPlatformKind()) but due to the handling of sub-integer at the current point + * (phi-)moves from e.g. integer to short can happen. Therefore we compare stack kinds. + */ + if (toStackKind(src.getPlatformKind()).equals(toStackKind(dst.getPlatformKind()))) { + return !src.isDerivedReference() || dst.isDerivedReference(); + } + return false; + } + + private static PlatformKind toStackKind(PlatformKind platformKind) { + if (platformKind instanceof Kind) { + return ((Kind) platformKind).getStackKind(); + } + return platformKind; + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/LineNumberTable.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/LineNumberTable.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,32 @@ +/* + * Copyright (c) 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.meta; + +public interface LineNumberTable { + + int[] getLineNumberEntries(); + + int[] getBciEntries(); + + int getLineNumber(int bci); +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/LineNumberTableImpl.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/LineNumberTableImpl.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 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.meta; + +public class LineNumberTableImpl implements LineNumberTable { + + private final int[] lineNumbers; + private final int[] bci; + + public LineNumberTableImpl(int[] lineNumbers, int[] bci) { + this.lineNumbers = lineNumbers; + this.bci = bci; + } + + @Override + public int[] getLineNumberEntries() { + return lineNumbers; + } + + @Override + public int[] getBciEntries() { + return bci; + } + + @Override + public int getLineNumber(@SuppressWarnings("hiding") int bci) { + for (int i = 0; i < this.bci.length - 1; i++) { + if (this.bci[i] <= bci && bci < this.bci[i + 1]) { + return lineNumbers[i]; + } + } + return lineNumbers[lineNumbers.length - 1]; + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/Local.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/Local.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,36 @@ +/* + * Copyright (c) 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.meta; + +public interface Local { + + int getStartBCI(); + + int getEndBCI(); + + int getSlot(); + + String getName(); + + JavaType getType(); +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/LocalImpl.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/LocalImpl.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,84 @@ +/* + * Copyright (c) 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.meta; + +public class LocalImpl implements Local { + + private final String name; + private final int startBci; + private final int endBci; + private final int slot; + private final JavaType type; + + public LocalImpl(String name, JavaType type, int startBci, int endBci, int slot) { + this.name = name; + this.startBci = startBci; + this.endBci = endBci; + this.slot = slot; + this.type = type; + } + + @Override + public int getStartBCI() { + return startBci; + } + + @Override + public int getEndBCI() { + return endBci; + } + + @Override + public String getName() { + return name; + } + + @Override + public JavaType getType() { + return type; + } + + @Override + public int getSlot() { + return slot; + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof LocalImpl)) { + return false; + } + LocalImpl that = (LocalImpl) obj; + return this.name.equals(that.name) && this.startBci == that.startBci && this.endBci == that.endBci && this.slot == that.slot && this.type.equals(that.type); + } + + @Override + public int hashCode() { + return super.hashCode(); + } + + @Override + public String toString() { + return "LocalImpl"; + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/LocalVariableTable.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/LocalVariableTable.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,32 @@ +/* + * Copyright (c) 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.meta; + +public interface LocalVariableTable { + + Local[] getLocals(); + + Local[] getLocalsAt(int bci); + + Local getLocal(int slot, int bci); +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/LocalVariableTableImpl.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/LocalVariableTableImpl.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,66 @@ +/* + * Copyright (c) 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.meta; + +import java.util.*; + +public class LocalVariableTableImpl implements LocalVariableTable { + + private final Local[] locals; + + public LocalVariableTableImpl(Local[] locals) { + this.locals = locals; + } + + @Override + public Local getLocal(int slot, int bci) { + Local result = null; + for (Local local : locals) { + if (local.getSlot() == slot && local.getStartBCI() <= bci && local.getEndBCI() >= bci) { + if (result == null) { + result = local; + } else { + throw new IllegalStateException("Locals overlap!"); + } + } + } + return result; + } + + @Override + public Local[] getLocals() { + return locals; + } + + @Override + public Local[] getLocalsAt(int bci) { + List result = new ArrayList<>(); + for (Local l : locals) { + if (l.getStartBCI() <= bci && bci <= l.getEndBCI()) { + result.add(l); + } + } + return result.toArray(new Local[result.size()]); + } + +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/LocationIdentity.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/LocationIdentity.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,82 @@ +/* + * 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.meta; + +import java.util.*; + +// JaCoCo Exclude + +/** + * Marker interface for location identities. Apart from the special values {@link #ANY_LOCATION} and + * {@link #FINAL_LOCATION}, a different location identity of two memory accesses guarantees that the + * two accesses do not interfere. + * + * Clients of {@link LocationIdentity} must use {@link #equals(Object)}, not {@code ==}, when + * comparing two {@link LocationIdentity} values for equality. Likewise, they must not use + * {@link IdentityHashMap}s with {@link LocationIdentity} values as keys. + */ +public abstract class LocationIdentity { + + /** + * Denotes any location. A write to such a location kills all values in a memory map during an + * analysis of memory accesses. A read from this location cannot be moved or coalesced with + * other reads because its interaction with other reads is not known. + */ + private static final LocationIdentity ANY_LOCATION = NamedLocationIdentity.mutable("ANY_LOCATION"); + + /** + * Denotes the location of a value that is guaranteed to be unchanging. + */ + public static final LocationIdentity FINAL_LOCATION = NamedLocationIdentity.immutable("FINAL_LOCATION"); + + /** + * Denotes the location of the length field of a Java array. + */ + public static final LocationIdentity ARRAY_LENGTH_LOCATION = NamedLocationIdentity.immutable("[].length"); + + public static LocationIdentity any() { + return ANY_LOCATION; + } + + /** + * Denotes a location is unchanging in all cases. Not that this is different than the Java + * notion of final which only requires definite assignment. + */ + public abstract boolean isImmutable(); + + public final boolean isMutable() { + return !isImmutable(); + } + + public final boolean isAny() { + return this == ANY_LOCATION; + } + + public final boolean isSingle() { + return this != ANY_LOCATION; + } + + public final boolean overlaps(LocationIdentity other) { + return isAny() || other.isAny() || this.equals(other); + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/MemoryAccessProvider.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/MemoryAccessProvider.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,60 @@ +/* + * 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.meta; + +/** + * Provides memory access operations for the target VM. + */ +public interface MemoryAccessProvider { + + /** + * Reads a value of this kind using a base address and a displacement. No bounds checking or + * type checking is performed. Returns {@code null} if the value is not available at this point. + * + * @param base the base address from which the value is read. + * @param displacement the displacement within the object in bytes + * @return the read value encapsulated in a {@link JavaConstant} object, or {@code null} if the + * value cannot be read. + */ + JavaConstant readUnsafeConstant(Kind kind, JavaConstant base, long displacement); + + /** + * Reads a primitive value using a base address and a displacement. + * + * @param kind the {@link Kind} of the returned {@link JavaConstant} object + * @param base the base address from which the value is read + * @param displacement the displacement within the object in bytes + * @param bits the number of bits to read from memory + * @return the read value encapsulated in a {@link JavaConstant} object of {@link Kind} kind + */ + JavaConstant readPrimitiveConstant(Kind kind, Constant base, long displacement, int bits); + + /** + * Reads a Java {@link Object} value using a base address and a displacement. + * + * @param base the base address from which the value is read + * @param displacement the displacement within the object in bytes + * @return the read value encapsulated in a {@link Constant} object + */ + JavaConstant readObjectConstant(Constant base, long displacement); +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/MetaAccessProvider.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/MetaAccessProvider.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,104 @@ +/* + * 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.meta; + +import java.lang.reflect.*; + +/** + * Provides access to the metadata of a class typically provided in a class file. + */ +public interface MetaAccessProvider { + + /** + * Returns the resolved Java type representing a given Java class. + * + * @param clazz the Java class object + * @return the resolved Java type object + */ + ResolvedJavaType lookupJavaType(Class clazz); + + /** + * Returns the resolved Java types representing some given Java classes. + * + * @param classes the Java class objects + * @return the resolved Java type objects + */ + default ResolvedJavaType[] lookupJavaTypes(Class[] classes) { + ResolvedJavaType[] result = new ResolvedJavaType[classes.length]; + for (int i = 0; i < result.length; i++) { + result[i] = lookupJavaType(classes[i]); + } + return result; + } + + /** + * Provides the {@link ResolvedJavaMethod} for a {@link Method} or {@link Constructor} obtained + * via reflection. + */ + ResolvedJavaMethod lookupJavaMethod(Executable reflectionMethod); + + /** + * Provides the {@link ResolvedJavaField} for a {@link Field} obtained via reflection. + */ + ResolvedJavaField lookupJavaField(Field reflectionField); + + /** + * Returns the resolved Java type of the given {@link JavaConstant} object. + * + * @return {@code null} if {@code constant.isNull() || !constant.kind.isObject()} + */ + ResolvedJavaType lookupJavaType(JavaConstant constant); + + /** + * Returns the number of bytes occupied by this constant value or constant object. + * + * @param constant the constant whose bytes should be measured + * @return the number of bytes occupied by this constant + */ + long getMemorySize(JavaConstant constant); + + /** + * Parses a method + * descriptor into a {@link Signature}. The behavior of this method is undefined if the + * method descriptor is not well formed. + */ + Signature parseMethodDescriptor(String methodDescriptor); + + /** + * Encodes a deoptimization action and a deoptimization reason in an integer value. + * + * @param debugId an integer that can be used to track the origin of a deoptimization at + * runtime. There is no guarantee that the runtime will use this value. The runtime + * may even keep fewer than 32 bits. + * + * @return the encoded value as an integer + */ + JavaConstant encodeDeoptActionAndReason(DeoptimizationAction action, DeoptimizationReason reason, int debugId); + + DeoptimizationReason decodeDeoptReason(JavaConstant constant); + + DeoptimizationAction decodeDeoptAction(JavaConstant constant); + + int decodeDebugId(JavaConstant constant); +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/MetaUtil.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/MetaUtil.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,341 @@ +/* + * 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.meta; + +import java.io.*; +import java.util.*; + +/** + * Miscellaneous collection of utility methods used by {@code com.oracle.jvmci.meta} and its + * clients. + */ +public class MetaUtil { + + private static class ClassInfo { + public long totalSize; + public long instanceCount; + + @Override + public String toString() { + return "totalSize=" + totalSize + ", instanceCount=" + instanceCount; + } + } + + /** + * Returns the number of bytes occupied by this constant value or constant object and + * recursively all values reachable from this value. + * + * @param constant the constant whose bytes should be measured + * @param printTopN print total size and instance count of the top n classes is desired + * @return the number of bytes occupied by this constant + */ + public static long getMemorySizeRecursive(MetaAccessProvider access, ConstantReflectionProvider constantReflection, JavaConstant constant, PrintStream out, int printTopN) { + Set marked = new HashSet<>(); + Deque stack = new ArrayDeque<>(); + if (constant.getKind() == Kind.Object && constant.isNonNull()) { + marked.add(constant); + } + final HashMap histogram = new HashMap<>(); + stack.push(constant); + long sum = 0; + while (!stack.isEmpty()) { + JavaConstant c = stack.pop(); + long memorySize = access.getMemorySize(constant); + sum += memorySize; + if (c.getKind() == Kind.Object && c.isNonNull()) { + ResolvedJavaType clazz = access.lookupJavaType(c); + if (!histogram.containsKey(clazz)) { + histogram.put(clazz, new ClassInfo()); + } + ClassInfo info = histogram.get(clazz); + info.instanceCount++; + info.totalSize += memorySize; + ResolvedJavaType type = access.lookupJavaType(c); + if (type.isArray()) { + if (!type.getComponentType().isPrimitive()) { + int length = constantReflection.readArrayLength(c); + for (int i = 0; i < length; i++) { + JavaConstant value = constantReflection.readArrayElement(c, i); + pushConstant(marked, stack, value); + } + } + } else { + ResolvedJavaField[] instanceFields = type.getInstanceFields(true); + for (ResolvedJavaField f : instanceFields) { + if (f.getKind() == Kind.Object) { + JavaConstant value = constantReflection.readFieldValue(f, c); + pushConstant(marked, stack, value); + } + } + } + } + } + ArrayList clazzes = new ArrayList<>(); + clazzes.addAll(histogram.keySet()); + Collections.sort(clazzes, new Comparator() { + + @Override + public int compare(ResolvedJavaType o1, ResolvedJavaType o2) { + long l1 = histogram.get(o1).totalSize; + long l2 = histogram.get(o2).totalSize; + if (l1 > l2) { + return -1; + } else if (l1 == l2) { + return 0; + } else { + return 1; + } + } + }); + + int z = 0; + for (ResolvedJavaType c : clazzes) { + if (z > printTopN) { + break; + } + out.println("Class " + c + ", " + histogram.get(c)); + ++z; + } + + return sum; + } + + private static void pushConstant(Set marked, Deque stack, JavaConstant value) { + if (value.isNonNull()) { + if (!marked.contains(value)) { + marked.add(value); + stack.push(value); + } + } + } + + /** + * Calls {@link JavaType#resolve(ResolvedJavaType)} on an array of types. + */ + public static ResolvedJavaType[] resolveJavaTypes(JavaType[] types, ResolvedJavaType accessingClass) { + ResolvedJavaType[] result = new ResolvedJavaType[types.length]; + for (int i = 0; i < result.length; i++) { + result[i] = types[i].resolve(accessingClass); + } + return result; + } + + /** + * Extends the functionality of {@link Class#getSimpleName()} to include a non-empty string for + * anonymous and local classes. + * + * @param clazz the class for which the simple name is being requested + * @param withEnclosingClass specifies if the returned name should be qualified with the name(s) + * of the enclosing class/classes of {@code clazz} (if any). This option is ignored + * if {@code clazz} denotes an anonymous or local class. + * @return the simple name + */ + public static String getSimpleName(Class clazz, boolean withEnclosingClass) { + final String simpleName = clazz.getSimpleName(); + if (simpleName.length() != 0) { + if (withEnclosingClass) { + String prefix = ""; + Class enclosingClass = clazz; + while ((enclosingClass = enclosingClass.getEnclosingClass()) != null) { + prefix = enclosingClass.getSimpleName() + "." + prefix; + } + return prefix + simpleName; + } + return simpleName; + } + // Must be an anonymous or local class + final String name = clazz.getName(); + int index = name.indexOf('$'); + if (index == -1) { + return name; + } + index = name.lastIndexOf('.', index); + if (index == -1) { + return name; + } + return name.substring(index + 1); + } + + static String internalNameToJava(String name, boolean qualified, boolean classForNameCompatible) { + switch (name.charAt(0)) { + case 'L': { + String result = name.substring(1, name.length() - 1).replace('/', '.'); + if (!qualified) { + final int lastDot = result.lastIndexOf('.'); + if (lastDot != -1) { + result = result.substring(lastDot + 1); + } + } + return result; + } + case '[': + return classForNameCompatible ? name.replace('/', '.') : internalNameToJava(name.substring(1), qualified, classForNameCompatible) + "[]"; + default: + if (name.length() != 1) { + throw new IllegalArgumentException("Illegal internal name: " + name); + } + return Kind.fromPrimitiveOrVoidTypeChar(name.charAt(0)).getJavaName(); + } + } + + /** + * Turns an class name in internal format into a resolved Java type. + */ + public static ResolvedJavaType classForName(String internal, MetaAccessProvider metaAccess, ClassLoader cl) { + Kind k = Kind.fromTypeString(internal); + try { + String n = internalNameToJava(internal, true, true); + return metaAccess.lookupJavaType(k.isPrimitive() ? k.toJavaClass() : Class.forName(n, true, cl)); + } catch (ClassNotFoundException cnfe) { + throw new IllegalArgumentException("could not instantiate class described by " + internal, cnfe); + } + } + + /** + * Convenient shortcut for calling + * {@link #appendLocation(StringBuilder, ResolvedJavaMethod, int)} without having to supply a + * {@link StringBuilder} instance and convert the result to a string. + */ + public static String toLocation(ResolvedJavaMethod method, int bci) { + return appendLocation(new StringBuilder(), method, bci).toString(); + } + + /** + * Appends a string representation of a location specified by a given method and bci to a given + * {@link StringBuilder}. If a stack trace element with a non-null file name and non-negative + * line number is {@linkplain ResolvedJavaMethod#asStackTraceElement(int) available} for the + * given method, then the string returned is the {@link StackTraceElement#toString()} value of + * the stack trace element, suffixed by the bci location. For example: + * + *

      +     *     java.lang.String.valueOf(String.java:2930) [bci: 12]
      +     * 
      + * + * Otherwise, the string returned is the value of applying {@link JavaMethod#format(String)} + * with the format string {@code "%H.%n(%p)"}, suffixed by the bci location. For example: + * + *
      +     *     java.lang.String.valueOf(int) [bci: 12]
      +     * 
      + * + * @param sb + * @param method + * @param bci + */ + public static StringBuilder appendLocation(StringBuilder sb, ResolvedJavaMethod method, int bci) { + if (method != null) { + StackTraceElement ste = method.asStackTraceElement(bci); + if (ste.getFileName() != null && ste.getLineNumber() > 0) { + sb.append(ste); + } else { + sb.append(method.format("%H.%n(%p)")); + } + } else { + sb.append("Null method"); + } + return sb.append(" [bci: ").append(bci).append(']'); + } + + static void appendProfile(StringBuilder buf, AbstractJavaProfile profile, int bci, String type, String sep) { + if (profile != null) { + AbstractProfiledItem[] pitems = profile.getItems(); + if (pitems != null) { + buf.append(String.format("%s@%d:", type, bci)); + for (int j = 0; j < pitems.length; j++) { + AbstractProfiledItem pitem = pitems[j]; + buf.append(String.format(" %.6f (%s)%s", pitem.getProbability(), pitem.getItem(), sep)); + } + if (profile.getNotRecordedProbability() != 0) { + buf.append(String.format(" %.6f %s", profile.getNotRecordedProbability(), type, sep)); + } else { + buf.append(String.format(" %s", type, sep)); + } + } + } + } + + /** + * Converts a Java source-language class name into the internal form. + * + * @param className the class name + * @return the internal name form of the class name + */ + public static String toInternalName(String className) { + String prefix = ""; + String base = className; + while (base.endsWith("[]")) { + prefix += "["; + base = base.substring(base.length() - 2); + } + + switch (className) { + case "boolean": + return prefix + "Z"; + case "byte": + return prefix + "B"; + case "short": + return prefix + "S"; + case "char": + return prefix + "C"; + case "int": + return prefix + "I"; + case "float": + return prefix + "F"; + case "long": + return prefix + "J"; + case "double": + return prefix + "D"; + case "void": + return prefix + "V"; + default: + return prefix + "L" + className.replace('.', '/') + ";"; + } + } + + /** + * Prepends the String {@code indentation} to every line in String {@code lines}, including a + * possibly non-empty line following the final newline. + */ + public static String indent(String lines, String indentation) { + if (lines.length() == 0) { + return lines; + } + final String newLine = "\n"; + if (lines.endsWith(newLine)) { + return indentation + (lines.substring(0, lines.length() - 1)).replace(newLine, newLine + indentation) + newLine; + } + return indentation + lines.replace(newLine, newLine + indentation); + } + + /** + * Gets a string representation of an object based soley on its class and its + * {@linkplain System#identityHashCode(Object) identity hash code}. This avoids and calls to + * virtual methods on the object such as {@link Object#hashCode()}. + */ + public static String identityHashCodeString(Object obj) { + if (obj == null) { + return "null"; + } + return obj.getClass().getName() + "@" + System.identityHashCode(obj); + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/MethodHandleAccessProvider.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/MethodHandleAccessProvider.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,76 @@ +/* + * 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.invoke.*; + +/** + * Interface to access the internals of the {@link MethodHandle} implementation of the VM. An + * implementation of this interface is usually required to access non-public classes, methods, and + * fields of {@link MethodHandle}, i.e., data that is not standardized by the Java specification. + */ +public interface MethodHandleAccessProvider { + + /** + * Identification for methods defined on the class {@link MethodHandle} that are processed by + * the {@link MethodHandleAccessProvider}. + */ + public enum IntrinsicMethod { + /** The method {@code MethodHandle.invokeBasic}. */ + INVOKE_BASIC, + /** The method {@code MethodHandle.linkToStatic}. */ + LINK_TO_STATIC, + /** The method {@code MethodHandle.linkToSpecial}. */ + LINK_TO_SPECIAL, + /** The method {@code MethodHandle.linkToVirtual}. */ + LINK_TO_VIRTUAL, + /** The method {@code MethodHandle.linkToInterface}. */ + LINK_TO_INTERFACE + } + + /** + * Returns the method handle method intrinsic identifier for the provided method, or + * {@code null} if the method is not an intrinsic processed by this interface. + */ + IntrinsicMethod lookupMethodHandleIntrinsic(ResolvedJavaMethod method); + + /** + * Resolves the invocation target for an invocation of {@link IntrinsicMethod#INVOKE_BASIC + * MethodHandle.invokeBasic} with the given constant receiver {@link MethodHandle}. Returns + * {@code null} if the invocation target is not available at this time. + *

      + * The first invocations of a method handle can use an interpreter to lookup the actual invoked + * method; frequently executed method handles can use Java bytecode generation to avoid the + * interpreter overhead. If the parameter forceBytecodeGeneration is set to true, the VM should + * try to generate bytecodes before this method returns. + */ + ResolvedJavaMethod resolveInvokeBasicTarget(JavaConstant methodHandle, boolean forceBytecodeGeneration); + + /** + * Resolves the invocation target for an invocation of a {@code MethodHandle.linkTo*} method + * with the given constant member name. The member name is the last parameter of the + * {@code linkTo*} method. Returns {@code null} if the invocation target is not available at + * this time. + */ + ResolvedJavaMethod resolveLinkToTarget(JavaConstant memberName); +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/MethodIdHolder.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/MethodIdHolder.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,93 @@ +/* + * 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.jvmci.meta; + +import java.util.*; +import java.util.function.*; + +/** + * An object that can be assigned a globally unique identifier for use as a key in a + * {@link MethodIdMap}. + */ +public interface MethodIdHolder { + /** + * Sets the unique, positive, non-zero identifier for this method. + */ + void setMethodId(int id); + + /** + * Gets the identifier set by {@link #setMethodId(int)} or 0 if no identifier was assigned to + * this method. + */ + int getMethodId(); + + /** + * A singleton class for allocating globally unique method identifiers. + */ + static final class MethodIdAllocator { + + /** + * Ensures a given method has a unique identifier. + */ + public int assignId(MethodIdHolder holder) { + assert Thread.holdsLock(instance) : "must only be called from within MethodIdHolder.allocateIds"; + int id = holder.getMethodId(); + if (id == 0) { + id = nextId++; + holder.setMethodId(id); + if (idVerifierMap != null) { + idVerifierMap.put(holder, id); + } + } else { + assert !idVerifierMap.containsKey(holder) || idVerifierMap.get(holder) == id; + } + return id; + } + + private int nextId = 1; + private final Map idVerifierMap; + + @SuppressWarnings("all") + private MethodIdAllocator() { + boolean assertionsEnabled = false; + assert assertionsEnabled = true; + idVerifierMap = assertionsEnabled ? new HashMap<>() : null; + } + + /** + * Singleton instance. + */ + private static final MethodIdAllocator instance = new MethodIdAllocator(); + } + + /** + * Executes some given code that ensures some set of {@link ResolvedJavaMethod}s have unique ids + * {@linkplain MethodIdHolder#setMethodId(int) assigned} to them. The + * {@link Consumer#accept(Object)} method of the given object is called under a global lock. + */ + static void assignIds(Consumer methodIdConsumer) { + synchronized (MethodIdAllocator.instance) { + methodIdConsumer.accept(MethodIdAllocator.instance); + } + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/MethodIdMap.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/MethodIdMap.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,236 @@ +/* + * 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.jvmci.meta; + +import java.lang.reflect.*; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import com.oracle.jvmci.meta.MethodIdHolder.MethodIdAllocator; + +/** + * A map whose keys are {@link MethodIdHolder}s. This data structure can be used for mapping + * identifiers to methods without requiring eager resolution of the latter (e.g., to + * {@link ResolvedJavaMethod}s) and has retrieval as fast as array indexing. The constraints on + * using such a map are: + *

        + *
      • at most one value can be added for any key
      • + *
      • no more entries can be added after the first {@linkplain #get(MethodIdHolder) retrieval}
      • + *
      + * + * @param the type of the values in the map + */ +public class MethodIdMap { + + /** + * Key for a method. + */ + public static class MethodKey { + final boolean isStatic; + final Class declaringClass; + final String name; + final Class[] argumentTypes; + final T value; + int id; + + MethodKey(T data, boolean isStatic, Class declaringClass, String name, Class... argumentTypes) { + assert isStatic || argumentTypes[0] == declaringClass; + this.value = data; + this.isStatic = isStatic; + this.declaringClass = declaringClass; + this.name = name; + this.argumentTypes = argumentTypes; + assert resolveJava() != null; + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof MethodKey) { + MethodKey that = (MethodKey) obj; + boolean res = this.name.equals(that.name) && this.declaringClass.equals(that.declaringClass) && Arrays.equals(this.argumentTypes, that.argumentTypes); + assert !res || this.isStatic == that.isStatic; + return res; + } + return false; + } + + public int getDeclaredParameterCount() { + return isStatic ? argumentTypes.length : argumentTypes.length - 1; + } + + @Override + public int hashCode() { + // Replay compilation mandates use of stable hash codes + return declaringClass.getName().hashCode() ^ name.hashCode(); + } + + private MethodIdHolder resolve(MetaAccessProvider metaAccess) { + return (MethodIdHolder) metaAccess.lookupJavaMethod(resolveJava()); + } + + private Executable resolveJava() { + try { + Executable res; + Class[] parameterTypes = isStatic ? argumentTypes : Arrays.copyOfRange(argumentTypes, 1, argumentTypes.length); + if (name.equals("")) { + res = declaringClass.getDeclaredConstructor(parameterTypes); + } else { + res = declaringClass.getDeclaredMethod(name, parameterTypes); + } + assert Modifier.isStatic(res.getModifiers()) == isStatic; + return res; + } catch (NoSuchMethodException | SecurityException e) { + throw new InternalError(e); + } + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(declaringClass.getName()).append('.').append(name).append('('); + for (Class p : argumentTypes) { + if (sb.charAt(sb.length() - 1) != '(') { + sb.append(", "); + } + sb.append(p.getSimpleName()); + } + return sb.append(')').toString(); + } + } + + private final MetaAccessProvider metaAccess; + + /** + * Initial list of entries. + */ + private final List> registrations; + + /** + * Entry array that is initialized upon first call to {@link #get(MethodIdHolder)}. + * + * Note: this must be volatile since double-checked locking is used to initialize it + */ + private volatile V[] entries; + + /** + * The minimum {@linkplain MethodIdHolder#getMethodId() id} for a key in this map. + */ + private int minId = Integer.MAX_VALUE; + + public MethodIdMap(MetaAccessProvider metaAccess) { + this.metaAccess = metaAccess; + this.registrations = new ArrayList<>(INITIAL_CAPACITY); + } + + private static final int INITIAL_CAPACITY = 64; + + /** + * Adds an entry to this map for a specified method. + * + * @param value value to be associated with the specified method + * @param isStatic specifies if the method is static + * @param declaringClass the class declaring the method + * @param name the name of the method + * @param argumentTypes the argument types of the method. Element 0 of this array must be + * {@code declaringClass} iff the method is non-static. + * @return an object representing the method + */ + public MethodKey put(V value, boolean isStatic, Class declaringClass, String name, Class... argumentTypes) { + assert isStatic || argumentTypes[0] == declaringClass; + MethodKey methodKey = new MethodKey<>(value, isStatic, declaringClass, name, argumentTypes); + assert entries == null : "registration is closed"; + assert !registrations.contains(methodKey) : "a value is already registered for " + methodKey; + registrations.add(methodKey); + return methodKey; + } + + @SuppressWarnings("unchecked") + protected V[] allocateEntries(int length) { + return (V[]) new Object[length]; + } + + /** + * Determines if a method denoted by a given {@link MethodKey} is in this map. + */ + public boolean containsKey(MethodKey key) { + return registrations.contains(key); + } + + public V get(MethodIdHolder method) { + if (entries == null) { + createEntries(); + } + + int id = method.getMethodId(); + int index = id - minId; + return index >= 0 && index < entries.length ? entries[index] : null; + } + + public void createEntries() { + // 'assignIds' synchronizes on a global lock which ensures thread safe + // allocation of identifiers across all MethodIdHolder objects + MethodIdHolder.assignIds(new Consumer() { + + public void accept(MethodIdAllocator idAllocator) { + if (entries == null) { + if (registrations.isEmpty()) { + entries = allocateEntries(0); + } else { + int max = Integer.MIN_VALUE; + for (MethodKey methodKey : registrations) { + MethodIdHolder m = methodKey.resolve(metaAccess); + int id = idAllocator.assignId(m); + if (id < minId) { + minId = id; + } + if (id > max) { + max = id; + } + methodKey.id = id; + } + + int length = (max - minId) + 1; + entries = allocateEntries(length); + for (MethodKey m : registrations) { + int index = m.id - minId; + entries[index] = m.value; + } + } + } + } + }); + } + + @Override + public String toString() { + return registrations.stream().map(MethodKey::toString).collect(Collectors.joining(", ")); + } + + public MetaAccessProvider getMetaAccess() { + return metaAccess; + } + + public int size() { + return registrations.size(); + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/ModifiersProvider.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/ModifiersProvider.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,140 @@ +/* + * 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.meta; + +import static java.lang.reflect.Modifier.*; + +import java.lang.reflect.*; + +/** + * A Java element (i.e., a class, interface, field or method) that is described by a set of Java + * language {@linkplain #getModifiers() modifiers}. + */ +public interface ModifiersProvider { + + /** + * Returns the Java language modifiers for this element. + */ + int getModifiers(); + + /** + * @see Modifier#isInterface(int) + */ + default boolean isInterface() { + return Modifier.isInterface(getModifiers()); + } + + /** + * @see Modifier#isSynchronized(int) + */ + default boolean isSynchronized() { + return Modifier.isSynchronized(getModifiers()); + } + + /** + * @see Modifier#isStatic(int) + */ + default boolean isStatic() { + return Modifier.isStatic(getModifiers()); + } + + /** + * @see Modifier#isFinal(int) + */ + default boolean isFinal() { + return Modifier.isFinal(getModifiers()); + } + + /** + * @see Modifier#isPublic(int) + */ + default boolean isPublic() { + return Modifier.isPublic(getModifiers()); + } + + /** + * Determines if this element is neither {@linkplain #isPublic() public}, + * {@linkplain #isProtected() protected} nor {@linkplain #isPrivate() private}. + */ + default boolean isPackagePrivate() { + return ((PUBLIC | PROTECTED | PRIVATE) & getModifiers()) == 0; + } + + /** + * @see Modifier#isPrivate(int) + */ + default boolean isPrivate() { + return Modifier.isPrivate(getModifiers()); + } + + /** + * @see Modifier#isProtected(int) + */ + default boolean isProtected() { + return Modifier.isProtected(getModifiers()); + } + + /** + * @see Modifier#isTransient(int) + */ + default boolean isTransient() { + return Modifier.isTransient(getModifiers()); + } + + /** + * @see Modifier#isStrict(int) + */ + default boolean isStrict() { + return Modifier.isStrict(getModifiers()); + } + + /** + * @see Modifier#isVolatile(int) + */ + default boolean isVolatile() { + return Modifier.isVolatile(getModifiers()); + } + + /** + * @see Modifier#isNative(int) + */ + default boolean isNative() { + return Modifier.isNative(getModifiers()); + } + + /** + * @see Modifier#isAbstract(int) + */ + default boolean isAbstract() { + return Modifier.isAbstract(getModifiers()); + } + + /** + * Checks that the method is concrete and not abstract. + * + * @return whether the method is a concrete method + */ + default boolean isConcrete() { + return !isAbstract(); + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/NamedLocationIdentity.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/NamedLocationIdentity.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,118 @@ +/* + * 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.meta; + +import java.util.*; + +import com.oracle.jvmci.meta.Kind.FormatWithToString; + +/** + * A {@link LocationIdentity} with a name. + */ +public final class NamedLocationIdentity extends LocationIdentity implements FormatWithToString { + + /** + * Map for asserting all {@link NamedLocationIdentity} instances have a unique name. + */ + static class DB { + private static final HashMap map = new HashMap<>(); + + static boolean checkUnique(NamedLocationIdentity identity) { + NamedLocationIdentity oldValue = map.put(identity.name, identity); + if (oldValue != null) { + throw new AssertionError("identity " + identity + " already exists"); + } + return true; + } + } + + private final String name; + private final boolean immutable; + + private NamedLocationIdentity(String name, boolean immutable) { + this.name = name; + this.immutable = immutable; + } + + /** + * Creates a named unique location identity for read and write operations against mutable + * memory. + * + * @param name the name of the new location identity + */ + public static NamedLocationIdentity mutable(String name) { + return create(name, false); + } + + /** + * Creates a named unique location identity for read operations against immutable memory. + * Immutable memory will never have a visible write in the graph, which is more restictive than + * Java final. + * + * @param name the name of the new location identity + */ + public static NamedLocationIdentity immutable(String name) { + return create(name, true); + } + + /** + * Creates a named unique location identity for read and write operations. + * + * @param name the name of the new location identity + * @param immutable true if the location is immutable + */ + private static NamedLocationIdentity create(String name, boolean immutable) { + NamedLocationIdentity id = new NamedLocationIdentity(name, immutable); + assert DB.checkUnique(id); + return id; + } + + @Override + public boolean isImmutable() { + return immutable; + } + + @Override + public String toString() { + return name + (isImmutable() ? ":final" : ""); + } + + /** + * Returns the named location identity for an array of the given element kind. Array accesses of + * the same kind must have the same location identity unless an alias analysis guarantees that + * two distinct arrays are accessed. + */ + public static LocationIdentity getArrayLocation(Kind elementKind) { + return ARRAY_LOCATIONS.get(elementKind); + } + + private static final EnumMap ARRAY_LOCATIONS = initArrayLocations(); + + private static EnumMap initArrayLocations() { + EnumMap result = new EnumMap<>(Kind.class); + for (Kind kind : Kind.values()) { + result.put(kind, NamedLocationIdentity.mutable("Array: " + kind.getJavaName())); + } + return result; + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/NullConstant.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/NullConstant.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,93 @@ +/* + * 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; + +/** + * The implementation type of the {@link JavaConstant#NULL_POINTER null constant}. + */ +final class NullConstant extends AbstractValue implements JavaConstant { + + protected NullConstant() { + super(LIRKind.reference(Kind.Object)); + } + + @Override + public boolean isNull() { + return true; + } + + @Override + public boolean isDefaultForKind() { + return true; + } + + @Override + public Object asBoxedPrimitive() { + throw new IllegalArgumentException(); + } + + @Override + public int asInt() { + throw new IllegalArgumentException(); + } + + @Override + public boolean asBoolean() { + throw new IllegalArgumentException(); + } + + @Override + public long asLong() { + throw new IllegalArgumentException(); + } + + @Override + public float asFloat() { + throw new IllegalArgumentException(); + } + + @Override + public double asDouble() { + throw new IllegalArgumentException(); + } + + @Override + public String toString() { + return JavaConstant.toString(this); + } + + @Override + public String toValueString() { + return "null"; + } + + @Override + public int hashCode() { + return 13; + } + + @Override + public boolean equals(Object o) { + return o instanceof NullConstant; + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/PlatformKind.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/PlatformKind.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,74 @@ +/* + * 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.meta; + +/** + * Represents a platform-specific low-level type for values. + */ +public interface PlatformKind { + + String name(); + + JavaConstant getDefaultValue(); + + public interface Key { + + } + + public class EnumKey implements Key { + @SuppressWarnings("rawtypes") private final Enum e; + + @SuppressWarnings("rawtypes") + public EnumKey(Enum e) { + this.e = e; + } + + @Override + public int hashCode() { + return e.ordinal() ^ e.name().hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (obj == this) { + return true; + } + if (obj instanceof EnumKey) { + EnumKey that = (EnumKey) obj; + return this.e == that.e; + } + return false; + } + } + + /** + * Gets a value associated with this object that can be used as a stable key in a map. The + * {@link Object#hashCode()} implementation of the returned value should be stable between VM + * executions. + */ + Key getKey(); + + default int getVectorLength() { + return 1; + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/PrimitiveConstant.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/PrimitiveConstant.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,164 @@ +/* + * Copyright (c) 2009, 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.meta; + +import java.nio.*; + +/** + * Represents a primitive constant value, such as an integer or floating point number, within the + * compiler and across the compiler/runtime interface. + */ +public class PrimitiveConstant extends AbstractValue implements JavaConstant, SerializableConstant { + + /** + * The boxed primitive value as a {@code long}. For {@code float} and {@code double} values, + * this value is the result of {@link Float#floatToRawIntBits(float)} and + * {@link Double#doubleToRawLongBits(double)} respectively. + */ + private final long primitive; + + protected PrimitiveConstant(Kind kind, long primitive) { + super(LIRKind.value(kind)); + this.primitive = primitive; + + assert kind.isPrimitive() || kind == Kind.Illegal; + } + + @Override + public boolean isNull() { + return false; + } + + @Override + public boolean isDefaultForKind() { + return primitive == 0; + } + + @Override + public boolean asBoolean() { + assert getKind() == Kind.Boolean; + return primitive != 0L; + } + + @Override + public int asInt() { + assert getKind().getStackKind() == Kind.Int : getKind().getStackKind(); + return (int) primitive; + } + + @Override + public long asLong() { + assert getKind().isNumericInteger(); + return primitive; + } + + @Override + public float asFloat() { + assert getKind() == Kind.Float; + return Float.intBitsToFloat((int) primitive); + } + + @Override + public double asDouble() { + assert getKind() == Kind.Double; + return Double.longBitsToDouble(primitive); + } + + @Override + public Object asBoxedPrimitive() { + switch (getKind()) { + case Byte: + return Byte.valueOf((byte) primitive); + case Boolean: + return Boolean.valueOf(asBoolean()); + case Short: + return Short.valueOf((short) primitive); + case Char: + return Character.valueOf((char) primitive); + case Int: + return Integer.valueOf(asInt()); + case Long: + return Long.valueOf(asLong()); + case Float: + return Float.valueOf(asFloat()); + case Double: + return Double.valueOf(asDouble()); + default: + throw new IllegalArgumentException("unexpected kind " + getKind()); + } + } + + @Override + public int getSerializedSize() { + return getKind().getByteCount(); + } + + @Override + public void serialize(ByteBuffer buffer) { + switch (getKind()) { + case Byte: + case Boolean: + buffer.put((byte) primitive); + break; + case Short: + buffer.putShort((short) primitive); + break; + case Char: + buffer.putChar((char) primitive); + break; + case Int: + buffer.putInt(asInt()); + break; + case Long: + buffer.putLong(asLong()); + break; + case Float: + buffer.putFloat(asFloat()); + break; + case Double: + buffer.putDouble(asDouble()); + break; + default: + throw new IllegalArgumentException("unexpected kind " + getKind()); + } + } + + @Override + public int hashCode() { + return (int) (primitive ^ (primitive >>> 32)) * (getKind().ordinal() + 31); + } + + @Override + public boolean equals(Object o) { + return o == this || (o instanceof PrimitiveConstant && super.equals(o) && primitive == ((PrimitiveConstant) o).primitive); + } + + @Override + public String toString() { + if (getKind() == Kind.Illegal) { + return "illegal"; + } else { + return getKind().getJavaName() + "[" + asBoxedPrimitive() + "|0x" + Long.toHexString(primitive) + "]"; + } + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/ProfilingInfo.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/ProfilingInfo.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,199 @@ +/* + * Copyright (c) 2012, 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.meta; + +/** + * Provides access to the profiling information of one specific method. Every accessor method + * returns the information that is available at the time of invocation. If a method is invoked + * multiple times, it may return significantly different results for every invocation as the + * profiling information may be changed by other Java threads at any time. + */ +public interface ProfilingInfo { + + /** + * Returns the length of the bytecodes associated with this profile. + */ + int getCodeSize(); + + /** + * Returns an estimate of how often the branch at the given byte code was taken. + * + * @return The estimated probability, with 0.0 meaning never and 1.0 meaning always, or -1 if + * this information is not available. + */ + double getBranchTakenProbability(int bci); + + /** + * Returns an estimate of how often the switch cases are taken at the given BCI. The default + * case is stored as the last entry. + * + * @return A double value that contains the estimated probabilities, with 0.0 meaning never and + * 1.0 meaning always, or -1 if this information is not available. + */ + double[] getSwitchProbabilities(int bci); + + /** + * Returns the TypeProfile for the given BCI. + * + * @return Returns a JavaTypeProfile object, or null if not available. + */ + JavaTypeProfile getTypeProfile(int bci); + + /** + * Returns the MethodProfile for the given BCI. + * + * @return Returns a JavaMethodProfile object, or null if not available. + */ + JavaMethodProfile getMethodProfile(int bci); + + /** + * Returns information if the given BCI did ever throw an exception. + * + * @return {@link TriState#TRUE} if the instruction has thrown an exception at least once, + * {@link TriState#FALSE} if it never threw an exception, and {@link TriState#UNKNOWN} + * if this information was not recorded. + */ + TriState getExceptionSeen(int bci); + + /** + * Returns information if null was ever seen for the given BCI. This information is collected + * for the aastore, checkcast and instanceof bytecodes. + * + * @return {@link TriState#TRUE} if null was seen for the instruction, {@link TriState#FALSE} if + * null was NOT seen, and {@link TriState#UNKNOWN} if this information was not recorded. + */ + TriState getNullSeen(int bci); + + /** + * Returns an estimate how often the current BCI was executed. Avoid comparing execution counts + * to each other, as the returned value highly depends on the time of invocation. + * + * @return the estimated execution count or -1 if not available. + */ + int getExecutionCount(int bci); + + /** + * Returns how frequently a method was deoptimized for the given deoptimization reason. This + * only indicates how often the method did fall back to the interpreter for the execution and + * does not indicate how often it was recompiled. + * + * @param reason the reason for which the number of deoptimizations should be queried + * @return the number of times the compiled method deoptimized for the given reason. + */ + int getDeoptimizationCount(DeoptimizationReason reason); + + /** + * Records the size of the compiler intermediate representation (IR) associated with this + * method. + * + * @param irType the IR type for which the size is being recorded + * @param irSize the IR size to be recorded. The unit depends on the IR. + * @return whether recording this information for {@code irType} is supported + */ + boolean setCompilerIRSize(Class irType, int irSize); + + /** + * Gets the size of the compiler intermediate representation (IR) associated with this method + * last recorded by {@link #setCompilerIRSize(Class, int)}. + * + * @param irType the IR type for which the size is being requested + * @return the requested IR size or -1 if it is unavailable for {@code irType} + */ + int getCompilerIRSize(Class irType); + + /** + * Returns true if the profiling information can be assumed as sufficiently accurate. + * + * @return true if the profiling information was recorded often enough mature enough, false + * otherwise. + */ + boolean isMature(); + + /** + * Force data to be treated as mature if possible. + */ + void setMature(); + + /** + * Formats this profiling information to a string. + * + * @param method an optional method that augments the profile string returned + * @param sep the separator to use for each separate profile record + */ + default String toString(ResolvedJavaMethod method, String sep) { + StringBuilder buf = new StringBuilder(100); + if (method != null) { + buf.append(String.format("canBeStaticallyBound: %b%s", method.canBeStaticallyBound(), sep)); + } + for (int i = 0; i < getCodeSize(); i++) { + if (getExecutionCount(i) != -1) { + buf.append(String.format("executionCount@%d: %d%s", i, getExecutionCount(i), sep)); + } + + if (getBranchTakenProbability(i) != -1) { + buf.append(String.format("branchProbability@%d: %.6f%s", i, getBranchTakenProbability(i), sep)); + } + + double[] switchProbabilities = getSwitchProbabilities(i); + if (switchProbabilities != null) { + buf.append(String.format("switchProbabilities@%d:", i)); + for (int j = 0; j < switchProbabilities.length; j++) { + buf.append(String.format(" %.6f", switchProbabilities[j])); + } + buf.append(sep); + } + + if (getExceptionSeen(i) != TriState.UNKNOWN) { + buf.append(String.format("exceptionSeen@%d: %s%s", i, getExceptionSeen(i).name(), sep)); + } + + if (getNullSeen(i) != TriState.UNKNOWN) { + buf.append(String.format("nullSeen@%d: %s%s", i, getNullSeen(i).name(), sep)); + } + + JavaTypeProfile typeProfile = getTypeProfile(i); + MetaUtil.appendProfile(buf, typeProfile, i, "types", sep); + + JavaMethodProfile methodProfile = getMethodProfile(i); + MetaUtil.appendProfile(buf, methodProfile, i, "methods", sep); + } + + boolean firstDeoptReason = true; + for (DeoptimizationReason reason : DeoptimizationReason.values()) { + int count = getDeoptimizationCount(reason); + if (count > 0) { + if (firstDeoptReason) { + buf.append("deoptimization history").append(sep); + firstDeoptReason = false; + } + buf.append(String.format(" %s: %d%s", reason.name(), count, sep)); + } + } + if (buf.length() == 0) { + return ""; + } + String s = buf.toString(); + return s.substring(0, s.length() - sep.length()); + } + +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/RawConstant.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/RawConstant.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2009, 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; + +public class RawConstant extends PrimitiveConstant { + + public RawConstant(long rawValue) { + super(Kind.Int, rawValue); + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/ResolvedJavaField.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/ResolvedJavaField.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2009, 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.*; +import java.lang.reflect.*; + +/** + * Represents a reference to a resolved Java field. Fields, like methods and types, are resolved + * through {@link ConstantPool constant pools}. + */ +public interface ResolvedJavaField extends JavaField, ModifiersProvider { + + /** + * {@inheritDoc} + *

      + * Only the {@linkplain Modifier#fieldModifiers() field flags} specified in the JVM + * specification will be included in the returned mask. + */ + int getModifiers(); + + /** + * Determines if this field was injected by the VM. Such a field, for example, is not derived + * from a class file. + */ + boolean isInternal(); + + /** + * Determines if this field is a synthetic field as defined by the Java Language Specification. + */ + boolean isSynthetic(); + + /** + * Returns the {@link ResolvedJavaType} object representing the class or interface that declares + * this field. + */ + ResolvedJavaType getDeclaringClass(); + + /** + * Returns the annotation for the specified type of this field, if such an annotation is + * present. + * + * @param annotationClass the Class object corresponding to the annotation type + * @return this element's annotation for the specified annotation type if present on this field, + * else {@code null} + */ + T getAnnotation(Class annotationClass); + + /** + * Returns an object representing the unique location identity of this resolved Java field. + * + * @return the location identity of the field + */ + LocationIdentity getLocationIdentity(); +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/ResolvedJavaMethod.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/ResolvedJavaMethod.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,316 @@ +/* + * Copyright (c) 2009, 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.*; +import java.lang.reflect.*; + +/** + * Represents a resolved Java method. Methods, like fields and types, are resolved through + * {@link ConstantPool constant pools}. + */ +public interface ResolvedJavaMethod extends JavaMethod, InvokeTarget, ModifiersProvider { + + /** + * Returns the bytecode of this method, if the method has code. The returned byte array does not + * contain breakpoints or non-Java bytecodes. This may return null if the + * {@link #getDeclaringClass() holder} is not {@link ResolvedJavaType#isLinked() linked}. + * + * The contained constant pool indices may not be the ones found in the original class file but + * they can be used with the JVMCI API (e.g. methods in {@link ConstantPool}). + * + * @return the bytecode of the method, or {@code null} if {@code getCodeSize() == 0} or if the + * code is not ready. + */ + byte[] getCode(); + + /** + * Returns the size of the bytecode of this method, if the method has code. This is equivalent + * to {@link #getCode()}. {@code length} if the method has code. + * + * @return the size of the bytecode in bytes, or 0 if no bytecode is available + */ + int getCodeSize(); + + /** + * Returns the {@link ResolvedJavaType} object representing the class or interface that declares + * this method. + */ + ResolvedJavaType getDeclaringClass(); + + /** + * Returns the maximum number of locals used in this method's bytecodes. + */ + int getMaxLocals(); + + /** + * Returns the maximum number of stack slots used in this method's bytecodes. + */ + int getMaxStackSize(); + + /** + * {@inheritDoc} + *

      + * Only the {@linkplain Modifier#methodModifiers() method flags} specified in the JVM + * specification will be included in the returned mask. + */ + int getModifiers(); + + /** + * Determines if this method is a synthetic method as defined by the Java Language + * Specification. + */ + boolean isSynthetic(); + + /** + * Returns {@code true} if this method is a default method; returns {@code false} otherwise. + * + * A default method is a public non-abstract instance method, that is, a non-static method with + * a body, declared in an interface type. + * + * @return true if and only if this method is a default method as defined by the Java Language + * Specification. + */ + boolean isDefault(); + + /** + * Checks whether this method is a class initializer. + * + * @return {@code true} if the method is a class initializer + */ + boolean isClassInitializer(); + + /** + * Checks whether this method is a constructor. + * + * @return {@code true} if the method is a constructor + */ + boolean isConstructor(); + + /** + * Checks whether this method can be statically bound (usually, that means it is final or + * private or static, but not abstract, or the declaring class is final). + * + * @return {@code true} if this method can be statically bound + */ + boolean canBeStaticallyBound(); + + /** + * Returns the list of exception handlers for this method. + */ + ExceptionHandler[] getExceptionHandlers(); + + /** + * Returns a stack trace element for this method and a given bytecode index. + */ + StackTraceElement asStackTraceElement(int bci); + + /** + * Returns an object that provides access to the profiling information recorded for this method. + */ + default ProfilingInfo getProfilingInfo() { + return getProfilingInfo(true, true); + } + + /** + * Returns an object that provides access to the profiling information recorded for this method. + * + * @param includeNormal if true, + * {@linkplain ProfilingInfo#getDeoptimizationCount(DeoptimizationReason) + * deoptimization counts} will include deoptimization that happened during execution + * of standard non-osr methods. + * @param includeOSR if true, + * {@linkplain ProfilingInfo#getDeoptimizationCount(DeoptimizationReason) + * deoptimization counts} will include deoptimization that happened during execution + * of on-stack-replacement methods. + */ + ProfilingInfo getProfilingInfo(boolean includeNormal, boolean includeOSR); + + /** + * Invalidates the profiling information and restarts profiling upon the next invocation. + */ + void reprofile(); + + /** + * Returns the constant pool of this method. + */ + ConstantPool getConstantPool(); + + /** + * Returns all annotations of this method. If no annotations are present, an array of length 0 + * is returned. + */ + Annotation[] getAnnotations(); + + /** + * Returns the annotation for the specified type of this method, if such an annotation is + * present. + * + * @param annotationClass the Class object corresponding to the annotation type + * @return this element's annotation for the specified annotation type if present on this + * method, else {@code null} + */ + T getAnnotation(Class annotationClass); + + /** + * Returns an array of arrays that represent the annotations on the formal parameters, in + * declaration order, of this method. + * + * @see Method#getParameterAnnotations() + */ + Annotation[][] getParameterAnnotations(); + + /** + * Returns an array of {@link Type} objects that represent the formal parameter types, in + * declaration order, of this method. + * + * @see Method#getGenericParameterTypes() + */ + Type[] getGenericParameterTypes(); + + /** + * Returns {@code true} if this method is not excluded from inlining and has associated Java + * bytecodes (@see {@link ResolvedJavaMethod#hasBytecodes()}). + */ + boolean canBeInlined(); + + /** + * Returns {@code true} if the inlining of this method should be forced. + */ + boolean shouldBeInlined(); + + /** + * Returns the LineNumberTable of this method or null if this method does not have a line + * numbers table. + */ + LineNumberTable getLineNumberTable(); + + /** + * Returns the local variable table of this method or null if this method does not have a local + * variable table. + */ + LocalVariableTable getLocalVariableTable(); + + /** + * Invokes the underlying method represented by this object, on the specified object with the + * specified parameters. This method is similar to a reflective method invocation by + * {@link Method#invoke}. + * + * @param receiver The receiver for the invocation, or {@code null} if it is a static method. + * @param arguments The arguments for the invocation. + * @return The value returned by the method invocation, or {@code null} if the return type is + * {@code void}. + */ + JavaConstant invoke(JavaConstant receiver, JavaConstant[] arguments); + + /** + * Gets the encoding of (that is, a constant representing the value of) this method. + * + * @return a constant representing a reference to this method + */ + Constant getEncoding(); + + /** + * Checks if this method is present in the virtual table for subtypes of the specified + * {@linkplain ResolvedJavaType type}. + * + * @return true is this method is present in the virtual table for subtypes of this type. + */ + boolean isInVirtualMethodTable(ResolvedJavaType resolved); + + /** + * Gets the annotation of a particular type for a formal parameter of this method. + * + * @param annotationClass the Class object corresponding to the annotation type + * @param parameterIndex the index of a formal parameter of {@code method} + * @return the annotation of type {@code annotationClass} for the formal parameter present, else + * null + * @throws IndexOutOfBoundsException if {@code parameterIndex} does not denote a formal + * parameter + */ + default T getParameterAnnotation(Class annotationClass, int parameterIndex) { + if (parameterIndex >= 0) { + Annotation[][] parameterAnnotations = getParameterAnnotations(); + for (Annotation a : parameterAnnotations[parameterIndex]) { + if (a.annotationType() == annotationClass) { + return annotationClass.cast(a); + } + } + } + return null; + } + + default JavaType[] toParameterTypes() { + JavaType receiver = isStatic() || isConstructor() ? null : getDeclaringClass(); + return getSignature().toParameterTypes(receiver); + } + + /** + * Gets the annotations of a particular type for the formal parameters of this method. + * + * @param annotationClass the Class object corresponding to the annotation type + * @return the annotation of type {@code annotationClass} (if any) for each formal parameter + * present + */ + @SuppressWarnings("unchecked") + default T[] getParameterAnnotations(Class annotationClass) { + Annotation[][] parameterAnnotations = getParameterAnnotations(); + T[] result = (T[]) Array.newInstance(annotationClass, parameterAnnotations.length); + for (int i = 0; i < parameterAnnotations.length; i++) { + for (Annotation a : parameterAnnotations[i]) { + if (a.annotationType() == annotationClass) { + result[i] = annotationClass.cast(a); + } + } + } + return result; + } + + /** + * Checks whether the method has bytecodes associated with it. Methods without bytecodes are + * either abstract or native methods. + * + * @return whether the definition of this method is Java bytecodes + */ + default boolean hasBytecodes() { + return isConcrete() && !isNative(); + } + + /** + * Checks whether the method has a receiver parameter - i.e., whether it is not static. + * + * @return whether the method has a receiver parameter + */ + default boolean hasReceiver() { + return !isStatic(); + } + + /** + * Determines if this method is {@link java.lang.Object#Object()}. + */ + default boolean isJavaLangObjectInit() { + return getDeclaringClass().isJavaLangObject() && getName().equals(""); + } + + SpeculationLog getSpeculationLog(); +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/ResolvedJavaType.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/ResolvedJavaType.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,354 @@ +/* + * Copyright (c) 2009, 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.*; +import java.net.*; + +import com.oracle.jvmci.meta.Assumptions.AssumptionResult; + +/** + * Represents a resolved Java type. Types include primitives, objects, {@code void}, and arrays + * thereof. Types, like fields and methods, are resolved through {@link ConstantPool constant pools} + * . + */ +public interface ResolvedJavaType extends JavaType, ModifiersProvider { + + /** + * Gets the runtime representation of the Java class object of this type. + */ + JavaConstant getJavaClass(); + + /** + * Gets the runtime representation of the "hub" of this type--that is, the closest part of the + * type representation which is typically stored in the object header. + */ + Constant getObjectHub(); + + /** + * Checks whether this type has a finalizer method. + * + * @return {@code true} if this class has a finalizer + */ + boolean hasFinalizer(); + + /** + * Checks whether this type has any finalizable subclasses so far. Any decisions based on this + * information require the registration of a dependency, since this information may change. + * + * @return {@code true} if this class has any subclasses with finalizers + */ + AssumptionResult hasFinalizableSubclass(); + + /** + * Checks whether this type is an interface. + * + * @return {@code true} if this type is an interface + */ + boolean isInterface(); + + /** + * Checks whether this type is an instance class. + * + * @return {@code true} if this type is an instance class + */ + boolean isInstanceClass(); + + /** + * Checks whether this type is an array class. + * + * @return {@code true} if this type is an array class + */ + boolean isArray(); + + /** + * Checks whether this type is primitive. + * + * @return {@code true} if this type is primitive + */ + boolean isPrimitive(); + + /** + * {@inheritDoc} + *

      + * Only the flags specified in the JVM specification will be included in the returned mask. This + * method is identical to {@link Class#getModifiers()} in terms of the value return for this + * type. + */ + int getModifiers(); + + /** + * Checks whether this type is initialized. If a type is initialized it implies that it was + * {@link #isLinked() linked} and that the static initializer has run. + * + * @return {@code true} if this type is initialized + */ + boolean isInitialized(); + + /** + * Initializes this type. + */ + void initialize(); + + /** + * Checks whether this type is linked and verified. When a type is linked the static initializer + * has not necessarily run. An {@link #isInitialized() initialized} type is always linked. + * + * @return {@code true} if this type is linked + */ + boolean isLinked(); + + /** + * Determines if this type is either the same as, or is a superclass or superinterface of, the + * type represented by the specified parameter. This method is identical to + * {@link Class#isAssignableFrom(Class)} in terms of the value return for this type. + */ + boolean isAssignableFrom(ResolvedJavaType other); + + /** + * Returns true if this type is exactly the type {@link java.lang.Object}. + */ + default boolean isJavaLangObject() { + // Removed assertion due to https://bugs.eclipse.org/bugs/show_bug.cgi?id=434442 + return getSuperclass() == null && !isInterface() && getKind() == Kind.Object; + } + + /** + * Checks whether the specified object is an instance of this type. + * + * @param obj the object to test + * @return {@code true} if the object is an instance of this type + */ + boolean isInstance(JavaConstant obj); + + /** + * Returns this type if it is an exact type otherwise returns null. This type is exact if it is + * void, primitive, final, or an array of a final or primitive type. + * + * @return this type if it is exact; {@code null} otherwise + */ + ResolvedJavaType asExactType(); + + /** + * Gets the super class of this type. If this type represents either the {@code Object} class, + * an interface, a primitive type, or void, then null is returned. If this object represents an + * array class then the type object representing the {@code Object} class is returned. + */ + ResolvedJavaType getSuperclass(); + + /** + * Gets the interfaces implemented or extended by this type. This method is analogous to + * {@link Class#getInterfaces()} and as such, only returns the interfaces directly implemented + * or extended by this type. + */ + ResolvedJavaType[] getInterfaces(); + + /** + * Gets the single implementor of this type. Calling this method on a non-interface type causes + * an exception. + *

      + * If the compiler uses the result of this method for its compilation, the usage must be guarded + * because the verifier can not guarantee that the assigned type really implements this + * interface. Additionally, class loading can invalidate the result of this method. + * + * @return {@code null} if there is no implementor, the implementor if there is only one, or + * {@code this} if there are more than one. + */ + ResolvedJavaType getSingleImplementor(); + + /** + * Walks the class hierarchy upwards and returns the least common class that is a superclass of + * both the current and the given type. + * + * @return the least common type that is a super type of both the current and the given type, or + * {@code null} if primitive types are involved. + */ + ResolvedJavaType findLeastCommonAncestor(ResolvedJavaType otherType); + + /** + * Attempts to get a leaf concrete subclass of this type. + *

      + * For an {@linkplain #isArray() array} type A, the leaf concrete subclass is A if the + * {@linkplain #getElementalType() elemental} type of A is final (which includes primitive + * types). Otherwise {@code null} is returned for A. + *

      + * For a non-array type T, the result is the leaf concrete type in the current hierarchy of T. + *

      + * A runtime may decide not to manage or walk a large hierarchy and so the result is + * conservative. That is, a non-null result is guaranteed to be the leaf concrete class in T's + * hierarchy at the current point in time but a null result does not necessarily imply + * that there is no leaf concrete class in T's hierarchy. + *

      + * If the compiler uses the result of this method for its compilation, it must register the + * {@link AssumptionResult} in its {@link Assumptions} because dynamic class loading can + * invalidate the result of this method. + * + * @return an {@link AssumptionResult} containing the leaf concrete subclass for this type as + * described above + */ + AssumptionResult findLeafConcreteSubtype(); + + ResolvedJavaType getComponentType(); + + default ResolvedJavaType getElementalType() { + ResolvedJavaType t = this; + while (t.isArray()) { + t = t.getComponentType(); + } + return t; + } + + ResolvedJavaType getArrayClass(); + + /** + * Resolves the method implementation for virtual dispatches on objects of this dynamic type. + * This resolution process only searches "up" the class hierarchy of this type. + * + * @param method the method to select the implementation of + * @param callerType the caller or context type used to perform access checks + * @param includeAbstract whether abstract methods should be returned. If it is {@code false} + * this method behaves like {@link #resolveConcreteMethod}. This is just a temporary + * parameter to highlight the changed semantics of this method. TODO (je) remove this + * flag. + * @return the link-time resolved method (might be abstract) or {@code null} if it can not be + * linked + */ + ResolvedJavaMethod resolveMethod(ResolvedJavaMethod method, ResolvedJavaType callerType, boolean includeAbstract); + + /** + * Resolves the method implementation for virtual dispatches on objects of this dynamic type. + * This resolution process only searches "up" the class hierarchy of this type. A broader search + * that also walks "down" the hierarchy is implemented by + * {@link #findUniqueConcreteMethod(ResolvedJavaMethod)}. + * + * @param method the method to select the implementation of + * @param callerType the caller or context type used to perform access checks + * @return the concrete method that would be selected at runtime, or {@code null} if there is no + * concrete implementation of {@code method} in this type or any of its superclasses + */ + ResolvedJavaMethod resolveConcreteMethod(ResolvedJavaMethod method, ResolvedJavaType callerType); + + /** + * Given a {@link ResolvedJavaMethod} A, returns a concrete {@link ResolvedJavaMethod} B that is + * the only possible unique target for a virtual call on A(). Returns {@code null} if either no + * such concrete method or more than one such method exists. Returns the method A if A is a + * concrete method that is not overridden. + *

      + * If the compiler uses the result of this method for its compilation, it must register an + * assumption because dynamic class loading can invalidate the result of this method. + * + * @param method the method A for which a unique concrete target is searched + * @return the unique concrete target or {@code null} if no such target exists or assumptions + * are not supported by this runtime + */ + AssumptionResult findUniqueConcreteMethod(ResolvedJavaMethod method); + + /** + * Returns the instance fields of this class, including + * {@linkplain ResolvedJavaField#isInternal() internal} fields. A zero-length array is returned + * for array and primitive types. The order of fields returned by this method is stable. That + * is, for a single JVM execution the same order is returned each time this method is called. It + * is also the "natural" order, which means that the JVM would expect the fields in this order + * if no specific order is given. + * + * @param includeSuperclasses if true, then instance fields for the complete hierarchy of this + * type are included in the result + * @return an array of instance fields + */ + ResolvedJavaField[] getInstanceFields(boolean includeSuperclasses); + + /** + * Returns the static fields of this class, including + * {@linkplain ResolvedJavaField#isInternal() internal} fields. A zero-length array is returned + * for array and primitive types. The order of fields returned by this method is stable. That + * is, for a single JVM execution the same order is returned each time this method is called. + */ + ResolvedJavaField[] getStaticFields(); + + /** + * Returns the annotation for the specified type of this class, if such an annotation is + * present. + * + * @param annotationClass the Class object corresponding to the annotation type + * @return this element's annotation for the specified annotation type if present on this class, + * else {@code null} + */ + T getAnnotation(Class annotationClass); + + /** + * Returns the instance field of this class (or one of its super classes) at the given offset, + * or {@code null} if there is no such field. + * + * @param offset the offset of the field to look for + * @return the field with the given offset, or {@code null} if there is no such field. + */ + ResolvedJavaField findInstanceFieldWithOffset(long offset, Kind expectedKind); + + /** + * Returns name of source file of this type. + */ + String getSourceFileName(); + + /** + * Returns the class file path - if available - of this type, or {@code null}. + */ + URL getClassFilePath(); + + /** + * Returns {@code true} if the type is a local type. + */ + boolean isLocal(); + + /** + * Returns {@code true} if the type is a member type. + */ + boolean isMember(); + + /** + * Returns the enclosing type of this type, if it exists, or {@code null}. + */ + ResolvedJavaType getEnclosingType(); + + /** + * Returns an array reflecting all the constructors declared by this type. This method is + * similar to {@link Class#getDeclaredConstructors()} in terms of returned constructors. + */ + ResolvedJavaMethod[] getDeclaredConstructors(); + + /** + * Returns an array reflecting all the methods declared by this type. This method is similar to + * {@link Class#getDeclaredMethods()} in terms of returned methods. + */ + ResolvedJavaMethod[] getDeclaredMethods(); + + /** + * Returns the {@code } method for this class if there is one. + */ + ResolvedJavaMethod getClassInitializer(); + + /** + * Returns true if this type represents an interface and it should be trusted even in places + * where the JVM verifier would not give any guarantees other than {@link Object}. + */ + boolean isTrustedInterfaceType(); +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/SerializableConstant.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/SerializableConstant.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,42 @@ +/* + * 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 + * 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.nio.*; + +/** + * Represents a compile-time constant that can be converted to a byte array. + */ +public interface SerializableConstant extends Constant { + + /** + * Return the size in bytes of the serialized representation of this constant. + */ + int getSerializedSize(); + + /** + * Serialize the constant into the ByteBuffer. There must be at least + * {@link #getSerializedSize()} bytes available capacity in the buffer. + */ + void serialize(ByteBuffer buffer); +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/Signature.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/Signature.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,139 @@ +/* + * Copyright (c) 2009, 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.meta; + +/** + * Represents a method signature provided by the runtime. + * + * @see Method + * Descriptors + */ +public interface Signature { + + /** + * Returns the number of parameters in this signature, adding 1 for a receiver if requested. + * + * @param receiver true if 1 is to be added to the result for a receiver + * @return the number of parameters; + 1 iff {@code receiver == true} + */ + int getParameterCount(boolean receiver); + + /** + * Gets the parameter type at the specified position. + * + * @param index the index into the parameters, with {@code 0} indicating the first parameter + * @param accessingClass the context of the type lookup. If non-null, its class loader is used + * for resolving the type. If {@code null}, then the type returned is either + * unresolved or a resolved type whose resolution is context free (e.g., a primitive + * type or a type in a java.* package). + * @return the {@code index}'th parameter type + * @throws LinkageError if {@code accessingClass != null} and resolution fails + * + */ + JavaType getParameterType(int index, ResolvedJavaType accessingClass); + + /** + * Gets the parameter kind at the specified position. This is the same as calling + * {@link #getParameterType}. {@link JavaType#getKind getKind}. + * + * @param index the index into the parameters, with {@code 0} indicating the first parameter + * @return the kind of the parameter at the specified position + */ + default Kind getParameterKind(int index) { + return getParameterType(index, null).getKind(); + } + + /** + * Gets the return type of this signature. + * + * @param accessingClass the context of the type lookup. If non-null, its class loader is used + * for resolving the type. If {@code null}, then the type returned is either + * unresolved or a resolved type whose resolution is context free (e.g., a primitive + * type or a type in a java.* package). + * @return the return type + * @throws LinkageError if {@code accessingClass != null} and resolution fails + */ + JavaType getReturnType(ResolvedJavaType accessingClass); + + /** + * Gets the return kind of this signature. This is the same as calling {@link #getReturnType}. + * {@link JavaType#getKind getKind}. + */ + default Kind getReturnKind() { + return getReturnType(null).getKind(); + } + + /** + * Gets the method + * descriptor corresponding to this signature. For example: + * + *

      +     * (ILjava/lang/String;D)V
      +     * 
      + * + * @return the signature as a string + */ + default String toMethodDescriptor() { + StringBuilder sb = new StringBuilder("("); + for (int i = 0; i < getParameterCount(false); ++i) { + sb.append(getParameterType(i, null).getName()); + } + sb.append(')').append(getReturnType(null).getName()); + return sb.toString(); + } + + default JavaType[] toParameterTypes(JavaType receiverType) { + int args = getParameterCount(false); + JavaType[] result; + int i = 0; + if (receiverType != null) { + result = new JavaType[args + 1]; + result[0] = receiverType; + i = 1; + } else { + result = new JavaType[args]; + } + for (int j = 0; j < args; j++) { + result[i + j] = getParameterType(j, null); + } + return result; + } + + default Kind[] toParameterKinds(boolean receiver) { + int args = getParameterCount(false); + Kind[] result; + int i = 0; + if (receiver) { + result = new Kind[args + 1]; + result[0] = Kind.Object; + i = 1; + } else { + result = new Kind[args]; + } + for (int j = 0; j < args; j++) { + result[i + j] = getParameterKind(j); + } + return result; + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/SpeculationLog.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/SpeculationLog.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,68 @@ +/* + * 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.meta; + +import java.util.*; +import java.util.concurrent.*; + +/** + * Manages a list of unique deoptimization reasons. + * + */ +public abstract class SpeculationLog { + private volatile Object lastFailed; + private volatile Collection speculations; + private Set failedSpeculations; + + public synchronized void collectFailedSpeculations() { + if (lastFailed != null) { + if (failedSpeculations == null) { + failedSpeculations = new HashSet<>(2); + } + failedSpeculations.add(lastFailed); + lastFailed = null; + speculations = null; + } + } + + public boolean maySpeculate(Object reason) { + if (failedSpeculations != null && failedSpeculations.contains(reason)) { + return false; + } + return true; + } + + protected void addSpeculation(Object reason) { + assert maySpeculate(reason); + if (speculations == null) { + synchronized (this) { + if (speculations == null) { + speculations = new ConcurrentLinkedQueue<>(); + } + } + } + speculations.add(reason); + } + + public abstract JavaConstant speculate(Object reason); +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/TriState.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/TriState.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,77 @@ +/* + * 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.meta; + +/** + * Represents a logic value that can be either {@link #TRUE}, {@link #FALSE}, or {@link #UNKNOWN}. + */ +public enum TriState { + TRUE, + FALSE, + UNKNOWN; + + public static TriState get(boolean value) { + return value ? TRUE : FALSE; + } + + /** + * This is optimistic about {@link #UNKNOWN} (it prefers known values over {@link #UNKNOWN}) and + * pesimistic about known (it perfers {@link #TRUE} over {@link #FALSE}). + */ + public static TriState merge(TriState a, TriState b) { + if (a == TRUE || b == TRUE) { + return TRUE; + } + if (a == FALSE || b == FALSE) { + return FALSE; + } + assert a == UNKNOWN && b == UNKNOWN; + return UNKNOWN; + } + + public boolean isTrue() { + return this == TRUE; + } + + public boolean isFalse() { + return this == FALSE; + } + + public boolean isUnknown() { + return this == UNKNOWN; + } + + public boolean isKnown() { + return this != UNKNOWN; + } + + public boolean toBoolean() { + if (isTrue()) { + return true; + } else if (isFalse()) { + return false; + } else { + throw new IllegalStateException("Cannot convert to boolean, TriState is in an unknown state"); + } + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/TrustedInterface.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/TrustedInterface.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,32 @@ +/* + * 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; + +/** + * Interfaces extanding this interface should be trusted by the compiler. See + * {@link ResolvedJavaType#isTrustedInterfaceType()}. + * + */ +public interface TrustedInterface { + +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/VMConstant.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/VMConstant.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,26 @@ +/* + * 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; + +public interface VMConstant extends Constant { +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/Value.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/Value.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2009, 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; + +/** + * Interface for values manipulated by the compiler. All values have a {@linkplain Kind kind} and + * are immutable. + */ +public interface Value extends KindProvider, TrustedInterface { + + Value[] NO_VALUES = new Value[0]; + + AllocatableValue ILLEGAL = new IllegalValue(); + + public final class IllegalValue extends AllocatableValue { + private IllegalValue() { + super(LIRKind.Illegal); + } + + @Override + public String toString() { + return "-"; + } + + @Override + public boolean equals(Object other) { + // Due to de-serialization this object may exist multiple times. So we compare classes + // instead of the individual objects. (This anonymous class has always the same meaning) + return other instanceof IllegalValue; + } + } + + LIRKind getLIRKind(); + + /** + * Returns the platform specific kind used to store this value. + */ + PlatformKind getPlatformKind(); + + /** + * Checks if this value is identical to {@code other}. + * + * Warning: Use with caution! Usually equivalence {@link #equals(Object)} is sufficient and + * should be used. + */ + default boolean identityEquals(Value other) { + return this == other; + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/package-info.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/package-info.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,29 @@ +/* + * 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 that defines the interface between a runtime and a Java application that wants to access meta information. The runtime + * provides an implementation of the {@link com.oracle.jvmci.meta.MetaAccessProvider} interface. + */ +package com.oracle.jvmci.meta; + diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.options.processor/src/META-INF/services/javax.annotation.processing.Processor --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.options.processor/src/META-INF/services/javax.annotation.processing.Processor Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,1 @@ +com.oracle.jvmci.options.processor.OptionProcessor diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.options.processor/src/com/oracle/jvmci/options/processor/JVMCIJars.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.options.processor/src/com/oracle/jvmci/options/processor/JVMCIJars.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,63 @@ +/* + * 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.jvmci.options.processor; + +import java.io.*; +import java.util.*; +import java.util.stream.*; +import java.util.zip.*; + +public class JVMCIJars implements Iterable { + private final List jars = new ArrayList<>(2); + + public JVMCIJars() { + String classPath = System.getProperty("java.class.path"); + for (String e : classPath.split(File.pathSeparator)) { + if (e.endsWith(File.separatorChar + "graal.jar") || e.endsWith(File.separatorChar + "graal-truffle.jar")) { + try { + jars.add(new ZipFile(e)); + } catch (IOException ioe) { + throw new InternalError(ioe); + } + } + } + if (jars.size() != 2) { + throw new InternalError("Could not find graal.jar or graal-truffle.jar on class path: " + classPath); + } + } + + public Iterator iterator() { + Stream entries = jars.stream().flatMap(ZipFile::stream); + return entries.iterator(); + } + + public InputStream getInputStream(String classFilePath) throws IOException { + for (ZipFile jar : jars) { + ZipEntry entry = jar.getEntry(classFilePath); + if (entry != null) { + return jar.getInputStream(entry); + } + } + return null; + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.options.processor/src/com/oracle/jvmci/options/processor/OptionProcessor.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.options.processor/src/com/oracle/jvmci/options/processor/OptionProcessor.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,378 @@ +/* + * 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.options.processor; + +import java.io.*; +import java.util.*; + +import javax.annotation.processing.*; +import javax.lang.model.*; +import javax.lang.model.element.*; +import javax.lang.model.type.*; +import javax.lang.model.util.*; +import javax.tools.Diagnostic.Kind; +import javax.tools.*; + +import com.oracle.jvmci.options.*; + +/** + * Processes static fields annotated with {@link Option}. An {@link Options} service is generated + * for each top level class containing at least one such field. These service objects can be + * retrieved as follows: + * + *
      + * ServiceLoader<Options> sl = ServiceLoader.load(Options.class);
      + * for (Options opts : sl) {
      + *     for (OptionDescriptor desc : sl) {
      + *         // use desc
      + *     }
      + * }
      + * 
      + */ +@SupportedAnnotationTypes({"com.oracle.jvmci.options.Option"}) +public class OptionProcessor extends AbstractProcessor { + + @Override + public SourceVersion getSupportedSourceVersion() { + return SourceVersion.latest(); + } + + private final Set processed = new HashSet<>(); + + private void processElement(Element element, OptionsInfo info) { + + if (!element.getModifiers().contains(Modifier.STATIC)) { + processingEnv.getMessager().printMessage(Kind.ERROR, "Option field must be static", element); + return; + } + + Option annotation = element.getAnnotation(Option.class); + assert annotation != null; + assert element instanceof VariableElement; + assert element.getKind() == ElementKind.FIELD; + VariableElement field = (VariableElement) element; + String fieldName = field.getSimpleName().toString(); + + Elements elements = processingEnv.getElementUtils(); + Types types = processingEnv.getTypeUtils(); + + TypeMirror fieldType = field.asType(); + if (fieldType.getKind() != TypeKind.DECLARED) { + processingEnv.getMessager().printMessage(Kind.ERROR, "Option field must be of type " + OptionValue.class.getName(), element); + return; + } + DeclaredType declaredFieldType = (DeclaredType) fieldType; + + TypeMirror optionValueType = elements.getTypeElement(OptionValue.class.getName()).asType(); + if (!types.isSubtype(fieldType, types.erasure(optionValueType))) { + String msg = String.format("Option field type %s is not a subclass of %s", fieldType, optionValueType); + processingEnv.getMessager().printMessage(Kind.ERROR, msg, element); + return; + } + + if (!field.getModifiers().contains(Modifier.STATIC)) { + processingEnv.getMessager().printMessage(Kind.ERROR, "Option field must be static", element); + return; + } + + String help = annotation.help(); + if (help.length() != 0) { + char firstChar = help.charAt(0); + if (!Character.isUpperCase(firstChar)) { + processingEnv.getMessager().printMessage(Kind.ERROR, "Option help text must start with upper case letter", element); + return; + } + } + + String optionName = annotation.name(); + if (optionName.equals("")) { + optionName = fieldName; + } + + DeclaredType declaredOptionValueType = declaredFieldType; + while (!types.isSameType(types.erasure(declaredOptionValueType), types.erasure(optionValueType))) { + List directSupertypes = types.directSupertypes(declaredFieldType); + assert !directSupertypes.isEmpty(); + declaredOptionValueType = (DeclaredType) directSupertypes.get(0); + } + + assert !declaredOptionValueType.getTypeArguments().isEmpty(); + String optionType = declaredOptionValueType.getTypeArguments().get(0).toString(); + if (optionType.startsWith("java.lang.")) { + optionType = optionType.substring("java.lang.".length()); + } + + Element enclosing = element.getEnclosingElement(); + String declaringClass = ""; + String separator = ""; + Set originatingElementsList = info.originatingElements; + originatingElementsList.add(field); + while (enclosing != null) { + if (enclosing.getKind() == ElementKind.CLASS || enclosing.getKind() == ElementKind.INTERFACE) { + if (enclosing.getModifiers().contains(Modifier.PRIVATE)) { + String msg = String.format("Option field cannot be declared in a private %s %s", enclosing.getKind().name().toLowerCase(), enclosing); + processingEnv.getMessager().printMessage(Kind.ERROR, msg, element); + return; + } + originatingElementsList.add(enclosing); + declaringClass = enclosing.getSimpleName() + separator + declaringClass; + separator = "."; + } else { + assert enclosing.getKind() == ElementKind.PACKAGE; + } + enclosing = enclosing.getEnclosingElement(); + } + + info.options.add(new OptionInfo(optionName, help, optionType, declaringClass, field)); + } + + private void createFiles(OptionsInfo info) { + String pkg = ((PackageElement) info.topDeclaringType.getEnclosingElement()).getQualifiedName().toString(); + Name topDeclaringClass = info.topDeclaringType.getSimpleName(); + + String optionsClassName = topDeclaringClass + "_" + Options.class.getSimpleName(); + Element[] originatingElements = info.originatingElements.toArray(new Element[info.originatingElements.size()]); + + Filer filer = processingEnv.getFiler(); + try (PrintWriter out = createSourceFile(pkg, optionsClassName, filer, originatingElements)) { + + out.println("// CheckStyle: stop header check"); + out.println("// GENERATED CONTENT - DO NOT EDIT"); + out.println("// Source: " + topDeclaringClass + ".java"); + out.println("package " + pkg + ";"); + out.println(""); + out.println("import java.util.*;"); + out.println("import " + Options.class.getPackage().getName() + ".*;"); + out.println(""); + out.println("public class " + optionsClassName + " implements " + Options.class.getSimpleName() + " {"); + out.println(" @Override"); + String desc = OptionDescriptor.class.getSimpleName(); + out.println(" public Iterator<" + desc + "> iterator() {"); + out.println(" // CheckStyle: stop line length check"); + out.println(" List<" + desc + "> options = Arrays.asList("); + + boolean needPrivateFieldAccessor = false; + int i = 0; + Collections.sort(info.options); + for (OptionInfo option : info.options) { + String optionValue; + if (option.field.getModifiers().contains(Modifier.PRIVATE)) { + needPrivateFieldAccessor = true; + optionValue = "field(" + option.declaringClass + ".class, \"" + option.field.getSimpleName() + "\")"; + } else { + optionValue = option.declaringClass + "." + option.field.getSimpleName(); + } + String name = option.name; + String type = option.type; + String help = option.help; + String declaringClass = option.declaringClass; + Name fieldName = option.field.getSimpleName(); + String comma = i == info.options.size() - 1 ? "" : ","; + out.printf(" new %s(\"%s\", %s.class, \"%s\", %s.class, \"%s\", %s)%s\n", desc, name, type, help, declaringClass, fieldName, optionValue, comma); + i++; + } + out.println(" );"); + out.println(" // CheckStyle: resume line length check"); + out.println(" return options.iterator();"); + out.println(" }"); + if (needPrivateFieldAccessor) { + out.println(" private static " + OptionValue.class.getSimpleName() + " field(Class declaringClass, String fieldName) {"); + out.println(" try {"); + out.println(" java.lang.reflect.Field field = declaringClass.getDeclaredField(fieldName);"); + out.println(" field.setAccessible(true);"); + out.println(" return (" + OptionValue.class.getSimpleName() + ") field.get(null);"); + out.println(" } catch (Exception e) {"); + out.println(" throw (InternalError) new InternalError().initCause(e);"); + out.println(" }"); + out.println(" }"); + } + out.println("}"); + } + + try { + createProviderFile(pkg, optionsClassName, originatingElements); + createOptionsFile(info, pkg, topDeclaringClass.toString(), originatingElements); + } catch (IOException e) { + processingEnv.getMessager().printMessage(Kind.ERROR, e.getMessage(), info.topDeclaringType); + } + } + + private void createProviderFile(String pkg, String providerClassName, Element... originatingElements) throws IOException { + String filename = "META-INF/providers/" + pkg + "." + providerClassName; + FileObject file = processingEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT, "", filename, originatingElements); + PrintWriter writer = new PrintWriter(new OutputStreamWriter(file.openOutputStream(), "UTF-8")); + writer.println(Options.class.getName()); + writer.close(); + } + + private void createOptionsFile(OptionsInfo info, String pkg, String relativeName, Element... originatingElements) throws IOException { + String filename = "META-INF/options/" + pkg + "." + relativeName; + FileObject file = processingEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT, "", filename, originatingElements); + PrintWriter writer = new PrintWriter(new OutputStreamWriter(file.openOutputStream(), "UTF-8")); + Types types = processingEnv.getTypeUtils(); + for (OptionInfo option : info.options) { + String help = option.help; + if (help.indexOf('\t') >= 0 || help.indexOf('\r') >= 0 || help.indexOf('\n') >= 0) { + processingEnv.getMessager().printMessage(Kind.WARNING, "Option help should not contain '\\t', '\\r' or '\\n'", option.field); + help = help.replace('\t', ' ').replace('\n', ' ').replace('\r', ' '); + } + try { + char optionTypeToChar = optionTypeToChar(option); + String fqDeclaringClass = className(types.erasure(option.field.getEnclosingElement().asType())); + String fqFieldType = className(types.erasure(option.field.asType())); + writer.printf("%s\t%s\t%s\t%s\t%s%n", option.name, optionTypeToChar, help, fqDeclaringClass, fqFieldType); + } catch (IllegalArgumentException iae) { + } + } + writer.close(); + } + + private String className(TypeMirror t) { + DeclaredType dt = (DeclaredType) t; + return processingEnv.getElementUtils().getBinaryName((TypeElement) dt.asElement()).toString(); + } + + private char optionTypeToChar(OptionInfo option) { + switch (option.type) { + case "Boolean": + return 'z'; + case "Integer": + return 'i'; + case "Long": + return 'j'; + case "Float": + return 'f'; + case "Double": + return 'd'; + case "String": + return 's'; + default: + processingEnv.getMessager().printMessage(Kind.ERROR, "Unsoported option type: " + option.type, option.field); + throw new IllegalArgumentException(); + } + } + + protected PrintWriter createSourceFile(String pkg, String relativeName, Filer filer, Element... originatingElements) { + try { + // Ensure Unix line endings to comply with code style guide checked by Checkstyle + JavaFileObject sourceFile = filer.createSourceFile(pkg + "." + relativeName, originatingElements); + return new PrintWriter(sourceFile.openWriter()) { + + @Override + public void println() { + print("\n"); + } + }; + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + static class OptionInfo implements Comparable { + + final String name; + final String help; + final String type; + final String declaringClass; + final VariableElement field; + + public OptionInfo(String name, String help, String type, String declaringClass, VariableElement field) { + this.name = name; + this.help = help; + this.type = type; + this.declaringClass = declaringClass; + this.field = field; + } + + @Override + public int compareTo(OptionInfo other) { + return name.compareTo(other.name); + } + + @Override + public String toString() { + return declaringClass + "." + field; + } + } + + static class OptionsInfo { + + final Element topDeclaringType; + final List options = new ArrayList<>(); + final Set originatingElements = new HashSet<>(); + + public OptionsInfo(Element topDeclaringType) { + this.topDeclaringType = topDeclaringType; + } + } + + private static Element topDeclaringType(Element element) { + Element enclosing = element.getEnclosingElement(); + if (enclosing == null || enclosing.getKind() == ElementKind.PACKAGE) { + assert element.getKind() == ElementKind.CLASS || element.getKind() == ElementKind.INTERFACE; + return element; + } + return topDeclaringType(enclosing); + } + + @Override + public boolean process(Set annotations, RoundEnvironment roundEnv) { + if (roundEnv.processingOver()) { + return true; + } + + Map map = new HashMap<>(); + for (Element element : roundEnv.getElementsAnnotatedWith(Option.class)) { + if (!processed.contains(element)) { + processed.add(element); + Element topDeclaringType = topDeclaringType(element); + OptionsInfo options = map.get(topDeclaringType); + if (options == null) { + options = new OptionsInfo(topDeclaringType); + map.put(topDeclaringType, options); + } + processElement(element, options); + } + } + + boolean ok = true; + Map uniqueness = new HashMap<>(); + for (OptionsInfo info : map.values()) { + for (OptionInfo option : info.options) { + OptionInfo conflict = uniqueness.put(option.name, option); + if (conflict != null) { + processingEnv.getMessager().printMessage(Kind.ERROR, "Duplicate option names for " + option + " and " + conflict, option.field); + ok = false; + } + } + } + + if (ok) { + for (OptionsInfo info : map.values()) { + createFiles(info); + } + } + + return true; + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.options.test/src/com/oracle/jvmci/options/test/NestedBooleanOptionValueTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.options.test/src/com/oracle/jvmci/options/test/NestedBooleanOptionValueTest.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,128 @@ +/* + * 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.options.test; + +import static com.oracle.jvmci.options.test.NestedBooleanOptionValueTest.Options.*; +import static org.junit.Assert.*; + +import org.junit.*; + +import com.oracle.jvmci.options.*; +import com.oracle.jvmci.options.OptionValue.OverrideScope; + +public class NestedBooleanOptionValueTest { + + public static class Options { + public static final OptionValue Master0 = new OptionValue<>(true); + public static final OptionValue NestedOption0 = new NestedBooleanOptionValue(Master0, true); + public static final OptionValue Master1 = new OptionValue<>(true); + public static final OptionValue NestedOption1 = new NestedBooleanOptionValue(Master1, true); + public static final OptionValue Master2 = new OptionValue<>(true); + public static final OptionValue NestedOption2 = new NestedBooleanOptionValue(Master2, false); + } + + static final OptionDescriptor master0 = new OptionDescriptor("Master0", Boolean.class, "", Options.class, "Master0", Master0); + static final OptionDescriptor nestedOption0 = new OptionDescriptor("NestedOption0", Boolean.class, "", Options.class, "NestedOption0", NestedOption0); + static final OptionDescriptor master1 = new OptionDescriptor("Master1", Boolean.class, "", Options.class, "Master1", Master1); + static final OptionDescriptor nestedOption1 = new OptionDescriptor("NestedOption1", Boolean.class, "", Options.class, "NestedOption1", NestedOption1); + static final OptionDescriptor master2 = new OptionDescriptor("Master2", Boolean.class, "", Options.class, "Master2", Master2); + static final OptionDescriptor nestedOption2 = new OptionDescriptor("NestedOption2", Boolean.class, "", Options.class, "NestedOption2", NestedOption2); + + @Test + public void runOverrides() { + assertTrue(Master0.getValue()); + assertTrue(NestedOption0.getValue()); + try (OverrideScope s1 = OptionValue.override(Master0, false)) { + assertFalse(Master0.getValue()); + assertFalse(NestedOption0.getValue()); + try (OverrideScope s2 = OptionValue.override(NestedOption0, false)) { + assertFalse(NestedOption0.getValue()); + } + try (OverrideScope s2 = OptionValue.override(NestedOption0, true)) { + assertTrue(NestedOption0.getValue()); + } + } + assertTrue(Master0.getValue()); + try (OverrideScope s1 = OptionValue.override(NestedOption0, false)) { + assertFalse(NestedOption0.getValue()); + } + try (OverrideScope s1 = OptionValue.override(NestedOption0, true)) { + assertTrue(NestedOption0.getValue()); + } + } + + @Test + public void runDefaultTrue() { + Master1.setValue(true); + assertTrue(Master1.getValue()); + assertTrue(NestedOption1.getValue()); + // nested value unset + Master1.setValue(false); + assertFalse(Master1.getValue()); + assertFalse(NestedOption1.getValue()); + // set false + Master1.setValue(false); + NestedOption1.setValue(false); + assertFalse(Master1.getValue()); + assertFalse(NestedOption1.getValue()); + Master1.setValue(true); + assertTrue(Master1.getValue()); + assertFalse(NestedOption1.getValue()); + // set true + Master1.setValue(false); + NestedOption1.setValue(true); + assertFalse(Master1.getValue()); + assertTrue(NestedOption1.getValue()); + Master1.setValue(true); + assertTrue(Master1.getValue()); + assertTrue(NestedOption1.getValue()); + } + + @Test + public void runDefaultFalse() { + Master2.setValue(true); + assertTrue(Master2.getValue()); + assertFalse(NestedOption2.getValue()); + // nested value unset + Master2.setValue(false); + assertFalse(Master2.getValue()); + assertFalse(NestedOption2.getValue()); + // set false + Master2.setValue(false); + NestedOption2.setValue(false); + assertFalse(Master2.getValue()); + assertFalse(NestedOption2.getValue()); + Master2.setValue(true); + assertTrue(Master2.getValue()); + assertFalse(NestedOption2.getValue()); + // set true + Master2.setValue(false); + NestedOption2.setValue(true); + assertFalse(Master2.getValue()); + assertTrue(NestedOption2.getValue()); + Master2.setValue(true); + assertTrue(Master2.getValue()); + assertTrue(NestedOption2.getValue()); + } + +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.options.test/src/com/oracle/jvmci/options/test/TestOptionValue.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.options.test/src/com/oracle/jvmci/options/test/TestOptionValue.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,127 @@ +/* + * 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.options.test; + +import static com.oracle.jvmci.options.test.TestOptionValue.Options.*; +import static org.junit.Assert.*; + +import java.util.*; + +import org.junit.*; + +import com.oracle.jvmci.options.*; +import com.oracle.jvmci.options.OptionValue.OverrideScope; + +public class TestOptionValue { + + public static class Options { + public static final OptionValue Stable = new StableOptionValue<>(true); + public static final OptionValue Mutable = new OptionValue<>("original"); + public static final OptionValue SecondMutable = new OptionValue<>("second"); + } + + static final OptionDescriptor stable = new OptionDescriptor("Stable", Boolean.class, "", Options.class, "Stable", Stable); + static final OptionDescriptor mutable = new OptionDescriptor("Mutable", String.class, "", Options.class, "Mutable", Mutable); + static final OptionDescriptor secondMutable = new OptionDescriptor("SecondMutable", String.class, "", Options.class, "SecondMutable", SecondMutable); + + @Test + public void testMutable() { + assertEquals("original", Mutable.getValue()); + try (OverrideScope s1 = OptionValue.override(Mutable, "override1")) { + assertEquals("override1", Mutable.getValue()); + try (OverrideScope s2 = OptionValue.override(Mutable, "override2")) { + assertEquals("override2", Mutable.getValue()); + } + assertEquals("override1", Mutable.getValue()); + try (OverrideScope s3 = OptionValue.override(Mutable, "override3")) { + assertEquals("override3", Mutable.getValue()); + } + assertEquals("override1", Mutable.getValue()); + } + assertEquals("original", Mutable.getValue()); + try (OverrideScope s1 = OptionValue.override(Mutable, "original")) { + assertEquals("original", Mutable.getValue()); + } + } + + @Test + public void testMultiple() { + assertEquals("original", Mutable.getValue()); + assertEquals("second", SecondMutable.getValue()); + try (OverrideScope s1 = OptionValue.override(Mutable, "override1", SecondMutable, "secondOverride1")) { + assertEquals("override1", Mutable.getValue()); + assertEquals("secondOverride1", SecondMutable.getValue()); + try (OverrideScope s2 = OptionValue.override(Mutable, "override2", SecondMutable, "secondOverride2")) { + assertEquals("override2", Mutable.getValue()); + assertEquals("secondOverride2", SecondMutable.getValue()); + } + assertEquals("override1", Mutable.getValue()); + assertEquals("secondOverride1", SecondMutable.getValue()); + try (OverrideScope s3 = OptionValue.override(Mutable, "override3", SecondMutable, "secondOverride3")) { + assertEquals("override3", Mutable.getValue()); + assertEquals("secondOverride3", SecondMutable.getValue()); + } + assertEquals("override1", Mutable.getValue()); + assertEquals("secondOverride1", SecondMutable.getValue()); + } + assertEquals("original", Mutable.getValue()); + assertEquals("second", SecondMutable.getValue()); + try (OverrideScope s1 = OptionValue.override(Mutable, "original", SecondMutable, "second")) { + assertEquals("original", Mutable.getValue()); + assertEquals("second", SecondMutable.getValue()); + } + } + + @Test + public void testStable() { + assertTrue(Stable.getValue()); + try (OverrideScope s = OptionValue.override(Stable, false)) { + fail("cannot override stable option"); + } catch (IllegalArgumentException e) { + // expected + } + } + + @Test + public void toStringTest() { + assertEquals("com.oracle.jvmci.options.test.TestOptionValue$Options.Mutable=original", Mutable.toString()); + try (OverrideScope s1 = OptionValue.override(Mutable, "override1")) { + assertEquals("com.oracle.jvmci.options.test.TestOptionValue$Options.Mutable=override1", Mutable.toString()); + try (OverrideScope s2 = OptionValue.override(Mutable, "override2")) { + assertEquals("com.oracle.jvmci.options.test.TestOptionValue$Options.Mutable=override2", Mutable.toString()); + } + } + } + + @Test + public void getValuesTest() { + assertEquals(Arrays.asList("original"), Mutable.getValues(null)); + assertEquals(Arrays.asList(true), Stable.getValues(null)); + try (OverrideScope s1 = OptionValue.override(Mutable, "override1")) { + assertEquals(Arrays.asList("override1", "original"), Mutable.getValues(null)); + try (OverrideScope s2 = OptionValue.override(Mutable, "override2")) { + assertEquals(Arrays.asList("override2", "override1", "original"), Mutable.getValues(null)); + } + } + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.options/src/com/oracle/jvmci/options/DerivedOptionValue.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.options/src/com/oracle/jvmci/options/DerivedOptionValue.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,59 @@ +/* + * 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.options; + +import java.io.*; +import java.util.function.*; + +import com.oracle.jvmci.options.OptionValue.OverrideScope; + +/** + * A cached value that needs to be recomputed when an option changes. + */ +public class DerivedOptionValue { + + public interface OptionSupplier extends Supplier, Serializable { + } + + private final T initialValue; + private final OptionSupplier supplier; + + public DerivedOptionValue(OptionSupplier supplier) { + this.supplier = supplier; + assert OptionValue.getOverrideScope() == null : "derived option value should be initialized outside any override scope"; + this.initialValue = createValue(); + } + + public T getValue() { + OverrideScope overrideScope = OptionValue.getOverrideScope(); + if (overrideScope != null) { + return overrideScope.getDerived(this); + } else { + return initialValue; + } + } + + T createValue() { + return supplier.get(); + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.options/src/com/oracle/jvmci/options/NestedBooleanOptionValue.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.options/src/com/oracle/jvmci/options/NestedBooleanOptionValue.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,58 @@ +/* + * 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.jvmci.options; + +/** + * A nested Boolean {@link OptionValue} that can be overridden by a {@link #masterOption master + * option}. + *

      + *

    • If the option is present on the command line the specified value is used. + *
    • Otherwise {@link #getValue()} depends on the {@link #masterOption} and evaluates as follows: + *
        + *
      • If {@link #masterOption} is set, this value equals to {@link #initialValue}. + *
      • Otherwise, if {@link #masterOption} is {@code false}, this option is {@code false}. + */ +public class NestedBooleanOptionValue extends OptionValue { + private final OptionValue masterOption; + private final Boolean initialValue; + + public NestedBooleanOptionValue(OptionValue masterOption, Boolean initialValue) { + super(null); + this.masterOption = masterOption; + this.initialValue = initialValue; + } + + public OptionValue getMasterOption() { + return masterOption; + } + + @Override + public Boolean getValue() { + Boolean v = super.getValue(); + if (v == null) { + return initialValue && masterOption.getValue(); + } + return v; + } + +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.options/src/com/oracle/jvmci/options/Option.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.options/src/com/oracle/jvmci/options/Option.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,52 @@ +/* + * 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.options; + +import java.lang.annotation.*; + +/** + * Describes the attributes of an option whose {@link OptionValue value} is in a static field + * annotated by this annotation type. + * + * @see OptionDescriptor + */ +@Retention(RetentionPolicy.CLASS) +@Target(ElementType.FIELD) +public @interface Option { + + /** + * Gets a help message for the option. New lines can be embedded in the message with + * {@code "%n"}. + */ + String help(); + + /** + * The name of the option. By default, the name of the annotated field should be used. + */ + String name() default ""; + + /** + * Specifies the type of the option. + */ + OptionType type() default OptionType.Debug; +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.options/src/com/oracle/jvmci/options/OptionDescriptor.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.options/src/com/oracle/jvmci/options/OptionDescriptor.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,93 @@ +/* + * 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.options; + +/** + * Describes the attributes of a static field {@linkplain Option option} and provides access to its + * {@linkplain OptionValue value}. + */ +public class OptionDescriptor { + + protected final String name; + protected final Class type; + protected final String help; + protected final OptionValue option; + protected final Class declaringClass; + protected final String fieldName; + + public OptionDescriptor(String name, Class type, String help, Class declaringClass, String fieldName, OptionValue option) { + this.name = name; + this.type = type; + this.help = help; + this.option = option; + this.declaringClass = declaringClass; + this.fieldName = fieldName; + assert !type.isPrimitive() : "must used boxed type instead of " + type; + option.setDescriptor(this); + } + + /** + * Gets the type of values stored in the option. This will be the boxed type for a primitive + * option. + */ + public Class getType() { + return type; + } + + /** + * Gets a descriptive help message for the option. + */ + public String getHelp() { + return help; + } + + /** + * Gets the name of the option. It's up to the client of this object how to use the name to get + * a user specified value for the option from the environment. + */ + public String getName() { + return name; + } + + /** + * Gets the boxed option value. + */ + public OptionValue getOptionValue() { + return option; + } + + public Class getDeclaringClass() { + return declaringClass; + } + + public String getFieldName() { + return fieldName; + } + + /** + * Gets a description of the location where this option is stored. + */ + public String getLocation() { + return getDeclaringClass().getName() + "." + getFieldName(); + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.options/src/com/oracle/jvmci/options/OptionType.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.options/src/com/oracle/jvmci/options/OptionType.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,44 @@ +/* + * 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.options; + +/** + * Classifies JVMCI options in several categories depending on who this option is relevant for. + * + */ +public enum OptionType { + /** + * An option common for users to apply. + */ + User, + + /** + * An option only relevant in corner cases and for fine-tuning. + */ + Expert, + + /** + * An option only relevant when debugging the compiler. + */ + Debug +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.options/src/com/oracle/jvmci/options/OptionUtils.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.options/src/com/oracle/jvmci/options/OptionUtils.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,182 @@ +/* + * 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.options; + +import java.util.*; + +public class OptionUtils { + + public interface OptionConsumer { + void set(OptionDescriptor desc, Object value); + } + + /** + * Parses a given option value specification. + * + * @param option the specification of an option and its value + * @param setter the object to notify of the parsed option and value. + */ + public static void parseOption(String option, OptionConsumer setter) { + SortedMap options = OptionsLoader.options; + Objects.requireNonNull(setter); + if (option.length() == 0) { + return; + } + + Object value = null; + String optionName = null; + String valueString = null; + + char first = option.charAt(0); + if (first == '+' || first == '-') { + optionName = option.substring(1); + value = (first == '+'); + } else { + int index = option.indexOf('='); + if (index == -1) { + optionName = option; + valueString = null; + } else { + optionName = option.substring(0, index); + valueString = option.substring(index + 1); + } + } + + OptionDescriptor desc = options.get(optionName); + if (desc == null) { + throw new IllegalArgumentException("Option '" + optionName + "' not found"); + } + + Class optionType = desc.getType(); + + if (value == null) { + if (optionType == Boolean.TYPE || optionType == Boolean.class) { + throw new IllegalArgumentException("Boolean option '" + optionName + "' must use +/- prefix"); + } + + if (valueString == null) { + throw new IllegalArgumentException("Missing value for non-boolean option '" + optionName + "' must use " + optionName + "= format"); + } + + if (optionType == Float.class) { + value = Float.parseFloat(valueString); + } else if (optionType == Double.class) { + value = Double.parseDouble(valueString); + } else if (optionType == Integer.class) { + value = Integer.valueOf((int) parseLong(valueString)); + } else if (optionType == Long.class) { + value = Long.valueOf(parseLong(valueString)); + } else if (optionType == String.class) { + value = valueString; + } else { + throw new IllegalArgumentException("Wrong value for option '" + optionName + "'"); + } + } else { + if (optionType != Boolean.class) { + throw new IllegalArgumentException("Non-boolean option '" + optionName + "' can not use +/- prefix. Use " + optionName + "= format"); + } + } + + setter.set(desc, value); + } + + private static long parseLong(String v) { + String valueString = v.toLowerCase(); + long scale = 1; + if (valueString.endsWith("k")) { + scale = 1024L; + } else if (valueString.endsWith("m")) { + scale = 1024L * 1024L; + } else if (valueString.endsWith("g")) { + scale = 1024L * 1024L * 1024L; + } else if (valueString.endsWith("t")) { + scale = 1024L * 1024L * 1024L * 1024L; + } + + if (scale != 1) { + /* Remove trailing scale character. */ + valueString = valueString.substring(0, valueString.length() - 1); + } + + return Long.parseLong(valueString) * scale; + } + + /** + * Wraps some given text to one or more lines of a given maximum width. + * + * @param text text to wrap + * @param width maximum width of an output line, exception for words in {@code text} longer than + * this value + * @return {@code text} broken into lines + */ + private static List wrap(String text, int width) { + List lines = Collections.singletonList(text); + if (text.length() > width) { + String[] chunks = text.split("\\s+"); + lines = new ArrayList<>(); + StringBuilder line = new StringBuilder(); + for (String chunk : chunks) { + if (line.length() + chunk.length() > width) { + lines.add(line.toString()); + line.setLength(0); + } + if (line.length() != 0) { + line.append(' '); + } + String[] embeddedLines = chunk.split("%n", -2); + if (embeddedLines.length == 1) { + line.append(chunk); + } else { + for (int i = 0; i < embeddedLines.length; i++) { + line.append(embeddedLines[i]); + if (i < embeddedLines.length - 1) { + lines.add(line.toString()); + line.setLength(0); + } + } + } + } + if (line.length() != 0) { + lines.add(line.toString()); + } + } + return lines; + } + + public static void printFlags(SortedMap options, String prefix) { + System.out.println("[List of " + prefix + " options]"); + SortedMap sortedOptions = options; + for (Map.Entry e : sortedOptions.entrySet()) { + e.getKey(); + OptionDescriptor desc = e.getValue(); + Object value = desc.getOptionValue().getValue(); + List helpLines = wrap(desc.getHelp(), 70); + System.out.println(String.format("%9s %-40s = %-14s %s", desc.getType().getSimpleName(), e.getKey(), value, helpLines.get(0))); + for (int i = 1; i < helpLines.size(); i++) { + System.out.println(String.format("%67s %s", " ", helpLines.get(i))); + } + } + + System.exit(0); + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.options/src/com/oracle/jvmci/options/OptionValue.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.options/src/com/oracle/jvmci/options/OptionValue.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,475 @@ +/* + * 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.options; + +import java.io.*; +import java.util.*; +import java.util.Map.Entry; + +/** + * An option value. + */ +public class OptionValue { + /** + * Temporarily changes the value for an option. The {@linkplain OptionValue#getValue() value} of + * {@code option} is set to {@code value} until {@link OverrideScope#close()} is called on the + * object returned by this method. + *

        + * Since the returned object is {@link AutoCloseable} the try-with-resource construct can be + * used: + * + *

        +     * try (OverrideScope s = OptionValue.override(myOption, myValue) {
        +     *     // code that depends on myOption == myValue
        +     * }
        +     * 
        + */ + public static OverrideScope override(OptionValue option, Object value) { + OverrideScope current = getOverrideScope(); + if (current == null) { + if (!value.equals(option.getValue())) { + return new SingleOverrideScope(option, value); + } + Map, Object> overrides = Collections.emptyMap(); + return new MultipleOverridesScope(current, overrides); + } + return new MultipleOverridesScope(current, option, value); + } + + /** + * Temporarily changes the values for a set of options. The {@linkplain OptionValue#getValue() + * value} of each {@code option} in {@code overrides} is set to the corresponding {@code value} + * in {@code overrides} until {@link OverrideScope#close()} is called on the object returned by + * this method. + *

        + * Since the returned object is {@link AutoCloseable} the try-with-resource construct can be + * used: + * + *

        +     * Map<OptionValue, Object> overrides = new HashMap<>();
        +     * overrides.put(myOption1, myValue1);
        +     * overrides.put(myOption2, myValue2);
        +     * try (OverrideScope s = OptionValue.override(overrides) {
        +     *     // code that depends on myOption == myValue
        +     * }
        +     * 
        + */ + public static OverrideScope override(Map, Object> overrides) { + OverrideScope current = getOverrideScope(); + if (current == null && overrides.size() == 1) { + Entry, Object> single = overrides.entrySet().iterator().next(); + OptionValue option = single.getKey(); + Object overrideValue = single.getValue(); + if (!overrideValue.equals(option.getValue())) { + return new SingleOverrideScope(option, overrideValue); + } + } + return new MultipleOverridesScope(current, overrides); + } + + /** + * Temporarily changes the values for a set of options. The {@linkplain OptionValue#getValue() + * value} of each {@code option} in {@code overrides} is set to the corresponding {@code value} + * in {@code overrides} until {@link OverrideScope#close()} is called on the object returned by + * this method. + *

        + * Since the returned object is {@link AutoCloseable} the try-with-resource construct can be + * used: + * + *

        +     * try (OverrideScope s = OptionValue.override(myOption1, myValue1, myOption2, myValue2) {
        +     *     // code that depends on myOption == myValue
        +     * }
        +     * 
        + * + * @param overrides overrides in the form {@code [option1, override1, option2, override2, ...]} + */ + public static OverrideScope override(Object... overrides) { + OverrideScope current = getOverrideScope(); + if (current == null && overrides.length == 2) { + OptionValue option = (OptionValue) overrides[0]; + Object overrideValue = overrides[1]; + if (!overrideValue.equals(option.getValue())) { + return new SingleOverrideScope(option, overrideValue); + } + } + Map, Object> map = Collections.emptyMap(); + for (int i = 0; i < overrides.length; i += 2) { + OptionValue option = (OptionValue) overrides[i]; + Object overrideValue = overrides[i + 1]; + if (!overrideValue.equals(option.getValue())) { + if (map.isEmpty()) { + map = new HashMap<>(); + } + map.put(option, overrideValue); + } + } + return new MultipleOverridesScope(current, map); + } + + private static final ThreadLocal overrideScopeTL = new ThreadLocal<>(); + + protected static OverrideScope getOverrideScope() { + return overrideScopeTL.get(); + } + + protected static void setOverrideScope(OverrideScope overrideScope) { + overrideScopeTL.set(overrideScope); + } + + private T defaultValue; + + /** + * The raw option value. + */ + protected T value; + + private OptionDescriptor descriptor; + + private long reads; + private OptionValue next; + private static OptionValue head; + + private static final boolean ShowReadsHistogram = Boolean.getBoolean("jvmci.showOptionValueReadsHistogram"); + + private static void addToHistogram(OptionValue option) { + if (ShowReadsHistogram) { + synchronized (OptionValue.class) { + option.next = head; + head = option; + } + } + } + + @SuppressWarnings("unchecked") + public OptionValue(T value) { + this.defaultValue = value; + this.value = (T) DEFAULT; + addToHistogram(this); + } + + private static final Object DEFAULT = "DEFAULT"; + private static final Object UNINITIALIZED = "UNINITIALIZED"; + + /** + * Creates an uninitialized option value for a subclass that initializes itself + * {@link #defaultValue() lazily}. + */ + @SuppressWarnings("unchecked") + protected OptionValue() { + this.defaultValue = (T) UNINITIALIZED; + this.value = (T) DEFAULT; + addToHistogram(this); + } + + /** + * Lazy initialization of default value. + */ + protected T defaultValue() { + throw new InternalError("Option without a default value value must override defaultValue()"); + } + + /** + * Sets the descriptor for this option. + */ + public void setDescriptor(OptionDescriptor descriptor) { + this.descriptor = descriptor; + } + + /** + * Returns the descriptor for this option, if it has been set by + * {@link #setDescriptor(OptionDescriptor)}. + */ + public OptionDescriptor getDescriptor() { + return descriptor; + } + + /** + * Gets the name of this option. The name for an option value with a null + * {@linkplain #setDescriptor(OptionDescriptor) descriptor} is the value of + * {@link Object#toString()}. + */ + public String getName() { + return descriptor == null ? super.toString() : (descriptor.getDeclaringClass().getName() + "." + descriptor.getName()); + } + + @Override + public String toString() { + return getName() + "=" + getValue(); + } + + /** + * The initial value specified in source code. The returned value is not affected by calls to + * {@link #setValue(Object)} or registering {@link OverrideScope}s. Therefore, it is also not + * affected by options set on the command line. + */ + public T getDefaultValue() { + if (defaultValue == UNINITIALIZED) { + defaultValue = defaultValue(); + } + return defaultValue; + } + + /** + * Returns true if the option has the same value that was set in the source code. + */ + public boolean hasDefaultValue() { + getValue(); // ensure initialized + return value == DEFAULT || Objects.equals(value, getDefaultValue()); + } + + /** + * Gets the value of this option. + */ + public T getValue() { + if (ShowReadsHistogram) { + reads++; + } + if (!(this instanceof StableOptionValue)) { + OverrideScope overrideScope = getOverrideScope(); + if (overrideScope != null) { + T override = overrideScope.getOverride(this); + if (override != null) { + return override; + } + } + } + if (value != DEFAULT) { + return value; + } else { + return getDefaultValue(); + } + } + + /** + * Gets the values of this option including overridden values. + * + * @param c the collection to which the values are added. If null, one is allocated. + * @return the collection to which the values were added in order from most overridden to + * current value + */ + @SuppressWarnings("unchecked") + public Collection getValues(Collection c) { + Collection values = c == null ? new ArrayList<>() : c; + if (!(this instanceof StableOptionValue)) { + OverrideScope overrideScope = getOverrideScope(); + if (overrideScope != null) { + overrideScope.getOverrides(this, (Collection) values); + } + } + if (value != DEFAULT) { + values.add(value); + } else { + values.add(getDefaultValue()); + } + return values; + } + + /** + * Sets the value of this option. + */ + @SuppressWarnings("unchecked") + public void setValue(Object v) { + this.value = (T) v; + } + + /** + * An object whose {@link #close()} method reverts the option value overriding initiated by + * {@link OptionValue#override(OptionValue, Object)} or {@link OptionValue#override(Map)}. + */ + public abstract static class OverrideScope implements AutoCloseable { + + private Map, Object> derivedCache = null; + + public T getDerived(DerivedOptionValue key) { + if (derivedCache == null) { + derivedCache = new HashMap<>(); + } + @SuppressWarnings("unchecked") + T ret = (T) derivedCache.get(key); + if (ret == null) { + ret = key.createValue(); + derivedCache.put(key, ret); + } + return ret; + } + + abstract void addToInherited(Map, Object> inherited); + + abstract T getOverride(OptionValue option); + + abstract void getOverrides(OptionValue option, Collection c); + + public abstract void close(); + } + + static class SingleOverrideScope extends OverrideScope { + + private final OptionValue option; + private final Object value; + + public SingleOverrideScope(OptionValue option, Object value) { + if (option instanceof StableOptionValue) { + throw new IllegalArgumentException("Cannot override stable option " + option); + } + this.option = option; + this.value = value; + setOverrideScope(this); + } + + @Override + void addToInherited(Map, Object> inherited) { + inherited.put(option, value); + } + + @SuppressWarnings("unchecked") + @Override + T getOverride(OptionValue key) { + if (key == this.option) { + return (T) value; + } + return null; + } + + @Override + void getOverrides(OptionValue key, Collection c) { + if (key == this.option) { + c.add(value); + } + } + + @Override + public void close() { + setOverrideScope(null); + } + } + + static class MultipleOverridesScope extends OverrideScope { + final OverrideScope parent; + final Map, Object> overrides; + + public MultipleOverridesScope(OverrideScope parent, OptionValue option, Object value) { + this.parent = parent; + this.overrides = new HashMap<>(); + if (parent != null) { + parent.addToInherited(overrides); + } + if (option instanceof StableOptionValue) { + throw new IllegalArgumentException("Cannot override stable option " + option); + } + if (!value.equals(option.getValue())) { + this.overrides.put(option, value); + } + if (!overrides.isEmpty()) { + setOverrideScope(this); + } + } + + MultipleOverridesScope(OverrideScope parent, Map, Object> overrides) { + this.parent = parent; + if (overrides.isEmpty() && parent == null) { + this.overrides = Collections.emptyMap(); + return; + } + this.overrides = new HashMap<>(); + if (parent != null) { + parent.addToInherited(this.overrides); + } + for (Map.Entry, Object> e : overrides.entrySet()) { + OptionValue option = e.getKey(); + if (option instanceof StableOptionValue) { + throw new IllegalArgumentException("Cannot override stable option " + option); + } + if (!e.getValue().equals(option.getValue())) { + this.overrides.put(option, e.getValue()); + } + } + if (!this.overrides.isEmpty()) { + setOverrideScope(this); + } + } + + @Override + void addToInherited(Map, Object> inherited) { + if (parent != null) { + parent.addToInherited(inherited); + } + inherited.putAll(overrides); + } + + @SuppressWarnings("unchecked") + @Override + T getOverride(OptionValue option) { + return (T) overrides.get(option); + } + + @Override + void getOverrides(OptionValue option, Collection c) { + Object v = overrides.get(option); + if (v != null) { + c.add(v); + } + if (parent != null) { + parent.getOverrides(option, c); + } + } + + @Override + public void close() { + if (!overrides.isEmpty()) { + setOverrideScope(parent); + } + } + } + + static { + if (ShowReadsHistogram) { + Runtime.getRuntime().addShutdownHook(new Thread() { + @Override + public void run() { + ArrayList> options = new ArrayList<>(); + for (OptionValue option = head; option != null; option = option.next) { + options.add(option); + } + Collections.sort(options, new Comparator>() { + + public int compare(OptionValue o1, OptionValue o2) { + if (o1.reads < o2.reads) { + return -1; + } else if (o1.reads > o2.reads) { + return 1; + } else { + return o1.getName().compareTo(o2.getName()); + } + } + }); + PrintStream out = System.out; + out.println("=== OptionValue reads histogram ==="); + for (OptionValue option : options) { + out.println(option.reads + "\t" + option); + } + } + }); + } + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.options/src/com/oracle/jvmci/options/Options.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.options/src/com/oracle/jvmci/options/Options.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,31 @@ +/* + * 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.options; + +import java.util.*; + +/** + * A {@linkplain ServiceLoader service} for accessing a set of {@link OptionDescriptor}s. + */ +public interface Options extends Iterable { +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.options/src/com/oracle/jvmci/options/OptionsLoader.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.options/src/com/oracle/jvmci/options/OptionsLoader.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,45 @@ +/* + * 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.options; + +import java.util.*; + +/** + * Helper class used to load option descriptors. Only to be used in the slow-path. + */ +public class OptionsLoader { + public static final SortedMap options = new TreeMap<>(); + + /** + * Initializes {@link #options} from {@link Options} services. + */ + static { + for (Options opts : ServiceLoader.load(Options.class, OptionsLoader.class.getClassLoader())) { + for (OptionDescriptor desc : opts) { + String name = desc.getName(); + OptionDescriptor existing = options.put(name, desc); + assert existing == null : "Option named \"" + name + "\" has multiple definitions: " + existing.getLocation() + " and " + desc.getLocation(); + } + } + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.options/src/com/oracle/jvmci/options/StableOptionValue.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.options/src/com/oracle/jvmci/options/StableOptionValue.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,75 @@ +/* + * 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.options; + +/** + * An option that always returns the same {@linkplain #getValue() value}. + */ +public class StableOptionValue extends OptionValue { + + /** + * Creates a stable option value. + */ + public StableOptionValue(T value) { + super(value); + } + + /** + * Used to assert the invariant for stability. Without using locks, this check is not safe + * against races and so it's only an assertion. + */ + private boolean getValueCalled; + + /** + * Creates an uninitialized stable option value for a subclass that initializes itself + * {@link #defaultValue() lazily}. + */ + public StableOptionValue() { + } + + /** + * Gets the value of this option. + */ + @Override + public final T getValue() { + T result = super.getValue(); + assert initGetValueCalled(); + return result; + } + + private boolean initGetValueCalled() { + getValueCalled = true; + return true; + } + + /** + * {@inheritDoc} + *

        + * This must only be called if {@link #getValue()} has never been called. + */ + @Override + public final void setValue(Object v) { + assert !getValueCalled; + super.setValue(v); + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/ConstantTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/ConstantTest.java Tue Jun 09 00:22:49 2015 +0200 @@ -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 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/FieldUniverse.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/FieldUniverse.java Tue Jun 09 00:22:49 2015 +0200 @@ -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 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/MethodUniverse.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/MethodUniverse.java Tue Jun 09 00:22:49 2015 +0200 @@ -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 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/NameAndSignature.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/NameAndSignature.java Tue Jun 09 00:22:49 2015 +0200 @@ -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 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/ResolvedJavaTypeResolveConcreteMethodTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/ResolvedJavaTypeResolveConcreteMethodTest.java Tue Jun 09 00:22:49 2015 +0200 @@ -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 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/ResolvedJavaTypeResolveMethodTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/ResolvedJavaTypeResolveMethodTest.java Tue Jun 09 00:22:49 2015 +0200 @@ -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 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/TestConstantReflectionProvider.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/TestConstantReflectionProvider.java Tue Jun 09 00:22:49 2015 +0200 @@ -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 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/TestJavaField.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/TestJavaField.java Tue Jun 09 00:22:49 2015 +0200 @@ -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 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/TestJavaMethod.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/TestJavaMethod.java Tue Jun 09 00:22:49 2015 +0200 @@ -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 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/TestJavaType.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/TestJavaType.java Tue Jun 09 00:22:49 2015 +0200 @@ -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 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/TestMetaAccessProvider.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/TestMetaAccessProvider.java Tue Jun 09 00:22:49 2015 +0200 @@ -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 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/TestResolvedJavaField.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/TestResolvedJavaField.java Tue Jun 09 00:22:49 2015 +0200 @@ -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 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/TestResolvedJavaMethod.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/TestResolvedJavaMethod.java Tue Jun 09 00:22:49 2015 +0200 @@ -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 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/TestResolvedJavaType.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/TestResolvedJavaType.java Tue Jun 09 00:22:49 2015 +0200 @@ -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 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/TypeUniverse.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/TypeUniverse.java Tue Jun 09 00:22:49 2015 +0200 @@ -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 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.runtime/src/com/oracle/jvmci/runtime/JVMCI.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.runtime/src/com/oracle/jvmci/runtime/JVMCI.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,59 @@ +/* + * 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.jvmci.runtime; + +import java.util.*; + +public class JVMCI { + + private static final JVMCIRuntime runtime; + + private static native JVMCIRuntime initializeRuntime(); + + /** + * Gets the singleton {@link JVMCIRuntime} instance available to the application. + * + * @throws UnsupportedOperationException if JVMCI is not supported + */ + public static JVMCIRuntime getRuntime() { + if (runtime == null) { + String javaHome = System.getProperty("java.home"); + String vmName = System.getProperty("java.vm.name"); + Formatter errorMessage = new Formatter(); + errorMessage.format("The VM does not support the JVMCI API.%n"); + errorMessage.format("Currently used Java home directory is %s.%n", javaHome); + errorMessage.format("Currently used VM configuration is: %s", vmName); + throw new UnsupportedOperationException(errorMessage.toString()); + } + return runtime; + } + + static { + JVMCIRuntime rt = null; + try { + rt = initializeRuntime(); + } catch (UnsatisfiedLinkError e) { + } + runtime = rt; + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.runtime/src/com/oracle/jvmci/runtime/JVMCIBackend.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.runtime/src/com/oracle/jvmci/runtime/JVMCIBackend.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,62 @@ +/* + * 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.jvmci.runtime; + +import com.oracle.jvmci.code.CodeCacheProvider; +import com.oracle.jvmci.code.TargetDescription; +import com.oracle.jvmci.meta.MetaAccessProvider; +import com.oracle.jvmci.meta.ConstantReflectionProvider; + +/** + * A JVMCI backend encapsulates the capabilities needed by a Java based compiler for compiling and + * installing code for a single compute unit within a JVM. In a JVM with support for heterogeneous + * computing, more than one backend may be exposed. + */ +public class JVMCIBackend { + + private final MetaAccessProvider metaAccess; + private final CodeCacheProvider codeCache; + private final ConstantReflectionProvider constantReflection; + + public JVMCIBackend(MetaAccessProvider metaAccess, CodeCacheProvider codeCache, ConstantReflectionProvider constantReflection) { + this.metaAccess = metaAccess; + this.codeCache = codeCache; + this.constantReflection = constantReflection; + } + + public MetaAccessProvider getMetaAccess() { + return metaAccess; + } + + public CodeCacheProvider getCodeCache() { + return codeCache; + } + + public ConstantReflectionProvider getConstantReflection() { + return constantReflection; + } + + public TargetDescription getTarget() { + return codeCache.getTarget(); + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.runtime/src/com/oracle/jvmci/runtime/JVMCIRuntime.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.runtime/src/com/oracle/jvmci/runtime/JVMCIRuntime.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,43 @@ +/* + * 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.jvmci.runtime; + +import com.oracle.jvmci.code.Architecture; + +/** + * Interface for accessing the {@link JVMCI} APIs supported by the runtime. + */ +public interface JVMCIRuntime { + + /** + * Gets the host JVMCI backend. + */ + JVMCIBackend getHostJVMCIBackend(); + + /** + * Gets the backend for a given architecture. + * + * @param arch a specific architecture class + */ + JVMCIBackend getJVMCIBackend(Class arch); +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.service.processor/src/META-INF/services/javax.annotation.processing.Processor --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.service.processor/src/META-INF/services/javax.annotation.processing.Processor Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,1 @@ +com.oracle.jvmci.service.processor.ServiceProviderProcessor diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.service.processor/src/com/oracle/jvmci/service/processor/ServiceProviderProcessor.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.service.processor/src/com/oracle/jvmci/service/processor/ServiceProviderProcessor.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,119 @@ +/* + * 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.service.processor; + +import java.io.*; +import java.util.*; + +import javax.annotation.processing.*; +import javax.lang.model.*; +import javax.lang.model.element.*; +import javax.lang.model.type.*; +import javax.tools.Diagnostic.Kind; +import javax.tools.*; + +import com.oracle.jvmci.service.*; + +@SupportedAnnotationTypes("com.oracle.jvmci.service.ServiceProvider") +public class ServiceProviderProcessor extends AbstractProcessor { + + private final Set processed = new HashSet<>(); + private TypeElement baseJVMCIServiceInterface; + + @Override + public SourceVersion getSupportedSourceVersion() { + return SourceVersion.latest(); + } + + 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); + return false; + } + + return true; + } + + private void processElement(TypeElement serviceProvider) { + if (processed.contains(serviceProvider)) { + return; + } + + processed.add(serviceProvider); + ServiceProvider annotation = serviceProvider.getAnnotation(ServiceProvider.class); + if (annotation != null) { + try { + annotation.value(); + } catch (MirroredTypeException ex) { + TypeMirror serviceInterface = ex.getTypeMirror(); + if (verifyAnnotation(serviceInterface, serviceProvider)) { + String interfaceName = ex.getTypeMirror().toString(); + createProviderFile(serviceProvider, interfaceName); + } + } + } + } + + private void createProviderFile(TypeElement serviceProvider, String interfaceName) { + if (serviceProvider.getNestingKind().isNested()) { + // This is a simplifying constraint that means we don't have to + // processed the qualified name to insert '$' characters at + // the relevant positions. + String msg = String.format("Service provider class %s must be a top level class", serviceProvider.getSimpleName()); + processingEnv.getMessager().printMessage(Kind.ERROR, msg, serviceProvider); + return; + } + + String filename = "META-INF/providers/" + serviceProvider.getQualifiedName(); + try { + FileObject file = processingEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT, "", filename, serviceProvider); + PrintWriter writer = new PrintWriter(new OutputStreamWriter(file.openOutputStream(), "UTF-8")); + writer.println(interfaceName); + writer.close(); + } catch (IOException e) { + processingEnv.getMessager().printMessage(Kind.ERROR, e.getMessage(), serviceProvider); + } + } + + @Override + public boolean process(Set annotations, RoundEnvironment roundEnv) { + if (roundEnv.processingOver()) { + 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); + } + + return true; + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.service/src/com/oracle/jvmci/service/JVMCIClassLoaderFactory.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.service/src/com/oracle/jvmci/service/JVMCIClassLoaderFactory.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,87 @@ +/* + * 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.service; + +import java.io.*; +import java.net.*; +import java.util.*; + +/** + * Utility called from the VM to create and register a separate class loader for loading JVMCI + * classes (i.e., those in found in lib/jvmci/*.jar). + */ +class JVMCIClassLoaderFactory { + + /** + * Copy of the {@code UseJVMCIClassLoader} VM option. Set by the VM before the static + * initializer is called. + */ + private static boolean useJVMCIClassLoader; + + /** + * Registers the JVMCI class loader in the VM. + */ + private static native void init(ClassLoader loader); + + static { + init(useJVMCIClassLoader ? newClassLoader() : null); + } + + /** + * Creates a new class loader for loading JVMCI classes. + */ + private static ClassLoader newClassLoader() { + URL[] urls = getJVMCIJarsUrls(); + ClassLoader parent = null; + return URLClassLoader.newInstance(urls, parent); + } + + /** + * Gets the URLs for lib/jvmci/*.jar. + */ + private static URL[] getJVMCIJarsUrls() { + File javaHome = new File(System.getProperty("java.home")); + File lib = new File(javaHome, "lib"); + File jvmci = new File(lib, "jvmci"); + if (!jvmci.exists()) { + throw new InternalError(jvmci + " does not exist"); + } + + List urls = new ArrayList<>(); + for (String fileName : jvmci.list()) { + if (fileName.endsWith(".jar")) { + File file = new File(jvmci, fileName); + if (file.isDirectory()) { + continue; + } + try { + urls.add(file.toURI().toURL()); + } catch (MalformedURLException e) { + throw new InternalError(e); + } + } + } + + return urls.toArray(new URL[urls.size()]); + } +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.service/src/com/oracle/jvmci/service/Service.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.service/src/com/oracle/jvmci/service/Service.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,39 @@ +/* + * 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.service; + +import java.util.*; + +/** + * Denotes a JVMCI service that can be loaded by {@link Services#load(Class)} or + * {@link Services#loadSingle(Class, boolean)}. JVMCI services differ from + * {@linkplain ServiceLoader#load(Class) standard} services in that they may have implementations + * hidden behind a class loader not accessible to applications. For this reason, + * {@link Services#load(Class)} and {@link Services#loadSingle(Class, boolean)} perform + * {@link SecurityManager} checks. + * + * @see Services + * @see ServiceProvider + */ +public interface Service { +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.service/src/com/oracle/jvmci/service/ServiceProvider.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.service/src/com/oracle/jvmci/service/ServiceProvider.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,37 @@ +/* + * 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.service; + +import java.lang.annotation.*; + +/** + * Annotates a class that implements a {@linkplain Service JVMCI service}. This annotation is used + * by the JVMCI build system to deploy the necessary files used to {@linkplain Services#load(Class) + * load} JVMCI services at runtime. + */ +@Retention(RetentionPolicy.CLASS) +@Target(ElementType.TYPE) +public @interface ServiceProvider { + + Class value(); +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.service/src/com/oracle/jvmci/service/Services.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.service/src/com/oracle/jvmci/service/Services.java Tue Jun 09 00:22:49 2015 +0200 @@ -0,0 +1,123 @@ +/* + * 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.service; + +import java.util.*; + +import sun.reflect.*; + +/** + * An mechanism for loading {@linkplain Service JVMCI services}. + */ +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) { + try { + return Arrays.asList(getServiceImpls(type)); + } catch (NoClassDefFoundError e) { + if (SuppressNoClassDefFoundError) { + return Collections.emptyList(); + } + throw e; + } + } + }; + + /** + * Gets an {@link Iterable} of the implementations available for a given JVMCI service. + * + * @throws SecurityException if a security manager is present and it denies + * {@link RuntimePermission}("jvmciServices") + */ + @SuppressWarnings("unchecked") + @CallerSensitive + public static Iterable load(Class service) { + SecurityManager sm = System.getSecurityManager(); + if (sm != null) { + sm.checkPermission(new RuntimePermission("jvmciServices")); + } + try { + return (Iterable) cache.get(service); + } catch (UnsatisfiedLinkError e) { + return Collections.emptyList(); + } + } + + /** + * Gets the implementation for a given service for which at most one implementation must be + * available. + * + * @param service the service whose implementation is being requested + * @param required specifies if an {@link InternalError} should be thrown if no implementation + * of {@code service} is available + * @throws SecurityException if a security manager is present and it denies + * {@link RuntimePermission}("jvmciServices") + */ + @SuppressWarnings("unchecked") + @CallerSensitive + public static S loadSingle(Class service, boolean required) { + SecurityManager sm = System.getSecurityManager(); + if (sm != null) { + sm.checkPermission(new RuntimePermission("jvmciServices")); + } + Iterable impls; + try { + impls = (Iterable) cache.get(service); + } catch (UnsatisfiedLinkError e) { + impls = Collections.emptyList(); + } + + S singleImpl = null; + for (S impl : impls) { + if (singleImpl != null) { + throw new InternalError(String.format("Multiple %s implementations found: %s, %s", service.getName(), singleImpl.getClass().getName(), impl.getClass().getName())); + } + singleImpl = impl; + } + if (singleImpl == null && required) { + String javaHome = System.getProperty("java.home"); + String vmName = System.getProperty("java.vm.name"); + Formatter errorMessage = new Formatter(); + errorMessage.format("The VM does not expose required service %s.%n", service.getName()); + errorMessage.format("Currently used Java home directory is %s.%n", javaHome); + errorMessage.format("Currently used VM configuration is: %s", vmName); + throw new UnsupportedOperationException(errorMessage.toString()); + } + return singleImpl; + } + + static { + Reflection.registerMethodsToFilter(Services.class, "getServiceImpls"); + Reflection.registerFieldsToFilter(Services.class, "cache"); + } + + private static native S[] getServiceImpls(Class service); +} diff -r 42452d2dfbec -r 395ac43a8578 jvmci/com.oracle.jvmci.sparc/src/com/oracle/jvmci/sparc/SPARC.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.sparc/src/com/oracle/jvmci/sparc/SPARC.java Tue Jun 09 00:22:49 2015 +0200 @@ -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 42452d2dfbec -r 395ac43a8578 jvmci/findbugs-SuppressFBWarnings.jar Binary file jvmci/findbugs-SuppressFBWarnings.jar has changed diff -r 42452d2dfbec -r 395ac43a8578 make/bsd/makefiles/vm.make --- a/make/bsd/makefiles/vm.make Mon Jun 08 23:40:08 2015 +0200 +++ b/make/bsd/makefiles/vm.make Tue Jun 09 00:22:49 2015 +0200 @@ -219,7 +219,7 @@ JVMCI_SPECIFIC_FILES := jvmci\* else JVMCI_SPECIFIC_FILES := - Src_Dirs_I += $(HS_COMMON_SRC)/../graal/com.oracle.jvmci.hotspot/src_gen/hotspot + Src_Dirs_I += $(HS_COMMON_SRC)/../jvmci/com.oracle.jvmci.hotspot/src_gen/hotspot endif # Always exclude these. diff -r 42452d2dfbec -r 395ac43a8578 make/jvmci.make --- a/make/jvmci.make Mon Jun 08 23:40:08 2015 +0200 +++ b/make/jvmci.make Tue Jun 09 00:22:49 2015 +0200 @@ -33,7 +33,7 @@ # Since all projects are built together with one javac call we cannot determine # which project contains HotSpotVMConfig.inline.hpp so we hardcode it. $(eval vmconfig=$(1)/hotspot/HotSpotVMConfig.inline.hpp) - $(eval vmconfigDest=$(HS_COMMON_SRC)/../graal/com.oracle.jvmci.hotspot/src_gen/hotspot) + $(eval vmconfigDest=$(HS_COMMON_SRC)/../jvmci/com.oracle.jvmci.hotspot/src_gen/hotspot) test ! -f $(vmconfig) || (mkdir -p $(vmconfigDest) && cp $(vmconfig) $(vmconfigDest)) endef @@ -57,70 +57,70 @@ JDK_BOOTCLASSPATH = $(ABS_BOOTDIR)/jre/lib/resources.jar:$(ABS_BOOTDIR)/jre/lib/rt.jar:$(ABS_BOOTDIR)/jre/lib/jsse.jar:$(ABS_BOOTDIR)/jre/lib/jce.jar:$(ABS_BOOTDIR)/jre/lib/charsets.jar:$(ABS_BOOTDIR)/jre/lib/jfr.jar -JVMCI_OPTIONS_PROCESSOR_SRC = $(shell find graal/com.oracle.jvmci.options/src -type f -name *.java 2> /dev/null) -JVMCI_OPTIONS_PROCESSOR_SRC += $(shell find graal/com.oracle.jvmci.options.processor/src -type f -name *.java 2> /dev/null) +JVMCI_OPTIONS_PROCESSOR_SRC = $(shell find jvmci/com.oracle.jvmci.options/src -type f -name *.java 2> /dev/null) +JVMCI_OPTIONS_PROCESSOR_SRC += $(shell find jvmci/com.oracle.jvmci.options.processor/src -type f -name *.java 2> /dev/null) -JVMCI_OPTIONS_PROCESSOR_JAR = $(TARGET)/graal/com.oracle.jvmci.options.processor/ap/com.oracle.jvmci.options.processor.jar +JVMCI_OPTIONS_PROCESSOR_JAR = $(TARGET)/jvmci/com.oracle.jvmci.options.processor/ap/com.oracle.jvmci.options.processor.jar -JVMCI_HOTSPOTVMCONFIG_PROCESSOR_SRC = $(shell find graal/com.oracle.jvmci.hotspotvmconfig/src -type f -name *.java 2> /dev/null) -JVMCI_HOTSPOTVMCONFIG_PROCESSOR_SRC += $(shell find graal/com.oracle.jvmci.common/src -type f -name *.java 2> /dev/null) -JVMCI_HOTSPOTVMCONFIG_PROCESSOR_SRC += $(shell find graal/com.oracle.jvmci.hotspotvmconfig.processor/src -type f -name *.java 2> /dev/null) +JVMCI_HOTSPOTVMCONFIG_PROCESSOR_SRC = $(shell find jvmci/com.oracle.jvmci.hotspotvmconfig/src -type f -name *.java 2> /dev/null) +JVMCI_HOTSPOTVMCONFIG_PROCESSOR_SRC += $(shell find jvmci/com.oracle.jvmci.common/src -type f -name *.java 2> /dev/null) +JVMCI_HOTSPOTVMCONFIG_PROCESSOR_SRC += $(shell find jvmci/com.oracle.jvmci.hotspotvmconfig.processor/src -type f -name *.java 2> /dev/null) -JVMCI_HOTSPOTVMCONFIG_PROCESSOR_JAR = $(TARGET)/graal/com.oracle.jvmci.hotspotvmconfig.processor/ap/com.oracle.jvmci.hotspotvmconfig.processor.jar +JVMCI_HOTSPOTVMCONFIG_PROCESSOR_JAR = $(TARGET)/jvmci/com.oracle.jvmci.hotspotvmconfig.processor/ap/com.oracle.jvmci.hotspotvmconfig.processor.jar -JVMCI_SERVICE_PROCESSOR_SRC = $(shell find graal/com.oracle.jvmci.service/src -type f -name *.java 2> /dev/null) -JVMCI_SERVICE_PROCESSOR_SRC += $(shell find graal/com.oracle.jvmci.service.processor/src -type f -name *.java 2> /dev/null) +JVMCI_SERVICE_PROCESSOR_SRC = $(shell find jvmci/com.oracle.jvmci.service/src -type f -name *.java 2> /dev/null) +JVMCI_SERVICE_PROCESSOR_SRC += $(shell find jvmci/com.oracle.jvmci.service.processor/src -type f -name *.java 2> /dev/null) -JVMCI_SERVICE_PROCESSOR_JAR = $(TARGET)/graal/com.oracle.jvmci.service.processor/ap/com.oracle.jvmci.service.processor.jar +JVMCI_SERVICE_PROCESSOR_JAR = $(TARGET)/jvmci/com.oracle.jvmci.service.processor/ap/com.oracle.jvmci.service.processor.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_SRC = $(shell find jvmci/com.oracle.jvmci.meta/src -type f -name *.java 2> /dev/null) +JVMCI_API_SRC += $(shell find jvmci/com.oracle.jvmci.code/src -type f -name *.java 2> /dev/null) +JVMCI_API_SRC += $(shell find jvmci/com.oracle.jvmci.runtime/src -type f -name *.java 2> /dev/null) +JVMCI_API_SRC += $(shell find jvmci/com.oracle.jvmci.options/src -type f -name *.java 2> /dev/null) +JVMCI_API_SRC += $(shell find jvmci/com.oracle.jvmci.common/src -type f -name *.java 2> /dev/null) +JVMCI_API_SRC += $(shell find jvmci/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 +JVMCI_API_DEP_JARS = $(TARGET)/build/jvmci-service.jar jvmci/findbugs-SuppressFBWarnings.jar EXPORTED_FILES += $(JVMCI_API_JAR) -JVMCI_SERVICE_SRC = $(shell find graal/com.oracle.jvmci.service/src -type f -name *.java 2> /dev/null) +JVMCI_SERVICE_SRC = $(shell find jvmci/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 +JVMCI_SERVICE_DEP_JARS = jvmci/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.amd64/src -type f -name *.java 2> /dev/null) -JVMCI_HOTSPOT_SRC += $(shell find graal/com.oracle.jvmci.amd64/graal/com.oracle.jvmci.amd64/src_gen -type f -name *.java 2> /dev/null) -JVMCI_HOTSPOT_SRC += $(shell find graal/com.oracle.jvmci.compiler/src -type f -name *.java 2> /dev/null) -JVMCI_HOTSPOT_SRC += $(shell find graal/com.oracle.jvmci.compiler/graal/com.oracle.jvmci.compiler/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.sparc/src -type f -name *.java 2> /dev/null) -JVMCI_HOTSPOT_SRC += $(shell find graal/com.oracle.jvmci.sparc/graal/com.oracle.jvmci.sparc/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_SRC = $(shell find jvmci/com.oracle.jvmci.hotspotvmconfig/src -type f -name *.java 2> /dev/null) +JVMCI_HOTSPOT_SRC += $(shell find jvmci/com.oracle.jvmci.hotspotvmconfig/jvmci/com.oracle.jvmci.hotspotvmconfig/src_gen -type f -name *.java 2> /dev/null) +JVMCI_HOTSPOT_SRC += $(shell find jvmci/com.oracle.jvmci.amd64/src -type f -name *.java 2> /dev/null) +JVMCI_HOTSPOT_SRC += $(shell find jvmci/com.oracle.jvmci.amd64/jvmci/com.oracle.jvmci.amd64/src_gen -type f -name *.java 2> /dev/null) +JVMCI_HOTSPOT_SRC += $(shell find jvmci/com.oracle.jvmci.compiler/src -type f -name *.java 2> /dev/null) +JVMCI_HOTSPOT_SRC += $(shell find jvmci/com.oracle.jvmci.compiler/jvmci/com.oracle.jvmci.compiler/src_gen -type f -name *.java 2> /dev/null) +JVMCI_HOTSPOT_SRC += $(shell find jvmci/com.oracle.jvmci.hotspot/src -type f -name *.java 2> /dev/null) +JVMCI_HOTSPOT_SRC += $(shell find jvmci/com.oracle.jvmci.hotspot/jvmci/com.oracle.jvmci.hotspot/src_gen -type f -name *.java 2> /dev/null) +JVMCI_HOTSPOT_SRC += $(shell find jvmci/com.oracle.jvmci.hotspot.amd64/src -type f -name *.java 2> /dev/null) +JVMCI_HOTSPOT_SRC += $(shell find jvmci/com.oracle.jvmci.hotspot.amd64/jvmci/com.oracle.jvmci.hotspot.amd64/src_gen -type f -name *.java 2> /dev/null) +JVMCI_HOTSPOT_SRC += $(shell find jvmci/com.oracle.jvmci.sparc/src -type f -name *.java 2> /dev/null) +JVMCI_HOTSPOT_SRC += $(shell find jvmci/com.oracle.jvmci.sparc/jvmci/com.oracle.jvmci.sparc/src_gen -type f -name *.java 2> /dev/null) +JVMCI_HOTSPOT_SRC += $(shell find jvmci/com.oracle.jvmci.hotspot.sparc/src -type f -name *.java 2> /dev/null) +JVMCI_HOTSPOT_SRC += $(shell find jvmci/com.oracle.jvmci.hotspot.sparc/jvmci/com.oracle.jvmci.hotspot.sparc/src_gen -type f -name *.java 2> /dev/null) +JVMCI_HOTSPOT_SRC += $(shell find jvmci/com.oracle.jvmci.hotspot.jfr/src -type f -name *.java 2> /dev/null) +JVMCI_HOTSPOT_SRC += $(shell find jvmci/com.oracle.jvmci.hotspot.jfr/jvmci/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-api.jar $(TARGET)/build/jvmci-service.jar graal/findbugs-SuppressFBWarnings.jar +JVMCI_HOTSPOT_DEP_JARS = $(TARGET)/build/jvmci-api.jar $(TARGET)/build/jvmci-service.jar jvmci/findbugs-SuppressFBWarnings.jar EXPORTED_FILES += $(JVMCI_HOTSPOT_JAR) $(JVMCI_OPTIONS_PROCESSOR_JAR): $(JVMCI_OPTIONS_PROCESSOR_SRC) $(eval TMP := $(shell mktemp -d JVMCI_OPTIONS_PROCESSOR_XXXXX)) $(JAVAC) -d $(TMP) -bootclasspath $(JDK_BOOTCLASSPATH) $(JVMCI_OPTIONS_PROCESSOR_SRC) - cp -r graal/com.oracle.jvmci.options.processor/src/META-INF $(TMP) + cp -r jvmci/com.oracle.jvmci.options.processor/src/META-INF $(TMP) $(call process_options,$(TMP),False) mkdir -p $$(dirname $(JVMCI_OPTIONS_PROCESSOR_JAR)) $(JAR) cf $(JVMCI_OPTIONS_PROCESSOR_JAR) -C $(TMP) . @@ -129,7 +129,7 @@ $(JVMCI_HOTSPOTVMCONFIG_PROCESSOR_JAR): $(JVMCI_HOTSPOTVMCONFIG_PROCESSOR_SRC) $(eval TMP := $(shell mktemp -d JVMCI_HOTSPOTVMCONFIG_PROCESSOR_XXXXX)) $(JAVAC) -d $(TMP) -bootclasspath $(JDK_BOOTCLASSPATH) $(JVMCI_HOTSPOTVMCONFIG_PROCESSOR_SRC) - cp -r graal/com.oracle.jvmci.hotspotvmconfig.processor/src/META-INF $(TMP) + cp -r jvmci/com.oracle.jvmci.hotspotvmconfig.processor/src/META-INF $(TMP) $(call process_options,$(TMP),False) mkdir -p $$(dirname $(JVMCI_HOTSPOTVMCONFIG_PROCESSOR_JAR)) $(JAR) cf $(JVMCI_HOTSPOTVMCONFIG_PROCESSOR_JAR) -C $(TMP) . @@ -138,7 +138,7 @@ $(JVMCI_SERVICE_PROCESSOR_JAR): $(JVMCI_SERVICE_PROCESSOR_SRC) $(eval TMP := $(shell mktemp -d JVMCI_SERVICE_PROCESSOR_XXXXX)) $(JAVAC) -d $(TMP) -bootclasspath $(JDK_BOOTCLASSPATH) $(JVMCI_SERVICE_PROCESSOR_SRC) - cp -r graal/com.oracle.jvmci.service.processor/src/META-INF $(TMP) + cp -r jvmci/com.oracle.jvmci.service.processor/src/META-INF $(TMP) $(call process_options,$(TMP),False) mkdir -p $$(dirname $(JVMCI_SERVICE_PROCESSOR_JAR)) $(JAR) cf $(JVMCI_SERVICE_PROCESSOR_JAR) -C $(TMP) . diff -r 42452d2dfbec -r 395ac43a8578 make/linux/makefiles/vm.make --- a/make/linux/makefiles/vm.make Mon Jun 08 23:40:08 2015 +0200 +++ b/make/linux/makefiles/vm.make Tue Jun 09 00:22:49 2015 +0200 @@ -199,7 +199,7 @@ JVMCI_SPECIFIC_FILES := jvmci\* else JVMCI_SPECIFIC_FILES := - Src_Dirs_I += $(HS_COMMON_SRC)/../graal/com.oracle.jvmci.hotspot/src_gen/hotspot + Src_Dirs_I += $(HS_COMMON_SRC)/../jvmci/com.oracle.jvmci.hotspot/src_gen/hotspot endif # Always exclude these. diff -r 42452d2dfbec -r 395ac43a8578 make/solaris/makefiles/vm.make --- a/make/solaris/makefiles/vm.make Mon Jun 08 23:40:08 2015 +0200 +++ b/make/solaris/makefiles/vm.make Tue Jun 09 00:22:49 2015 +0200 @@ -211,7 +211,7 @@ JVMCI_SPECIFIC_FILES := jvmci\* else JVMCI_SPECIFIC_FILES := - Src_Dirs_I += $(HS_COMMON_SRC)/../graal/com.oracle.jvmci.hotspot/src_gen/hotspot + Src_Dirs_I += $(HS_COMMON_SRC)/../jvmci/com.oracle.jvmci.hotspot/src_gen/hotspot endif # Always exclude these. diff -r 42452d2dfbec -r 395ac43a8578 make/windows/makefiles/projectcreator.make --- a/make/windows/makefiles/projectcreator.make Mon Jun 08 23:40:08 2015 +0200 +++ b/make/windows/makefiles/projectcreator.make Tue Jun 09 00:22:49 2015 +0200 @@ -56,7 +56,7 @@ -relativeInclude src\os\windows\vm \ -relativeInclude src\os_cpu\windows_$(Platform_arch)\vm \ -relativeInclude src\cpu\$(Platform_arch)\vm \ - -relativeInclude graal\com.oracle.jvmci.hotspot\src_gen\hotspot \ + -relativeInclude jvmci\com.oracle.jvmci.hotspot\src_gen\hotspot \ -absoluteInclude $(HOTSPOTBUILDSPACE)/%f/generated \ -relativeSrcInclude src \ -absoluteSrcInclude $(HOTSPOTBUILDSPACE) \ @@ -152,7 +152,7 @@ ProjectCreatorIDEOptionsIgnoreJVMCI=\ -ignorePath_TARGET src/share/vm/jvmci \ - -ignorePath_TARGET graal\com.oracle.jvmci.hotspot\src_gen\hotspot \ + -ignorePath_TARGET jvmci\com.oracle.jvmci.hotspot\src_gen\hotspot \ -ignorePath_TARGET vm/jvmci ProjectCreatorIDEOptionsIgnoreCompiler2=\ diff -r 42452d2dfbec -r 395ac43a8578 mx/mx_graal.py --- a/mx/mx_graal.py Mon Jun 08 23:40:08 2015 +0200 +++ b/mx/mx_graal.py Tue Jun 09 00:22:49 2015 +0200 @@ -922,7 +922,7 @@ mustBuild = False timestamp = os.path.getmtime(timestampFile) sources = [] - for d in ['src', 'make', join('graal', 'com.oracle.jvmci.hotspot', 'src_gen', 'hotspot')]: + for d in ['src', 'make', join('jvmci', 'com.oracle.jvmci.hotspot', 'src_gen', 'hotspot')]: for root, dirnames, files in os.walk(join(_graal_home, d)): # ignore /src/share/tools if root == join(_graal_home, 'src', 'share'): diff -r 42452d2dfbec -r 395ac43a8578 mx/mx_graal_makefile.py --- a/mx/mx_graal_makefile.py Mon Jun 08 23:40:08 2015 +0200 +++ b/mx/mx_graal_makefile.py Tue Jun 09 00:22:49 2015 +0200 @@ -204,7 +204,7 @@ # Since all projects are built together with one javac call we cannot determine # which project contains HotSpotVMConfig.inline.hpp so we hardcode it. $(eval vmconfig=$(1)/hotspot/HotSpotVMConfig.inline.hpp) - $(eval vmconfigDest=$(HS_COMMON_SRC)/../graal/com.oracle.jvmci.hotspot/src_gen/hotspot) + $(eval vmconfigDest=$(HS_COMMON_SRC)/../jvmci/com.oracle.jvmci.hotspot/src_gen/hotspot) test ! -f $(vmconfig) || (mkdir -p $(vmconfigDest) && cp $(vmconfig) $(vmconfigDest)) endef diff -r 42452d2dfbec -r 395ac43a8578 mx/suite.py --- a/mx/suite.py Mon Jun 08 23:40:08 2015 +0200 +++ b/mx/suite.py Tue Jun 09 00:22:49 2015 +0200 @@ -83,7 +83,7 @@ }, "FINDBUGS" : { - "path" : "graal/findbugs-SuppressFBWarnings.jar", + "path" : "jvmci/findbugs-SuppressFBWarnings.jar", "sha1" : "fb78822d27c68fabf2cb2e5e573b3cdb5f9cae2d", }, @@ -159,7 +159,7 @@ # ------------- JVMCI:Service ------------- "com.oracle.jvmci.service" : { - "subDir" : "graal", + "subDir" : "jvmci", "sourceDirs" : ["src"], "checkstyle" : "com.oracle.graal.graph", "javaCompliance" : "1.8", @@ -167,7 +167,7 @@ }, "com.oracle.jvmci.service.processor" : { - "subDir" : "graal", + "subDir" : "jvmci", "sourceDirs" : ["src"], "dependencies" : ["com.oracle.jvmci.service"], "checkstyle" : "com.oracle.graal.graph", @@ -178,7 +178,7 @@ # ------------- JVMCI:API ------------- "com.oracle.jvmci.common" : { - "subDir" : "graal", + "subDir" : "jvmci", "sourceDirs" : ["src"], "checkstyle" : "com.oracle.graal.graph", "javaCompliance" : "1.8", @@ -186,7 +186,7 @@ }, "com.oracle.jvmci.meta" : { - "subDir" : "graal", + "subDir" : "jvmci", "sourceDirs" : ["src"], "checkstyle" : "com.oracle.graal.graph", "javaCompliance" : "1.8", @@ -194,7 +194,7 @@ }, "com.oracle.jvmci.code" : { - "subDir" : "graal", + "subDir" : "jvmci", "sourceDirs" : ["src"], "dependencies" : ["com.oracle.jvmci.meta"], "checkstyle" : "com.oracle.graal.graph", @@ -203,7 +203,7 @@ }, "com.oracle.jvmci.runtime" : { - "subDir" : "graal", + "subDir" : "jvmci", "sourceDirs" : ["src"], "dependencies" : [ "com.oracle.jvmci.code" @@ -214,7 +214,7 @@ }, "com.oracle.jvmci.runtime.test" : { - "subDir" : "graal", + "subDir" : "jvmci", "sourceDirs" : ["src"], "dependencies" : [ "JUNIT", @@ -227,7 +227,7 @@ }, "com.oracle.jvmci.debug" : { - "subDir" : "graal", + "subDir" : "jvmci", "sourceDirs" : ["src"], "checkstyle" : "com.oracle.graal.graph", "dependencies" : [ @@ -240,7 +240,7 @@ }, "com.oracle.jvmci.debug.test" : { - "subDir" : "graal", + "subDir" : "jvmci", "sourceDirs" : ["src"], "dependencies" : [ "JUNIT", @@ -252,7 +252,7 @@ }, "com.oracle.jvmci.options" : { - "subDir" : "graal", + "subDir" : "jvmci", "sourceDirs" : ["src"], "checkstyle" : "com.oracle.graal.graph", "javaCompliance" : "1.8", @@ -260,7 +260,7 @@ }, "com.oracle.jvmci.compiler" : { - "subDir" : "graal", + "subDir" : "jvmci", "sourceDirs" : ["src"], "dependencies" : [ "com.oracle.jvmci.debug", @@ -272,7 +272,7 @@ }, "com.oracle.jvmci.options.processor" : { - "subDir" : "graal", + "subDir" : "jvmci", "sourceDirs" : ["src"], "dependencies" : [ "com.oracle.jvmci.options", @@ -283,7 +283,7 @@ }, "com.oracle.jvmci.options.test" : { - "subDir" : "graal", + "subDir" : "jvmci", "sourceDirs" : ["src"], "dependencies" : [ "com.oracle.jvmci.options", @@ -298,7 +298,7 @@ # ------------- JVMCI:HotSpot ------------- "com.oracle.jvmci.amd64" : { - "subDir" : "graal", + "subDir" : "jvmci", "sourceDirs" : ["src"], "dependencies" : ["com.oracle.jvmci.code"], "checkstyle" : "com.oracle.graal.graph", @@ -307,7 +307,7 @@ }, "com.oracle.jvmci.sparc" : { - "subDir" : "graal", + "subDir" : "jvmci", "sourceDirs" : ["src"], "dependencies" : ["com.oracle.jvmci.code"], "checkstyle" : "com.oracle.graal.graph", @@ -316,7 +316,7 @@ }, "com.oracle.jvmci.hotspot" : { - "subDir" : "graal", + "subDir" : "jvmci", "sourceDirs" : ["src"], "dependencies" : [ "com.oracle.jvmci.hotspotvmconfig", @@ -336,7 +336,7 @@ }, "com.oracle.jvmci.hotspotvmconfig" : { - "subDir" : "graal", + "subDir" : "jvmci", "sourceDirs" : ["src"], "checkstyle" : "com.oracle.graal.graph", "javaCompliance" : "1.8", @@ -344,7 +344,7 @@ }, "com.oracle.jvmci.hotspotvmconfig.processor" : { - "subDir" : "graal", + "subDir" : "jvmci", "sourceDirs" : ["src"], "dependencies" : ["com.oracle.jvmci.hotspotvmconfig", "com.oracle.jvmci.common"], "checkstyle" : "com.oracle.graal.graph", @@ -353,7 +353,7 @@ }, "com.oracle.jvmci.hotspot.amd64" : { - "subDir" : "graal", + "subDir" : "jvmci", "sourceDirs" : ["src"], "dependencies" : [ "com.oracle.jvmci.amd64", @@ -366,7 +366,7 @@ }, "com.oracle.jvmci.hotspot.sparc" : { - "subDir" : "graal", + "subDir" : "jvmci", "sourceDirs" : ["src"], "dependencies" : [ "com.oracle.jvmci.sparc", @@ -379,7 +379,7 @@ }, "com.oracle.jvmci.hotspot.jfr" : { - "subDir" : "graal", + "subDir" : "jvmci", "sourceDirs" : ["src"], "dependencies" : [ "com.oracle.jvmci.hotspot",