From 78931d9f07babe64a20380b83e554b3ef05e857f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ciro=20Santilli=20=E5=85=AD=E5=9B=9B=E4=BA=8B=E4=BB=B6=20?= =?UTF-8?q?=E6=B3=95=E8=BD=AE=E5=8A=9F?= Date: Sun, 14 Feb 2021 00:00:00 +0000 Subject: [PATCH] start java --- README.adoc | 8 +++ java | 1 + .../lkmc/java/LinkedHashMapCheat.java | 59 +++++++++++++++++++ rootfs_overlay/lkmc/java/Makefile | 40 +++++++++++++ 4 files changed, 108 insertions(+) create mode 120000 java create mode 100644 rootfs_overlay/lkmc/java/LinkedHashMapCheat.java create mode 100644 rootfs_overlay/lkmc/java/Makefile diff --git a/README.adoc b/README.adoc index b8e805c..16ebbb5 100644 --- a/README.adoc +++ b/README.adoc @@ -20936,6 +20936,8 @@ Maybe some day someone will use this setup to study the performance of interpret ==== Python +link:rootfs_overlay/lkmc/python[] + Examples: * link:rootfs_overlay/lkmc/python/hello.py[]: hello world @@ -21095,6 +21097,8 @@ pybind11 is amazingly easy to use. But it can also make your builds really slow: ==== Node.js +link:rootfs_overlay/lkmc/nodejs[] + Host installation shown at: https://askubuntu.com/questions/594656/how-to-install-the-latest-versions-of-nodejs-and-npm/971612#971612 Build and install the interpreter in Buildroot with: @@ -21161,6 +21165,8 @@ https://stackoverflow.com/questions/31642477/how-to-publish-a-npm-package-with-d ==== Java +link:rootfs_overlay/lkmc/java[] + No OpenJDK package as of 2018.08: https://stackoverflow.com/questions/28874150/buildroot-with-jamvm-2-0-for-java-8/59290927#59290927 partly because their build system is shit like the rest of the project's setup. Unmerged patch at: http://lists.busybox.net/pipermail/buildroot/2018-February/213282.html @@ -25639,6 +25645,8 @@ TODO create a minimal working aarch64 example analogous to the x86 one at: https A general introduction to paging with x86 examples can be found at: https://cirosantilli.com/x86-paging[]. +Then, this article is amazing: https://www.starlab.io/blog/deep-dive-mmu-virtualization-with-xen-on-arm + ARM paging is documented at <> Chapter D5 and is mostly called VMSAv8 in the ARMv8 manual (Virtual Memory System Architecture). Paging is enabled by the `SCTLR_EL1.M` bit. diff --git a/java b/java new file mode 120000 index 0000000..b1dcf2c --- /dev/null +++ b/java @@ -0,0 +1 @@ +rootfs_overlay/lkmc/java \ No newline at end of file diff --git a/rootfs_overlay/lkmc/java/LinkedHashMapCheat.java b/rootfs_overlay/lkmc/java/LinkedHashMapCheat.java new file mode 100644 index 0000000..1c8938f --- /dev/null +++ b/rootfs_overlay/lkmc/java/LinkedHashMapCheat.java @@ -0,0 +1,59 @@ +/* +# LinkedHashMap + +http://docs.oracle.com/javase/7/docs/api/java/util/LinkedHashMap.html + +Hash map that is iterable in insertion order. + +Application LRU cache: + +- https://github.com/haoel/leetcode/pull/90/files +- http://stackoverflow.com/questions/23772102/lru-cache-in-java-with-generics-and-o1-operations + +This is a sub-case of a binary heap: it is efficient +when every item update makes it either the most recent, or oldest. +For more general binary heap, the new item can go anywhere. + +# removeEldestEntry + +Example: +https://github.com/cirosantilli/haoel-leetcode/commit/ff04930b2dc31f270854e40b560723577c7b49fd + +Only acts on `put`, `get` does not update values for us. +*/ + +import java.util.LinkedList; +import java.util.LinkedHashMap; +import java.util.Iterator; + +public class LinkedHashMapCheat { + public static void main(String[] args) { + LinkedList output; + LinkedList expected; + Iterator it; + + LinkedHashMap m = new LinkedHashMap<>(); + assert m.put(2, -2) == null; + assert m.put(1, -1) == null; + assert m.put(3, -3) == null; + output = new LinkedList<>(); + expected = new LinkedList<>(); + expected.add(2); + expected.add(1); + expected.add(3); + for (int i : m.keySet()) + output.add(i); + assert output.equals(expected); + + it = m.keySet().iterator(); + it.next(); + it.remove(); + output = new LinkedList<>(); + expected = new LinkedList<>(); + expected.add(1); + expected.add(3); + for (int i : m.keySet()) + output.add(i); + assert output.equals(expected); + } +} diff --git a/rootfs_overlay/lkmc/java/Makefile b/rootfs_overlay/lkmc/java/Makefile new file mode 100644 index 0000000..a9a2e29 --- /dev/null +++ b/rootfs_overlay/lkmc/java/Makefile @@ -0,0 +1,40 @@ +IN_EXT ?= .java +OUT_EXT ?= .class +RUN ?= Main +TEST ?= test + +OUTS := $(addsuffix $(OUT_EXT), $(basename $(wildcard *$(IN_EXT)))) + +-include Makefile_params + +.PHONY: all clean run + +all: + javac *.java + +clean: + rm -f *$(OUT_EXT) + +run: all + java -ea $(RUN) + +test: all + @\ + if [ -x $(TEST) ]; then \ + ./$(TEST) '$(OUTS)' ;\ + else\ + fail=false ;\ + for t in $(basename $(OUTS)); do\ + if ! java -ea "$$t"; then \ + fail=true ;\ + break ;\ + fi ;\ + done ;\ + if $$fail; then \ + echo "TEST FAILED: $$t" ;\ + exit 1 ;\ + else \ + echo 'ALL TESTS PASSED' ;\ + exit 0 ;\ + fi ;\ + fi ;\