JDK-8166017 : Memory leak in rt8u112-b01 BridgeUtils.cpp
  • Type: Bug
  • Component: javafx
  • Sub-Component: web
  • Affected Version: 8u112
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_7
  • CPU: x86_64
  • Submitted: 2016-09-13
  • Updated: 2016-09-14
  • Resolved: 2016-09-14
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 9
9Resolved
Related Reports
Duplicate :  
Relates :  
Description
FULL PRODUCT VERSION :


A DESCRIPTION OF THE PROBLEM :
This is a follow up for my original report - Review ID: JI-9041436.

In July 2013 a new version of webkit was merged into Java FX code base.

The older version of JSValueMakeString wouldn't make a copy:

http://hg.openjdk.java.net/openjfx/8u-dev/rt/file/bcd662ba5826/modules/web/src/main/native/Source/JavaScriptCore/API/OpaqueJSString.cpp
UString OpaqueJSString::ustring() const
{
    if (this && m_characters)
        return UString(m_characters, m_length);
    return UString();
}

http://hg.openjdk.java.net/openjfx/8u-dev/rt/file/bcd662ba5826/modules/web/src/main/native/Source/JavaScriptCore/API/JSValueRef.cpp
JSValueRef JSValueMakeString(JSContextRef ctx, JSStringRef string)
{
    ExecState* exec = toJS(ctx);
    APIEntryShim entryShim(exec);

    return toRef(exec, jsString(exec, string->ustring()));
}

But the new version of OpaqueJSString makes a copy:

http://hg.openjdk.java.net/openjfx/8u-dev/rt/file/8cbaf9096cda/modules/web/src/main/native/Source/JavaScriptCore/API/OpaqueJSString.cpp
String OpaqueJSString::string() const
{
    if (!this)
        return String();

    // Return a copy of the wrapped string, because the caller may make it an Identifier.
    return m_string.isolatedCopy();
}

http://hg.openjdk.java.net/openjfx/8u-dev/rt/file/8cbaf9096cda/modules/web/src/main/native/Source/JavaScriptCore/API/JSValueRef.cpp
JSValueRef JSValueMakeString(JSContextRef ctx, JSStringRef string)
{
    if (!ctx) {
        ASSERT_NOT_REACHED();
        return 0;
    }
    ExecState* exec = toJS(ctx);
    APIEntryShim entryShim(exec);

    return toRef(exec, jsString(exec, string->string()));
}


In BridgeUtils.cpp - Java_Object_to_JSValue never accomodated for the change and now leaks memory.

    if (env->IsInstanceOf(val, clString)) {
      JSStringRef value = asJSStringRef(env, (jstring) val);
      return JSValueMakeString(ctx, value);
    }

The "value" variable is getting cloned in JSValueMakeString, but it's never released.


REPRODUCIBILITY :
This bug can be reproduced always.


Comments
This issue is fixed as part of JDK-8161053. Regarding In BridgeUtils.cpp - Java_Object_to_JSValue never accomodated for the change and now leaks memory. if (env->IsInstanceOf(val, clString)) { JSStringRef value = asJSStringRef(env, (jstring) val); return JSValueMakeString(ctx, value); } The "value" variable is getting cloned in JSValueMakeString, but it's never released. Now this leak is fixed as below in JDK-8161053 jclass clString = getStringClass(env); if (env->IsInstanceOf(val, clString)) { - JSStringRef value = asJSStringRef(env, (jstring) val); - return JSValueMakeString(ctx, value); + JSStringRef value = asJSStringRef(env, (jstring) val); + JSValueRef jsvalue = JSValueMakeString(ctx, value); + JSStringRelease(value); + return jsvalue; } Hence closing this issue as duplicate of JDK-8161053
14-09-2016

This is a follow-on bug to JDK-8161053 (originally filed as JI-9041436). I note that JDK-8161053 was fixed in 8u112-b03, so this bug is possibly a duplicate.
14-09-2016

It seems this is NOT a regression in 8u112
14-09-2016