Whitelisting modules in layers

Mark Raynsford org.openjdk at io7m.com
Fri Dec 1 18:47:49 UTC 2017


Hello.

Is it possible to whitelist the modules available to a given layer?

I'm in the process of implementing a small experimental language that's
designed to be embedded in Java programs in a similar manner to the way
that Lua is embedded in C++ programs. The language has a module system
that I intend to map directly to Jigsaw/JPMS modules. The further
intention is that user programs are placed into their own module layer,
distinct from the host application layer (and that of the compiler).
I'd like to allow for whitelisting the modules available to user code.
Something like:

  Evaluator e =
    Evaluator.builder()
      .setModuleSearchPath(dir1, dir2, dir3)
      .setModuleWhitelist("java.base","com.example.m1","com.example.m2")
      .build();
  e.evaluate("[print \"hello\"]");

The user code passed to e.evaluate() would be compiled in its own module
and would only be able to create "reads" edges to java.base,
com.example.m1, and com.example.m2. Any other modules that happen to be
available to the host application would be invisible to the user's code.

I've played around with the ModuleFinder API a little, and came up
with the following:

  https://github.com/io7m/moduledemo-20171201/blob/master/src/main/java/com/io7m/moduledemo/WhitelistModuleDemo.java

However, the boot_layer.defineModulesWithOneLoader() call raises an
exception: "Class loader must be the boot class loader". Clearly I'm
not meant to use the API in this way!

-- 
Mark Raynsford | http://www.io7m.com



More information about the jigsaw-dev mailing list