diff --git a/CHANGELOG.md b/CHANGELOG.md index c0d20e918..1b476fe00 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ +### February 11, 2022 version 1.5.7 * Add `Loader.clearCacheDir()` along with new `ClearMojo` and `-clear` command line option * Speed up `Loader` on Windows when there are no symbolic links or library versions ([pull #512](https://github.com/bytedeco/javacpp/pull/512)) * Enhance `Pointer.physicalBytes()` by excluding shared pages from memory-mapped files, etc ([issue #468](https://github.com/bytedeco/javacpp/issues/468)) diff --git a/README.md b/README.md index c82c623ef..8652d555a 100644 --- a/README.md +++ b/README.md @@ -26,27 +26,27 @@ We can also have everything downloaded and installed automatically with: org.bytedeco javacpp - 1.5.6 + 1.5.7 ``` * Gradle (inside the `build.gradle` file) ```groovy dependencies { - implementation group: 'org.bytedeco', name: 'javacpp', version: '1.5.6' + implementation group: 'org.bytedeco', name: 'javacpp', version: '1.5.7' } ``` * Leiningen (inside the `project.clj` file) ```clojure :dependencies [ - [org.bytedeco/javacpp "1.5.6"] + [org.bytedeco/javacpp "1.5.7"] ] ``` * sbt (inside the `build.sbt` file) ```scala - libraryDependencies += "org.bytedeco" % "javacpp" % "1.5.6" + libraryDependencies += "org.bytedeco" % "javacpp" % "1.5.7" ``` Another option available to Gradle users is [Gradle JavaCPP](https://github.com/bytedeco/gradle-javacpp), and similarly for Scala users there is [SBT-JavaCPP](https://github.com/bytedeco/sbt-javacpp). diff --git a/platform/pom.xml b/platform/pom.xml index 071b892ba..81844314e 100644 --- a/platform/pom.xml +++ b/platform/pom.xml @@ -4,7 +4,7 @@ 4.0.0 org.bytedeco javacpp-platform - 1.5.7-SNAPSHOT + 1.5.7 JavaCPP Platform The missing bridge between Java and native C++ diff --git a/platform/src/main/assembly/bin.xml b/platform/src/main/assembly/bin.xml index fd768fa3f..0b98657ba 100644 --- a/platform/src/main/assembly/bin.xml +++ b/platform/src/main/assembly/bin.xml @@ -26,6 +26,7 @@ *-javadoc.jar *-sources.jar + 0644 ${project.build.directory}/site diff --git a/pom.xml b/pom.xml index 5749e3d7e..10417cc3e 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 org.bytedeco javacpp - 1.5.7-SNAPSHOT + 1.5.7 JavaCPP The missing bridge between Java and native C++ diff --git a/src/main/assembly/bin.xml b/src/main/assembly/bin.xml index 30842b76c..acf9c9197 100644 --- a/src/main/assembly/bin.xml +++ b/src/main/assembly/bin.xml @@ -26,6 +26,7 @@ *-javadoc.jar *-sources.jar + 0644 ${project.build.directory}/site diff --git a/src/main/java/org/bytedeco/javacpp/Loader.java b/src/main/java/org/bytedeco/javacpp/Loader.java index 573ef84bc..cbce1ddb7 100644 --- a/src/main/java/org/bytedeco/javacpp/Loader.java +++ b/src/main/java/org/bytedeco/javacpp/Loader.java @@ -479,7 +479,7 @@ public static File cacheResource(URL resourceURL) throws IOException { /** * Extracts a resource, if the size or last modified timestamp differs from what is in cache, * and returns the cached {@link File}. If target is not null, creates instead a symbolic link - * where the resource would have been extracted. + * where the resource would have been extracted. Directories from JAR files are extracted recursively. * * @param resourceURL the URL of the resource to extract and cache * @param target of the symbolic link to create (must be null to have the resource actually extracted) @@ -760,6 +760,7 @@ public static File extractResource(URL resourceURL, File directoryOrFile, * Extracts a resource into the specified directory and with the specified * prefix and suffix for the filename. If both prefix and suffix are {@code null}, * the original filename is used, so directoryOrFile must not be {@code null}. + * Directories from JAR files are extracted recursively. * * @param resourceURL the URL of the resource to extract * @param directoryOrFile the output directory or file ({@code null == System.getProperty("java.io.tmpdir")}) diff --git a/src/main/java/org/bytedeco/javacpp/Pointer.java b/src/main/java/org/bytedeco/javacpp/Pointer.java index 0893bbe7d..ab62fc78f 100644 --- a/src/main/java/org/bytedeco/javacpp/Pointer.java +++ b/src/main/java/org/bytedeco/javacpp/Pointer.java @@ -576,6 +576,9 @@ public static long maxPhysicalBytes() { * Also known as "anonymous resident set size" (Linux, Mac OS X, etc) or "private working set size" (Windows). */ @Name("JavaCPP_physicalBytes") public static native long physicalBytes(); + /** May return a value larger than {@link #physicalBytes()} but less than {@code maxSize} to save processing time. */ + @Name("JavaCPP_physicalBytes") public static native long physicalBytesInaccurate(long maxSize); + /** Returns the amount of physical memory installed according to the operating system, or 0 if unknown. * It should not be possible for {@link #physicalBytes()} to go over this value. */ @Name("JavaCPP_totalPhysicalBytes") public static native long totalPhysicalBytes(); @@ -687,8 +690,19 @@ protected

P deallocator(Deallocator deallocator) { this.deallocator = r; if (referenceQueue != null) synchronized (DeallocatorThread.class) { int count = 0; - long lastPhysicalBytes = maxPhysicalBytes > 0 ? physicalBytes() : 0; + long lastPhysicalBytes = 0; try { + if (maxPhysicalBytes > 0) { + try { + lastPhysicalBytes = physicalBytesInaccurate(maxPhysicalBytes); + } catch (UnsatisfiedLinkError e) { + // old binaries with physicalBytesInaccurate() missing -> call physicalBytes() for backward compatibility + if (logger.isDebugEnabled()) { + logger.debug(e.getMessage()); + } + lastPhysicalBytes = physicalBytes(); + } + } while (count++ < maxRetries && ((maxBytes > 0 && DeallocatorReference.totalBytes + r.bytes > maxBytes) || (maxPhysicalBytes > 0 && lastPhysicalBytes > maxPhysicalBytes))) { if (logger.isDebugEnabled()) { diff --git a/src/main/java/org/bytedeco/javacpp/tools/ClearMojo.java b/src/main/java/org/bytedeco/javacpp/tools/ClearMojo.java index 06f44851b..5629a40ee 100644 --- a/src/main/java/org/bytedeco/javacpp/tools/ClearMojo.java +++ b/src/main/java/org/bytedeco/javacpp/tools/ClearMojo.java @@ -34,7 +34,7 @@ * * @author Samuel Audet */ -@Mojo(name = "clear", defaultPhase = LifecyclePhase.NONE) +@Mojo(name = "clear", defaultPhase = LifecyclePhase.NONE, requiresProject = false) public class ClearMojo extends AbstractMojo { @Override public void execute() throws MojoExecutionException { try { diff --git a/src/main/java/org/bytedeco/javacpp/tools/Generator.java b/src/main/java/org/bytedeco/javacpp/tools/Generator.java index b46c7b15f..75e547c36 100644 --- a/src/main/java/org/bytedeco/javacpp/tools/Generator.java +++ b/src/main/java/org/bytedeco/javacpp/tools/Generator.java @@ -543,7 +543,7 @@ boolean classes(boolean handleExceptions, boolean defineAdapters, boolean conver out.println("#endif"); out.println("}"); out.println(); - out.println("static inline jlong JavaCPP_physicalBytes() {"); + out.println("static inline jlong JavaCPP_physicalBytes(jlong maxSize = 0) {"); out.println(" jlong size = 0;"); out.println("#ifdef __linux__"); out.println(" static int fd = open(\"/proc/self/statm\", O_RDONLY, 0);"); @@ -567,6 +567,11 @@ boolean classes(boolean handleExceptions, boolean defineAdapters, boolean conver out.println(" size = (jlong)info.internal;"); out.println(" }"); out.println("#elif defined(_WIN32)"); + out.println(" PROCESS_MEMORY_COUNTERS counters;"); + out.println(" if (GetProcessMemoryInfo(GetCurrentProcess(), &counters, sizeof(counters))) {"); + out.println(" jlong size2 = (jlong)counters.WorkingSetSize;"); + out.println(" if (size2 <= maxSize) return size2;"); + out.println(" }"); out.println(" DWORD length = sizeof(PSAPI_WORKING_SET_INFORMATION);"); out.println(" PSAPI_WORKING_SET_INFORMATION *info = (PSAPI_WORKING_SET_INFORMATION*)malloc(length);"); out.println(" BOOL success = QueryWorkingSet(GetCurrentProcess(), info, length);"); diff --git a/src/test/java/org/bytedeco/javacpp/PointerTest.java b/src/test/java/org/bytedeco/javacpp/PointerTest.java index d4ee0ff51..90fd067a2 100644 --- a/src/test/java/org/bytedeco/javacpp/PointerTest.java +++ b/src/test/java/org/bytedeco/javacpp/PointerTest.java @@ -1172,6 +1172,6 @@ static class TestFunction extends FunctionPointer { long bytesAfter = Pointer.physicalBytes(); System.out.println(bytesBefore + " " + bytesAfter); - assertTrue(Math.abs(bytesAfter - bytesBefore) < 10_000_000 + buffer.get(0)); + assertTrue(Math.abs(bytesAfter - bytesBefore) < 100_000_000 + buffer.get(0)); } }