8 ms·
Close Encounters of the Java Memory Model Kind
- banku_brougham 10y agoi barely know some java, and i have heard of concurrency and locks, and probably understand the idea of thrrads. yet, i found this to be a thoroughly enjoyable and mysterious read!
- kovrik 10y agoAleksey Shipilev is a great developer and writer. His articles are must read!
- zalg0 10y agoThat zalgo toward the end made me smile.
- ajkjk 10y agoI'm not done reading this yet, but I have a "does this have a name/does this exist"-type question after reading the jcstress example (section 1.1): It seems like it would be possible to enumerate all interesting orderings of several threads running at once at the threading-engine level, and therefore do this kind of probabilistic test deterministically. Of course, the number of possible orderings of two n-length programs is very high (2n choose n, since 2n instructions are run in total and you can place the n instructions in one thread first). But the language definition also provides some concept of 'commuting' operations. For example, unrelated writes to two different variables can't have their orderings matter. That should cut down the number of orderings a great deal. And it's possible useful even if it it's only practical for small programs with few total orderings. Is there a language or framework that does something like this?
- BenoitP 10y agoI don't know if this answers your question. I feel like it is about enumerating the possible states your program can be in. You could model it in TLA+, which is about Temporal Logic of Actions; a good fit for modeling the happens-before. There are some nice visualizations associated with a checked model: https://www3.hhu.de/stups/prob/index.php/State_space_visualization_examples https://www3.hhu.de/stups/prob/index.php/State_space_visuali...
- jstclair 10y agoSounds like you're describing Microsoft Research's CHESS (2007), and a host of related projects (Google's ThreadWeaver for Java). See http://research.microsoft.com/en-us/projects/chess/ http://research.microsoft.com/en-us/projects/chess/ and https://code.google.com/archive/p/thread-weaver/wikis/UsersGuide.wiki https://code.google.com/archive/p/thread-weaver/wikis/UsersG...
- jkot 10y agoI made blogpost about thread weaver some time ago. Not very useful http://www.mapdb.org/news/thread_weaver/ http://www.mapdb.org/news/thread_weaver/
- Roboprog 10y agoWow. That made my head hurt. And, I'm more convinced than ever before that threads remain a TERRIBLE idea. Maybe Java 13 will have something like Erlang tasks with isolated memory and message queues (only) or something... Somehow I expected more on memory allocation, arrangement or whatnot, rather than concurrency access. Glad I clicked on it for the nightmarish skim, though.
- chrisseaton 10y agoThis isn't what a normal programmer using threads is supposed to do. Most people using threads are expected to use locks, concurrent data structures and higher level tools. This is all about covering behaviour for very low level programs and language implementations which don't use these tools.
- fpoling 10y agoThe current situation with just few cores is temporary. In future CPU with massive numbers of cores will be a norm and Erlang model will be very natural. Also things like transactional memory should make life easier.
- sievebrain 10y agoComplicated things are not inherently terrible ideas: your CPU is complex, but you have compilers to abstract you from it. Likewise the ways your multi-core machine shares memory is complicated, and the JMM partly abstracts it, but really you're meant to use much higher level constructs. The JMM matters to people writing lock libraries and compilers, not ordinary users. It's a common logical fallacy that you can simplify a complex solution by simply redefining the problem it solves as not a problem. The "Erlang model" you discuss is in fact the model the entire computing world used before threads were invented and there were only processes. But threads weren't invented for shits and giggles, they were invented for good reasons!
- pawadu 10y agowell said (written)!
- 10y ago
- abalone 10y agoI wonder whether Java will get displaced by Swift on the server at some point. Anyone want to place bets? No garbage collection, so no GC performance hiccups. No explicit threading for easier concurrency.[1] Optionals for protection from null pointer exceptions. These are 3 of the biggest problems in server-side Java programming, I'd say. That's before we even get to the elegance of the syntax. [1] https://developer.ibm.com/swift/2016/02/22/talking-about-swift-concurrency-on-linux/ https://developer.ibm.com/swift/2016/02/22/talking-about-swi...
- johncolanduoni 10y ago> No garbage collection, so no GC performance hiccups. If your models are naturally highly cyclic, dropping a GC can vary from painful to near impossible. I think a better solution for most server-side code (from both an ease of use and performance standpoint) is to use a hybrid GC/arena approach, centered around tasks. If most of your work and memory churn centers around discrete and relatively short-lived requests, you can allocate all objects whose lifetimes are bounded by the duration of the transaction in a thread-local arena. You can't beat unsynchronized bump-pointer allocation, and you can simply throw the memory away at the end. I've been really disappointed with the lack of innovation in the memory management space. Rust is the only recent language I've seen that did something more significant than choose between GC and reference-counting.
- abalone 10y agoPainful in terms of what?
- johncolanduoni 10y agoJumping through hoops and hoping you put enough weak pointers. Such structures, if they are getting mutated, also tend to take significant performance hits even if you get it right, because of all the synchronized increment/decrementing. Another place where this can really hurt is "reactive" approaches, where cycles are very hard to avoid. Weak delegates (like what WinRT uses for events) can help here, but they raise a number of complications. The biggest is that they compose poorly: if you have an intermediary in your event chain, you need to make sure the subscription is the only place where a reference is being held.
- fpoling 10y agoI recently talked with a Microsoft engineer and his observation was that a lot of MS customers have troubles running their C# code on ARM. As with Java C# does not guarantee much beyond stating that word-sized writes are atomic allowing a lot of reordering. However, Intel CPU are nice to developers allowing a lot of buggy code to work, but ARM is not forgiving resulting in a really hard to track bugs.
- Sarkie 10y agoI have a task coming up about reducing the memory of some WebLogic Java applications, I'm not very familiar with Java. Does anyone suggest a book / site / tool I can use? Currently they have Min/Max/ 4 GB and Object 2 GB for the Java args and I want to delve into it to see more about actual memory use etc.