Skip to content

Commit

Permalink
Painless: Fix method references to ctor with the new LambdaBootstrap …
Browse files Browse the repository at this point in the history
…and cleanup code (#24406)

* Fix wrong delegation to constructors when compiling lambdas with method references to ctors. Also remove the get$lambda factory.
* Cleanup code and remove unneeded transformations between binary and internal class names (uses ASM Type class instead)
* Cleanup Exception handling
* Simplification by moving the type adaption to the outside
* Remove STATIC access flag from our Lambda class (not required and also officially not allowed)
* Move the lambda counter to the classloader, so we have a per-script lambda ID
* Change Codesource of generated lambdas to be consistent
  • Loading branch information
uschindler authored and jdconrad committed May 1, 2017
1 parent cd78967 commit d464e06
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 156 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.security.SecureClassLoader;
import java.security.cert.Certificate;
import java.util.BitSet;
import java.util.concurrent.atomic.AtomicInteger;

import static org.elasticsearch.painless.WriterConstants.CLASS_NAME;

Expand Down Expand Up @@ -66,6 +67,8 @@ final class Compiler {
* A secure class loader used to define Painless scripts.
*/
static final class Loader extends SecureClassLoader {
private final AtomicInteger lambdaCounter = new AtomicInteger(0);

/**
* @param parent The parent ClassLoader.
*/
Expand All @@ -90,7 +93,15 @@ Class<? extends PainlessScript> defineScript(String name, byte[] bytes) {
* @return A Class object.
*/
Class<?> defineLambda(String name, byte[] bytes) {
return defineClass(name, bytes, 0, bytes.length);
return defineClass(name, bytes, 0, bytes.length, CODESOURCE);
}

/**
* A counter used to generate a unique name for each lambda
* function/reference class in this classloader.
*/
int newLambdaIdentifier() {
return lambdaCounter.getAndIncrement();
}
}

Expand Down
Loading

0 comments on commit d464e06

Please sign in to comment.