RFR: 8278125: Some preallocated OOMEs are missing stack trace [v2]

David Holmes dholmes at openjdk.java.net
Fri Dec 17 02:36:26 UTC 2021


On Wed, 15 Dec 2021 16:52:32 GMT, Coleen Phillimore <coleenp at openjdk.org> wrote:

>> src/hotspot/share/memory/universe.cpp line 597:
>> 
>>> 595:   const char * msg_str = java_lang_String::as_utf8_string(msg_oop);
>>> 596:   return strcmp(msg, msg_str) == 0;
>>> 597: }
>> 
>> Yes, I agree with David about strcmp.  Could you add this instead (it was trying to compare the oops for equality, and unintentionally generated a new one).
>> 
>> oop Universe::is_out_of_memory_error_metaspace(oop exception) {
>>   return out_of_memory_errors()->obj_at(_oom_metaspace)) == exception;
>> }
>
> Ok, I see how this isn't right, but I still don't like the strcmp.  Can the string be interned and checked for equality?  Otherwise you also need a ResourceMark here.

We are comparing a `char*` and a Java String (the message from the Exception oop), so we either convert the Java String to a `char*` and compare them with `strcmp` as shown; or we turn the incoming `char*` into a Java String and then use `java_lang_String::equals`. The latter is an expensive operation and more importantly creating the String requires an allocation when we are trying to throw an OutOfMemoryError! So I don't see a reasonable alternative to the `strcmp`.

-------------

PR: https://git.openjdk.java.net/jdk/pull/6672


More information about the hotspot-runtime-dev mailing list