-
Notifications
You must be signed in to change notification settings - Fork 781
add a caching mechanism for the getMethodFromName function on the VMJ9Server #23183
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
add a caching mechanism for the getMethodFromName function on the VMJ9Server #23183
Conversation
|
Note, it will be a while before this is merged, as testing needs to be done to demonstrate an actual performance improvement. |
|
A quick explanation ContextOne of the VM methods that JITServer requires It seems like all calls to this method just reference hard-coded strings. However, from this issue (https://github.ibm.com/runtimes/rt-tr-control-repo/issues/24), it seems like this message is sent hundreds of times. While this is a very small amount in the grand scheme of things
Actual Implementation
|
mpirvu
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the code run? You are missing the initialization of the newly created monitor which should cause a crash.
Also, your code always creates a local copy of the new hashtable, thus the hit rate is going to be 0.
I am also concerned about the overhead of scanning the entire hashtable for every class that gets unloaded (O(m*n)) while holding the romMapMonitor. This is probably the most contended monitor at the server.
c53037d to
e26efad
Compare
mpirvu
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apart from the smaller inline suggestions, there are some bigger concerns with the current implementation.
- A name does not uniquely determine a method. You can have a class being loaded by two different classloaders, so the resulting j9class entities will have the same class name (and same method names) but their are considered different otherwise. If you look at the existing code, when we retrieve a class from its name we also specify the classloader (e.g
PersistentUnorderedMap<ClassLoaderStringPair, TR_OpaqueClassBlock*> _classBySignatureMap; - Not all classes are cached by the server. Your code could cache a {name --> j9method} mapping and the code that needs to delete the mapping (because of a class unload) will not be able to find it (because you cannot find the j9class, so you cannot find the name).
- For a large application there could be a very large number of methods cached and the keys (composed of 3 std::strings) could also be large. This may end-up taking too much memory, especially relative to the improvement that this feature is going to provide (TBD).
| for (auto it = _methodByNameMap.begin(); it != _methodByNameMap.end();) | ||
| { | ||
| MethodSignatureTriplet tpl = it->first; | ||
| std::string methodClassName = tpl.second; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be a const reference to avoid creating another string. Even the triplet tpl can be a const reference.
| for (int i = 0; i < methodClassName.length(); ++i) | ||
| { | ||
| if (unloadedClassNameUTF8->data[i] != methodClassName[i]) | ||
| { | ||
| classNamesMatch = false; | ||
| break; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could use memcmp which may be optimized internally.
|
Ignoring the functional issues mentioned above, it would be interesting to get a feel for the hit rate of this proposed cache. If the hit rate is not very high (75+%) the complications and overhead of the implementation may not be worthwhile. |
|
Here's my proposed design (which still needs to be validated from performance point of view): We can delete the JITServer implementation of For deleting from the |
In order to reduce the messages sent between the JITServer and Client, we introduce a caching mechanism for calls
fe->getMethodFromName(...)as overloaded by VMJ9Server.cpp