Skip to content

Commit

Permalink
JSON dumping and I have no idea what Emacs is doing...these buffers a…
Browse files Browse the repository at this point in the history
…re saved
  • Loading branch information
enebo committed Jul 28, 2014
1 parent 7fa4d67 commit dfc52aa
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 192 deletions.
5 changes: 5 additions & 0 deletions bin/alienist
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,10 @@ File.open(filename, "rb") do |io|
require 'alienist/console'

IRB.start_session binding
else # Assume dumping for now
require 'alienist/dumper/ruby_json_dumper'

# FIXME Hook up io explicitly
Alienist::Dumper::RubyJSONDumper.dump(snapshot)
end
end
111 changes: 0 additions & 111 deletions lib/alienist/#reader.rb#

This file was deleted.

1 change: 0 additions & 1 deletion lib/alienist/.#reader.rb

This file was deleted.

37 changes: 37 additions & 0 deletions lib/alienist/dumper/ruby_json_dumper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
module Alienist
module Dumper
class RubyJSONDumper
# Hmmm I don't want to do this by hand but I need to not dump my
# entire POROs
def self.dump(snapshot)
puts "{"
snapshot.ruby_classes.each do |name, cls|
dump_pair 'name', name, ' '
dump_pair 'size', cls.size, ' ', ''
dump_pair 'id', cls.id, ' ', ''
puts " \"instances\": {"
cls.ruby_instances.each do |obj|
dump_pair 'id', obj.id, ' ', ''
dump_pair 'size', obj.size, ' ', ''
dump_pair 'data', dump_type_data(snapshot, name, obj), ' '
end
puts " },"
end
puts "}"
end

def self.dump_type_data(snapshot, name, obj)
case name
when 'Fixnum'
obj.field('value').value
else
""
end
end

def self.dump_pair(key, value, indent, del=%q{"})
puts "#{indent}\"#{key}\": #{del}#{value}#{del},"
end
end
end
end
66 changes: 0 additions & 66 deletions lib/alienist/model/java/#java_class.rb#

This file was deleted.

1 change: 0 additions & 1 deletion lib/alienist/model/java/.#java_class.rb

This file was deleted.

2 changes: 0 additions & 2 deletions lib/alienist/model/java/java_class.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ module Java
class JavaClass
attr_reader :instances, :subclasses, :fields, :static_fields, :name
attr_reader :total_field_count, :field_values, :super_class
attr_reader :ruby_instances

def initialize(snapshot, id, name, super_id, classloader_id, signers_id,
protection_domain_id, instance_size)
Expand All @@ -16,7 +15,6 @@ def initialize(snapshot, id, name, super_id, classloader_id, signers_id,
@subclasses = []
@fields = []
@static_fields = {}
@ruby_instances = []
end

# We resolve after all classes have been added to the system
Expand Down
6 changes: 3 additions & 3 deletions lib/alienist/model/java/java_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ module Alienist
module Model
module Java
class JavaObject
attr_reader :id, :name, :signature, :cls
attr_reader :id, :name, :signature, :cls, :size
attr_accessor :field_values, :display_value
attr_reader :ruby_instances # FIXME:

def initialize(id, serial, class_id, field_io_offset)
@id, @serial, @class_id = id, serial, class_id
def initialize(id, serial, class_id, field_io_offset, size)
@id, @serial, @class_id, @size = id, serial, class_id, size
@field_io_offset = field_io_offset
@ruby_instances = []
end
Expand Down
7 changes: 4 additions & 3 deletions lib/alienist/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def initialize(io, snapshot, debug=0)
def parse
version = read_version_header
@io.identifier_size = @io.read_int
@snapshot.minimum_object_size = 2 * @io.identifier_size # Don't know the 2 ids?
creation_date = @io.read_date
@snapshot.parsing(self) do
loop do
Expand Down Expand Up @@ -172,16 +173,16 @@ def read_primitive_array_dump

def read_instance_dump
read_section do |id, serial|
class_id, bytes_following = @io.read_id, @io.read_int
class_id, length = @io.read_id, @io.read_int

value_offset = @io.pos
# We skip field values until whole system loaded so that
# all classes can be resolved. we save position for that
# later parsing into the memory image for that object.
@io.skip_bytes bytes_following, "instance_dump"
@io.skip_bytes length, "instance_dump"

puts "+I 0x#{id.to_s(16)} 0x#{class_id.to_s(16)}" if @debug > 10
@snapshot.add_instance id, serial, class_id, value_offset
@snapshot.add_instance id, serial, class_id, value_offset, length
end
end

Expand Down
4 changes: 3 additions & 1 deletion lib/alienist/snapshot/base_snapshot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ module Snapshot
# This is using a base-class for this because the parser would be incapable
# of executing if the snapshot did not have these methods.
class BaseSnapshot
attr_accessor :minimum_object_size

def initialize
@class_name_from_id = {} # {id -> class_name}
@class_name_from_serial = {} # {serial_no -> class_name}
Expand Down Expand Up @@ -85,7 +87,7 @@ def add_class(id, name, super_id, classloader_id, signers_id,
def add_field(class_ref, name_id, type)
end

def add_instance(id, serial, class_id, field_io_offset)
def add_instance(id, serial, class_id, field_io_offset, length)
end

def add_object_array(id, serial, length, class_id, field_io_offset)
Expand Down
15 changes: 11 additions & 4 deletions lib/alienist/snapshot/memory_snapshot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,12 @@ def initialize
@instances = {} # id -> java_object
@ruby_class_from_name = {} # name -> ruby_class
@name_from_ruby_class = {} # ruby_class -> name
@ruby_class_from_id = {} # id -> ruby_class
end

def pretty_display?(obj)
false
end


def create_pretty_display(obj)
end

Expand Down Expand Up @@ -59,8 +57,9 @@ def add_field(cls, name_id, signature)
cls.fields << JavaField.new(name_id, name, signature)
end

def add_instance(id, serial, class_id, field_io_offset)
object = JavaObject.new id, serial, class_id, field_io_offset
def add_instance(id, serial, class_id, field_io_offset, length)
object = JavaObject.new id, serial, class_id, field_io_offset,
length + minimum_object_size
@instances[id] = object

object
Expand All @@ -82,6 +81,10 @@ def add_static_field(cls, name_id, signature, value)
cls.static_fields[name] = JavaStatic.new field, value
end

def ruby_name2class(name)
@ruby_class_from_name[name]
end

def name2class(name)
@class_from_name[name]
end
Expand All @@ -90,6 +93,10 @@ def id2class(id)
@class_from_id[id]
end

def ruby_classes
@ruby_class_from_name
end

def classes
@class_from_id.values
end
Expand Down

0 comments on commit dfc52aa

Please sign in to comment.