Closed HKruenaegel closed 1 year ago
EXCEPTION_ACCESS_VIOLATION
is thrown when the windows kernel detects that a program tried to access memory it did not allocate, so I would assume that somewhere a pointer pointing to invalid memory is dereferenced.
Is the main you posted the entirety or did you omit something? Also what is the identification and version of your compiler?
I can't reproduce this on linux or my windows 10 laptop.
Also could you try running the unit tests? Do they fail too?
You can run the tests by doing make test
inside the cmake build directory.
Actually could you also change your main to:
using namespace jluna;
int main()
{
initialize();
Main.safe_eval("array = Int64[1, 2, 3, 4]");
Array<Int64, 1> array = Main["array"];
Int64 third = array[2];
std::cout << third << std::endl;
return 0;
}
And tell me if it still throws?
Compiler Windows SDK version 10.0.19041.0 to target Windows 10.0.19044.
jluna_test.exe gives:
[JULIA][LOG] initialization successful (1 thread(s)).
starting test...
...
Number of tests unsuccessful: 0
Yes, it is the hole main function.
It does not throw ACCESS_VIOALTION but in debug mode I see:
Unbehandelte Ausnahme bei 0x00007FF9C4D1CF19 in Jluna_test.exe: Microsoft C++-Ausnahme: jluna::JuliaException bei Speicherort 0x00000087A495F460.
At the row "return Proxy("
{
jl_sym_t* symbol = jl_symbol(field);
return Proxy(
_content.get()->get_field(symbol),
_content,
(unsafe::Value*) symbol
);
}
The jluna::JuliaException
should have a message content with the entire stacktrace, are you able to access that? Idk VS but it should print a long verbose message to the console.
Also did you try the second main?
This is the behavior of your suggested main.
Unfortunately I dont see a stacktrace. Even not in a running "hello julia" example.
Okay, thank you. Could you also give me the cmake output that happens when you build either jluna and/or your executable? I will try to look at it and see if I can reproduce this somehow.
The fact that the unit test runs through makes this very suspicious, the unit test already tests if jluna::Array
works and it clearly does there but not in your main.
Of course that is strange. Her is the output of building jluna incl. test:
PS D:\Julia\jluna\cmake> cmake .. -DJULIA_BINDIR=D:\julia-1.8.5-win64\julia-1.8.5\bin -DCMAKE_CXX_COMPILER=cl -DCMAKE_INSTALL_PREFIX=D:\Julia\Jluna_liblib
-- Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.19044.
-- Found Julia: D:/julia-1.8.5-win64/julia-1.8.5/lib/libjulia.dll.a (found suitable version "1.8.5", minimum required is "1.7.0")
-- Configuring done (0.4s)
-- Generating done (0.5s)
-- Build files have been written to: D:/Julia/jluna/cmake
PS D:\Julia\jluna\cmake> cmake --build . --target INSTALL --config Release
MSBuild version 17.5.1+f6fdcf537 for .NET Framework
c_adapter.cpp
generator_expression.cpp
module.cpp
mutex.cpp
proxy.cpp
safe_utilities.cpp
symbol.cpp
type.cpp
Code wird generiert...
Auto build dll exports
Bibliothek "D:/Julia/jluna/cmake/Release/jluna.lib" und Objekt "D:/Julia/jluna/cmake/Release/jluna.exp" werden erstellt.
jluna.vcxproj -> D:\Julia\jluna\cmake\Release\jluna.dll
main.cpp
D:\Julia\jluna\.test\main.cpp(936): warning C4267: "Argument": Konvertierung von "size_t" nach "uint32_t", Datenverlust möglich [D:\Julia\jluna\cmake\jluna_test.vcxproj]
D:\Julia\jluna\.src/array.inl(229,42): warning C4244: "Argument": Konvertierung von "uint64_t" in "int", möglicher Datenverlust [D:\Julia\jluna\cmake\jluna_test.vcxproj]
D:\Julia\jluna\.test\main.cpp(959): message : Siehe Verweis auf die gerade kompilierte Instanziierung "auto jluna::Array<jluna::unsafe::Value *,3>::at<uint64_t,uint64_t,uint64_t,true>(uint64_t,uint64_t,uint64_t)" der Funktions-Vorlage.
[D:\Julia\jluna\cmake\jluna_test.vcxproj]
jluna_test.vcxproj -> D:\Julia\jluna\cmake\Release\jluna_test.exe
1>
-- Install configuration: "Release"
-- Installing: D:/Julia/Jluna_liblib/include/jluna/jluna.hpp
-- Installing: D:/Julia/Jluna_liblib/include/jluna/include
-- Installing: D:/Julia/Jluna_liblib/include/jluna/include/array.hpp
-- Installing: D:/Julia/Jluna_liblib/include/jluna/include/box.hpp
-- Installing: D:/Julia/Jluna_liblib/include/jluna/include/concepts.hpp
-- Installing: D:/Julia/Jluna_liblib/include/jluna/include/cppcall.hpp
-- Installing: D:/Julia/Jluna_liblib/include/jluna/include/docs_only_dummy.hpp
-- Installing: D:/Julia/Jluna_liblib/include/jluna/include/exceptions.hpp
-- Installing: D:/Julia/Jluna_liblib/include/jluna/include/generator_expression.hpp
-- Installing: D:/Julia/Jluna_liblib/include/jluna/include/julia
-- Installing: D:/Julia/Jluna_liblib/include/jluna/include/julia/jluna_01.jl
-- Installing: D:/Julia/Jluna_liblib/include/jluna/include/julia/jluna_02.jl
-- Installing: D:/Julia/Jluna_liblib/include/jluna/include/julia/jluna_03.jl
-- Installing: D:/Julia/Jluna_liblib/include/jluna/include/julia/jluna_04.jl
-- Installing: D:/Julia/Jluna_liblib/include/jluna/include/julia/jluna_05.jl
-- Installing: D:/Julia/Jluna_liblib/include/jluna/include/julia/jluna_06.jl
-- Installing: D:/Julia/Jluna_liblib/include/jluna/include/julia_wrapper.hpp
-- Installing: D:/Julia/Jluna_liblib/include/jluna/include/module.hpp
-- Installing: D:/Julia/Jluna_liblib/include/jluna/include/multi_threading.hpp
-- Installing: D:/Julia/Jluna_liblib/include/jluna/include/mutex.hpp
-- Installing: D:/Julia/Jluna_liblib/include/jluna/include/proxy.hpp
-- Installing: D:/Julia/Jluna_liblib/include/jluna/include/safe_utilities.hpp
-- Installing: D:/Julia/Jluna_liblib/include/jluna/include/symbol.hpp
-- Installing: D:/Julia/Jluna_liblib/include/jluna/include/type.hpp
-- Installing: D:/Julia/Jluna_liblib/include/jluna/include/typedefs.hpp
-- Installing: D:/Julia/Jluna_liblib/include/jluna/include/unbox.hpp
-- Installing: D:/Julia/Jluna_liblib/include/jluna/include/unsafe_utilities.hpp
-- Installing: D:/Julia/Jluna_liblib/include/jluna/include/usertype.hpp
-- Installing: D:/Julia/Jluna_liblib/include/jluna/.src
-- Installing: D:/Julia/Jluna_liblib/include/jluna/.src/array.inl
-- Installing: D:/Julia/Jluna_liblib/include/jluna/.src/array_iterator.inl
-- Installing: D:/Julia/Jluna_liblib/include/jluna/.src/box.inl
-- Installing: D:/Julia/Jluna_liblib/include/jluna/.src/common.hpp
-- Installing: D:/Julia/Jluna_liblib/include/jluna/.src/cppcall.inl
-- Installing: D:/Julia/Jluna_liblib/include/jluna/.src/c_adapter.cpp
-- Installing: D:/Julia/Jluna_liblib/include/jluna/.src/c_adapter.hpp
-- Installing: D:/Julia/Jluna_liblib/include/jluna/.src/exceptions.cpp
-- Installing: D:/Julia/Jluna_liblib/include/jluna/.src/gc_sentinel.hpp
-- Installing: D:/Julia/Jluna_liblib/include/jluna/.src/generator_expression.cpp
-- Installing: D:/Julia/Jluna_liblib/include/jluna/.src/generator_expression.inl
-- Installing: D:/Julia/Jluna_liblib/include/jluna/.src/include_julia.inl
-- Installing: D:/Julia/Jluna_liblib/include/jluna/.src/include_julia.inl.in
-- Installing: D:/Julia/Jluna_liblib/include/jluna/.src/module.cpp
-- Installing: D:/Julia/Jluna_liblib/include/jluna/.src/module.inl
-- Installing: D:/Julia/Jluna_liblib/include/jluna/.src/multi_threading.inl
-- Installing: D:/Julia/Jluna_liblib/include/jluna/.src/mutex.cpp
-- Installing: D:/Julia/Jluna_liblib/include/jluna/.src/mutex.inl
-- Installing: D:/Julia/Jluna_liblib/include/jluna/.src/proxy.cpp
-- Installing: D:/Julia/Jluna_liblib/include/jluna/.src/proxy.inl
-- Installing: D:/Julia/Jluna_liblib/include/jluna/.src/safe_utilities.cpp
-- Installing: D:/Julia/Jluna_liblib/include/jluna/.src/safe_utilities.inl
-- Installing: D:/Julia/Jluna_liblib/include/jluna/.src/symbol.cpp
-- Installing: D:/Julia/Jluna_liblib/include/jluna/.src/symbol.inl
-- Installing: D:/Julia/Jluna_liblib/include/jluna/.src/type.cpp
-- Installing: D:/Julia/Jluna_liblib/include/jluna/.src/type.inl
-- Installing: D:/Julia/Jluna_liblib/include/jluna/.src/typedefs.inl
-- Installing: D:/Julia/Jluna_liblib/include/jluna/.src/unbox.inl
-- Installing: D:/Julia/Jluna_liblib/include/jluna/.src/unsafe_utilities.cpp
-- Installing: D:/Julia/Jluna_liblib/include/jluna/.src/unsafe_utilities.inl
-- Installing: D:/Julia/Jluna_liblib/include/jluna/.src/usertype.inl
-- Installing: D:/Julia/Jluna_liblib/lib/jluna.lib
-- Installing: D:/Julia/Jluna_liblib/bin/jluna.dll
-- Installing: D:/Julia/Jluna_liblib/lib/cmake/jluna/jluna-config.cmake
-- Installing: D:/Julia/Jluna_liblib/lib/cmake/jluna/jluna-config-version.cmake
-- Installing: D:/Julia/Jluna_liblib/lib/cmake/jluna/jluna-targets.cmake
-- Installing: D:/Julia/Jluna_liblib/lib/cmake/jluna/jluna-targets-release.cmake
PS D:\Julia\jluna\cmake> D:\Julia\jluna\cmake\Release\jluna_test.exe
[JULIA][ERROR] In jluna.verify_library: Unable to locate jluna shared library at `D:/Julia/Jluna_liblib/jluna.dll`. You can specify the correct path manually when calling jluna::initialize.`
[JULIA][ERROR] initialization failed.
PS D:\Julia\jluna\cmake> D:\Julia\jluna\cmake\Release\jluna_test.exe
[JULIA][LOG] initialization successful (1 thread(s)).
starting test...
c_adapter found: [OK]
unsafe: gc_push / gc_pop: [OK]
unsafe: gc: [OK]
unsafe: _sym: [OK]
as_julia_pointer: [OK]
unsafe: get_function: [OK]
unsafe: Expr & eval: [OK]
unsafe: get/set value: [OK]
unsafe: get_field: [OK]
unsafe: set_field: [OK]
unsafe: call: [OK]
unsafe: new_array: [OK]
unsafe: new_array_from_data: [OK]
unsafe: override_array: [OK]
unsafe: swap_array_data: [OK]
unsafe: set_array_data: [OK]
unsafe: resize_array: reshape: [OK]
unsafe: resize_array: grow: [OK]
unsafe: array: get_index: [OK]
unsafe: get_array_size: [OK]
catch c exception: [OK]
safe_call: [OK]
safe_eval: [OK]
box/unbox Char: [OK]
box/unbox String: [OK]
box/unbox Int8: [OK]
box/unbox Int16: [OK]
box/unbox Int32: [OK]
box/unbox Int64: [OK]
box/unbox UInt8: [OK]
box/unbox UInt16: [OK]
box/unbox UInt32: [OK]
box/unbox UInt64: [OK]
box/unbox Float32: [OK]
box/unbox Float64: [OK]
box/unbox Complex: [OK]
box/unbox Pair: [OK]
box/unbox Tuple3: [OK]
box/unbox Symbol: [OK]
box/unbox Vector: [OK]
box/unbox Dict: [OK]
box/unbox Dict: [OK]
box/unbox Set: [OK]
make_new_named_undef: [OK]
make_new_named_int: [OK]
make_new_named_float: [OK]
make_new_named_vector: [OK]
make_new_named_set: [OK]
make_new_named_dict: [OK]
make_new_pair: [OK]
make_new_tuple: [OK]
create_reference: [OK]
proxy ctor: [OK]
proxy trivial dtor: [OK]
proxy inheritance dtor: [OK]
proxy reject as non-vector: [OK]
proxy reject as non-function: [OK]
proxy reject as non-struct: [OK]
proxy fieldnames: [OK]
proxy mutation: [OK]
proxy mutate unnamed member: [OK]
proxy detach update: [OK]
proxy make unnamed: [OK]
proxy reject immutable: [OK]
proxy cast: [OK]
array: ctor: [OK]
array: range index: [OK]
array: reject wrong type: [OK]
array: front/back: [OK]
array: empty: [OK]
array: Nd at: [OK]
array: out of range: [OK]
array_iterator: +/-: [OK]
array_iterator: on owner reassignment: [OK]
array_iterator: comparison: [OK]
array_iterator: cast to value: [OK]
array_iterator: cast to proxy: [OK]
array: comprehension: [OK]
vector: insert: [OK]
vector: erase: [OK]
vector: append: [OK]
C: call success: [OK]
C: forward exception: [OK]
C: reject wrong-sized tuple: [OK]
Symbol: CTOR: [OK]
Symbol: Hash: [OK]
Type: CTOR: [OK]
Type Constant: AbstractArray{T, N}: [OK]
Type Constant: AbstractChar: [OK]
Type Constant: AbstractFloat: [OK]
Type Constant: AbstractString: [OK]
Type Constant: Any: [OK]
Type Constant: Array{T, N}: [OK]
Type Constant: Bool: [OK]
Type Constant: Char: [OK]
Type Constant: DataType: [OK]
Type Constant: DenseArray{T, N}: [OK]
Type Constant: Exception: [OK]
Type Constant: Expr: [OK]
Type Constant: Float16: [OK]
Type Constant: Float32: [OK]
Type Constant: Float64: [OK]
Type Constant: Function: [OK]
Type Constant: GlobalRef: [OK]
Type Constant: IO: [OK]
Type Constant: Int128: [OK]
Type Constant: Int16: [OK]
Type Constant: Int32: [OK]
Type Constant: Int64: [OK]
Type Constant: Integer: [OK]
Type Constant: LineNumberNode: [OK]
Type Constant: Method: [OK]
Type Constant: Module: [OK]
Type Constant: Tuple{Vararg{T, N}}: [OK]
Type Constant: NamedTuple{names, T<:Tuple}: [OK]
Type Constant: Nothing: [OK]
Type Constant: Number: [OK]
Type Constant: Pair{A, B}: [OK]
Type Constant: Ptr{T}: [OK]
Type Constant: QuoteNode: [OK]
Type Constant: Real: [OK]
Type Constant: Ref{T}: [OK]
Type Constant: Signed: [OK]
Type Constant: String: [OK]
Type Constant: Symbol: [OK]
Type Constant: Task: [OK]
Type Constant: Tuple: [OK]
Type Constant: Type{T}: [OK]
Type Constant: TypeVar: [OK]
Type Constant: UInt128: [OK]
Type Constant: UInt16: [OK]
Type Constant: UInt32: [OK]
Type Constant: UInt64: [OK]
Type Constant: UndefInitializer: [OK]
Type Constant: Union: [OK]
Type Constant: UnionAll: [OK]
Type Constant: Unsigned: [OK]
Type Constant: VecElement{T}: [OK]
Type Constant: WeakRef: [OK]
Type: (<:): [OK]
Type: get_symbol: [OK]
Type: get_parameters: [OK]
Type: get_fields: [OK]
Type: is_primitive: [OK]
Type: is_struct_type: [OK]
Type: is_declared_mutable: [OK]
Type: is_isbits: [OK]
Type: is_singleton: [OK]
Type: is_abstract_type: [OK]
Type: is_abstract_ref_type: [OK]
Type: is_typename: [OK]
Generator Expression: [OK]
Usertype: enable: [OK]
Usertype: add property: [OK]
Usertype: implement: [OK]
Usertype: box/unbox: [OK]
jluna::Mutex: [OK]
Task<T>: schedule/join: [OK]
Task<T>: move ctor: [OK]
Task<T>: access task proxy: [OK]
Task<void>: schedule/join: [OK]
Task<void>: move ctor: [OK]
Task<void>: access task proxy: [OK]
Number of tests unsuccessful: 0
The test.exe I build with Visual Studio 2022. Starting with a new Console-Project I have added the jluna and julia libraries and then I built.
I have started a new attempt. I opened the jluna project created by CMAKE and replaced the test-main there with the following:
#include <iostream>
#include <include/julia_wrapper.hpp>
#include <ptrhash.h>
#include <jluna.hpp>
#include <.test/test.hpp>
#include <jluna.hpp>
#include <thread>
#include <include/multi_threading.hpp>
#include <include/box.hpp>
#include <chrono>
#include <.src/cppcall.inl>
using namespace jluna;
#include <thread>
int main()
{
initialize(2);
Main.safe_eval("array = Int64[1, 2, 3, 4]");
Array<Int64, 1> array = Main["array"];
Int64 third = array[2];
std::cout << third << std::endl;
return 0;
}
Then I get the right result:
PS D:\Julia\jluna\cmake> D:\Julia\jluna\cmake\Debug\jluna_test.exe
[JULIA][LOG] initialization successful (1 thread(s)).
3
The error must therefore lie in the creation of the VS project or in the integration of the libraries.
Thank you for your help, which has put me on the right track.
My actual goal is to create a DLL that loads into Java and executes Julia code.
Here there were difficulties with the stack size of the Java threads. But I have now created a thread in the DLL whose stack size I can control myself.
Now I have the same error as described above. The program stops at proxy.inl line 74 with:
Unbehandelte Ausnahme bei 0x00007FF9C4D1CF19 in java.exe: Microsoft C++-Ausnahme: jluna::JuliaException bei Speicherort 0x0000009791BFFC10.
Before that I get the console output:
WARNING: failed to initialize stack walk info
Here is the VS 2022 Debugger output.
"java.exe" (Win32): "D:\Julia\jluna\cmake\Debug\jluna_test.dll" geladen. Symbole wurden geladen.
"java.exe" (Win32): "C:\Windows\System32\msvcp140d.dll" geladen.
"java.exe" (Win32): "C:\Windows\System32\vcruntime140d.dll" geladen.
"java.exe" (Win32): "D:\julia-1.8.5-win64\julia-1.8.5\bin\libjulia.dll" geladen. Das Modul wurde ohne Symbole erstellt.
"java.exe" (Win32): "D:\Julia\Jluna_liblib\bin\jluna.dll" geladen. Das Modul wurde ohne Symbole erstellt.
"java.exe" (Win32): "C:\Windows\System32\ucrtbased.dll" geladen.
"java.exe" (Win32): "C:\Windows\System32\vcruntime140_1d.dll" geladen.
"java.exe" (Win32): "C:\Windows\System32\vcruntime140_1d.dll" geladen.
"java.exe" (Win32): "C:\Windows\System32\vcruntime140_1d.dll" wurde entladen.
"java.exe" (Win32): "C:\Windows\System32\vcruntime140_1.dll" geladen.
"java.exe" (Win32): "D:\julia-1.8.5-win64\julia-1.8.5\bin\libgcc_s_seh-1.dll" geladen.
"java.exe" (Win32): "D:\julia-1.8.5-win64\julia-1.8.5\bin\libwinpthread-1.dll" geladen.
"java.exe" (Win32): "D:\julia-1.8.5-win64\julia-1.8.5\bin\libopenlibm.dll" geladen.
"java.exe" (Win32): "D:\julia-1.8.5-win64\julia-1.8.5\bin\libjulia-internal.dll" geladen.
"java.exe" (Win32): "C:\Windows\System32\IPHLPAPI.DLL" geladen.
"java.exe" (Win32): "C:\Windows\System32\secur32.dll" geladen.
"java.exe" (Win32): "D:\julia-1.8.5-win64\julia-1.8.5\bin\libstdc++-6.dll" geladen.
"java.exe" (Win32): "C:\Windows\System32\userenv.dll" geladen.
"java.exe" (Win32): "C:\Windows\System32\cryptbase.dll" geladen.
"java.exe" (Win32): "C:\Windows\System32\sspicli.dll" geladen.
"java.exe" (Win32): "D:\julia-1.8.5-win64\julia-1.8.5\bin\libjulia-codegen.dll" geladen.
"java.exe" (Win32): "D:\julia-1.8.5-win64\julia-1.8.5\bin\libLLVM-13jl.dll" geladen.
"java.exe" (Win32): "D:\julia-1.8.5-win64\julia-1.8.5\bin\libz.dll" geladen.
"java.exe" (Win32): "C:\Windows\System32\cryptsp.dll" geladen.
"java.exe" (Win32): "C:\Windows\System32\rsaenh.dll" geladen.
Ausnahme ausgelöst bei 0x0000021074ADEA4A in java.exe: 0xC0000005: Zugriffsverletzung beim Lesen an Position 0x0000021062910008.
If I load the jluna.dll in a separate thread, which exits after loading, and after that start a new thread with the code:
DWORD WINAPI JuliaThread(LPVOID lpParameter)
{
jluna::initialize();
jluna::Base["println"]("hello julia");
jluna::Main.safe_eval("array = Int64[1, 2, 3, 4]");
jluna::Array<jluna::Int64, 1> array = jluna::Main["array"];
jluna::Int64 third = array[2];
std::cout << third << std::endl;
return 0;
}
I get the right output:
WARNING: failed to initialize stack walk info
[JULIA][LOG] initialization successful (1 thread(s)).
hello julia
3
Is there a problem with loading the depending dlls or something?
If I start the code in a new Process it is of course working. So its fine for me and I think not an Issue, so I will close.
Thank you, Clemapfel!
If I make an exe with VS 2022 with this code:
I get the following EXCEPTION_ACCESS_VIOLATION.
What could be the cause of this?