Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for compiling Windows on VS2017 #1697

Closed
pshipton opened this issue Apr 16, 2018 · 72 comments
Closed

Support for compiling Windows on VS2017 #1697

pshipton opened this issue Apr 16, 2018 · 72 comments

Comments

@pshipton
Copy link
Member

OpenJDK is modifying Windows compilation for Java 11+ to use VS2017 and OpenJ9 should support the same.

https://bugs.openjdk.java.net/browse/JDK-8201267

See also #1684

@irinarada
Copy link

Do we have an outlook for starting this?

@DanHeidinga DanHeidinga added this to the Release 0.10.0 milestone Jun 5, 2018
@ChengJin01
Copy link

I will check it out to see how to get this work.

@ChengJin01
Copy link

After fixing the setting issues with jre-image, paths to MSVC, etc, I am currently working on other issues in config/mk scripts captured during compilation.

@ChengJin01
Copy link

Currently it ended up with linking failure on unresolved external symbols as follows:

x86_64-w64-mingw32-g++ -O3 -DWIN32 -D_WIN32 -DOMR_OS_WINDOWS -D_AMD64_=1 -DWIN64 -D_WIN64 -DJ9HAMMER -D_CRT_SECURE_NO_WARNINGS -DCRTAPI1=_cdecl -DCRTAPI2=_cdecl -D_WIN95 -D_WIN32_WINDOWS=0x0500 -D_WIN32_DCOM -D_WIN32_IE=0x0500 -DWINVER=0x0501 -D_WIN32_WINNT=0x0501 -D_MT -D_WINSOCKAPI_ -D_DLL -I. -I../include -I../oti -I../util -I../gc_include -I../omr/gc/include -I../shared_common/include -I../gc_glue_java -I../nls -I../omr/include_core  -I../oti/mingw   -mdll -mwin32 -mthreads -fno-rtti -fno-threadsafe-statics -fno-strict-aliasing -fno-exceptions -fno-use-linker-plugin -fno-asynchronous-unwind-tables -DUT_DIRECT_TRACE_REGISTRATION -DTR_HOST_X86 -c BytecodeInterpreter.cpp -o BytecodeInterpreter.obj
...
link  /debug  /opt:icf /opt:ref /INCREMENTAL:NO /NOLOGO  -entry:_DllMainCRTStartup -dll  -machine:AMD64 \
  -subsystem:console -out:../j9vm29.dll -map:j9vm.map \
   copyright.obj AsyncMessageHandler.obj BytecodeInterpreter.obj ClassInitialization.obj DebugBytecodeInterpreter.obj
...
BytecodeInterpreter.obj : error LNK2019: unresolved external symbol __imp___iob_func referenced in function _ZN22VM_BytecodeInterpreter3runEP10J9VMThread
DebugBytecodeInterpreter.obj : error LNK2001: unresolved external symbol __imp___iob_func
MHInterpreter.obj : error LNK2001: unresolved external symbol __imp___iob_func
../j9vm29.dll : fatal error LNK1120: 1 unresolved externals

It seems the failure was triggered when linking (VS2017) the .obj files (compiled by mingw) with non-existent functions in libraries in VS2017 (___iob_func was already renamed to acrt_iob_func since VS2015)

Here's typical explanations online of what happens to "unresolved external symbol __imp___iob_func"
[1] https://stackoverflow.com/questions/30412951/unresolved-external-symbol-imp-fprintf-and-imp-iob-func-sdl2
[2] https://msdn.microsoft.com/en-us/library/bb531344.aspx#BK_CRT

There are a bunch of discussions on "unresolved external symbol __imp___iob_func" but none of them works for our case (tried with legacy_stdio_definitions.lib but didn't work. might be in the wrong way?)

I am wondering whether it is possible to get the linker (VS2017) to pick up the static libraries ( __imp___iob_func) supported in mingw.

@pshipton
Copy link
Member Author

We can try compiling the BytecodeInterpreter with VS2017 instead of mingw. Perhaps it will work, even though 2010 and 2013 do not.

As I recall 2010 and 2013 can't compile BytecodeInterpreter with optimization enabled. It compiles with -O0 but then we have stack related problems at runtime.

@dnakamura
Copy link
Contributor

THe issue is that by default the new VS uses a bunch of inlined functions for CRT functions, but mingw doesnt pick them up. IIRC this can be fixed by setting the VS12AndHigher flag in the buildspec.
@pshipton it will compile with 2017, but with optimizations disabled. (enabling still results in a hang)

@ChengJin01
Copy link

ChengJin01 commented Jun 16, 2018

To verify the suggestion above, I made the following changes:

1) /buildspecs/win_x86-64_cmprssptrs.spec
	<flags>
		<flag id="build_VS12AndHigher" value="true"/>  <--- enable VS12AndHigher
2) /runtime/makelib/targets.mk.win.inc.ftl
CFLAGS+=$(UMA_OPTIMIZATION_FLAGS)
CXXFLAGS+=$(UMA_OPTIMIZATION_FLAGS)
ifdef USE_MINGW
	ifdef VS12AndHigher  (already set up in /runtime/makelib/mkconstants.mk.ftl)
		MINGW_CXXFLAGS+=-O0  <----- optimization disabled
	else
		MINGW_CXXFLAGS+=-O3
	endif
endif

However, it still ended up with the same linking failures as follows:

x86_64-w64-mingw32-g++ -O0 -DWIN32 -D_WIN32 -DOMR_OS_WINDOWS -D_AMD64_=1 -DWIN64 -D_WIN64 -DJ9HAMMER -D_CRT_SECURE_NO_WARNINGS -DCRTAPI1=_cdecl -DCRTAPI2=_cdecl -D_WIN95 -D_WIN32_WINDOWS=0x0500 -D_WIN32_DCOM -D_WIN32_IE=0x0500 -DWINVER=0x0501 -D_WIN32_WINNT=0x0501 -D_MT -D_WINSOCKAPI_ -D_DLL -I. -I../include -I../oti -I../util -I../gc_include -I../omr/gc/include -I../shared_common/include -I../gc_glue_java -I../nls -I../omr/include_core  -I../oti/mingw   -mdll -mwin32 -mthreads -fno-rtti -fno-threadsafe-statics -fno-strict-aliasing -fno-exceptions -fno-use-linker-plugin -fno-asynchronous-unwind-tables -std=c++0x -D_CRT_SUPPRESS_RESTRICT -DVS12AndHigher -D_M_X64 -DUT_DIRECT_TRACE_REGISTRATION -DTR_HOST_X86 -c BytecodeInterpreter.cpp -o BytecodeInterpreter.obj
x86_64-w64-mingw32-g++ -O0 -DWIN32 -D_WIN32 -DOMR_OS_WINDOWS -D_AMD64_=1 -DWIN64 -D_WIN64 -DJ9HAMMER -D_CRT_SECURE_NO_WARNINGS -DCRTAPI1=_cdecl -DCRTAPI2=_cdecl -D_WIN95 -D_WIN32_WINDOWS=0x0500 -D_WIN32_DCOM -D_WIN32_IE=0x0500 -DWINVER=0x0501 -D_WIN32_WINNT=0x0501 -D_MT -D_WINSOCKAPI_ -D_DLL -I. -I../include -I../oti -I../util -I../gc_include -I../omr/gc/include -I../shared_common/include -I../gc_glue_java -I../nls -I../omr/include_core  -I../oti/mingw   -mdll -mwin32 -mthreads -fno-rtti -fno-threadsafe-statics -fno-strict-aliasing -fno-exceptions -fno-use-linker-plugin -fno-asynchronous-unwind-tables -std=c++0x -D_CRT_SUPPRESS_RESTRICT -DVS12AndHigher -D_M_X64 -DUT_DIRECT_TRACE_REGISTRATION -DTR_HOST_X86 -c DebugBytecodeInterpreter.cpp -o DebugBytecodeInterpreter.obj
In file included from BytecodeInterpreter.hpp:41:0,
                 from BytecodeInterpreter.cpp:94,
                 from DebugBytecodeInterpreter.cpp:25:
../include/ffi.h:85:0: warning: "LONG_LONG_MAX" redefined
 #   define LONG_LONG_MAX __LONG_LONG_MAX__

In file included from /usr/lib/gcc/x86_64-w64-mingw32/6.4.0/include-fixed/limits.h:168:0,
                 from /usr/lib/gcc/x86_64-w64-mingw32/6.4.0/include-fixed/syslimits.h:7,
                 from /usr/lib/gcc/x86_64-w64-mingw32/6.4.0/include-fixed/limits.h:34,
                 from ../include/ffi.h:76,
                 from BytecodeInterpreter.hpp:41,
                 from BytecodeInterpreter.cpp:94,
                 from DebugBytecodeInterpreter.cpp:25:
/usr/x86_64-w64-mingw32/sys-root/mingw/include/limits.h:63:0: note: this is the location of the previous definition
 #define LONG_LONG_MAX 9223372036854775807ll

In file included from BytecodeInterpreter.hpp:41:0,
                 from BytecodeInterpreter.cpp:94:
../include/ffi.h:85:0: warning: "LONG_LONG_MAX" redefined
 #   define LONG_LONG_MAX __LONG_LONG_MAX__

In file included from /usr/lib/gcc/x86_64-w64-mingw32/6.4.0/include-fixed/limits.h:168:0,
                 from /usr/lib/gcc/x86_64-w64-mingw32/6.4.0/include-fixed/syslimits.h:7,
                 from /usr/lib/gcc/x86_64-w64-mingw32/6.4.0/include-fixed/limits.h:34,
                 from ../include/ffi.h:76,
                 from BytecodeInterpreter.hpp:41,
                 from BytecodeInterpreter.cpp:94:
/usr/x86_64-w64-mingw32/sys-root/mingw/include/limits.h:63:0: note: this is the location of the previous definition
 #define LONG_LONG_MAX 9223372036854775807ll

x86_64-w64-mingw32-g++ -O0 -DWIN32 -D_WIN32 -DOMR_OS_WINDOWS -D_AMD64_=1 -DWIN64 -D_WIN64 -DJ9HAMMER -D_CRT_SECURE_NO_WARNINGS -DCRTAPI1=_cdecl -DCRTAPI2=_cdecl -D_WIN95 -D_WIN32_WINDOWS=0x0500 -D_WIN32_DCOM -D_WIN32_IE=0x0500 -DWINVER=0x0501 -D_WIN32_WINNT=0x0501 -D_MT -D_WINSOCKAPI_ -D_DLL -I. -I../include -I../oti -I../util -I../gc_include -I../omr/gc/include -I../shared_common/include -I../gc_glue_java -I../nls -I../omr/include_core  -I../oti/mingw   -mdll -mwin32 -mthreads -fno-rtti -fno-threadsafe-statics -fno-strict-aliasing -fno-exceptions -fno-use-linker-plugin -fno-asynchronous-unwind-tables -std=c++0x -D_CRT_SUPPRESS_RESTRICT -DVS12AndHigher -D_M_X64 -DUT_DIRECT_TRACE_REGISTRATION -DTR_HOST_X86 -c MHInterpreter.cpp -o MHInterpreter.obj
In file included from MHInterpreter.hpp:26:0,
                 from MHInterpreter.cpp:29:
../include/ffi.h:85:0: warning: "LONG_LONG_MAX" redefined
 #   define LONG_LONG_MAX __LONG_LONG_MAX__

In file included from /usr/lib/gcc/x86_64-w64-mingw32/6.4.0/include-fixed/limits.h:168:0,
                 from /usr/lib/gcc/x86_64-w64-mingw32/6.4.0/include-fixed/syslimits.h:7,
                 from /usr/lib/gcc/x86_64-w64-mingw32/6.4.0/include-fixed/limits.h:34,
                 from ../include/ffi.h:76,
                 from MHInterpreter.hpp:26,
                 from MHInterpreter.cpp:29:
/usr/x86_64-w64-mingw32/sys-root/mingw/include/limits.h:63:0: note: this is the location of the previous definition
 #define LONG_LONG_MAX 9223372036854775807ll

lib -subsystem:console -out:../lib/j9vm.lib -def:j9vm.def -machine:AMD64 copyright.obj AsyncMessageHandler.obj BytecodeInterpreter.obj ClassInitialization.obj DebugBytecodeInterpreter.obj FFITypeHelpers.obj FastJNI.obj FastJNI_com_ibm_oti_vm_VM.obj FastJNI_java_lang_Class.obj FastJNI_java_lang_ClassLoader.obj FastJNI_java_lang_J9VMInternals.obj FastJNI_java_lang_Object.obj FastJNI_java_lang_String.obj FastJNI_java_lang_System.obj FastJNI_java_lang_Thread.obj FastJNI_java_lang_Throwable.obj FastJNI_java_lang_invoke_MethodHandle.obj FastJNI_java_lang_ref_Reference.obj FastJNI_java_lang_reflect_Array.obj FastJNI_sun_misc_Unsafe.obj FlushProcessWriteBuffers.obj J9OMRHelpers.obj KeyHashTable.obj MHInterpreter.obj ModularityHashTables.obj NativeHelpers.obj ObjectFieldInfo.obj ObjectMonitor.obj OutOfLineINL_com_ibm_jit_JITHelpers.obj OutOfLineINL_java_lang_invoke_NativeMethodHandle.obj OutOfLineINL_jdk_internal_misc_Unsafe.obj StackDumper.obj VMAccess.obj annsup.obj bchelper.obj bindnatv.obj callin.obj classallocation.obj classloadersearch.obj classseg.obj classsupport.obj createramclass.obj description.obj dllsup.obj drophelp.obj exceptiondescribe.obj exceptionsupport.obj findmethod.obj gphandle.obj growstack.obj guardedstorage.obj hookableAsync.obj initsendtarget.obj intfunc.obj j9dll.obj j9vm.res javaPriority.obj jnicgen.obj jnicsup.obj jnifield.obj jniinv.obj jnimem.obj jnimisc.obj jnireflect.obj jvmfree.obj jvminit.obj jvminitcommon.obj jvmrisup.obj linearswalk.obj lockwordconfig.obj logsupport.obj lookuphelper.obj lookupmethod.obj monhelpers.obj montable.obj ownedmonitors.obj profilingbc.obj rasdump.obj rastrace.obj resolvefield.obj resolvesupport.obj romclasses.obj romutil.obj segment.obj stackswap.obj statistics.obj stringhelpers.obj swalk.obj threadhelp.obj threadpark.obj throwexception.obj ut_j9vm.obj visible.obj vmbootlib.obj vmhook.obj vmifunc.obj vmizip.obj vmphases.obj vmprops.obj vmruntimestate.obj vmthinit.obj vmthread.obj xcheck.obj xcinterp.obj  ../lib/j9thr.lib ../lib/j9hookable.lib ../lib/j9prt.lib ../lib/omrsig.lib  ../lib/j9verutil.lib ../lib/j9util.lib ../lib/j9utilcore.lib ../lib/j9stackmap.lib ../lib/j9bcv.lib ../lib/j9dyn.lib ../lib/j9simplepool.lib ../lib/j9zip.lib ../lib/ffi.lib ../lib/j9avl.lib ../lib/j9hashtable.lib ../lib/j9pool.lib ../lib/j9omr.lib
Microsoft (R) Library Manager Version 14.14.26430.0
Copyright (C) Microsoft Corporation.  All rights reserved.

   Creating library ../lib/j9vm.lib and object ../lib/j9vm.exp
../makelib/targets.mk:476: UMA_SINGLE_REBASE specified, suppressing per-directory rebase.
link  /debug  /opt:icf /opt:ref /INCREMENTAL:NO /NOLOGO  -entry:_DllMainCRTStartup -dll  -machine:AMD64 \
  -subsystem:console -out:../j9vm29.dll -map:j9vm.map \
   copyright.obj AsyncMessageHandler.obj BytecodeInterpreter.obj ClassInitialization.obj DebugBytecodeInterpreter.obj FFITypeHelpers.obj FastJNI.obj FastJNI_com_ibm_oti_vm_VM.obj FastJNI_java_lang_Class.obj FastJNI_java_lang_ClassLoader.obj FastJNI_java_lang_J9VMInternals.obj FastJNI_java_lang_Object.obj FastJNI_java_lang_String.obj FastJNI_java_lang_System.obj FastJNI_java_lang_Thread.obj FastJNI_java_lang_Throwable.obj FastJNI_java_lang_invoke_MethodHandle.obj FastJNI_java_lang_ref_Reference.obj FastJNI_java_lang_reflect_Array.obj FastJNI_sun_misc_Unsafe.obj FlushProcessWriteBuffers.obj J9OMRHelpers.obj KeyHashTable.obj MHInterpreter.obj ModularityHashTables.obj NativeHelpers.obj ObjectFieldInfo.obj ObjectMonitor.obj OutOfLineINL_com_ibm_jit_JITHelpers.obj OutOfLineINL_java_lang_invoke_NativeMethodHandle.obj OutOfLineINL_jdk_internal_misc_Unsafe.obj StackDumper.obj VMAccess.obj annsup.obj bchelper.obj bindnatv.obj callin.obj classallocation.obj classloadersearch.obj classseg.obj classsupport.obj createramclass.obj description.obj dllsup.obj drophelp.obj exceptiondescribe.obj exceptionsupport.obj findmethod.obj gphandle.obj growstack.obj guardedstorage.obj hookableAsync.obj initsendtarget.obj intfunc.obj j9dll.obj j9vm.res javaPriority.obj jnicgen.obj jnicsup.obj jnifield.obj jniinv.obj jnimem.obj jnimisc.obj jnireflect.obj jvmfree.obj jvminit.obj jvminitcommon.obj jvmrisup.obj linearswalk.obj lockwordconfig.obj logsupport.obj lookuphelper.obj lookupmethod.obj monhelpers.obj montable.obj ownedmonitors.obj profilingbc.obj rasdump.obj rastrace.obj resolvefield.obj resolvesupport.obj romclasses.obj romutil.obj segment.obj stackswap.obj statistics.obj stringhelpers.obj swalk.obj threadhelp.obj threadpark.obj throwexception.obj ut_j9vm.obj visible.obj vmbootlib.obj vmhook.obj vmifunc.obj vmizip.obj vmphases.obj vmprops.obj vmruntimestate.obj vmthinit.obj vmthread.obj xcheck.obj xcinterp.obj  ../lib/j9thr.lib ../lib/j9hookable.lib ../lib/j9prt.lib ../lib/omrsig.lib  ../lib/j9verutil.lib ../lib/j9util.lib ../lib/j9utilcore.lib ../lib/j9stackmap.lib ../lib/j9bcv.lib ../lib/j9dyn.lib ../lib/j9simplepool.lib ../lib/j9zip.lib ../lib/ffi.lib ../lib/j9avl.lib ../lib/j9hashtable.lib ../lib/j9pool.lib ../lib/j9omr.lib kernel32.lib ws2_32.lib advapi32.lib user32.lib gdi32.lib comdlg32.lib winspool.lib \
   ../lib/j9vm.exp
BytecodeInterpreter.obj : error LNK2019: unresolved external symbol __imp___iob_func referenced in function _ZN22VM_BytecodeInterpreter15i2jMHTransitionERPyRPh
DebugBytecodeInterpreter.obj : error LNK2001: unresolved external symbol __imp___iob_func
MHInterpreter.obj : error LNK2001: unresolved external symbol __imp___iob_func
../j9vm29.dll : fatal error LNK1120: 1 unresolved externals
make[5]: *** [../makelib/targets.mk:475: ../j9vm29.dll] Error 96
make[5]: Leaving directory '/cygdrive/c/temp/openj9-openjdk-jdk/build/windows-x86_64-normal-server-release/vm/vm'
make[4]: *** [makefile:146: j9vm] Error 2
make[4]: Leaving directory '/cygdrive/c/temp/openj9-openjdk-jdk/build/windows-x86_64-normal-server-release/vm'
make[3]: *** [/cygdrive/c/temp/openj9-openjdk-jdk/closed/OpenJ9.gmk:387: build-j9] Error 2
make[2]: *** [/cygdrive/c/temp/openj9-openjdk-jdk/closed/make/Main.gmk:40: j9vm-build] Error 2
make[2]: *** Waiting for unfinished jobs....

The failures shows -O0 and -DVS12AndHigher were already set up for x86_64-w64-mingw32-g++ and it works in some way but it didn't help to get these obj file linked correctly.

My understanding is that mingw does pick up the inlined CRT functions (the error above is kind of different from previous one) but it is unable to replace __imp___iob_func with the renamed acrt_iob_func or it can't find acrt_iob_func in its own lib path during compilation.

Double-checked BytecodeInterpreter.obj with dumpbin.exe tool.
It shows __imp___iob_func is still there and there is no acrt_iob_func found in the obj file:

6F9 00000000 SECT24D notype       External    | .refptr.omrthread_monitor_notify
6FA 00000000 UNDEF  notype       External     | __imp___iob_func <-----

@ChengJin01
Copy link

Also checked the directories of mingw but acrt_iob_func doesn't exist:

./sys-root/mingw/include/stdio.h:  _CRTIMP FILE *__cdecl __iob_func(void);
./sys-root/mingw/include/stdio.h:#define _iob  __iob_func()
./sys-root/mingw/include/stdio.h:#define __iob_func()   (_iob)
./sys-root/mingw/include/stdio.h:#define __iob_func()   (* __MINGW_IMP_SYMBOL(_iob))
./sys-root/mingw/include/stdio.h:#define _iob __iob_func()
./sys-root/mingw/include/stdio.h:#define stdin (&__iob_func()[0])
./sys-root/mingw/include/stdio.h:#define stdout (&__iob_func()[1])
./sys-root/mingw/include/stdio.h:#define stderr (&__iob_func()[2])

@fjeremic
Copy link
Contributor

@pshipton it will compile with 2017, but with optimizations disabled. (enabling still results in a hang)

An aside have we thought of taking advantage now that we're open source to file a bug report with Microsoft [1] on this one so it can be fixed in a future release?

[1] https://docs.microsoft.com/en-us/cpp/how-to-report-a-problem-with-the-visual-cpp-toolset

@ChengJin01
Copy link

The best case is that mingw guys upgrade their code to keep up with the stdio-related changes in VS2015/2017. However, they didn't do that as they didn't expect we to compile the code in this way.

@pshipton
Copy link
Member Author

file a bug report with Microsoft

I think @charliegracie was in communication at one point, not sure if we got as far as filing a bug.

@ChengJin01
Copy link

ChengJin01 commented Jun 16, 2018

The situation is quite similar to compiling code with an earlier version of VS (VS2010) and linking them via VS2015/2017, which most users encountered in their projects as discussed on websites.
Under such circumstance, the only solution to this issue suggested by Microsoft at https://msdn.microsoft.com/en-us/library/bb531344.aspx#BK_CRT is to compile the whole project with VS2015/2017 or modify the code involved to create a new DLL to encapsulate the usage of the library if technically possible.

<stdio.h> and <conio.h>
... ...
If your project links with static libraries that were compiled with a release of Visual C++ earlier than 2015,
the linker might report an unresolved external symbol. These errors might reference internal stdio 
definitions for _iob, _iob_func, or related imports for certain stdio functions in the form of _imp_*. 
Microsoft recommends that you recompile all static libraries with the latest version of the Visual C++
compiler and libraries when you upgrade a project. If the library is a third-party library for which source 
is not available, you should either request an updated binary from the third party or encapsulate your 
usage of that library into a separate DLL that you compile with the older version of the Visual C++ 
compiler and libraries.

@ChengJin01
Copy link

ChengJin01 commented Jun 17, 2018

Currently the build is compiled on Windows 7 in which mingw still sticks with an older version of CRT.

The link from Microsoft at https://msdn.microsoft.com/en-us/library/abx4dbyh.aspx says:

The CRT Library has been refactored into a two different binaries, a Universal CRT (ucrtbase), which contains most of the standard functionality, and a VC Runtime Library (vcruntime140), which contains the compiler-related functionality, such as exception handling, and intrinsics.

In Visual Studio 2015, the CRT has been refactored into new binaries. 
The Universal CRT (UCRT) contains the functions and globals exported by the standard C99 CRT library. 
The UCRT is now a Windows component, and ships as part of Windows 10. 
The static library, DLL import library, and header files for  the UCRT are now found in the Windows 10 
SDK.

The website of mingw-w64 at https://mingw-w64.org/doku.php#mingw-w64
shows the latest version already provides support on Windows 10 and UCRT in stdio.h

https://github.com/mirror/mingw-w64/blob/master/mingw-w64-headers/crt/stdio.h
#define stdin (__acrt_iob_func(0))
#define stdout (__acrt_iob_func(1))
#define stderr (__acrt_iob_func(2))
#endif

Given that the stuff with "stdio.h" was categorized to UCRT since VS2015, it might be worthy to try installing Cygwin with the latest mingw-w64 packages + VS2017 (plus Windows 10 SDK ? ) on Windows 10 to see whether mingw-w64 compile our code with UCRT.

@ChengJin01
Copy link

ChengJin01 commented Jun 17, 2018

It turns out the mingw64 package specified in cygwin is still an older version without UCRT support.
So I need to:

  1. reinstall cygwin without mingw64 package
  2. download the source from https://github.com/mirror/mingw-w64/ and manually configure everything in mingw64 for UCRT to see whether it works.
    or 3) install from https://sourceforge.net/projects/mingw-w64/files/?source=navbar

@ChengJin01
Copy link

ChengJin01 commented Jun 17, 2018

The new version of x86_64-w64-mingw32-g++ works good on in terms of compiling BytecodeInterpreter.cpp, DebugBytecodeInterpreter.cpp and MHInterpreter.cpp on Win 7 after installing the latest version of mingw64 downloaded from https://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win32/Personal%20Builds/mingw-builds/installer/mingw-w64-install.exe

So the root cause is that the latest cgywin didn't pick up the new version of mingw64 (which already supports UCRT). The way around this issue is to update our config/setting file (e.g./runtime/makelib/mkconstants.mk.ftl) to point to the new version of mingw64 (which is installed separately/outside of cygwin dir) rather than the outdated one installed in cygwin by default. (Note: the problem has nothing to do with Windows 10)

Will keep investigating as there are still other issues during compilation.

@dnakamura
Copy link
Contributor

dnakamura commented Jun 18, 2018

I think @charliegracie was in communication at one point, not sure if we got as far as filing a bug.

I think he sent then the prepossessed interpreter and they just laughed and said no.

@ChengJin01
Copy link

ChengJin01 commented Jun 20, 2018

Currently investigating the error related to ddrgen.
The backtrace below shows it failed to locate the offset type when parsing these .pdf files as follows:

../ddrgen --blob ../j9ddr.dat --superset ../superset.dat --blacklist blacklist --macrolist ../macroList --overrides overrides --show-empty  \
        ../j9ddr_misc29.pdb ../j9gc29.pdb ../j9jvmti29.pdb ../j9prt29.pdb ../j9shr29.pdb ../j9thr29.pdb ../j9trc29.pdb ../j9vm29.pdb ../jclse11_29.pdb
Error: pdb/PdbScanner.cpp:640 PdbScanner::setMemberOffset - Unknown offset type: 10, name: invalidByteCodeIndex
make[5]: *** [run_omrddrgen.mk:73: ../j9ddr.dat] Error 1
make[5]: Leaving directory '/cygdrive/c/temp/openj9-openjdk-jdk/build/windows-x86_64-normal-server-release/vm/ddr'

0:002> ~* k
   0  Id: 46f0.18d0 Suspend: 1 Teb: 000007ff`fffde000 Unfrozen
Child-SP          RetAddr           Call Site
00000000`0030ea20 00000001`3f32442d ddrgen!PdbScanner::setMemberOffset+0x160 [pdb\pdbscanner.cpp @ 642]
00000000`0030ea80 00000001`3f324d4a ddrgen!PdbScanner::addSymbol+0x13d [pdb\pdbscanner.cpp @ 1291]
00000000`0030eb20 00000001`3f325b03 ddrgen!PdbScanner::addChildrenSymbols+0x3da [pdb\pdbscanner.cpp @ 354]
00000000`0030ec30 00000001`3f3243e2 ddrgen!PdbScanner::createClassUDT+0x533 [pdb\pdbscanner.cpp @ 1191]
00000000`0030edc0 00000001`3f324d4a ddrgen!PdbScanner::addSymbol+0xf2 [pdb\pdbscanner.cpp @ 1288]
00000000`0030ee60 00000001`3f322709 ddrgen!PdbScanner::addChildrenSymbols+0x3da [pdb\pdbscanner.cpp @ 354] <---SymTagUDT
00000000`0030ef70 00000001`3f2f1b09 ddrgen!PdbScanner::startScan+0x1a9 [pdb\pdbscanner.cpp @ 149]
00000000`0030f010 00000001`3f342b18 ddrgen!main+0x289 [\vm\omr\ddr\tools\ddrgen\ddrgen.cpp @ 131]
00000000`0030fa10 00000000`773a59cd ddrgen!__scrt_common_main_seh+0x10c [f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl @ 283]
00000000`0030fa50 00000000`7750383d kernel32!BaseThreadInitThunk+0xd
00000000`0030fa80 00000000`00000000 ntdll!RtlUserThreadStart+0x1d

e.g. for j9ddr_misc29.pdb

ddrgen --blob ../j9ddr.dat --superset ../superset.dat --blacklist blacklist --macrolist ../macroList --overrides overrides --show-empty  ../j9ddr_misc29.pdb (FAILED)
Error: pdb/PdbScanner.cpp:644 PdbScanner::setMemberOffset - Unknown offset type: 10, name: invalidByteCodeIndex

Comparing the printing messages (from ddrgen) of j9ddr_misc29.pdb created by VS2010 and VS2017 suggests that the existing code in PdbScanner.cpp might have problem in dealing with the case of the nested SymTagUDT (only occurs in VS2017) or something new was generated in j9ddr_misc29.pdb.

@pshipton
Copy link
Member Author

@keithc-ca fyi #1697 (comment)

@ChengJin01
Copy link

ChengJin01 commented Jun 20, 2018

Here're the results from j9gc29.pdb and j9thr29.pdb:

1) ddrgen --blob ../j9ddr.dat --superset ../superset.dat --blacklist blacklist --macrolist ../macroList --overrides overrides --show-empty  ../j9gc29.pdb
Error: pdb/PdbScanner.cpp:644 PdbScanner::setMemberOffset - Unknown offset type: 10, name: _FNV_prime

2) ddrgen --blob ../j9ddr.dat --superset ../superset.dat --blacklist blacklist --macrolist ../macroList --overrides overrides --show-empty  ../j9thr29.pdb 
Error: pdb/PdbScanner.cpp:644 PdbScanner::setMemberOffset - Unknown offset type: 10, name: _FNV_prime

I didn't find any file containing "_FNV_prime" in the build compiled via VS2010 while there are a bunch of .pdb files containing _FNV_prime (including j9thr29.pdb, j9thr29.pdb) in the build compiled by VS2017. If so, I am wondering whether the new type name needs to be added in a certain config/setting file in ddrgen/pdbscanner or the existing code in setMemberOffset() should address the case.

@keithc-ca
Copy link
Contributor

Error: pdb/PdbScanner.cpp:644 PdbScanner::setMemberOffset - Unknown offset type: 10, name: invalidByteCodeIndex

According to [1], offset type 10 is LocIsConstant.

An offending field is

   static const int32_t invalidByteCodeIndex =  -1;

Perhaps we need to check whether a field is static before worrying about its offset.

[1] https://docs.microsoft.com/en-us/visualstudio/debugger/debug-interface-access/locationtype
[2] https://docs.microsoft.com/en-us/visualstudio/debugger/debug-interface-access/idiasymbol-get-locationtype

@ChengJin01
Copy link

The problem is it returns LocIsConstant for both "const" and "static const" variables, in which case there is no easy way to tell whether the current field is static or not.

@keithc-ca
Copy link
Contributor

Can you give an example of a non-static field where that happens?

@ChengJin01
Copy link

  1. e.g. I_32 minAOT;
    it shows in superset.dat:
    F|minAOT|minAOT|I32|I32

  2. e.g. const UDATA _maxObjectCount;
    it shows in superset.dat:
    F|_maxObjectCount|_maxObjectCount|U64|const U64

@keithc-ca
Copy link
Contributor

Those fields certainly have 'const' type, but they are not compile-time constants so I would not expect offset type LocIsConstant. Is that what you're seeing?

@ChengJin01
Copy link

I double-checked the superset.dat generated via VS2010 and VS2017 and it turns out
it returns LocIsStatic for "static const" variables on VS2010
it returns LocIsConstant for "static const" variables on VS2017

e.g. static const int32_t invalidByteCodeIndex = -1;
it returns LocIsStatic on VS2010
superset.dat: F|invalidByteCodeIndex|invalidByteCodeIndex|I32|const I32

That means "static" is just ignored when calling get_locationType in the case of "const static" variables.

@ChengJin01
Copy link

ChengJin01 commented Jun 20, 2018

As for a "const" variable definition, e.g. const uint32_t categoryCode;
It shows in superdat:
F|categoryCode|categoryCode|U32|const U32

It means it returns something else (e.g. LocIsThisRel, LocIsBitField, etc) for "const" variables instead of LocIsConstant. If so, the field must be a static if it returns LocIsConstant (Correct me if wrong).

Then we can safely change the code to:

PdbScanner::setMemberOffset(IDiaSymbol *symbol, Field *newField)
{
...
		case LocIsStatic:  //fall through
		case LocIsConstant :  <------------
		{
			/* Get offset of static class members. */
			newField->_isStatic = true;
                ... ...

@ChengJin01
Copy link

ChengJin01 commented Jul 17, 2018

With the latest changes above (ibmruntimes/openj9-openjdk-jdk11#3 and #2374), the compilation ended up with a module related exception after copying/rename j9vm_jdk11/jdk11_jvm.lib & .exp to vm/lib:

Compiling 4 files for BUILD_JIGSAW_TOOLS
java.lang.module.FindException: Error reading module: c:\temp\openj9-openjdk-jdk11\build\windows-x86_64-normal-server-release\jdk\modules\java.base
        at jdk.internal.module.ModulePath.readModule(java.base@9/ModulePath.java:349)
        at jdk.internal.module.ModulePath.scanDirectory(java.base@9/ModulePath.java:283)
        at jdk.internal.module.ModulePath.scan(java.base@9/ModulePath.java:231)
        at jdk.internal.module.ModulePath.scanNextEntry(java.base@9/ModulePath.java:189)
        at jdk.internal.module.ModulePath.find(java.base@9/ModulePath.java:153)
        at jdk.internal.module.SystemModuleFinders$1.lambda$find$0(java.base@9/SystemModuleFinders.java:215)
        at jdk.internal.module.SystemModuleFinders$1$$Lambda$1.000000000FD2CAE0.run(java.base@9/Unknown Source)
        at java.security.AccessController.doPrivileged(java.base@9/AccessController.java:640)
        at jdk.internal.module.SystemModuleFinders$1.find(java.base@9/SystemModuleFinders.java:216)
        at jdk.internal.module.ModuleBootstrap.boot(java.base@9/ModuleBootstrap.java:211)
        at java.lang.ClassLoader.initializeClassLoaders(java.base@9/ClassLoader.java:217)
        at java.lang.Thread.initialize(java.base@9/Thread.java:422)
        at java.lang.Thread.<init>(java.base@9/Thread.java:153)
Caused by: java.lang.module.InvalidModuleDescriptorException: called wrong accept method
        at jdk.internal.module.ModuleInfo.invalidModuleDescriptor(java.base@9/ModuleInfo.java:1092)
        at jdk.internal.module.ModuleInfo.read(java.base@9/ModuleInfo.java:134)
        at jdk.internal.module.ModulePath.readExplodedModule(java.base@9/ModulePath.java:688)
        at jdk.internal.module.ModulePath.readModule(java.base@9/ModulePath.java:319)
        ... 12 more
make[3]: *** [ExplodedImageOptimize.gmk:41: /cygdrive/c/temp/openj9-openjdk-jdk11/build/windows-x86_64-normal-server-release/jdk/_packages_attribute.done] Error 1
Administrator@JCHWINVM21 /cygdrive/c/temp/openj9-openjdk-jdk11/build/windows-x86_64-normal-server-release
$ jdk/bin/java   -version
java.lang.module.FindException: Error reading module: C:\temp\openj9-openjdk-jdk11\build\windows-x86_64-normal-server-release\jdk\modules\java.base
        at jdk.internal.module.ModulePath.readModule(java.base@9/ModulePath.java:349)
        at jdk.internal.module.ModulePath.scanDirectory(java.base@9/ModulePath.java:283)
        at jdk.internal.module.ModulePath.scan(java.base@9/ModulePath.java:231)
        at jdk.internal.module.ModulePath.scanNextEntry(java.base@9/ModulePath.java:189)
        at jdk.internal.module.ModulePath.find(java.base@9/ModulePath.java:153)
        at jdk.internal.module.SystemModuleFinders$1.lambda$find$0(java.base@9/SystemModuleFinders.java:215)
        at jdk.internal.module.SystemModuleFinders$1$$Lambda$1.00000000107B0B90.run(java.base@9/Unknown Source)
        at java.security.AccessController.doPrivileged(java.base@9/AccessController.java:640)
        at jdk.internal.module.SystemModuleFinders$1.find(java.base@9/SystemModuleFinders.java:216)
        at jdk.internal.module.ModuleBootstrap.boot(java.base@9/ModuleBootstrap.java:211)
        at java.lang.ClassLoader.initializeClassLoaders(java.base@9/ClassLoader.java:217)
        at java.lang.Thread.initialize(java.base@9/Thread.java:422)
        at java.lang.Thread.<init>(java.base@9/Thread.java:153)
Caused by: java.lang.module.InvalidModuleDescriptorException: called wrong accept method
        at jdk.internal.module.ModuleInfo.invalidModuleDescriptor(java.base@9/ModuleInfo.java:1092)
        at jdk.internal.module.ModuleInfo.read(java.base@9/ModuleInfo.java:134)
        at jdk.internal.module.ModulePath.readExplodedModule(java.base@9/ModulePath.java:688)
        at jdk.internal.module.ModulePath.readModule(java.base@9/ModulePath.java:319)
        ... 12 more

If the merged fixes are correct, then the problem might be related to the module setting at java.base (e.g. src/java.base/share/classes/module-info.java)

@ChengJin01
Copy link

ChengJin01 commented Jul 18, 2018

The detailed backtrace in java is as follows:

Administrator@JCHWINVM21 /cygdrive/c/temp/openj9-openjdk-jdk11/build/windows-x86_64-normal-server-release
$ jdk/bin/java   -version
java.lang.NullPointerException
        at java.lang.String.getBytes(java.base@9/String.java)
       ...
        at java.util.stream.ReferencePipeline.collect(java.base@9/ReferencePipeline.java:578)
        at jdk.internal.module.ModulePath.explodedPackages(java.base@9/ModulePath.java:672)
        at jdk.internal.module.ModulePath.lambda$readExplodedModule$9(java.base@9/ModulePath.java:690)
        at jdk.internal.module.ModulePath$$Lambda$2.00000000108A4450.get(java.base@9/Unknown Source)
        at jdk.internal.module.ModuleInfo.doRead(java.base@9/ModuleInfo.java:306) <------------------
        at jdk.internal.module.ModuleInfo.read(java.base@9/ModuleInfo.java:132)
        at jdk.internal.module.ModulePath.readExplodedModule(java.base@9/ModulePath.java:689)
        at jdk.internal.module.ModulePath.readModule(java.base@9/ModulePath.java:319)
        at jdk.internal.module.ModulePath.scanDirectory(java.base@9/ModulePath.java:283)
        at jdk.internal.module.ModulePath.scan(java.base@9/ModulePath.java:231)
        at jdk.internal.module.ModulePath.scanNextEntry(java.base@9/ModulePath.java:189)
        at jdk.internal.module.ModulePath.find(java.base@9/ModulePath.java:153)
        at jdk.internal.module.SystemModuleFinders$1.lambda$find$0(java.base@9/SystemModuleFinders.java:215)
        at jdk.internal.module.SystemModuleFinders$1$$Lambda$1.0000000010C90B90.run(java.base@9/Unknown Source)
        at java.security.AccessController.doPrivileged(java.base@9/AccessController.java:640)
        at jdk.internal.module.SystemModuleFinders$1.find(java.base@9/SystemModuleFinders.java:216)
        at jdk.internal.module.ModuleBootstrap.boot(java.base@9/ModuleBootstrap.java:211)
        at java.lang.ClassLoader.initializeClassLoaders(java.base@9/ClassLoader.java:217)
        at java.lang.Thread.initialize(java.base@9/Thread.java:422)
        at java.lang.Thread.<init>(java.base@9/Thread.java:153)

Looking at the code of ModuleInfo.doRead() in src/java.base/share/classes/jdk/internal/module/ModuleInfo.java

    private Attributes doRead(DataInput in) throws IOException {

       ...
        int attributes_count = in.readUnsignedShort();

        // the names of the attributes found in the class file
        Set<String> attributes = new HashSet<>();

        Builder builder = null;
        Set<String> allPackages = null;
        String mainClass = null;
        ModuleTarget moduleTarget = null;
        ModuleHashes moduelHashes = null;
        ModuleResolution moduleResolution = null;

        for (int i = 0; i < attributes_count ; i++) {
            int name_index = in.readUnsignedShort();
            String attribute_name = cpool.getUtf8(name_index);
            int length = in.readInt();

            boolean added = attributes.add(attribute_name);
            if (!added && isAttributeAtMostOnce(attribute_name)) {
                throw invalidModuleDescriptor("More than one "
                                              + attribute_name + " attribute");
            }

            switch (attribute_name) { <--------- not MODULE_PACKAGES ?

                case MODULE :
                    builder = readModuleAttribute(in, cpool, major_version);
                    break;

                case MODULE_PACKAGES :
                    allPackages = readModulePackagesAttribute(in, cpool); <--- or return null
                    break;
               ...

            }
        }
      ...
        // If the ModulePackages attribute is not present then the packageFinder
        // is used to find the set of packages
        boolean usedPackageFinder = false;
        if (allPackages == null && packageFinder != null) { <------- allPackages is null
            try {
                allPackages = packageFinder.get(); <------ exception occurred from inside
            } catch (UncheckedIOException x) {
                throw x.getCause();
            }

    private Set<String> readModulePackagesAttribute(DataInput in, ConstantPool cpool)
        throws IOException
    {
        int package_count = in.readUnsignedShort();
        Set<String> packages = new HashSet<>(package_count);
        for (int i=0; i<package_count; i++) {
            int index = in.readUnsignedShort();
            String pn = cpool.getPackageName(index); <--------- extract package name from constant pool
            boolean added = packages.add(pn);
            if (!added) {
                throw invalidModuleDescriptor("Package " + pn + " in ModulePackages"
                                              + "attribute more than once");
            }
        }
        return packages; <----- returns a set of package names
    }

Looking at src/java.base/share/classes/module-info.java (packages exist in there)

module java.base {

    exports java.io;
    exports java.lang;
    exports java.lang.annotation;
    exports java.lang.invoke;
    exports java.lang.module;
    exports java.lang.ref;
    exports java.lang.reflect;
    exports java.math;
    exports java.net;
    exports java.net.spi;
...

So it seems the failure to parse package names from java.base/module-info.class triggered the exception. Given that the exposed packages exist in java.base, I need to figure out whether
attribute_name in ModuleInfo.doRead() is set to MODULE_PACKAGES or there is any issue with constant pool or something else.

@ChengJin01
Copy link

ChengJin01 commented Jul 19, 2018

  1. I didn't spot anything abnormal with the generated module-info.class at java.base in terms of binary format as well as the original java file.

  2. The exceptions above (FindException, etc) seem to be a red herring because the compiled build failed to initialize the library jclse11_29.dll at stage 14 (JCL_INITIALIZED) with JIT off as follows:

Compiling 4 files for BUILD_JIGSAW_TOOLS
JVMJ9VM015W Initialization error for library jclse11_29(14): JVMJ9VM009E J9VMDllMain failed
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
make[3]: *** [ExplodedImageOptimize.gmk:41: /cygdrive/c/temp/openj9-openjdk-jdk11/build/windows-x86_64-normal-server-release/jdk/_packages_attribute.done] Error 1
make[2]: *** [make/Main.gmk:347: exploded-image-optimize] Error 2


Administrator@JCHWINVM21 /cygdrive/c/temp/openj9-openjdk-jdk11/build/windows-x86_64-normal-server-release
$ jdk/bin/java  -Xint -version
JVMJ9VM015W Initialization error for library jclse11_29(14): JVMJ9VM009E J9VMDllMain failed
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.

If so, it is likely jclse11_29.dll was not generated correctly during compilation or there are still problems with the corresponding config/setting for the library generation.

@ChengJin01
Copy link

Investigation shows the problem with jclse11_29 came from the code in J9SigQuitStartup as follows:

jcl/common/sigquit.c
J9SigQuitStartup(J9JavaVM * vm)
{
	PORT_ACCESS_FROM_JAVAVM(vm);

	Trc_JCL_J9SigQuitStartup_Entry();

	if (vm->sigFlags & J9_SIG_NO_SIG_QUIT) {
		/* Set if -Xrs command-line option */
		Trc_JCL_J9SigQuitStartup_Disabled();
		return 0;
	}

	if (j9sig_set_async_signal_handler(sigQuitWrapper, vm, J9PORT_SIG_FLAG_SIGQUIT)) {
		Trc_JCL_J9SigQuitStartup_Failure();
		return JNI_ERR;  <------------- failure to set up the SigQuit handler
	}

	vm->J9SigQuitShutdown = J9SigQuitShutdown;

	Trc_JCL_J9SigQuitStartup_Exit();

	return 0;
}

The problem with Initialization disappear if disabling SigQuit with -Xrs (JIT off)

Administrator@JCHWINVM21 /cygdrive/c/temp/openj9-openjdk-jdk11/build/windows-x86_64-normal-server-release
$ jdk/bin/java   -Xrs -Xint -version
openjdk version "11-internal" 2018-09-25
OpenJDK Runtime Environment (build 11-internal+0-adhoc.Administrator.openj9-openjdk-jdk11)
Eclipse OpenJ9 VM (build Fix_issues_Win_JDK11-0b1cd35e, JRE 11 Windows 7 amd64-64-Bit Compressed References 20180719_000000 (JIT disabled, AOT disabled)
OpenJ9   - 0b1cd35e
OMR      - c402a576
JCL      - 7b9095d1b6 based on jdk-11+21)

How, the issue with module-info.class still exist with JIT on:

$ jdk/bin/java   -Xrs -version
java.lang.module.FindException: Error reading module: C:\temp\openj9-openjdk-jdk11\build\windows-x86_64-normal-server-release\jdk\modules\java.base
        at jdk.internal.module.ModulePath.readModule(java.base@9/ModulePath.java:349)
        at jdk.internal.module.ModulePath.scanDirectory(java.base@9/ModulePath.java:283)
        at jdk.internal.module.ModulePath.scan(java.base@9/ModulePath.java:231)
        at jdk.internal.module.ModulePath.scanNextEntry(java.base@9/ModulePath.java:189)
        at jdk.internal.module.ModulePath.find(java.base@9/ModulePath.java:153)
        at jdk.internal.module.SystemModuleFinders$1.lambda$find$0(java.base@9/SystemModuleFinders.java:215)
        at jdk.internal.module.SystemModuleFinders$1$$Lambda$1.00000000103B9BA0.run(java.base@9/Unknown Source)
        at java.security.AccessController.doPrivileged(java.base@9/AccessController.java:640)
        at jdk.internal.module.SystemModuleFinders$1.find(java.base@9/SystemModuleFinders.java:216)
        at jdk.internal.module.ModuleBootstrap.boot(java.base@9/ModuleBootstrap.java:211)
        at java.lang.ClassLoader.initializeClassLoaders(java.base@9/ClassLoader.java:217)
        at java.lang.Thread.initialize(java.base@9/Thread.java:422)
        at java.lang.Thread.<init>(java.base@9/Thread.java:153)
Caused by: java.lang.module.InvalidModuleDescriptorException: called wrong accept method
        at jdk.internal.module.ModuleInfo.invalidModuleDescriptor(java.base@9/ModuleInfo.java:1092)
        at jdk.internal.module.ModuleInfo.read(java.base@9/ModuleInfo.java:134)
        at jdk.internal.module.ModulePath.readExplodedModule(java.base@9/ModulePath.java:688)
        at jdk.internal.module.ModulePath.readModule(java.base@9/ModulePath.java:319)
        ... 12 more

So it is hard to determine whether they came from the same root cause or they are totally different issues.

@ChengJin01
Copy link

ChengJin01 commented Jul 21, 2018

I think the root cause for unresolved external symbol to JVM_BeforeHalt/JVM_AreNestMates is that these natives not exported via j9vm/module.xml. So I made some changes as follows:

	<exports group="all">
		<export name="JNI_CreateJavaVM" />
		<export name="JNI_GetCreatedJavaVMs" />
		<export name="JNI_GetDefaultJavaVMInitArgs" />
		<export name="_JVM_GetCallerClass@8" />
		<export name="JVM_BeforeHalt" />  <----------- added from this line
		<export name="JVM_GetNestHost" />
		<export name="JVM_GetNestMembers" />
		<export name="JVM_AreNestMates" />
	</exports>

		<flags>
			<flag name="J9VM_JAVA9_BUILD" value="148"/>
			<flag name="J9VM_JCL_SE11"/>  <------------------- specify jclse11
		</flags>

The compilation ended up with the same result as copying/renaming j9vm_jdk11/jdk11_jvm.lib & .exp to vm/lib, which means copying/renaming j9vm_jdk11/jdk11_jvm.lib was incorrect or at least unnecessary.

$ jdk/bin/java -Xint -version
JVMJ9VM015W Initialization error for library jclse11_29(14): JVMJ9VM009E J9VMDllMain failed
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.

Administrator@JCHWINVM21 /cygdrive/c/temp/openj9-openjdk-jdk11/build/windows-x86_64-normal-server-release
$ jdk/bin/java  -Xrs -Xint -version
openjdk version "11-internal" 2018-09-25
OpenJDK Runtime Environment (build 11-internal+0-adhoc.Administrator.openj9-openjdk-jdk11)
Eclipse OpenJ9 VM (build Fix_issues_Win_JDK11-0b1cd35e, JRE 11 Windows 7 amd64-64-Bit Compressed References 20180720_000000 (JIT disabled, AOT disabled)
OpenJ9   - 0b1cd35e
OMR      - c402a576
JCL      - 7b9095d1b6 based on jdk-11+21)

If so, I need to double-check the generation of jclse11_29.dll as well as all related module.xml to see whether there is anything else should be fixed.

@ChengJin01
Copy link

ChengJin01 commented Jul 22, 2018

I tried two steps to narrow down the scope:

  1. compiled an older version openJDK11 (only support JVM_BeforeHalt) and openJ9 (including the setting and empty interfaces of JVM_BeforeHalt, JVM_AreNestMates, etc) and it finished without any error:
$ jdk/bin/java  -Xint  -version
openjdk version "11-internal" 2018-09-25
OpenJDK Runtime Environment (build 11-internal+0-adhoc.Administrator.v1openj9-openjdk-jdk)
Eclipse OpenJ9 VM (build Fix_issues_JDK11_Windows-2d26ff4d, JRE 11 Windows 7 amd64-64-Bit Compressed References 20180721_000000 (JIT disabled, AOT disabled)
OpenJ9   - 2d26ff4d
OMR      - d7b6d0c7
JCL      - 313973a59a based on jdk-11+17)

$ jdk/bin/java  -version
openjdk version "11-internal" 2018-09-25
OpenJDK Runtime Environment (build 11-internal+0-adhoc.Administrator.v1openj9-openjdk-jdk)
Eclipse OpenJ9 VM (build Fix_issues_JDK11_Windows-2d26ff4d, JRE 11 Windows 7 amd64-64-Bit Compressed References 20180721_000000 (JIT enabled, AOT enabled)
OpenJ9   - 2d26ff4d
OMR      - d7b6d0c7
JCL      - 313973a59a based on jdk-11+17)
  1. compiled the same version of openJDK11(only support JVM_BeforeHalt) and the latest version of openJ9 (support all JDK11 natives, including JVM_BeforeHalt, JVM_AreNestMates, etc) and it ended up with same failure as the latest version of openJDK11:
Compiling 4 files for BUILD_JIGSAW_TOOLS
java.lang.NullPointerException
        at java.util.stream.ReduceOps$3ReducingSink.begin(java.base@9/ReduceOps.java:164)
        at java.util.stream.Streams$StreamBuilderImpl.forEachRemaining(java.base@9/Streams.java:432)
        at java.util.stream.ReferencePipeline$Head.forEach(java.base@9/ReferencePipeline.java:658)
        at java.util.stream.ReferencePipeline$7$1.accept(java.base@9/ReferencePipeline.java:274)
        at java.util.stream.ReferencePipeline$3$1.accept(java.base@9/ReferencePipeline.java:195)
        at java.util.stream.ReferencePipeline$3$1.accept(java.base@9/ReferencePipeline.java:195)
        at java.util.stream.ReferencePipeline$3$1.accept(java.base@9/ReferencePipeline.java:195)
...

Administrator@JCHWINVM21 /cygdrive/c/temp/v1_1_openj9-openjdk-jdk/build/windows-x86_64-normal-server-release
$ jdk/bin/java   -version
java.lang.module.FindException: Error reading module: C:\temp\v1_1_openj9-openjdk-jdk\build\windows-x86_64-normal-server-release\jdk\modules\java.base
        at jdk.internal.module.ModulePath.readModule(java.base@9/ModulePath.java:349)
        at jdk.internal.module.ModulePath.scanDirectory(java.base@9/ModulePath.java:283)
        at jdk.internal.module.ModulePath.scan(java.base@9/ModulePath.java:231)
        at jdk.internal.module.ModulePath.scanNextEntry(java.base@9/ModulePath.java:189)

Administrator@JCHWINVM21 /cygdrive/c/temp/v1_1_openj9-openjdk-jdk/build/windows-x86_64-normal-server-release
$ jdk/bin/java  -Xint  -version
JVMJ9VM015W Initialization error for library jclse11_29(14): JVMJ9VM009E J9VMDllMain failed
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.

Administrator@JCHWINVM21 /cygdrive/c/temp/v1_1_openj9-openjdk-jdk/build/windows-x86_64-normal-server-release
$ jdk/bin/java  -Xrs  -Xint  -version
openjdk version "11-internal" 2018-09-25
OpenJDK Runtime Environment (build 11-internal+0-adhoc.Administrator.v11openj9-openjdk-jdk)
Eclipse OpenJ9 VM (build Fix_issues_Win_JDK11-0b1cd35e, JRE 11 Windows 7 amd64-64-Bit Compressed References 20180722_000000 (JIT disabled, AOT disabled)
OpenJ9   - 0b1cd35e
OMR      - c402a576
JCL      - 313973a59a based on jdk-11+17)

So the investigation above indicates:
(1) the problem has nothing to with the latest version of openJDK11
(2) the problem came from the recent changes for JDK11 in openJ9, especially the changes with nestMates.

@ChengJin01
Copy link

ChengJin01 commented Jul 24, 2018

  1. With the same old version JDK11 (only support JVM_BeforeHalt) , I manually merged the changes at Turn on nestmates spec #2270 (turn on the changes for nestMates on OpenJ9 ) to the older version of OpenJ9 ( (including the setting and empty interfaces of JVM_BeforeHalt, JVM_AreNestMates, etc) and it ended up with pretty much the same compilation failures as the result above at 2).
$ jdk/bin/java   -Xint -version  (worked but ran very slowly (over 30 secs))
openjdk version "11-internal" 2018-09-25
OpenJDK Runtime Environment (build 11-internal+0-adhoc.Administrator.v12openj9-openjdk-jdk)
Eclipse OpenJ9 VM (build Fix_issues_JDK11_Windows-2d26ff4d, JRE 11 Windows 7 amd64-64-Bit Compressed References 20180723_000000 (JIT disabled, AOT disabled)
OpenJ9   - 2d26ff4d
OMR      - d7b6d0c7
JCL      - 313973a59a based on jdk-11+17)

$ jdk/bin/java    -version
java.lang.module.FindException: Error reading module: C:\temp\v1_2_openj9-openjdk-jdk\build\windows-x86_64-normal-server-release\jdk\modules\java.base
        at jdk.internal.module.ModulePath.readModule(java.base@9/ModulePath.java:349)
        at jdk.internal.module.ModulePath.scanDirectory(java.base@9/ModulePath.java:283)
        at jdk.internal.module.ModulePath.scan(java.base@9/ModulePath.java:231)
        at jdk.internal.module.ModulePath.scanNextEntry(java.base@9/ModulePath.java:189)
        at jdk.internal.module.ModulePath.find(java.base@9/ModulePath.java:153)
        at jdk.internal.module.SystemModuleFinders$1.lambda$find$0(java.base@9/SystemModuleFinders.java:214)
        at jdk.internal.module.SystemModuleFinders$1$$Lambda$1.000000000FAFEF00.run(java.base@9/Unknown Source)
        at java.security.AccessController.doPrivileged(java.base@9/AccessController.java:640)
        at jdk.internal.module.SystemModuleFinders$1.find(java.base@9/SystemModuleFinders.java:215)
        at jdk.internal.module.ModuleBootstrap.boot(java.base@9/ModuleBootstrap.java:211)
        at java.lang.ClassLoader.initializeClassLoaders(java.base@9/ClassLoader.java:217)
        at java.lang.Thread.initialize(java.base@9/Thread.java:422)
        at java.lang.Thread.<init>(java.base@9/Thread.java:153)
  1. After removing J9VM_OPT_VALHALLA_NESTMATES in j9cfg.h.in and j9cfg.h.ftl, all problems above disappeared and the compilation finished without any error.
$ jdk/bin/java   -version  (ran vary fast (within 3 secs))
openjdk version "11-internal" 2018-09-25
OpenJDK Runtime Environment (build 11-internal+0-adhoc.Administrator.v12openj9-openjdk-jdk)
Eclipse OpenJ9 VM (build Fix_issues_JDK11_Windows-2d26ff4d, JRE 11 Windows 7 amd64-64-Bit Compressed References 20180723_000000 (JIT enabled, AOT enabled)
OpenJ9   - 2d26ff4d
OMR      - d7b6d0c7
JCL      - 313973a59a based on jdk-11+17)

$ jdk/bin/java  -Xint  -version (ran vary fast (within 3 secs))
openjdk version "11-internal" 2018-09-25
OpenJDK Runtime Environment (build 11-internal+0-adhoc.Administrator.v12openj9-openjdk-jdk)
Eclipse OpenJ9 VM (build Fix_issues_JDK11_Windows-2d26ff4d, JRE 11 Windows 7 amd64-64-Bit Compressed References 20180723_000000 (JIT disabled, AOT disabled)
OpenJ9   - 2d26ff4d
OMR      - d7b6d0c7
JCL      - 313973a59a based on jdk-11+17)

Given that turning on J9VM_OPT_VALHALLA_NESTMATES enables all code changes of nestMates, I suspect there might be code issues in the existing implementation of nestMates. If so, there is no way to fix them in our script/setting from the compilation perspective (This is the only issue left here). I will double-check all my changes so far in jdk11/OpeJ9/omr and submit them for review soon.

FYI: @tajila.

@keithc-ca
Copy link
Contributor

The issues with nestmates should go away once #2459 is merged.

@ChengJin01
Copy link

ChengJin01 commented Jul 24, 2018

After manually merging the changes at #2459, all problems with nestMates were fixed and the compilation passed without error:

...
Compiling 4 files for BUILD_JIGSAW_TOOLS
Creating images/jmods/java.datatransfer.jmod
Creating images/jmods/java.compiler.jmod
Creating images/jmods/java.instrument.jmod
Creating images/jmods/java.desktop.jmod
Creating images/jmods/java.logging.jmod
...
Creating support/demos/image/jfc/TableExample/TableExample.jar
Creating support/demos/image/jfc/TransparentRuler/TransparentRuler.jar
Creating jdk image
Stopping sjavac server
Finished building target 'all' in configuration 'windows-x86_64-normal-server-release'


Administrator@JCHWINVM21 /cygdrive/c/temp/openj9-openjdk-jdk11/build/windows-x86_64-normal-server-release/images
$ jdk/bin/java    -version
openjdk version "11-internal" 2018-09-25
OpenJDK Runtime Environment (build 11-internal+0-adhoc.Administrator.openj9-openjdk-jdk11)
Eclipse OpenJ9 VM (build Fix_issues_Win_JDK11-11410ac2, JRE 11 Windows 7 amd64-64-Bit Compressed References 20180724_000000 (JIT enabled, AOT enabled)
OpenJ9   - 11410ac2
OMR      - e2e4b67c
JCL      - a786f96b13 based on jdk-11+21)


Administrator@JCHWINVM21 /cygdrive/c/temp/openj9-openjdk-jdk11/build/windows-x86_64-normal-server-release/images
$ jdk/bin/java   -Xint    -version
openjdk version "11-internal" 2018-09-25
OpenJDK Runtime Environment (build 11-internal+0-adhoc.Administrator.openj9-openjdk-jdk11)
Eclipse OpenJ9 VM (build Fix_issues_Win_JDK11-11410ac2, JRE 11 Windows 7 amd64-64-Bit Compressed References 20180724_000000 (JIT disabled, AOT disabled)
OpenJ9   - 11410ac2
OMR      - e2e4b67c
JCL      - a786f96b13 based on jdk-11+21)

Given all issues are fixed in compilation, I will set up to run sanity test to verify its basic functionalities.

@ChengJin01
Copy link

ChengJin01 commented Jul 25, 2018

A test failure with UnsatisfiedLinkError is detected during the sanity test as follows:

Problem opening JNI library
java.lang.UnsatisfiedLinkError: j9ben (Not found in java.library.path)
        at java.lang.ClassLoader.loadLibraryWithPath(java.base@11-internal/ClassLoader.java:1678)
...
or 
Testing no deadlocks...No natives for j9vm.test.thread tests
Exception in thread "main" java.lang.UnsatisfiedLinkError: j9vm/test/thread/NativeHelpers.findDeadlockedThreads()[Ljava/lang/Thread;
        at j9vm.test.thread.FindDeadlockTest.checkDeadlocks(FindDeadlockTest.java:177)
        at j9vm.test.thread.FindDeadlockTest.testNoDeadlocks(FindDeadlockTest.java:301)
        at j9vm.test.thread.FindDeadlockTest.runTests(FindDeadlockTest.java:204)
        at j9vm.test.thread.FindDeadlockTest.main(FindDeadlockTest.java:29)
...

Look at the test code:

	static boolean checkDeadlocks(Thread[] expThreads, Object[] expObjs) {
		boolean ok = true;
		
		Thread dthreads[] = NativeHelpers.findDeadlockedThreads(); <------
		if (!FindDeadlockTest.matchThreads(dthreads, expThreads)) {
			ok = false;
		}

public class NativeHelpers {
	static {
		try {
			System.loadLibrary("j9ben");  <-------------- missing when loading
		} catch (UnsatisfiedLinkError e) {
			System.out.println("No natives for j9vm.test.thread tests");
		}
	}

Currently I am running tests with .../build/windows-x86_64-normal-server-release/images/jdk/bin

Comparison with the compiled build with openjdk8/open9 shows the j9ben.dll exists in .../build/windows-x86_64-normal-server-release/jdk/bin/compressedrefs but missing in openj9-openjdk-jdk11/build/windows-x86_64-normal-server-release/images/jdk/bin/compressedrefs

openj9-openjdk-jdk8/build/windows-x86_64-normal-server-release
$ find . -name j9ben.*
./images/j2re-image/bin/compressedrefs/j9ben.dll
./images/j2sdk-image/jre/bin/compressedrefs/j9ben.dll
./jdk/bin/compressedrefs/j9ben.dll
./vm/j9ben.dll
./vm/j9ben.pdb
./vm/lib/j9ben.exp
./vm/lib/j9ben.lib
./vm/tests/jni/j9ben.def
./vm/tests/jni/j9ben.map
./vm/tests/jni/j9ben.rc
./vm/tests/jni/j9ben.res

openj9-openjdk-jdk11/build/windows-x86_64-normal-server-release
$ find . -name  j9ben.*
./jdk/bin/compressedrefs/j9ben.dll
./vm/j9ben.dll
./vm/j9ben.pdb
./vm/lib/j9ben.exp
./vm/lib/j9ben.lib
./vm/tests/jni/j9ben.def
./vm/tests/jni/j9ben.map
./vm/tests/jni/j9ben.rc
./vm/tests/jni/j9ben.res

Looking at the dll files at jdk/bin/compressedrefs and images/jdk/bin/compressedrefs:

Administrator@JCHWINVM21 /cygdrive/c/temp/openj9-openjdk-jdk11/build/windows-x86_64-normal-server-release/jdk/bin/compressedrefs
$ ls
balloon29.dll        j9shr29.dll             jvm.dll
bcuwhite.dll         j9thr29.dll             jvmtitest.dll
bcvwhite.dll         j9thrnumanatives29.dll  management.dll
cuda4j29.dll         j9thrtestnatives29.dll  management_ext.dll
gptest.dll           j9trc29.dll             memorywatcher29.dll
hooktests.dll        j9vm29.dll              migration.dll
j9ben.dll            j9vmchk29.dll           omrsig.dll
j9ddr_misc29.dll     j9vmtest.dll            osmemory29.dll
j9dfix29.dll         j9vrb29.dll             SharedClassesNativeAgent.dll
j9dmp29.dll          j9windbg.dll            softmxtest.dll
j9gc29.dll           j9zlib29.dll            testjvmtiA.dll
j9gcchk29.dll        jclse10_29.dll          testjvmtiB.dll
j9hookable29.dll     jclse11_29.dll          testlibA.dll
j9jextract.dll       jclse7b_29.dll          testlibB.dll
j9jit29.dll          jclse9_29.dll           thrtrace.dll
j9jnichk29.dll       jcoregen29.dll          vmruntimestateagent29.dll
j9jvmti29.dll        jlmagent29.dll          win_6429.dll
j9lazyClassLoad.dll  jniargtests.dll
j9prt29.dll          jsig.dll

Administrator@JCHWINVM21 /cygdrive/c/temp/openj9-openjdk-jdk11/build/windows-x86_64-normal-server-release/images/jdk/bin/compressedrefs
$ ls
cuda4j29.dll      j9jnichk29.dll  j9vm29.dll      jvm.dll
j9dmp29.dll       j9jvmti29.dll   j9vmchk29.dll   management.dll
j9gc29.dll        j9prt29.dll     j9vrb29.dll     management_ext.dll
j9gcchk29.dll     j9shr29.dll     j9zlib29.dll    omrsig.dll
j9hookable29.dll  j9thr29.dll     jclse11_29.dll
j9jit29.dll       j9trc29.dll     jsig.dll

It seems a lot of test related dll files are missing in images/jdk/bin/compressedrefs except j9ben.dll.

@keithc-ca, I suspect the current script in openjdk11 didn't or failed to copy these dll files from /vm to the right place after improving these setting (e.g. OpenJ9.gmk). If so, the issue should be fixed to enable the test execution.

@keithc-ca
Copy link
Contributor

The JDK should have none of those tests DLLs: tests should bring their own DLLs rather than expect the JDK to have them.

@pshipton
Copy link
Member Author

We'll have to put the test libraries into images/test I expect. Then PR builds and pipeline builds will have to find them there.

@ChengJin01
Copy link

ChengJin01 commented Jul 25, 2018

I already finished the sanity test with build/windows-x86_64-normal-server-release/jdk/bin and it shows the compiled build functionally works:

TEST TARGETS SUMMARY
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
PASSED test targets:
        cmdLineTester_test_0
        cmdLineTest_J9test_0
        cmdLineTester_GCRegressionTests_2
        cmdLineTester_gcsuballoctests_0
        cmdLineTester_ignoreunrecognizedvmoptions_0
        cmdLineTester_J9securityTests_0
        cmdLineTester_jvmtitests_1
        cmdLineTester_jvmtitests_2
        cmdLineTester_jvmtitests_7
        cmdLineTester_jvmtitests_8
        cmdLineTester_jvmtitests_hcr_4
        cmdLineTester_jvmtitests_hcr_8
        cmdLineTester_jvmtitests_hcr_10
        cmdLineTester_decompilationTests_1
        decompileAtMethodResolve_0
        cmdLineTester_libpathTestRtf_0
        cmdLineTester_libpathTestRtfChild_0
        cmdLineTester_loadLibraryTests_0
        cmdLineTester_loopReduction_0
        cmdLineTester_getPid_0
        cmdLineTester_DataHelperTests_1
        testSCCMLTests1_1
        cmdLineTester_SCHelperCompatibilityTests_win_1
        cmdLineTester_ShareClassesSimpleSanity_1
        cmdLineTester_SCURLHelperTests_90_1
        cmdLineTester_SCURLClassLoaderTests_1
        cmdLineTester_SCURLClassLoaderNPTests_1
        cmdLineTester_XcheckJNI_0
        testXXArgumentTesting_0
        String_CompactStrings_0
        generalSanityTest_0
        regressionFastresolve_mode150_0
        AttachAPISanity_0
        CtorBCVTests_0
        J9VMInternals_Test_0
        JCL_Test_JITHelpers_0
        TestArrayCopy_2
        TestArrayCopy_3
        pthreadDestructor_0
        testReflectInvoke_0
        testInvokeSpecialInsideInterface_0
        reflect_getMethods_0
        NoSuchMethodTests_0
        hanoiTest_0
        memleaksTest_0
        fibTest_0
        testStringInterning_1
        floatSanityTests_0
        floatSanityTests_2
        FileSystem-isAccessUserOnlyTests_0
        Test_Class_0
        TestFlushReflectionCache_0
        TestRefreshGCSpecialClassesCache_NOBCI_0
        stringConcatOptTest_0
        jit_jitt_0
        jit_jitt_1
        jit_jitt_2
        jit_jitt_3
        jit_jar_0
        jit_tr_0
        StringPeepholeTest_0
        jit_vich_0
        JLM_Tests_class_0
        JLM_Tests_class_1
        JLM_Tests_IBMinternal_0
        JLM_Tests_IBMinternal_1
        openj9_jsr292Test_0
        openj9_jsr292Test_JitCount0_0
        SharedCPEntryInvokerTests_0
        SharedCPEntryInvokerTests_1
        UnsafeTests_0
        UnsafeTests_1

FAILED test targets:
        cmdLineTester_callsitedbgddrext_openj9_0
        cmdLineTester_GCRegressionTests_3
        testSCCMLModularity_1
        JCL_Test_0
        JCL_Test_1
        JCL_Test_OutOfMemoryError_0
        JCL_Test_OutOfMemoryError_1
        JCL_TEST_Java-Security_0
        JCL_Test_Package_0
        JLM_Tests_interface_0
        JLM_Tests_interface_1
        J9vmTest_4
        J9vmTest_5

TOTAL: 166   EXECUTED: 85   PASSED: 72   FAILED: 13   SKIPPED: 81

==========

@ChengJin01
Copy link

ChengJin01 commented Jul 25, 2018

I will prepare all changes I made in compilation for review before addressing the test failure in another issue.

@ChengJin01
Copy link

ChengJin01 commented Jul 25, 2018

All script/setting changes have been submitted for review:
OpenJDK11: ibmruntimes/openj9-openjdk-jdk11#7
OpenJ9: #2483
OMR: eclipse-omr/omr#2798

@pshipton
Copy link
Member Author

pshipton commented Sep 4, 2018

I don't think this is going to be ready for the 0.10.0 release, deferring.

@DanHeidinga
Copy link
Member

@pshipton We should be trying to contain this in the 0.10.0 release to match the compiler levels used by OpenJDK.

Is there a critical blocker preventing this from making the 0.10.0 release? If so, let's identify it and try to solve it.

@keithc-ca
Copy link
Contributor

I have been working on eclipse-omr/omr#2885 which would be a prerequisite of DDR support with that compiler.

@pshipton
Copy link
Member Author

Closing, since Java 11 Windows is now compiling with MSVC 2017.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants