< prev index next >

src/jdk.aot/share/classes/jdk.tools.jaotc/src/jdk/tools/jaotc/Collector.java

Print this page
rev 56282 : [mq]: graal
   1 /*
   2  * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 
  25 
  26 package jdk.tools.jaotc;
  27 
  28 import java.io.BufferedReader;
  29 import java.io.FileNotFoundException;
  30 import java.io.FileReader;
  31 import java.io.IOException;
  32 import java.util.ArrayList;
  33 import java.util.HashSet;
  34 import java.util.List;
  35 import java.util.Set;
  36 
  37 import jdk.tools.jaotc.collect.ClassSearch;
  38 import jdk.tools.jaotc.collect.FileSupport;
  39 import jdk.tools.jaotc.collect.classname.ClassNameSourceProvider;
  40 import jdk.tools.jaotc.collect.directory.DirectorySourceProvider;
  41 import jdk.tools.jaotc.collect.jar.JarSourceProvider;
  42 import jdk.tools.jaotc.collect.module.ModuleSourceProvider;

  43 import jdk.vm.ci.meta.MetaAccessProvider;
  44 import jdk.vm.ci.meta.ResolvedJavaMethod;
  45 import jdk.vm.ci.meta.ResolvedJavaType;
  46 
  47 final class Collector {
  48 
  49     private final Main main;
  50 
  51     Collector(Main main) {
  52         this.main = main;
  53     }
  54 
  55     Set<Class<?>> collectClassesToCompile() {
  56         Set<Class<?>> classesToCompile = new HashSet<>();
  57         FileSupport fileSupport = new FileSupport();
  58         ClassSearch lookup = new ClassSearch();
  59         lookup.addProvider(new ModuleSourceProvider());
  60         lookup.addProvider(new ClassNameSourceProvider(fileSupport));
  61         lookup.addProvider(new JarSourceProvider());
  62         lookup.addProvider(new DirectorySourceProvider(fileSupport));


  75         return classesToCompile;
  76     }
  77 
  78     private void addMethods(AOTCompiledClass aotClass, ResolvedJavaMethod[] methods, CompilationSpec compilationRestrictions) {
  79         for (ResolvedJavaMethod m : methods) {
  80             addMethod(aotClass, m, compilationRestrictions);
  81         }
  82     }
  83 
  84     private void addMethod(AOTCompiledClass aotClass, ResolvedJavaMethod method, CompilationSpec compilationRestrictions) {
  85         // Don't compile native or abstract methods.
  86         if (!method.hasBytecodes()) {
  87             return;
  88         }
  89         if (!compilationRestrictions.shouldCompileMethod(method)) {
  90             return;
  91         }
  92         if (!main.filters.shouldCompileMethod(method)) {
  93             return;
  94         }

  95 
  96         aotClass.addMethod(method);
  97         main.printer.printlnVerbose("  added " + method.getName() + method.getSignature().toMethodDescriptor());
  98     }
  99 
 100     /**
 101      * Collect all method we should compile.
 102      *
 103      * @return array list of AOT classes which have compiled methods.
 104      */
 105     List<AOTCompiledClass> collectMethodsToCompile(Set<Class<?>> classesToCompile, MetaAccessProvider metaAccess) {
 106         int total = 0;
 107         int count = 0;
 108         List<AOTCompiledClass> classes = new ArrayList<>();
 109         CompilationSpec compilationRestrictions = collectSpecifiedMethods();
 110 
 111         for (Class<?> c : classesToCompile) {
 112             ResolvedJavaType resolvedJavaType = metaAccess.lookupJavaType(c);
 113             if (main.filters.shouldCompileAnyMethodInClass(resolvedJavaType)) {
 114                 AOTCompiledClass aotClass = new AOTCompiledClass(resolvedJavaType);


   1 /*
   2  * Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 
  25 
  26 package jdk.tools.jaotc;
  27 
  28 import java.io.BufferedReader;
  29 import java.io.FileNotFoundException;
  30 import java.io.FileReader;
  31 import java.io.IOException;
  32 import java.util.ArrayList;
  33 import java.util.HashSet;
  34 import java.util.List;
  35 import java.util.Set;
  36 
  37 import jdk.tools.jaotc.collect.ClassSearch;
  38 import jdk.tools.jaotc.collect.FileSupport;
  39 import jdk.tools.jaotc.collect.classname.ClassNameSourceProvider;
  40 import jdk.tools.jaotc.collect.directory.DirectorySourceProvider;
  41 import jdk.tools.jaotc.collect.jar.JarSourceProvider;
  42 import jdk.tools.jaotc.collect.module.ModuleSourceProvider;
  43 import jdk.vm.ci.hotspot.HotSpotResolvedObjectType;
  44 import jdk.vm.ci.meta.MetaAccessProvider;
  45 import jdk.vm.ci.meta.ResolvedJavaMethod;
  46 import jdk.vm.ci.meta.ResolvedJavaType;
  47 
  48 final class Collector {
  49 
  50     private final Main main;
  51 
  52     Collector(Main main) {
  53         this.main = main;
  54     }
  55 
  56     Set<Class<?>> collectClassesToCompile() {
  57         Set<Class<?>> classesToCompile = new HashSet<>();
  58         FileSupport fileSupport = new FileSupport();
  59         ClassSearch lookup = new ClassSearch();
  60         lookup.addProvider(new ModuleSourceProvider());
  61         lookup.addProvider(new ClassNameSourceProvider(fileSupport));
  62         lookup.addProvider(new JarSourceProvider());
  63         lookup.addProvider(new DirectorySourceProvider(fileSupport));


  76         return classesToCompile;
  77     }
  78 
  79     private void addMethods(AOTCompiledClass aotClass, ResolvedJavaMethod[] methods, CompilationSpec compilationRestrictions) {
  80         for (ResolvedJavaMethod m : methods) {
  81             addMethod(aotClass, m, compilationRestrictions);
  82         }
  83     }
  84 
  85     private void addMethod(AOTCompiledClass aotClass, ResolvedJavaMethod method, CompilationSpec compilationRestrictions) {
  86         // Don't compile native or abstract methods.
  87         if (!method.hasBytecodes()) {
  88             return;
  89         }
  90         if (!compilationRestrictions.shouldCompileMethod(method)) {
  91             return;
  92         }
  93         if (!main.filters.shouldCompileMethod(method)) {
  94             return;
  95         }
  96         assert ((HotSpotResolvedObjectType) method.getDeclaringClass()).getFingerprint() != 0 : "no fingerprint for " + method.getDeclaringClass().getName();
  97 
  98         aotClass.addMethod(method);
  99         main.printer.printlnVerbose("  added " + method.getName() + method.getSignature().toMethodDescriptor());
 100     }
 101 
 102     /**
 103      * Collect all method we should compile.
 104      *
 105      * @return array list of AOT classes which have compiled methods.
 106      */
 107     List<AOTCompiledClass> collectMethodsToCompile(Set<Class<?>> classesToCompile, MetaAccessProvider metaAccess) {
 108         int total = 0;
 109         int count = 0;
 110         List<AOTCompiledClass> classes = new ArrayList<>();
 111         CompilationSpec compilationRestrictions = collectSpecifiedMethods();
 112 
 113         for (Class<?> c : classesToCompile) {
 114             ResolvedJavaType resolvedJavaType = metaAccess.lookupJavaType(c);
 115             if (main.filters.shouldCompileAnyMethodInClass(resolvedJavaType)) {
 116                 AOTCompiledClass aotClass = new AOTCompiledClass(resolvedJavaType);


< prev index next >