ivandasch commented on a change in pull request #9521:
URL: https://github.com/apache/ignite/pull/9521#discussion_r740763961
##########
File path: modules/platforms/cpp/core/include/ignite/jni/utils.h
##########
@@ -124,8 +119,16 @@ namespace ignite
}
private:
+ /** Initializer */
+ void Init(const
common::concurrent::SharedPointer<java::JniContext>& ctx0, jobject obj0) {
+ ctx = ctx0;
+
+ if (ctx.IsValid())
+ this->obj = ctx.Get()->Acquire(obj0);
+ }
+
/** Context. */
- java::JniContext* ctx;
+ common::concurrent::SharedPointer<java::JniContext> ctx;
Review comment:
I suppose there is no.
1. JniContext doesn't have any references to JavaGlobalRef
2. The only declared instance of JavaGlobalRef belongs to IgniteEnvironment,
the same for shared_ptr to JniContext.
Therefore, there is no cyclic reference and all resources will be freed
during destruction of IgniteEnvironment.
May be I am wrong, but I suppose that all ok.
##########
File path: modules/platforms/cpp/core/include/ignite/jni/utils.h
##########
@@ -124,8 +119,16 @@ namespace ignite
}
private:
+ /** Initializer */
+ void Init(const
common::concurrent::SharedPointer<java::JniContext>& ctx0, jobject obj0) {
+ ctx = ctx0;
+
+ if (ctx.IsValid())
+ this->obj = ctx.Get()->Acquire(obj0);
+ }
+
/** Context. */
- java::JniContext* ctx;
+ common::concurrent::SharedPointer<java::JniContext> ctx;
Review comment:
I've created small test to simulate our situation
```
#include <memory>
#include <iostream>
using namespace std;
class Ctx {
public:
~Ctx() {
cout << "destroyed";
}
};
class Wrapper{
public:
Wrapper() {}
Wrapper(shared_ptr<Ctx> pCtx_): pCtx(pCtx_) {}
private:
shared_ptr<Ctx> pCtx;
};
class Env {
public:
Env(shared_ptr<Ctx> pCtx_): pCtx(pCtx_) {}
void AddWrapper() {
cout << "Num references before setting wrapper " << pCtx.use_count()
<< endl;
this->wrapper = Wrapper(pCtx);
cout << "Num references after after setting wrapper " <<
pCtx.use_count() << endl;
}
private:
shared_ptr<Ctx> pCtx;
Wrapper wrapper;
};
int main() {
auto pCtx = make_shared<Ctx>();
cout << "Num references before assignment " << pCtx.use_count() << endl;
{
Env env(pCtx);
env.AddWrapper();
env.AddWrapper();
}
cout << "Num references final " << pCtx.use_count() << endl;
return 0;
}
```
Num references before assignment 1
Num references before setting wrapper 2
Num references after after setting wrapper 3
Num references before setting wrapper 3
Num references after after setting wrapper 3
Num references final 1
destroyed
```
##########
File path: modules/platforms/cpp/core/include/ignite/jni/utils.h
##########
@@ -124,8 +119,16 @@ namespace ignite
}
private:
+ /** Initializer */
+ void Init(const
common::concurrent::SharedPointer<java::JniContext>& ctx0, jobject obj0) {
+ ctx = ctx0;
+
+ if (ctx.IsValid())
+ this->obj = ctx.Get()->Acquire(obj0);
+ }
+
/** Context. */
- java::JniContext* ctx;
+ common::concurrent::SharedPointer<java::JniContext> ctx;
Review comment:
I've created small test to simulate our situation
```
#include <memory>
#include <iostream>
using namespace std;
class Ctx {
public:
~Ctx() {
cout << "destroyed";
}
};
class Wrapper{
public:
Wrapper() {}
Wrapper(shared_ptr<Ctx> pCtx_): pCtx(pCtx_) {}
private:
shared_ptr<Ctx> pCtx;
};
class Env {
public:
Env(shared_ptr<Ctx> pCtx_): pCtx(pCtx_) {}
void AddWrapper() {
cout << "Num references before setting wrapper " << pCtx.use_count()
<< endl;
this->wrapper = Wrapper(pCtx);
cout << "Num references after after setting wrapper " <<
pCtx.use_count() << endl;
}
private:
shared_ptr<Ctx> pCtx;
Wrapper wrapper;
};
int main() {
auto pCtx = make_shared<Ctx>();
cout << "Num references before assignment " << pCtx.use_count() << endl;
{
Env env(pCtx);
env.AddWrapper();
env.AddWrapper();
}
cout << "Num references final " << pCtx.use_count() << endl;
return 0;
}
```
```
Num references before assignment 1
Num references before setting wrapper 2
Num references after after setting wrapper 3
Num references before setting wrapper 3
Num references after after setting wrapper 3
Num references final 1
destroyed
```
##########
File path: modules/platforms/cpp/core/include/ignite/jni/utils.h
##########
@@ -124,8 +119,16 @@ namespace ignite
}
private:
+ /** Initializer */
+ void Init(const
common::concurrent::SharedPointer<java::JniContext>& ctx0, jobject obj0) {
+ ctx = ctx0;
+
+ if (ctx.IsValid())
+ this->obj = ctx.Get()->Acquire(obj0);
+ }
+
/** Context. */
- java::JniContext* ctx;
+ common::concurrent::SharedPointer<java::JniContext> ctx;
Review comment:
I've created small test to simulate our situation
```C++
#include <memory>
#include <iostream>
using namespace std;
class Ctx {
public:
~Ctx() {
cout << "destroyed";
}
};
class Wrapper{
public:
Wrapper() {}
Wrapper(shared_ptr<Ctx> pCtx_): pCtx(pCtx_) {}
private:
shared_ptr<Ctx> pCtx;
};
class Env {
public:
Env(shared_ptr<Ctx> pCtx_): pCtx(pCtx_) {}
void AddWrapper() {
cout << "Num references before setting wrapper " << pCtx.use_count()
<< endl;
this->wrapper = Wrapper(pCtx);
cout << "Num references after after setting wrapper " <<
pCtx.use_count() << endl;
}
private:
shared_ptr<Ctx> pCtx;
Wrapper wrapper;
};
int main() {
auto pCtx = make_shared<Ctx>();
cout << "Num references before assignment " << pCtx.use_count() << endl;
{
Env env(pCtx);
env.AddWrapper();
env.AddWrapper();
}
cout << "Num references final " << pCtx.use_count() << endl;
return 0;
}
```
```
Num references before assignment 1
Num references before setting wrapper 2
Num references after after setting wrapper 3
Num references before setting wrapper 3
Num references after after setting wrapper 3
Num references final 1
destroyed
```
##########
File path: modules/platforms/cpp/core/CMakeLists.txt
##########
@@ -17,12 +17,15 @@
project(ignite)
+find_library(JVM_LIBRARY jvm ${JAVA_JVM_LIBRARY_DIRECTORIES})
+
include_directories(SYSTEM ${JNI_INCLUDE_DIRS})
include_directories(include)
set(TARGET ${PROJECT_NAME})
set(SOURCES src/ignite.cpp
+ src/jni/java.cpp
Review comment:
Here and in other files changed `\t` to whitespaces
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]