You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by GitBox <gi...@apache.org> on 2021/10/23 11:27:26 UTC

[GitHub] [ignite] ivandasch opened a new pull request #9521: IGNITE-15806 CPP: Remove JNI module and move it to Core.

ivandasch opened a new pull request #9521:
URL: https://github.com/apache/ignite/pull/9521


   Thank you for submitting the pull request to the Apache Ignite.
   
   In order to streamline the review of the contribution 
   we ask you to ensure the following steps have been taken:
   
   ### The Contribution Checklist
   - [ ] There is a single JIRA ticket related to the pull request. 
   - [ ] The web-link to the pull request is attached to the JIRA ticket.
   - [ ] The JIRA ticket has the _Patch Available_ state.
   - [ ] The pull request body describes changes that have been made. 
   The description explains _WHAT_ and _WHY_ was made instead of _HOW_.
   - [ ] The pull request title is treated as the final commit message. 
   The following pattern must be used: `IGNITE-XXXX Change summary` where `XXXX` - number of JIRA issue.
   - [ ] A reviewer has been mentioned through the JIRA comments 
   (see [the Maintainers list](https://cwiki.apache.org/confluence/display/IGNITE/How+to+Contribute#HowtoContribute-ReviewProcessandMaintainers)) 
   - [ ] The pull request has been checked by the Teamcity Bot and 
   the `green visa` attached to the JIRA ticket (see [TC.Bot: Check PR](https://mtcga.gridgain.com/prs.html))
   
   ### Notes
   - [How to Contribute](https://cwiki.apache.org/confluence/display/IGNITE/How+to+Contribute)
   - [Coding abbreviation rules](https://cwiki.apache.org/confluence/display/IGNITE/Abbreviation+Rules)
   - [Coding Guidelines](https://cwiki.apache.org/confluence/display/IGNITE/Coding+Guidelines)
   - [Apache Ignite Teamcity Bot](https://cwiki.apache.org/confluence/display/IGNITE/Apache+Ignite+Teamcity+Bot)
   
   If you need any help, please email dev@ignite.apache.org or ask anу advice on http://asf.slack.com _#ignite_ channel.
   


-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite] ivandasch commented on a change in pull request #9521: IGNITE-15806 CPP: Remove JNI module and move it to Core.

Posted by GitBox <gi...@apache.org>.
ivandasch commented on a change in pull request #9521:
URL: https://github.com/apache/ignite/pull/9521#discussion_r740772780



##########
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
   ```
   




-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite] ivandasch commented on a change in pull request #9521: IGNITE-15806 CPP: Remove JNI module and move it to Core.

Posted by GitBox <gi...@apache.org>.
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite] ivandasch commented on a change in pull request #9521: IGNITE-15806 CPP: Remove JNI module and move it to Core.

Posted by GitBox <gi...@apache.org>.
ivandasch commented on a change in pull request #9521:
URL: https://github.com/apache/ignite/pull/9521#discussion_r740781062



##########
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite] ivandasch commented on a change in pull request #9521: IGNITE-15806 CPP: Remove JNI module and move it to Core.

Posted by GitBox <gi...@apache.org>.
ivandasch commented on a change in pull request #9521:
URL: https://github.com/apache/ignite/pull/9521#discussion_r740772780



##########
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
   ```
   




-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite] ivandasch commented on a change in pull request #9521: IGNITE-15806 CPP: Remove JNI module and move it to Core.

Posted by GitBox <gi...@apache.org>.
ivandasch commented on a change in pull request #9521:
URL: https://github.com/apache/ignite/pull/9521#discussion_r740772780



##########
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
   ```
   




-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite] ivandasch closed pull request #9521: IGNITE-15806 CPP: Remove JNI module and move it to Core.

Posted by GitBox <gi...@apache.org>.
ivandasch closed pull request #9521:
URL: https://github.com/apache/ignite/pull/9521


   


-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite] ivandasch closed pull request #9521: IGNITE-15806 CPP: Remove JNI module and move it to Core.

Posted by GitBox <gi...@apache.org>.
ivandasch closed pull request #9521:
URL: https://github.com/apache/ignite/pull/9521


   


-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite] isapego commented on a change in pull request #9521: IGNITE-15806 CPP: Remove JNI module and move it to Core.

Posted by GitBox <gi...@apache.org>.
isapego commented on a change in pull request #9521:
URL: https://github.com/apache/ignite/pull/9521#discussion_r740584203



##########
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:
       Whitespaces :)

##########
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:
       Are you sure there is no cyclic reference? 




-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite] isapego commented on a change in pull request #9521: IGNITE-15806 CPP: Remove JNI module and move it to Core.

Posted by GitBox <gi...@apache.org>.
isapego commented on a change in pull request #9521:
URL: https://github.com/apache/ignite/pull/9521#discussion_r740584203



##########
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:
       Whitespaces :)

##########
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:
       Are you sure there is no cyclic reference? 




-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite] ivandasch closed pull request #9521: IGNITE-15806 CPP: Remove JNI module and move it to Core.

Posted by GitBox <gi...@apache.org>.
ivandasch closed pull request #9521:
URL: https://github.com/apache/ignite/pull/9521


   


-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite] ivandasch commented on a change in pull request #9521: IGNITE-15806 CPP: Remove JNI module and move it to Core.

Posted by GitBox <gi...@apache.org>.
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.




-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite] isapego commented on a change in pull request #9521: IGNITE-15806 CPP: Remove JNI module and move it to Core.

Posted by GitBox <gi...@apache.org>.
isapego commented on a change in pull request #9521:
URL: https://github.com/apache/ignite/pull/9521#discussion_r740584203



##########
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:
       Whitespaces :)

##########
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:
       Are you sure there is no cyclic reference? 




-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite] ivandasch commented on a change in pull request #9521: IGNITE-15806 CPP: Remove JNI module and move it to Core.

Posted by GitBox <gi...@apache.org>.
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org