[lworld] RFR: 8335545: [lworld] JNI MonitorEnter doesn't throw the right exception

Coleen Phillimore coleenp at openjdk.org
Tue Jul 9 20:13:28 UTC 2024


On Tue, 9 Jul 2024 14:17:19 GMT, Frederic Parain <fparain at openjdk.org> wrote:

> Fix JNI's MonitorEnter to throw IdentityException instead of IllegalMonitorStateException.

I had a similar change, which I'll remove this part.

src/hotspot/share/runtime/synchronizer.cpp line 315:

> 313:     const char* className = obj->klass()->external_name(); \
> 314:     size_t msglen = strlen(desc) + strlen(className) + 1; \
> 315:     char* message = NEW_RESOURCE_ARRAY(char, msglen); \

If NEW_RESOURCE_ARRAY fails, it will call vm_exit_out_of_memory, so no need to check for nullptr.

src/hotspot/share/runtime/synchronizer.cpp line 324:

> 322:   }
> 323: 
> 324: #define CHECK_THROW_NOSYNC_IMSE(obj)  \

I added a short comment why this is needed. like:

// These checks are required for wait, notify and exit to avoid inflating the monitor to
// find out this inline type object cannot be locked.

src/hotspot/share/runtime/synchronizer.cpp line 561:

> 559:     // JITed code should never have locked an instance of a value class
> 560:     ShouldNotReachHere();
> 561:   }

You could make this an assert instead.
assert(!EnableValhalla || !obj->klass()->is_inline_klass(), "^ above comment");

Then it's self documenting.  Better than ShouldNotReachHere.

src/hotspot/share/runtime/synchronizer.cpp line 581:

> 579:   assert(current == Thread::current(), "must be");
> 580:   JavaThread* THREAD = current;
> 581:   CHECK_THROW_NOSYNC_IE(obj);

We never get here.  The c1 slow path and interpreter code check for inline types before calling this.

I added an assert.

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

Changes requested by coleenp (no project role).

PR Review: https://git.openjdk.org/valhalla/pull/1160#pullrequestreview-2167391006
PR Review Comment: https://git.openjdk.org/valhalla/pull/1160#discussion_r1671170297
PR Review Comment: https://git.openjdk.org/valhalla/pull/1160#discussion_r1671178652
PR Review Comment: https://git.openjdk.org/valhalla/pull/1160#discussion_r1671173868
PR Review Comment: https://git.openjdk.org/valhalla/pull/1160#discussion_r1671168488


More information about the valhalla-dev mailing list