开发者

Will the JVM ever inline an object's instance variables and methods?

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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜