Reputation: 45408
Suppose I have a very tight inner loop, each iteration of which accesses and mutates a single bookkeeping object that stores some simple data about the algorithm and has simple logic for manipulating it
The bookkeeping object is private and final and all of its methods are private, final and @inline. Here's an example (in Scala syntax):
object Frobnicate {
private class DataRemaining(val start: Int, val end: Int) {
@inline private def nextChunk = ....
}
def frobnicate {
// ...
val bookkeeper = new DataRemaining(0, 1000)
while( bookeeper.hasData ) {
val data = bookkeeper.nextChunk
// ......
}
}
}
Will the JVM ever inline the whole DataRemaining object into Frobnicate.frobnicate
? That is, will it treat start
and end
as local variables and inline the nextChunk code directly into frobnicate
?
Upvotes: 3
Views: 753
Reputation: 533472
In Java it can inline fields and methods in a situation as you have. It does not eliminate the Object completely, but gets close. I assume Scala would work similarly.
Upvotes: 3