RE: Questions about using `assert` in Java

2023-07-17 Thread Andrew Luo
Thanks, I see. Then I wonder if we should consider the size of a function with assertions removed when making JIT inline decisions? Since at JIT time I presume whether assertions are turned on or off is known – or is it too inefficient to calculate this metric? Thanks, -Andrew From: Daohan Q

RE: Questions about using `assert` in Java

2023-07-17 Thread Andrew Luo
17, 2023 2:08 AM To: Daohan Qu ; core-libs-dev@openjdk.org Subject: Re: Questions about using `assert` in Java On 15/07/2023 17:53, Daohan Qu wrote: : Although the assert​ keyword has been around for a long time and is handy for invariant checks, it does not seem to be widely used. For example, in

Re: Questions about using `assert` in Java

2023-07-17 Thread John Rose
On 17 Jul 2023, at 2:08, Alan Bateman wrote: On 15/07/2023 17:53, Daohan Qu wrote: You will find places in the JDK code, esp. in performance critical code, where assertions are commented out. The reason is that asserts, even if disabled, increase the method size and can impact inlining by th

Re: Questions about using `assert` in Java

2023-07-17 Thread Daohan Qu
Hi Pavel, > There have been studies looking into correlation between assertion density > and fault/defect density. Here's one such study: "Assessing the Relationship > between Software Assertions and Code Quality: An Empirical Investigation". Thanks and yes! And there are also some more recent st

Re: Questions about using `assert` in Java

2023-07-17 Thread Daohan Qu
Hi John, > I believe this can be partially alleviated by extracting the asserts to a > method (partially as the call also increases method size). The optimizer > seems to be smart enough to not call the method if it does nothing > (when ea is disabled). Thanks a lot! Good to know that. I'm not su

Re: Questions about using `assert` in Java

2023-07-17 Thread Daohan Qu
Hi Alan, > You will find places in the JDK code, esp. in performance critical code, > where assertions are commented out. The reason is that asserts, even if > disabled, increase the method size and can impact inlining by the > compiler at run-time. So while useful when debugging some issue in suc

Re: Questions about using `assert` in Java

2023-07-17 Thread Daohan Qu
Regards, Daohan From: liangchenb...@gmail.com Sent: Sunday, July 16, 2023 7:09 To: Daohan Qu Cc: core-libs-dev@openjdk.org Subject: Re: Questions about using `assert` in Java Hi Daohan, assert keyword is safely usable within production code. I don't think it

Re: Questions about using `assert` in Java

2023-07-17 Thread Daohan Qu

Re: Questions about using `assert` in Java

2023-07-17 Thread Pavel Rappo
In this thread, Alan has already pointed out possible runtime cost of Java assertions. But as far as the general idea goes, I find assertions to be very helpful. There have been studies looking into correlation between assertion density and fault/defect density. Here's one such study: "Assessin

Re: Questions about using `assert` in Java

2023-07-17 Thread John Hendrikx
On 17/07/2023 11:08, Alan Bateman wrote: On 15/07/2023 17:53, Daohan Qu wrote: : Although the |assert|​ keyword has been around for a long time and is handy for invariant checks, it does not seem to be widely used. For example, in the famous |j.u.c|​ packages, nearly all |assert|​ statements ar

Re: Questions about using `assert` in Java

2023-07-17 Thread Alan Bateman
On 15/07/2023 17:53, Daohan Qu wrote: : Although the |assert|​ keyword has been around for a long time and is handy for invariant checks, it does not seem to be widely used. For example, in the famous |j.u.c|​ packages, nearly all |assert|​ statements are commented out [1]. My questions are, sh

Re: Questions about using `assert` in Java

2023-07-15 Thread -
Hi Daohan, assert keyword is safely usable within production code. I don't think it has a significant performance impact if it is not enabled. Thus, you should not enable it in production unless you are debugging. A package that uses assert extensively is java.lang.invoke package. For me, these a