JDK-4920112 : JNI_CreateJavaVM executed from DLL hangs
  • Type: Bug
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: 1.4.2
  • Priority: P3
  • Status: Closed
  • Resolution: Not an Issue
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2003-09-10
  • Updated: 2012-11-02
  • Resolved: 2003-11-12
Related Reports
Relates :  
Description

Name: gm110360			Date: 09/10/2003


FULL PRODUCT VERSION :
java version "1.4.2_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_01-b06)
Java HotSpot(TM) Client VM (build 1.4.2_01-b06, mixed mode)

FULL OS VERSION :
Microsoft Windows XP [Version 5.1.2600]

EXTRA RELEVANT SYSTEM CONFIGURATION :
Initially discovered on J2SE 1.4.1, reproduced with the latest J2SE.
Reported in the "Native Methods" Forum (with no replies): http://forum.java.sun.com/thread.jsp?forum=52&thread=437693
I found an occurrence of the same problem reported to Win2000/1.4.0 as well: http://forum.java.sun.com/thread.jsp?forum=52&thread=338124

A DESCRIPTION OF THE PROBLEM :
When called from a DLL, JNI_CreateJavaVM() never returns.
Executing JNI_CreateJavaVM() with the same initialization from the main application works as expected.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Reproduceable:
//////////////////////////////////////////
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <jni.h>
#include <memory.h>

JavaVM* jvm;
JNIEnv* env;

void CreateVM()
{
        JavaVMInitArgs args;
        JavaVMOption options[1];

        memset(&args, 0, sizeof(args));
        args.version = JNI_VERSION_1_4;
        args.nOptions = 1;
        options[0].optionString = "-Djava.class.path=<classpath>";
        args.options = options;
        args.ignoreUnrecognized = JNI_FALSE;

        //JNI_CreateJavaVM(&jvm, (void **)&env, &args);
}

BOOL APIENTRY DllMain( HANDLE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
					 )
{
    switch (ul_reason_for_call)
	{
	case DLL_PROCESS_ATTACH:
                CreateVM();
                break;
    }
    return TRUE;
}
//////////////////////////////////////////

Executing the above CreateVM() method from the main application works as expected.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
JNICreateJavaVM() should initialize the VM
ACTUAL -
Process hangs in call to JNI_CreateJavaVM()

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
See "Steps to reproduce" above.
Create a DLL from the supplied code.
---------- END SOURCE ----------
(Incident Review ID: 200738) 
======================================================================

Comments
EVALUATION This is not a bug. Applications should not call JNI_CreateJavaVM (or JNI_DestroyJavaVM, or any functions at all that use thread synchronization) from DllMain. This type of deadlock is well known and documented by Microsoft at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/dllmain.asp . ###@###.### 2003-11-12
12-11-2003