Javac2 & @NotNull in production

Hello!

I'm interested in using javac2 feature of checking @NotNull annotations at runtime in production in our company.
One of the questions that bothers me a lot is whether @NotNull checking through bytecode patching in the way javac2 does can decrease performance comparing to the simple not null checking like: if (arg == null) throw new SomeException.
Are there any benchmarks comparing runtime performance? Or maybe my fears can be ruined even without any benchmarks?

Thank you in advance!
Anton.

0
3 comments

Well, looked through the bytecode output with javap. It looks like added bytecode does exactly same null-check as I mentioned in my question:
if (arg == null) throw new IllegalArgException("...")
So runtime performance of the code compiled with and without @NotNull checks should be exactly the same. Am I right?

0

Hello Anton,

Yes, you are right. We have @NotNull instrumentation always enabled in IDEA
builds since the feature was implemented, and we're not seeing any significant
performance impact from that.

Well, looked through the bytecode output with javap. It looks like
added bytecode does exactly same null-check as I mentioned in my
question:

if (arg == null) throw new IllegalArgException("...")

So runtime performance of the code compiled with and without @NotNull
checks should be exactly the same. Am I right?


--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0

But what you have to be aware of is that you are revealing externals.
Just in case you plan to obfuscate and sell your code.
The Annotation adds the Methodname as String and that does not get obfuscated along with the methodname itself.
So you make reverse engineering of your code easier.

0

Please sign in to leave a comment.