JDK-8031968 : Mac OS X: VM starts the agent by calling both Agent_OnAttach and Agent_OnAttach_L functions if its agent library is dynamically linked.
  • Type: Bug
  • Component: hotspot
  • Sub-Component: jvmti
  • Affected Version: 8,9
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: os_x
  • CPU: x86_64
  • Submitted: 2014-01-16
  • Updated: 2015-03-13
  • Resolved: 2014-02-26
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 8 JDK 9
8u20 b04Fixed 9Fixed
Related Reports
Relates :  
Description
JDK 8 JVMTI spec. 1.2.3 (http://download.java.net/jdk8/docs/platform/jvmti/jvmti.html) states:
Agent Start-Up (Live phase)
...
If an agent is started during the live phase then its agent library must export a start-up function with the following prototype:
JNIEXPORT jint JNICALL 
Agent_OnAttach(JavaVM* vm, char *options, void *reserved)
Or for a statically linked agent named 'L':
JNIEXPORT jint JNICALL 
Agent_OnAttach_L(JavaVM* vm, char *options, void *reserved)
The VM will start the agent by calling this function. 
....
According to this assertion the VM will never call Agent_OnAttach_L if the function exists and the agent library is dynamically linked.

This issue causes a failure of 366 JCK 8 tests (JCK-7301996)
Error log is:
--''--
Successfully attached to JVM with id: 15050
Native agent successfully loaded:  name=jckjvmti  opts=ascl00101
Agent_OnAttach_jckjvmti entry was unexpectedly invoked
--''--
Source file that returns "failed" status is JCK-runtime-8/src/javasoft/sqe/jck/lib/jvmti/Agent.java 
Appropriate code snippet is:

if (isOnAttachMode) {
            if (isJckjvmtiStaticallyLinked) {
                if (!isAgentOnAttachForJckJvmtiInvoked()) {
                    out.println("Agent_OnAttach_jckjvmti entry was not invoked as expected\n");
                    status = STAT_FAILED;
                    return false;
                }
                if (isAgentOnAttachInvoked()) {
                    out.println("Agent_OnAttach entry was unexpectedly invoked");
                    status = STAT_FAILED;
                    return false;
                }
            } else {
                if (!isAgentOnAttachInvoked()) {
                    out.println("Agent_OnAttach entry was not invoked as expected");
                    status = STAT_FAILED;
                    return false;
                }
                if (isAgentOnAttachForJckJvmtiInvoked()) {
                    out.println("Agent_OnAttach_jckjvmti entry was unexpectedly invoked");
                    status = STAT_FAILED;
                    return false;
                }
            }

            if (isAgentOnLoadInvoked()) {
                out.println("Agent_OnLoad entry was unexpectedly invoked");
                status = STAT_FAILED;
                return false;
            }
            if (isAgentOnLoadForJckJvmtiInvoked()) {
                out.println("Agent_OnLoad_jckjvmti entry was unexpectedly invoked\n");
                status = STAT_FAILED;
                return false;
            }
        }

Note: This issue only happens on Mac OS X  (10.9.1)






  



Comments
Thanks!
26-02-2014

When the fix will be backported into 8u20?
25-02-2014

The JCK team is OK with the proposed deferral in JDK 8, with a request to address this tck-red issue as soon as possible in 8 update. Given the large # of failures, we plan to note this as a known issue in JCK 8 release notes, as described in issue JCK-7302296.
24-01-2014

366 JVMTI tests in JCK 8 won't be excluded because they pass on Mac OS in any other test execution mode that Single JVM
22-01-2014

Release team: Approved for deferral.
21-01-2014

8-defer-request: I would argue that this a very small edge case and does not pose a great problem for users. It does, however, cause many JCK tests to fail which could be a problem in and of itself since other failures may be hidden.
21-01-2014

The problem is that dlopen() works differently on OS X than on Linux/Solaris. We are using dlopen(NULL, RTLD_LAZY) to get a handle for the main program. On OS X, the call should be dlopen(NULL, RTLD_FIRST). The consequence of this is that on OS X if an agent defines Agent_OnAttach_L but is not statically linked, the JVM will not find that symbol the first time the agent is loaded (which is as expected), but the second time the same agent is loaded, the symbol will already exists in the process and now the JVM will call it (which is not expected).
21-01-2014

Adding this to critical watch list until we know more about the issue.
21-01-2014

Please, use attached script as an example. Since jck4jdk has defect (JCK-7302237) to reproduce JVMTI failures JCK will be started in gui mode. Please select: Configure/Edit Quick Set/Keywords: and set Express... to "jvmtilivephase" instead of "!only_once&!jvmti&!jvmtilivephase&!jniinvocationapi&!needsharedclassloader&!jdwp&!jplis&!jplislivephase&!interactive" Done. Run tests
20-01-2014

How do I reproduce this? I have downloaded JCK-runtime-8.jar and JCK-extra-8.zip, installed them and ran the JVMTI tests without problem. I'm missing something.
20-01-2014

The spec states: "An agent L whose image has been combined with the VM is defined as statically linked if and only if the agent exports a function called Agent_OnLoad_L." I take this to mean that if there is a Agent_OnLoad_L function, then the agent is defined as statically linked. Further: "If a statically linked agent L exports a function called Agent_OnLoad_L and a function called Agent_OnLoad, the Agent_OnLoad function will be ignored." So if there is a _L function that will be called and the Agent_OnLoad will be ignored. It looks to me like having a _L function is what defines the library as statically linked - not if it is a dynamic library or not.
17-01-2014

I agree, that if an Agent exports both Agent_OnLoad_L and Agent_OnLoad then one of them should be ignored. Unfortunately JVMTI behaviour differs for 1. Mac realization starts both functions Agent_OnLoad and Agent_OnLoad_L. 2. Linux/Solaris/Windows realization starts Agent_OnLoad and ignores Agent_OnLoad_L.
17-01-2014