jrjackson 0.0.7 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,2 +1,9 @@
1
- source :rubygems
1
+ # A sample Gemfile
2
+ source "https://rubygems.org"
3
+
4
+ group :development do
5
+ gem 'gson', '>= 0.6'
6
+ gem 'json', '~> 1.7'
7
+ end
8
+
2
9
  gemspec
data/README.md ADDED
@@ -0,0 +1,59 @@
1
+ LICENSE applicable to this library:
2
+
3
+ Apache License 2.0 see http://www.apache.org/licenses/LICENSE-2.0
4
+
5
+ Jrjackson:
6
+
7
+ a jruby library wrapping the JAVA jackson jars
8
+
9
+ Version: 0.0.9
10
+
11
+ NOTE: Smile support has been temporarily dropped
12
+
13
+ The code has been refactored to use almost all Java.
14
+
15
+ There is shortly to be a MultiJson adapter added for JrJackson
16
+
17
+ provides:
18
+
19
+ ```
20
+ JrJackson::Json.load(str, options) -> hash like object
21
+ aliased as parse
22
+ JrJackson::Json.dump(obj) -> json string
23
+ aliased as generate
24
+ ```
25
+
26
+ By default the load method will return Ruby objects (Hashes have string keys).
27
+ The options hash respects two symbol keys
28
+ :symbolize_keys
29
+ Will return symbol keys in hashes
30
+ :raw
31
+ Will return JRuby wrapped java objects that quack like ruby objects
32
+ This is the fastest option
33
+
34
+ Behind the scenes there are three Ruby sub modules of the JrJackson module
35
+ ```
36
+ JrJackson::Str
37
+ JrJackson::Sym
38
+ JrJackson::Raw
39
+
40
+ These all have the same method signatures - they map to different java classes
41
+ that parse appropriately
42
+ ```
43
+
44
+ Credit to Chuck Remes for the benchmark and initial
45
+ investigation when the jruby, json gem and the jackson
46
+ libraries were young.
47
+
48
+ I compared Json (java) 1.7.7, Gson 0.6.1 and jackson 2.1.4 on jruby 1.7.3 and Java 7
49
+ ```
50
+ user system total real
51
+ ruby parse: 10.300000 0.020000 10.320000 ( 10.014000)
52
+ gson parse: 11.270000 0.010000 11.280000 ( 10.958000)
53
+ jrjackson parse raw: 4.840000 0.080000 4.920000 ( 3.767000)
54
+ jrjackson parse symbol keys: 5.130000 0.010000 5.140000 ( 4.975000)
55
+ jrjackson parse string keys: 7.370000 0.010000 7.380000 ( 7.223000)
56
+ ruby generate: 13.590000 0.050000 13.640000 ( 12.815000)
57
+ gson generate: 5.080000 0.010000 5.090000 ( 4.949000)
58
+ jackson generate: 4.640000 0.010000 4.650000 ( 4.560000)
59
+ ```
data/Rakefile CHANGED
@@ -1,159 +1,9 @@
1
- require 'date'
2
1
  require 'rspec/core/rake_task'
3
2
 
4
- #############################################################################
5
- #
6
- # Helper functions
7
- #
8
- #############################################################################
9
-
10
- def name
11
- @name ||= Dir['*.gemspec'].first.split('.').first
12
- end
13
-
14
- def version
15
- line = File.read("lib/#{name}/version.rb")[/^\s*VERSION\s*=\s*.*/]
16
- line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
17
- end
18
-
19
- def date
20
- Date.today.to_s
21
- end
22
-
23
- def rubyforge_project
24
- name
25
- end
26
-
27
- def gemspec_file
28
- "#{name}.gemspec"
29
- end
30
-
31
- def gem_file
32
- "#{name}-#{version}.gem"
33
- end
34
-
35
- def replace_header(head, header_name, provider = nil)
36
- if provider
37
- value = send(provider)
38
- else
39
- value = "'#{send(header_name)}'"
40
- end
41
-
42
- provider ||= header_name
43
- head.sub!(/(\.#{header_name}\s*= ).*/) { "#{$1}#{value}"}
44
- end
45
-
46
- def platform
47
- jruby? ? '-java' : ''
48
- end
49
-
50
- def platform_dependant_gem_file
51
- "#{name}-#{version}#{platform}.gem"
52
- end
53
-
54
- def platform_dependent_version
55
- "'#{version}#{platform}'"
56
- end
57
-
58
- def jruby?
59
- RUBY_PLATFORM.to_s == 'java'
60
- end
61
-
62
- def trim_array_ends array
63
- array.shift
64
- array.pop
65
- array
66
- end
67
-
68
- #############################################################################
69
- #
70
- # Custom tasks
71
- #
72
- #############################################################################
3
+ Bundler::GemHelper.install_tasks
73
4
 
74
5
  desc "Run benchmarks"
75
6
  task :benchmark do
76
7
  load 'benchmarking/benchmark.rb'
77
8
  end
78
9
 
79
- #############################################################################
80
- #
81
- # Packaging tasks
82
- #
83
- #############################################################################
84
-
85
- def built_gem
86
- @built_gem ||= Dir["#{name}*.gem"].first
87
- end
88
-
89
- desc "Create tag v#{platform_dependent_version} and build and push #{platform_dependant_gem_file} to Rubygems"
90
- task :release => :build do
91
- unless `git branch` =~ /^\* master$/
92
- puts "You must be on the master branch to release!"
93
- exit!
94
- end
95
-
96
- sh "git commit --allow-empty -a -m 'Release #{platform_dependent_version}'"
97
- sh "git tag v#{platform_dependent_version}"
98
- sh "git push origin master"
99
- sh "git push origin v#{platform_dependent_version}"
100
-
101
- command = "gem push pkg/#{platform_dependant_gem_file}"
102
-
103
- if jruby?
104
- puts "--------------------------------------------------------------------------------------"
105
- puts "can't push to rubygems using jruby at the moment, so switch to mri and run: #{command}"
106
- puts "--------------------------------------------------------------------------------------"
107
- else
108
- sh command
109
- end
110
- end
111
-
112
- desc "Build #{platform_dependant_gem_file} into the pkg directory"
113
- task :build => :gemspec do
114
- sh "mkdir -p pkg"
115
- sh "gem build #{gemspec_file}"
116
- sh "mv #{built_gem} pkg"
117
- end
118
-
119
- desc "Generate #{gemspec_file}"
120
- task :gemspec => :validate do
121
- # read spec file and split out manifest section
122
- spec = File.read(gemspec_file)
123
- head, manifest, tail = spec.split(" # = MANIFEST =\n")
124
-
125
- # replace name version and date
126
- replace_header(head, :name)
127
- replace_header(head, :version)
128
- replace_header(head, :date)
129
- #comment this out if your rubyforge_project has a different name
130
- #replace_header(head, :rubyforge_project)
131
-
132
- # determine file list from git ls-files
133
- files = `git ls-files`.
134
- split("\n").
135
- sort.
136
- reject { |file| file =~ /^\./ }.
137
- reject { |file| file =~ /^(rdoc|pkg)/ }.
138
- map { |file| " #{file}" }.
139
- join("\n")
140
-
141
- # piece file back together and write
142
- manifest = " s.files = %w[\n#{files}\n ]\n"
143
- spec = [head, manifest, tail].join(" # = MANIFEST =\n")
144
- File.open(gemspec_file, 'w') { |io| io.write(spec) }
145
- puts "Updated #{gemspec_file}"
146
- end
147
-
148
- desc "Validate #{gemspec_file}"
149
- task :validate do
150
- # libfiles = Dir['lib/*'] - ["lib/#{name}.rb", "lib/#{name}"]
151
- # unless libfiles.empty?
152
- # puts "Directory `lib` should only contain a `#{name}.rb` file and `#{name}` dir."
153
- # exit!
154
- # end
155
- unless Dir['VERSION*'].empty?
156
- puts "A `VERSION` file at root level violates Gem best practices."
157
- exit!
158
- end
159
- end
@@ -0,0 +1,434 @@
1
+ ################################################################################
2
+ # compiler settings
3
+ ################################################################################
4
+
5
+ # Set compilation mode. JIT = at runtime; FORCE = before execution.
6
+ # Options: [JIT, FORCE, OFF, OFFIR], Default: JIT.
7
+ # compile.mode=JIT
8
+ compile.mode=FORCE
9
+
10
+ # Dump to console all bytecode generated at runtime.
11
+ # Options: [true, false], Default: false.
12
+ compile.dump=false
13
+
14
+ # (EXPERIMENTAL) Turn on compilation without polling for "unsafe" thread events.
15
+ # Options: [true, false], Default: false.
16
+ compile.threadless=false
17
+
18
+ # Turn on fast operators for Fixnum and Float.
19
+ # Options: [true, false], Default: true.
20
+ compile.fastops=true
21
+
22
+ # Set the number of lines at which compiled bodies are "chained".
23
+ # Options: [Integer], Default: 500.
24
+ compile.chainsize=500
25
+
26
+ # Generate method bindings (handles) for compiled methods lazily.
27
+ # Options: [true, false], Default: false.
28
+ compile.lazyHandles=false
29
+
30
+ # Enable or disable peephole optimizations.
31
+ # Options: [true, false], Default: true.
32
+ compile.peephole=true
33
+
34
+ # Compile calls without guards, for experimentation.
35
+ # Options: [true, false], Default: false.
36
+ compile.noguards=false
37
+
38
+ # Compile with all "mostly harmless" compiler optimizations.
39
+ # Options: [true, false], Default: false.
40
+ compile.fastest=false
41
+
42
+ # Compile obj.__send__(<literal>, ...) as obj.<literal>(...).
43
+ # Options: [true, false], Default: false.
44
+ compile.fastsend=false
45
+
46
+ # Return true from multiple assignment instead of a new array.
47
+ # Options: [true, false], Default: false.
48
+ compile.fastMasgn=false
49
+
50
+ # Use invokedynamic for optimizing Ruby code
51
+ # Options: [true, false], Default: false.
52
+ # compile.invokedynamic=false
53
+ compile.invokedynamic=true
54
+
55
+
56
+ ################################################################################
57
+ # invokedynamic settings
58
+ ################################################################################
59
+
60
+ # Maximum call site failures after which to inline cache.
61
+ # Options: [Integer], Default: 1000.
62
+ invokedynamic.maxfail=1000
63
+
64
+ # Maximum polymorphism of PIC binding.
65
+ # Options: [Integer], Default: 2.
66
+ invokedynamic.maxpoly=2
67
+
68
+ # Log binding of invokedynamic call sites.
69
+ # Options: [true, false], Default: false.
70
+ invokedynamic.log.binding=false
71
+
72
+ # Log invokedynamic-based constant lookups.
73
+ # Options: [true, false], Default: false.
74
+ invokedynamic.log.constants=false
75
+
76
+ # Enable all possible uses of invokedynamic.
77
+ # Options: [true, false], Default: false.
78
+ invokedynamic.all=false
79
+
80
+ # Enable all safe (but maybe not fast) uses of invokedynamic.
81
+ # Options: [true, false], Default: false.
82
+ invokedynamic.safe=false
83
+
84
+ # Enable invokedynamic for method invocations.
85
+ # Options: [true, false], Default: true.
86
+ invokedynamic.invocation=true
87
+
88
+ # Use SwitchPoint for class modification guards on invocations.
89
+ # Options: [true, false], Default: true.
90
+ invokedynamic.invocation.switchpoint=true
91
+
92
+ # Also bind indirect method invokers to invokedynamic.
93
+ # Options: [true, false], Default: true.
94
+ invokedynamic.invocation.indirect=true
95
+
96
+ # Bind Ruby to Java invocations with invokedynamic.
97
+ # Options: [true, false], Default: true.
98
+ invokedynamic.invocation.java=true
99
+
100
+ # Bind Ruby attribue invocations directly to invokedynamic.
101
+ # Options: [true, false], Default: true.
102
+ invokedynamic.invocation.attr=true
103
+
104
+ # Bind Fixnum and Float math using optimized logic.
105
+ # Options: [true, false], Default: true.
106
+ invokedynamic.invocation.fastops=true
107
+
108
+ # Use invokedynamic to load cached values like literals and constants.
109
+ # Options: [true, false], Default: true.
110
+ invokedynamic.cache=true
111
+
112
+ # Use invokedynamic to load constants.
113
+ # Options: [true, false], Default: true.
114
+ invokedynamic.cache.constants=true
115
+
116
+ # Use invokedynamic to load literals.
117
+ # Options: [true, false], Default: true.
118
+ invokedynamic.cache.literals=true
119
+
120
+ # Use invokedynamic to get/set instance variables.
121
+ # Options: [true, false], Default: true.
122
+ invokedynamic.cache.ivars=true
123
+
124
+ # Use ClassValue to store class-specific data.
125
+ # Options: [true, false], Default: false.
126
+ invokedynamic.class.values=false
127
+
128
+
129
+ # ################################################################################
130
+ # # jit settings
131
+ # ################################################################################
132
+
133
+ # # Set the JIT threshold to the specified method invocation count.
134
+ # # Options: [Integer], Default: 50.
135
+ # jit.threshold=50
136
+
137
+ # # Set the max count of active methods eligible for JIT-compilation.
138
+ # # Options: [Integer], Default: 4096.
139
+ # jit.max=4096
140
+
141
+ # # Set the maximum full-class byte size allowed for jitted methods.
142
+ # # Options: [Integer], Default: 30000.
143
+ # jit.maxsize=30000
144
+
145
+ # # Enable JIT logging (reports successful compilation).
146
+ # # Options: [true, false], Default: false.
147
+ # jit.logging=false
148
+
149
+ # # Enable verbose JIT logging (reports failed compilation).
150
+ # # Options: [true, false], Default: false.
151
+ # jit.logging.verbose=false
152
+
153
+ # # Enable stdout dumping of JITed bytecode.
154
+ # # Options: [true, false], Default: false.
155
+ # jit.dumping=false
156
+
157
+ # # Log a message every n methods JIT compiled.
158
+ # # Options: [Integer], Default: 0.
159
+ # jit.logEvery=0
160
+
161
+ # # Exclude methods from JIT. Comma delimited.
162
+ # # Options: [ClsOrMod, ClsOrMod::method_name, -::method_name], Default: none.
163
+ # jit.exclude=none
164
+
165
+ # # Cache jitted method in-memory bodies across runtimes and loads.
166
+ # # Options: [true, false], Default: true.
167
+ # jit.cache=true
168
+
169
+ # # Save jitted methods to <dir> as they're compiled, for future runs.
170
+ # # Options: [dir], Default: null.
171
+ # jit.codeCache=null
172
+
173
+ # # Log loading of JITed bytecode.
174
+ # # Options: [true, false], Default: false.
175
+ # jit.debug=false
176
+
177
+ # # Run the JIT compiler in a background thread.
178
+ # # Options: [true, false], Default: true.
179
+ # jit.background=true
180
+
181
+
182
+ # ################################################################################
183
+ # # intermediate representation settings
184
+ # ################################################################################
185
+
186
+ # # Debug generation of JRuby IR.
187
+ # # Options: [true, false], Default: false.
188
+ # ir.debug=false
189
+
190
+ # # [EXPT]: Profile IR code during interpretation.
191
+ # # Options: [true, false], Default: false.
192
+ # ir.profile=false
193
+
194
+ # # Debug compilation of JRuby IR.
195
+ # # Options: [true, false], Default: false.
196
+ # ir.compiler.debug=false
197
+
198
+ # # Specify comma delimeted list of passes to run.
199
+ # # Options: [String], Default: null.
200
+ # ir.passes=null
201
+
202
+ # # Specify comma delimeted list of passes to run after inlining a method.
203
+ # # Options: [String], Default: null.
204
+ # ir.inline_passes=null
205
+
206
+
207
+ # ################################################################################
208
+ # # native settings
209
+ # ################################################################################
210
+
211
+ # # Enable/disable native code, including POSIX features and C exts.
212
+ # # Options: [true, false], Default: true.
213
+ # native.enabled=true
214
+
215
+ # # Enable verbose logging of native extension loading.
216
+ # # Options: [true, false], Default: false.
217
+ # native.verbose=false
218
+
219
+ # # Enable or disable C extension support.
220
+ # # Options: [true, false], Default: false.
221
+ # cext.enabled=false
222
+
223
+ # # Dump bytecode-generated FFI stubs to console.
224
+ # # Options: [true, false], Default: false.
225
+ # ffi.compile.dump=false
226
+
227
+ # # Number of FFI invocations before generating a bytecode stub.
228
+ # # Options: [Integer], Default: 100.
229
+ # ffi.compile.threshold=100
230
+
231
+ # # Use invokedynamic to bind FFI invocations.
232
+ # # Options: [true, false], Default: false.
233
+ # ffi.compile.invokedynamic=false
234
+
235
+
236
+ # ################################################################################
237
+ # # thread pooling settings
238
+ # ################################################################################
239
+
240
+ # # Enable reuse of native threads via a thread pool.
241
+ # # Options: [true, false], Default: false.
242
+ # thread.pool.enabled=false
243
+
244
+ # # The minimum number of threads to keep alive in the pool.
245
+ # # Options: [Integer], Default: 0.
246
+ # thread.pool.min=0
247
+
248
+ # # The maximum number of threads to allow in the pool.
249
+ # # Options: [Integer], Default: 2147483647.
250
+ # thread.pool.max=2147483647
251
+
252
+ # # The maximum number of seconds to keep alive an idle thread.
253
+ # # Options: [Integer], Default: 60.
254
+ # thread.pool.ttl=60
255
+
256
+
257
+ ################################################################################
258
+ # miscellaneous settings
259
+ ################################################################################
260
+
261
+ # Specify the major Ruby version to be compatible with.
262
+ # Options: [1.8, 1.9, 2.0], Default: 1.9.
263
+ compat.version=1.9
264
+
265
+ # Enable or disable ObjectSpace.each_object.
266
+ # Options: [true, false], Default: false.
267
+ objectspace.enabled=false
268
+
269
+ # Enable or disable SipHash for String hash function.
270
+ # Options: [true, false], Default: false.
271
+ siphash.enabled=false
272
+
273
+ # Set in-process launching of e.g. system('ruby ...').
274
+ # Options: [true, false], Default: false.
275
+ launch.inproc=false
276
+
277
+ # Specify the major Java bytecode version.
278
+ # Options: [1.5, 1.6, 1.7], Default: 1.7.
279
+ bytecode.version=1.7
280
+
281
+ # Set whether JMX management is enabled.
282
+ # Options: [true, false], Default: false.
283
+ management.enabled=false
284
+
285
+ # Make non-local flow jumps generate backtraces.
286
+ # Options: [true, false], Default: false.
287
+ jump.backtrace=false
288
+
289
+ # Do not unwrap process streams (issue on some recent JVMs).
290
+ # Options: [true, false], Default: false.
291
+ process.noUnwrap=false
292
+
293
+ # Before instantiation, stand up a real Java class for ever Ruby class.
294
+ # Options: [true, false], Default: false.
295
+ reify.classes=false
296
+
297
+ # Log errors during reification (reify.classes=true).
298
+ # Options: [true, false], Default: false.
299
+ reify.logErrors=false
300
+
301
+ # Use reflection for binding methods, not generated bytecode.
302
+ # Options: [true, false], Default: false.
303
+ reflected.handles=false
304
+
305
+ # Enable colorized backtraces.
306
+ # Options: [true, false], Default: false.
307
+ backtrace.color=false
308
+
309
+ # Set the style of exception backtraces.
310
+ # Options: [normal, raw, full, mri], Default: normal.
311
+ backtrace.style=normal
312
+
313
+ # Mask .java lines in Ruby backtraces.
314
+ # Options: [true, false], Default: false.
315
+ backtrace.mask=false
316
+
317
+ # Set the signal used for dumping thread stacks.
318
+ # Options: [USR1, USR2, etc], Default: USR2.
319
+ thread.dump.signal=USR2
320
+
321
+ # Use native impls for parts of net/protocol.
322
+ # Options: [true, false], Default: false.
323
+ native.net.protocol=false
324
+
325
+ # Use JVM coroutines for Fiber.
326
+ # Options: [true, false], Default: false.
327
+ fiber.coroutines=false
328
+
329
+ # Use a single global lock for requires.
330
+ # Options: [true, false], Default: false.
331
+ global.require.lock=false
332
+
333
+ # Do a true process-obliterating native exec for Kernel#exec.
334
+ # Options: [true, false], Default: true.
335
+ native.exec=true
336
+
337
+
338
+ # ################################################################################
339
+ # # debugging and logging settings
340
+ # ################################################################################
341
+
342
+ # # Log require/load file searches.
343
+ # # Options: [true, false], Default: false.
344
+ # debug.loadService=false
345
+
346
+ # # Log require/load parse+evaluate times.
347
+ # # Options: [true, false], Default: false.
348
+ # debug.loadService.timing=false
349
+
350
+ # # Log externally-launched processes.
351
+ # # Options: [true, false], Default: false.
352
+ # debug.launch=false
353
+
354
+ # # Set whether full traces are enabled (c-call/c-return).
355
+ # # Options: [true, false], Default: false.
356
+ # debug.fullTrace=false
357
+
358
+ # # Print which script is executed by '-S' flag.
359
+ # # Options: [true, false], Default: false.
360
+ # debug.scriptResolution=false
361
+
362
+ # # disables JRuby impl script loads and prints parse exceptions
363
+ # # Options: [true, false], Default: false.
364
+ # debug.parser=false
365
+
366
+ # # Generate backtraces for heavily-used Errno exceptions (EAGAIN).
367
+ # # Options: [true, false], Default: false.
368
+ # errno.backtrace=false
369
+
370
+ # # Log every time an exception is constructed.
371
+ # # Options: [true, false], Default: false.
372
+ # log.exceptions=false
373
+
374
+ # # Log every time an exception backtrace is generated.
375
+ # # Options: [true, false], Default: false.
376
+ # log.backtraces=false
377
+
378
+ # # Log every time a Kernel#caller backtrace is generated.
379
+ # # Options: [true, false], Default: false.
380
+ # log.callers=false
381
+
382
+ # # Log every time a built-in warning backtrace is generated.
383
+ # # Options: [true, false], Default: false.
384
+ # log.warnings=false
385
+
386
+ # # Use specified class for logging.
387
+ # # Options: [class name], Default: org.jruby.util.log.JavaUtilLoggingLogger.
388
+ # logger.class=org.jruby.util.log.JavaUtilLoggingLogger
389
+
390
+
391
+ # ################################################################################
392
+ # # java integration settings
393
+ # ################################################################################
394
+
395
+ # # Try to set inaccessible Java methods to be accessible.
396
+ # # Options: [true, false], Default: true.
397
+ # ji.setAccessible=true
398
+
399
+ # # Log whether setAccessible is working.
400
+ # # Options: [true, false], Default: false.
401
+ # ji.logCanSetAccessible=false
402
+
403
+ # # Allow Capitalized Java pacakge names.
404
+ # # Options: [true, false], Default: false.
405
+ # ji.upper.case.package.name.allowed=false
406
+
407
+ # # Use java.lang.reflect.Proxy for interface impl.
408
+ # # Options: [true, false], Default: false.
409
+ # interfaces.useProxy=false
410
+
411
+ # # Use generated handles instead of reflection for calling Java.
412
+ # # Options: [true, false], Default: false.
413
+ # java.handles=false
414
+
415
+ # # Extend Java classes without using a proxy object.
416
+ # # Options: [true, false], Default: false.
417
+ # ji.newStyleExtension=false
418
+
419
+ # # Cache Java object wrappers between calls.
420
+ # # Options: [true, false], Default: true.
421
+ # ji.objectProxyCache=true
422
+
423
+ # # Allow external envs to replace JI proxy class factory
424
+ # # Options: [String], Default: null.
425
+ # ji.proxyClassFactory=null
426
+
427
+
428
+ # ################################################################################
429
+ # # profiling settings
430
+ # ################################################################################
431
+
432
+ # # Maximum number of methods to consider for profiling.
433
+ # # Options: [Integer], Default: 100000.
434
+ # profile.max.methods=100000