<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body style="overflow-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;">
Hi all,
<div><br>
</div>
<div>I run in same issue before, I think some solution could be to create Map of symbols from JExtract, or instance classes (there’s risk of missed inlining).</div>
<div><br>
</div>
<div>However JExtract could generate code like this</div>
<div><br>
</div>
<div>Class BindingOSX extends ClassNameProvidedByUser {</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>static final BindingOSX INSTANCE;</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>static final VarHandle copyVH;</div>
<div><br>
</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>copy() {copyVH.invoke()};</div>
<div>}</div>
<div><br>
</div>
<div>Class BindingWin extends ClassNameProvidedByUser {</div>
<div>
<div><span class="Apple-tab-span" style="white-space: pre;"></span>static final BindingOSX INSTANCE;</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>static final VarHandle copyVH;</div>
<div><span class="Apple-tab-span" style="white-space: pre;"></span></div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>copy() {copyVH.invoke()};</div>
</div>
<div>}</div>
<div><br>
</div>
<div>// Created manually</div>
<div><br>
</div>
<div>Then on runtime in static initialisation we could choose implementation, this way we would only risk missed inlining due to additional call depth.</div>
<div><br>
</div>
<div>Class PlatformBinding {</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>static final ClassNameProvidedByUser IMPL;</div>
<div><br>
</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>static {</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>if (isOsx) IMPL = BindingOSX.INSTANCE;</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>else if (isWin) IMPL = BindingWin.INSTANCE;</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>}</div>
<div><br>
</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>copy() {</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>IMPL.copy();</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>}</div>
<div>}</div>
<div><br>
</div>
<div>Could be as well achieved with HashMaps, but would required more work from developer side.<br>
<div><br>
</div>
<div>Best regards,</div>
<div>Radoslaw Smogura<br>
<blockquote type="cite">
<div>On 29 Dec 2022, at 13:25, Martin Pernollet <martin.pernollet@protonmail.com> wrote:</div>
<br class="Apple-interchange-newline">
<div>
<div style="font-family: Arial; font-size: 14px;">That would be very valuable to have such guide.</div>
<div style="font-family: Arial; font-size: 14px;"><br>
</div>
<div style="font-family: Arial; font-size: 14px;">I am currently going further with OpenGL on macOS platform mainly, but I'll soon catch up on Ubuntu - and on Windows when I have migrated to JDK 19. When back on Ubuntu/Windows, I'll be happy to read this guide
 (and participate if this makes sense).</div>
<div style="font-family: Arial; font-size: 14px;"><br>
</div>
<div class="protonmail_signature_block" style="font-family: Arial; font-size: 14px;">
<div class="protonmail_signature_block-user protonmail_signature_block-empty"></div>
<div class="protonmail_signature_block-proton">Envoyé avec la messagerie sécurisée
<a target="_blank" href="https://proton.me/" rel="noopener noreferrer">Proton Mail</a>.
</div>
</div>
<div style="font-family: Arial; font-size: 14px;"><br>
</div>
<div class="protonmail_quote">------- Original Message -------<br>
Le mercredi 28 décembre 2022 à 23:02, Maurizio Cimadamore <maurizio.cimadamore@oracle.com> a écrit :<br>
<br>
<blockquote class="protonmail_quote" type="cite">
<p>We do not have concrete examples showing this yet - but, if desirable, we can cook up something in that direction.</p>
<p>Maurizio<br>
</p>
<div class="moz-cite-prefix">On 28/12/2022 16:06, Martin Pernollet wrote:<br>
</div>
<blockquote type="cite">
<div style="font-family: Arial; font-size: 14px;">Thank you for these advices! I complemented my
<a target="_blank" rel="noreferrer nofollow noopener" href="https://urldefense.com/v3/__https://github.com/jzy3d/panama-gl/issues/14__;!!ACWV5N9M2RV99hQ!N1IqZWbHmbyQKeD-bZ56aFuRVi5ggyH3P29fbW4qQWw5aUZA5FGUXzIA2_xKtJLsPq5eP2TSyTzgXDKBuZ0Um11CORVuaFUbcokSgQ$" title="last year notes">
last year notes</a> on this topic with your suggestions.</div>
<div style="font-family: Arial; font-size: 14px;"><br>
</div>
<div style="font-family: Arial; font-size: 14px;">Do you have in mind code samples </div>
<div style="font-family: Arial; font-size: 14px;">
<ul>
<li><span>demonstrating ways to reconcile such cases, </span></li><li><span>which could provide a larger view of the number of specific cases one might encounter when building multi-platform native projects?<br>
</span></li></ul>
</div>
<div style="font-family: Arial; font-size: 14px;"><br>
</div>
<div style="font-family: Arial; font-size: 14px;"><br>
</div>
<div class="protonmail_quote"><br>
<blockquote class="protonmail_quote" type="cite">
<p><span style="font-size: 0.875rem;">Another approach that might work would be to work at a lower level - and generate ad-hoc downcall method handles which automagically fix up mismatches that can arise across platforms. Note that jextract should expose the
 method handles it generates, so perhaps this adaptation can be done semi-automatically based on what comes out of jextract (and based on what the mismatches really are in your use case).</span></p>
<p>I know that e.g. the JavaDoesUSB [1] project has faced similar issues, so perhaps their authors might want to share some insights here.</p>
<p>Cheers<br>
Maurizio<br>
<br>
[1] - <a href="https://urldefense.com/v3/__https://github.com/manuelbl/JavaDoesUSB__;!!ACWV5N9M2RV99hQ!N1IqZWbHmbyQKeD-bZ56aFuRVi5ggyH3P29fbW4qQWw5aUZA5FGUXzIA2_xKtJLsPq5eP2TSyTzgXDKBuZ0Um11CORVuaFXTRYCSxg$" class="moz-txt-link-freetext" rel="noreferrer nofollow noopener" target="_blank">
https://github.com/manuelbl/JavaDoesUSB</a><br>
</p>
<div class="moz-cite-prefix">On 20/12/2022 15:04, Martin Pernollet wrote:<br>
</div>
<blockquote type="cite">
<div style="font-family: Arial; font-size: 14px;">Hi everyone,</div>
<div style="font-family: Arial; font-size: 14px;"><br>
</div>
<div style="font-family: Arial; font-size: 14px;">I am back on track with OpenGL binding with Panama!</div>
<div style="font-family: Arial; font-size: 14px;"><br>
</div>
<div style="font-family: Arial; font-size: 14px;">I have one code design / tooling question related to JExtract : is it possible to
<b>generate a common interface that would be implemented by all platform specific binding</b> generated by JExtract since JDK 19 or 20?</div>
<div style="font-family: Arial; font-size: 14px;"><br>
</div>
<div style="font-family: Arial; font-size: 14px;">Here's my use case in more detail : I've been advised to generate
<b>different binding for different OS</b> (and maybe version). For OpenGL, this lead me to a glut_h binding for macOS, one for Windows and one for Linux.</div>
<div style="font-family: Arial; font-size: 14px;"><br>
</div>
<div style="font-family: Arial; font-size: 14px;">To let <b>the user/developer face a single entry point</b>, I manually write a
<a title="GL interface" href="https://urldefense.com/v3/__https://github.com/jzy3d/panama-gl/blob/feature/fbo/src/main/java/opengl/GL.java__;!!ACWV5N9M2RV99hQ!N1IqZWbHmbyQKeD-bZ56aFuRVi5ggyH3P29fbW4qQWw5aUZA5FGUXzIA2_xKtJLsPq5eP2TSyTzgXDKBuZ0Um11CORVuaFXTDX0_Zw$" rel="noreferrer nofollow noopener" target="_blank">
GL interface</a>. I then define a <a title="GL_macOS_10_15_3" href="https://urldefense.com/v3/__https://github.com/jzy3d/panama-gl/blob/feature/fbo/src/main/java/opengl/macos/GL_macOS_10_15_3.java__;!!ACWV5N9M2RV99hQ!N1IqZWbHmbyQKeD-bZ56aFuRVi5ggyH3P29fbW4qQWw5aUZA5FGUXzIA2_xKtJLsPq5eP2TSyTzgXDKBuZ0Um11CORVuaFWtFaPP-w$" rel="noreferrer nofollow noopener" target="_blank">
GL_macOS_10_15_3</a> class that wraps the binding (!). When I expand the prototype to Windows, I should copy paste this to GL_Windows_10 and modify the imports to reference the appropriate bindings. The goal is to write code like this</div>
<div style="font-family: Arial; font-size: 14px;"><br>
</div>
<div style="font-family: Arial; font-size: 14px;">GL gl = Platform.selectAmong(GL_macOS_10_15_3.class, GL_windows_10.class, ...)</div>
<div style="font-family: Arial; font-size: 14px;">gl.glDoSomething()</div>
<div style="font-family: Arial; font-size: 14px;"><br>
</div>
<div style="font-family: Arial; font-size: 14px;">I don't think there would be another way to have java developer write
<b>applications that ignore the target hardware</b>. However my approach is stupid : time consuming and error prone because manual. A real life case may have 10 implementations and 1000 functions.</div>
<div style="font-family: Arial; font-size: 14px;"><br>
</div>
<div style="font-family: Arial; font-size: 14px;"><b>Does JExtract provide a solution to this</b>? Should I create this tool by myself based on all generated bindings ? Would anyone
<b>recommend something smarter</b>?</div>
<div style="font-family: Arial; font-size: 14px;"><br>
</div>
<div style="font-family: Arial; font-size: 14px;">Regards,</div>
<div style="font-family: Arial; font-size: 14px;"><br>
</div>
<div style="font-family: Arial; font-size: 14px;">Martin   </div>
<div style="font-family: Arial; font-size: 14px;"><br>
</div>
<div style="font-family:
              Arial; font-size: 14px;" class="protonmail_signature_block">
</div>
</blockquote>
</blockquote>
<br>
</div>
</blockquote>
</blockquote>
<br>
</div>
</div>
</blockquote>
</div>
<br>
</div>
</body>
</html>