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

Add annotations for Java 10+ javac -h for native headers #943

Closed
wants to merge 1 commit into from
Closed

Add annotations for Java 10+ javac -h for native headers #943

wants to merge 1 commit into from

Conversation

wltjr
Copy link

@wltjr wltjr commented Mar 22, 2018

Initial modifications for Java 10+ javac -h since javah was removed starting with Java 10 now released per issue #902. I am good with the annotations. I am NOT ok with the FIXME code in there. That was the ONLY way I could find to generate the header files for those classes. I had to introduce a variable in both classes and interfaces, so I could add the annotations. I do not like adding unused variables....

However that did generate the header files for the methods exactly as javah did before. The exception is the interfaces. Since I could not make those variables private, those variables show up in the header files, unlike javah. With these modifications, if you do javah with < 10, and then do javac -h with 9, 10, or 11. The output is the same except the following. A and B are folders, javah is outputted to A, javac -h from 11 in B. You can see the only difference is the header files for interfaces due to unused variable being public.

$ diff -Naur a b
diff -Naur a/com_sun_jna_Function_PostCallRead.h b/com_sun_jna_Function_PostCallRead.h
--- a/com_sun_jna_Function_PostCallRead.h       2018-03-21 19:04:13.921572141 -0400
+++ b/com_sun_jna_Function_PostCallRead.h       2018-03-21 20:04:13.605134889 -0400
@@ -7,6 +7,8 @@
 #ifdef __cplusplus
 extern "C" {
 #endif
+#undef com_sun_jna_Function_PostCallRead_UNUSED
+#define com_sun_jna_Function_PostCallRead_UNUSED 0L
 #ifdef __cplusplus
 }
 #endif
diff -Naur a/com_sun_jna_Native_ffi_callback.h b/com_sun_jna_Native_ffi_callback.h
--- a/com_sun_jna_Native_ffi_callback.h 2018-03-21 19:04:15.531624426 -0400
+++ b/com_sun_jna_Native_ffi_callback.h 2018-03-21 20:04:14.325158271 -0400
@@ -7,6 +7,8 @@
 #ifdef __cplusplus
 extern "C" {
 #endif
+#undef com_sun_jna_Native_ffi_callback_UNUSED
+#define com_sun_jna_Native_ffi_callback_UNUSED 0L
 #ifdef __cplusplus
 }
 #endif

Now if the header files for the interfaces are not needed. Then it is a bit better. Still have unused private variables. Seems no other means to mark the class for native generation. Maybe a bug to be fixed in java 11? Likely to late for Java 10. Seems like interfaces and classes need to be able to be marked as Native via annotation or modifier/keyword.

Seems like there should be a better way. javah removal seems premature with javac -h not having full replacement abilities.

  • unable to generate native headers for classes without global variables to annotate with @java.lang.annotation.Native
  • unable to generate native headers for interfaces in classes without adding a global public variable to annotate with @java.lang.annotation.Native

@matthiasblaesing
Copy link
Member

Thank you for looking into this - these are some random thoughts:

  • if a header will be empty - why should we generate it? It has no consequence for the compilation, so could just be dropped (removing the need for the UNUSED variables
  • check if a java.lang.annotation.Native definition can be added to the build if building with a java < 8 (solaris x86-32 bit has no Java 8) - else you break the build
  • bonus points if you can adjust the build to see if a jdk >= 8 is used, if so, just use javac to create the headers (could be part of the regular build) and if a prior JDK is detected, use javah

@wltjr
Copy link
Author

wltjr commented Mar 22, 2018

  • It seems some things need these empty headers. I need to verify which, but I ran into these issues trying to use javac -h. Need to double check if it was JNA itself or dependent projects. There was some reason why they were needed. It could be incorrect dependency/include as they are empty.
  • if Solaris x86-32 does not have Java 8 or newer. That clearly says Oracle the maker of Solaris does not care about that platform. I fail to see why that should hold back JNA development. Or why anyone running Solaris x86-32 needs a newer JNA with a older < 8 JDK. Should JNA be held back from Java 10, now released, and upcoming Java 11, because solaris x86-32 does not have Java 8+. That does not make much sense, and is not a main stream operating system. Not to mention 1.7 is EOL, so not sure about even solaris x86-32 there. Seems a platform even Oracle does not care to support anymore or for some time. Java 8 has been out for like 4 years now.
  • Not sure what you mean, but I am already building JNA under 9, as release/source/target 9. This issue is preventing me from moving to 10 and 11. Thus far this is the only package I am aware of preventing me from moving to 10 and 11.

@matthiasblaesing
Copy link
Member

I gave solaris as a sample. We are running machines are work, that use java 1.5. Am I proud of it? No, but I have to live with it. So I know why backwards-compatibility is important.
For the other work - if build with JDK 7 javac can't generate headers, so the build process needs to adjust based on the JDK.

@wltjr
Copy link
Author

wltjr commented Mar 22, 2018

Just because you are stuck in the past does not mean projects should be. Also why do you need to use newer versions of JNA? Why are you pushing your legacy needs on the world? Java is clearly moving forward much faster. Others need to adapt or be left behind. But that is no reason to hold back projects.

I am trying to get things working on current JDK 10 and future JDKs. You want to prevent that for legacy purposes. Or waste time with conditionals supporting older code vs updating the older code. Which you will have to someday...

If you are on legacy Java versions, I do not see why you need updated libraries. You have other vulnerabilities, bugs, etc in the core that will not be fixed nor addressed. That is very strange to be updating libraries and not the core. That entire scenario does not make sense, why still on 1.5, why using newer libraries with older jdk, etc. Need to revisit both development and deployment practices.

Sorry but IMHO none are valid reasons to hold JNA back. You may need to back port things for your purposes and allow the project to move forward. While you remain in the past.

@wltjr
Copy link
Author

wltjr commented Mar 22, 2018

FYI I still have clients running code I did back in 1.4 days. It builds fine under 11... I packaged hundreds of java packages. Very few require older JDKs and I consider that bad coding. If your code requires a specific JDK and prevents you from moving to newer JDK your writing bad code. Your developers are not forward looking, and that whole scenario needs to change. Not impose such needs on others.

Many are going to have serious growing pains with Java going forward. As they learn to stop requiring legacy support and start being more adaptable and allow things to move at a faster pace.

@matthiasblaesing
Copy link
Member

matthiasblaesing commented Mar 22, 2018

I did not require you to stay in the past - I asked you to put into work not to break support for older JDKs. You did not even consider this. I'm fine if you want to rush into the future, but my usecase is different - if you can't respect this, fine with me, then my review ends at this point and I'll focus on fixing bugs.

For you allegation, that I decided to run java 1.5: My boss decided that and I have to live with that decision. The JVM is embedded into a third-party product, that is way past its support time. You don't have to face these issues: consider yourself lucky.

@wltjr
Copy link
Author

wltjr commented Mar 22, 2018

My interest is clearly in moving things forward, not legacy support. If your interest in legacy support, then you could look to make any such modifications. Not request others spend their time on your needs, which contradict their needs. Your use case is different than mine. IMHO you should spend your time for your legacy needs. My needs are for current and future versions of Java. Thus my efforts.

I am not rushing into the future... Java is clearly... Guess you missed the memo...
https://mreinhold.org/blog/forward-faster

What is the current JDK? 10... how is that the future? This is the present... Your the one living in the past, way in the past....
https://en.wikipedia.org/wiki/Java_version_history

Everyone has long EOL 1.5, and very few if any support 1.6 for much longer, and that is paid support.
http://www.oracle.com/technetwork/java/eol-135779.html
https://developer.ibm.com/javasdk/support/lifecycle/
https://access.redhat.com/articles/1299013

So I guess JNA cannot be fixed for current JDK 10, because of others legacy needs for support < 8. Without any such means to address the issue for both without different code bases, modifying files on the fly etc. There is no clean way to move forward and support legacy. There has to be a trade off, and IMHO it is dropping legacy support.

JNA should build under current JDK which is 10.
http://www.oracle.com/technetwork/java/javase/downloads/index.html

@wltjr
Copy link
Author

wltjr commented Mar 22, 2018

Just noticed in #902 (comment) it was mentioned to make things compatible for 8-10, with no mention of need to support < 8.

matthiasblaesing added a commit to matthiasblaesing/jna that referenced this pull request Mar 24, 2018
matthiasblaesing added a commit to matthiasblaesing/jna that referenced this pull request Mar 24, 2018
matthiasblaesing added a commit to matthiasblaesing/jna that referenced this pull request Mar 24, 2018
@wltjr
Copy link
Author

wltjr commented Mar 24, 2018

Closing in favor of #945 due to lack of changes to build system. These were the only changes required for my needs.

@wltjr wltjr closed this Mar 24, 2018
matthiasblaesing added a commit to matthiasblaesing/jna that referenced this pull request Apr 25, 2018
… version is 6)

- Support for JDK 10 requires removal of usage of javah, which was
  replaced by the javac of JDK8, which can generate headers while
  processing the java classes (bumping the minimum build JDK to 8)

- A new build target "native-build-package" was introduced, to
  create a zip file with the files necessary to build the native
  libraries, only requireing the JDK present on the build system,
  but can be an older JDK.

  Properties to select the build.os.name, build.os.arch and build.os.endianess
  were added to allow cross-system generation of the build package

- the native Makefile is not modified by the build.xml anymore, as the
  two parameters JNA_JNI_VERSION and CHECKSUM are already passed in via
  command line parameters

- Support for "-d32" and "-d64" datamodel selectors was removed
  as it was only needed for solaris and JDK8 (minimum build JDK)
  on solaris only supports 64 bit

Closes: java-native-access#902
Closes: java-native-access#943
matthiasblaesing added a commit to matthiasblaesing/jna that referenced this pull request Apr 25, 2018
… version is 6)

- Support for JDK 10 requires removal of usage of javah, which was
  replaced by the javac of JDK8, which can generate headers while
  processing the java classes (bumping the minimum build JDK to 8)

- A new build target "native-build-package" was introduced, to
  create a zip file with the files necessary to build the native
  libraries, only requireing the JDK present on the build system,
  but can be an older JDK.

  Properties to select the build.os.name, build.os.arch and build.os.endianess
  were added to allow cross-system generation of the build package

- the native Makefile is not modified by the build.xml anymore, as the
  two parameters JNA_JNI_VERSION and CHECKSUM are already passed in via
  command line parameters

- Support for "-d32" and "-d64" datamodel selectors was removed
  as it was only needed for solaris and JDK8 (minimum build JDK)
  on solaris only supports 64 bit

Closes: java-native-access#902
Closes: java-native-access#943
idosu pushed a commit to idosu/jna that referenced this pull request May 8, 2018
… version is 6)

- Support for JDK 10 requires removal of usage of javah, which was
  replaced by the javac of JDK8, which can generate headers while
  processing the java classes (bumping the minimum build JDK to 8)

- A new build target "native-build-package" was introduced, to
  create a zip file with the files necessary to build the native
  libraries, only requireing the JDK present on the build system,
  but can be an older JDK.

  Properties to select the build.os.name, build.os.arch and build.os.endianess
  were added to allow cross-system generation of the build package

- the native Makefile is not modified by the build.xml anymore, as the
  two parameters JNA_JNI_VERSION and CHECKSUM are already passed in via
  command line parameters

- Support for "-d32" and "-d64" datamodel selectors was removed
  as it was only needed for solaris and JDK8 (minimum build JDK)
  on solaris only supports 64 bit

Closes: java-native-access#902
Closes: java-native-access#943
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants