Skip to content

Array load/store and length with invokedynamic#18232

Merged
rmuir merged 1 commit intoelastic:masterfrom
uschindler:array_invoke_dynamic
May 10, 2016
Merged

Array load/store and length with invokedynamic#18232
rmuir merged 1 commit intoelastic:masterfrom
uschindler:array_invoke_dynamic

Conversation

@uschindler
Copy link
Copy Markdown
Contributor

After @rmuir's improvements for using invokedynamic (#18201) with dynamic method calls and field load/stores, this extends the whole thing to array loads and stores.

It also optimizes access to array.length by using a specialization for every array type. This works around a missing method in Java's MethodHandles class (e.g., MethodHandles.arrayLengthGetter(Class<?> arrayType)).

I did not do performance checks for now, because @rmuir knows better how to do that in ES - I just coded it :-)

@uschindler uschindler changed the title Array invoke dynamic painless: Array load/store and length with invokedynamic May 10, 2016
@clintongormley clintongormley added >enhancement review :Core/Infra/Scripting Scripting abstractions, Painless, and Mustache labels May 10, 2016
@rmuir
Copy link
Copy Markdown
Contributor

rmuir commented May 10, 2016

Looks great. Thanks, the current Array get/set is really horrible, although in my tests the getLength is not so bad.

So i think its best to do what you have, eliminate usage of this reflection class alltogether. Its performance is inconsistent and cannot be trusted!

Can you also update the docs to explain a bit more (https://github.com/uschindler/elasticsearch/blob/array_invoke_dynamic/modules/lang-painless/src/main/java/org/elasticsearch/painless/Def.java#L50) ?

We may want to also test assigning different array types to def so we know nothing breaks.

Thanks again!

@uschindler
Copy link
Copy Markdown
Contributor Author

OK, I added a test class ArrayTests which also uses a for loop to calculate the sum of the aritmetic series.

I also updated docs to add array loads and stores to indy section in Def.

@uschindler
Copy link
Copy Markdown
Contributor Author

FYI: Reflective Array.get/Array.set are slow like hell - some pointers and issues at the OpenJDK bug tracker are here: http://stackoverflow.com/questions/30306160/performance-of-java-lang-reflect-array, https://bugs.openjdk.java.net/browse/JDK-8051447

People say like 20 times slower :-)

@uschindler uschindler force-pushed the array_invoke_dynamic branch from c6ff54f to 2e613f4 Compare May 10, 2016 10:50
@rmuir
Copy link
Copy Markdown
Contributor

rmuir commented May 10, 2016

Thanks @uschindler for taking care of this.

@rmuir rmuir merged commit b6a1491 into elastic:master May 10, 2016
@rmuir rmuir removed the review label May 10, 2016
@uschindler uschindler deleted the array_invoke_dynamic branch May 10, 2016 10:56
@uschindler uschindler restored the array_invoke_dynamic branch May 10, 2016 10:58
@uschindler uschindler deleted the array_invoke_dynamic branch May 10, 2016 11:01
@uschindler uschindler restored the array_invoke_dynamic branch May 10, 2016 12:14
@uschindler uschindler deleted the array_invoke_dynamic branch May 10, 2016 12:16
@uschindler
Copy link
Copy Markdown
Contributor Author

FYI: There is now an issue for the arraylength bytecode MethodHandle that we emulated here by the inner utility class:

https://bugs.openjdk.java.net/browse/JDK-8156915

@clintongormley clintongormley changed the title painless: Array load/store and length with invokedynamic Array load/store and length with invokedynamic May 17, 2016
@uschindler uschindler mentioned this pull request May 19, 2016
18 tasks
@clintongormley clintongormley added :Core/Infra/Scripting Scripting abstractions, Painless, and Mustache and removed :Plugin Lang Painless labels Feb 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:Core/Infra/Scripting Scripting abstractions, Painless, and Mustache >enhancement v5.0.0-alpha3

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants