aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/com/jogamp/gluegen/JavaEmitter.java
Commit message (Collapse)AuthorAgeFilesLines
* GlueGen JavaCallback: Add capability to have UserParam as (part of) keySven Gothel2023-07-081-1/+1
| | | | | | | | | Resolves use case where UserParam reflects e.g. a context (AL_SOFT_events) and will be (part of) the key mapping. Implementation required an additional userParamID -> userParam mapping for default Object/ID usage. Added 2 test cases.
* GlueGen JavaCallback: Remove ambiguity: Config ↵Sven Gothel2023-07-061-20/+6
| | | | JavaCallbackDef/JavaCallbackKey: Always define both parameter indices; emitJavaStaticCallback(): Use cbFuncBinding and cbFuncKeyIndices from callback parameter to build key
* GlueGen: Add 'PascalString' string semantics (length + value-ptr), added ↵Sven Gothel2023-07-051-5/+14
| | | | | | | | | | | | | | | | | | | | | | | | | prelim code for JavaCallback use-case emitBodyMapCToJNIType() It is common in toolkit APIs that a string might not be passed as a 'nul' terminated (EOS) C string, but as a Pascal string with a given length argument. A C string is specied as ArgumentIsString alEventCallbackInject 3 while allowing multiple indices .. A Pascal string can be specified as ArgumentIsPascalString ALEVENTPROCSOFT 3 4 while allowing multiple indice-tuples for length and value .. The tuple consist of the length agrument-index first (usually an int) followed by the value argument-index (usually a 'char*'). +++ CMethodBindingEmitter.emitBodyMapCToJNIType(), where PascalString is implemented, is currently being used for - JNI return statement (no PascalString impact possible) - JavaCallback C type -> JNI type, PascalString impacting
* GlueGen JavaCallback/LibraryOnLoad: Always include the `libraryBasename` ↵Sven Gothel2023-07-051-2/+2
| | | | agnostic 'emitJNIEnvDecl()' (declaration) in JNI code; Detach the thread from the JVM if newly attach in callback!
* GlueGen JavaCallback: Revised: Static Java callback dispatcher, dropping ↵Sven Gothel2023-07-041-11/+25
| | | | | | | | | | | | | | | | | | | | | | | | | native heap, support Struct UserParam ... Implementation now generates a static Java callback dispatcher for each defined SetCallbackFunction, which gets invoked by the generated native static counterpart with all arguments required. The static callback utilizes its own synchronization for thread-safety and fetches the required data set stored at SetCallbackFunction to dispatch the call to the users' CallbackFunction. In case the callback has been removed already, the static callback simply bails out quietly. The native code does not create, release or manage heap memory and therefore is considered safe. +++ Further Struct Type UserParam are now supported including Heterogeneous UserParam mapping (read GlueGen_Mapping.*). +++ Cleaned up code by extracting all JavaCallback emitter code into JavaCallbackEmitter class in one place, leaving JavaMethodbindingEmitter and CMethodbindingEmitter mostly in their original stage (non-convoluted). In this regard, I had to refactor a few function, i.e. moving CMethodbindingEmitter.getJNIMangledArg(..) into JavaType.appendDescriptor(..) and JavaType.appendJNIDescriptor(..) while reusing the toJNIMethodDescriptor(..) conversion. Test4JavaCallback covers and passes all cases.
* GlueGen JavaCallback: Unify native 'T_JavaCallbackGlueData' typedef structcallback_jniuserparamproxySven Gothel2023-07-021-0/+3
|
* GlueGen Struct [18]: Drop redundant 'static get*ElemCount() { return 1 }` ↵Sven Gothel2023-07-021-2/+4
| | | | for: isPrimitive && !isPointer && staticElemCount && maxOneElement
* GlueGen JavaCallback: Only produce default 'Key' class if keys are used, ↵Sven Gothel2023-07-011-0/+5
| | | | | | | | | | | expose 'Key' to public and use it. Expose release*() and get*Keys() methods Further we use a dedicated lock Object used in the Java implementation. TODO: Native static callback dispatch code shall - (also) acquire the lock - handle case where the data has been released already to render this solution thread-safe and data-race free
* GlueGen JavaCallback: Resolve key mapping of callback and associated ↵Sven Gothel2023-06-301-22/+40
| | | | | | | | | | | | | | | | resources via 'JavaCallbackKey' config and custom `SetCallback-KeyClass` Updated unit test and doc accordingly. Unit tests handle OpenAL's AL_SOFT_callback_buffer and AL_SOFT_events. Tested global scope (no key, default) and 1 key (default) and 1 key (custom class). Added more query functions, which all only take the `SetCallbackFunction` key arguments as specified. Cleaned up JavaCallback* config class field naminig scheme. Added 'synchronized (..Map) { }' block in crucial `SetCallbackFunction`, rendering implementation thread safe.
* GlueGen JavaCallback: 1st Working Draft: Changed 'JavaCallbackDef' config, ↵Sven Gothel2023-06-291-55/+45
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | added code generation incl. native to Java dispatch and resource management Tested via Test4JavaCallback.java (using test2.[hc]). Please read the GlueGen_Mapping.md as well as Test4JavaCallback.java . +++ Some implementation details: JavaConfiguration maps JavaCallbackDef to JavaCallback set-function and maintains a list. JavaCallbackDef itself holds all configured details. JavaConfiguration also maps JavaCallbackInfo to JavaCallback set-function. JavaCallbackInfo itself holds all compile time information, as produced by JavaEmitter.beginFunctions(..). This extends JavaCallbackDef and avoid repetetive computation for the callback-function-type and its MethodBinding, parameter indices for the callback interface and userParam, etc. CMethodBindingEmitter: Native callback to Java dispatch - The JavaCallback setter function creates a native 'UserParam' struct instance, which holds the callback-interface-jobject, its callback-jmethodID and the userParam-jobject for invocation of the actual JavaCallback interface method. - To produce the C-Type -> JNI-Type conversion, An internal CMethodBindingEmitter instance for the native-callback function binding is created inside the CMethodBindingEmitter of the callback setter method. It is being used to map the types to JNI within the generated native callback function, passed to the actual JavaCallback method. JavaMethodBindingEmitter: Native callback to Java dispatch - The JavaCallbacl setter passes the callback-interface-object, the userParam-object and the callback-method-signature (to have the native method retrieve the jmethodID). - It receives the native pointer of the native `UserParam` struct instance, which gets mapped to the userParam-object. (*TODO: Refine ownership + release*).
* GlueGen: Move [de]captializeString(..) JavaEmitter -> static in CodeGenUtilsSven Gothel2023-06-291-7/+7
|
* GlueGen LibraryOnLoad Config: Generate `JNI_OnLoad(..)` for dynamic and ↵Sven Gothel2023-06-291-1/+7
| | | | `JNI_OnLoad_<LibraryBasename>(..)` for static libraries and `JVMUtil_GetJNIEnv(..)` to resolve the `JNIEnv*` as used by JavaCallback
* GlueGen Struct [17]: Handle void pointers, i.e. `void*`, within a struct as ↵Sven Gothel2023-06-291-10/+5
| | | | | | `Opaque` configured pointer-types .. includes cross-ref'ed doc and unit test
* GlueGen JavaCallback: Move JavaCallback into JavaConfiguration, accessible ↵Sven Gothel2023-06-261-52/+31
| | | | across *Emitter (needed for CMethodEmitter as well); Add JavaCallback.methodSignature to be passed to native function later on to find the callback jmethodID
* GlueGen JavaCallback: Expose getJNIMethodDescriptor() for JNI mangled method ↵Sven Gothel2023-06-261-7/+11
| | | | names, used in CMethodBindingEmitter; Use JavaCallback's function-pointer-type capital-name as simple-class-name and its FQN for JNI resolution.
* GlueGen JavaCallback: Use new JavaType nature 'named-class', denoting the ↵Sven Gothel2023-06-261-1/+1
| | | | | | | | | | | | generated callback interface mapping the callback function. This passes the jobject for the callback function/interface and the userParam (from 'void*') down to the native implementation. TODO: Add specific native implementation for JavaCallback, wrapping the jobject's into a native struct as user-param and a universal C-function as the native callback to dispatch the call to the java method with known arguments.
* GlueGen JavaCallback: Add preliminary implementation (WIP): Produces proper ↵Sven Gothel2023-06-251-5/+134
| | | | | | interfaces, TODO implementation Note: JavaCallbackDef is commented out on test2.cfg example, since implementation is missing.
* JavaEmitter.generateArrayGetterSetterCode(): Place elemCountExpr null check ↵Sven Gothel2023-06-251-8/+7
| | | | where it could occur -> non-opaque, non-primitive array case
* GlueGen: Add JavaEmitter(JavaConfiguration) ctorSven Gothel2023-06-251-0/+5
|
* GlueGen: Rename GlueEmitter.getConfig{uration->}() and drop ↵Sven Gothel2023-06-251-10/+3
| | | | JavaEmitter.getConfig(), cleaning up API usage
* GlueGen Struct [16]: Add support for pointer-pointer and function-pointer valuesSven Gothel2023-06-231-173/+195
| | | | See documentation and unit test test2.h, Test2FuncPtr.java and Test3PtrStorage.java
* GlueGen: Type: Have get{Base,Target}Type() stop at isFunctionPointer(), ↵Sven Gothel2023-06-231-20/+8
| | | | | | | | | | enhance API doc; Add getArrayBaseOrPointerTargetType() and getTargetFunction() Added getArrayBaseOrPointerTargetType() returns getBaseType() for arrays or getTargetType() for pointer, i.e. stops traversing if an elementType is a pointer and returns the elementType as target-type. This resolves 'int* intPtrArray[10]', but also simplifies all cases of 'int** intPtrPtr' and 'int intPtr[10]' etc. Since get{Base,Target}Type() returns the functionPointer, getTargetFunction() allows to retrieve the actual target function type.
* JavaEmitter.typeToJavaTypeImpl(): Add targetType in GlueGenException and ↵Sven Gothel2023-06-211-13/+15
| | | | remove '"' in message
* GlueGen Struct [15b]: FunctionPointer: Drop is<FuncName>Null() -> use ↵Sven Gothel2023-06-201-7/+2
| | | | get<FuncName>()
* GlueGen Struct [15]: Add FunctionPointer getter and setter support w/ ↵Sven Gothel2023-06-201-39/+84
| | | | documentation
* GlueGen Type: Use virt getTargetType() for ArrayType dropping ↵Sven Gothel2023-06-191-8/+8
| | | | getElementType(); Rename getBase{Elem ->}Type() to align with getTargetType()
* CustomJNICode: Fix/complete commit d7bc10d7ff0e3a30d74c4e4c439230f3983bcfb4: ↵Sven Gothel2023-06-181-0/+4
| | | | Add emitCustomJNICode(..) for JavaEmitter.endFunctions() not just structs and fix the JNI-c stub code
* Merge remote-tracking branch 'Mathieu_Fery/feature/add_customJNICode_directive'Sven Gothel2023-06-181-1/+19
|\
| * feat(jni): Add directive for dedicated JNI Code with CustomJNICodeMathieu Féry2023-06-161-1/+19
| |
* | GlueGen Struct [12]: Throw InternalError(..) for produced code-path where ↵Sven Gothel2023-06-181-0/+15
| | | | | | | | Ownership.Native _and_ native memory potentially gets replaced
* | GlueGen Struct [11]: Formalize Ownership (enum) and elaborate generated Java ↵Sven Gothel2023-06-181-120/+208
| | | | | | | | API-Doc
* | GlueGen Struct [10]: Don't skip primitive w/ platform dependent sized type ↵Sven Gothel2023-06-181-14/+7
| | | | | | | | | | | | | | | | | | | | in struct (like 'int') .. We already support platform dependent sizes like pointer etc, no reason to drop e.g. 'int'. Note: 'int' is also always 32bit of size within our current set of supported platforms, e.g. MachineDataInfo. Further fix and clarify primCElemFixedSize and primElemSizeExpr, only to be true and set if isPrimitive.
* | GlueGen Struct [9]: Fix regression which added a pointer referencing type ↵Sven Gothel2023-06-181-0/+8
| | | | | | | | 'void', i.e. exclude if !baseCElemType.hasSize() // like 'void*' -> 'void'
* | GlueGen Struct [8]: Revised setter (resolved shrinking array, using 'subset' ↵Sven Gothel2023-06-171-87/+180
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | flag), added (detailed) JavaDoc in generated code Revised setter: A) int32_t val[10] -> setter for a subset change only, as-is with args[src, srcPos, destPos, length] - no new memory, reuse only - no special action to be performed B) int32_t* val -> setter with toggle 'subset' with args[subset, src, srcPos, destPos, length], - replace memory w/ 'subset==false' where it also may copy 'destPos' gap from old -> new - reuse memory w/ 'subset==true', where destPos+length <= elementCount C) const int32_t* val -> setter to replace referenced memory only args[src, srcPos, length] - always replaces memory, no copy of a gap (no destPos) Hence: - case (A) stays as is - case (B) will be revised and argument 'boolean subset' added - case (C) will be revised (simplified) and argument 'destPos' removed
* | GlueGen Struct [7]: Keep struct class non-final (revert), but ensure methods ↵Sven Gothel2023-06-161-9/+9
|/ | | | are final. Drop useless 'final' of 'static final'.
* GlueGen Struct [6]: Simplify adding 'private ElementBuffer _eb*' memory ↵Sven Gothel2023-06-161-27/+3
| | | | buffer cache once @ 'releaseVal(..)' code creation
* GlueGen Struct [5]: Revised Struct Mapping + DocumentationSven Gothel2023-06-161-868/+959
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | GlueGen Revised Struct Mapping (esp pointer to array or single element), Struct String Charset, .. and Documentation - Documentation: - Added README.md Let's have a proper face for the git repo - Added doc/GlueGen_Mapping.md (and its html conversion doc/GlueGen_Mapping.html) Created a new document covering application and implementation details suitable for users/devs. - Added doc/JogAmpMacOSVersions.md conversion to doc/JogAmpMacOSVersions.html - Updated www/index.html - Use *CodeUnit instead of PrintWriter, representing a Java or C code unit covering a set of functions and structs. The CCodeUnit also handles common code shared by its unit across functions etc. - Dropping 'static initializer', as its no more required due to simplified `JVMUtil_NewDirectByteBufferCopy()` variant. - Revised Struct Mapping: - Pure Java implementation to map primitive and struct fields within a struct by utilizing ElementBuffer. Only 'Function Pointer' fields within a struct require native code. Exposes `static boolean usesNativeCode()` to query whether native code is used/required. - Transparent native memory address API Expose `long getDirectBufferAddress()` and `static TK_Struct derefPointer(long addr)`, allowing to - pass the native struct-pointer with native code - reconstruct the struct from a native struct-pointer - have a fully functional `TK_Struct.derefPointer(struct.getDirectBufferAddress())` cycle. - Add 'boolean is<Val>Null() to query whether a pointer (array) is NULL - *Changed* array get/set method for more flexibility alike `System.arraycopy(src, srcPos, dest, destPos, len)`, where 'src' is being dropped for the getter and 'dest' is being dropped for the setter as both objects are reflected by the struct instance. - *Changed* `get<Val>ArrayLength()` -> `get<Val>ElemCount()` for clarity - Considering all ConstElemCount values with config 'ReturnedArrayLength <int>' to be owned by native code -> NativeOwnership -> Not changing the underlying memory region! JavaOwnership is considered for all pointer-arrays not of NativeOwnership. Hence any setter on a NativeOwnership pointer-array will fail with non-matching elem-count. - Add 'release<Val>()' for JavaOwnership pointer-arrays, allowing to release the Java owned native memory incl. null-ing pointer and set<Val>ElemCount(0). - Support setter for 'const <type>*' w/ JavaOwnership, i.e. pointer to const value of a primitive or struct, setter and getter using pointer to array or single element in general. - Added Config `ImmutableAccess symbol` to disable all setter for whole struct or a field - Added Config `MaxOneElement symbol` to restrict a pointer to maximum one element and unset initial value (zero elements) - Added Config `ReturnsStringOnly symbol` to restrict mapping only to a Java String, dropping the ByteBuffer variant for 'char' - String mapping default is UTF-8 and can be read and set via [get|set]Charset(..) per class. - Dynamic string length retrieval in case no `ReturnedArrayLength` has been configured has changed from `strlen()` to `strnlen(aptr, max_len)` to be on the safe site. The maximum length default is 8192 bytes and can be read and set via [get|set]MaxStrnlen(..) per class. FIXME: strnlen(..) using EOS byte non-functional for non 8-bit codecs like UTF-8, US-ASCII. This is due to e.g. UTF-16 doesn't use an EOS byte, but interprets it as part of a code point. - TODO: Perhaps a few more unit tests - TODO: Allow plain 'int' to be mapped in structs IFF their size is same for all MachineDescriptions used. Currently this is the case -> 4 bytes like int32_t.
* GlueGen Struct [4]: JavaConfiguration Change: Drop 'ManualStaticInitCall', ↵Sven Gothel2023-06-161-29/+0
| | | | | | | | | | | | | 'ForceStaticInitCode'; Add 'ReturnsStringOnly', 'MaxOneElement' and 'ImmutableAccess' Drop 'ManualStaticInitCall', 'ForceStaticInitCode': With new CCodeUnit's `JVMUtil_NewDirectByteBufferCopy(..)` implementation and generalized Buffers' methods, no specific init code is required anymore. Add 'ReturnsStringOnly', 'MaxOneElement' and 'ImmutableAccess': - 'ReturnsStringOnly' only String getter, drop ByteBuffer/byte[] - 'MaxOneElement' only one element maximum for pointer reference - 'ImmutableAccess' strict read-only, also reduces generated code a lot
* Bug 1412 - JNI: GlueGen JavaEmitter: Check & Handle Exception after calling ↵Sven Gothel2019-12-061-0/+7
| | | | | | | back into Java The generated JNI code JVMUtil_NewDirectByteBufferCopy(..) calls Buffers.newDirectByteBuffer(..) and potential exceptions should be checked.
* Bug 1166: Refine fix of JavaEmitter's JVMUtil_NewDirectByteBufferCopy (2)Sven Gothel2015-07-161-3/+11
| | | | | | | Further refine code, see commit f6a5ac4473135bbc4bc1a5f537e060df45eb4824. - Perform a NULL check on Buffers.newDirectByteBuffer(..) result. - Only copy memory if capacity > 0, incl fetching direct buffer address
* JavaEmitter.staticClassInitCodeCCode: Reuse static stringsSven Gothel2015-07-161-7/+10
|
* Bug 1166: Refine fix of JavaEmitter's JVMUtil_NewDirectByteBufferCopySven Gothel2015-07-161-3/+11
| | | | | | | | | | | See commit e424c28f869269f5a22c22ef017230346b22847a (first patch) Since JVMUtil_NewDirectByteBufferCopy is being called w/ 'size_t' values, e.g. 'count * sizeof(Structure)', we shall validate whether 'capacity' is valid, i.e. <= MAX_INT. After validation, 'capacity' is being cast to 'jint' before being passed to the java method.
* BUG 1166: Fix JavaEmitter JVMUtil_NewDirectByteBufferCopyXerxes Rånby2015-07-081-2/+2
| | | | | | | | | | | Prevents jlong to jint truncation when capacity is passed from jni to java. com.jogamp.common.nio.Buffers newDirectByteBuffer and the underlying java.nio.ByteBuffer allocateDirect only work with capacitys of int size. Signed-off-by: Xerxes Rånby <[email protected]>
* Bug 1153 - GlueGen: Support [const] [native] expressions and conversion to ↵Sven Gothel2015-04-011-203/+76
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | java space, incl. [native] numbers Rewrite ConstantDefinition: Add sub-class CNumber: - containing integer/float values and their original qualifiers [long, double, unsigned] - conversion to java number ConstantDefinition: - holds native expression - optionally holds CNumber representing native expression, if [only] a number - can compute equivalent java expression with result type (JavaExpr) Add static native number reg-expression for number detection and parsing. Add static native number to CNumber conversion methods. +++ Retrieve full LISP tree and convert to serialized expression to be utilized for expressions used in enumerates. Parse enumerates, allowing const native expressions: - Utilize ConstantDefinition either for definite CNumber or expression - Simply add "+1" for new default values, if previous is an expression
* JavaEmitter: Always use 'containingJTypeName' for ↵Sven Gothel2015-03-261-6/+6
| | | | | | | JavaConfiguration.canonicalStructFieldSymbol(..) Patch harmonizes configuration, was also using 'structCTypeName' besides 'containingJTypeName', but surely it makes no sense to use different type names for struct-field configurations.
* Bug 1149: Fix parsing of hexadecimal w/ binary exponent floats in ↵Sven Gothel2015-03-251-4/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | regexp-constant and java-parser. (Due to PCPP -> JCPP) Lack of parsing binary exponent floats is exposed due to using JCPP and correct constant-definitions. - JavaParser.g: - Add support for hexadecimal w/ binary exponent floats - TAB -> 4 spaces - ConstantDefinition.java: - Add RegExp 'fpRegexp', patternDecimalNumber: decimal number w/ support for hexadecimal w/ binary exponent floats. - isDecimalNumber(..): Use patternDecimalNumber instead of try-and-error (NumberFormatException) - patternCPPOperand: exclude patternDecimalNumber! - JavaEmitter.java: - Respect explicit suffix [dD] for double type. - Drop floating point suffixes [fF] - Test: Added tests for hexadecimal w/ binary exponent floats
* Bug 1149 - Replacing PCPP w/ JCPP, allowing complete macro handling (Part-1: ↵Sven Gothel2015-03-231-37/+35
| | | | Cleanup / Preparation)
* Bug 1144 - Add 'DelegateImplementation': Requires own MethodBinding for ↵Sven Gothel2015-03-111-38/+58
| | | | | | | | | | | | | | | | | | | | | | delegates impl. / Adding ReturnsOpaque - DelegateImplementation requires own MethodBinding for delegates impl. The delegation name must be included within the FunctionSymbol's aliases _only_ for implementations, where delegation applies. This allows all subsequent type/cfg checks to hit on AliasedSymbol! Hence we need to create individual MethodBinding instances for interfaces and public/private implementations. - Adding ReturnsOpaque Configuration: ReturnsOpaque <Primitive Java Type> <Function Name> This feature is necessary to achieve 'Opaque' functionality for function's return type - instead of types in general. - Fix AliasedSymbolImpl copy-ctor, i.e. this.name = o.name !
* Bug 1134 - LOG AliasedSymbol: Don't issue getAliasedString(), logger takes ↵Sven Gothel2015-03-111-2/+2
| | | | care of that, when it logs.
* Bug 1144 - Add 'DelegateImplementation', manually impl. may delegate to ↵Sven Gothel2015-03-111-7/+16
| | | | | | | | | | | | | | | | | | | | | | | | renamed original 'DelegateImplementation' is a variation of 'ManuallyImplement'. 'ManuallyImplement' emits the interface method, but suppresses the Java and native-code implementation. The latter shall be implemented manually by the user. 'DelegateImplementation' emits the interface method, and the _private_ renamed Java and native-code implementation. Both can be called from the manual user implementation, hence delegation. Configuration: DelegateImplementation <ORIG-SYMBOL> <RENAMED-IMPL-SYMBOL> I.e. delegation model shall apply to <ORIG-SYMBOL> and the Java and native-code implementation renamed to <RENAMED-IMPL-SYMBOL>. The user manual implementation of <ORIG-SYMBOL> may delegate to <RENAMED-IMPL-SYMBOL>.