LuciferYang edited a comment on pull request #32536:
URL: https://github.com/apache/spark/pull/32536#issuecomment-842979946


   @maropu for the above problem, can we add a case similar to the following to 
compare the result of `reflection api and using ClassBodyEvaluator.getBytecodes 
api` directly ?
   
   ```
   val codeBody = s"""
           public java.lang.Object generate(Object[] references) {
             return new TestMetricCode(references);
           }
   
           class TestMetricCode {
   
             public TestMetricCode(Object[] references) {
             }
   
             public long sumOfSquares(long left, long right) {
               return left * left + right * right;
             }
           }
         """
      // createClassBodyEvaluator is a new method to extract from 
CodeGenerator#doCompile
       val evaluator = CodeGenerator.createClassBodyEvaluator() 
   
       evaluator.cook("generated.java", codeBody)
   
       import scala.collection.JavaConverters._
       val bytecodesFromApi = evaluator.getBytecodes.asScala
       val bytecodesFromReflectionApi = {
         val scField = classOf[ClassBodyEvaluator].getDeclaredField("sc")
         scField.setAccessible(true)
         val compiler = scField.get(evaluator).asInstanceOf[SimpleCompiler]
         val loader = compiler.getClassLoader.asInstanceOf[ByteArrayClassLoader]
         val classesField = loader.getClass.getDeclaredField("classes")
         classesField.setAccessible(true)
         classesField.get(loader).asInstanceOf[java.util.Map[String, 
Array[Byte]]].asScala
       }
   
       assert(bytecodesFromApi == bytecodesFromReflectionApi)
   ```
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to