Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Inlining in constructors has been disabled a long time ago due to some VerifyErrors. Unfortunately, @dragos cannot recall what exactly was the problem. I tried to enable inlining in constructors and I didn't see any problem. `Predef.assert` calls in class constructors are one of the biggest contributors to closure allocation in a compiler so we better off get rid of it. Added a test-case that checks if inlining in constructors works properly. Review by @magarciaEPFL and @paulp.
- Loading branch information
1 parent
d8b35a1
commit 4caa766
Showing
6 changed files
with
40 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Method call statistics: | ||
1 instrumented/Bar.<init>(Z)V | ||
1 instrumented/Foo.<init>(I)V |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
-optimise |
13 changes: 13 additions & 0 deletions
13
test/files/instrumented/inline-in-constructors/assert_1.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package instrumented | ||
|
||
object MyPredef { | ||
@inline | ||
final def assert(assertion: Boolean, message: => Any) { | ||
if (!assertion) | ||
throw new java.lang.AssertionError("assertion failed: " + message) | ||
} | ||
} | ||
|
||
class Foo(x: Int) { | ||
MyPredef.assert(x > 0, "not positive: " + x) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package instrumented | ||
|
||
/** Class that uses assert compiled in previous compiler run so we check if | ||
inlining in constructors works across different compilation runs */ | ||
class Bar(x: Boolean) { | ||
MyPredef.assert(x, "not true: " + x) | ||
} |
15 changes: 15 additions & 0 deletions
15
test/files/instrumented/inline-in-constructors/test_3.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import scala.tools.partest.instrumented.Instrumentation._ | ||
import instrumented._ | ||
|
||
object Test { | ||
def main(args: Array[String]) { | ||
// force predef initialization before profiling | ||
Predef | ||
MyPredef | ||
startProfiling() | ||
val a = new Foo(2) | ||
val b = new Bar(true) | ||
stopProfiling() | ||
printStatistics() | ||
} | ||
} |