Bug 247997 - databases/cassandra3: fix build on aarch64 (Java OutOfMemory during build)
Summary: databases/cassandra3: fix build on aarch64 (Java OutOfMemory during build)
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Some People
Assignee: freebsd-ports-bugs (Nobody)
Keywords: easy, patch
Depends on:
Reported: 2020-07-15 13:26 UTC by Ronald Klop
Modified: 2020-07-24 15:48 UTC (History)
2 users (show)

See Also:
language.devel: maintainer-feedback+

increase memory 256 (default) -> 512 MB (svn diff) (789 bytes, patch)
2020-07-15 13:26 UTC, Ronald Klop
no flags Details | Diff
set max mem to 512 MB (svn diff) (817 bytes, patch)
2020-07-17 10:03 UTC, Ronald Klop
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ronald Klop 2020-07-15 13:26:07 UTC
Created attachment 216466 [details]
increase memory 256 (default) -> 512 MB (svn diff)

Aarch64 has OpenJDK8 without hotspot compiler. I'm not sure if that is the reason it goes OutOfMemory in the build step.

See http://thunderx1.nyi.freebsd.org/data/121arm64-quarterly/540450/logs/errors/cassandra3-3.11.6.log

    [javac] Compiling 606 source files to /wrkdirs/usr/ports/databases/cassandra3/work/apache-cassandra-3.11.6-src/build/test/classes
    [javac] The system is out of resources.
    [javac] Consult the following stack trace for details.
    [javac] java.lang.OutOfMemoryError: Java heap space
    [javac] 	at com.sun.tools.javac.code.Scope$ImportScope.makeEntry(Scope.java:530)
    [javac] 	at com.sun.tools.javac.code.Scope.enter(Scope.java:220)
Comment 1 Angelo Polo 2020-07-15 20:05:32 UTC
Looks Ok to me if the default is indeed 256 MB, though I can't find where this would be getting set on my (amd64) machine either in Mk/, /usr/local/bin/ant, nor in the ant manual.
Comment 2 Angelo Polo 2020-07-15 20:29:21 UTC
Maybe it would be better to have ANT_OPTS="$ANT_OPTS -Xmx512M" in case someone already has some settings in ANT_OPTS.
Comment 3 Ronald Klop 2020-07-16 08:27:12 UTC
(In reply to Angelo Polo from comment #1)

Ah, I looked it up. The default of openjdk 8 is like 1/4 of the amount of memory depending on some conditions like client or server VM. My RPI3 has 1GB mem. I don't know how much mem the pkg build system has.
I think properly defining the max. gives more predictable results anyways.

I will look into keeping existing ANT_OPTS values and update the patch.
Comment 4 Ronald Klop 2020-07-17 10:03:00 UTC
Created attachment 216511 [details]
set max mem to 512 MB (svn diff)

Used the ANT_OPTS="$ANT_OPTS ..." construction.

Did some more testing with "java -XX:+PrintFlagsFinal -version | grep MaxHeap".
On my RPI3 with 1 GB RAM Java uses a default mx of 256MB which is too small.
On my amd64 VM with 5 GB RAM Java uses an mx of 1270MB which is plenty.

Both compile perfectly with -Xmx512m.
jstat -gc shows the RPI3 does quite some GC and reaches 512MB quite often. The amd64 never hits the max mem with 512 MB avail.

This is all on openjdk8.
RPI3: OpenJDK 64-Bit Zero VM (build 25.242-b07, interpreted mode)
AMD64: OpenJDK 64-Bit Server VM (build 25.252-b09, mixed mode)

So I think this is ready to be committed.
Comment 5 Mikael Urankar freebsd_committer 2020-07-17 16:33:02 UTC
Is it required with jdk11? (jdk8 is in zero mode, jdk11 is in mixed mode on aarch64)
Comment 6 Ronald Klop 2020-07-20 14:59:08 UTC
(In reply to Mikael Urankar from comment #5)
My quick test with OpenJDK 11 gives build errors.

    [javac] /data/ports-build/usr/ports/databases/cassandra3/work/apache-cassandra-3.11.6-src/src/java/org/apache/cassandra/utils/Throwables.java:80: err
or: unreported exception Exception; must be caught or declared to be thrown                                                                                  [javac]         perform(Stream.of(actions));                                                                                                         


    [javac] /data/ports-build/usr/ports/databases/cassandra3/work/apache-cassandra-3.11.6-src/src/java/org/apache/cassandra/utils/concurrent/Locks.java:46: error: cannot find symbol
    [javac]             unsafe.monitorEnter(object);
    [javac]                   ^
    [javac]   symbol:   method monitorEnter(Object)
    [javac]   location: variable unsafe of type Unsafe
    [javac] /data/ports-build/usr/ports/databases/cassandra3/work/apache-cassandra-3.11.6-src/src/java/org/apache/cassandra/utils/concurrent/Locks.java:52: error: cannot find symbol
    [javac]             unsafe.monitorExit(object);
    [javac]                   ^
    [javac]   symbol:   method monitorExit(Object)
    [javac]   location: variable unsafe of type Unsafe

Unfortunately I don't have the time to dive into the specific code.
Comment 7 Angelo Polo 2020-07-20 17:43:31 UTC
(In reply to Mikael Urankar from comment #5)

databases/cassandra3 isn't compatible with Java 11, so let's not worry about that. 

Too bad we can't very easily specify a minimum max memory (letting Java set a higher max from the default but not allowing it to set a limit below a certain value). But wishful thinking aside, this gets a green light from me.
Comment 8 commit-hook freebsd_committer 2020-07-24 15:48:01 UTC
A commit references this bug:

Author: mikael
Date: Fri Jul 24 15:47:22 UTC 2020
New revision: 543250
URL: https://svnweb.freebsd.org/changeset/ports/543250

  databases/cassandra3: fix build on aarch64 (Java OutOfMemory during build)

  increase memory 256 (default) to 512 MB

  PR:		247997
  Submitted by:	Ronald Klop <ronald-lists@klop.ws>
  Approved by:	Angelo Polo <language.devel@gmail.com> (maintainer)

Comment 9 Mikael Urankar freebsd_committer 2020-07-24 15:48:57 UTC
Committed, Thanks!