Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

* Example to trigger ArrayIndexOutOfBoundsException

  • Loading branch information...
commit 24b90005ee046d44553767930a0c90f0772b9c24 1 parent 561fca9
@donv donv authored
View
BIN  JRUBY_6792.class
Binary file not shown
View
31 JRUBY_6792.java
@@ -0,0 +1,31 @@
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jruby.embed.ScriptingContainer;
+import org.jruby.embed.internal.EmbedEvalUnitImpl;
+
+class JRUBY_6792 {
+ public static void main(String[] args) {
+ ScriptingContainer container = new ScriptingContainer();
+
+ // Simulate a garbage collection of softreference to current context
+ container.getProvider().getRuntime().getThreadService().setCurrentContext(null);
+
+ container.put("MyConstant", 42);
+ container.runScriptlet("a = 1");
+ container.runScriptlet("b = 2");
+
+ }
+
+ private static void oome() {
+ try {
+ List<byte[]> l = new ArrayList<byte[]>();
+ while(true) {
+ l.add(new byte[1024 * 1024]);
+ }
+ } catch (OutOfMemoryError oome) {
+ System.out.println("Forced SoftReference collection: " + oome);
+ }
+ }
+
+}
View
11 src/org/jruby/embed/internal/EmbedEvalUnitImpl.java
@@ -108,6 +108,17 @@ public IRubyObject run() {
if (sharing_variables) {
vars.inject(scope, 0, null);
runtime.getCurrentContext().pushScope(scope);
+
+ // Simulate a constrained memory situation to collect soft references
+ try {
+ java.util.List<byte[]> l = new java.util.ArrayList<byte[]>();
+ while(true) {
+ l.add(new byte[1024 * 1024]);
+ }
+ } catch (OutOfMemoryError oome) {
+ System.out.println("Forced SoftReference collection: " + oome);
+ }
+
}
IRubyObject ret;
CompileMode mode = runtime.getInstanceConfig().getCompileMode();
View
2  src/org/jruby/internal/runtime/ThreadService.java
@@ -216,7 +216,7 @@ public void setCurrentContext(ThreadContext context) {
private SoftReference adoptCurrentThread() {
Thread current = Thread.currentThread();
-
+ System.out.println("ThreadService.adoptCurrentThread: " + current);
RubyThread.adopt(runtime.getThread(), current);
return (SoftReference) localContext.get();
View
2  src/org/jruby/runtime/ThreadContext.java
@@ -276,9 +276,11 @@ public void pushScope(DynamicScope scope) {
if (index + 1 == stack.length) {
expandScopesIfNecessary();
}
+ System.out.println("ThreadContext.pushScope: " + Thread.currentThread() + ", " + this + ", scopeIndex: " + scopeIndex + ", scope: " + scope.hashCode());
}
public void popScope() {
+ System.out.println("ThreadContext.popScope: " + Thread.currentThread() + ", " + this + ", scopeIndex: " + scopeIndex + ", scope: " + scopeStack[scopeIndex].hashCode());
scopeStack[scopeIndex--] = null;
}
View
70 test/org/jruby/embed/ScriptingContainerSingletonTest.java
@@ -0,0 +1,70 @@
+/**
+ * **** BEGIN LICENSE BLOCK *****
+ * Version: CPL 1.0/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Common 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/cpl-v10.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.
+ *
+ * Copyright (C) 2009-2010 Yoko Harada <yokolet@gmail.com>
+ *
+ * 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 CPL, 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 CPL, the GPL or the LGPL.
+ * **** END LICENSE BLOCK *****
+ */
+package org.jruby.embed;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author donV
+ */
+public class ScriptingContainerSingletonTest {
+ private ScriptingContainer container;
+
+ @Before
+ public void setUp() {
+ container = new ScriptingContainer(LocalContextScope.SINGLETON);
+ }
+
+ @After
+ public void tearDown() {
+ container = null;
+ }
+
+ /**
+ * Test of runScriptlet method, of class ScriptingContainer.
+ */
+ @Test
+ public void testRunScriptletCheckConstant() {
+ System.out.println();
+ System.out.println("*******************************************************************************************************************");
+
+ // Simulate a garbage collection of softreference to current context
+ container.getProvider().getRuntime().getThreadService().setCurrentContext(null);
+
+ container.put("MyConstant", 42);
+ container.runScriptlet("a = 1");
+ container.runScriptlet("b = 2");
+
+ System.out.println("*******************************************************************************************************************");
+ }
+
+}
Please sign in to comment.
Something went wrong with that request. Please try again.