RFR: 8195972: Refactor oops in JNI to use the Access API (original) (raw)
Erik Ă–sterlund erik.osterlund at oracle.com
Thu Mar 29 13:54:08 UTC 2018
- Previous message: RFR: 8195972: Refactor oops in JNI to use the Access API
- Next message: RFR: 8195972: Refactor oops in JNI to use the Access API
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Hi Kim,
On 2018-03-29 01:35, Kim Barrett wrote:
On Mar 28, 2018, at 9:40 AM, Erik Ă–sterlund <erik.osterlund at oracle.com> wrote:
Hi Kim, I noticed that jobjects are now INCONCURRENTROOT in this patch. I wonder if this is the right time to upgrade them to INCONCURRENTROOT. Until there is at least one GC that actually scans these concurrently, this will only impose extra overheads (unnecessary G1 SATB-enqueue barriers on the store required to release jobjects) with no obvious gains. The platform specific code needs to go along with this. I have a patch out to generalize interpreter code. In there, I am treating resolve jobject as a normal strong root. That would probably need to change. It is also troubling that jniFastGetField shoots raw loads into (hopefully) the heap, dodging all GC barriers, hoping that is okay. I wonder if starting to actually scan jobjects concurrently would force us to disable that optimization completely to be generally useful to all collectors. For example, an INCONCURRENTROOT load access for ZGC might require a slowpath. But in jniFastGetField, there is no frame, and hence any code that runs in there must not call anything in the runtime. Therefore, with INCONCURRENTROOT, it is not generally safe to use jniFastGetField, without doing... something about that code. I would like to hear your thoughts about this. Perhaps the intention is just to take incremental steps towards being able to scan jobjects concurrently, and this is just the first step? Still, I would be interested to hear about what you think about the next steps. If we decide to go with INCONCURRENTROOT now already, then I should change my interpreter changes that are out for review to do the same so that we are consistent. Otherwise, this looks great, and I am glad we finally have jni handles accessorized. With this change in place I think it should be straight-forward for G1 to do JNI global handle marking concurrently, rather than during a pause. This change does come with some costs. (1) For G1 (and presumably Shenandoah), a SATB enqueue barrier when setting a global handle's value to NULL as part of releasing the handle. (2) For other collectors, selection between the above barrier and do-nothing code. (3) For ZGC, a read barrier when resolving the value of a non-weak handle. (4) For other collectors (when ZGC is present), selection between the above barrier and do-nothing code. (1) and (2) are wasted costs until G1 is changed to do that marking concurrently. But the cost is pretty small. I think (3) and (4) don't apply to the jdk repo yet. And even in the zgc repo the impact should be small. All of these are costs that we expect to be taking eventually anyway. The real costs today are that we're not getting the pause-time benefit from these changes yet.
Fair enough.
Even those (temporary) costs could be mitigated if we weren't forced to use the overly generic INCONCURRENTROOT decorator, and could instead provide more precise information to the GC-specific backends (e.g. something like INJNIGLOBALROOT), letting each GC defer its extra barrier work until the changes to get the pause-time benefits are being made.
Sure. But I'd like to avoid overly specific decorators that describe the exact root being accessed, rather than its semantic properties, unless there are very compelling reasons to do so.
I'd forgotten about jniFastGetField. This was discussed when Mikael and I were adding the jweak tag support. At the time it was decided it was acceptable (though dirty) for G1 to not ensure the base object was kept alive when fetching a primitive field value from it.
http://mail.openjdk.java.net/pipermail/hotspot-dev/2017-March/026231.html I suspect that choice was driven by the difficulties you noted, and knowing that something better to solve all our problems (Access!) was coming soon :) Unfortunately, that (among other things here) really doesn't work for ZGC, even though it seems okay for all the other collectors, at least for now. Any idea how important an optimization jniFastGetField might be? How bad would it be to turn it off for ZGC?
I have no idea what the cost would be of turning it off. But I feel more compelled to fix it so that we do not have to turn it off. Should not be impossible, but can be done outside of this RFE.
For the interpreter, I think you are referring to 8199417? I hadn't looked at that before (I'll try to review it tomorrow). Yes, I think those should be using INCONCURRENTROOT too, so that eventually ZGC can do JNI global marking concurrently.
Yeah.
And there are two other pre-existing uses of INCONCURRENTROOT, both of which seem suspicious to me.
- In ClassLoaderData::removehandle() we have // This root is not walked in safepoints, and hence requires an appropriate // decorator that e.g. maintains the SATB invariant in SATB collectors. RootAccess::oopstore(ptr, oop(NULL)); But there aren't any corresponding INCONCURRENTROOT loads, nor is the initializing store (CLD::ChunkedHandleList::add), which seems inconsistent. (To be pedantic, the initializing store should probably be using the new RootAccess rather than a raw store.) Oh, the load is OopHandle::resolve; and I think OopHandle is still pending accessorizing (and probably needs the access.inline.hpp cleanup...). - In InstanceKlass::klassholderphantom() we have return RootAccess<INCONCURRENTROOT | ONPHANTOMOOPREF>::oopload(addr); My understanding of it is that INCONCURRENTROOT is not correct here. I think this is similar to jweaks, where I only used ONPHANTOMOOPREF.
Yes, that sounds like it should be fixed in separate RFEs.
Your JNI handle changes look good.
Thanks, /Erik
- Previous message: RFR: 8195972: Refactor oops in JNI to use the Access API
- Next message: RFR: 8195972: Refactor oops in JNI to use the Access API
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]