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: 0c99acc61627
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 6db28942331d
Choose a head ref
  • 2 commits
  • 4 files changed
  • 1 contributor

Commits on Aug 29, 2015

  1. Copy the full SHA
    b9e23d3 View commit details
  2. Copy the full SHA
    6db2894 View commit details
Showing with 78 additions and 13 deletions.
  1. +12 −0 core/src/main/java/org/jruby/Main.java
  2. +1 −0 core/src/main/java/org/jruby/util/cli/Options.java
  3. +32 −13 test/truffle/memory/minimum-heap.rb
  4. +33 −0 test/truffle/memory/total-allocation.rb
12 changes: 12 additions & 0 deletions core/src/main/java/org/jruby/Main.java
Original file line number Diff line number Diff line change
@@ -222,6 +222,7 @@ public static void main(String[] args) {
}

printTruffleTimeMetric("after-main");
printTruffleMemoryMetric();
}

public Status run(String[] args) {
@@ -543,6 +544,17 @@ public static void printTruffleTimeMetric(String id) {
}
}

private static void printTruffleMemoryMetric() {
System.gc();

try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}

System.err.printf("allocated %d%n", ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getUsed());
}

private final RubyInstanceConfig config;
}

1 change: 1 addition & 0 deletions core/src/main/java/org/jruby/util/cli/Options.java
Original file line number Diff line number Diff line change
@@ -150,6 +150,7 @@ public class Options {
public static final Option<Boolean> TRUFFLE_DISPATCH_METHODMISSING_ALWAYS_INLINED = bool(TRUFFLE, "truffle.call.method_missing_always_inlined", true, "Always inline #method_missing call targets.");

public static final Option<Boolean> TRUFFLE_METRICS_TIME = bool(TRUFFLE, "truffle.metrics.time", false, "Print the time at various stages of VM operation.");
public static final Option<Boolean> TRUFFLE_METRICS_MEMORY_USED_ON_EXIT = bool(TRUFFLE, "truffle.metrics.memory_used_on_exit", false, "Print the size of heap memory in use on exit.");

public static final Option<Boolean> NATIVE_ENABLED = bool(NATIVE, "native.enabled", true, "Enable/disable native code, including POSIX features and C exts.");
public static final Option<Boolean> NATIVE_VERBOSE = bool(NATIVE, "native.verbose", false, "Enable verbose logging of native extension loading.");
45 changes: 32 additions & 13 deletions test/truffle/memory/minimum-heap.rb
Original file line number Diff line number Diff line change
@@ -13,28 +13,47 @@
# For example:
# $ ruby test/truffle/memory/minimum-heap.rb bin/jruby "-X+T -e 'puts 14'"

tolerance = 5
max_iterations = 100
COMMAND = ARGV[0]
OPTIONS = ARGV[1]

lower = 0
upper = 4 * 1024
iterations = 0
TOLERANCE = 1
UPPER_FACTOR = 4

while upper - lower > tolerance && iterations < max_iterations
mid = lower + (upper - lower) / 2
def can_run(heap)
print "trying #{heap} MB... "

print "trying #{mid}m... "
can_run = !(`#{ARGV[0]} -J-Xmx#{mid}m #{ARGV[1]} 2>&1`.include? 'GC overhead limit exceeded')
output = `#{COMMAND} -J-Xmx#{heap}m #{OPTIONS} 2>&1`
can_run = !output.include?('OutOfMemoryError')

if can_run
puts "yes"
upper = mid
else
puts "no"
end

can_run
end

puts "looking for an upper bound..."

lower = 0
upper = 1

while !can_run(upper)
lower = upper
upper *= UPPER_FACTOR
end

puts "binary search between #{lower} and #{upper} MB..."

while upper - lower > TOLERANCE
mid = lower + (upper - lower) / 2

if can_run(mid)
upper = mid
else
lower = mid
end

iterations += 1
end

puts "minimum heap: #{upper}m"
puts "minimum heap: #{upper} MB"
33 changes: 33 additions & 0 deletions test/truffle/memory/total-allocation.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env ruby
# Copyright (c) 2015 Oracle and/or its affiliates. All rights reserved. This
# code is released under a tri EPL/GPL/LGPL license. You can use it,
# redistribute it and/or modify it under the terms of the:
#
# Eclipse Public License version 1.0
# GNU General Public License version 2
# GNU Lesser General Public License version 2.1

# Calculates the total memory allocated to run a program.

# For example:
# $ bin/jruby -X+T -Xtruffle.metrics.memory_used_on_exit=true -J-verbose:gc -e 'puts 14' 2>&1 | ruby test/truffle/memory/total-allocation.rb

on_exit = nil
allocated = 0

ARGF.each do |line|
if line =~ /(\d+)K->(\d+)K/
before = $1.to_i * 1024
after = $2.to_i * 1024
collected = before - after
allocated += collected
elsif line =~ /^allocated (\d+)$/
on_exit = $1.to_i
else
puts line
end
end

allocated += on_exit

puts "#{allocated/1024/1024} MB"