Commit Graph

44 Commits

Author SHA1 Message Date
Peter Johnson
af2f54720d Java: Don't detach thread when releasing globals.
JavaGlobal was unconditionally attaching to (okay) and detaching from (bad)
the current thread during destruction.  We don't want to do this if the
destructor gets called from an attached thread.  Instead, use GetEnv to
first try to get the environment, and only attach and detach if it returns
an error saying the thread is detached.

Also, make sure notifier callbacks appropriately free Java locals to avoid
running out of local variable space.
2016-01-01 19:05:00 -08:00
Peter Johnson
fef8f933d9 Add SafeThread to fix thread JNI shutdown races.
During JVM shutdown, some JNI calls may not return, so it's not possible to
reliably perform a join() during static variable destruction (which occurs
as the JVM unloads the JNI module).

Also, due to static variable destruction, it's not safe to use any members
of a static class instance from a separate thread of execution.

SafeThread is a templated thread class and a related owner class that's
designed for safe operation and shutdown of threads in the presence of
callbacks that may not return.  It also passes ownership of variables from
the static instance to the thread, so the thread can safely operate until
it exits (the last operation of the thread being to destroy its instance).

Notifiers, RpcServer, and Logger now use SafeThread to ensure race-free
destruction in both C++ and Java.

All Java callback threads are now marked as Java daemon threads so they
don't keep the JVM running after main() terminates.

All Java callback threads are now named so their purpose is more easily
identified in a debugger.

Add SetRpcServerOnStart and SetRpcServerOnExit (similar to Listener).
2015-12-28 17:51:56 -08:00
Peter Johnson
8b3f4aa68c Remove unused member variable. 2015-12-21 09:03:30 -08:00
Peter Johnson
65e4eeeb7c Fix Windows linkage.
Windows needs ATOMIC_STATIC_INIT.
2015-12-20 21:06:17 -08:00
Peter Johnson
298dc54910 Fix Windows build. 2015-12-20 20:55:36 -08:00
Peter Johnson
32001427d4 Java: call JNI AttachCurrentThread less frequently.
Each call to AttachCurrentThread results in a new Java thread object being
created.  This is inefficient and also causes debugging issues with Eclipse
due to constant creation and removal of threads.  Now AttachCurrentThread is
only called once for (all) listeners and once for logging (if used).
2015-12-20 20:42:09 -08:00
Peter Johnson
76ee093e92 Add exception-generating C++ functions, but mark as deprecated.
These are good to have for backwards compatibility, but discouraged for new
development (default-taking functions should be used instead).  The reason
is that the exceptions must be explicitly handled and may initially work but
then fail at an inopportune moment.

Mark the similar Java functions as deprecated as well for the same reason.

Update all the docs for consistency.

Mark overridden functions as such in both C++ and Java.

Make IsPersistent and GetFlags const in C++.
2015-12-06 22:39:38 -08:00
Fredric Silberberg
db91e20ec7 Updated ntcore build to build both arm and native versions
Change-Id: I515f051bbb816a1a82667462ad4e140cdb0fabdc
2015-12-06 14:43:30 -05:00
Peter Johnson
3cd20d3ff2 Java: Fix getValue(). 2015-12-06 08:22:34 -08:00
Fredric Silberberg
26c27756af Updated the definitions file to add overloaded functions, added
no-unused-private-field for Mac builds. Gradle also now works
with the classifier-based dependency system, rather than having
separate repos for every level.

Change-Id: I2eb87391181e91b5675e3e982e4d915be83e14ea
2015-11-23 18:36:43 -05:00
Peter Johnson
c76e60324b Add Java support for raw values.
Either ByteBuffer or byte[] can be used for putRaw().
getRaw() returns byte[].
2015-11-20 01:22:26 -08:00
Thad House
2e050b0540 Makes SetTeam use Mdns 2015-11-19 23:02:39 -08:00
Jonathan Leitschuh
4c42712b24 Makes ITableListener a lambda function 2015-11-18 01:39:53 -05:00
Fredric Silberberg
6a0485a72c Fixed mac lib path
Change-Id: Ib6f38b7f42df9c9908c7e60eca12dd48c9c4114a
2015-11-17 18:51:16 -05:00
Peter Johnson
9200b7c78c Add extern "C" to JNI definitions to catch mismatches. 2015-11-01 07:44:43 -08:00
Fredric Silberberg
b793810e4a Fixes for mac builds
Change-Id: I66dafd5e6d5ff10e7fb98cf718bb6f9343d03184
2015-10-31 18:49:11 -04:00
Fredric Silberberg
9df5f5e27a When running on jenkins, the base name of produced archives becomes the project name. This fixes that to be the correct name.
Change-Id: Ie5a25bf9eabdb8fb1a1ee14d56e2e7badc634afc
2015-10-31 14:28:54 -04:00
Fredric Silberberg
77cf3adf64 This commit updates the gradle files to be cleaner. It also builds for the
current platform by default, and only builds tests when building for the
current platform. Mac builds and VS2015 builds are fixed.

The other big change in this update is the introduction of Debug and
Release builds. Debug builds are built with -O0 and -g. Release builds are
built with -O2 and -g. For GCC-based builds, the resulting shared object
is copied, stripped of debug information, and a debug link is set up to
the copied shared object. This allows the release build to clock in at
around 600 KB. On Windows, the debug info is already stored in a separate
PDB file, so this copy and strip is not necessary.

ntcore is being separated out from the rest of allwpilib. All other
builds will consume a published maven dependency from this project.
There are 4 possible publishing targets now: release, stable, beta, and
development. These are specified on the command line via -Prepo=<repo
name>.

Change-Id: Ie8cb21f910953e09b80a5192317033eb0866cb70
2015-10-31 13:31:01 -04:00
Joe Ross
202cb8bb1f fix javadoc warnings/errors 2015-10-03 19:20:26 -07:00
Peter Johnson
90959defd9 Provide more extensive listener features.
This enables listeners to be notified of not only value updates, but also flag
changes and deletions by using a bitmask to specify what notifications are
desired.  The old API (which only provided a new/not new) flag is still
supported.  This also subsumes the feature to listen to local changes (that's
one of the bitmask options).
2015-09-27 01:55:32 -07:00
Peter Johnson
3e8afc14b0 Java NetworkTable: perform string comparion correctly. 2015-09-27 01:55:32 -07:00
Peter Johnson
424bf51a7b Implement local notification.
The default behavior is to only notify remote changes, but for some
applications (e.g. GUI's) it's advantageous to know about local
changes as well.

This is (slightly) optimized in that local changes only result in
additional resources being consumed if (any) local listeners have been
created.
2015-09-23 00:56:08 -07:00
Peter Johnson
e2879b7bf2 Fix JNI embed location on Windows.
Make it Windows version agnostic and fix the amd64 runtime / x86-64 build
architecture naming difference.

See artf4198.
2015-09-20 10:56:06 -07:00
Peter Johnson
a3effbfb9f Java NetworkTable: Don't use ipAddress when starting server.
This matches the C++ behavior.  Using the IP address here is confusing to
users because it's actually the listen address.
2015-09-19 11:45:07 -07:00
Peter Johnson
23448c8277 NetworkTable interface: Provide method to set persistent filename. 2015-09-19 11:40:31 -07:00
Peter Johnson
d9fa086ec0 Include the ARM JDK JNI headers.
These are GPL-licensed.  This removes the dependency on the ARM JDK being
installed.

Fixes #24.
2015-09-19 08:30:40 -07:00
Peter Johnson
e42f9b0603 Add EntryInfo class (missed in previous commit). 2015-09-16 00:53:14 -07:00
Peter Johnson
c5d456f3a6 Add ITable/NetworkTable GetKeys and GetSubTables accessors. 2015-09-16 00:51:05 -07:00
Peter Johnson
6cbc219427 Add ITable/NetworkTable accessors for new features. 2015-09-15 23:43:42 -07:00
Peter Johnson
4b06e74a14 Java: Return boolean from put functions.
The put functions return false if the key already exists with a different type.
2015-09-15 22:23:34 -07:00
Peter Johnson
42f973ebe0 Java: Don't raise illegal state exceptions unless really necessary.
- Ignore no-op calls to setServerMode() / setClientMode().
- Duplicate calls to initialize() act as a restart.
- shutdown() silently does nothing if not running.
2015-09-15 22:03:11 -07:00
Peter Johnson
84e7d5906c Java: Use Global instead of WeakGlobal for callbacks.
For some reason, weak globals don't work as they (unexpectedly) are
getting destroyed even though we save the callback in a map at the Java
level.
2015-09-15 21:32:51 -07:00
Peter Johnson
51eb96903c Java: Improve robustness against JVM crashes on exit.
The JVM doesn't always do a good job of telling JNI modules that the JVM
is going away, which results in a crash in the JavaGlobal and/or
JavaWeakGlobal destructors as they try to delete the associated references
after the JVM has already gone away.

To protect against this, the Notifier now has a static variable that's set
when the Notifier instance (a singleton) is destroyed.  This is used by
JavaGlobal and JavaWeakGlobal to detect when a process exit is in process.
2015-09-14 22:00:22 -07:00
Peter Johnson
5181c4e5be Java: Don't free locals after detaching thread.
We use a smart pointer to hold local java variables, and it was getting
destructed after DetachCurrentThread() was called, causing a JVM crash.
2015-09-11 16:28:58 -07:00
Peter Johnson
a2ec638db8 Java: Use empty string as default IP rather than null.
Using null can crash the JVM if initialize() is called before setIPAddress.
2015-09-11 12:06:22 -07:00
Peter Johnson
702b6de734 Java: Fix crash on JVM exit.
Fixes #22.
2015-09-05 11:05:02 -07:00
Peter Johnson
6233b3477b Java: Fix fallback on external library. 2015-09-05 10:57:37 -07:00
Peter Johnson
e516200e09 Java: Add shutdown method to NetworkTable. 2015-08-28 23:57:37 -07:00
Peter Johnson
1ca0157768 Java: Add backwards compat shims for array types. 2015-08-28 21:09:46 -07:00
Peter Johnson
dbe4168d8d Java: allow both object arrays and native arrays.
This allows easier use of things like ArrayList<Double>.
2015-08-28 20:48:29 -07:00
Peter Johnson
969916851c Need to return nullptr, not false. 2015-08-28 17:17:20 -07:00
Peter Johnson
2b9e7c6af1 Silence MSVC warnings regarding bool conversions. 2015-08-28 14:07:51 -07:00
Peter Johnson
b971c741d7 Fix JNI for Windows and implement JNI getValue functions. 2015-08-28 13:52:16 -07:00
Peter Johnson
a990859db6 Initial commit of Java wrappers.
The JNI bindings are built directly into the shared library.  In the gradle
build, all built shared libraries are embedded into the generated jar.

Java bindings may be disabled via -DWITHOUT_JAVA (cmake) or -PskipJava=true
(gradle).

TODO:
- getEntryInfo() and RPC are not yet implemented.
- The cmake build doesn't integrate the built objects into the jar.
- The Java client and server tests are not built (but have been manually
  tested).

This has not yet been tested on Windows.
2015-08-28 12:43:49 -07:00