summaryrefslogtreecommitdiff
path: root/test/ruby
diff options
context:
space:
mode:
authorko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-12-19 22:29:18 +0000
committerko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-12-19 22:29:18 +0000
commit87e1616048edca270c86ab7e5d8b8599e1df79de (patch)
tree97ab05b808201a66b21d7cacbc5702769507abcf /test/ruby
parent5d92f6ec05be5df5f89f81fb926ad08faf22ee03 (diff)
* vm.c: support variable VM/Machine stack sizes.
Specified by the following environment variaables: - RUBY_THREAD_VM_STACK_SIZE: vm stack size used at thread creation. default: 128KB (32bit CPU) or 256KB (64bit CPU). - RUBY_THREAD_MACHINE_STACK_SIZE: machine stack size used at thread creation. default: 512KB or 1024KB. - RUBY_FIBER_VM_STACK_SIZE: vm stack size used at fiber creation. default: 64KB or 128KB. - RUBY_FIBER_MACHINE_STACK_SIZE: machine stack size used at fiber creation. default: 256KB or 256KB. This values are specified at launched timing. You can not change these values at running time. Environ variables are only *hints* because: - They are aligned to 4KB. - They have minimum values (depend on OSs). - Machine stack settings are ignored by some OSs. Default values especially fiber stack sizes are increased. This change affect Fiber's behavior: (1) You can run more complex program on a Fiber. (2) You can not make many (thousands) Fibers because of lack of address space (on 32bit CPU). If (2) bothers you, (a) Use 64bit CPU with big memory, or (b) Specify RUBY_FIBER_(VM|MACHINE)_STACK_SIZE correctly. You need to choose correct stack size carefully. These values are completely rely on systems (OS/compiler and so on). * vm_core.h (rb_vm_t::default_params): add to record above settings. * vm.c (RubyVM::DEFAULT_PARAMS): add new constant to see above setting. * thread_pthread.c: support RUBY_THREAD_MACHINE_STACK_SIZE. * cont.c: support RUBY_FIBER_(VM|MACHINE)_STACK_SIZE. * test/ruby/test_fiber.rb: add tests for above. * test/ruby/test_thread.rb: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38478 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby')
-rw-r--r--test/ruby/test_fiber.rb42
-rw-r--r--test/ruby/test_thread.rb40
2 files changed, 82 insertions, 0 deletions
diff --git a/test/ruby/test_fiber.rb b/test/ruby/test_fiber.rb
index cc0df749b0..4288cabe09 100644
--- a/test/ruby/test_fiber.rb
+++ b/test/ruby/test_fiber.rb
@@ -4,6 +4,7 @@ require 'continuation'
require_relative './envutil'
class TestFiber < Test::Unit::TestCase
+if false
def test_normal
f = Fiber.current
assert_equal(:ok2,
@@ -280,3 +281,44 @@ class TestFiber < Test::Unit::TestCase
end
end
+ def invoke_rec script, vm_stack_size, machine_stack_size, use_length = true
+ env = {}
+ env['RUBY_FIBER_VM_STACK_SIZE'] = vm_stack_size.to_s if vm_stack_size
+ env['RUBY_FIBER_MACHINE_STACK_SIZE'] = machine_stack_size.to_s if machine_stack_size
+ out, = EnvUtil.invoke_ruby([env, '-e', script], '', true, true)
+ use_length ? out.length : out
+ end
+
+ def test_stack_size
+ h_default = eval(invoke_rec('p RubyVM::DEFAULT_PARAMS', nil, nil, false))
+ h_0 = eval(invoke_rec('p RubyVM::DEFAULT_PARAMS', 0, 0, false))
+ h_large = eval(invoke_rec('p RubyVM::DEFAULT_PARAMS', 1024 * 1024 * 10, 1024 * 1024 * 10, false))
+
+ assert(h_default[:fiber_vm_stack_size] > h_0[:fiber_vm_stack_size])
+ assert(h_default[:fiber_vm_stack_size] < h_large[:fiber_vm_stack_size])
+ assert(h_default[:fiber_machine_stack_size] >= h_0[:fiber_machine_stack_size])
+ assert(h_default[:fiber_machine_stack_size] <= h_large[:fiber_machine_stack_size])
+
+ # check VM machine stack size
+ script = 'def rec; print "."; rec; end; Fiber.new{rec}.resume'
+ size_default = invoke_rec script, nil, nil
+ assert(size_default > 0, size_default.to_s)
+ size_0 = invoke_rec script, 0, nil
+ assert(size_default > size_0, [size_default, size_0].inspect)
+ size_large = invoke_rec script, 1024 * 1024 * 10, nil
+ assert(size_default < size_large, [size_default, size_large].inspect)
+
+ return if /mswin|mingw/ =~ RUBY_PLATFORM
+
+ # check machine stack size
+ # Note that machine stack size may not change size (depend on OSs)
+ script = 'def rec; print "."; 1.times{1.times{1.times{rec}}}; end; Fiber.new{rec}.resume'
+ vm_stack_size = 1024 * 1024
+ size_default = invoke_rec script, vm_stack_size, nil
+ size_0 = invoke_rec script, vm_stack_size, 0
+ assert(size_default >= size_0, [size_default, size_0].inspect)
+ size_large = invoke_rec script, vm_stack_size, 1024 * 1024 * 10
+ assert(size_default <= size_large, [size_default, size_large].inspect)
+ end
+end
+
diff --git a/test/ruby/test_thread.rb b/test/ruby/test_thread.rb
index f8b2868c08..1bc4410f6d 100644
--- a/test/ruby/test_thread.rb
+++ b/test/ruby/test_thread.rb
@@ -870,4 +870,44 @@ Thread.new(Thread.current) {|mth|
th.kill if th
end
end
+
+ def invoke_rec script, vm_stack_size, machine_stack_size, use_length = true
+ env = {}
+ env['RUBY_THREAD_VM_STACK_SIZE'] = vm_stack_size.to_s if vm_stack_size
+ env['RUBY_THREAD_MACHINE_STACK_SIZE'] = machine_stack_size.to_s if machine_stack_size
+ out, = EnvUtil.invoke_ruby([env, '-e', script], '', true, true)
+ use_length ? out.length : out
+ end
+
+ def test_stack_size
+ h_default = eval(invoke_rec('p RubyVM::DEFAULT_PARAMS', nil, nil, false))
+ h_0 = eval(invoke_rec('p RubyVM::DEFAULT_PARAMS', 0, 0, false))
+ h_large = eval(invoke_rec('p RubyVM::DEFAULT_PARAMS', 1024 * 1024 * 10, 1024 * 1024 * 10, false))
+
+ assert(h_default[:thread_vm_stack_size] > h_0[:thread_vm_stack_size])
+ assert(h_default[:thread_vm_stack_size] < h_large[:thread_vm_stack_size])
+ assert(h_default[:thread_machine_stack_size] >= h_0[:thread_machine_stack_size])
+ assert(h_default[:thread_machine_stack_size] <= h_large[:thread_machine_stack_size])
+
+ # check VM machine stack size
+ script = 'def rec; print "."; rec; end; rec'
+ size_default = invoke_rec script, nil, nil
+ assert(size_default > 0, size_default.to_s)
+ size_0 = invoke_rec script, 0, nil
+ assert(size_default > size_0, [size_default, size_0].inspect)
+ size_large = invoke_rec script, 1024 * 1024 * 10, nil
+ assert(size_default < size_large, [size_default, size_large].inspect)
+
+ return if /mswin|mingw/ =~ RUBY_PLATFORM
+
+ # check machine stack size
+ # Note that machine stack size may not change size (depend on OSs)
+ script = 'def rec; print "."; 1.times{1.times{1.times{rec}}}; end; Thread.new{rec}.join'
+ vm_stack_size = 1024 * 1024
+ size_default = invoke_rec script, vm_stack_size, nil
+ size_0 = invoke_rec script, vm_stack_size, 0
+ assert(size_default >= size_0, [size_default, size_0].inspect)
+ size_large = invoke_rec script, vm_stack_size, 1024 * 1024 * 10
+ assert(size_default <= size_large, [size_default, size_large].inspect)
+ end
end