changeset 13712:190d29710e97

Merge.
author Christian Humer <christian.humer@gmail.com>
date Mon, 20 Jan 2014 18:25:17 +0100
parents 193e3917dc07 (current diff) e749c19405ce (diff)
children 984782c1211c cffcb8e38c4c
files
diffstat 12 files changed, 188 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.asm.ptx/src/com/oracle/graal/asm/ptx/PTXAssembler.java	Mon Jan 20 16:33:40 2014 +0100
+++ b/graal/com.oracle.graal.asm.ptx/src/com/oracle/graal/asm/ptx/PTXAssembler.java	Mon Jan 20 18:25:17 2014 +0100
@@ -700,6 +700,9 @@
         bra(str);
     }
 
+    /**
+     * @param r
+     */
     public void nullCheck(Register r) {
         // setp(....);
     }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/PTXMethodInvalidation1Test.java	Mon Jan 20 18:25:17 2014 +0100
@@ -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.graal.compiler.ptx.test;
+
+import org.junit.*;
+
+import com.oracle.graal.api.code.*;
+import com.oracle.graal.api.meta.*;
+import com.oracle.graal.hotspot.meta.*;
+import com.oracle.graal.hotspot.ptx.*;
+
+/**
+ * Tests that a {@linkplain PTXWrapperBuilder PTX kernel wrapper} deoptimizes if the kernel is
+ * invalid.
+ */
+public class PTXMethodInvalidation1Test extends PTXTest {
+
+    @Test
+    public void test() {
+        test("testSnippet", 100);
+    }
+
+    @Override
+    protected HotSpotNmethod installKernel(ResolvedJavaMethod method, ExternalCompilationResult ptxCode) {
+        HotSpotNmethod ptxKernel = super.installKernel(method, ptxCode);
+        ptxKernel.invalidate();
+        return ptxKernel;
+    }
+
+    int f = 42;
+
+    public int testSnippet(int delta) {
+        return f + delta;
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/PTXMethodInvalidation2Test.java	Mon Jan 20 18:25:17 2014 +0100
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.oracle.graal.compiler.ptx.test;
+
+import org.junit.*;
+
+import com.oracle.graal.api.code.*;
+import com.oracle.graal.api.meta.*;
+import com.oracle.graal.hotspot.meta.*;
+import com.oracle.graal.hotspot.ptx.*;
+import com.oracle.graal.nodes.*;
+
+/**
+ * A full GC on HotSpot will unload an nmethod that has an embedded oop that is only referenced from
+ * the nmethod. The nmethod created for a {@linkplain PTXWrapperBuilder PTX kernel wrapper} has an
+ * embedded oop referring to the {@link HotSpotNmethod} linked with the nmethod for the installed
+ * PTX kernel. This embedded oop is a weak as described above sp there must be another strong
+ * reference from the wrapper to the {@link HotSpotNmethod} object.
+ */
+public class PTXMethodInvalidation2Test extends PTXTest {
+
+    @Test
+    public void test() {
+        test("testSnippet", 100);
+    }
+
+    @Override
+    @Ignore("still need to make a strong reference from a PTX wrapper to a PTX kernel")
+    protected InstalledCode getCode(ResolvedJavaMethod method, StructuredGraph graph) {
+        InstalledCode code = super.getCode(method, graph);
+
+        // This seems to result in a full GC on HotSpot but there's no guarantee of that
+        System.gc();
+
+        Assert.assertFalse(code.getStart() == 0L);
+        return code;
+    }
+
+    int f = 42;
+
+    public int testSnippet(int delta) {
+        return f + delta;
+    }
+}
--- a/graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/PTXTest.java	Mon Jan 20 16:33:40 2014 +0100
+++ b/graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/PTXTest.java	Mon Jan 20 18:25:17 2014 +0100
@@ -57,13 +57,18 @@
         return compileKernel(getMetaAccess().lookupJavaMethod(getMethod(test)));
     }
 
+    protected HotSpotNmethod installKernel(ResolvedJavaMethod method, ExternalCompilationResult ptxCode) {
+        PTXHotSpotBackend ptxBackend = getPTXBackend();
+        return ptxBackend.installKernel(method, ptxCode);
+    }
+
     @Override
     protected InstalledCode getCode(ResolvedJavaMethod method, StructuredGraph graph) {
         PTXHotSpotBackend ptxBackend = getPTXBackend();
         ExternalCompilationResult ptxCode = compileKernel(method);
         Assume.assumeTrue(ptxBackend.isDeviceInitialized());
-        InstalledCode installedPTXCode = ptxBackend.installKernel(method, ptxCode);
-        StructuredGraph wrapper = new PTXWrapperBuilder(method, installedPTXCode.getStart(), (HotSpotProviders) getProviders()).getGraph();
+        HotSpotNmethod installedPTXCode = installKernel(method, ptxCode);
+        StructuredGraph wrapper = new PTXWrapperBuilder(method, installedPTXCode, (HotSpotProviders) getProviders()).getGraph();
         return super.getCode(method, wrapper);
     }
 
--- a/graal/com.oracle.graal.hotspot.ptx/src/com/oracle/graal/hotspot/ptx/PTXHotSpotBackend.java	Mon Jan 20 16:33:40 2014 +0100
+++ b/graal/com.oracle.graal.hotspot.ptx/src/com/oracle/graal/hotspot/ptx/PTXHotSpotBackend.java	Mon Jan 20 18:25:17 2014 +0100
@@ -141,8 +141,8 @@
             public StructuredGraph getGraphFor(ResolvedJavaMethod method) {
                 if (canOffloadToGPU(method)) {
                     ExternalCompilationResult ptxCode = PTXHotSpotBackend.this.compileKernel(method, true);
-                    InstalledCode installedPTXCode = PTXHotSpotBackend.this.installKernel(method, ptxCode);
-                    return new PTXWrapperBuilder(method, installedPTXCode.getStart(), getRuntime().getHostBackend().getProviders()).getGraph();
+                    HotSpotNmethod installedPTXCode = PTXHotSpotBackend.this.installKernel(method, ptxCode);
+                    return new PTXWrapperBuilder(method, installedPTXCode, getRuntime().getHostBackend().getProviders()).getGraph();
                 }
                 return null;
             }
@@ -181,7 +181,7 @@
 
     }
 
-    public InstalledCode installKernel(ResolvedJavaMethod method, ExternalCompilationResult ptxCode) {
+    public HotSpotNmethod installKernel(ResolvedJavaMethod method, ExternalCompilationResult ptxCode) {
         assert ptxCode.getEntryPoint() != 0L;
         return getProviders().getCodeCache().addExternalMethod(method, ptxCode);
     }
--- a/graal/com.oracle.graal.hotspot.ptx/src/com/oracle/graal/hotspot/ptx/PTXWrapperBuilder.java	Mon Jan 20 16:33:40 2014 +0100
+++ b/graal/com.oracle.graal.hotspot.ptx/src/com/oracle/graal/hotspot/ptx/PTXWrapperBuilder.java	Mon Jan 20 18:25:17 2014 +0100
@@ -22,6 +22,7 @@
  */
 package com.oracle.graal.hotspot.ptx;
 
+import static com.oracle.graal.api.meta.DeoptimizationAction.*;
 import static com.oracle.graal.api.meta.DeoptimizationReason.*;
 import static com.oracle.graal.api.meta.LocationIdentity.*;
 import static com.oracle.graal.api.meta.MetaUtil.*;
@@ -97,9 +98,9 @@
      * Creates the graph implementing the CPU to GPU transition.
      * 
      * @param method a method that has been compiled to GPU binary code
-     * @param kernelAddress the entry point of the GPU binary for {@code kernelMethod}
+     * @param ptxInstalledCode the installed GPU binary for {@code method}
      */
-    public PTXWrapperBuilder(ResolvedJavaMethod method, long kernelAddress, HotSpotProviders providers) {
+    public PTXWrapperBuilder(ResolvedJavaMethod method, HotSpotNmethod ptxInstalledCode, HotSpotProviders providers) {
         super(new StructuredGraph(method), providers);
         int wordSize = providers.getCodeCache().getTarget().wordSize;
         Kind wordKind = providers.getCodeCache().getTarget().wordKind;
@@ -132,11 +133,13 @@
             }
         }
 
+        InvokeNode kernel = createInvoke(getClass(), "getKernelStart", ConstantNode.forObject(ptxInstalledCode, providers.getMetaAccess(), getGraph()));
+
         AllocaNode buf = append(new AllocaNode(bufSize / wordSize, objects));
 
         Map<LaunchArg, ValueNode> args = new EnumMap<>(LaunchArg.class);
         args.put(Thread, append(new ReadRegisterNode(providers.getRegisters().getThreadRegister(), true, false)));
-        args.put(Kernel, ConstantNode.forLong(kernelAddress, getGraph()));
+        args.put(Kernel, kernel);
         args.put(DimX, forInt(1, getGraph()));
         args.put(DimY, forInt(1, getGraph()));
         args.put(DimZ, forInt(1, getGraph()));
@@ -252,6 +255,19 @@
     }
 
     /**
+     * Snippet invoked to get the {@linkplain HotSpotNmethod#getStart() entry point} of the kernel,
+     * deoptimizing if the kernel is invalid.
+     */
+    @Snippet
+    private static long getKernelStart(HotSpotNmethod ptxKernel) {
+        long start = ptxKernel.getStart();
+        if (start == 0L) {
+            DeoptimizeNode.deopt(InvalidateRecompile, RuntimeConstraint);
+        }
+        return start;
+    }
+
+    /**
      * Snippet invoked upon return from the kernel to handle any pending exceptions.
      */
     @Snippet
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotCodeCacheProvider.java	Mon Jan 20 16:33:40 2014 +0100
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotCodeCacheProvider.java	Mon Jan 20 18:25:17 2014 +0100
@@ -190,16 +190,16 @@
         return installMethod(hotspotMethod, compResult);
     }
 
-    public InstalledCode addExternalMethod(ResolvedJavaMethod method, CompilationResult compResult) {
+    public HotSpotNmethod addExternalMethod(ResolvedJavaMethod method, CompilationResult compResult) {
         HotSpotResolvedJavaMethod javaMethod = (HotSpotResolvedJavaMethod) method;
-        HotSpotInstalledCode icode = new HotSpotNmethod(javaMethod, compResult.getName(), false, true);
+        HotSpotNmethod code = new HotSpotNmethod(javaMethod, compResult.getName(), false, true);
         HotSpotCompiledNmethod compiled = new HotSpotCompiledNmethod(target.arch, javaMethod, compResult);
         CompilerToVM vm = runtime.getCompilerToVM();
-        CodeInstallResult result = vm.installCode(compiled, icode, null);
+        CodeInstallResult result = vm.installCode(compiled, code, null);
         if (result != CodeInstallResult.OK) {
             return null;
         }
-        return icode;
+        return code;
     }
 
     public boolean needsDataPatch(Constant constant) {
--- a/mx/mx_graal.py	Mon Jan 20 16:33:40 2014 +0100
+++ b/mx/mx_graal.py	Mon Jan 20 18:25:17 2014 +0100
@@ -344,10 +344,10 @@
                     for line in releaseFileLines:
                         if line.startswith("SOURCE="):
                             try:
-                                sourceLine = line[0:-2] # remove last char
+                                sourceLine = line[0:-2]  # remove last char
                                 hgcfg = mx.HgConfig()
                                 hgcfg.check()
-                                revision = hgcfg.tip('.')[:12] # take first 12 chars
+                                revision = hgcfg.tip('.')[:12]  # take first 12 chars
                                 fp.write(sourceLine + ' graal:' + revision + '\"\n')
                             except:
                                 fp.write(line)
@@ -793,26 +793,29 @@
         if t.startswith('-'):
             mx.abort('VM option ' + t + ' must precede ' + tests[0])
 
-    candidates = []
+    candidates = {}
     for p in mx.projects_opt_limit_to_suites():
         if mx.java().javaCompliance < p.javaCompliance:
             continue
-        candidates += _find_classes_with_annotations(p, None, annotations).keys()
+        for c in _find_classes_with_annotations(p, None, annotations).keys():
+            candidates[c] = p
 
     classes = []
     if len(tests) == 0:
-        classes = candidates
+        classes = candidates.keys()
+        projectscp = mx.classpath([pcp.name for pcp in mx.projects_opt_limit_to_suites() if pcp.javaCompliance <= mx.java().javaCompliance])
     else:
+        projs = set()
         for t in tests:
             found = False
-            for c in candidates:
+            for c, p in candidates.iteritems():
                 if t in c:
                     found = True
                     classes.append(c)
+                    projs.add(p.name)
             if not found:
                 mx.log('warning: no tests matched by substring "' + t)
-
-    projectscp = mx.classpath([pcp.name for pcp in mx.projects_opt_limit_to_suites() if pcp.javaCompliance <= mx.java().javaCompliance])
+        projectscp = mx.classpath(projs)
 
     if len(classes) != 0:
         f_testfile = open(testfile, 'w')
@@ -1504,11 +1507,11 @@
     # gather graal options
     output = StringIO.StringIO()
     vm(['-XX:-BootstrapGraal', '-G:+PrintFlags' if optionType == "graal" else '-XX:+PrintFlagsWithComments'],
-       vm = "graal",
-       vmbuild = "optimized",
-       nonZeroIsFatal = False,
-       out = output.write,
-       err = subprocess.STDOUT)
+       vm="graal",
+       vmbuild="optimized",
+       nonZeroIsFatal=False,
+       out=output.write,
+       err=subprocess.STDOUT)
 
     valueMap = parser.parse(output.getvalue())
     return valueMap
--- a/src/share/tools/IdealGraphVisualizer/Bytecodes/src/com/sun/hotspot/igv/bytecodes/BytecodeViewTopComponent.java	Mon Jan 20 16:33:40 2014 +0100
+++ b/src/share/tools/IdealGraphVisualizer/Bytecodes/src/com/sun/hotspot/igv/bytecodes/BytecodeViewTopComponent.java	Mon Jan 20 18:25:17 2014 +0100
@@ -179,9 +179,13 @@
                     if (graph != null) {
                         Group g = graph.getGroup();
                         rootNode.update(graph, g.getMethod());
+                    } else {
+                        rootNode.update(null, null);
                     }
                 }
             });
+        } else {
+            rootNode.update(null, null);
         }
     }
 
--- a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/DiagramViewModel.java	Mon Jan 20 16:33:40 2014 +0100
+++ b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/DiagramViewModel.java	Mon Jan 20 18:25:17 2014 +0100
@@ -389,4 +389,9 @@
         }
         this.setSelectedNodes(newSelectedNodes);
     }
+
+    void close() {
+        filterChain.getChangedEvent().removeListener(filterChainChangedListener);
+        sequenceFilterChain.getChangedEvent().removeListener(filterChainChangedListener);
 }
+}
--- a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/EditorTopComponent.java	Mon Jan 20 16:33:40 2014 +0100
+++ b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/EditorTopComponent.java	Mon Jan 20 18:25:17 2014 +0100
@@ -408,6 +408,7 @@
 
     @Override
     public void componentClosed() {
+        rangeSliderModel.close();
     }
 
     @Override
@@ -580,4 +581,8 @@
         return scene.getUndoRedo();
     }
 
+    @Override
+    protected Object writeReplace() throws ObjectStreamException {
+        throw new NotSerializableException();
 }
+}
--- a/src/share/vm/graal/graalCompilerToVM.cpp	Mon Jan 20 16:33:40 2014 +0100
+++ b/src/share/vm/graal/graalCompilerToVM.cpp	Mon Jan 20 18:25:17 2014 +0100
@@ -688,6 +688,9 @@
   HandleMark hm;
 
   jlong nmethodValue = HotSpotInstalledCode::codeBlob(hotspotInstalledCode);
+  if (nmethodValue == 0L) {
+    THROW_(vmSymbols::com_oracle_graal_api_code_InvalidInstalledCodeException(), NULL);
+  }
   nmethod* nm = (nmethod*) (address) nmethodValue;
   methodHandle mh = nm->method();
   Symbol* signature = mh->signature();