changeset 9148:b67a0963fb00

Merge.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Tue, 16 Apr 2013 16:07:27 +0200
parents 07f05f2a8149 (current diff) 57f85e39c75f (diff)
children 85b71f453ef5
files graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/PartialCanonicalizerPhase.java
diffstat 7 files changed, 84 insertions(+), 110 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalCompiler.java	Tue Apr 16 16:07:16 2013 +0200
+++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalCompiler.java	Tue Apr 16 16:07:27 2013 +0200
@@ -139,12 +139,12 @@
 
         plan.runPhases(PhasePosition.HIGH_LEVEL, graph);
 
-        Suites.DEFAULT.highTier.apply(graph, highTierContext);
+        Suites.DEFAULT.getHighTier().apply(graph, highTierContext);
 
         new LoweringPhase(target, runtime, replacements, assumptions).apply(graph);
 
         MidTierContext midTierContext = new MidTierContext(runtime, assumptions);
-        Suites.DEFAULT.midTier.apply(graph, midTierContext);
+        Suites.DEFAULT.getMidTier().apply(graph, midTierContext);
 
         plan.runPhases(PhasePosition.MID_LEVEL, graph);
 
--- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/MidTier.java	Tue Apr 16 16:07:16 2013 +0200
+++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/MidTier.java	Tue Apr 16 16:07:27 2013 +0200
@@ -37,7 +37,7 @@
         }
 
         if (GraalOptions.OptFloatingReads) {
-            PartialCanonicalizerPhase<MidTierContext> canonicalizer = new PartialCanonicalizerPhase<>();
+            IncrementalCanonicalizerPhase<MidTierContext> canonicalizer = new IncrementalCanonicalizerPhase<>();
             canonicalizer.addPhase(new FloatingReadPhase());
             addPhase(canonicalizer);
             if (GraalOptions.OptReadElimination) {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/IncrementalCanonicalizerPhase.java	Tue Apr 16 16:07:27 2013 +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.graal.phases.common;
+
+import com.oracle.graal.nodes.*;
+import com.oracle.graal.phases.*;
+import com.oracle.graal.phases.common.CanonicalizerPhase.CustomCanonicalizer;
+import com.oracle.graal.phases.tiers.*;
+
+public class IncrementalCanonicalizerPhase<C extends PhaseContext> extends PhaseSuite<C> {
+
+    private final CustomCanonicalizer customCanonicalizer;
+
+    public IncrementalCanonicalizerPhase() {
+        this(null);
+    }
+
+    public IncrementalCanonicalizerPhase(CustomCanonicalizer customCanonicalizer) {
+        this.customCanonicalizer = customCanonicalizer;
+    }
+
+    @Override
+    protected void run(StructuredGraph graph, C context) {
+        int mark = graph.getMark();
+        super.run(graph, context);
+        new CanonicalizerPhase.Instance(context.getRuntime(), context.getAssumptions(), mark, customCanonicalizer).apply(graph);
+    }
+}
--- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/PartialCanonicalizerPhase.java	Tue Apr 16 16:07:16 2013 +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.graal.phases.common;
-
-import com.oracle.graal.nodes.*;
-import com.oracle.graal.phases.*;
-import com.oracle.graal.phases.common.CanonicalizerPhase.CustomCanonicalizer;
-import com.oracle.graal.phases.tiers.*;
-
-public class PartialCanonicalizerPhase<C extends PhaseContext> extends PhaseSuite<C> {
-
-    private final CustomCanonicalizer customCanonicalizer;
-
-    public PartialCanonicalizerPhase() {
-        this(null);
-    }
-
-    public PartialCanonicalizerPhase(CustomCanonicalizer customCanonicalizer) {
-        this.customCanonicalizer = customCanonicalizer;
-    }
-
-    @Override
-    protected void run(StructuredGraph graph, C context) {
-        int mark = graph.getMark();
-        super.run(graph, context);
-        new CanonicalizerPhase.Instance(context.getRuntime(), context.getAssumptions(), mark, customCanonicalizer).apply(graph);
-    }
-}
--- a/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/tiers/Suites.java	Tue Apr 16 16:07:16 2013 +0200
+++ b/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/tiers/Suites.java	Tue Apr 16 16:07:27 2013 +0200
@@ -29,13 +29,21 @@
 
 public final class Suites {
 
-    public final PhaseSuite<HighTierContext> highTier;
-    public final PhaseSuite<MidTierContext> midTier;
-
     public static final Suites DEFAULT;
 
+    private final PhaseSuite<HighTierContext> highTier;
+    private final PhaseSuite<MidTierContext> midTier;
+
     private static final Map<String, CompilerConfiguration> configurations;
 
+    public PhaseSuite<HighTierContext> getHighTier() {
+        return highTier;
+    }
+
+    public PhaseSuite<MidTierContext> getMidTier() {
+        return midTier;
+    }
+
     static {
         configurations = new HashMap<>();
         for (CompilerConfiguration config : ServiceLoader.loadInstalled(CompilerConfiguration.class)) {
--- a/graal/com.oracle.graal.service.processor/src/com/oracle/graal/service/processor/ServiceProviderProcessor.java	Tue Apr 16 16:07:16 2013 +0200
+++ b/graal/com.oracle.graal.service.processor/src/com/oracle/graal/service/processor/ServiceProviderProcessor.java	Tue Apr 16 16:07:27 2013 +0200
@@ -29,7 +29,6 @@
 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.*;
 
@@ -39,38 +38,7 @@
 @SupportedAnnotationTypes("com.oracle.graal.api.runtime.ServiceProvider")
 public class ServiceProviderProcessor extends AbstractProcessor {
 
-    private Map<String, Set<TypeElement>> serviceMap;
-
-    public ServiceProviderProcessor() {
-        serviceMap = new HashMap<>();
-    }
-
-    private void addProvider(String serviceName, TypeElement serviceProvider) {
-        Set<TypeElement> providers = serviceMap.get(serviceName);
-        if (providers == null) {
-            providers = new HashSet<>();
-            serviceMap.put(serviceName, providers);
-        }
-        providers.add(serviceProvider);
-    }
-
-    private void generateServicesFiles() {
-        Filer filer = processingEnv.getFiler();
-        for (Map.Entry<String, Set<TypeElement>> entry : serviceMap.entrySet()) {
-            String filename = "META-INF/services/" + entry.getKey();
-            TypeElement[] providers = entry.getValue().toArray(new TypeElement[0]);
-            try {
-                FileObject servicesFile = filer.createResource(StandardLocation.CLASS_OUTPUT, "", filename, providers);
-                PrintWriter writer = new PrintWriter(new OutputStreamWriter(servicesFile.openOutputStream(), "UTF-8"));
-                for (TypeElement provider : providers) {
-                    writer.println(provider.getQualifiedName());
-                }
-                writer.close();
-            } catch (IOException e) {
-                processingEnv.getMessager().printMessage(Kind.ERROR, e.getMessage());
-            }
-        }
-    }
+    private final Set<TypeElement> processed = new HashSet<>();
 
     private boolean verifyAnnotation(TypeMirror serviceInterface, TypeElement serviceProvider) {
         if (!processingEnv.getTypeUtils().isSubtype(serviceProvider.asType(), serviceInterface)) {
@@ -83,6 +51,11 @@
     }
 
     private void processElement(TypeElement serviceProvider) {
+        if (processed.contains(serviceProvider)) {
+            return;
+        }
+
+        processed.add(serviceProvider);
         ServiceProvider annotation = serviceProvider.getAnnotation(ServiceProvider.class);
         if (annotation != null) {
             try {
@@ -91,40 +64,27 @@
                 TypeMirror serviceInterface = ex.getTypeMirror();
                 if (verifyAnnotation(serviceInterface, serviceProvider)) {
                     String interfaceName = ex.getTypeMirror().toString();
-                    addProvider(interfaceName, serviceProvider);
+                    createProviderFile(serviceProvider, interfaceName);
                 }
             }
         }
     }
 
-    private void processOldElements() {
-        Filer filer = processingEnv.getFiler();
-        Elements elements = processingEnv.getElementUtils();
-        for (String key : serviceMap.keySet()) {
-            String filename = "META-INF/services/" + key;
-            try {
-                FileObject servicesFile = filer.getResource(StandardLocation.CLASS_OUTPUT, "", filename);
-                BufferedReader reader = new BufferedReader(new InputStreamReader(servicesFile.openInputStream(), "UTF-8"));
-                String line;
-                while ((line = reader.readLine()) != null) {
-                    TypeElement serviceProvider = elements.getTypeElement(line);
-                    if (serviceProvider != null) {
-                        processElement(serviceProvider);
-                    }
-                }
-                reader.close();
-                servicesFile.delete();
-            } catch (IOException e) {
-                // old services file not found: do nothing
-            }
+    private void createProviderFile(TypeElement serviceProvider, String interfaceName) {
+        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<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
         if (roundEnv.processingOver()) {
-            processOldElements();
-            generateServicesFiles();
             return true;
         }
 
--- a/mxtool/mx.py	Tue Apr 16 16:07:16 2013 +0200
+++ b/mxtool/mx.py	Tue Apr 16 16:07:27 2013 +0200
@@ -1684,6 +1684,12 @@
                                     with open(join(root, f), 'r') as infile:
                                         for line in infile:
                                             outfile.write(line)
+                        elif relpath == join('META-INF', 'providers'):
+                            for f in files:
+                                with open(join(root, f), 'r') as infile:
+                                    for line in infile:
+                                        with open(join(services, line.strip()), 'a') as outfile:
+                                            outfile.write(f + '\n')
                         else:
                             for f in files:
                                 arcname = join(relpath, f).replace(os.sep, '/')