Live data from Hacker News

JVM JIT optimization techniques

advancedweb.hu

51–60 of 62 posts

Re: JVM JIT optimization techniques

#51
post #48
post #44

Earlier quoted context omitted.

I feel with companies moving to cloud environment defending Java memory bloat will be harder and harder. Java's limited value types may be out by 2020-21 or so and it will be many more years libraries ecosystem start utilizing it. So we are still at least 10 years away from some form of Java value type available for general users.

1. Memory "bloat" is always a better use of resources than increased development time, regardless of how you have to pay for it. 2. How are Java's value types limited? 3. I find your calculation extremely pessimistic. Lambda expression are widespread a couple of years after their release, and I see no reason why value types will be different. I think that 5 years are a better estimate for wide use of value types.

Here is what I read from JEP 169

> Except for pointer equality checks, forbidden operations will throw some sort of exception. How to control pointer equality checks is an open question with several possible answers.

And more:

  Rules for permanently locked objects:
  
  - restrictions on classes of locked objects
      - all non-static fields must be final
      - there must be no finalizer method (no override to `Object.finalize`)
      - these restrictions apply to any superclasses as well
      - an array can be marked locked, but then (of course) its elements cannot be stored to
      - if not an array, the object's class must implement the marker type `PermanentlyLockable` (is this a good idea?)
  - restricted operations on locked objects (could be enforced, or else documented as producing undefined results)
      - do not use any astore or putfield instructions, nor their reflective equivalents, to change any field
      - do not lock (you may get a hang or a LockedObjectException)
      - do not test for pointer equality; use Object.equals instead (there may be a test for this)
      - do not ask for an identity hash code; use Object.hashCode instead (there may be a test for this)
      - do not call wait, notify, or notifyAll methods in Object
      - at the time it is marked locked, an object's monitor must not be locked (in fact, should never have been?)
  - side effects
      - elements of locked arrays are stably available to readers just like final object fields (i.e., there is a memory fence)
      - a locked object can be locked again, with no additional effect
      - any attempt to mutate a permanently locked object raises java.lang.LockedObjectException
      - any attempt to synchronize on a permanently locked object raises java.lang.LockedObjectException
  - object lifecycle
      - all objects are initially created in a normal (unlocked) state
      - an object marked locked cannot be "unlocked" (reverted to a normal state)
      - an object marked locked must be unreferenced by any other thread (can we enforce this?)
      - the reference returned from the (unsafe) marking primitive must be used for all future accesses
      - any previous references (including the one passed to the marking primitive) must be unused
      - in practice, this means you must mark an object locked immediately after constructing it
  - API
      - the method `lockPermanently` is used to lock an object permanently
      - there is a predicate `isLockedPermanently` which can test whether an object is locked or not
      - for initial experiments, these methods are in `sun.misc.Unsafe`; perhaps they belong on `Object` (cf. `clone`)`
With all this above I feel it is not exactly same as understood in languages which natively support value type.

Re: JVM JIT optimization techniques

#52

Earlier quoted context omitted.

I guess you see a lot of such articles because of comments like yours - lots of people still think Java is generically slow or Java code is always bloated, despite not having used it for 10 years or more. Whilst such views persist, there will be articles arguing they're false based on newer data. Nobody writes "C is not slow" articles any more, but I remember a time when there were people who believed C++ was inheren…

despite not having used it for 10 years or more I just don't write code in Java anymore --- I still need to use some Java apps, and the difference remains obvious. The other thing I've noticed is that a lot of those "Java is actually fast" articles are [1] entirely words about all the fancy optimisations JVMs do with no real numbers, [2] comparing Java with previous versions of itself, [3] comparing Java with highly…

Well, here is a paper you may find useful:

https://days2011.scala-lang.org/sites/days2011/files/ws3-1-H...

They write the same program in C++, Java, Scala and Go, then compare performance both before and after optimisation.

They key part that shows Java can be as fast as C++ is V.E "Java tunings":

Jeremy Manson brought the performance of Java on par with the original C++ version. This version is kept in the java_pro directory. Note that Jeremy deliberately refused to optimize the code further, many of the C++ optimizations would apply to the Java version as well.

The tunings he applied are not exotic, but would not be used in most code unless it was actually performance sensitive. For instance he chose better starting sizes in ArrayLists and replaced boxing collections with more optimal ones (presumably from GNU Trove).

Of course, that is a comparison against the original C++. Later in the paper it is shown that Google were able to optimize the C++ version heavily and it then beat the Java version again, however, apparently the optimised version relied on data structures so exotic that they're Google proprietary and they chose not to open source them, so I'm not sure that'd be reflective of the experience of the average C++ developer.

Re: JVM JIT optimization techniques

#53

Earlier quoted context omitted.

Given that the HotSpot compilers are not Graal and HotSpot's scalar replacement optimisation is notoriously fragile, I think the original statement was fair. Once Java 9 rolls around and Graal is just a plugin instead of a whole separate VM build, it'll be less fair, and if Graal ever becomes the default compiler that replaces C2 then it'll be even more fair, but I guess that is years away at best. The biggest constr…

Hot spot is based on a relatively old paper at this point from what I remember and there are alternatives which purportedly perform better.

Can you name one?

Re: JVM JIT optimization techniques

#54

Earlier quoted context omitted.

Hot spot is based on a relatively old paper at this point from what I remember and there are alternatives which purportedly perform better.

Can you name one?

Partial escape analysis is one http://www.ssw.uni-linz.ac.at/Research/Papers/Stadler14/Stad...

Re: JVM JIT optimization techniques

#55
post #51
post #48

Earlier quoted context omitted.

1. Memory "bloat" is always a better use of resources than increased development time, regardless of how you have to pay for it. 2. How are Java's value types limited? 3. I find your calculation extremely pessimistic. Lambda expression are widespread a couple of years after their release, and I see no reason why value types will be different. I think that 5 years are a better estimate for wide use of value types.

Here is what I read from JEP 169 > Except for pointer equality checks, forbidden operations will throw some sort of exception. How to control pointer equality checks is an open question with several possible answers. And more: Rules for permanently locked objects: - restrictions on classes of locked objects - all non-static fields must be final - there must be no finalizer method (no override to `Object.finalize`) -…

Java will natively support value types (and already does, just not user-defined value types). What you've quoted is the spec for locked arrays; those arrays are not value types, but reference types. I'm not sure about the relationship between the text in that JEP and the current work on value types: http://openjdk.java.net/projects/valhalla/

Re: JVM JIT optimization techniques

#56
post #49
post #16

Earlier quoted context omitted.

> I don't know anyone who would say the majority of Java applications aren't huge, slow, memory-hogging beasts compared to equivalent native ones, and whose codebases are just as unoptimised for the perspective of the humans who have to work with them. I would, and I've been developing in Java for over ten years now, after ten years of C/C++. I think that your complaints have nothing to do with Java, and much to do w…

Well if Graal is faster why is it not made part JDK distribution.

As of JDK 9, Graal will be a pluggable JIT that you can opt to use (it's just a Java library). It is not the default JIT because it is still experimental and not productized yet.

Re: JVM JIT optimization techniques

#57

Earlier quoted context omitted.

Can you name one?

Partial escape analysis is one http://www.ssw.uni-linz.ac.at/Research/Papers/Stadler14/Stad...

Ah, I meant "alternatives to HotSpot" which is what the parent was implying.

I've read the Graal papers and part of the source code. So I am familiar with PEA. It's too bad that optimisation didn't make it into C2 yet. I wonder if it ever will.

Re: JVM JIT optimization techniques

#58

Earlier quoted context omitted.

Partial escape analysis is one http://www.ssw.uni-linz.ac.at/Research/Papers/Stadler14/Stad...

Ah, I meant "alternatives to HotSpot" which is what the parent was implying. I've read the Graal papers and part of the source code. So I am familiar with PEA. It's too bad that optimisation didn't make it into C2 yet. I wonder if it ever will.

Someone told me that Zing also does PEA, but I don't know that to be a fact.

Re: JVM JIT optimization techniques

#59

Earlier quoted context omitted.

Ah, I meant "alternatives to HotSpot" which is what the parent was implying. I've read the Graal papers and part of the source code. So I am familiar with PEA. It's too bad that optimisation didn't make it into C2 yet. I wonder if it ever will.

Someone told me that Zing also does PEA, but I don't know that to be a fact.

Oh and I think JRockit might have done it as well.

Re: JVM JIT optimization techniques

#60

Earlier quoted context omitted.

Ah, the Java is slow argument. When were you doing Enterprise Java? It must have been around the pre HotSpot years. As for applications that are huge, memory hogs, complex and non elegant, well, congratulations you just described the majority of enterprise applications.

https://benchmarksgame.alioth.debian.org/u64q/java.html Consistently twice as slow, with memory usage between 2 and 400(!) times larger. Java is slow and bloated compared to native. Your next argument will be something about how micro-benchmarks don't reflect reality for larger programs...

>> memory usage

http://programmers.stackexchange.com/a/189552/4334

Post reply on HN