# HG changeset patch # User Doug Simon # Date 1432461417 -7200 # Node ID de0cf192779cfc8cf15715c595c7d8a11dee2640 # Parent 513f8d0ae27d2db7c6afd1e7c4c6d7a2bc5be457 removed more dependencies from JVMCI classes to non-JVMCI classes (JBS:GRAAL-53) diff -r 513f8d0ae27d -r de0cf192779c graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotVmSymbols.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotVmSymbols.java Fri May 22 23:58:35 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.hotspot; - -import static com.oracle.graal.compiler.common.UnsafeAccess.*; -import static com.oracle.graal.hotspot.HotSpotGraalRuntime.*; - -import com.oracle.graal.hotspot.jvmci.*; - -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) { - HotSpotGraalRuntimeProvider 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 513f8d0ae27d -r de0cf192779c graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/PrintStreamOption.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/PrintStreamOption.java Fri May 22 23:58:35 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,138 +0,0 @@ -/* - * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.hotspot; - -import java.io.*; -import java.lang.management.*; - -import com.oracle.graal.hotspot.jvmci.*; -import com.oracle.graal.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 513f8d0ae27d -r de0cf192779c graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/jvmci/HotSpotCodeCacheProvider.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/jvmci/HotSpotCodeCacheProvider.java Fri May 22 23:58:35 2015 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/jvmci/HotSpotCodeCacheProvider.java Sun May 24 11:56:57 2015 +0200 @@ -40,7 +40,6 @@ import com.oracle.graal.api.meta.*; import com.oracle.graal.compiler.common.*; import com.oracle.graal.debug.*; -import com.oracle.graal.hotspot.meta.*; import com.oracle.graal.printer.*; /** diff -r 513f8d0ae27d -r de0cf192779c graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/jvmci/HotSpotConstantPool.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/jvmci/HotSpotConstantPool.java Fri May 22 23:58:35 2015 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/jvmci/HotSpotConstantPool.java Sun May 24 11:56:57 2015 +0200 @@ -31,8 +31,6 @@ import com.oracle.graal.bytecode.*; import com.oracle.graal.compiler.common.*; -//import com.oracle.graal.hotspot.meta.*; - /** * Implementation of {@link ConstantPool} for HotSpot. */ diff -r 513f8d0ae27d -r de0cf192779c graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/jvmci/HotSpotConstantReflectionProvider.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/jvmci/HotSpotConstantReflectionProvider.java Fri May 22 23:58:35 2015 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/jvmci/HotSpotConstantReflectionProvider.java Sun May 24 11:56:57 2015 +0200 @@ -32,7 +32,6 @@ import com.oracle.graal.api.meta.*; import com.oracle.graal.compiler.common.*; import com.oracle.graal.graph.*; -import com.oracle.graal.hotspot.meta.*; import com.oracle.graal.options.*; import com.oracle.graal.replacements.*; import com.oracle.graal.replacements.SnippetTemplate.Arguments; @@ -47,6 +46,8 @@ protected final HotSpotMethodHandleAccessProvider methodHandleAccess; protected final HotSpotMemoryAccessProviderImpl memoryAccess; + public static final ThreadLocal FieldReadEnabledInImmutableCode = new ThreadLocal<>(); + public HotSpotConstantReflectionProvider(HotSpotJVMCIRuntimeProvider runtime) { this.runtime = runtime; this.methodHandleAccess = new HotSpotMethodHandleAccessProvider(this); @@ -228,7 +229,8 @@ * {@code receiver} is (assignable to) {@link StableOptionValue}. */ public JavaConstant readConstantFieldValue(JavaField field, JavaConstant receiver) { - assert !ImmutableCode.getValue() || isCalledForSnippets() || SnippetGraphUnderConstruction.get() != null || HotSpotLoadFieldPlugin.FieldReadEnabledInImmutableCode.get() == Boolean.TRUE : receiver; + assert !ImmutableCode.getValue() || isCalledForSnippets() || SnippetGraphUnderConstruction.get() != null || + HotSpotConstantReflectionProvider.FieldReadEnabledInImmutableCode.get() == Boolean.TRUE : receiver; HotSpotResolvedJavaField hotspotField = (HotSpotResolvedJavaField) field; if (hotspotField.isStatic()) { diff -r 513f8d0ae27d -r de0cf192779c graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/jvmci/HotSpotJVMCIRuntime.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/jvmci/HotSpotJVMCIRuntime.java Fri May 22 23:58:35 2015 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/jvmci/HotSpotJVMCIRuntime.java Sun May 24 11:56:57 2015 +0200 @@ -32,7 +32,6 @@ import com.oracle.graal.api.meta.*; import com.oracle.graal.api.runtime.*; import com.oracle.graal.debug.*; -import com.oracle.graal.hotspot.*; import com.oracle.graal.hotspot.jvmci.logging.*; import com.oracle.graal.options.*; import com.oracle.jvmci.runtime.*; diff -r 513f8d0ae27d -r de0cf192779c graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/jvmci/HotSpotMetaAccessProvider.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/jvmci/HotSpotMetaAccessProvider.java Fri May 22 23:58:35 2015 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/jvmci/HotSpotMetaAccessProvider.java Sun May 24 11:56:57 2015 +0200 @@ -30,8 +30,6 @@ import com.oracle.graal.api.code.*; import com.oracle.graal.api.meta.*; -import com.oracle.graal.compiler.common.*; -import com.oracle.graal.hotspot.replacements.*; /** * HotSpot implementation of {@link MetaAccessProvider}. @@ -78,7 +76,7 @@ field.setAccessible(true); return field; } catch (NoSuchFieldException | SecurityException e) { - throw new GraalInternalError(e); + throw new InternalError(e); } } @@ -90,7 +88,7 @@ final long metaspaceMethod = runtime.getCompilerToVM().getMetaspaceMethod(holder, slot); return HotSpotResolvedJavaMethodImpl.fromMetaspace(metaspaceMethod); } catch (IllegalArgumentException | IllegalAccessException e) { - throw new GraalInternalError(e); + throw new InternalError(e); } } @@ -110,7 +108,7 @@ HotSpotResolvedObjectType resolved = holder; return resolved.createField(name, type, offset, modifiers); } else { - throw GraalInternalError.shouldNotReachHere("unresolved field " + reflectionField); + throw new InternalError("unresolved field " + reflectionField); } } @@ -163,7 +161,7 @@ case InvalidateStopCompiling: return config.deoptActionMakeNotCompilable; default: - throw GraalInternalError.shouldNotReachHere(); + throw new InternalError(action.toString()); } } @@ -184,7 +182,7 @@ if (action == config.deoptActionMakeNotCompilable) { return DeoptimizationAction.InvalidateStopCompiling; } - throw GraalInternalError.shouldNotReachHere(); + throw new InternalError(String.valueOf(action)); } public int convertDeoptReason(DeoptimizationReason reason) { @@ -223,7 +221,7 @@ case TransferToInterpreter: return config.deoptReasonTransferToInterpreter; default: - throw GraalInternalError.shouldNotReachHere(); + throw new InternalError(reason.toString()); } } @@ -277,7 +275,7 @@ if (reason == config.deoptReasonTransferToInterpreter) { return DeoptimizationReason.TransferToInterpreter; } - throw GraalInternalError.shouldNotReachHere(Integer.toHexString(reason)); + throw new InternalError(Integer.toHexString(reason)); } @Override @@ -298,7 +296,7 @@ int sizeOfElement = target.getSizeInBytes(elementKind); int alignment = target.wordSize; int log2ElementSize = CodeUtil.log2(sizeOfElement); - return NewObjectSnippets.computeArrayAllocationSize(length, alignment, headerSize, log2ElementSize); + return computeArrayAllocationSize(length, alignment, headerSize, log2ElementSize); } return lookupJavaType.instanceSize(); } @@ -306,4 +304,20 @@ 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 513f8d0ae27d -r de0cf192779c graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/jvmci/HotSpotMethodHandleAccessProvider.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/jvmci/HotSpotMethodHandleAccessProvider.java Sun May 24 11:56:57 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.graal.hotspot.jvmci; + +import static com.oracle.graal.hotspot.HotSpotGraalRuntime.*; +import static com.oracle.graal.hotspot.jvmci.HotSpotResolvedJavaType.*; +import static com.oracle.graal.hotspot.jvmci.HotSpotResolvedObjectTypeImpl.*; + +import com.oracle.graal.api.meta.*; +import com.oracle.graal.compiler.common.*; + +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 GraalInternalError.shouldNotReachHere(); + } + } + } + + @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 513f8d0ae27d -r de0cf192779c graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/jvmci/HotSpotOptions.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/jvmci/HotSpotOptions.java Fri May 22 23:58:35 2015 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/jvmci/HotSpotOptions.java Sun May 24 11:56:57 2015 +0200 @@ -26,11 +26,10 @@ import static com.oracle.graal.hotspot.jvmci.HotSpotOptionsLoader.*; import static java.lang.Double.*; -import com.oracle.graal.api.runtime.*; import com.oracle.graal.debug.*; -import com.oracle.graal.hotspot.*; import com.oracle.graal.options.*; import com.oracle.graal.options.OptionUtils.OptionConsumer; +import com.oracle.jvmci.runtime.*; //JaCoCo Exclude @@ -43,15 +42,15 @@ private static final String GRAAL_OPTION_PREFIX = "-G:"; /** - * Parses the Graal specific options specified to HotSpot (e.g., on the command line). + * Parses the JVMCI specific options specified to HotSpot (e.g., on the command line). */ private static native void parseVMOptions(); static { parseVMOptions(); - assert !Debug.Initialization.isDebugInitialized() : "The class " + Debug.class.getName() + " must not be initialized before the Graal runtime has been initialized. " + - "This can be fixed by placing a call to " + Graal.class.getName() + ".runtime() on the path that triggers initialization of " + Debug.class.getName(); + assert !Debug.Initialization.isDebugInitialized() : "The class " + Debug.class.getName() + " must not be initialized before the JVMCI runtime has been initialized. " + + "This can be fixed by placing a call to " + JVMCI.class.getName() + ".getRuntime() on the path that triggers initialization of " + Debug.class.getName(); if (areDebugScopePatternsEnabled()) { System.setProperty(Debug.Initialization.INITIALIZER_PROPERTY_NAME, "true"); } diff -r 513f8d0ae27d -r de0cf192779c graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/jvmci/HotSpotResolvedJavaMethodImpl.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/jvmci/HotSpotResolvedJavaMethodImpl.java Fri May 22 23:58:35 2015 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/jvmci/HotSpotResolvedJavaMethodImpl.java Sun May 24 11:56:57 2015 +0200 @@ -35,7 +35,6 @@ import com.oracle.graal.api.meta.*; import com.oracle.graal.debug.*; import com.oracle.graal.graphbuilderconf.*; -import com.oracle.graal.hotspot.meta.*; import com.oracle.graal.nodes.*; /** diff -r 513f8d0ae27d -r de0cf192779c graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/jvmci/HotSpotResolvedObjectTypeImpl.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/jvmci/HotSpotResolvedObjectTypeImpl.java Fri May 22 23:58:35 2015 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/jvmci/HotSpotResolvedObjectTypeImpl.java Sun May 24 11:56:57 2015 +0200 @@ -39,7 +39,6 @@ import com.oracle.graal.api.meta.Assumptions.NoFinalizableSubclass; import com.oracle.graal.api.meta.*; import com.oracle.graal.compiler.common.*; -import com.oracle.graal.hotspot.*; /** * Implementation of {@link JavaType} for resolved non-primitive HotSpot classes. diff -r 513f8d0ae27d -r de0cf192779c graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/jvmci/HotSpotSpeculationLog.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/jvmci/HotSpotSpeculationLog.java Sun May 24 11:56:57 2015 +0200 @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2014, 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.graal.hotspot.jvmci; + +import com.oracle.graal.api.code.*; +import com.oracle.graal.api.meta.*; + +public class HotSpotSpeculationLog extends SpeculationLog { + + @Override + public JavaConstant speculate(Object reason) { + addSpeculation(reason); + return HotSpotObjectConstantImpl.forObject(reason); + } +} diff -r 513f8d0ae27d -r de0cf192779c graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/jvmci/HotSpotVmSymbols.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/jvmci/HotSpotVmSymbols.java Sun May 24 11:56:57 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.graal.hotspot.jvmci; + +import static com.oracle.graal.compiler.common.UnsafeAccess.*; +import static com.oracle.graal.hotspot.jvmci.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 513f8d0ae27d -r de0cf192779c graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/jvmci/PrintStreamOption.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/jvmci/PrintStreamOption.java Sun May 24 11:56:57 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.graal.hotspot.jvmci; + +import java.io.*; +import java.lang.management.*; + +import com.oracle.graal.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 513f8d0ae27d -r de0cf192779c graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotLoadFieldPlugin.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotLoadFieldPlugin.java Fri May 22 23:58:35 2015 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotLoadFieldPlugin.java Sun May 24 11:56:57 2015 +0200 @@ -26,6 +26,7 @@ import com.oracle.graal.api.meta.*; import com.oracle.graal.graphbuilderconf.*; +import com.oracle.graal.hotspot.jvmci.*; import com.oracle.graal.nodes.*; public final class HotSpotLoadFieldPlugin implements LoadFieldPlugin { @@ -37,8 +38,6 @@ this.constantReflection = constantReflection; } - public static final ThreadLocal FieldReadEnabledInImmutableCode = new ThreadLocal<>(); - public boolean apply(GraphBuilderContext b, ValueNode receiver, ResolvedJavaField field) { if (!ImmutableCode.getValue() || b.parsingIntrinsic()) { if (receiver.isConstant()) { @@ -51,13 +50,13 @@ private boolean tryReadField(GraphBuilderContext b, ResolvedJavaField field, JavaConstant receiver) { if (ImmutableCode.getValue()) { - FieldReadEnabledInImmutableCode.set(Boolean.TRUE); + HotSpotConstantReflectionProvider.FieldReadEnabledInImmutableCode.set(Boolean.TRUE); } try { return tryConstantFold(b, metaAccess, constantReflection, field, receiver); } finally { if (ImmutableCode.getValue()) { - FieldReadEnabledInImmutableCode.set(null); + HotSpotConstantReflectionProvider.FieldReadEnabledInImmutableCode.set(null); } } } diff -r 513f8d0ae27d -r de0cf192779c graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotSpeculationLog.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotSpeculationLog.java Fri May 22 23:58:35 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2014, 2014, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.hotspot.meta; - -import com.oracle.graal.api.code.*; -import com.oracle.graal.api.meta.*; -import com.oracle.graal.hotspot.jvmci.*; - -public class HotSpotSpeculationLog extends SpeculationLog { - - @Override - public JavaConstant speculate(Object reason) { - addSpeculation(reason); - return HotSpotObjectConstantImpl.forObject(reason); - } -} diff -r 513f8d0ae27d -r de0cf192779c graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/NewObjectSnippets.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/NewObjectSnippets.java Fri May 22 23:58:35 2015 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/NewObjectSnippets.java Sun May 24 11:56:57 2015 +0200 @@ -24,6 +24,7 @@ import static com.oracle.graal.api.code.UnsignedMath.*; import static com.oracle.graal.compiler.common.GraalOptions.*; +import static com.oracle.graal.hotspot.jvmci.HotSpotMetaAccessProvider.*; import static com.oracle.graal.hotspot.nodes.CStringNode.*; import static com.oracle.graal.hotspot.replacements.HotSpotReplacementsUtil.*; import static com.oracle.graal.hotspot.replacements.NewObjectSnippets.Options.*; @@ -261,22 +262,6 @@ } /** - * 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; - } - - /** * Calls the runtime stub for implementing MULTIANEWARRAY. */ @Snippet diff -r 513f8d0ae27d -r de0cf192779c graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/NewArrayStub.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/NewArrayStub.java Fri May 22 23:58:35 2015 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/NewArrayStub.java Sun May 24 11:56:57 2015 +0200 @@ -22,6 +22,7 @@ */ package com.oracle.graal.hotspot.stubs; +import static com.oracle.graal.hotspot.jvmci.HotSpotMetaAccessProvider.*; import static com.oracle.graal.hotspot.replacements.HotSpotReplacementsUtil.*; import static com.oracle.graal.hotspot.replacements.NewObjectSnippets.*; import static com.oracle.graal.hotspot.stubs.NewInstanceStub.*;