How can I put some code into try capture blocks so that the JVM does not perform optimization?

In the Exceptions chapter in Effective Java:

Placing code inside a try-catch block blocks certain optimizations that otherwise JVM implementations might perform

Why and how does a try-catch block prevent JVM optimization?

+5
source share
3 answers

"" , ; , . , , JIT , .

JIT , . :

  • , , ,
  • ( Oracle) , ( /), .

, . , ( ) , . , , , (, , ,...) .

+2

JVM try/catch , try/catch. . , JVM, , , , .

+5

:

Java?

I think exceptions are Java objects, and these objects need to be created. Creating an object is an expensive operation. Therefore, use exceptions only for error handling and not for flow control.

-1
source

All Articles