-
-
Notifications
You must be signed in to change notification settings - Fork 925
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into psych_3_update
Showing
6,296 changed files
with
108,530 additions
and
58,349 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
9.1.17.0-SNAPSHOT | ||
9.2.0.0-SNAPSHOT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
version = ENV['JRUBY_VERSION'] || | ||
File.read(File.join(basedir, '..', 'VERSION')).strip | ||
|
||
project 'JRuby Benchmark' do | ||
|
||
model_version '4.0.0' | ||
inherit 'org.jruby:jruby-parent', version | ||
id 'org.jruby:jruby-benchmark' | ||
|
||
properties('polyglot.dump.pom' => 'pom.xml', | ||
'polyglot.dump.readonly' => true, | ||
'maven.build.timestamp.format' => 'yyyy-MM-dd', | ||
'maven.test.skip' => 'true', | ||
'build.date' => '${maven.build.timestamp}', | ||
'main.basedir' => '${project.parent.basedir}', | ||
'jruby.basedir' => '${basedir}/..', | ||
'jmh.version' => '1.19' | ||
) | ||
|
||
IO.foreach(File.join(basedir, '..', 'default.build.properties')) do |line| | ||
line.chomp! | ||
# skip comments | ||
next if line =~ /(^\W*#|^$)/ | ||
# build const name | ||
name, value = line.split('=', 2) | ||
properties name => value | ||
end | ||
|
||
jar 'org.jruby:jruby-core:${project.version}' | ||
jar 'org.openjdk.jmh:jmh-core:${jmh.version}' | ||
jar 'org.openjdk.jmh:jmh-generator-annprocess:${jmh.version}' | ||
jar 'org.openjdk.jmh:jmh-core-benchmarks:${jmh.version}' | ||
|
||
plugin(:compiler, | ||
'encoding' => 'utf-8', | ||
'debug' => 'true', | ||
'verbose' => 'true', | ||
'fork' => 'true', | ||
'compilerArgs' => { 'arg' => '-J-Xmx1G' }, | ||
'showWarnings' => 'true', | ||
'showDeprecation' => 'true', | ||
'source' => ['${base.java.version}', '1.7'], | ||
'target' => ['${base.javac.version}', '1.7'], | ||
'useIncrementalCompilation' => 'false') | ||
|
||
plugin :shade do | ||
execute_goals('shade', | ||
:id => 'create jruby-benchmark.jar', | ||
:phase => 'package', | ||
'outputFile' => '${project.build.directory}/jruby-benchmark.jar', | ||
'transformers' => [{ '@implementation' => 'org.apache.maven.plugins.shade.resource.ManifestResourceTransformer', | ||
'mainClass' => 'org.openjdk.jmh.Main' }] | ||
) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
DO NOT MODIFIY - GENERATED CODE | ||
--> | ||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.jruby</groupId> | ||
<artifactId>jruby-parent</artifactId> | ||
<version>9.2.0.0-SNAPSHOT</version> | ||
</parent> | ||
<artifactId>jruby-benchmark</artifactId> | ||
<name>JRuby Benchmark</name> | ||
<properties> | ||
<version.ruby>2.4.1</version.ruby> | ||
<prawn.dir>${test.dir}/prawn</prawn.dir> | ||
<spec.tags.dir>${spec.dir}/tags</spec.tags.dir> | ||
<polyglot.dump.pom>pom.xml</polyglot.dump.pom> | ||
<pkg.dir>${build.dir}/pkg</pkg.dir> | ||
<spec.dir>spec</spec.dir> | ||
<maven.build.timestamp.format>yyyy-MM-dd</maven.build.timestamp.format> | ||
<installer.gems>${jruby.win32ole.gem}</installer.gems> | ||
<prawn.git.repo>git://github.com/sandal/prawn.git</prawn.git.repo> | ||
<version.ruby.minor>1</version.ruby.minor> | ||
<install4j.executable>/Applications/install4j 4/bin/install4jc</install4j.executable> | ||
<jay.bin>jay</jay.bin> | ||
<polyglot.dump.readonly>true</polyglot.dump.readonly> | ||
<dest.lib.dir>${lib.dir}</dest.lib.dir> | ||
<rails.git.repo>git://github.com/rails/rails.git</rails.git.repo> | ||
<build.dir>target</build.dir> | ||
<maven.test.skip>true</maven.test.skip> | ||
<rubyspec.1.8.dir>${rubyspec.dir}/1.8</rubyspec.1.8.dir> | ||
<jruby.launch.memory>1024M</jruby.launch.memory> | ||
<version.ruby.major>2.4</version.ruby.major> | ||
<release.dir>release</release.dir> | ||
<lib.dir>lib</lib.dir> | ||
<rails.dir>${test.dir}/rails</rails.dir> | ||
<parser.dir>core/src/main/java/org/jruby/parser</parser.dir> | ||
<jruby.basedir>${basedir}/..</jruby.basedir> | ||
<rubyspec.dir>${spec.dir}/ruby</rubyspec.dir> | ||
<version.ruby.revision>58053</version.ruby.revision> | ||
<mspec.dir>${spec.dir}/mspec</mspec.dir> | ||
<build.date>${maven.build.timestamp}</build.date> | ||
<main.basedir>${project.parent.basedir}</main.basedir> | ||
<test.results.dir>${build.dir}/test-results</test.results.dir> | ||
<prawn.stable.version>0.4.1</prawn.stable.version> | ||
<mspec.tar.file>${build.dir}/mspec.tgz</mspec.tar.file> | ||
<build.lib.dir>test/target</build.lib.dir> | ||
<jmh.version>1.19</jmh.version> | ||
<rake.args></rake.args> | ||
<test.dir>test</test.dir> | ||
<jflex.bin>jflex</jflex.bin> | ||
<jruby.win32ole.gem>jruby-win32ole</jruby.win32ole.gem> | ||
<mspec.bin>${mspec.dir}/bin/mspec</mspec.bin> | ||
<jruby.gem.home>lib/ruby/gems/shared</jruby.gem.home> | ||
<test.classes.dir>${test.dir}/target/test-classes</test.classes.dir> | ||
</properties> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.jruby</groupId> | ||
<artifactId>jruby-core</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.openjdk.jmh</groupId> | ||
<artifactId>jmh-core</artifactId> | ||
<version>${jmh.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.openjdk.jmh</groupId> | ||
<artifactId>jmh-generator-annprocess</artifactId> | ||
<version>${jmh.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.openjdk.jmh</groupId> | ||
<artifactId>jmh-core-benchmarks</artifactId> | ||
<version>${jmh.version}</version> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<encoding>utf-8</encoding> | ||
<debug>true</debug> | ||
<verbose>true</verbose> | ||
<fork>true</fork> | ||
<compilerArgs> | ||
<arg>-J-Xmx1G</arg> | ||
</compilerArgs> | ||
<showWarnings>true</showWarnings> | ||
<showDeprecation>true</showDeprecation> | ||
<source>${base.java.version}</source> | ||
<source>1.7</source> | ||
<target>${base.javac.version}</target> | ||
<target>1.7</target> | ||
<useIncrementalCompilation>false</useIncrementalCompilation> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-shade-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<id>create jruby-benchmark.jar</id> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>shade</goal> | ||
</goals> | ||
<configuration> | ||
<outputFile>${project.build.directory}/jruby-benchmark.jar</outputFile> | ||
<transformers> | ||
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> | ||
<mainClass>org.openjdk.jmh.Main</mainClass> | ||
</transformer> | ||
</transformers> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
127 changes: 127 additions & 0 deletions
127
bench/src/main/java/org/jruby/benchmark/ArrayCopyBenchmark.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
package org.jruby.benchmark; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
import org.jruby.util.ArraySupport; | ||
import org.openjdk.jmh.annotations.Benchmark; | ||
import org.openjdk.jmh.annotations.BenchmarkMode; | ||
import org.openjdk.jmh.annotations.Fork; | ||
import org.openjdk.jmh.annotations.Measurement; | ||
import org.openjdk.jmh.annotations.Mode; | ||
import org.openjdk.jmh.annotations.OperationsPerInvocation; | ||
import org.openjdk.jmh.annotations.OutputTimeUnit; | ||
import org.openjdk.jmh.annotations.Scope; | ||
import org.openjdk.jmh.annotations.State; | ||
import org.openjdk.jmh.annotations.Warmup; | ||
|
||
@Warmup(iterations = 3, time = 500, timeUnit = TimeUnit.MILLISECONDS) | ||
@Measurement(iterations = 10, time = 500, timeUnit = TimeUnit.MILLISECONDS) | ||
@Fork(1) | ||
@BenchmarkMode(Mode.Throughput) | ||
@OutputTimeUnit(TimeUnit.NANOSECONDS) | ||
@State(Scope.Thread) | ||
public class ArrayCopyBenchmark { | ||
|
||
private static final int INVOCATIONS = 100_000_000; | ||
|
||
private static final String[] arr0 = new String[0]; | ||
private static final Object[] arr1 = {"obj"}; | ||
private static final Object[] arr2 = {1, 2}; | ||
private static final Object[] arr3 = {1, 2, null}; | ||
private static final Object[] arr4 = {1, 2, 3, 4}; | ||
private static final Object[] arr5 = {1, 2, null, 4, null}; | ||
|
||
private static final String[] dst0 = {}; | ||
private static final Object[] dst1 = new Object[1]; | ||
private static final Object[] dst2 = new Object[3]; | ||
private static final Object[] dst3 = {1, 2, null}; | ||
private static final Object[] dst4 = {1, 2, null, 4, null}; | ||
|
||
@Benchmark | ||
@OperationsPerInvocation(INVOCATIONS) | ||
public void benchSystemCopy0() { | ||
for (int i = 0; i < INVOCATIONS; i++) { | ||
System.arraycopy(arr0, 0, dst0, 0, arr0.length); | ||
} | ||
} | ||
|
||
@Benchmark | ||
@OperationsPerInvocation(INVOCATIONS) | ||
public void benchSystemCopy1() { | ||
for (int i = 0; i < INVOCATIONS; i++) { | ||
System.arraycopy(arr1, 0, dst1, 0, arr1.length); | ||
} | ||
} | ||
|
||
@Benchmark | ||
@OperationsPerInvocation(INVOCATIONS) | ||
public void benchSystemCopy2() { | ||
for (int i = 0; i < INVOCATIONS; i++) { | ||
System.arraycopy(arr2, 0, dst2, 0, arr2.length); | ||
} | ||
} | ||
|
||
@Benchmark | ||
@OperationsPerInvocation(INVOCATIONS) | ||
public void benchSystemCopy3() { | ||
for (int i = 0; i < INVOCATIONS; i++) { | ||
System.arraycopy(arr3, 0, dst3, 0, arr3.length); | ||
} | ||
} | ||
|
||
@Benchmark | ||
@OperationsPerInvocation(INVOCATIONS) | ||
public void benchSystemCopy4() { | ||
for (int i = 0; i < INVOCATIONS; i++) { | ||
System.arraycopy(arr4, 0, dst4, 0, arr4.length); | ||
} | ||
} | ||
|
||
@Benchmark | ||
@OperationsPerInvocation(INVOCATIONS) | ||
public void benchSystemCopy5() { | ||
for (int i = 0; i < INVOCATIONS; i++) { | ||
System.arraycopy(arr5, 0, new Object[6], 1, arr5.length); | ||
} | ||
} | ||
|
||
@Benchmark | ||
@OperationsPerInvocation(INVOCATIONS) | ||
public void benchUtilsCopy0() { | ||
for (int i = 0; i < INVOCATIONS; i++) { | ||
ArraySupport.copy(arr0, dst0, 0, arr0.length); | ||
} | ||
} | ||
|
||
@Benchmark | ||
@OperationsPerInvocation(INVOCATIONS) | ||
public void benchUtilsCopy1() { | ||
for (int i = 0; i < INVOCATIONS; i++) { | ||
ArraySupport.copy(arr1, dst1, 0, arr1.length); | ||
} | ||
} | ||
|
||
@Benchmark | ||
@OperationsPerInvocation(INVOCATIONS) | ||
public void benchUtilsCopy2() { | ||
for (int i = 0; i < INVOCATIONS; i++) { | ||
ArraySupport.copy(arr2, dst2, 0, arr2.length); | ||
} | ||
} | ||
|
||
@Benchmark | ||
@OperationsPerInvocation(INVOCATIONS) | ||
public void benchUtilsCopy3() { | ||
for (int i = 0; i < INVOCATIONS; i++) { | ||
ArraySupport.copy(arr3, dst3, 0, arr3.length); | ||
} | ||
} | ||
|
||
@Benchmark | ||
@OperationsPerInvocation(INVOCATIONS) | ||
public void benchUtilsCopy4() { | ||
for (int i = 0; i < INVOCATIONS; i++) { | ||
ArraySupport.copy(arr4, dst4, 0, arr4.length); | ||
} | ||
} | ||
|
||
} |
139 changes: 139 additions & 0 deletions
139
bench/src/main/java/org/jruby/benchmark/EventHookBenchmark.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
package org.jruby.benchmark; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
import org.jruby.Ruby; | ||
import org.jruby.RubyInstanceConfig; | ||
import org.jruby.runtime.Binding; | ||
import org.jruby.runtime.EventHook; | ||
import org.jruby.runtime.RubyEvent; | ||
import org.jruby.runtime.ThreadContext; | ||
import org.jruby.runtime.builtin.IRubyObject; | ||
import org.openjdk.jmh.annotations.Benchmark; | ||
import org.openjdk.jmh.annotations.BenchmarkMode; | ||
import org.openjdk.jmh.annotations.Fork; | ||
import org.openjdk.jmh.annotations.Measurement; | ||
import org.openjdk.jmh.annotations.Mode; | ||
import org.openjdk.jmh.annotations.OperationsPerInvocation; | ||
import org.openjdk.jmh.annotations.OutputTimeUnit; | ||
import org.openjdk.jmh.annotations.Scope; | ||
import org.openjdk.jmh.annotations.State; | ||
import org.openjdk.jmh.annotations.Warmup; | ||
|
||
@Warmup(iterations = 3, time = 3) | ||
@Measurement(iterations = 10, time = 3) | ||
@Fork(1) | ||
@BenchmarkMode(Mode.Throughput) | ||
@OutputTimeUnit(TimeUnit.SECONDS) | ||
@State(Scope.Thread) | ||
public class EventHookBenchmark { | ||
|
||
private static final int INVOCATIONS = 10; | ||
|
||
private static final String BOOT_SCRIPT = | ||
"def fib(a) \n if a.send :<, \n 2 \n a \n else \n fib(a.send :-, 1).send :+, \n fib(a.send :-, 2) \n end \n end"; | ||
|
||
private static final String RUN_SCRIPT = "fib(30)"; | ||
|
||
private static final Ruby RUNTIME = initRuntime(); | ||
private static final Ruby INTERP_RUNTIME = initInterpRuntime(); | ||
private static final Ruby TRACED_RUNTIME = initTracedRuntime(); | ||
private static final Ruby HOOKED_RUNTIME_ONE = initHookedRuntime( | ||
new EventHook() { | ||
@Override | ||
public void eventHandler(final ThreadContext context, final String eventName, | ||
final String file, final int line, final String name, final IRubyObject type) { | ||
// do nothing | ||
} | ||
|
||
@Override | ||
public boolean isInterestedInEvent(final RubyEvent event) { | ||
// want everything | ||
return true; | ||
} | ||
}); | ||
private static final Ruby HOOKED_RUNTIME_TWO = initHookedRuntime( | ||
new EventHook() { | ||
@Override | ||
public void eventHandler(final ThreadContext context, final String eventName, | ||
final String file, final int line, final String name, final IRubyObject type) { | ||
// get binding | ||
final Binding binding = context.currentBinding(); | ||
} | ||
|
||
@Override | ||
public boolean isInterestedInEvent(final RubyEvent event) { | ||
// want everything | ||
return true; | ||
} | ||
} | ||
); | ||
|
||
@Benchmark | ||
@OperationsPerInvocation(INVOCATIONS) | ||
public void benchControl() { | ||
for (int i = 0; i < INVOCATIONS; i++) { | ||
RUNTIME.evalScriptlet(RUN_SCRIPT); | ||
} | ||
} | ||
|
||
@Benchmark | ||
@OperationsPerInvocation(INVOCATIONS) | ||
public void benchInterp() { | ||
for (int i = 0; i < INVOCATIONS; i++) { | ||
INTERP_RUNTIME.evalScriptlet(RUN_SCRIPT); | ||
} | ||
} | ||
|
||
@Benchmark | ||
@OperationsPerInvocation(INVOCATIONS) | ||
public void benchTraced() { | ||
for (int i = 0; i < INVOCATIONS; i++) { | ||
TRACED_RUNTIME.evalScriptlet(RUN_SCRIPT); | ||
} | ||
} | ||
|
||
@Benchmark | ||
@OperationsPerInvocation(INVOCATIONS) | ||
public void benchHooked1() { | ||
for (int i = 0; i < INVOCATIONS; i++) { | ||
HOOKED_RUNTIME_ONE.evalScriptlet(RUN_SCRIPT); | ||
} | ||
} | ||
|
||
@Benchmark | ||
@OperationsPerInvocation(INVOCATIONS) | ||
public void benchHooked2() { | ||
for (int i = 0; i < INVOCATIONS; i++) { | ||
HOOKED_RUNTIME_TWO.evalScriptlet(RUN_SCRIPT); | ||
} | ||
} | ||
|
||
private static Ruby initRuntime() { | ||
final RubyInstanceConfig config = new RubyInstanceConfig(); | ||
config.setCompileMode(RubyInstanceConfig.CompileMode.OFF); | ||
config.setObjectSpaceEnabled(true); | ||
final Ruby runtime = Ruby.newInstance(config); | ||
runtime.evalScriptlet(BOOT_SCRIPT); | ||
return runtime; | ||
} | ||
|
||
private static Ruby initInterpRuntime() { | ||
final Ruby runtime = Ruby.newInstance(new RubyInstanceConfig()); | ||
runtime.evalScriptlet(BOOT_SCRIPT); | ||
return runtime; | ||
} | ||
|
||
private static Ruby initTracedRuntime() { | ||
final RubyInstanceConfig config = new RubyInstanceConfig(); | ||
RubyInstanceConfig.FULL_TRACE_ENABLED = true; | ||
final Ruby runtime = Ruby.newInstance(config); | ||
runtime.evalScriptlet(BOOT_SCRIPT); | ||
return runtime; | ||
} | ||
|
||
private static Ruby initHookedRuntime(final EventHook hook) { | ||
final Ruby runtime = initTracedRuntime(); | ||
runtime.addEventHook(hook); | ||
return runtime; | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
bench/src/main/java/org/jruby/benchmark/FixnumCreationBenchmark.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package org.jruby.benchmark; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
import org.jruby.Ruby; | ||
import org.jruby.RubyFixnum; | ||
import org.jruby.runtime.ThreadContext; | ||
import org.jruby.runtime.builtin.IRubyObject; | ||
import org.openjdk.jmh.annotations.Benchmark; | ||
import org.openjdk.jmh.annotations.BenchmarkMode; | ||
import org.openjdk.jmh.annotations.Fork; | ||
import org.openjdk.jmh.annotations.Measurement; | ||
import org.openjdk.jmh.annotations.Mode; | ||
import org.openjdk.jmh.annotations.OperationsPerInvocation; | ||
import org.openjdk.jmh.annotations.OutputTimeUnit; | ||
import org.openjdk.jmh.annotations.Scope; | ||
import org.openjdk.jmh.annotations.State; | ||
import org.openjdk.jmh.annotations.Warmup; | ||
import org.openjdk.jmh.infra.Blackhole; | ||
|
||
@Warmup(iterations = 3, time = 500, timeUnit = TimeUnit.MILLISECONDS) | ||
@Measurement(iterations = 20, time = 500, timeUnit = TimeUnit.MILLISECONDS) | ||
@Fork(1) | ||
@BenchmarkMode(Mode.Throughput) | ||
@OutputTimeUnit(TimeUnit.NANOSECONDS) | ||
@State(Scope.Thread) | ||
public class FixnumCreationBenchmark { | ||
|
||
private static final int INVOCATIONS = 1_000_000; | ||
|
||
private static final Ruby RUBY = Ruby.newInstance(); | ||
|
||
private static final RubyFixnum ONE = RubyFixnum.newFixnum(RUBY, 1L); | ||
|
||
private static final RubyFixnum TWO = RubyFixnum.newFixnum(RUBY, 2L); | ||
|
||
@Benchmark | ||
@OperationsPerInvocation(INVOCATIONS) | ||
public void benchFixnumCreation(final Blackhole blackhole) { | ||
final long time = System.currentTimeMillis(); | ||
final Ruby ruby = RUBY; | ||
for (int i = 0; i < INVOCATIONS; i++) { | ||
blackhole.consume(RubyFixnum.newFixnum(ruby, time)); | ||
} | ||
} | ||
|
||
@Benchmark | ||
@OutputTimeUnit(TimeUnit.SECONDS) | ||
public void benchStaticFib(final Blackhole blackhole) { | ||
final Ruby ruby = RUBY; | ||
final ThreadContext context = ruby.getCurrentContext(); | ||
blackhole.consume(fib(context, RubyFixnum.newFixnum(ruby, 30L))); | ||
} | ||
|
||
private static IRubyObject fib(final ThreadContext context, final IRubyObject object) { | ||
final RubyFixnum value = (RubyFixnum) object; | ||
if (value.op_lt(context, TWO).isTrue()) { | ||
return value; | ||
} | ||
return ((RubyFixnum) fib(context, value.op_minus(context, TWO))) | ||
.op_plus(context, fib(context, value.op_minus(context, ONE))); | ||
} | ||
} |
90 changes: 90 additions & 0 deletions
90
bench/src/main/java/org/jruby/benchmark/JavaInterfaceBenchmark.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package org.jruby.benchmark; | ||
|
||
import java.util.concurrent.ThreadLocalRandom; | ||
import java.util.concurrent.TimeUnit; | ||
import org.jruby.Ruby; | ||
import org.jruby.RubyFixnum; | ||
import org.jruby.RubyInstanceConfig; | ||
import org.jruby.runtime.builtin.IRubyObject; | ||
import org.openjdk.jmh.annotations.Benchmark; | ||
import org.openjdk.jmh.annotations.BenchmarkMode; | ||
import org.openjdk.jmh.annotations.Fork; | ||
import org.openjdk.jmh.annotations.Measurement; | ||
import org.openjdk.jmh.annotations.Mode; | ||
import org.openjdk.jmh.annotations.OperationsPerInvocation; | ||
import org.openjdk.jmh.annotations.OutputTimeUnit; | ||
import org.openjdk.jmh.annotations.Scope; | ||
import org.openjdk.jmh.annotations.State; | ||
import org.openjdk.jmh.annotations.Warmup; | ||
import org.openjdk.jmh.infra.Blackhole; | ||
|
||
@Warmup(iterations = 3, time = 500, timeUnit = TimeUnit.MILLISECONDS) | ||
@Measurement(iterations = 10, time = 500, timeUnit = TimeUnit.MILLISECONDS) | ||
@Fork(1) | ||
@BenchmarkMode(Mode.Throughput) | ||
@OutputTimeUnit(TimeUnit.NANOSECONDS) | ||
@State(Scope.Thread) | ||
public class JavaInterfaceBenchmark { | ||
|
||
private static final int INVOCATIONS = 200_000_000; | ||
|
||
private static final Ruby RUBY = initRuby(); | ||
|
||
private static final RubyFixnum LEFT = RUBY.newFixnum(ThreadLocalRandom.current().nextInt()); | ||
|
||
private static final RubyFixnum RIGHT = RUBY.newFixnum(ThreadLocalRandom.current().nextInt()); | ||
|
||
private static final JavaInterfaceBenchmark.Summation JAVA_SUMMER = | ||
new JavaInterfaceBenchmark.Summation() { | ||
@Override | ||
public IRubyObject sum(final RubyFixnum left, final RubyFixnum right) { | ||
return left.op_plus(RUBY.getCurrentContext(), right); | ||
} | ||
}; | ||
|
||
public interface Summation { | ||
IRubyObject sum(RubyFixnum left, RubyFixnum right); | ||
} | ||
|
||
@Benchmark | ||
@OperationsPerInvocation(INVOCATIONS) | ||
public void benchHalfRubyVersion(final Blackhole blackhole) { | ||
blackhole.consume( | ||
RUBY.executeScript( | ||
"org.jruby.benchmark.JavaInterfaceBenchmark.doRun(RubySummation.new)" | ||
,"benchHalfRubyVersion") | ||
); | ||
} | ||
|
||
@Benchmark | ||
@OperationsPerInvocation(INVOCATIONS) | ||
public void benchJavaVersion(final Blackhole blackhole) { | ||
blackhole.consume(doRun(JAVA_SUMMER)); | ||
} | ||
|
||
public static IRubyObject doRun(final JavaInterfaceBenchmark.Summation summer) { | ||
IRubyObject sum = null; | ||
for (int i = 0; i < INVOCATIONS; ++i) { | ||
sum = summer.sum(LEFT, RIGHT); | ||
} | ||
return sum; | ||
} | ||
|
||
private static Ruby initRuby() { | ||
final RubyInstanceConfig config = new RubyInstanceConfig(); | ||
config.setCompileMode(RubyInstanceConfig.CompileMode.FORCE); | ||
final Ruby ruby = Ruby.newInstance(config); | ||
ruby.executeScript( | ||
new StringBuilder() | ||
.append("class RubySummation\n") | ||
.append("\tinclude org.jruby.benchmark.JavaInterfaceBenchmark::Summation\n") | ||
.append('\n') | ||
.append("\tdef sum(a, b)\n") | ||
.append("\t\ta + b\n") | ||
.append("\tend\n") | ||
.append("end") | ||
.toString(), "initRuby" | ||
); | ||
return ruby; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import org.jruby.Ruby; | ||
|
||
import javax.script.ScriptContext; | ||
import javax.script.ScriptEngine; | ||
import javax.script.ScriptEngineManager; | ||
import javax.script.ScriptException; | ||
import javax.script.SimpleScriptContext; | ||
import java.io.IOException; | ||
|
||
public class Test { | ||
public static void main(String[] args) throws InterruptedException, ScriptException, ClassNotFoundException, IOException { | ||
for (int i = 0; i < 100; i++) blah(); | ||
|
||
System.gc(); | ||
System.gc(); | ||
Thread.sleep(5000); | ||
|
||
System.out.println(Ruby.getGlobalRuntime().getFilenoUtil().getNumberOfWrappers()); | ||
|
||
} | ||
|
||
private static void blah() throws ScriptException { | ||
ScriptEngineManager scriptEngineManager = new ScriptEngineManager(); | ||
final ScriptEngine engine = scriptEngineManager.getEngineByName("jruby"); | ||
final ScriptContext scriptContext = new SimpleScriptContext(); | ||
scriptContext.setAttribute("org.jruby.embed.termination", true, ScriptContext.ENGINE_SCOPE); | ||
|
||
engine.eval("print 'test\n'", scriptContext); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/***** BEGIN LICENSE BLOCK ***** | ||
* Version: EPL 2.0/GPL 2.0/LGPL 2.1 | ||
* | ||
* The contents of this file are subject to the Eclipse Public | ||
* License Version 2.0 (the "License"); you may not use this file | ||
* except in compliance with the License. You may obtain a copy of | ||
* the License at http://www.eclipse.org/legal/epl-v20.html | ||
* | ||
* Software distributed under the License is distributed on an "AS | ||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or | ||
* implied. See the License for the specific language governing | ||
* rights and limitations under the License. | ||
* | ||
* Alternatively, the contents of this file may be used under the terms of | ||
* either of the GNU General Public License Version 2 or later (the "GPL"), | ||
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), | ||
* in which case the provisions of the GPL or the LGPL are applicable instead | ||
* of those above. If you wish to allow use of your version of this file only | ||
* under the terms of either the GPL or the LGPL, and not to allow others to | ||
* use your version of this file under the terms of the EPL, indicate your | ||
* decision by deleting the provisions above and replace them with the notice | ||
* and other provisions required by the GPL or the LGPL. If you do not delete | ||
* the provisions above, a recipient may use your version of this file under | ||
* the terms of any one of the EPL, the GPL or the LGPL. | ||
***** END LICENSE BLOCK *****/ | ||
|
||
package org.jruby; | ||
|
||
import org.jruby.anno.JRubyClass; | ||
import org.jruby.exceptions.RaiseException; | ||
import org.jruby.exceptions.ArgumentError; | ||
|
||
/** | ||
* The Java representation of a Ruby ArgumentError. | ||
* | ||
* @see ArgumentError | ||
*/ | ||
@JRubyClass(name="ArgumentError", parent="StandardError") | ||
public class RubyArgumentError extends RubyStandardError { | ||
protected RubyArgumentError(Ruby runtime, RubyClass exceptionClass) { | ||
super(runtime, exceptionClass); | ||
} | ||
|
||
protected RubyArgumentError(Ruby runtime, RubyClass exceptionClass, String message) { | ||
super(runtime, exceptionClass, message); | ||
} | ||
|
||
static RubyClass define(Ruby runtime, RubyClass exceptionClass) { | ||
RubyClass argumentErrorClass = runtime.defineClass("ArgumentError", exceptionClass, (r, klass) -> new RubyArgumentError(runtime, klass)); | ||
|
||
return argumentErrorClass; | ||
} | ||
|
||
@Override | ||
protected RaiseException constructThrowable(String message) { | ||
return new ArgumentError(message, this); | ||
} | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/***** BEGIN LICENSE BLOCK ***** | ||
* Version: EPL 2.0/GPL 2.0/LGPL 2.1 | ||
* | ||
* The contents of this file are subject to the Eclipse Public | ||
* License Version 2.0 (the "License"); you may not use this file | ||
* except in compliance with the License. You may obtain a copy of | ||
* the License at http://www.eclipse.org/legal/epl-v20.html | ||
* | ||
* Software distributed under the License is distributed on an "AS | ||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or | ||
* implied. See the License for the specific language governing | ||
* rights and limitations under the License. | ||
* | ||
* Alternatively, the contents of this file may be used under the terms of | ||
* either of the GNU General Public License Version 2 or later (the "GPL"), | ||
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), | ||
* in which case the provisions of the GPL or the LGPL are applicable instead | ||
* of those above. If you wish to allow use of your version of this file only | ||
* under the terms of either the GPL or the LGPL, and not to allow others to | ||
* use your version of this file under the terms of the EPL, indicate your | ||
* decision by deleting the provisions above and replace them with the notice | ||
* and other provisions required by the GPL or the LGPL. If you do not delete | ||
* the provisions above, a recipient may use your version of this file under | ||
* the terms of any one of the EPL, the GPL or the LGPL. | ||
***** END LICENSE BLOCK *****/ | ||
|
||
package org.jruby; | ||
|
||
import org.jruby.anno.JRubyClass; | ||
import org.jruby.exceptions.RaiseException; | ||
import org.jruby.exceptions.ConcurrencyError; | ||
|
||
/** | ||
* The Java representation of a Ruby ConcurrencyError. | ||
* | ||
* @see ConcurrencyError | ||
*/ | ||
@JRubyClass(name="ConcurrencyError", parent="ThreadError") | ||
public class RubyConcurrencyError extends RubyThreadError { | ||
protected RubyConcurrencyError(Ruby runtime, RubyClass exceptionClass) { | ||
super(runtime, exceptionClass); | ||
} | ||
|
||
static RubyClass define(Ruby runtime, RubyClass exceptionClass) { | ||
RubyClass concurrencyErrorClass = runtime.defineClass("ConcurrencyError", exceptionClass, (r, klass) -> new RubyConcurrencyError(runtime, klass)); | ||
|
||
return concurrencyErrorClass; | ||
} | ||
|
||
protected RaiseException constructThrowable(String message) { | ||
return new ConcurrencyError(message, this); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/***** BEGIN LICENSE BLOCK ***** | ||
* Version: EPL 2.0/GPL 2.0/LGPL 2.1 | ||
* | ||
* The contents of this file are subject to the Eclipse Public | ||
* License Version 2.0 (the "License"); you may not use this file | ||
* except in compliance with the License. You may obtain a copy of | ||
* the License at http://www.eclipse.org/legal/epl-v20.html | ||
* | ||
* Software distributed under the License is distributed on an "AS | ||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or | ||
* implied. See the License for the specific language governing | ||
* rights and limitations under the License. | ||
* | ||
* Alternatively, the contents of this file may be used under the terms of | ||
* either of the GNU General Public License Version 2 or later (the "GPL"), | ||
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), | ||
* in which case the provisions of the GPL or the LGPL are applicable instead | ||
* of those above. If you wish to allow use of your version of this file only | ||
* under the terms of either the GPL or the LGPL, and not to allow others to | ||
* use your version of this file under the terms of the EPL, indicate your | ||
* decision by deleting the provisions above and replace them with the notice | ||
* and other provisions required by the GPL or the LGPL. If you do not delete | ||
* the provisions above, a recipient may use your version of this file under | ||
* the terms of any one of the EPL, the GPL or the LGPL. | ||
***** END LICENSE BLOCK *****/ | ||
|
||
package org.jruby; | ||
|
||
import org.jruby.anno.JRubyClass; | ||
import org.jruby.exceptions.DomainError; | ||
import org.jruby.exceptions.RaiseException; | ||
|
||
/** | ||
/** | ||
* The Java representation of a Ruby DomainError. | ||
* | ||
* @see DomainError | ||
* @see RubyEnumerator | ||
* @author kares | ||
*/ | ||
@JRubyClass(name="DomainError", parent="ArgumentError") | ||
public class RubyDomainError extends RubyArgumentError { | ||
protected RubyDomainError(Ruby runtime, RubyClass exceptionClass) { | ||
super(runtime, exceptionClass); | ||
} | ||
|
||
static RubyClass define(Ruby runtime, RubyClass superClass, RubyModule under) { | ||
return under.defineClassUnder("DomainError", superClass, (runtime1, klass) -> new RubyDomainError(runtime1, klass)); | ||
} | ||
|
||
@Override | ||
protected RaiseException constructThrowable(String message) { | ||
return new DomainError(message, this); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/***** BEGIN LICENSE BLOCK ***** | ||
* Version: EPL 2.0/GPL 2.0/LGPL 2.1 | ||
* | ||
* The contents of this file are subject to the Eclipse Public | ||
* License Version 2.0 (the "License"); you may not use this file | ||
* except in compliance with the License. You may obtain a copy of | ||
* the License at http://www.eclipse.org/legal/epl-v20.html | ||
* | ||
* Software distributed under the License is distributed on an "AS | ||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or | ||
* implied. See the License for the specific language governing | ||
* rights and limitations under the License. | ||
* | ||
* Alternatively, the contents of this file may be used under the terms of | ||
* either of the GNU General Public License Version 2 or later (the "GPL"), | ||
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), | ||
* in which case the provisions of the GPL or the LGPL are applicable instead | ||
* of those above. If you wish to allow use of your version of this file only | ||
* under the terms of either the GPL or the LGPL, and not to allow others to | ||
* use your version of this file under the terms of the EPL, indicate your | ||
* decision by deleting the provisions above and replace them with the notice | ||
* and other provisions required by the GPL or the LGPL. If you do not delete | ||
* the provisions above, a recipient may use your version of this file under | ||
* the terms of any one of the EPL, the GPL or the LGPL. | ||
***** END LICENSE BLOCK *****/ | ||
|
||
package org.jruby; | ||
|
||
import org.jruby.anno.JRubyClass; | ||
import org.jruby.exceptions.EOFError; | ||
import org.jruby.exceptions.RaiseException; | ||
|
||
/** | ||
* The Java representation of a Ruby EOFError. | ||
* | ||
* @see EOFError | ||
*/ | ||
@JRubyClass(name="EOFError", parent="IOError") | ||
public class RubyEOFError extends RubyIOError { | ||
protected RubyEOFError(Ruby runtime, RubyClass exceptionClass) { | ||
super(runtime, exceptionClass); | ||
} | ||
|
||
static RubyClass define(Ruby runtime, RubyClass exceptionClass) { | ||
RubyClass eofErrorClass = runtime.defineClass("EOFError", exceptionClass, (r, klass) -> new RubyEOFError(runtime, klass)); | ||
|
||
return eofErrorClass; | ||
} | ||
|
||
protected RaiseException constructThrowable(String message) { | ||
return new EOFError(message, this); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
/***** BEGIN LICENSE BLOCK ***** | ||
* Version: EPL 2.0/GPL 2.0/LGPL 2.1 | ||
* | ||
* The contents of this file are subject to the Eclipse Public | ||
* License Version 2.0 (the "License"); you may not use this file | ||
* except in compliance with the License. You may obtain a copy of | ||
* the License at http://www.eclipse.org/legal/epl-v20.html | ||
* | ||
* Software distributed under the License is distributed on an "AS | ||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or | ||
* implied. See the License for the specific language governing | ||
* rights and limitations under the License. | ||
* | ||
* Alternatively, the contents of this file may be used under the terms of | ||
* either of the GNU General Public License Version 2 or later (the "GPL"), | ||
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), | ||
* in which case the provisions of the GPL or the LGPL are applicable instead | ||
* of those above. If you wish to allow use of your version of this file only | ||
* under the terms of either the GPL or the LGPL, and not to allow others to | ||
* use your version of this file under the terms of the EPL, indicate your | ||
* decision by deleting the provisions above and replace them with the notice | ||
* and other provisions required by the GPL or the LGPL. If you do not delete | ||
* the provisions above, a recipient may use your version of this file under | ||
* the terms of any one of the EPL, the GPL or the LGPL. | ||
***** END LICENSE BLOCK *****/ | ||
|
||
package org.jruby; | ||
|
||
import org.jruby.anno.JRubyClass; | ||
import org.jruby.exceptions.RaiseException; | ||
import org.jruby.exceptions.EncodingError; | ||
|
||
/** | ||
* The Java representation of a Ruby EncodingError. | ||
* | ||
* @see EncodingError | ||
*/ | ||
@JRubyClass(name="EncodingError", parent="StandardError") | ||
public class RubyEncodingError extends RubyStandardError { | ||
protected RubyEncodingError(Ruby runtime, RubyClass exceptionClass) { | ||
super(runtime, exceptionClass); | ||
} | ||
|
||
static RubyClass define(Ruby runtime, RubyClass exceptionClass) { | ||
RubyClass encodingErrorClass = runtime.defineClass("EncodingError", exceptionClass, (r, klass) -> new RubyEncodingError(runtime, klass)); | ||
|
||
return encodingErrorClass; | ||
} | ||
|
||
protected RaiseException constructThrowable(String message) { | ||
return new EncodingError(message, this); | ||
} | ||
|
||
@JRubyClass(name="CompatibilityError", parent="EncodingError") | ||
public static class RubyCompatibilityError extends RubyEncodingError { | ||
protected RubyCompatibilityError(Ruby runtime, RubyClass exceptionClass) { | ||
super(runtime, exceptionClass); | ||
} | ||
|
||
static RubyClass define(Ruby runtime, RubyClass exceptionClass, RubyModule under) { | ||
return under.defineClassUnder("CompatibilityError", exceptionClass, (r, klass) -> new RubyCompatibilityError(runtime, klass)); | ||
} | ||
|
||
protected RaiseException constructThrowable(String message) { | ||
return new EncodingError.CompatibilityError(message, this); | ||
} | ||
} | ||
|
||
@JRubyClass(name="InvalidByteSequenceError", parent="EncodingError") | ||
public static class RubyInvalidByteSequenceError extends RubyEncodingError { | ||
protected RubyInvalidByteSequenceError(Ruby runtime, RubyClass exceptionClass) { | ||
super(runtime, exceptionClass); | ||
} | ||
|
||
static RubyClass define(Ruby runtime, RubyClass exceptionClass, RubyModule under) { | ||
RubyClass invalidByteSequenceErrorClass = under.defineClassUnder("InvalidByteSequenceError", exceptionClass, (r, klass) -> new RubyInvalidByteSequenceError(runtime, klass)); | ||
|
||
invalidByteSequenceErrorClass.defineAnnotatedMethods(RubyConverter.EncodingErrorMethods.class); | ||
invalidByteSequenceErrorClass.defineAnnotatedMethods(RubyConverter.InvalidByteSequenceErrorMethods.class); | ||
|
||
return invalidByteSequenceErrorClass; | ||
} | ||
|
||
protected RaiseException constructThrowable(String message) { | ||
return new EncodingError.InvalidByteSequenceError(message, this); | ||
} | ||
} | ||
|
||
@JRubyClass(name="UndefinedConversionError", parent="EncodingError") | ||
public static class RubyUndefinedConversionError extends RubyEncodingError { | ||
protected RubyUndefinedConversionError(Ruby runtime, RubyClass exceptionClass) { | ||
super(runtime, exceptionClass); | ||
} | ||
|
||
static RubyClass define(Ruby runtime, RubyClass exceptionClass, RubyModule under) { | ||
RubyClass undefinedConversionErrorClass = under.defineClassUnder("UndefinedConversionError", exceptionClass, (r, klass) -> new RubyUndefinedConversionError(runtime, klass)); | ||
|
||
undefinedConversionErrorClass.defineAnnotatedMethods(RubyConverter.EncodingErrorMethods.class); | ||
undefinedConversionErrorClass.defineAnnotatedMethods(RubyConverter.UndefinedConversionErrorMethods.class); | ||
|
||
return undefinedConversionErrorClass; | ||
} | ||
|
||
protected RaiseException constructThrowable(String message) { | ||
return new EncodingError.UndefinedConversionError(message, this); | ||
} | ||
} | ||
|
||
@JRubyClass(name="ConverterNotFoundError", parent="EncodingError") | ||
public static class RubyConverterNotFoundError extends RubyEncodingError { | ||
protected RubyConverterNotFoundError(Ruby runtime, RubyClass exceptionClass) { | ||
super(runtime, exceptionClass); | ||
} | ||
|
||
static RubyClass define(Ruby runtime, RubyClass exceptionClass, RubyModule under) { | ||
RubyClass converterNotFoundErrorClass = under.defineClassUnder("ConverterNotFoundError", exceptionClass, (r, klass) -> new RubyConverterNotFoundError(runtime, klass)); | ||
|
||
return converterNotFoundErrorClass; | ||
} | ||
|
||
protected RaiseException constructThrowable(String message) { | ||
return new EncodingError.ConverterNotFoundError(message, this); | ||
} | ||
} | ||
} |
Oops, something went wrong.