Skip to content

Add UTF to String cache for reflection calls - #13311

Merged
tajila merged 1 commit into
eclipse-openj9:masterfrom
gacholio:utf
Sep 22, 2021
Merged

tajila merged 1 commit into
eclipse-openj9:masterfrom
gacholio:utf

Conversation

@gacholio

@gacholio gacholio commented Aug 11, 2021 •

Copy link
Copy Markdown
Contributor

Maintain a cache of J9UTF8 pointers to the matching java String for use
in reflection, StackWalker, etc.

The cache is on by default and can be controlled on the command line via
the -XX:[+|-]UTFCache options.

Fixes: #13289

[ci skip]

Signed-off-by: Graham Chapman graham_chapman@ca.ibm.com

@gacholio

Copy link
Copy Markdown
Contributor Author

Opening this up for discussion @fjeremic @amicic @tajila @DanHeidinga

Some points:

  • using direct code in releaseExclusiveVMAccess rather than the GC cycle hooks to free the cache
  • cache grows forever until it's freed
  • missing some doc / use more descriptive function name
  • more places should use the cache?

Comment thread runtime/gc_base/StringTable.cpp Resolved
Comment thread runtime/vm/VMAccess.cpp Resolved
Comment thread runtime/gc_base/StringTable.cpp Resolved
@DanHeidinga

Copy link
Copy Markdown
Member

more places should use the cache?

jclexception.c should be re-examined as we had previously done similar improvements there:

/* Fill in method name - intern the string as it's also interned by the StackWalker API and by Reflection */
utf = J9ROMMETHOD_NAME(romMethod);
string = mmfns->j9gc_createJavaLangString(vmThread, J9UTF8_DATA(utf), (U_32) J9UTF8_LENGTH(utf), J9_STR_TENURE | J9_STR_INTERN);
if (NULL == string) {
rc = FALSE;
/* exception is pending from the call */
goto done;
}

Reflection's interning of method names / signatures is worth checking as well

@amicic

amicic commented Aug 11, 2021

Copy link
Copy Markdown
Contributor

It would be nice to have some visibility of the size. GC already reports this:

<stringconstants candidates="6088" cleared="11"  />

Perhaps we add another attribute to this line for the total size of this cache just prior to a flush? VGC changes could be a separate PR, though.

I would not mind aligning the flushing with string&monitor pruning (see scanMonitorLookupCaches, for example), rather then piggybacking on exclusive access . The cache is already somewhat visible to GC (for concurrent movement updates).

@gacholio

Copy link
Copy Markdown
Contributor Author

Planned updates:

  • rename function and move flags into it so there's no confusion
  • move clearing the hash table into the GC (so we have the option of treating this as a clearable root rather than just dumping the cache)
  • use cache in reflect code

Possibly:

  • add a maximum size and command line option to control it

@gacholio

gacholio commented Aug 18, 2021 •

Copy link
Copy Markdown
Contributor Author

Generic signature is currently not interned - it will have to be if we want it to take advantage of the cache (which is going to allocate strings only with J9_STR_INTERN and not J9_STR_XLAT).

@gacholio

Copy link
Copy Markdown
Contributor Author

@amicic I've moved the freeing code into the GC (without verbose or trace support). Can you please have a look and tell me if I need to override it in RealtimeRootScanner?

Comment thread runtime/gc_base/StringTable.cpp Resolved
@gacholio
gacholio force-pushed the utf branch 4 times, most recently from 5555646 to fbecd0e Compare August 23, 2021 17:43
Comment thread runtime/gc_base/StringTable.cpp Resolved
@gacholio

Copy link
Copy Markdown
Contributor Author

I think I will update the code handling generic signatures to use the cache (and hence intern the String). I'm sure generic signatures are common enough these days to warrant the caching.

After #13320 is merged I'll also commonize the (admittedly trivial) code that fills in the filename for Class objects.

@gacholio
gacholio force-pushed the utf branch 3 times, most recently from ab5ccaf to aed268d Compare August 27, 2021 17:08
@gacholio

Copy link
Copy Markdown
Contributor Author

@tajila What are your feelings about the infinitely growing cache? I feel adding command line controls to this might be overdesigning, as the cache is freed every GC. If we later decide to treat the cache as a clearable root, we could add the controls then.

@tajila

tajila commented Sep 16, 2021

Copy link
Copy Markdown
Contributor

Judging from this PR, it looks like the we are only populating the cache for things like method/field/class names for the purposes of reflection, stackwalking, etc. Based on this I think the risk ballooning native mem usage is low if the vmthread->utfCache is going to be cleared every time the GC scans the thread. So I don't think we need options to limit the size.

@dmitripivkine is there an easy way to collect metrics in the RootScanner code? As a defensive move we could track the size of the utfCache and add it to verbose:gc? If there is a case that we suspect the utfCache to be the issue, at least we would have the data to confirm it.

@gacholio

Copy link
Copy Markdown
Contributor Author

The verbose GC/trace has been discussed above as future work.

@gacholio
gacholio force-pushed the utf branch 4 times, most recently from 78eb86e to b203812 Compare September 16, 2021 16:48
@gacholio

Copy link
Copy Markdown
Contributor Author

I believe this is ready to go once the question about tenuring filenames is resolved.

@tajila

tajila commented Sep 17, 2021

Copy link
Copy Markdown
Contributor

Do you think we should tenure in both cases?

Yea I think we should be consistent there and tenure fileName in both stackwalker and jclexception.

I think we should also tenure JAVA_BASE_MODULE and JAVA_SPEC_VERSION_STRING in jclexception since those are attached to the lifetime of the JVM.

@gacholio

Copy link
Copy Markdown
Contributor Author

Tenuring changes made.

@gacholio

Copy link
Copy Markdown
Contributor Author

@pshipton What do I need to do to open a doc item for this?

@gacholio
gacholio force-pushed the utf branch 2 times, most recently from f9e322e to 0326786 Compare September 19, 2021 18:01
@gacholio

Copy link
Copy Markdown
Contributor Author

jenkins test sanity,extended win jdk11

@pshipton

Copy link
Copy Markdown
Member

Create an issue at https://github.com/eclipse-openj9/openj9-docs and follow the template, and then create a PR to made the doc changes. The new options page needs to be added to mkdocs.yml

@gacholio

Copy link
Copy Markdown
Contributor Author

Testing has passed. I'm going to undo a non-change (copyright only) now, but I suggest not bothering with retesting after.

Maintain a cache of J9UTF8 pointers to the matching java String for use
in reflection, StackWalker, etc.

The cache is on by default and can be controlled on the command line via
the -XX:[+|-]UTFCache options.

Fixes: eclipse-openj9#13289

[ci skip]

Signed-off-by: Graham Chapman <graham_chapman@ca.ibm.com>
@tajila

tajila commented Sep 20, 2021

Copy link
Copy Markdown
Contributor

@dmitripivkine @DanHeidinga any concerns?

@DanHeidinga DanHeidinga left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@tajila
tajila merged commit d7ee310 into eclipse-openj9:master Sep 22, 2021
@tajila

tajila commented Sep 22, 2021

Copy link
Copy Markdown
Contributor

@gacholio We will also need this in the 0.29 branch

@pshipton

pshipton commented Sep 22, 2021 •

Copy link
Copy Markdown
Member

I pushed it to the 0.29 branch, along with removing Unsafe.defineAnonymousClass() from jdk17, so we don't need to double deliver.

@gacholio
gacholio deleted the utf branch September 22, 2021 16:28
@pshipton

Copy link
Copy Markdown
Member

Change appears responsible for some intermittent internal test failures, and may also show up in the public builds. I'm going to revert until it can be fixed.

@gacholio

Copy link
Copy Markdown
Contributor Author

Can confirm that disabling the feature seems to make the problem go away.

@gacholio

Copy link
Copy Markdown
Contributor Author

Testing the probable fix now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve performance of StackWalker.walk

7 participants