asterixdb-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Dmitry Lychagin (Code Review)" <do-not-re...@asterixdb.incubator.apache.org>
Subject Change in asterixdb[master]: [ASTERIXDB-1976][FUN] Invoke code generation from asterix-ru...
Date Fri, 07 Jul 2017 00:39:19 GMT
Dmitry Lychagin has submitted this change and it was merged.

Change subject: [ASTERIXDB-1976][FUN] Invoke code generation from asterix-runtime module
......................................................................


[ASTERIXDB-1976][FUN] Invoke code generation from asterix-runtime module

- user model changes: no
- storage format changes: no
- interface changes: no

Details:
- Invoke function code generation from asterix-runtime module
  instead of asterix-algebra module

Change-Id: I2bb9a2cef1d346242c65d76378fbbf0e18a94bfe
Reviewed-on: https://asterix-gerrit.ics.uci.edu/1870
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
BAD: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Yingyi Bu <buyingyi@gmail.com>
---
M asterixdb/asterix-algebra/pom.xml
M asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/util/FunctionCollection.java
A asterixdb/asterix-common/src/main/java/org/apache/asterix/common/utils/CodeGenHelper.java
M asterixdb/asterix-maven-plugins/asterix-evaluator-generator-maven-plugin/pom.xml
M asterixdb/asterix-maven-plugins/asterix-evaluator-generator-maven-plugin/src/main/java/org/apache/asterix/runtime/evaluators/plugin/EvaluatorGeneratorMojo.java
R asterixdb/asterix-maven-plugins/asterix-evaluator-generator-maven-plugin/src/main/java/org/apache/asterix/runtime/evaluators/staticcodegen/CodeGenUtil.java
R asterixdb/asterix-maven-plugins/asterix-evaluator-generator-maven-plugin/src/main/java/org/apache/asterix/runtime/evaluators/staticcodegen/EvaluatorMissingCheckVisitor.java
R asterixdb/asterix-maven-plugins/asterix-evaluator-generator-maven-plugin/src/main/java/org/apache/asterix/runtime/evaluators/staticcodegen/EvaluatorNullCheckVisitor.java
R asterixdb/asterix-maven-plugins/asterix-evaluator-generator-maven-plugin/src/main/java/org/apache/asterix/runtime/evaluators/staticcodegen/GatherEvaluatorCreationVisitor.java
R asterixdb/asterix-maven-plugins/asterix-evaluator-generator-maven-plugin/src/main/java/org/apache/asterix/runtime/evaluators/staticcodegen/GatherEvaluatorFactoryCreationVisitor.java
R asterixdb/asterix-maven-plugins/asterix-evaluator-generator-maven-plugin/src/main/java/org/apache/asterix/runtime/evaluators/staticcodegen/GatherInnerClassVisitor.java
R asterixdb/asterix-maven-plugins/asterix-evaluator-generator-maven-plugin/src/main/java/org/apache/asterix/runtime/evaluators/staticcodegen/MethodIdentifier.java
R asterixdb/asterix-maven-plugins/asterix-evaluator-generator-maven-plugin/src/main/java/org/apache/asterix/runtime/evaluators/staticcodegen/RenameClassVisitor.java
M asterixdb/asterix-runtime/pom.xml
14 files changed, 250 insertions(+), 168 deletions(-)

Approvals:
  Yingyi Bu: Looks good to me, approved
  Jenkins: Verified; No violations found; Verified

Objections:
  Jenkins: Violations found



diff --git a/asterixdb/asterix-algebra/pom.xml b/asterixdb/asterix-algebra/pom.xml
index 04f8d63..2cc9075 100644
--- a/asterixdb/asterix-algebra/pom.xml
+++ b/asterixdb/asterix-algebra/pom.xml
@@ -97,23 +97,6 @@
           </execution>
         </executions>
       </plugin>
-      <plugin>
-        <groupId>org.apache.asterix</groupId>
-        <artifactId>asterix-evaluator-generator-maven-plugin</artifactId>
-        <version>${project.version}</version>
-        <configuration>
-          <evaluatorPackagePrefix>org.apache.asterix.runtime.evaluators</evaluatorPackagePrefix>
-        </configuration>
-        <executions>
-          <execution>
-            <id>generate-evaluator</id>
-            <phase>compile</phase>
-            <goals>
-              <goal>generate-evaluator</goal>
-            </goals>
-          </execution>
-        </executions>
-      </plugin>
     </plugins>
     <pluginManagement>
       <plugins>
@@ -129,19 +112,6 @@
                     <groupId>org.codehaus.mojo</groupId>
                     <artifactId>javacc-maven-plugin</artifactId>
                     <versionRange>[2.6,)</versionRange>
-                    <goals>
-                      <goal>javacc</goal>
-                    </goals>
-                  </pluginExecutionFilter>
-                  <action>
-                    <ignore />
-                  </action>
-                </pluginExecution>
-                <pluginExecution>
-                  <pluginExecutionFilter>
-                    <groupId>org.apache.asterix</groupId>
-                    <artifactId>asterix-evaluator-generator-maven-plugin</artifactId>
-                    <versionRange>(0.8.8-incubating,)</versionRange>
                     <goals>
                       <goal>javacc</goal>
                     </goals>
@@ -220,10 +190,6 @@
     </dependency>
     <dependency>
       <groupId>org.apache.hyracks</groupId>
-      <artifactId>hyracks-util</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.hyracks</groupId>
       <artifactId>hyracks-dataflow-common</artifactId>
     </dependency>
     <dependency>
@@ -260,11 +226,6 @@
     <dependency>
       <groupId>org.apache.hyracks</groupId>
       <artifactId>hyracks-dataflow-std</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.asterix</groupId>
-      <artifactId>asterix-fuzzyjoin</artifactId>
-      <version>${project.version}</version>
     </dependency>
     <dependency>
       <groupId>org.apache.hyracks</groupId>
diff --git a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/util/FunctionCollection.java
b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/util/FunctionCollection.java
index 92ca977..fa67e25 100644
--- a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/util/FunctionCollection.java
+++ b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/util/FunctionCollection.java
@@ -23,6 +23,7 @@
 import java.util.ArrayList;
 import java.util.List;
 
+import org.apache.asterix.common.utils.CodeGenHelper;
 import org.apache.asterix.om.functions.IFunctionDescriptorFactory;
 import org.apache.asterix.runtime.aggregates.collections.FirstElementAggregateDescriptor;
 import org.apache.asterix.runtime.aggregates.collections.ListifyAggregateDescriptor;
@@ -324,7 +325,6 @@
 import org.apache.asterix.runtime.evaluators.functions.temporal.UnixTimeFromTimeInMsDescriptor;
 import org.apache.asterix.runtime.evaluators.functions.temporal.YearMonthDurationGreaterThanComparatorDescriptor;
 import org.apache.asterix.runtime.evaluators.functions.temporal.YearMonthDurationLessThanComparatorDescriptor;
-import org.apache.asterix.runtime.evaluators.staticcodegen.CodeGenUtil;
 import org.apache.asterix.runtime.runningaggregates.std.TidRunningAggregateDescriptor;
 import org.apache.asterix.runtime.unnestingfunctions.std.RangeDescriptor;
 import org.apache.asterix.runtime.unnestingfunctions.std.ScanCollectionDescriptor;
@@ -731,8 +731,8 @@
      */
     private static IFunctionDescriptorFactory getGeneratedFunctionDescriptorFactory(Class<?>
cl) {
         try {
-            String className = CodeGenUtil.getGeneratedFunctionDescriptorClassName(cl.getName(),
-                    CodeGenUtil.DEFAULT_SUFFIX_FOR_GENERATED_CLASS);
+            String className = CodeGenHelper.getGeneratedClassName(cl.getName(),
+                    CodeGenHelper.DEFAULT_SUFFIX_FOR_GENERATED_CLASS);
             Class<?> generatedCl = cl.getClassLoader().loadClass(className);
             Field factory = generatedCl.getDeclaredField(FACTORY);
             return (IFunctionDescriptorFactory) factory.get(null);
diff --git a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/utils/CodeGenHelper.java
b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/utils/CodeGenHelper.java
new file mode 100644
index 0000000..b8397f2
--- /dev/null
+++ b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/utils/CodeGenHelper.java
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.asterix.common.utils;
+
+public final class CodeGenHelper {
+
+    public final static String DEFAULT_SUFFIX_FOR_GENERATED_CLASS = "Gen";
+
+    private final static String DOLLAR = "$";
+
+    private final static String NESTED_CLASSNAME_PREFIX = "_";
+
+    public static String getGeneratedClassName(String originalClassName, String suffixForGeneratedClass)
{
+        return toJdkStandardName(getGeneratedInternalClassName(originalClassName, suffixForGeneratedClass));
+    }
+
+    public static String getGeneratedInternalClassName(String originalClassName, String suffixForGeneratedClass)
{
+        String originalFuncDescriptorClassInternalName = toInternalClassName(originalClassName);
+        return generateClassName(originalFuncDescriptorClassInternalName, suffixForGeneratedClass,
0);
+    }
+
+    /**
+     * Gets the name of a generated class.
+     *
+     * @param originalClassName,
+     *            the original class, i.e., the source of the generated class.
+     * @param suffix,
+     *            the suffix for the generated class.
+     * @param counter,
+     *            a counter that appearing at the end of the name of the generated class.
+     * @return the name of the generated class.
+     */
+    public static String generateClassName(String originalClassName, String suffix, int counter)
{
+        StringBuilder sb = new StringBuilder();
+        int end = originalClassName.indexOf(DOLLAR);
+        if (end < 0) {
+            end = originalClassName.length();
+        }
+
+        String name = originalClassName.substring(0, end);
+        sb.append(name);
+        sb.append(DOLLAR);
+        sb.append(NESTED_CLASSNAME_PREFIX);
+        sb.append(suffix);
+
+        if (counter > 0) {
+            sb.append(counter);
+        }
+        return sb.toString();
+    }
+
+    /**
+     * Converts an ASM class name to the JDK class naming format.
+     *
+     * @param name,
+     *            a class name following the ASM convention.
+     * @return a "."-separated class name for JDK.
+     */
+    public static String toJdkStandardName(String name) {
+        return name.replace("/", ".");
+    }
+
+    /**
+     * Converts a JDK class name to the class naming format of ASM.
+     *
+     * @param name,
+     *            a class name following the JDK convention.
+     * @return a "/"-separated class name assumed by ASM.
+     */
+    public static String toInternalClassName(String name) {
+        return name.replace(".", "/");
+    }
+
+    private CodeGenHelper() {
+    }
+}
diff --git a/asterixdb/asterix-maven-plugins/asterix-evaluator-generator-maven-plugin/pom.xml
b/asterixdb/asterix-maven-plugins/asterix-evaluator-generator-maven-plugin/pom.xml
index a8ada2c..77ceb83 100644
--- a/asterixdb/asterix-maven-plugins/asterix-evaluator-generator-maven-plugin/pom.xml
+++ b/asterixdb/asterix-maven-plugins/asterix-evaluator-generator-maven-plugin/pom.xml
@@ -32,13 +32,30 @@
   <properties>
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
   </properties>
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-dependency-plugin</artifactId>
+        <version>2.10</version>
+        <configuration>
+          <ignoredUnusedDeclaredDependencies combine.children="append">
+            <ignoredUnusedDeclaredDependency>org.apache.asterix:asterix-om:*</ignoredUnusedDeclaredDependency>
+          </ignoredUnusedDeclaredDependencies>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
   <dependencies>
     <dependency>
       <groupId>org.apache.asterix</groupId>
-      <artifactId>asterix-runtime</artifactId>
-      <type>jar</type>
+      <artifactId>asterix-common</artifactId>
       <version>${project.version}</version>
-      <scope>compile</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.asterix</groupId>
+      <artifactId>asterix-om</artifactId>
+      <version>${project.version}</version>
     </dependency>
     <dependency>
       <groupId>org.apache.maven</groupId>
@@ -59,5 +76,15 @@
       <artifactId>maven-model</artifactId>
       <version>3.3.9</version>
     </dependency>
+    <dependency>
+      <groupId>org.apache.commons</groupId>
+      <artifactId>commons-lang3</artifactId>
+      <version>3.5</version>
+    </dependency>
+    <dependency>
+      <groupId>org.ow2.asm</groupId>
+      <artifactId>asm-all</artifactId>
+      <version>5.1</version>
+    </dependency>
   </dependencies>
 </project>
diff --git a/asterixdb/asterix-maven-plugins/asterix-evaluator-generator-maven-plugin/src/main/java/org/apache/asterix/runtime/evaluators/plugin/EvaluatorGeneratorMojo.java
b/asterixdb/asterix-maven-plugins/asterix-evaluator-generator-maven-plugin/src/main/java/org/apache/asterix/runtime/evaluators/plugin/EvaluatorGeneratorMojo.java
index 888df55..74084af 100644
--- a/asterixdb/asterix-maven-plugins/asterix-evaluator-generator-maven-plugin/src/main/java/org/apache/asterix/runtime/evaluators/plugin/EvaluatorGeneratorMojo.java
+++ b/asterixdb/asterix-maven-plugins/asterix-evaluator-generator-maven-plugin/src/main/java/org/apache/asterix/runtime/evaluators/plugin/EvaluatorGeneratorMojo.java
@@ -22,21 +22,25 @@
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
+import java.net.URI;
+import java.net.URL;
+import java.net.URLClassLoader;
 import java.util.Set;
 
-import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
+import org.apache.asterix.common.utils.CodeGenHelper;
 import org.apache.asterix.runtime.evaluators.staticcodegen.CodeGenUtil;
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
 import org.apache.maven.project.MavenProject;
 import org.reflections.Reflections;
+import org.reflections.util.ConfigurationBuilder;
 
 /**
  * Statically generates null-handling byte code for scalar functions.
  *
  * @goal generate-evaluator
- * @phase compile
+ * @phase process-classes
  */
 public class EvaluatorGeneratorMojo extends AbstractMojo {
 
@@ -62,23 +66,41 @@
     @Override
     public void execute() throws MojoExecutionException, MojoFailureException {
         baseDir = project.getBuild().getDirectory() + File.separator + "classes";
-        try {
-            // Finds all sub-classes of AbstractScalarFunctionDynamicDescriptor with in the
package
-            // org.apache.asterix.runtime.evaluators.
-            Reflections reflections = new Reflections(evaluatorPackagePrefix);
-            Set<Class<? extends AbstractScalarFunctionDynamicDescriptor>> allClasses
= reflections
-                    .getSubTypesOf(AbstractScalarFunctionDynamicDescriptor.class);
 
-            // Generates byte code for all sub-classes of AbstractScalarFunctionDynamicDescriptor.
+        URLClassLoader classLoader = null;
+        try {
+            URI baseURI = new File(baseDir).toURI();
+            classLoader = new URLClassLoader(new URL[] { baseURI.toURL() }, getClass().getClassLoader());
+
+            String superClassName = CodeGenHelper.toJdkStandardName(CodeGenUtil.DESCRIPTOR_SUPER_CLASS_NAME);
+            Class superClass = Class.forName(superClassName, false, classLoader);
+
+            // Finds all sub-classes of the given root class within the specified package
+            ConfigurationBuilder config = ConfigurationBuilder.build(classLoader, evaluatorPackagePrefix);
+            String genSuffix = CodeGenHelper.DEFAULT_SUFFIX_FOR_GENERATED_CLASS + ".class";
+            config.setInputsFilter(path -> path != null && !path.endsWith(genSuffix));
+
+            Reflections reflections = new Reflections(config);
+            Set<Class<?>> allClasses = reflections.getSubTypesOf(superClass);
+
+            // Generates byte code for all sub-classes
             for (Class<?> cl : allClasses) {
                 getLog().info("Generating byte code for " + cl.getName());
                 CodeGenUtil.generateScalarFunctionDescriptorBinary(evaluatorPackagePrefix,
cl.getName(),
-                        CodeGenUtil.DEFAULT_SUFFIX_FOR_GENERATED_CLASS, reflections.getClass().getClassLoader(),
+                        CodeGenHelper.DEFAULT_SUFFIX_FOR_GENERATED_CLASS, classLoader,
                         (name, bytes) -> writeFile(name, bytes));
             }
         } catch (Exception e) {
             getLog().error(e);
             throw new MojoFailureException(e.toString());
+        } finally {
+            if (classLoader != null) {
+                try {
+                    classLoader.close();
+                } catch (IOException e) {
+                    getLog().error(e);
+                }
+            }
         }
     }
 
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/staticcodegen/CodeGenUtil.java
b/asterixdb/asterix-maven-plugins/asterix-evaluator-generator-maven-plugin/src/main/java/org/apache/asterix/runtime/evaluators/staticcodegen/CodeGenUtil.java
similarity index 71%
rename from asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/staticcodegen/CodeGenUtil.java
rename to asterixdb/asterix-maven-plugins/asterix-evaluator-generator-maven-plugin/src/main/java/org/apache/asterix/runtime/evaluators/staticcodegen/CodeGenUtil.java
index 87a9a84..6d3feb7 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/staticcodegen/CodeGenUtil.java
+++ b/asterixdb/asterix-maven-plugins/asterix-evaluator-generator-maven-plugin/src/main/java/org/apache/asterix/runtime/evaluators/staticcodegen/CodeGenUtil.java
@@ -27,6 +27,7 @@
 import java.util.List;
 import java.util.Set;
 
+import org.apache.asterix.common.utils.CodeGenHelper;
 import org.apache.commons.lang3.tuple.Pair;
 import org.objectweb.asm.ClassReader;
 import org.objectweb.asm.ClassWriter;
@@ -36,15 +37,12 @@
  */
 public class CodeGenUtil {
 
-    public final static String DEFAULT_SUFFIX_FOR_GENERATED_CLASS = "Gen";
     private final static String OBJECT_CLASS_NAME = "java/lang/Object";
-    private final static String DESCRIPTOR_SUPER_CLASS_NAME = "org/apache/asterix/runtime/"
-            + "evaluators/base/AbstractScalarFunctionDynamicDescriptor";
+    public final static String DESCRIPTOR_SUPER_CLASS_NAME =
+            "org/apache/asterix/runtime/evaluators/base/AbstractScalarFunctionDynamicDescriptor";
     private final static String EVALUATOR_FACTORY = "EvaluatorFactory";
     private final static String EVALUATOR = "Evaluator";
     private final static String INNER = "Inner";
-    private final static String DOLLAR = "$";
-    private final static String NESTED_CLASSNAME_PREFIX = "_";
 
     /**
      * The callback interface for a caller to determine what it needs to do for
@@ -81,31 +79,31 @@
     public static List<Pair<String, String>> generateScalarFunctionDescriptorBinary(String
packagePrefix,
             String originalFuncDescriptorClassName, String suffixForGeneratedClass, ClassLoader
classLoader,
             ClassByteCodeAction action) throws IOException, ClassNotFoundException {
-        originalFuncDescriptorClassName = toInternalClassName(originalFuncDescriptorClassName);
-        if (originalFuncDescriptorClassName.equals(DESCRIPTOR_SUPER_CLASS_NAME)) {
+        String internalFuncDescriptorClassName = CodeGenHelper.toInternalClassName(originalFuncDescriptorClassName);
+        if (internalFuncDescriptorClassName.equals(DESCRIPTOR_SUPER_CLASS_NAME)) {
             return Collections.emptyList();
         }
 
-        String targetFuncDescriptorClassName = getGeneratedFunctionDescriptorInternalClassName(
-                originalFuncDescriptorClassName, suffixForGeneratedClass);
+        String targetFuncDescriptorClassName =
+                CodeGenHelper.getGeneratedInternalClassName(internalFuncDescriptorClassName,
suffixForGeneratedClass);
 
         // Adds the mapping of the old/new names of the function descriptor.
         List<Pair<String, String>> nameMappings = new ArrayList<>();
 
         // Generates code for super classes except java.lang.Object.
-        Class<?> evaluatorClass = CodeGenUtil.class.getClassLoader()
-                .loadClass(toJdkStandardName(originalFuncDescriptorClassName));
+        Class<?> evaluatorClass =
+                classLoader.loadClass(CodeGenHelper.toJdkStandardName(internalFuncDescriptorClassName));
         nameMappings.addAll(generateScalarFunctionDescriptorBinary(packagePrefix,
                 evaluatorClass.getSuperclass().getName(), suffixForGeneratedClass, classLoader,
action));
 
-        nameMappings.add(Pair.of(originalFuncDescriptorClassName, targetFuncDescriptorClassName));
-        nameMappings.add(Pair.of(toJdkStandardName(originalFuncDescriptorClassName),
-                toJdkStandardName(targetFuncDescriptorClassName)));
+        nameMappings.add(Pair.of(internalFuncDescriptorClassName, targetFuncDescriptorClassName));
+        nameMappings.add(Pair.of(CodeGenHelper.toJdkStandardName(internalFuncDescriptorClassName),
+                CodeGenHelper.toJdkStandardName(targetFuncDescriptorClassName)));
 
         // Gathers evaluator factory classes that are created in the function descriptor.
-        ClassReader reader = new ClassReader(getResourceStream(originalFuncDescriptorClassName,
classLoader));
-        GatherEvaluatorFactoryCreationVisitor evalFactoryCreationVisitor = new GatherEvaluatorFactoryCreationVisitor(
-                toInternalClassName(packagePrefix));
+        ClassReader reader = new ClassReader(getResourceStream(internalFuncDescriptorClassName,
classLoader));
+        GatherEvaluatorFactoryCreationVisitor evalFactoryCreationVisitor =
+                new GatherEvaluatorFactoryCreationVisitor(CodeGenHelper.toInternalClassName(packagePrefix));
         reader.accept(evalFactoryCreationVisitor, 0);
         Set<String> evaluatorFactoryClassNames = evalFactoryCreationVisitor.getCreatedEvaluatorFactoryClassNames();
 
@@ -126,20 +124,6 @@
         reader.accept(renamingVisitor, 0);
         action.runAction(targetFuncDescriptorClassName, writer.toByteArray());
         return nameMappings;
-    }
-
-    public static String getGeneratedFunctionDescriptorClassName(String originalFuncDescriptorClassName,
-            String suffixForGeneratedClass) {
-        return toJdkStandardName(getGeneratedFunctionDescriptorInternalClassName(originalFuncDescriptorClassName,
-                suffixForGeneratedClass));
-    }
-
-    private static String getGeneratedFunctionDescriptorInternalClassName(String originalFuncDescriptorClassName,
-            String suffixForGeneratedClass) {
-        String originalFuncDescriptorClassInternalName = toInternalClassName(originalFuncDescriptorClassName);
-        String targetFuncDescriptorClassName = getGeneratedClassName(originalFuncDescriptorClassInternalName,
-                suffixForGeneratedClass, 0);
-        return targetFuncDescriptorClassName;
     }
 
     /**
@@ -193,19 +177,19 @@
             String originalEvaluatorFactoryClassName, String suffixForGeneratedClass, int
factoryCounter,
             List<Pair<String, String>> nameMappings, ClassLoader classLoader,
ClassByteCodeAction action)
             throws IOException, ClassNotFoundException {
-        originalEvaluatorFactoryClassName = toInternalClassName(originalEvaluatorFactoryClassName);
-        String targetEvaluatorFactoryClassName = getGeneratedClassName(originalEvaluatorFactoryClassName,
+        String internalEvaluatorFactoryClassName = CodeGenHelper.toInternalClassName(originalEvaluatorFactoryClassName);
+        String targetEvaluatorFactoryClassName = CodeGenHelper.generateClassName(internalEvaluatorFactoryClassName,
                 EVALUATOR_FACTORY + suffixForGeneratedClass, factoryCounter);
 
         // Adds the old/new names of the evaluator factory into the mapping.
-        nameMappings.add(Pair.of(originalEvaluatorFactoryClassName, targetEvaluatorFactoryClassName));
-        nameMappings.add(Pair.of(toJdkStandardName(originalEvaluatorFactoryClassName),
-                toJdkStandardName(targetEvaluatorFactoryClassName)));
+        nameMappings.add(Pair.of(internalEvaluatorFactoryClassName, targetEvaluatorFactoryClassName));
+        nameMappings.add(Pair.of(CodeGenHelper.toJdkStandardName(internalEvaluatorFactoryClassName),
+                CodeGenHelper.toJdkStandardName(targetEvaluatorFactoryClassName)));
 
         // Gathers the class names of the evaluators that are created in the evaluator factory.
-        ClassReader reader = new ClassReader(getResourceStream(originalEvaluatorFactoryClassName,
classLoader));
-        GatherEvaluatorCreationVisitor evalCreationVisitor = new GatherEvaluatorCreationVisitor(
-                toInternalClassName(packagePrefix));
+        ClassReader reader = new ClassReader(getResourceStream(internalEvaluatorFactoryClassName,
classLoader));
+        GatherEvaluatorCreationVisitor evalCreationVisitor =
+                new GatherEvaluatorCreationVisitor(CodeGenHelper.toInternalClassName(packagePrefix));
         reader.accept(evalCreationVisitor, 0);
         Set<String> evaluatorClassNames = evalCreationVisitor.getCreatedEvaluatorClassNames();
 
@@ -249,25 +233,24 @@
             int evalCounter, List<Pair<String, String>> nameMappings, ClassLoader
classLoader,
             ClassByteCodeAction action) throws IOException, ClassNotFoundException {
         // Convert class names.
-        originalEvaluatorClassName = toInternalClassName(originalEvaluatorClassName);
-        if (originalEvaluatorClassName.equals(OBJECT_CLASS_NAME)) {
+        String internalEvaluatorClassName = CodeGenHelper.toInternalClassName(originalEvaluatorClassName);
+        if (internalEvaluatorClassName.equals(OBJECT_CLASS_NAME)) {
             return;
         }
-        String targetEvaluatorClassName = getGeneratedClassName(originalEvaluatorClassName,
+        String targetEvaluatorClassName = CodeGenHelper.generateClassName(internalEvaluatorClassName,
                 EVALUATOR + suffixForGeneratedClass, evalCounter);
 
         // Generates code for super classes except java.lang.Object.
-        Class<?> evaluatorClass = CodeGenUtil.class.getClassLoader()
-                .loadClass(toJdkStandardName(originalEvaluatorClassName));
+        Class<?> evaluatorClass = classLoader.loadClass(CodeGenHelper.toJdkStandardName(internalEvaluatorClassName));
         generateEvaluatorClassBinary(evaluatorClass.getSuperclass().getName(), suffixForGeneratedClass,
evalCounter,
                 nameMappings, classLoader, action);
 
         // Adds name mapping.
-        nameMappings.add(Pair.of(originalEvaluatorClassName, targetEvaluatorClassName));
-        nameMappings.add(
-                Pair.of(toJdkStandardName(originalEvaluatorClassName), toJdkStandardName(targetEvaluatorClassName)));
+        nameMappings.add(Pair.of(internalEvaluatorClassName, targetEvaluatorClassName));
+        nameMappings.add(Pair.of(CodeGenHelper.toJdkStandardName(internalEvaluatorClassName),
+                CodeGenHelper.toJdkStandardName(targetEvaluatorClassName)));
 
-        ClassReader firstPassReader = new ClassReader(getResourceStream(originalEvaluatorClassName,
classLoader));
+        ClassReader firstPassReader = new ClassReader(getResourceStream(internalEvaluatorClassName,
classLoader));
         // Generates inner classes other than the evaluator.
         Set<String> excludedNames = new HashSet<>();
         for (Pair<String, String> entry : nameMappings) {
@@ -285,11 +268,11 @@
         // Injects null-handling byte code and output the class binary.
         // Since we're going to add jump instructions, we have to let the ClassWriter to
         // automatically generate frames for JVM to verify the class.
-        ClassWriter secondPassWriter = new ClassWriter(secondPassReader,
-                ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
+        ClassWriter secondPassWriter =
+                new ClassWriter(secondPassReader, ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
         RenameClassVisitor renamingVisitor = new RenameClassVisitor(secondPassWriter, nameMappings);
-        EvaluatorNullCheckVisitor nullHandlingVisitor = new EvaluatorNullCheckVisitor(renamingVisitor,
-                missingHandlingVisitor.getLastAddedLabel());
+        EvaluatorNullCheckVisitor nullHandlingVisitor =
+                new EvaluatorNullCheckVisitor(renamingVisitor, missingHandlingVisitor.getLastAddedLabel());
         secondPassReader.accept(nullHandlingVisitor, 0);
         action.runAction(targetEvaluatorClassName, secondPassWriter.toByteArray());
     }
@@ -325,9 +308,10 @@
         String suffix = INNER + suffixForGeneratedClass;
         for (String innerClassName : innerClassNames) {
             // adds name mapping.
-            String targetInnerClassName = getGeneratedClassName(innerClassName, suffix, counter++);
+            String targetInnerClassName = CodeGenHelper.generateClassName(innerClassName,
suffix, counter++);
             nameMappings.add(Pair.of(innerClassName, targetInnerClassName));
-            nameMappings.add(Pair.of(toJdkStandardName(innerClassName), toJdkStandardName(targetInnerClassName)));
+            nameMappings.add(Pair.of(CodeGenHelper.toJdkStandardName(innerClassName),
+                    CodeGenHelper.toJdkStandardName(targetInnerClassName)));
 
             // Renaming appearances of original class names.
             ClassReader innerClassReader = new ClassReader(getResourceStream(innerClassName,
classLoader));
@@ -336,58 +320,6 @@
             innerClassReader.accept(renamingVisitor, 0);
             action.runAction(targetInnerClassName, writer.toByteArray());
         }
-    }
-
-    /**
-     * Converts a JDK class name to the class naming format of ASM.
-     *
-     * @param name,
-     *            a class name following the JDK convention.
-     * @return a "/"-separated class name assumed by ASM.
-     */
-    private static String toInternalClassName(String name) {
-        return name.replace(".", "/");
-    }
-
-    /**
-     * Converts an ASM class name to the JDK class naming format.
-     *
-     * @param name,
-     *            a class name following the ASM convention.
-     * @return a "."-separated class name for JDK.
-     */
-    private static String toJdkStandardName(String name) {
-        return name.replace("/", ".");
-    }
-
-    /**
-     * Gets the name of a generated class.
-     *
-     * @param originalClassName,
-     *            the original class, i.e., the source of the generated class.
-     * @param suffix,
-     *            the suffix for the generated class.
-     * @param counter,
-     *            a counter that appearing at the end of the name of the generated class.
-     * @return the name of the generated class.
-     */
-    private static String getGeneratedClassName(String originalClassName, String suffix,
int counter) {
-        StringBuilder sb = new StringBuilder();
-        int end = originalClassName.indexOf(DOLLAR);
-        if (end < 0) {
-            end = originalClassName.length();
-        }
-
-        String name = originalClassName.substring(0, end);
-        sb.append(name);
-        sb.append(DOLLAR);
-        sb.append(NESTED_CLASSNAME_PREFIX);
-        sb.append(suffix);
-
-        if (counter > 0) {
-            sb.append(counter);
-        }
-        return sb.toString();
     }
 
     /**
@@ -402,4 +334,7 @@
     private static InputStream getResourceStream(String className, ClassLoader classLoader)
{
         return classLoader.getResourceAsStream(className.replace('.', '/') + ".class");
     }
+
+    private CodeGenUtil() {
+    }
 }
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/staticcodegen/EvaluatorMissingCheckVisitor.java
b/asterixdb/asterix-maven-plugins/asterix-evaluator-generator-maven-plugin/src/main/java/org/apache/asterix/runtime/evaluators/staticcodegen/EvaluatorMissingCheckVisitor.java
similarity index 100%
rename from asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/staticcodegen/EvaluatorMissingCheckVisitor.java
rename to asterixdb/asterix-maven-plugins/asterix-evaluator-generator-maven-plugin/src/main/java/org/apache/asterix/runtime/evaluators/staticcodegen/EvaluatorMissingCheckVisitor.java
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/staticcodegen/EvaluatorNullCheckVisitor.java
b/asterixdb/asterix-maven-plugins/asterix-evaluator-generator-maven-plugin/src/main/java/org/apache/asterix/runtime/evaluators/staticcodegen/EvaluatorNullCheckVisitor.java
similarity index 100%
rename from asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/staticcodegen/EvaluatorNullCheckVisitor.java
rename to asterixdb/asterix-maven-plugins/asterix-evaluator-generator-maven-plugin/src/main/java/org/apache/asterix/runtime/evaluators/staticcodegen/EvaluatorNullCheckVisitor.java
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/staticcodegen/GatherEvaluatorCreationVisitor.java
b/asterixdb/asterix-maven-plugins/asterix-evaluator-generator-maven-plugin/src/main/java/org/apache/asterix/runtime/evaluators/staticcodegen/GatherEvaluatorCreationVisitor.java
similarity index 96%
rename from asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/staticcodegen/GatherEvaluatorCreationVisitor.java
rename to asterixdb/asterix-maven-plugins/asterix-evaluator-generator-maven-plugin/src/main/java/org/apache/asterix/runtime/evaluators/staticcodegen/GatherEvaluatorCreationVisitor.java
index 416ce63..17f60ee 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/staticcodegen/GatherEvaluatorCreationVisitor.java
+++ b/asterixdb/asterix-maven-plugins/asterix-evaluator-generator-maven-plugin/src/main/java/org/apache/asterix/runtime/evaluators/staticcodegen/GatherEvaluatorCreationVisitor.java
@@ -31,7 +31,7 @@
  */
 public class GatherEvaluatorCreationVisitor extends ClassVisitor {
 
-    private static String METHOD_NAME = "createScalarEvaluator";
+    private static final String METHOD_NAME = "createScalarEvaluator";
     private Set<String> createdEvaluatorClassNames = new HashSet<>();
     private String ownerPrefix;
 
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/staticcodegen/GatherEvaluatorFactoryCreationVisitor.java
b/asterixdb/asterix-maven-plugins/asterix-evaluator-generator-maven-plugin/src/main/java/org/apache/asterix/runtime/evaluators/staticcodegen/GatherEvaluatorFactoryCreationVisitor.java
similarity index 96%
rename from asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/staticcodegen/GatherEvaluatorFactoryCreationVisitor.java
rename to asterixdb/asterix-maven-plugins/asterix-evaluator-generator-maven-plugin/src/main/java/org/apache/asterix/runtime/evaluators/staticcodegen/GatherEvaluatorFactoryCreationVisitor.java
index 19234e2..eeeb313 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/staticcodegen/GatherEvaluatorFactoryCreationVisitor.java
+++ b/asterixdb/asterix-maven-plugins/asterix-evaluator-generator-maven-plugin/src/main/java/org/apache/asterix/runtime/evaluators/staticcodegen/GatherEvaluatorFactoryCreationVisitor.java
@@ -31,7 +31,7 @@
  */
 public class GatherEvaluatorFactoryCreationVisitor extends ClassVisitor {
 
-    private static String METHOD_NAME = "createEvaluatorFactory";
+    private static final String METHOD_NAME = "createEvaluatorFactory";
     private final Set<String> createdEvaluatorFactoryClassNames = new HashSet<>();
     private String ownerPrefix;
 
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/staticcodegen/GatherInnerClassVisitor.java
b/asterixdb/asterix-maven-plugins/asterix-evaluator-generator-maven-plugin/src/main/java/org/apache/asterix/runtime/evaluators/staticcodegen/GatherInnerClassVisitor.java
similarity index 100%
rename from asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/staticcodegen/GatherInnerClassVisitor.java
rename to asterixdb/asterix-maven-plugins/asterix-evaluator-generator-maven-plugin/src/main/java/org/apache/asterix/runtime/evaluators/staticcodegen/GatherInnerClassVisitor.java
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/staticcodegen/MethodIdentifier.java
b/asterixdb/asterix-maven-plugins/asterix-evaluator-generator-maven-plugin/src/main/java/org/apache/asterix/runtime/evaluators/staticcodegen/MethodIdentifier.java
similarity index 100%
rename from asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/staticcodegen/MethodIdentifier.java
rename to asterixdb/asterix-maven-plugins/asterix-evaluator-generator-maven-plugin/src/main/java/org/apache/asterix/runtime/evaluators/staticcodegen/MethodIdentifier.java
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/staticcodegen/RenameClassVisitor.java
b/asterixdb/asterix-maven-plugins/asterix-evaluator-generator-maven-plugin/src/main/java/org/apache/asterix/runtime/evaluators/staticcodegen/RenameClassVisitor.java
similarity index 100%
rename from asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/staticcodegen/RenameClassVisitor.java
rename to asterixdb/asterix-maven-plugins/asterix-evaluator-generator-maven-plugin/src/main/java/org/apache/asterix/runtime/evaluators/staticcodegen/RenameClassVisitor.java
diff --git a/asterixdb/asterix-runtime/pom.xml b/asterixdb/asterix-runtime/pom.xml
index 7f1fabd..6092cc5 100644
--- a/asterixdb/asterix-runtime/pom.xml
+++ b/asterixdb/asterix-runtime/pom.xml
@@ -35,6 +35,55 @@
       <comments>A business-friendly OSS license</comments>
     </license>
   </licenses>
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.asterix</groupId>
+        <artifactId>asterix-evaluator-generator-maven-plugin</artifactId>
+        <version>${project.version}</version>
+        <configuration>
+          <evaluatorPackagePrefix>org.apache.asterix.runtime.evaluators</evaluatorPackagePrefix>
+        </configuration>
+        <executions>
+          <execution>
+            <id>generate-evaluator</id>
+            <phase>process-classes</phase>
+            <goals>
+              <goal>generate-evaluator</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+    <pluginManagement>
+      <plugins>
+        <plugin>
+          <groupId>org.eclipse.m2e</groupId>
+          <artifactId>lifecycle-mapping</artifactId>
+          <version>1.0.0</version>
+          <configuration>
+            <lifecycleMappingMetadata>
+              <pluginExecutions>
+                <pluginExecution>
+                  <pluginExecutionFilter>
+                    <groupId>org.apache.asterix</groupId>
+                    <artifactId>asterix-evaluator-generator-maven-plugin</artifactId>
+                    <versionRange>(0.8.8-incubating,)</versionRange>
+                    <goals>
+                      <goal>generate-evaluator</goal>
+                    </goals>
+                  </pluginExecutionFilter>
+                  <action>
+                    <ignore />
+                  </action>
+                </pluginExecution>
+              </pluginExecutions>
+            </lifecycleMappingMetadata>
+          </configuration>
+        </plugin>
+      </plugins>
+    </pluginManagement>
+  </build>
   <dependencies>
     <dependency>
       <groupId>org.apache.asterix</groupId>
@@ -133,11 +182,6 @@
       <groupId>org.apache.asterix</groupId>
       <artifactId>asterix-transactions</artifactId>
       <version>${project.version}</version>
-    </dependency>
-    <dependency>
-      <groupId>org.ow2.asm</groupId>
-      <artifactId>asm-all</artifactId>
-      <version>5.1</version>
     </dependency>
     <dependency>
       <groupId>com.fasterxml.jackson.core</groupId>

-- 
To view, visit https://asterix-gerrit.ics.uci.edu/1870
To unsubscribe, visit https://asterix-gerrit.ics.uci.edu/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I2bb9a2cef1d346242c65d76378fbbf0e18a94bfe
Gerrit-PatchSet: 3
Gerrit-Project: asterixdb
Gerrit-Branch: master
Gerrit-Owner: Dmitry Lychagin <dmitry.lychagin@couchbase.com>
Gerrit-Reviewer: Dmitry Lychagin <dmitry.lychagin@couchbase.com>
Gerrit-Reviewer: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Gerrit-Reviewer: Till Westmann <tillw@apache.org>
Gerrit-Reviewer: Yingyi Bu <buyingyi@gmail.com>


Mime
View raw message