FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
jruby/src/org/jruby/RubyInstanceConfig.java at serializable_procs · MSNexploder/jruby · GitHub
MSNexploder
/
jruby
Public
forked from
jruby/jruby
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
jruby
/
src
/
org
/
jruby
/
RubyInstanceConfig.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
1563 lines (1365 loc) · 62.9 KB
Breadcrumbs
jruby
/
src
/
org
/
jruby
/
RubyInstanceConfig.java
Copy path
File metadata and controls
1563 lines (1365 loc) · 62.9 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/***** 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) 2007-2010 Nick Sieger <nicksieger@gmail.com>
* Copyright (C) 2009 Joseph LaFata <joe@quibb.org>
*
* 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
;
import
java
.
io
.
BufferedInputStream
;
import
java
.
io
.
BufferedReader
;
import
java
.
io
.
ByteArrayInputStream
;
import
java
.
io
.
File
;
import
java
.
io
.
FileInputStream
;
import
java
.
io
.
FileReader
;
import
java
.
io
.
IOException
;
import
java
.
io
.
InputStream
;
import
java
.
io
.
PrintStream
;
import
java
.
net
.
URI
;
import
java
.
net
.
URL
;
import
java
.
util
.
ArrayList
;
import
java
.
util
.
HashMap
;
import
java
.
util
.
HashSet
;
import
java
.
util
.
List
;
import
java
.
util
.
Map
;
import
java
.
util
.
Set
;
import
java
.
util
.
jar
.
JarEntry
;
import
java
.
util
.
jar
.
JarFile
;
import
org
.
jruby
.
ast
.
executable
.
Script
;
import
org
.
jruby
.
compiler
.
ASTCompiler
;
import
org
.
jruby
.
compiler
.
ASTCompiler19
;
import
org
.
jruby
.
exceptions
.
MainExitException
;
import
org
.
jruby
.
runtime
.
Constants
;
import
org
.
jruby
.
runtime
.
load
.
LoadService
;
import
org
.
jruby
.
runtime
.
load
.
LoadService19
;
import
org
.
jruby
.
util
.
ClassCache
;
import
org
.
jruby
.
util
.
JRubyFile
;
import
org
.
jruby
.
util
.
KCode
;
import
org
.
jruby
.
util
.
NormalizedFile
;
import
org
.
jruby
.
util
.
SafePropertyAccessor
;
import
org
.
objectweb
.
asm
.
Opcodes
;
public
class
RubyInstanceConfig
{
/**
* The max count of active methods eligible for JIT-compilation.
*/
public
static
final
int
JIT_MAX_METHODS_LIMIT
=
4096
;
/**
* The max size of JIT-compiled methods (full class size) allowed.
*/
public
static
final
int
JIT_MAX_SIZE_LIMIT
=
10000
;
/**
* The JIT threshold to the specified method invocation count.
*/
public
static
final
int
JIT_THRESHOLD
=
50
;
/** The version to use for generated classes. Set to current JVM version by default */
public
static
final
int
JAVA_VERSION
;
/**
* Default size for chained compilation.
*/
public
static
final
int
CHAINED_COMPILE_LINE_COUNT_DEFAULT
=
500
;
/**
* The number of lines at which a method, class, or block body is split into
* chained methods (to dodge 64k method-size limit in JVM).
*/
public
static
final
int
CHAINED_COMPILE_LINE_COUNT
=
SafePropertyAccessor
.
getInt
(
"jruby.compile.chainsize"
,
CHAINED_COMPILE_LINE_COUNT_DEFAULT
);
/**
* Indicates whether the script must be extracted from script source
*/
private
boolean
xFlag
;
public
boolean
hasShebangLine
() {
return
hasShebangLine
;
}
public
void
setHasShebangLine
(
boolean
hasShebangLine
) {
this
.
hasShebangLine
=
hasShebangLine
;
}
/**
* Indicates whether the script has a shebang line or not
*/
private
boolean
hasShebangLine
;
public
boolean
isxFlag
() {
return
xFlag
;
}
public
enum
CompileMode
{
JIT
,
FORCE
,
OFF
;
public
boolean
shouldPrecompileCLI
() {
switch
(
this
) {
case
JIT
:
case
FORCE
:
if
(
DYNOPT_COMPILE_ENABLED
) {
// don't precompile the CLI script in dynopt mode
return
false
;
}
return
true
;
}
return
false
;
}
public
boolean
shouldJIT
() {
switch
(
this
) {
case
JIT
:
case
FORCE
:
return
true
;
}
return
false
;
}
public
boolean
shouldPrecompileAll
() {
return
this
==
FORCE
;
}
}
private
InputStream
input
=
System
.
in
;
private
PrintStream
output
=
System
.
out
;
private
PrintStream
error
=
System
.
err
;
private
Profile
profile
=
Profile
.
DEFAULT
;
private
boolean
objectSpaceEnabled
=
SafePropertyAccessor
.
getBoolean
(
"jruby.objectspace.enabled"
,
false
);
private
CompileMode
compileMode
=
CompileMode
.
JIT
;
private
boolean
runRubyInProcess
=
true
;
private
String
currentDirectory
;
private
Map
environment
;
private
String
[]
argv
= {};
private
final
boolean
jitLogging
;
private
final
boolean
jitLoggingVerbose
;
private
int
jitLogEvery
;
private
int
jitThreshold
;
private
int
jitMax
;
private
int
jitMaxSize
;
private
final
boolean
samplingEnabled
;
private
CompatVersion
compatVersion
;
private
ClassLoader
contextLoader
=
Thread
.
currentThread
().
getContextClassLoader
();
private
ClassLoader
loader
=
contextLoader
==
null
?
RubyInstanceConfig
.
class
.
getClassLoader
() :
contextLoader
;
private
ClassCache
<
Script
>
classCache
;
// from CommandlineParser
private
List
<
String
>
loadPaths
=
new
ArrayList
<
String
>();
private
Set
<
String
>
excludedMethods
=
new
HashSet
<
String
>();
private
StringBuffer
inlineScript
=
new
StringBuffer
();
private
boolean
hasInlineScript
=
false
;
private
String
scriptFileName
=
null
;
private
List
<
String
>
requiredLibraries
=
new
ArrayList
<
String
>();
private
boolean
benchmarking
=
false
;
private
boolean
argvGlobalsOn
=
false
;
private
boolean
assumeLoop
=
false
;
private
boolean
assumePrinting
=
false
;
private
Map
optionGlobals
=
new
HashMap
();
private
boolean
processLineEnds
=
false
;
private
boolean
split
=
false
;
// This property is a Boolean, to allow three values, so it can match MRI's nil, false and true
private
Boolean
verbose
=
Boolean
.
FALSE
;
private
boolean
debug
=
false
;
private
boolean
showVersion
=
false
;
private
boolean
showBytecode
=
false
;
private
boolean
showCopyright
=
false
;
private
boolean
endOfArguments
=
false
;
private
boolean
shouldRunInterpreter
=
true
;
private
boolean
shouldPrintUsage
=
false
;
private
boolean
shouldPrintProperties
=
false
;
private
KCode
kcode
=
KCode
.
NONE
;
private
String
recordSeparator
=
"
\n
"
;
private
boolean
shouldCheckSyntax
=
false
;
private
String
inputFieldSeparator
=
null
;
private
boolean
managementEnabled
=
false
;
private
String
inPlaceBackupExtension
=
null
;
private
boolean
parserDebug
=
false
;
private
String
threadDumpSignal
=
null
;
private
boolean
saveRbjFiles
=
false
;
private
int
safeLevel
=
0
;
private
String
jrubyHome
;
public
static
final
boolean
PEEPHOLE_OPTZ
=
SafePropertyAccessor
.
getBoolean
(
"jruby.compile.peephole"
,
true
);
public
static
boolean
DYNOPT_COMPILE_ENABLED
=
SafePropertyAccessor
.
getBoolean
(
"jruby.compile.dynopt"
);
public
static
boolean
NOGUARDS_COMPILE_ENABLED
=
SafePropertyAccessor
.
getBoolean
(
"jruby.compile.noguards"
);
public
static
boolean
FASTEST_COMPILE_ENABLED
=
SafePropertyAccessor
.
getBoolean
(
"jruby.compile.fastest"
);
public
static
boolean
FASTOPS_COMPILE_ENABLED
=
FASTEST_COMPILE_ENABLED
||
SafePropertyAccessor
.
getBoolean
(
"jruby.compile.fastops"
);
public
static
boolean
FRAMELESS_COMPILE_ENABLED
=
FASTEST_COMPILE_ENABLED
||
SafePropertyAccessor
.
getBoolean
(
"jruby.compile.frameless"
);
public
static
boolean
POSITIONLESS_COMPILE_ENABLED
=
FASTEST_COMPILE_ENABLED
||
SafePropertyAccessor
.
getBoolean
(
"jruby.compile.positionless"
);
public
static
boolean
THREADLESS_COMPILE_ENABLED
=
FASTEST_COMPILE_ENABLED
||
SafePropertyAccessor
.
getBoolean
(
"jruby.compile.threadless"
);
public
static
boolean
FASTCASE_COMPILE_ENABLED
=
SafePropertyAccessor
.
getBoolean
(
"jruby.compile.fastcase"
);
public
static
boolean
FASTSEND_COMPILE_ENABLED
=
SafePropertyAccessor
.
getBoolean
(
"jruby.compile.fastsend"
);
public
static
boolean
LAZYHANDLES_COMPILE
=
SafePropertyAccessor
.
getBoolean
(
"jruby.compile.lazyHandles"
,
false
);
public
static
boolean
INLINE_DYNCALL_ENABLED
=
FASTEST_COMPILE_ENABLED
||
SafePropertyAccessor
.
getBoolean
(
"jruby.compile.inlineDyncalls"
);
public
static
final
boolean
FORK_ENABLED
=
SafePropertyAccessor
.
getBoolean
(
"jruby.fork.enabled"
);
public
static
final
boolean
POOLING_ENABLED
=
SafePropertyAccessor
.
getBoolean
(
"jruby.thread.pool.enabled"
);
public
static
final
int
POOL_MAX
=
SafePropertyAccessor
.
getInt
(
"jruby.thread.pool.max"
,
Integer
.
MAX_VALUE
);
public
static
final
int
POOL_MIN
=
SafePropertyAccessor
.
getInt
(
"jruby.thread.pool.min"
,
0
);
public
static
final
int
POOL_TTL
=
SafePropertyAccessor
.
getInt
(
"jruby.thread.pool.ttl"
,
60
);
public
static
final
boolean
NATIVE_NET_PROTOCOL
=
SafePropertyAccessor
.
getBoolean
(
"jruby.native.net.protocol"
,
false
);
public
static
boolean
FULL_TRACE_ENABLED
=
SafePropertyAccessor
.
getBoolean
(
"jruby.debug.fullTrace"
,
false
);
public
static
final
String
COMPILE_EXCLUDE
=
SafePropertyAccessor
.
getProperty
(
"jruby.jit.exclude"
);
public
static
boolean
nativeEnabled
=
true
;
public
static
final
boolean
REIFY_RUBY_CLASSES
=
SafePropertyAccessor
.
getBoolean
(
"jruby.reify.classes"
,
false
);
public
static
final
boolean
USE_GENERATED_HANDLES
=
SafePropertyAccessor
.
getBoolean
(
"jruby.java.handles"
,
false
);
public
static
final
boolean
DEBUG_LOAD_SERVICE
=
SafePropertyAccessor
.
getBoolean
(
"jruby.debug.loadService"
,
false
);
public
static
final
boolean
DEBUG_LOAD_TIMINGS
=
SafePropertyAccessor
.
getBoolean
(
"jruby.debug.loadService.timing"
,
false
);
public
static
final
boolean
DEBUG_LAUNCHING
=
SafePropertyAccessor
.
getBoolean
(
"jruby.debug.launch"
,
false
);
public
static
final
boolean
JUMPS_HAVE_BACKTRACE
=
SafePropertyAccessor
.
getBoolean
(
"jruby.jump.backtrace"
,
false
);
public
static
final
boolean
JIT_CACHE_ENABLED
=
SafePropertyAccessor
.
getBoolean
(
"jruby.jit.cache"
,
true
);
public
static
final
String
JIT_CODE_CACHE
=
SafePropertyAccessor
.
getProperty
(
"jruby.jit.codeCache"
,
null
);
public
static
final
boolean
REFLECTED_HANDLES
=
SafePropertyAccessor
.
getBoolean
(
"jruby.reflected.handles"
,
false
)
||
SafePropertyAccessor
.
getBoolean
(
"jruby.reflection"
,
false
);
public
static
final
boolean
NO_UNWRAP_PROCESS_STREAMS
=
SafePropertyAccessor
.
getBoolean
(
"jruby.process.noUnwrap"
,
false
);
public
static
final
boolean
INTERFACES_USE_PROXY
=
SafePropertyAccessor
.
getBoolean
(
"jruby.interfaces.useProxy"
);
public
static
final
boolean
JIT_LOADING_DEBUG
=
SafePropertyAccessor
.
getBoolean
(
"jruby.jit.debug"
,
false
);
public
static
interface
LoadServiceCreator
{
LoadService
create
(
Ruby
runtime
);
LoadServiceCreator
DEFAULT
=
new
LoadServiceCreator
() {
public
LoadService
create
(
Ruby
runtime
) {
if
(
runtime
.
is1_9
()) {
return
new
LoadService19
(
runtime
);
}
return
new
LoadService
(
runtime
);
}
};
}
private
LoadServiceCreator
creator
=
LoadServiceCreator
.
DEFAULT
;
static
{
String
specVersion
=
null
;
try
{
specVersion
=
System
.
getProperty
(
"jruby.bytecode.version"
);
if
(
specVersion
==
null
) {
specVersion
=
System
.
getProperty
(
"java.specification.version"
);
}
if
(
System
.
getProperty
(
"jruby.native.enabled"
) !=
null
) {
nativeEnabled
=
Boolean
.
getBoolean
(
"jruby.native.enabled"
);
}
}
catch
(
SecurityException
se
) {
nativeEnabled
=
false
;
specVersion
=
"1.5"
;
}
if
(
specVersion
.
equals
(
"1.5"
)) {
JAVA_VERSION
=
Opcodes
.
V1_5
;
}
else
{
JAVA_VERSION
=
Opcodes
.
V1_6
;
}
}
public
int
characterIndex
=
0
;
public
RubyInstanceConfig
(
RubyInstanceConfig
parentConfig
) {
setCurrentDirectory
(
parentConfig
.
getCurrentDirectory
());
samplingEnabled
=
parentConfig
.
samplingEnabled
;
compatVersion
=
parentConfig
.
compatVersion
;
compileMode
=
parentConfig
.
getCompileMode
();
jitLogging
=
parentConfig
.
jitLogging
;
jitLoggingVerbose
=
parentConfig
.
jitLoggingVerbose
;
jitLogEvery
=
parentConfig
.
jitLogEvery
;
jitThreshold
=
parentConfig
.
jitThreshold
;
jitMax
=
parentConfig
.
jitMax
;
jitMaxSize
=
parentConfig
.
jitMaxSize
;
managementEnabled
=
parentConfig
.
managementEnabled
;
runRubyInProcess
=
parentConfig
.
runRubyInProcess
;
excludedMethods
=
parentConfig
.
excludedMethods
;
threadDumpSignal
=
parentConfig
.
threadDumpSignal
;
classCache
=
new
ClassCache
<
Script
>(
loader
,
jitMax
);
}
public
RubyInstanceConfig
() {
setCurrentDirectory
(
Ruby
.
isSecurityRestricted
() ?
"/"
:
JRubyFile
.
getFileProperty
(
"user.dir"
));
samplingEnabled
=
SafePropertyAccessor
.
getBoolean
(
"jruby.sampling.enabled"
,
false
);
String
compatString
=
SafePropertyAccessor
.
getProperty
(
"jruby.compat.version"
,
"RUBY1_8"
);
if
(
compatString
.
equalsIgnoreCase
(
"RUBY1_8"
)) {
setCompatVersion
(
CompatVersion
.
RUBY1_8
);
}
else
if
(
compatString
.
equalsIgnoreCase
(
"RUBY1_9"
)) {
setCompatVersion
(
CompatVersion
.
RUBY1_9
);
}
else
{
error
.
println
(
"Compatibility version `"
+
compatString
+
"' invalid; use RUBY1_8 or RUBY1_9. Using RUBY1_8."
);
setCompatVersion
(
CompatVersion
.
RUBY1_8
);
}
if
(
Ruby
.
isSecurityRestricted
()) {
compileMode
=
CompileMode
.
OFF
;
jitLogging
=
false
;
jitLoggingVerbose
=
false
;
jitLogEvery
=
0
;
jitThreshold
= -
1
;
jitMax
=
0
;
jitMaxSize
= -
1
;
managementEnabled
=
false
;
}
else
{
String
threshold
=
SafePropertyAccessor
.
getProperty
(
"jruby.jit.threshold"
);
String
max
=
SafePropertyAccessor
.
getProperty
(
"jruby.jit.max"
);
String
maxSize
=
SafePropertyAccessor
.
getProperty
(
"jruby.jit.maxsize"
);
if
(
COMPILE_EXCLUDE
!=
null
) {
String
[]
elements
=
COMPILE_EXCLUDE
.
split
(
","
);
for
(
String
element
:
elements
)
excludedMethods
.
add
(
element
);
}
managementEnabled
=
SafePropertyAccessor
.
getBoolean
(
"jruby.management.enabled"
,
false
);
runRubyInProcess
=
SafePropertyAccessor
.
getBoolean
(
"jruby.launch.inproc"
,
true
);
boolean
jitProperty
=
SafePropertyAccessor
.
getProperty
(
"jruby.jit.enabled"
) !=
null
;
if
(
jitProperty
) {
error
.
print
(
"jruby.jit.enabled property is deprecated; use jruby.compile.mode=(OFF|JIT|FORCE) for -C, default, and +C flags"
);
compileMode
=
SafePropertyAccessor
.
getBoolean
(
"jruby.jit.enabled"
) ?
CompileMode
.
JIT
:
CompileMode
.
OFF
;
}
else
{
String
jitModeProperty
=
SafePropertyAccessor
.
getProperty
(
"jruby.compile.mode"
,
"JIT"
);
if
(
jitModeProperty
.
equals
(
"OFF"
)) {
compileMode
=
CompileMode
.
OFF
;
}
else
if
(
jitModeProperty
.
equals
(
"JIT"
)) {
compileMode
=
CompileMode
.
JIT
;
}
else
if
(
jitModeProperty
.
equals
(
"FORCE"
)) {
compileMode
=
CompileMode
.
FORCE
;
}
else
{
error
.
print
(
"jruby.compile.mode property must be OFF, JIT, FORCE, or unset; defaulting to JIT"
);
compileMode
=
CompileMode
.
JIT
;
}
}
jitLogging
=
SafePropertyAccessor
.
getBoolean
(
"jruby.jit.logging"
);
jitLoggingVerbose
=
SafePropertyAccessor
.
getBoolean
(
"jruby.jit.logging.verbose"
);
String
logEvery
=
SafePropertyAccessor
.
getProperty
(
"jruby.jit.logEvery"
);
jitLogEvery
=
logEvery
==
null
?
0
:
Integer
.
parseInt
(
logEvery
);
jitThreshold
=
threshold
==
null
?
JIT_THRESHOLD
:
Integer
.
parseInt
(
threshold
);
jitMax
=
max
==
null
?
JIT_MAX_METHODS_LIMIT
:
Integer
.
parseInt
(
max
);
jitMaxSize
=
maxSize
==
null
?
JIT_MAX_SIZE_LIMIT
:
Integer
.
parseInt
(
maxSize
);
}
// default ClassCache using jitMax as a soft upper bound
classCache
=
new
ClassCache
<
Script
>(
loader
,
jitMax
);
threadDumpSignal
=
SafePropertyAccessor
.
getProperty
(
"jruby.thread.dump.signal"
,
"USR2"
);
if
(
FORK_ENABLED
) {
error
.
print
(
"WARNING: fork is highly unlikely to be safe or stable on the JVM. Have fun!
\n
"
);
}
}
public
LoadServiceCreator
getLoadServiceCreator
() {
return
creator
;
}
public
void
setLoadServiceCreator
(
LoadServiceCreator
creator
) {
this
.
creator
=
creator
;
}
public
LoadService
createLoadService
(
Ruby
runtime
) {
return
this
.
creator
.
create
(
runtime
);
}
public
String
getBasicUsageHelp
() {
StringBuilder
sb
=
new
StringBuilder
();
sb
.
append
(
"Usage: jruby [switches] [--] [programfile] [arguments]
\n
"
)
.
append
(
" -0[octal] specify record separator (
\\
0, if no argument)
\n
"
)
.
append
(
" -a autosplit mode with -n or -p (splits $_ into $F)
\n
"
)
.
append
(
" -b benchmark mode, times the script execution
\n
"
)
.
append
(
" -c check syntax only
\n
"
)
.
append
(
" -Cdirectory cd to directory, before executing your script
\n
"
)
.
append
(
" -d set debugging flags (set $DEBUG to true)
\n
"
)
.
append
(
" -e 'command' one line of script. Several -e's allowed. Omit [programfile]
\n
"
)
.
append
(
" -Fpattern split() pattern for autosplit (-a)
\n
"
)
.
append
(
" -i[extension] edit ARGV files in place (make backup if extension supplied)
\n
"
)
.
append
(
" -Idirectory specify $LOAD_PATH directory (may be used more than once)
\n
"
)
.
append
(
" -J[java option] pass an option on to the JVM (e.g. -J-Xmx512m)
\n
"
)
.
append
(
" use --properties to list JRuby properties
\n
"
)
.
append
(
" run 'java -help' for a list of other Java options
\n
"
)
.
append
(
" -Kkcode specifies code-set (e.g. -Ku for Unicode, -Ke for EUC and -Ks for SJIS)
\n
"
)
.
append
(
" -l enable line ending processing
\n
"
)
.
append
(
" -n assume 'while gets(); ... end' loop around your script
\n
"
)
.
append
(
" -p assume loop like -n but print line also like sed
\n
"
)
.
append
(
" -rlibrary require the library, before executing your script
\n
"
)
.
append
(
" -s enable some switch parsing for switches after script name
\n
"
)
.
append
(
" -S look for the script in bin or using PATH environment variable
\n
"
)
.
append
(
" -T[level] turn on tainting checks
\n
"
)
.
append
(
" -v print version number, then turn on verbose mode
\n
"
)
.
append
(
" -w turn warnings on for your script
\n
"
)
.
append
(
" -W[level] set warning level; 0=silence, 1=medium, 2=verbose (default)
\n
"
)
.
append
(
" -x[directory] strip off text before #!ruby line and perhaps cd to directory
\n
"
)
.
append
(
" -X[option] enable extended option (omit option to list)
\n
"
)
.
append
(
" -y enable parsing debug output
\n
"
)
.
append
(
" --copyright print the copyright
\n
"
)
.
append
(
" --debug sets the execution mode most suitable for debugger functionality
\n
"
)
.
append
(
" --jdb runs JRuby process under JDB
\n
"
)
.
append
(
" --properties List all configuration Java properties (pass -J-Dproperty=value)
\n
"
)
.
append
(
" --sample run with profiling using the JVM's sampling profiler
\n
"
)
.
append
(
" --client use the non-optimizing
\"
client
\"
JVM (improves startup; default)
\n
"
)
.
append
(
" --server use the optimizing
\"
server
\"
JVM (improves perf)
\n
"
)
.
append
(
" --manage enable remote JMX management and monitoring of the VM and JRuby
\n
"
)
.
append
(
" --headless do not launch a GUI window, no matter what
\n
"
)
.
append
(
" --1.8 specify Ruby 1.8.x compatibility (default)
\n
"
)
.
append
(
" --1.9 specify Ruby 1.9.x compatibility
\n
"
)
.
append
(
" --bytecode show the JVM bytecode produced by compiling specified code
\n
"
)
.
append
(
" --version print the version
\n
"
);
return
sb
.
toString
();
}
public
String
getExtendedHelp
() {
StringBuilder
sb
=
new
StringBuilder
();
sb
.
append
(
"These flags are for extended JRuby options.
\n
"
)
.
append
(
"Specify them by passing -X<option>
\n
"
)
.
append
(
" -O run with ObjectSpace disabled (default; improves performance)
\n
"
)
.
append
(
" +O run with ObjectSpace enabled (reduces performance)
\n
"
)
.
append
(
" -C disable all compilation
\n
"
)
.
append
(
" +C force compilation of all scripts before they are run (except eval)
\n
"
);
return
sb
.
toString
();
}
public
String
getPropertyHelp
() {
StringBuilder
sb
=
new
StringBuilder
();
sb
.
append
(
"These properties can be used to alter runtime behavior for perf or compatibility.
\n
"
)
.
append
(
"Specify them by passing -J-D<property>=<value>
\n
"
)
.
append
(
"
\n
COMPILER SETTINGS:
\n
"
)
.
append
(
" jruby.compile.mode=JIT|FORCE|OFF
\n
"
)
.
append
(
" Set compilation mode. JIT is default; FORCE compiles all, OFF disables
\n
"
)
.
append
(
" jruby.compile.fastest=true|false
\n
"
)
.
append
(
" (EXPERIMENTAL) Turn on all experimental compiler optimizations
\n
"
)
.
append
(
" jruby.compile.frameless=true|false
\n
"
)
.
append
(
" (EXPERIMENTAL) Turn on frameless compilation where possible
\n
"
)
.
append
(
" jruby.compile.positionless=true|false
\n
"
)
.
append
(
" (EXPERIMENTAL) Turn on compilation that avoids updating Ruby position info. Default is false
\n
"
)
.
append
(
" jruby.compile.threadless=true|false
\n
"
)
.
append
(
" (EXPERIMENTAL) Turn on compilation without polling for
\"
unsafe
\"
thread events. Default is false
\n
"
)
.
append
(
" jruby.compile.fastops=true|false
\n
"
)
.
append
(
" (EXPERIMENTAL) Turn on fast operators for Fixnum. Default is false
\n
"
)
.
append
(
" jruby.compile.fastcase=true|false
\n
"
)
.
append
(
" (EXPERIMENTAL) Turn on fast case/when for all-Fixnum whens. Default is false
\n
"
)
.
append
(
" jruby.compile.chainsize=<line count>
\n
"
)
.
append
(
" Set the number of lines at which compiled bodies are
\"
chained
\"
. Default is "
+
CHAINED_COMPILE_LINE_COUNT_DEFAULT
+
"
\n
"
)
.
append
(
" jruby.compile.lazyHandles=true|false
\n
"
)
.
append
(
" Generate method bindings (handles) for compiled methods lazily. Default is false.
\n
"
)
.
append
(
" jruby.compile.peephole=true|false
\n
"
)
.
append
(
" Enable or disable peephole optimizations. Default is true (on).
\n
"
)
.
append
(
"
\n
JIT SETTINGS:
\n
"
)
.
append
(
" jruby.jit.threshold=<invocation count>
\n
"
)
.
append
(
" Set the JIT threshold to the specified method invocation count. Default is "
+
JIT_THRESHOLD
+
".
\n
"
)
.
append
(
" jruby.jit.max=<method count>
\n
"
)
.
append
(
" Set the max count of active methods eligible for JIT-compilation.
\n
"
)
.
append
(
" Default is "
+
JIT_MAX_METHODS_LIMIT
+
" per runtime. A value of 0 disables JIT, -1 disables max.
\n
"
)
.
append
(
" jruby.jit.maxsize=<jitted method size (full .class)>
\n
"
)
.
append
(
" Set the maximum full-class byte size allowed for jitted methods. Default is "
+
JIT_MAX_SIZE_LIMIT
+
".
\n
"
)
.
append
(
" jruby.jit.logging=true|false
\n
"
)
.
append
(
" Enable JIT logging (reports successful compilation). Default is false
\n
"
)
.
append
(
" jruby.jit.logging.verbose=true|false
\n
"
)
.
append
(
" Enable verbose JIT logging (reports failed compilation). Default is false
\n
"
)
.
append
(
" jruby.jit.logEvery=<method count>
\n
"
)
.
append
(
" Log a message every n methods JIT compiled. Default is 0 (off).
\n
"
)
.
append
(
" jruby.jit.exclude=<ClsOrMod,ClsOrMod::method_name,-::method_name>
\n
"
)
.
append
(
" Exclude methods from JIT by class/module short name, c/m::method_name,
\n
"
)
.
append
(
" or -::method_name for anon/singleton classes/modules. Comma-delimited.
\n
"
)
.
append
(
" jruby.jit.cache=true|false
\n
"
)
.
append
(
" Cache jitted method in-memory bodies across runtimes and loads. Default is true.
\n
"
)
.
append
(
" jruby.jit.codeCache=<dir>
\n
"
)
.
append
(
" Save jitted methods to <dir> as they're compiled, for future runs.
\n
"
)
.
append
(
"
\n
NATIVE SUPPORT:
\n
"
)
.
append
(
" jruby.native.enabled=true|false
\n
"
)
.
append
(
" Enable/disable native extensions (like JNA for non-Java APIs; Default is true
\n
"
)
.
append
(
" (This affects all JRuby instances in a given JVM)
\n
"
)
.
append
(
" jruby.native.verbose=true|false
\n
"
)
.
append
(
" Enable verbose logging of native extension loading. Default is false.
\n
"
)
.
append
(
" jruby.fork.enabled=true|false
\n
"
)
.
append
(
" (EXPERIMENTAL, maybe dangerous) Enable fork(2) on platforms that support it.
\n
"
)
.
append
(
"
\n
THREAD POOLING:
\n
"
)
.
append
(
" jruby.thread.pool.enabled=true|false
\n
"
)
.
append
(
" Enable reuse of native backing threads via a thread pool. Default is false.
\n
"
)
.
append
(
" jruby.thread.pool.min=<min thread count>
\n
"
)
.
append
(
" The minimum number of threads to keep alive in the pool. Default is 0.
\n
"
)
.
append
(
" jruby.thread.pool.max=<max thread count>
\n
"
)
.
append
(
" The maximum number of threads to allow in the pool. Default is unlimited.
\n
"
)
.
append
(
" jruby.thread.pool.ttl=<time to live, in seconds>
\n
"
)
.
append
(
" The maximum number of seconds to keep alive an idle thread. Default is 60.
\n
"
)
.
append
(
"
\n
MISCELLANY:
\n
"
)
.
append
(
" jruby.compat.version=RUBY1_8|RUBY1_9
\n
"
)
.
append
(
" Specify the major Ruby version to be compatible with; Default is RUBY1_8
\n
"
)
.
append
(
" jruby.objectspace.enabled=true|false
\n
"
)
.
append
(
" Enable or disable ObjectSpace.each_object (default is disabled)
\n
"
)
.
append
(
" jruby.launch.inproc=true|false
\n
"
)
.
append
(
" Set in-process launching of e.g. system('ruby ...'). Default is true
\n
"
)
.
append
(
" jruby.bytecode.version=1.5|1.6
\n
"
)
.
append
(
" Set bytecode version for JRuby to generate. Default is current JVM version.
\n
"
)
.
append
(
" jruby.management.enabled=true|false
\n
"
)
.
append
(
" Set whether JMX management is enabled. Default is false.
\n
"
)
.
append
(
" jruby.jump.backtrace=true|false
\n
"
)
.
append
(
" Make non-local flow jumps generate backtraces. Default is false.
\n
"
)
.
append
(
" jruby.process.noUnwrap=true|false
\n
"
)
.
append
(
" Do not unwrap process streams (IBM Java 6 issue). Default is false.
\n
"
)
.
append
(
" jruby.interfaces.useProxy=true|false
\n
"
)
.
append
(
" Use java.lang.reflect.Proxy for interface impl. Default is false.
\n
"
)
.
append
(
"
\n
DEBUGGING/LOGGING:
\n
"
)
.
append
(
" jruby.debug.loadService=true|false
\n
"
)
.
append
(
" LoadService logging
\n
"
)
.
append
(
" jruby.debug.loadService.timing=true|false
\n
"
)
.
append
(
" Print load timings for each require'd library. Default is false.
\n
"
)
.
append
(
" jruby.debug.launch=true|false
\n
"
)
.
append
(
" ShellLauncher logging
\n
"
)
.
append
(
" jruby.debug.fullTrace=true|false
\n
"
)
.
append
(
" Set whether full traces are enabled (c-call/c-return). Default is false.
\n
"
)
.
append
(
" jruby.reflected.handles=true|false
\n
"
)
.
append
(
" Use reflection for binding methods, not generated bytecode. Default is false.
\n
"
);
return
sb
.
toString
();
}
public
String
getVersionString
() {
String
ver
=
null
;
String
patchDelimeter
=
null
;
int
patchlevel
=
0
;
switch
(
getCompatVersion
()) {
case
RUBY1_8
:
ver
=
Constants
.
RUBY_VERSION
;
patchlevel
=
Constants
.
RUBY_PATCHLEVEL
;
patchDelimeter
=
" patchlevel "
;
break
;
case
RUBY1_9
:
ver
=
Constants
.
RUBY1_9_VERSION
;
patchlevel
=
Constants
.
RUBY1_9_PATCHLEVEL
;
patchDelimeter
=
" trunk "
;
break
;
}
String
fullVersion
=
String
.
format
(
"jruby %s (ruby %s%s%d) (%s %s) (%s %s) [%s-java]"
,
Constants
.
VERSION
,
ver
,
patchDelimeter
,
patchlevel
,
Constants
.
COMPILE_DATE
,
Constants
.
REVISION
,
System
.
getProperty
(
"java.vm.name"
),
System
.
getProperty
(
"java.version"
),
SafePropertyAccessor
.
getProperty
(
"os.arch"
,
"unknown"
)
);
return
fullVersion
;
}
public
String
getCopyrightString
() {
return
"JRuby - Copyright (C) 2001-2010 The JRuby Community (and contribs)"
;
}
public
void
processArguments
(
String
[]
arguments
) {
new
ArgumentProcessor
(
arguments
).
processArguments
();
tryProcessArgumentsWithRubyopts
(
arguments
);
}
private
void
tryProcessArgumentsWithRubyopts
(
String
[]
arguments
) {
try
{
String
rubyopt
=
System
.
getenv
(
"RUBYOPT"
);
if
(
rubyopt
==
null
&&
environment
!=
null
&&
environment
.
containsKey
(
"RUBYOPT"
)) {
rubyopt
=
environment
.
get
(
"RUBYOPT"
).
toString
();
}
if
(
rubyopt
!=
null
) {
String
[]
rubyoptArgs
=
rubyopt
.
split
(
"
\\
s+"
);
for
(
int
i
=
0
;
i
<
rubyoptArgs
.
length
;
i
++) {
if
(!
rubyoptArgs
[
i
].
startsWith
(
"-"
)) {
rubyoptArgs
[
i
] =
"-"
+
rubyoptArgs
[
i
];
}
}
new
ArgumentProcessor
(
rubyoptArgs
,
false
).
processArguments
();
}
}
catch
(
SecurityException
se
) {
// ignore and do nothing
}
}
public
CompileMode
getCompileMode
() {
return
compileMode
;
}
public
void
setCompileMode
(
CompileMode
compileMode
) {
this
.
compileMode
=
compileMode
;
}
public
boolean
isJitLogging
() {
return
jitLogging
;
}
public
boolean
isJitLoggingVerbose
() {
return
jitLoggingVerbose
;
}
public
int
getJitLogEvery
() {
return
jitLogEvery
;
}
public
void
setJitLogEvery
(
int
jitLogEvery
) {
this
.
jitLogEvery
=
jitLogEvery
;
}
public
boolean
isSamplingEnabled
() {
return
samplingEnabled
;
}
public
int
getJitThreshold
() {
return
jitThreshold
;
}
public
void
setJitThreshold
(
int
jitThreshold
) {
this
.
jitThreshold
=
jitThreshold
;
}
public
int
getJitMax
() {
return
jitMax
;
}
public
void
setJitMax
(
int
jitMax
) {
this
.
jitMax
=
jitMax
;
}
public
int
getJitMaxSize
() {
return
jitMaxSize
;
}
public
void
setJitMaxSize
(
int
jitMaxSize
) {
this
.
jitMaxSize
=
jitMaxSize
;
}
public
boolean
isRunRubyInProcess
() {
return
runRubyInProcess
;
}
public
void
setRunRubyInProcess
(
boolean
flag
) {
this
.
runRubyInProcess
=
flag
;
}
public
void
setInput
(
InputStream
newInput
) {
input
=
newInput
;
}
public
InputStream
getInput
() {
return
input
;
}
public
CompatVersion
getCompatVersion
() {
return
compatVersion
;
}
public
void
setCompatVersion
(
CompatVersion
compatVersion
) {
// Until we get a little more solid on 1.9 support we will only run interpreted mode
if
(
compatVersion
==
CompatVersion
.
RUBY1_9
)
compileMode
=
CompileMode
.
OFF
;
if
(
compatVersion
==
null
)
compatVersion
=
CompatVersion
.
RUBY1_8
;
this
.
compatVersion
=
compatVersion
;
}
public
void
setOutput
(
PrintStream
newOutput
) {
output
=
newOutput
;
}
public
PrintStream
getOutput
() {
return
output
;
}
public
void
setError
(
PrintStream
newError
) {
error
=
newError
;
}
public
PrintStream
getError
() {
return
error
;
}
public
void
setCurrentDirectory
(
String
newCurrentDirectory
) {
currentDirectory
=
newCurrentDirectory
;
}
public
String
getCurrentDirectory
() {
return
currentDirectory
;
}
public
void
setProfile
(
Profile
newProfile
) {
profile
=
newProfile
;
}
public
Profile
getProfile
() {
return
profile
;
}
public
void
setObjectSpaceEnabled
(
boolean
newObjectSpaceEnabled
) {
objectSpaceEnabled
=
newObjectSpaceEnabled
;
}
public
boolean
isObjectSpaceEnabled
() {
return
objectSpaceEnabled
;
}
public
void
setEnvironment
(
Map
newEnvironment
) {
environment
=
newEnvironment
;
}
public
Map
getEnvironment
() {
return
environment
;
}
public
ClassLoader
getLoader
() {
return
loader
;
}
public
void
setLoader
(
ClassLoader
loader
) {
// Setting the loader needs to reset the class cache
if
(
this
.
loader
!=
loader
) {
this
.
classCache
=
new
ClassCache
<
Script
>(
loader
,
this
.
classCache
.
getMax
());
}
this
.
loader
=
loader
;
}
public
String
[]
getArgv
() {
return
argv
;
}
public
void
setArgv
(
String
[]
argv
) {
this
.
argv
=
argv
;
}
public
String
getJRubyHome
() {
if
(
jrubyHome
==
null
) {
// try the normal property first
if
(!
Ruby
.
isSecurityRestricted
()) {
jrubyHome
=
SafePropertyAccessor
.
getProperty
(
"jruby.home"
);
}
if
(
jrubyHome
!=
null
) {
// verify it if it's there
jrubyHome
=
verifyHome
(
jrubyHome
);
}
else
{
try
{
// try loading from classloader resources
URI
jrubyHomeURI
=
getClass
().
getResource
(
"/META-INF/jruby.home"
).
toURI
();
String
scheme
=
jrubyHomeURI
.
getScheme
();
String
path
=
jrubyHomeURI
.
getSchemeSpecificPart
();
if
(
"jar"
.
equals
(
scheme
) &&
path
.
startsWith
(
"file:"
)) {
// special case for jar:file (most typical case)
jrubyHome
=
path
;
}
else
{
jrubyHome
=
"classpath:/META-INF/jruby.home"
;
return
jrubyHome
;
}
}
catch
(
Exception
e
) {}
if
(
jrubyHome
!=
null
) {
// verify it if it's there
jrubyHome
=
verifyHome
(
jrubyHome
);
}
else
{
// otherwise fall back on system temp location
jrubyHome
=
SafePropertyAccessor
.
getProperty
(
"java.io.tmpdir"
);
}
}
}
return
jrubyHome
;
}
public
void
setJRubyHome
(
String
home
) {
jrubyHome
=
verifyHome
(
home
);
}
// We require the home directory to be absolute
private
String
verifyHome
(
String
home
) {
if
(
home
.
equals
(
"."
)) {
home
=
SafePropertyAccessor
.
getProperty
(
"user.dir"
);
}
if
(
home
.
startsWith
(
"cp:"
)) {
home
=
home
.
substring
(
3
);
}
else
if
(!
home
.
startsWith
(
"file:"
) && !
home
.
startsWith
(
"classpath:"
)) {
NormalizedFile
f
=
new
NormalizedFile
(
home
);
if
(!
f
.
isAbsolute
()) {
home
=
f
.
getAbsolutePath
();
}
if
(!
f
.
exists
()) {
System
.
err
.
println
(
"Warning: JRuby home
\"
"
+
f
+
"
\"
does not exist, using "
+
SafePropertyAccessor
.
getProperty
(
"java.io.tmpdir"
));
return
System
.
getProperty
(
"java.io.tmpdir"
);
}
}
return
home
;
}
private
class
ArgumentProcessor
{
private
String
[]
arguments
;
private
int
argumentIndex
=
0
;
private
boolean
processArgv
;
public
ArgumentProcessor
(
String
[]
arguments
) {
this
(
arguments
,
true
);
}
public
ArgumentProcessor
(
String
[]
arguments
,
boolean
processArgv
) {
this
.
arguments
=
arguments
;
this
.
processArgv
=
processArgv
;
}
public
void
processArguments
() {
while
(
argumentIndex
<
arguments
.
length
&&
isInterpreterArgument
(
arguments
[
argumentIndex
])) {
processArgument
();
argumentIndex
++;
}
if
(!
hasInlineScript
&&
scriptFileName
==
null
) {
if
(
argumentIndex
<
arguments
.
length
) {
setScriptFileName
(
arguments
[
argumentIndex
]);
//consume the file name
argumentIndex
++;
}
}
if
(
processArgv
)
processArgv
();
}
private
void
processArgv
() {
List
<
String
>
arglist
=
new
ArrayList
<
String
>();
for
(;
argumentIndex
<
arguments
.
length
;
argumentIndex
++) {
String
arg
=
arguments
[
argumentIndex
];
if
(
argvGlobalsOn
&&
arg
.
startsWith
(
"-"
)) {
arg
=
arg
.
substring
(
1
);
if
(
arg
.
indexOf
(
'='
) >
0
) {
String
[]
keyvalue
=
arg
.
split
(
"="
,
2
);
optionGlobals
.
put
(
keyvalue
[
0
],
keyvalue
[
1
]);
}
else
{
optionGlobals
.
put
(
arg
,
null
);
}
}
else
{
argvGlobalsOn
=
false
;
arglist
.
add
(
arg
);
}
}
// Remaining arguments are for the script itself
for
(
String
arg
:
argv
)
arglist
.
add
(
arg
);
argv
=
arglist
.
toArray
(
new
String
[
arglist
.
size
()]);
}
private
boolean
isInterpreterArgument
(
String
argument
) {
return
argument
.
length
() >
0
&& (
argument
.
charAt
(
0
) ==
'-'
||
argument
.
charAt
(
0
) ==
'+'
) && !
endOfArguments
;
}
private
String
getArgumentError
(
String
additionalError
) {
return
"jruby: invalid argument
\n
"
+
additionalError
+
"
\n
"
;
}
private
void
processArgument
() {
String
argument
=
arguments
[
argumentIndex
];
FOR
:
for
(
characterIndex
=
1
;
characterIndex
<
argument
.
length
();
characterIndex
++) {
switch
(
argument
.
charAt
(
characterIndex
)) {
case
'0'
: {
String
temp
=
grabOptionalValue
();
if
(
null
==
temp
) {
recordSeparator
=
"
\u0000
"
;
}
else
if
(
temp
.
equals
(
"0"
)) {
recordSeparator
=
"
\n
\n
"
;
}
else
if
(
temp
.
equals
(
"777"
)) {
recordSeparator
=
"
\uFFFF
"
;
// Specify something that can't separate
}
else
{
try
{
int
val
=
Integer
.
parseInt
(
temp
,
8
);
recordSeparator
=
""
+ (
char
)
val
;
}
catch
(
Exception
e
) {
MainExitException
mee
=
new
MainExitException
(
1
,
getArgumentError
(
" -0 must be followed by either 0, 777, or a valid octal value"
));
mee
.
setUsageError
(
true
);
throw
mee
;
}
}
break
FOR
;
}
case
'a'
:
split
=
true
;
break
;
case
'b'
:
benchmarking
=
true
;
break
;
case
'c'
:
shouldCheckSyntax
=
true
;
break
;
case
'C'
:
try
{
String
saved
=
grabValue
(
getArgumentError
(
" -C must be followed by a directory expression"
));
File
base
=
new
File
(
currentDirectory
);
File
newDir
=
new
File
(
saved
);
if
(
newDir
.
isAbsolute
()) {
currentDirectory
=
newDir
.
getCanonicalPath
();
}
else
{
currentDirectory
=
new
File
(
base
,
newDir
.
getPath
()).
getCanonicalPath
();
}
if
(!(
new
File
(
currentDirectory
).
isDirectory
())) {
MainExitException
mee
=
new
MainExitException
(
1
,
"jruby: Can't chdir to "
+
saved
+
" (fatal)"
);
throw
mee
;
}
}
catch
(
IOException
e
) {
MainExitException
mee
=
new
MainExitException
(
1
,
getArgumentError
(
" -C must be followed by a valid directory"
));
throw
mee
;
}
break
FOR
;
case
'd'
:
debug
=
true
;
verbose
=
Boolean
.
TRUE
;
break
;
case
'e'
:
inlineScript
.
append
(
grabValue
(
getArgumentError
(
" -e must be followed by an expression to evaluate"
)));
inlineScript
.
append
(
'\n'
);
hasInlineScript
=
true
;
break
FOR
;
case
'F'
:
inputFieldSeparator
=
grabValue
(
getArgumentError
(
" -F must be followed by a pattern for input field separation"
));
break
FOR
;
case
'h'
:
shouldPrintUsage
=
true
;
shouldRunInterpreter
=
false
;
break
;
case
'i'
:
inPlaceBackupExtension
=
grabOptionalValue
();
if
(
inPlaceBackupExtension
==
null
)
inPlaceBackupExtension
=
""
;
break
FOR
;
case
'I'
:
String
s
=
grabValue
(
getArgumentError
(
"-I must be followed by a directory name to add to lib path"
));
String
[]
ls
=
s
.
split
(
java
.
io
.
File
.
pathSeparator
);
for
(
int
i
=
0
;
i
<
ls
.
length
;
i
++) {
View remainder of file in raw view
Back
|
FazBrowse Home
|
New Git URL