Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added Info.plist
Binary file not shown.
12 changes: 12 additions & 0 deletions archive_jnf.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh -e

distdir=$(pwd)/dist

mkdir ${distdir}
rm -f ${distdir}/JavaNativeFoundation.zip
rm -f ${distdir}/JavaNativeFoundation.dmg

(cd buildNative/Frameworks; zip --symlinks -r ${distdir}/JavaNativeFoundation.zip JavaNativeFoundation.framework)

hdiutil create -srcfolder buildNative/Frameworks -volname JavaNativeFoundation ${distdir}/JavaNativeFoundation.dmg

6 changes: 2 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,9 @@ val buildJNF by tasks.registering(Exec::class) {
commandLine("sh", "build_jnf.sh")
}

val archiveJNF by tasks.registering(Zip::class) {
val archiveJNF by tasks.registering(Exec::class) {
dependsOn(buildJNF)
archiveFileName.set("JavaNativeFoundation.framework.zip")
destinationDirectory.set(project.buildDir.resolve("frameworks"))
from("buildNative/Frameworks/JavaNativeFoundation.framework")
commandLine("sh", "archive_jnf.sh");
}

fun registerJNFConfiguration(architecture : String) = configurations.registering {
Expand Down
2 changes: 1 addition & 1 deletion build_jnf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

if [[ $(arch) == "arm64" ]] ; then
echo "Re-execing build using Rosetta." >&2
exec arch -x86_64 ${0} "${@}"
exec arch -x86_64 /bin/sh ${0} "${@}"
fi

SDK_NAME=macosx
Expand Down
75 changes: 75 additions & 0 deletions build_jnf2.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/bin/sh -e

SDK_NAME=macosx

CONCURRENCY=$(sysctl -n hw.activecpu)
CODE_SIGN_IDENTITY=${AMFITRUSTED_IDENTITY:--}
DEBUG_LEVEL=release

# Exporting this such that /usr/bin/clang uses it implictly
export SDKROOT=$(xcrun --sdk ${SDK_NAME} --show-sdk-path)
MACOSX_DEPLOYMENT_TARGET=10.10
export LD_DYLIB_INSTALL_NAME=@rpath/JavaNativeFoundation.framework/Versions/A/JavaNativeFoundation

cc=/usr/bin/cc
lipo=/usr/bin/lipo
srcdir=$(pwd)/src/JavaNativeFoundation
include1=${JAVA_HOME}/include
include2=${JAVA_HOME}/include/darwin
include3=${srcdir}/..

topdir=$(pwd)
libdir=$(pwd)/buildNative/lib
fwdir=$(pwd)/buildNative/Frameworks

build1() {
arch=$1
echo building for $arch
${cc} -arch $arch -o ${libdir}/lib$arch.dylib -I${include1} -I${include2} -I${include3} -framework Cocoa \
-dynamiclib -ObjC -fvisibility=hidden -install_name ${LD_DYLIB_INSTALL_NAME} -g \
-mmacosx-version-min=${MACOSX_DEPLOYMENT_TARGET} -Wl,-current_version,80 -Wl,-compatibility_version,1 \
${srcdir}/*.m
}

do_jnf() {
rm -rf buildNative
mkdir -p buildNative/Frameworks
mkdir -p buildNative/lib
build1 x86_64
build1 arm64
${lipo} ${libdir}/libx86_64.dylib ${libdir}/libarm64.dylib -create -output ${libdir}/JavaNativeFoundation
${lipo} ${libdir}/libx86_64.dylib.dSYM/Contents/Resources/DWARF/libx86_64.dylib \
${libdir}/libarm64.dylib.dSYM/Contents/Resources/DWARF/libarm64.dylib \
-create -output ${libdir}/JavaNativeFoundation-DSYM

cd ${fwdir}
mkdir JavaNativeFoundation.framework
cd JavaNativeFoundation.framework
mkdir -p Versions/A/Headers
mkdir -p Versions/A/Resources
mkdir -p Versions/A/Modules
cp -p ${libdir}/JavaNativeFoundation Versions/A
cp -p ${srcdir}/J*.h Versions/A/Headers
cp -p ${srcdir}/Modules/module.modulemap Versions/A/Modules
xcrun tapi stubify --filetype=tbd-v5 -o Versions/A/JavaNativeFoundation.tbd \
Versions/A/JavaNativeFoundation
cp -p ${topdir}/Info.plist Versions/A/Resources

(cd Versions; ln -s A Current)
ln -s Versions/Current/Headers .
ln -s Versions/Current/Resources .
ln -s Versions/Current/Modules .
ln -s Versions/Current/JavaNativeFoundation .
ln -s Versions/Current/JavaNativeFoundation.tbd .

cd ${fwdir}
mkdir -p JavaNativeFoundation.framework.dSYM/Contents/Resources/DWARF
cp -p ${libdir}/JavaNativeFoundation-DSYM JavaNativeFoundation.framework.dSYM/Contents/Resources/DWARF/JavaNativeFoundation
cp -p ${topdir}/dsym-Info.plist JavaNativeFoundation.framework.dSYM/Contents/Info.plist

codesign --sign ${CODE_SIGN_IDENTITY} --timestamp --force --verbose JavaNativeFoundation.framework/*.tbd
codesign --sign ${CODE_SIGN_IDENTITY} --timestamp --force --verbose JavaNativeFoundation.framework
codesign --sign ${CODE_SIGN_IDENTITY} --timestamp --force --verbose JavaNativeFoundation.framework.dSYM
}

do_jnf
20 changes: 20 additions & 0 deletions dsym-Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleIdentifier</key>
<string>com.apple.xcode.dsym.com.apple.JavaNativeFoundation</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>dSYM</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleShortVersionString</key>
<string>80</string>
<key>CFBundleVersion</key>
<string>80</string>
</dict>
</plist>
5 changes: 5 additions & 0 deletions module.modulemap
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
framework module JavaNativeFoundation [extern_c] {
umbrella header "JavaNativeFoundation.h"
export *
module * { export * }
}
1 change: 0 additions & 1 deletion openjdk
Submodule openjdk deleted from 356491
104 changes: 104 additions & 0 deletions src/JavaNativeFoundation/JNFAssert.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*
* Copyright (c) 2008-2020 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* --
*
* Assertions used by the JNF_COCOA_ENTER()/JNF_COCOA_EXIT() and class
* caching macros. When building debug builds, improper use of the caching
* macros will trigger warnings output to the console.
*/

#import <JavaNativeFoundation/JNFJNI.h>

#ifdef DEBUG
#define JAVA_ASSERTIONS_ON
#endif /* DEBUG */

// Use the WARN macro to send a message to stderr in the
// debug build. It gets removed from the optimized build
// during preprocessing.
#ifdef DEBUG
#define JNF_WARN JNFDebugWarning
#else
#define JNF_WARN if (0) JNFDebugWarning
#endif /* DEBUG */

__BEGIN_DECLS

JNF_EXPORT extern void JNFDebugWarning(const char *fmt, ...);

JNF_EXPORT extern void JNFAssertionFailure(const char *file, int line, const char *condition, const char *msg);

#ifdef JAVA_ASSERTIONS_ON

#define JNF_ASSERT_FAILURE(condition, msg) \
JNFAssertionFailure(__FILE__, __LINE__, condition, msg) \


#define JNF_ASSERT_MSG(condition, msg) \
do { \
if (!(condition)) { \
JNF_ASSERT_FAILURE(#condition, msg); \
} \
} while(0) \


#define JNF_ASSERT_COND(condition) \
JNF_ASSERT_MSG(condition, NULL) \


#define JNF_EXCEPTION_WARN(env, msg) \
do { \
(*(env))->ExceptionDescribe(env); \
JNF_ASSERT_FAILURE("Java exception thrown", msg); \
} while (0) \


#define JNF_ASSERT_NO_EXCEPTION_MSG(env, msg) \
if ((*(env))->ExceptionOccurred(env)) { \
JNF_EXCEPTION_WARN(env, msg); \
} \


#define JNF_ASSERT_NO_EXCEPTION(env) \
JNF_ASSERT_NO_EXCEPTION_MSG(env, NULL) \

#else

#define JNF_ASSERT_COND(condition)
#define JNF_ASSERT_MSG(condition, msg)
#define JNF_EXCEPTION_WARN(env, msg)
#define JNF_ASSERT_NO_EXCEPTION(env)
#define JNF_ASSERT_NO_EXCEPTION_MSG(env, msg)

#endif /* JAVA_ASSERTIONS_ON */

JNF_EXPORT extern void JNFDumpJavaStack(JNIEnv *env);

__END_DECLS
69 changes: 69 additions & 0 deletions src/JavaNativeFoundation/JNFAssert.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Copyright (c) 2008-2020 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/

#import "JNFJNI.h"
#import "JNFAssert.h"

#import "debug.h"

static void JNFDebugMessageV(const char *fmt, va_list args) {
// Prints a message and breaks into debugger.
fprintf(stderr, "JavaNativeFoundation: ");
vfprintf(stderr, fmt, args);
fprintf(stderr, "\n");
}

static void JNFDebugMessage(const char *fmt, ...) {
// Takes printf args and then calls DebugBreak
va_list args;
va_start(args, fmt);
JNFDebugMessageV(fmt, args);
va_end(args);
}

void JNFDebugWarning(const char *fmt, ...) {
// Takes printf args and then calls DebugBreak
va_list args;
va_start(args, fmt);
JNFDebugMessageV(fmt, args);
va_end(args);
}

void JNFAssertionFailure(const char *file, int line, const char *condition, const char *msg) {
JNFDebugMessage("Assertion failure: %s", condition);
if (msg) JNFDebugMessage(msg);
JNFDebugMessage("File %s; Line %d", file, line);
}

void JNFDumpJavaStack(JNIEnv *env) {
static JNF_CLASS_CACHE(jc_Thread, "java/lang/Thread");
static JNF_STATIC_MEMBER_CACHE(jsm_Thread_dumpStack, jc_Thread, "dumpStack", "()V");
JNFCallVoidMethod(env, jc_Thread.cls, jsm_Thread_dumpStack);
}
52 changes: 52 additions & 0 deletions src/JavaNativeFoundation/JNFAutoreleasePool.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright (c) 2008-2020 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* --
*
* Utility class used by the JNF_COCOA_ENTER()/JNF_COCOA_EXIT() macros
* from JNFJNI.h. Do not use this class or releated functions directly.
*/

#import <Foundation/Foundation.h>

#import <JavaNativeFoundation/JNFJNI.h>

__BEGIN_DECLS

typedef void JNFAutoreleasePoolToken;

// JNFNativeMethodEnter - called on entry to each native method by the
// JNF_COCOA_ENTER(env) macro in JNFJNI.h
JNF_EXPORT extern JNFAutoreleasePoolToken *JNFNativeMethodEnter(void);

// JNFNativeMethodExit - called on exit from each native method by the
// JNF_COCOA_EXIT(env) macro in JNFJNI.h
JNF_EXPORT extern void JNFNativeMethodExit(JNFAutoreleasePoolToken *token);

__END_DECLS
Loading