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: 9fd9078e6d30
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 7e826db4b5a3
Choose a head ref

Commits on Jul 10, 2015

  1. Copy the full SHA
    07987e5 View commit details
  2. Copy the full SHA
    0aad2b4 View commit details

Commits on Jul 16, 2015

  1. Copy the full SHA
    1c3cdaa View commit details
  2. Improvements to MapJavaProxy for rehash and shift. #3142

    * Make the default rehash impl no-op. If the map supports rehash,
      the correct Java method will be bound instead.
    * Make the default shift have a better error explaining that Java
      Map does not generally preserve insertion order.
    headius committed Jul 16, 2015
    Copy the full SHA
    01bc92c View commit details
  3. Mark default java.util.Map rehash and shift as not implemented.

    Allows using respond_to? to check if they do anything. #3142
    headius committed Jul 16, 2015
    Copy the full SHA
    8e87c09 View commit details
  4. Copy the full SHA
    a5dc5b2 View commit details

Commits on Jul 17, 2015

  1. Merge pull request #3127 from jkutner/jruby-1_7

    Added uri to path when using file protocol to chdir
    mkristian committed Jul 17, 2015
    Copy the full SHA
    26d0b20 View commit details

Commits on Jul 21, 2015

  1. [#2867] modified Date#>> to take calendar reforms under consideration

    - added tests for next month with calendar reform
    - uses solution provided in #1769 comments
    - also fixes issues #1769
    Ranjeet Singh authored and eregon committed Jul 21, 2015
    Copy the full SHA
    3b83d09 View commit details
  2. Add specs for Date#{<<,prev_year,next_year} around calendar reforms.

    * See #2867.
    Ranjeet Singh authored and eregon committed Jul 21, 2015
    Copy the full SHA
    d2a4cb2 View commit details
  3. Add specs for Date#{<<,prev_year,next_year} around calendar reforms.

    * See #2867.
    Ranjeet Singh authored and eregon committed Jul 21, 2015
    Copy the full SHA
    ec80a32 View commit details
  4. [#2867] modified Date#>> to take calendar reforms under consideration

    - added tests for next month with calendar reform
    - uses solution provided in #1769 comments
    - also fixes issues #1769
    Ranjeet Singh authored and eregon committed Jul 21, 2015
    Copy the full SHA
    40e9140 View commit details
  5. Copy the full SHA
    a8ee690 View commit details
  6. Use iteration count for final size in map. Fixes #3155.

    When the block passed to map makes modifications to the array
    under iteration, we may prematurely finish the map loop due to the
    size changing. However our logic for creating the mapped array
    assumed the new array's size would always be the same as the
    original array's size, leading to an array with null elements.
    This fix uses the iteration count as the final size, so we at
    least know how many elements in the new array were populated.
    
    Note that this behavior is officially undefined; modifying the
    array while performing internal iteration can cause peculiar
    effects across runtimes and potentially across the different
    versions of the same runtime. We add a regression spec here to
    at least make sure we don't produce an invalid array.
    headius committed Jul 21, 2015
    Copy the full SHA
    59fe0bf View commit details
  7. Copy the full SHA
    ff53331 View commit details
  8. Copy the full SHA
    b0dcd91 View commit details
  9. tune proc-to-iface callable matching to do less work

    ... and handle proc's with arity >
    
    than the functional-interface methods parameter count
    kares committed Jul 21, 2015
    Copy the full SHA
    581a815 View commit details
  10. re-arrange proc arity matching

    avoids incorrect ambiguous warning e.g. in case of :
    `java.io.File.new('.').listFiles { |pathname| ... }`
    kares committed Jul 21, 2015
    Copy the full SHA
    7d24ec4 View commit details
  11. Copy the full SHA
    e7fcfd6 View commit details
  12. [ji] fix missing local assing + do not match duckables when primitiva…

    …ble/assignable found
    
    this avoids an incorrect ambiguous warning when matching proc-to-iface methods e.g. : 
    `executor_spec.rb:22 warning: ambiguous Java methods found, using submit(java.util.concurrent.Callable)`
    
    ... also exploded the 3 level nested for loop to be only 2 levels
    kares committed Jul 21, 2015
    Copy the full SHA
    9599674 View commit details
  13. forgot to initialize the mostSpecificArity for the first list element…

    … (thus not matching)
    kares committed Jul 21, 2015
    Copy the full SHA
    120e0ab View commit details
  14. a unit test since we can not influence getMethods order (closer to fa…

    …ilure at travis-ci)
    kares committed Jul 21, 2015
    Copy the full SHA
    623a6f1 View commit details
  15. [ji] travis showcased negative proc-to-iface arity (still) dependent …

    …on getMethods order
    kares committed Jul 21, 2015
    Copy the full SHA
    3d7ac8f View commit details
  16. travis showcased we did not handle all negative proc-to-iface arity c…

    …ases correctly
    
    ... they were still dependent on getMethods order (travis-ci failures in **spec:ji**)
    kares committed Jul 21, 2015
    Copy the full SHA
    e20d6c7 View commit details
  17. Copy the full SHA
    a1a99aa View commit details

Commits on Jul 22, 2015

  1. Fix RubyRange#initialize_copy mistakenly erroring on #dup'ing a range.

    …Closes #3163
    
    MRI checks if the EXCL flag is Qnil to see if the range has been initalized. This doesn't work
    in Java because we use a boolean which can't have a nil value. Instead, introduce a new isInited
    flag which is used to track the initialization state of the Range, which corrently permits #dup
    while not permitting reinitialization of a Range.
    cheald committed Jul 22, 2015
    Copy the full SHA
    ede3cf6 View commit details

Commits on Jul 23, 2015

  1. Merge pull request #3157 from eregon/date_next_year_difference

    Date next year difference
    eregon committed Jul 23, 2015
    Copy the full SHA
    45154e9 View commit details
  2. [Truffle] No more global lock!

    eregon committed Jul 23, 2015
    2
    Copy the full SHA
    eaa15cf View commit details
  3. [Truffle] Fix Rubinius.synchronize.

    * Still a shim as we might have troubles supporting lock/unlock
      and might change the implementation.
    eregon committed Jul 23, 2015
    Copy the full SHA
    27e8286 View commit details
  4. Copy the full SHA
    d619a6c View commit details
  5. Merge pull request #3148 from jruby/truffle_rm_gil

    [Truffle] No more global lock!
    eregon committed Jul 23, 2015
    Copy the full SHA
    155ee96 View commit details
  6. Back to bleeding edge!

    eregon committed Jul 23, 2015
    5
    Copy the full SHA
    89c1348 View commit details
  7. Copy the full SHA
    0590488 View commit details
  8. [Truffle] No need to pass the Ruby thread in SafepointManager.

    * The currentThread ThreadLocal will tell us anyway.
    eregon committed Jul 23, 2015
    Copy the full SHA
    be414cf View commit details
  9. Copy the full SHA
    a766ce8 View commit details
  10. Copy the full SHA
    eb332f2 View commit details
  11. [Truffle] Full Kernel#inspect.

    * Just use #to_s if you need to print an object before bootstrap/kernel.rb is loaded.
    eregon committed Jul 23, 2015
    Copy the full SHA
    c83de9b View commit details
  12. Copy the full SHA
    5afcafa View commit details
  13. Merge pull request #3165 from cheald/fix_range

    Fix RubyRange#initialize_copy mistakenly erroring on #dup'ing a range
    enebo committed Jul 23, 2015
    Copy the full SHA
    a3cd23d View commit details
  14. [Truffle] 2**63-1 ms is more than enough.

    * It is about 292 471 208 years.
    eregon committed Jul 23, 2015
    Copy the full SHA
    c7acd56 View commit details
  15. Make sure the thread is actually waiting in ConditionVariable specs

    * The thread can also have the status "sleep" very shortly when calling Mutex#lock.
    eregon committed Jul 23, 2015
    Copy the full SHA
    acb9129 View commit details
  16. Make sure threads are actually waiting in other ConditionVariable specs

    * The thread can also have the status "sleep" very shortly when calling Mutex#lock.
    eregon committed Jul 23, 2015
    Copy the full SHA
    8c884c0 View commit details
  17. Copy the full SHA
    31d5310 View commit details
  18. Copy the full SHA
    7d8c779 View commit details
  19. [Truffle] remove broken case from pack-pack Hash merge

    It was giving bad rusults for cases like:
    {a:1, b:2}.merge(b:3) # => {:a=>1, :b=>2}
    pitr-ch committed Jul 23, 2015
    Copy the full SHA
    90aede3 View commit details
  20. [Truffle] Add printableBacktrace to DebugOperations

    * to be able to get the backtrace in debuger
    pitr-ch committed Jul 23, 2015
    Copy the full SHA
    01c1e58 View commit details
  21. Copy the full SHA
    9f1e745 View commit details
  22. Copy the full SHA
    41a8a10 View commit details
  23. Copy the full SHA
    afc6ef2 View commit details
  24. Copy the full SHA
    f7107f7 View commit details
  25. Copy the full SHA
    9db38b9 View commit details
Showing 321 changed files with 3,587 additions and 2,402 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -77,7 +77,6 @@ matrix:
fast_finish: true
allow_failures:
- env: COMMAND=test/truffle/run.sh
- env: COMMAND=tool/truffle-findbugs.sh


branches:
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
9.0.0.0
9.0.1.0-SNAPSHOT
2 changes: 1 addition & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ DO NOT MODIFIY - GENERATED CODE
<parent>
<groupId>org.jruby</groupId>
<artifactId>jruby-parent</artifactId>
<version>9.0.0.0</version>
<version>9.0.1.0-SNAPSHOT</version>
</parent>
<artifactId>jruby-core</artifactId>
<name>JRuby Core</name>
32 changes: 19 additions & 13 deletions core/src/main/java/org/jruby/Ruby.java
Original file line number Diff line number Diff line change
@@ -93,7 +93,6 @@
import org.jruby.internal.runtime.GlobalVariables;
import org.jruby.internal.runtime.ThreadService;
import org.jruby.internal.runtime.ValueAccessor;
import org.jruby.internal.runtime.methods.CallConfiguration;
import org.jruby.internal.runtime.methods.DynamicMethod;
import org.jruby.internal.runtime.methods.JavaMethod;
import org.jruby.ir.Compiler;
@@ -177,6 +176,7 @@
import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.EnumMap;
import java.util.EnumSet;
import java.util.HashMap;
@@ -1381,7 +1381,7 @@ private void initRoot() {

// In 1.9 and later, Kernel.gsub is defined only when '-p' or '-n' is given on the command line
if (config.getKernelGsubDefined()) {
kernel.addMethod("gsub", new JavaMethod(kernel, Visibility.PRIVATE, CallConfiguration.FrameFullScopeNone) {
kernel.addMethod("gsub", new JavaMethod(kernel, Visibility.PRIVATE) {

@Override
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject[] args, Block block) {
@@ -2930,8 +2930,6 @@ public void compileAndLoadFile(String filename, InputStream in, boolean wrap) {
InputStream readStream = in;

Script script = null;
ScriptAndCode scriptAndCode = null;
String className = null;

try {
// read full contents of file, hash it, and try to load that class first
@@ -2943,12 +2941,12 @@ public void compileAndLoadFile(String filename, InputStream in, boolean wrap) {
}
buffer = baos.toByteArray();
String hash = JITCompiler.getHashForBytes(buffer);
className = JITCompiler.RUBY_JIT_PREFIX + ".FILE_" + hash;
final String className = JITCompiler.RUBY_JIT_PREFIX + ".FILE_" + hash;

// FIXME: duplicated from ClassCache
Class contents;
try {
contents = jrubyClassLoader.loadClass(className);
contents = getJRubyClassLoader().loadClass(className);
if (RubyInstanceConfig.JIT_LOADING_DEBUG) {
LOG.info("found jitted code for " + filename + " at class: " + className);
}
@@ -2974,7 +2972,9 @@ public void compileAndLoadFile(String filename, InputStream in, boolean wrap) {
// script was not found in cache above, so proceed to compile
RootNode scriptNode = (RootNode) parseFile(readStream, filename, null);
if (script == null) {
scriptAndCode = tryCompile(scriptNode, new ClassDefiningJRubyClassLoader(jrubyClassLoader));
ScriptAndCode scriptAndCode = tryCompile(scriptNode,
new ClassDefiningJRubyClassLoader(getJRubyClassLoader())
);
if (scriptAndCode != null) script = scriptAndCode.script();
}

@@ -3307,7 +3307,7 @@ public void tearDown(boolean systemExit) {

getSelectorPool().cleanup();

tearDownClassLoader();
// NOTE: its intentional that we're not doing releaseClassLoader();

if (config.isProfilingEntireRun()) {
// not using logging because it's formatted
@@ -3332,10 +3332,16 @@ public void tearDown(boolean systemExit) {
}
}

private void tearDownClassLoader() {
if (getJRubyClassLoader() != null) {
getJRubyClassLoader().tearDown(isDebug());
}
/**
* By default {@link #tearDown(boolean)} does not release the class-loader's
* resources as threads might be still running accessing the classes/packages
* even after the runtime has been torn down.
*
* This method exists to handle such cases, e.g. with embedded uses we always
* release the runtime loader but not otherwise - you should do that manually.
*/
public void releaseClassLoader() {
if ( jrubyClassLoader != null ) getJRubyClassLoader().close();
}

/**
@@ -5105,7 +5111,7 @@ public void addToObjectSpace(boolean useObjectSpace, IRubyObject object) {
*
* Access must be synchronized.
*/
private WeakHashMap<RubyString, WeakReference<RubyString>> dedupMap = new WeakHashMap<RubyString, WeakReference<RubyString>>();
private Map<RubyString, WeakReference<RubyString>> dedupMap = Collections.synchronizedMap(new WeakHashMap<RubyString, WeakReference<RubyString>>());

private static final AtomicInteger RUNTIME_NUMBER = new AtomicInteger(0);
private final int runtimeNumber = RUNTIME_NUMBER.getAndIncrement();
4 changes: 3 additions & 1 deletion core/src/main/java/org/jruby/RubyDir.java
Original file line number Diff line number Diff line change
@@ -84,6 +84,8 @@ public class RubyDir extends RubyObject {

private final static Encoding UTF8 = UTF8Encoding.INSTANCE;

private static Pattern PROTOCOL_PATTERN = Pattern.compile("^(uri|jar|file|classpath):([^:]*:)?//?.*");

public RubyDir(Ruby runtime, RubyClass type) {
super(runtime, type);
}
@@ -308,7 +310,7 @@ public static IRubyObject chdir(ThreadContext context, IRubyObject recv, IRubyOb
checkDirIsTwoSlashesOnWindows(runtime, adjustedPath);
String realPath = null;
String oldCwd = runtime.getCurrentDirectory();
if (adjustedPath.startsWith("uri:")){
if (PROTOCOL_PATTERN.matcher(adjustedPath).matches()) {
realPath = adjustedPath;
}
else {
11 changes: 7 additions & 4 deletions core/src/main/java/org/jruby/RubyFile.java
Original file line number Diff line number Diff line change
@@ -1540,16 +1540,18 @@ private static IRubyObject expandPathInternal(ThreadContext context, IRubyObject
// argument is relative.
if (args.length == 2 && !args[1].isNil()) {
// TODO maybe combine this with get_path method
if ((args[1] instanceof RubyString) && args[1].asJavaString().startsWith("uri:")) {
cwd = args[1].asJavaString();
String path = args[1].toString();
if (path.startsWith("uri:")) {
cwd = path;
} else {
cwd = StringSupport.checkEmbeddedNulls(runtime, get_path(context, args[1])).getUnicodeValue();

// Handle ~user paths.
if (expandUser) {
cwd = expandUserPath(context, cwd, true);
}


// TODO try to treat all uri-like paths alike
String[] cwdURIParts = splitURI(cwd);
if (uriParts == null && cwdURIParts != null) {
uriParts = cwdURIParts;
@@ -1566,7 +1568,8 @@ private static IRubyObject expandPathInternal(ThreadContext context, IRubyObject
// If the path isn't absolute, then prepend the current working
// directory to the path.
if (!startsWithSlashNotOnWindows && !startsWithDriveLetterOnWindows(cwd)) {
cwd = new File(runtime.getCurrentDirectory(), cwd).getAbsolutePath();
if ("".equals(cwd)) cwd = ".";
cwd = JRubyFile.create(runtime.getCurrentDirectory(), cwd).getAbsolutePath();
}
}
} else {
7 changes: 1 addition & 6 deletions core/src/main/java/org/jruby/RubyInstanceConfig.java
Original file line number Diff line number Diff line change
@@ -53,9 +53,7 @@
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
@@ -70,8 +68,6 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.regex.Pattern;

/**
@@ -1756,8 +1752,6 @@ public boolean shouldPrecompileAll() {

public static final boolean JIT_CACHE_ENABLED = Options.JIT_CACHE.load();

public static final String JIT_CODE_CACHE = Options.JIT_CODECACHE.load();

public static final boolean REFLECTED_HANDLES = Options.REFLECTED_HANDLES.load();

public static final boolean NO_UNWRAP_PROCESS_STREAMS = Options.PROCESS_NOUNWRAP.load();
@@ -1947,4 +1941,5 @@ public boolean isCextEnabled() {
return false;
}

@Deprecated public static final String JIT_CODE_CACHE = "";
}
3 changes: 1 addition & 2 deletions core/src/main/java/org/jruby/RubyKernel.java
Original file line number Diff line number Diff line change
@@ -48,7 +48,6 @@
import org.jruby.common.IRubyWarnings.ID;
import org.jruby.exceptions.MainExitException;
import org.jruby.exceptions.RaiseException;
import org.jruby.internal.runtime.methods.CallConfiguration;
import org.jruby.internal.runtime.methods.DynamicMethod;
import org.jruby.internal.runtime.methods.JavaMethod.JavaMethodNBlock;
import org.jruby.ir.interpreter.Interpreter;
@@ -104,7 +103,7 @@ public static class MethodMissingMethod extends JavaMethodNBlock {
private final CallType callType;

public MethodMissingMethod(RubyModule implementationClass, Visibility visibility, CallType callType) {
super(implementationClass, Visibility.PRIVATE, CallConfiguration.FrameFullScopeNone);
super(implementationClass, Visibility.PRIVATE);

this.callType = callType;
this.visibility = visibility;
50 changes: 25 additions & 25 deletions core/src/main/java/org/jruby/RubyModule.java
Original file line number Diff line number Diff line change
@@ -1485,29 +1485,29 @@ public synchronized void defineAliases(List<String> aliases, String oldName) {
private DynamicMethod searchForAliasMethod(Ruby runtime, String name) {
DynamicMethod method = deepMethodSearch(name, runtime);

if (method instanceof JavaMethod) {
// JRUBY-2435: Aliasing eval and other "special" methods should display a warning
// We warn because we treat certain method names as "special" for purposes of
// optimization. Hopefully this will be enough to convince people not to alias
// them.
CallConfiguration callerReq = ((JavaMethod)method).getCallerRequirement();

if (callerReq.framing() != Framing.None ||
callerReq.scoping() != Scoping.None) {String baseName = getBaseName();
char refChar = '#';
String simpleName = getSimpleName();

if (baseName == null && this instanceof MetaClass) {
IRubyObject attached = ((MetaClass)this).getAttached();
if (attached instanceof RubyModule) {
simpleName = ((RubyModule)attached).getSimpleName();
refChar = '.';
}
}

runtime.getWarnings().warn(simpleName + refChar + name + " accesses caller's state and should not be aliased");
}
}
// if (method instanceof JavaMethod) {
// // JRUBY-2435: Aliasing eval and other "special" methods should display a warning
// // We warn because we treat certain method names as "special" for purposes of
// // optimization. Hopefully this will be enough to convince people not to alias
// // them.
// CallConfiguration callerReq = ((JavaMethod)method).getCallerRequirement();
//
// if (callerReq.framing() != Framing.None ||
// callerReq.scoping() != Scoping.None) {String baseName = getBaseName();
// char refChar = '#';
// String simpleName = getSimpleName();
//
// if (baseName == null && this instanceof MetaClass) {
// IRubyObject attached = ((MetaClass)this).getAttached();
// if (attached instanceof RubyModule) {
// simpleName = ((RubyModule)attached).getSimpleName();
// refChar = '.';
// }
// }
//
// runtime.getWarnings().warn(simpleName + refChar + name + " accesses caller's state and should not be aliased");
// }
// }

return method;
}
@@ -1608,12 +1608,12 @@ private void addAccessor(ThreadContext context, String internedName, Visibility

final String variableName = ("@" + internedName).intern();
if (readable) {
addMethod(internedName, new AttrReaderMethod(methodLocation, visibility, CallConfiguration.FrameNoneScopeNone, variableName));
addMethod(internedName, new AttrReaderMethod(methodLocation, visibility, variableName));
callMethod(context, "method_added", runtime.fastNewSymbol(internedName));
}
if (writeable) {
internedName = (internedName + "=").intern();
addMethod(internedName, new AttrWriterMethod(methodLocation, visibility, CallConfiguration.FrameNoneScopeNone, variableName));
addMethod(internedName, new AttrWriterMethod(methodLocation, visibility, variableName));
callMethod(context, "method_added", runtime.fastNewSymbol(internedName));
}
}
8 changes: 5 additions & 3 deletions core/src/main/java/org/jruby/RubyRange.java
Original file line number Diff line number Diff line change
@@ -81,6 +81,7 @@ public class RubyRange extends RubyObject {
private IRubyObject begin;
private IRubyObject end;
private boolean isExclusive;
private boolean isInited = false;

public static RubyClass createRangeClass(Ruby runtime) {
RubyClass result = runtime.defineClass("Range", runtime.getObject(), RANGE_ALLOCATOR);
@@ -230,11 +231,12 @@ private void init(ThreadContext context, IRubyObject begin, IRubyObject end, boo
this.begin = begin;
this.end = end;
this.isExclusive = isExclusive;
this.isInited = true;
}

@JRubyMethod(required = 2, optional = 1, visibility = PRIVATE)
public IRubyObject initialize(ThreadContext context, IRubyObject[] args, Block unusedBlock) {
if (!begin.isNil() || !end.isNil()) {
if (this.isInited) {
throw getRuntime().newNameError("`initialize' called twice", "initialize");
}
init(context, args[0], args[1], args.length > 2 && args[2].isTrue());
@@ -243,7 +245,7 @@ public IRubyObject initialize(ThreadContext context, IRubyObject[] args, Block u

@JRubyMethod(required = 1, visibility = PRIVATE)
public IRubyObject initialize_copy(ThreadContext context, IRubyObject original) {
if (!begin.isNil() || !end.isNil()) {
if (this.isInited) {
throw context.runtime.newNameError("`initialize' called twice", "initialize");
}

@@ -657,7 +659,7 @@ public IRubyObject max(ThreadContext context, Block block) {
if (!(begin instanceof RubyInteger)) {
throw context.runtime.newTypeError("cannot exclude end value with non Integer begin value");
}
rangeEnd = RubyFixnum.newFixnum(context.runtime, ((RubyFixnum) end).getLongValue() - 1);
rangeEnd = RubyFixnum.newFixnum(context.runtime, ((RubyInteger) end).getLongValue() - 1);
} else {
rangeEnd = end;
}
5 changes: 2 additions & 3 deletions core/src/main/java/org/jruby/RubyStruct.java
Original file line number Diff line number Diff line change
@@ -36,7 +36,6 @@
import org.jruby.anno.JRubyMethod;
import org.jruby.common.IRubyWarnings.ID;
import org.jruby.exceptions.RaiseException;
import org.jruby.internal.runtime.methods.CallConfiguration;
import org.jruby.internal.runtime.methods.DynamicMethod;
import org.jruby.runtime.Arity;
import org.jruby.runtime.Block;
@@ -215,7 +214,7 @@ public static RubyClass newInstance(IRubyObject recv, IRubyObject[] args, Block
final String memberName = args[i].asJavaString();
// if we are storing a name as well, index is one too high for values
final int index = (name == null && !nilName) ? i : i - 1;
newStruct.addMethod(memberName, new DynamicMethod(newStruct, Visibility.PUBLIC, CallConfiguration.FrameNoneScopeNone) {
newStruct.addMethod(memberName, new DynamicMethod(newStruct, Visibility.PUBLIC) {
@Override
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject[] args, Block block) {
Arity.checkArgumentCount(context.runtime, name, args, 0, 0);
@@ -232,7 +231,7 @@ public DynamicMethod dup() {
return this;
}
});
newStruct.addMethod(memberName + "=", new DynamicMethod(newStruct, Visibility.PUBLIC, CallConfiguration.FrameNoneScopeNone) {
newStruct.addMethod(memberName + "=", new DynamicMethod(newStruct, Visibility.PUBLIC) {
@Override
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject[] args, Block block) {
Arity.checkArgumentCount(context.runtime, name, args, 1, 1);
27 changes: 10 additions & 17 deletions core/src/main/java/org/jruby/RubyThread.java
Original file line number Diff line number Diff line change
@@ -148,8 +148,8 @@ public class RubyThread extends RubyObject implements ExecutionContext {
private final SleepTask2 sleepTask = new SleepTask2();

private static final boolean DEBUG = false;
private static final int RUBY_MIN_THREAD_PRIORITY = -3;
private static final int RUBY_MAX_THREAD_PRIORITY = 3;
public static final int RUBY_MIN_THREAD_PRIORITY = -3;
public static final int RUBY_MAX_THREAD_PRIORITY = 3;

/** Thread statuses */
public static enum Status {
@@ -1106,26 +1106,19 @@ public IRubyObject priority_set(IRubyObject priority) {
return RubyFixnum.newFixnum(getRuntime(), iPriority);
}

/* helper methods to translate java thread priority (1-10) to
* Ruby thread priority (-3 to 3) using a quadratic polynoimal ant its
* inverse
/* helper methods to translate Java thread priority (1-10) to
* Ruby thread priority (-3 to 3) using a quadratic polynomial ant its
* inverse passing by (Ruby,Java): (-3,1), (0,5) and (3,10)
* i.e., j = r^2/18 + 3*r/2 + 5
* r = 3/2*sqrt(8*j + 41) - 27/2
*/
private int javaPriorityToRubyPriority(int javaPriority) {
double d; // intermediate value
d = 1.5 * Math.sqrt(8.0*javaPriority + 41) - 13.5;
public static int javaPriorityToRubyPriority(int javaPriority) {
double d = 1.5 * Math.sqrt(8.0 * javaPriority + 41) - 13.5;
return Math.round((float) d);
}

private int rubyPriorityToJavaPriority(int rubyPriority) {
double d;
if (rubyPriority < RUBY_MIN_THREAD_PRIORITY) {
rubyPriority = RUBY_MIN_THREAD_PRIORITY;
} else if (rubyPriority > RUBY_MAX_THREAD_PRIORITY) {
rubyPriority = RUBY_MAX_THREAD_PRIORITY;
}
d = Math.pow(rubyPriority, 2.0)/18.0 + 1.5 * rubyPriority + 5;

public static int rubyPriorityToJavaPriority(int rubyPriority) {
double d = (rubyPriority * rubyPriority) / 18.0 + 1.5 * rubyPriority + 5;
return Math.round((float) d);
}

Loading