Skip to content

Commit

Permalink
Merge branch 'master' into truffle-head-next
Browse files Browse the repository at this point in the history
# Conflicts:
#	truffle/src/main/java/org/jruby/truffle/core/rope/RopeTable.java
#	truffle/src/main/java/org/jruby/truffle/core/string/CoreStrings.java
#	truffle/src/main/java/org/jruby/truffle/extra/AttachmentsManager.java
#	truffle/src/main/java/org/jruby/truffle/language/RubyGuards.java
chrisseaton committed Apr 11, 2016
2 parents 9ac73f9 + 96a38e8 commit 5fd9fe0
Showing 115 changed files with 1,740 additions and 1,230 deletions.
2 changes: 1 addition & 1 deletion .mvn/extensions.xml
Original file line number Diff line number Diff line change
@@ -3,6 +3,6 @@
<extension>
<groupId>io.takari.polyglot</groupId>
<artifactId>polyglot-ruby</artifactId>
<version>0.1.11</version>
<version>0.1.15</version>
</extension>
</extensions>
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -47,8 +47,6 @@ matrix:
- env: JT=check_ambiguous_arguments
jdk: oraclejdk8
- env: JT='test mri'
- env: PHASE='-Pmain --projects !truffle'
jdk: oraclejdk8
- env: PHASE='-Pj2ee --projects !truffle'
jdk: oraclejdk7
# NOTE: build seems to never start (waited for any to finish for more than a day) - probably a travis-ci bug
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/RubyBasicObject.java
Original file line number Diff line number Diff line change
@@ -1075,7 +1075,7 @@ public IRubyObject inspect() {
return to_s();
}

public IRubyObject hashyInspect() {
public final IRubyObject hashyInspect() {
final Ruby runtime = getRuntime();
String cname = getMetaClass().getRealClass().getName();
StringBuilder part = new StringBuilder(2 + cname.length() + 3 + 8 + 1); // #<Object:0x5a1c0542>
99 changes: 53 additions & 46 deletions core/src/main/java/org/jruby/RubyModule.java
Original file line number Diff line number Diff line change
@@ -884,25 +884,19 @@ public void defineAnnotatedMethod(Class clazz, String name) {
}
}

public void defineAnnotatedConstants(Class clazz) {
Field[] declaredFields = clazz.getDeclaredFields();
for (Field field : declaredFields) {
public final void defineAnnotatedConstants(Class clazz) {
for (Field field : clazz.getDeclaredFields()) {
if (Modifier.isStatic(field.getModifiers())) {
defineAnnotatedConstant(field);
}
}
}

public boolean defineAnnotatedConstant(Field field) {
public final boolean defineAnnotatedConstant(Field field) {
JRubyConstant jrubyConstant = field.getAnnotation(JRubyConstant.class);

if (jrubyConstant == null) return false;

String[] names = jrubyConstant.value();
if(names.length == 0) {
names = new String[]{field.getName()};
}

Class tp = field.getType();
IRubyObject realVal;

@@ -918,9 +912,12 @@ public boolean defineAnnotatedConstant(Field field) {
realVal = getRuntime().getNil();
}


for(String name : names) {
this.setConstant(name, realVal);
String[] names = jrubyConstant.value();
if (names.length == 0) {
setConstant(field.getName(), realVal);
}
else {
for (String name : names) setConstant(name, realVal);
}

return true;
@@ -931,12 +928,12 @@ public void defineAnnotatedMethods(Class clazz) {
defineAnnotatedMethodsIndividually(clazz);
}

public static class MethodClumper {
Map<String, List<JavaMethodDescriptor>> annotatedMethods = new HashMap<String, List<JavaMethodDescriptor>>();
Map<String, List<JavaMethodDescriptor>> staticAnnotatedMethods = new HashMap<String, List<JavaMethodDescriptor>>();
Map<String, List<JavaMethodDescriptor>> allAnnotatedMethods = new HashMap<String, List<JavaMethodDescriptor>>();
public static final class MethodClumper {
private HashMap<String, List<JavaMethodDescriptor>> annotatedMethods;
private HashMap<String, List<JavaMethodDescriptor>> staticAnnotatedMethods;
// final HashMap<String, List<JavaMethodDescriptor>> allAnnotatedMethods = new HashMap<>();

public void clump(Class cls) {
public void clump(final Class cls) {
Method[] declaredMethods = Initializer.DECLARED_METHODS.get(cls);
for (Method method: declaredMethods) {
JRubyMethod anno = method.getAnnotation(JRubyMethod.class);
@@ -953,56 +950,66 @@ public void clump(Class cls) {
List<JavaMethodDescriptor> methodDescs;
Map<String, List<JavaMethodDescriptor>> methodsHash;
if (desc.isStatic) {
methodsHash = staticAnnotatedMethods;
if ( (methodsHash = staticAnnotatedMethods) == null ) {
methodsHash = staticAnnotatedMethods = new HashMap<>();
}
} else {
methodsHash = annotatedMethods;
if ( (methodsHash = annotatedMethods) == null ) {
methodsHash = annotatedMethods = new HashMap<>();
}
}

// add to specific
methodDescs = methodsHash.get(name);
if (methodDescs == null) {
methodDescs = new ArrayList<JavaMethodDescriptor>();
methodsHash.put(name, methodDescs);
} else {
// optimize for most methods mapping to one method for a given name :
methodsHash.put(name, Collections.singletonList(desc));
}
else {
CompatVersion oldCompat = methodDescs.get(0).anno.compat();
CompatVersion newCompat = desc.anno.compat();

int comparison = newCompat.compareTo(oldCompat);
if (comparison == 1) {
// new method's compat is higher than old method's, so we throw old one away
methodDescs = new ArrayList<JavaMethodDescriptor>();
methodsHash.put(name, methodDescs);
methodsHash.put(name, methodDescs = new ArrayList<>(2));
} else if (comparison == 0) {
// same compat version, proceed to adding additional method
} else {
// lower compat, skip this method
continue;
}
}

methodDescs.add(desc);
if (methodDescs.getClass() != ArrayList.class) { // due singletonList
ArrayList<JavaMethodDescriptor> newDescs = new ArrayList<>(4);
newDescs.addAll(methodDescs);
methodsHash.put(name, methodDescs = newDescs);
}

// add to general
methodDescs = allAnnotatedMethods.get(name);
if (methodDescs == null) {
methodDescs = new ArrayList<JavaMethodDescriptor>();
allAnnotatedMethods.put(name, methodDescs);
methodDescs.add(desc);
}

methodDescs.add(desc);
// add to general
//methodDescs = allAnnotatedMethods.get(name);
//if (methodDescs == null) {
// methodDescs = new ArrayList<JavaMethodDescriptor>();
// allAnnotatedMethods.put(name, methodDescs);
//}
//methodDescs.add(desc);
}
}

@Deprecated // no-longer used
public Map<String, List<JavaMethodDescriptor>> getAllAnnotatedMethods() {
return allAnnotatedMethods;
return null; // return allAnnotatedMethods;
}

public Map<String, List<JavaMethodDescriptor>> getAnnotatedMethods() {
return annotatedMethods;
public final Map<String, List<JavaMethodDescriptor>> getAnnotatedMethods() {
return annotatedMethods == null ? Collections.EMPTY_MAP : annotatedMethods;
}

public Map<String, List<JavaMethodDescriptor>> getStaticAnnotatedMethods() {
return staticAnnotatedMethods;
public final Map<String, List<JavaMethodDescriptor>> getStaticAnnotatedMethods() {
return staticAnnotatedMethods == null ? Collections.EMPTY_MAP : staticAnnotatedMethods;
}
}

@@ -1032,23 +1039,23 @@ public static TypePopulator loadPopulatorFor(Class<?> type) {
return new TypePopulator.ReflectiveTypePopulator(type);
}

public void defineAnnotatedMethodsIndividually(Class clazz) {
public final void defineAnnotatedMethodsIndividually(Class clazz) {
getRuntime().POPULATORS.get(clazz).populate(this, clazz);
}

public boolean defineAnnotatedMethod(String name, List<JavaMethodDescriptor> methods, MethodFactory methodFactory) {
public final boolean defineAnnotatedMethod(String name, List<JavaMethodDescriptor> methods, MethodFactory methodFactory) {
JavaMethodDescriptor desc = methods.get(0);
if (methods.size() == 1) {
return defineAnnotatedMethod(name, desc, methodFactory);
} else {
DynamicMethod dynamicMethod = methodFactory.getAnnotatedMethod(this, methods);
define(this, desc, name, dynamicMethod);

return true;
}

DynamicMethod dynamicMethod = methodFactory.getAnnotatedMethod(this, methods);
define(this, desc, name, dynamicMethod);

return true;
}

public boolean defineAnnotatedMethod(Method method, MethodFactory methodFactory) {
public final boolean defineAnnotatedMethod(Method method, MethodFactory methodFactory) {
JRubyMethod jrubyMethod = method.getAnnotation(JRubyMethod.class);

if (jrubyMethod == null) return false;
@@ -1060,7 +1067,7 @@ public boolean defineAnnotatedMethod(Method method, MethodFactory methodFactory)
return true;
}

public boolean defineAnnotatedMethod(String name, JavaMethodDescriptor desc, MethodFactory methodFactory) {
public final boolean defineAnnotatedMethod(String name, JavaMethodDescriptor desc, MethodFactory methodFactory) {
JRubyMethod jrubyMethod = desc.anno;

if (jrubyMethod == null) return false;
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/RubyString.java
Original file line number Diff line number Diff line change
@@ -517,7 +517,7 @@ public static RubyString newUTF8String(Ruby runtime, CharSequence str) {
}

public static RubyString newUTF16String(Ruby runtime, CharSequence str) {
ByteList byteList = new ByteList(RubyEncoding.encodeUTF16(str.toString()), UTF16BEEncoding.INSTANCE, false);
ByteList byteList = new ByteList(RubyEncoding.encodeUTF16(str), UTF16BEEncoding.INSTANCE, false);
return new RubyString(runtime, runtime.getString(), byteList);
}

24 changes: 15 additions & 9 deletions core/src/main/java/org/jruby/anno/TypePopulator.java
Original file line number Diff line number Diff line change
@@ -74,7 +74,7 @@ public void populate(RubyModule clsmod, Class clazz) {
}
}

public static class ReflectiveTypePopulator extends TypePopulator {
public static final class ReflectiveTypePopulator extends TypePopulator {
private final Class clazz;
private final RubyModule.MethodClumper clumper;

@@ -88,20 +88,26 @@ public void populate(RubyModule clsmod, Class clazz) {
assert clazz == this.clazz : "populator for " + this.clazz + " used for " + clazz;

// fallback on non-pregenerated logic
MethodFactory methodFactory = MethodFactory.createFactory(clsmod.getRuntime().getJRubyClassLoader());
Ruby runtime = clsmod.getRuntime();
final Ruby runtime = clsmod.getRuntime();
final MethodFactory methodFactory = MethodFactory.createFactory(runtime.getJRubyClassLoader());

for (Map.Entry<String, List<JavaMethodDescriptor>> entry : clumper.getStaticAnnotatedMethods().entrySet()) {
clsmod.defineAnnotatedMethod(entry.getKey(), entry.getValue(), methodFactory);
for (JavaMethodDescriptor desc : entry.getValue()) {
if (!desc.anno.omit()) runtime.addBoundMethod(desc.declaringClassName, desc.name, entry.getKey());
final String name = entry.getKey();
final List<JavaMethodDescriptor> methods = entry.getValue();
clsmod.defineAnnotatedMethod(name, methods, methodFactory);
for ( int i=0; i<methods.size(); i++ ) {
final JavaMethodDescriptor desc = methods.get(i);
if (!desc.anno.omit()) runtime.addBoundMethod(desc.declaringClassName, desc.name, name);
}
}

for (Map.Entry<String, List<JavaMethodDescriptor>> entry : clumper.getAnnotatedMethods().entrySet()) {
clsmod.defineAnnotatedMethod(entry.getKey(), entry.getValue(), methodFactory);
for (JavaMethodDescriptor desc : entry.getValue()) {
if (!desc.anno.omit()) runtime.addBoundMethod(desc.declaringClassName, desc.name, entry.getKey());
final String name = entry.getKey();
final List<JavaMethodDescriptor> methods = entry.getValue();
clsmod.defineAnnotatedMethod(name, methods, methodFactory);
for ( int i=0; i<methods.size(); i++ ) {
final JavaMethodDescriptor desc = methods.get(i);
if (!desc.anno.omit()) runtime.addBoundMethod(desc.declaringClassName, desc.name, name);
}
}
}
46 changes: 31 additions & 15 deletions core/src/main/java/org/jruby/compiler/impl/SkinnyMethodAdapter.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,34 @@
/*
* SkinnyMethodAdapter.java
/***** BEGIN LICENSE BLOCK *****
* Version: EPL 1.0/GPL 2.0/LGPL 2.1
*
* Created on March 10, 2007, 2:52 AM
* The contents of this file are subject to the Eclipse Public
* License Version 1.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-v10.html
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/

* 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.compiler.impl;

import java.io.PrintStream;
import java.io.PrintWriter;
import java.util.Map;
import java.util.concurrent.Callable;

import org.jruby.util.SafePropertyAccessor;
import org.jruby.util.cli.Options;
import static org.jruby.util.CodegenUtils.*;

@@ -26,24 +40,26 @@
import org.objectweb.asm.Handle;
import org.objectweb.asm.Label;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
import org.objectweb.asm.util.Printer;
import org.objectweb.asm.util.Textifier;
import org.objectweb.asm.util.TraceMethodVisitor;
import static org.objectweb.asm.Opcodes.*;

/**
*
* @author headius
*/
public class SkinnyMethodAdapter extends MethodVisitor implements Opcodes {
public final class SkinnyMethodAdapter extends MethodVisitor {
private final static boolean DEBUG = Options.COMPILE_DUMP.load();

private final String name;
private final ClassVisitor cv;
private final Label start;
private final Label end;

private MethodVisitor method;
private Printer printer;
private String name;
private ClassVisitor cv;
private Label start;
private Label end;

public SkinnyMethodAdapter(ClassVisitor cv, int flags, String name, String signature, String something, String[] exceptions) {
super(ASM4);
21 changes: 18 additions & 3 deletions core/src/main/java/org/jruby/embed/IsolatedScriptingContainer.java
Original file line number Diff line number Diff line change
@@ -10,16 +10,28 @@
import org.jruby.util.UriLikePathHelper;

/**
* the IsolatedScriptingContainer does set GEM_HOME and GEM_PATH and JARS_HOME
* The IsolatedScriptingContainer does set GEM_HOME and GEM_PATH and JARS_HOME
* in such a way that it uses only resources which can be reached with classloader.
*
* GEM_HOME is uri:classloader://META-INF/jruby.home/lib/ruby/gems/shared
* GEM_PATH is uri:classloader://
* JARS_HOME is uri:classloader://jars
*
* but whenever you want to set them via {@link #setEnvironment(Map)} this will be honored.
* But whenever you want to set them via {@link #setEnvironment(Map)} this will be honored.
*
* it also comes with OSGi support which allows to add a bundle to LOAD_PATH or GEM_PATH.
* It also allows to add a classloaders to LOAD_PATH or GEM_PATH.
*
* This container also sets option classloader.delegate to false, i.e. the JRubyClassloader
* for each runtime will lookup classes first on itself before looking into the parent
* classloader.
*
* WARNING: this can give problems when joda-time is used inside the
* JRubyClassloader or with current version of nokogiri (1.6.7.2) as it uses
* (sun-)jdk classes which conflicts with classes nokogiri loaded into the
* JRubyClassloader.
*
* With any classloader related problem the first thing is to try
* <code>container.getProvider().getRubyInstanceConfig().setClassloaderDelegate(true);</code> to solve it.
*/
public class IsolatedScriptingContainer extends ScriptingContainer {

@@ -65,6 +77,9 @@ public IsolatedScriptingContainer( LocalContextScope scope,

// setup the isolated GEM_PATH, i.e. without $HOME/.gem/**
setEnvironment(null);

// give preference to jrubyClassloader over parent-classloader
getProvider().getRubyInstanceConfig().setClassloaderDelegate(false);
}

@Override
Loading

0 comments on commit 5fd9fe0

Please sign in to comment.