10 ms·
JVM implementation challenges: Why the future is hard but worth it [pdf]
- nusbit 12y agoIs there a video?
- oldmanjay 12y agoOh please give me continuations in the VM and I will take back every angry thought I've ever directed at Oracle.
- haddr 12y agoLightweight threads (fibers) looks especially interesting to me. I wonder if there is some library that already tries to ger around threads with something more lightweight...
- norswap 12y agoAssuming this is not rhetorical; yes there is: http://www.paralleluniverse.co/quasar/ http://www.paralleluniverse.co/quasar/
- tormeh 12y agohttp://akka.io/ http://akka.io/
- eranation 12y agoI love Akka, but I thought their implementation relies on regular JVM threads at the moment, isn't it? (I had a wishful thinking at first that they are using user-threads at first, but they are not like quasar or goroutines in any way from what I read, Actors might reuse threads and seem like a "lighter thread" but they are still using plain old JVM threads, for now at least)
- tormeh 12y agoCorrect. Like goroutines, but even lighter, as they have no stack. Java threads map directly to OS threads, do they not?
- eeperson 12y agoI'm not sure I understand what distinction you are making. All of the examples you mention are built by reusing OS/JVM threads. That is how you have to implement user-threads. How do you feel Akka differs from Quasar/Go (aside from the coroutine/actor distinction) .
- eranation 12y agoQuasar uses byte code instrumentation to do things you can't do with "regular" java. How exactly they can do things whne the JVM is the same JVM? good question, I don't know, I know implementing user threads simply means keeping stack information, keeping a scheduler, handling signals, without asking the kernel / OS for a native thread (had to implement user threads in C in the past, not fun) Maybe the JVM allows for more fine grained control on PC location, and allows to "go to" different places in the code without invoking a native thread. But I know that when you create a Quasar co-routine / green thread / user thread / continuation or whatever we want to call it, then it's not the same as Akka. In Akka, if you have a "conversation" between a million actors in a circle, you can still get 1 thread to be reused, if there is no need to use more than one. But if you try to do 3 things in 100% parallel, you might find yourself with 3 threads (from the little that I know). In quasar, you can do all that, without invoking an OS thread, I think this is the main difference. http://docs.paralleluniverse.co/quasar/ http://docs.paralleluniverse.co/quasar/
- x0x0 12y agofj / jsr166 is in 7 sample code: http://docs.oracle.com/javase/tutorial/essential/concurrency/forkjoin.html http://docs.oracle.com/javase/tutorial/essential/concurrency...
- rdtsc 12y agoAn interesting one is http://docs.paralleluniverse.co/quasar/ http://docs.paralleluniverse.co/quasar/ They claim to have "true lightweight" threads. (I am sure pron if he is a around can jump in and expand on it). It takes a lot from Erlang even pattern matching.
- pron 12y agoWell, the pattern matching is only in the Clojure API, but yeah, these are true fibers based on continuations implemented with bytecode instrumentation, scheduled by a work stealing scheduler (or any other scheduler of your choice). It lets you write simple blocking code with all its familiarity and advantages (exceptions, thread-local data) but enjoy the performance of async code. The downside is that libraries have to be integrated in order to block gracefully when called on fibers, but we already have a long and growing list of integration modules for popular libraries.
- justinsb 12y agoI would love to see threads based on this work (OS support for lightweight threads): http://www.linuxplumbersconf.org/2013/ocw//system/presentations/1653/original/LPC%20-%20User%20Threading.pdf http://www.linuxplumbersconf.org/2013/ocw//system/presentati... It seems this would move most of the heavy lifting into the kernel (and out of the already-very-complicated JVM). Anyone know what happened to that work?
- pron 12y agoAFAIK, Google uses it (to some extent, at least), but the solution suffers some issues that make it less than ideal. While it relinquishes scheduling to the application, stack management remains the kernel responsibility, so while the task-switching overhead is greatly reduced, the threads are still not quite lightweight. The advantages to the approach is that it automatically crosses "language barriers", say, between the JVM and native code. This is very important for Google, who use C++ libraries as common code in their polyglot projects, but maybe not so important in other shops.
- x0x0 12y agoThere's some exciting stuff in the presentation. In particular: next gen threading (fibers/warps, fj), plus attention to java's profligate use of memory b/w because of it's reliance on pointers-for-all-the-things. Plus the idea of the jvm helping out languages besides java is also exciting. That said, it's a little scary to contemplate the power that microsoft, steward of the clr, and oracle, steward of the jvm have over our industry. It's staggering to see the amount of engineering that's gone into bullet-proofing the jvm. What happens when microsoft or oracle decline to continue paying for hundreds of very expensive senior compiler/vm/language engineers?
- tormeh 12y agoI've long wondered what's in it for Oracle and now Microsoft. Microsoft stands to profit from applications written for Windows that are hard to port, but they seem to be abandoning that approach. Oracle seems to have no real upside to maintaining Java. No one is paying for C# and Java directly, so I don't get it.
- xxxyy 12y agoJava is the corporate powerhouse, especially for banking. Together with Oracle DB. Owning two out of three crucial components (the third being the hardware) creates a lot of good business opportunities for them, makes it easier to enforce monopoly.
- Gurkenmaster 12y agoOracle already released new SPARC processors that are optimized for the Oracle DB and Java: https://blogs.oracle.com/rajadurai/entry/sparc_m7_chip_32_cores https://blogs.oracle.com/rajadurai/entry/sparc_m7_chip_32_co...
- parkovski 12y agoBoth companies have a lot of enterprise software that exposes either Java or .NET APIs, and lots of companies pay them for support and troubleshooting, and licensing those other products.
- tomp 12y agoOn slide 16, which talks about cache, there is this: > Rule #1: Cache lines should contain 50% of each bit (1/0) > – E.g., if cache lines are 75% zeroes, your D$ size is effectively halved Can anyone explain this?
- x0x0 12y agoa cache line is the unit of read from ram, and is at a premium At least for data, a common win is to compress the data in ram and decompress once it is in-core; this is often essentially free as many machine learning algorithms are bandwidth starved but have plenty of compute available. Suppose you are eg storing small integer counts in ints; if it's a java int you are using 4B to store 1B, while if it's a java.lang.Integer it costs 16 bytes plus most likely an 8B pointer. Another way to consider this is if you are using 8B pointers, you waste a lot of that as constant zeros -- 1TB is 2^40, so even on a 1TB machine 3B/24b are wasted. Particularly with (all? at least that I know of) jvms that have 8B alignment, another 4 bits are wasted. This is how the CompressedOops hack words to access 32G ram w/ 32b pointers.
- bluecalm 12y ago>>At least for data, a common win is to compress the data in ram and decompress once it is in-core I have problems imagining how it could be done. Would you mind elaborating and/or sharing some examples ?
- Someone 12y agoIf you build your own hardware, you don't even have to decompress it. Let's limit each process to 2^40 bytes of RAM. Build your virtual address space so that it masks out the top 24 bits of each address before doing address translation. Then, you can store 24 bits of extra information in each pointer. For example, you could store 3 bytes of a C++ object in a vtable pointer (with 'interesting' repercussions for the sizeof and offsetof macros) That is more or less what the original Macintosh did with its handles. The hardware wrapped addresses around at 24 bits. That allowed Apple to store 3 bits of data in each handle ('data can be purged from memory if needed', 'data cannot be moved', 'data is read from a resource'). Third parties sometimes used the other 5 bits. With the introduction of Macs with more memory, that led to the "program has special memory requirements" system error, which actually meant "this is Excel version so and so. It cannot run on a machine that has 32 address bus lines because it mangles pointers"
- pjmlp 12y agoGreat to see AOT compilation coming to the reference JVM instead of relying on third parties. Also the desire to go meta-circular and reduce even more the amount of C++ code. Most likely based on the Graal/SubstrateVM work. Finally JNI being replaced by something developer friendly.
- vardump 12y agoCache, cache and cache. Three of the most important things Java gets wrong today. Mostly because Java doesn't have object arrays at all. Only primitive types can be array elements. So you get array of references to objects instead of array of objects. There are only 512 L1D cache lines in a CPU core. After just 512 references to memory areas covered by different cache lines, L1D entries will start to drop. Or earlier. In Java this happens very easily. Like when just iterating a single, not very large, data structure. Everything else (except maybe SIMD/GPU related items for compute purposes) are not anywhere near as important as fixing Java's current problems with CPU caches.
- pjmlp 12y agoBack when Java still wasn't known, we had Oberon(-2), Component Pascal and Modula-3. All system programming languages with GC, value types and AOT compilers (some implementations of Oberon did have JITs). Apparently 20 years detour was needed to go back to those features.
- seanmcdirmid 12y agoThe CLR has had value types from the onset.
- pjmlp 12y agoTrue, but only now is getting static compilation to native core. There were Bartok, mono -aot, Cosmo OS, but it seems if it isn't part of the reference platform, developers tend to ignore them. I have meet a few .NET devs unaware of NGEN.
- seanmcdirmid 12y agoNGEN is a detail. If you don't care about it, it can remain an obscure detail :)
- mike_hearn 12y agoApparently 20 years detour was needed to go back to those features. I think this is explainable by Java's history. When it was created, the design docs said Java was a simple, interpreted language with distributed objects and the target hardware was set top boxes. When Java unexpectedly took off, I suspect Sun weren't quite sure which ingredients were key to that success but fixated on "simple". They unlocked a huge market that was unserved at the time: companies that needed a much simpler C++. So that wasn't unreasonable. They then spent many years trying to handle customer requests for ever more runtime speed, whilst simultaneously not making Java as complex as C++. Hence the focus on super whizzy optimisations inside HotSpot ... many of which are just undoing performance hits introduced by the simplicity of the Java language. Value types increase the complexity of the language, no doubt about it. Heck, even having a difference between int and Integer increases complexity. When value types come out, I expect much rejoicing from people who need more runtime speed, and a whole lot of confused questions on Stack Overflow from people who aren't totally sure about the difference between a value type and a regular class. I also expect to come across codebases where classes were turned into value types more or less at random, or where the style code forbids value types entirely, etc. Java sort of has this problem already where weaker programmers who are using threads just slap synchronized keywords on every method until the crashes stop. Then HotSpot goes in and tries to figure out if the locks are actually needed or not and removes them at runtime. Don't get me wrong. I'm A++++ in favour of having value types on the JVM and in Java. But increasing complexity of the language is absolutely not cost free, especially not given Java's value proposition to big corporates.