Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a bootstrap method?

Tags:

java

I have been reading this presentation about java8 lambdas implementation http://fr.slideshare.net/czechscala/java-8-under-the-hood

LambdaMetaFactory contains bootstrap methods for converting lambda expressions to functional interface objects.

What are these bootstrap methods, and are they related to invokedynamic ?

like image 766
Bionix1441 Avatar asked Jun 09 '15 13:06

Bionix1441


People also ask

What is meant by bootstrap method?

The bootstrap method is a statistical technique for estimating quantities about a population by averaging estimates from multiple small data samples. Importantly, samples are constructed by drawing observations from a large data sample one at a time and returning them to the data sample after they have been chosen.

What does bootstrap mean in statistics?

“Bootstrapping is a statistical procedure that resamples a single dataset to create many simulated samples. This process allows for the calculation of standard errors, confidence intervals, and hypothesis testing” (Forst).

What is a bootstrap example?

What is a Bootstrap Sample? A bootstrap sample is a smaller sample that is “bootstrapped” from a larger sample. Bootstrapping is a type of resampling where large numbers of smaller samples of the same size are repeatedly drawn, with replacement, from a single original sample.

When should I use bootstrap method?

Bootstrap comes in handy when there is no analytical form or normal theory to help estimate the distribution of the statistics of interest since bootstrap methods can apply to most random quantities, e.g., the ratio of variance and mean.


1 Answers

invokedynamic is a bytecode operation used to call arbitrary method within JVM. The exact method to be called and executed is unknown at a compile-time. Instead it is computed by object implementing CallSite. Thus the dynamic in invokedynamic.

CallSite objects, as any other, have to be instantiated. Boostrap Method is a method which instantiates CallSite objects.

Each invokedynamic has a known bootstrap method given as its compile-time parameter. Whenever a invokedynamic is processed for a first time, appropriate bootstrap method is invoked. As result of boostrap method execution a CallSite object is created. This CallSite object is then cached and associated by JVM to a given invokedynamic operation. From now on, whenever particular invokedynamic call is to be executed, a cached CallSite instance is used to resolve called method.

Majority of boostrap methods are not written directly by end Java programmer. However that doesn't mean they are some rare obscure mechanism. They are created by javac compiler whenever particular java statements are used within source. String concatenation or lambda expression come to mind.

For example lambda expression could be implemented as inner classes. For matter of fact, lambdas are presented to programmers 'as shorthand' to using inner classes. However actual javac implementation, for performance reasons, avoids inner classes by generating lambda code under a static method and using invokedynamic to invoke this method.

For more direct, more impressive usage of invokedynamic, I recommend Charles Nutter blog on how he optimizes JRuby calls sites with this mechanism. While writing RubyVM is not usual Java Programmer activity, it is a really an eye opener on how to appropriately use invokedynamic.

like image 84
Talijanac Avatar answered Oct 14 '22 05:10

Talijanac