Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: b30ed1c8d06e
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 877bcf42c0a8
Choose a head ref
  • 2 commits
  • 3 files changed
  • 1 contributor

Commits on Apr 19, 2018

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    743642a View commit details
  2. Add JRuby::Util.internal_libraries for bootsnap.

    In Shopify/bootsnap#162, I reported that
    bootsnap's load path caching breaks JRuby's internal extensions,
    since they do not live on the filesystem anywhere. They have logic
    for CRuby to skip their search logic for known CRuby-internal
    extensions, but there are many more for JRuby and they do not
    follow the same naming pattern as in CRuby. This patch adds a
    JRuby utility method for getting an array of all such internal
    libraries, so they can be skipped by bootsnap.
    headius committed Apr 19, 2018
    Copy the full SHA
    877bcf4 View commit details
21 changes: 21 additions & 0 deletions core/src/main/java/org/jruby/ext/jruby/JRubyUtilLibrary.java
Original file line number Diff line number Diff line change
@@ -110,6 +110,11 @@ public static IRubyObject unseeded_hash(ThreadContext context, IRubyObject recv)
}
}

/**
* Provide stats on how many method and constant invalidations have occurred globally.
*
* This was added for Pry in https://github.com/jruby/jruby/issues/4384
*/
@JRubyMethod(name = "cache_stats", module = true)
public static IRubyObject cache_stats(ThreadContext context, IRubyObject self) {
Ruby runtime = context.runtime;
@@ -120,4 +125,20 @@ public static IRubyObject cache_stats(ThreadContext context, IRubyObject self) {

return stat;
}

/**
* Return a list of files and extensions that JRuby treats as internal (or "built-in"), skipping load path and
* filesystem search.
*
* This was added for Bootsnap in https://github.com/Shopify/bootsnap/issues/162
*/
@JRubyMethod(module = true)
public static RubyArray internal_libraries(ThreadContext context, IRubyObject self) {
Ruby runtime = context.runtime;
List<String> builtinLibraries = runtime.getLoadService().getBuiltinLibraries();

IRubyObject[] names = builtinLibraries.stream().map(name -> runtime.newString(name)).toArray(i->new IRubyObject[i]);

return runtime.newArrayNoCopy(names);
}
}
8 changes: 8 additions & 0 deletions core/src/main/java/org/jruby/runtime/load/LoadService.java
Original file line number Diff line number Diff line change
@@ -51,6 +51,7 @@
import java.util.jar.JarFile;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.zip.ZipException;

import org.jruby.Ruby;
@@ -628,6 +629,13 @@ public void removeBuiltinLibrary(String name) {
builtinLibraries.remove(name);
}

/**
* Get a list of all libraries JRuby considers "built-in".
*/
public List<String> getBuiltinLibraries() {
return builtinLibraries.keySet().stream().collect(Collectors.toList());
}

public void removeInternalLoadedFeature(String name) {
loadedFeatures.deleteString(runtime.getCurrentContext(), name);
}
9 changes: 9 additions & 0 deletions test/jruby/test_jruby_core_ext.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'test/unit'
require 'jruby/util'

class TestJRubyCoreExt < Test::Unit::TestCase

@@ -76,6 +77,14 @@ def test_with_current_runtime_as_global
assert_equal other_runtime, org.jruby.Ruby.global_runtime
end

def test_internal_libraries
internal_libraries = JRuby::Util.internal_libraries

assert_equal Array, internal_libraries.class
assert_true internal_libraries.size > 0
assert_include internal_libraries, "cgi/escape.jar"
end

private

def assert_same_contents(expect, actual)