-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmethod_desc.cc
3069 lines (3004 loc) · 92.6 KB
/
method_desc.cc
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
#ifdef VISUAL_CPP
#define snprintf _snprintf
#endif
#include "method_desc.hh"
void print_call_sequence(callee_desc* callee, int loop_id, int path_id)
{
if (callee != NULL) {
print_call_sequence((callee_desc*)callee->backtrace, loop_id, path_id);
callee->message(msg_loop, (void*)loop_id, (void*)path_id,
callee->method);
}
}
int method_desc::demangle_method_name(char* buf)
{
char* dst = buf;
const char* src = desc.as_asciz();
// TODO: assertion changes variable
assert(*src++ == '(');
dst += sprintf(dst, "%s.%s(", cls->name.as_asciz(), name.as_asciz());
int first_parameter = true;
while (*src != ')') {
if (!first_parameter) {
*dst++ = ',';
*dst++ = ' ';
}
first_parameter = false;
int indirect = 0;
while (*src == '[') {
indirect += 1;
src += 1;
}
switch (*src++) {
case 'I':
dst += sprintf(dst, "int");
break;
case 'S':
dst += sprintf(dst, "short");
break;
case 'D':
dst += sprintf(dst, "double");
break;
case 'J':
dst += sprintf(dst, "long");
break;
case 'F':
dst += sprintf(dst, "float");
break;
case 'B':
dst += sprintf(dst, "byte");
break;
case 'C':
dst += sprintf(dst, "char");
break;
case 'Z':
dst += sprintf(dst, "boolean");
break;
case 'L':
while (*src != ';') {
if (*src == '/') *dst++ = '.';
else *dst++ = *src;
src += 1;
}
src += 1;
}
while (indirect != 0) {
*dst++ = '[';
*dst++ = ']';
indirect -= 1;
}
}
*dst++ = ')';
*dst = 0;
return dst - buf;
}
void method_desc::check_invocations()
{
for (int i = 0; i < 32; i++) {
if (null_parameter_mask & unchecked_use_mask & (1 << i)) {
message_at(msg_null_param, cls->source_file, first_line, this, i);
}
}
}
bool method_desc::build_call_graph(method_desc* caller, callee_desc* callee,
int caller_attr)
{
callee->backtrace = caller;
for (overridden_method* ovr = overridden; ovr != NULL; ovr = ovr->next) {
ovr->method->build_call_graph(caller, callee, caller_attr);
}
if ((attr & m_synchronized) || (attr & m_sync_block)) {
if (!(caller_attr & callee_desc::i_self)) {
#ifdef DUMP_EDGES
char buf[2][MAX_MSG_LENGTH];
caller->demangle_method_name(buf[0]);
demangle_method_name(buf[1]);
printf("Call graph edge %s -> %s\n", buf[0], buf[1]);
#endif
graph_edge* edge = new graph_edge(vertex, caller, callee);
assert(caller->vertex != NULL);
caller->vertex->attach(edge);
}
return true;
} else if (!(attr & m_deadlock_free)) {
bool can_cause_deadlock = false;
for (callee = callees; callee != NULL; callee = callee->next) {
if (callee->backtrace != caller) {
can_cause_deadlock |=
callee->method->build_call_graph(caller, callee,
caller_attr&callee->attr);
}
}
if (!can_cause_deadlock) {
attr |= m_deadlock_free;
}
return can_cause_deadlock;
}
return false;
}
void method_desc::check_synchronization()
{
if (attr & m_concurrent) {
for (callee_desc* callee = callees; callee != NULL;
callee = callee->next)
{
if (!(callee->method->attr & (m_serialized|m_synchronized)) &&
!(callee->method->cls->attr & class_desc::cl_system) &&
!(callee->attr & (callee_desc::i_self
|callee_desc::i_synchronized)) &&
(strstr(callee->method->name.as_asciz(), "init>") == NULL) )
{
callee->message(msg_concurrent_call, callee->method);
}
}
for (access_desc* paccessor = accessors; paccessor != NULL;
paccessor = paccessor->next)
{
if (!(paccessor->field->attr
& (field_desc::f_volatile|field_desc::f_final
|field_desc::f_serialized))
&& !(paccessor->field->cls->attr & class_desc::cl_system)
&& !(paccessor->attr&(access_desc::a_new|access_desc::a_self)))
{
paccessor->message(msg_concurrent_access,
&paccessor->field->name, paccessor->field->cls);
}
}
}
}
void method_desc::find_access_dependencies()
{
for (callee_desc* callee = callees; callee != NULL; callee = callee->next){
class_desc* caller_class = callee->method->accessor;
if (caller_class == NULL) {
callee->method->accessor = cls;
} else if (!cls->in_relationship_with(caller_class)) {
// Method is called from two unrelated classes, so if this
// two methods are executed concurrently we will have access conflict
callee->method->attr &= ~m_serialized;
}
if ((!(attr & m_static) && (callee->method->attr & m_static))
|| !(attr & m_concurrent))
{
//
// If caller is instance method and callee - static method
// of the class, or caller is not included in concurrent closure
// (and so it can be executed in main thread of control), then
// any invocation of callee method from concurrent thread can
// cause concurrent execution of this method. If no method
// from concurrent closure invoke this method, then
// "m_serialized" attribute will not checked at all, otherwise
// message about concurrent invocation of non-synchronized method
// will be reported.
//
callee->method->attr &= ~m_serialized;
}
}
for (access_desc* paccessor = accessors; paccessor != NULL;
paccessor = paccessor->next)
{
class_desc* accessor_class = paccessor->field->accessor;
if (accessor_class == NULL) {
paccessor->field->accessor = cls;
} else if (!cls->in_relationship_with(accessor_class)) {
paccessor->field->attr &= ~field_desc::f_serialized;
}
if ((attr & m_static) && (paccessor->field->attr & field_desc::f_static)
&& cls->isa(paccessor->field->cls))
{
paccessor->attr |= access_desc::a_self;
}
if ((!(attr & m_static)
&& (paccessor->field->attr & field_desc::f_static))
|| !(attr & m_concurrent))
{
paccessor->field->attr &= ~field_desc::f_serialized;
}
}
}
void method_desc::build_call_graph()
{
if (attr & m_synchronized) {
for (callee_desc* callee=callees; callee != NULL; callee=callee->next){
callee->method->build_call_graph(this, callee, callee->attr);
}
}
}
int method_desc::print_call_path_to(callee_desc* target,
int loop_id, int path_id, int caller_attr,
callee_desc* prev)
{
if (attr & (m_deadlock_free|m_visited)) {
return path_id;
}
attr |= m_visited;
if (prev != NULL) {
for (overridden_method* ovr = overridden;
ovr != NULL && path_id < max_shown_paths;
ovr = ovr->next)
{
path_id = ovr->method->print_call_path_to(target, loop_id, path_id,
caller_attr, prev);
}
}
for (callee_desc* callee = callees;
callee != NULL && path_id < max_shown_paths;
callee = callee->next)
{
int callee_attr = callee->attr & caller_attr;
if (callee->method->attr & m_synchronized) {
if (callee == target && !(callee_attr & callee_desc::i_self)) {
print_call_sequence(prev, loop_id, ++path_id);
}
} else {
callee->backtrace = prev;
path_id = callee->method->print_call_path_to(target, loop_id,
path_id, callee_attr,
callee);
}
}
attr &= ~m_visited;
return path_id;
}
void method_desc::add_to_concurrent_closure(callee_desc* caller,
int caller_attr, int depth)
{
for (overridden_method* ovr=overridden; ovr != NULL; ovr=ovr->next) {
add_to_concurrent_closure(caller, caller_attr, depth);
}
if (attr & m_synchronized) {
if ((caller_attr & (callee_desc::i_synchronized|callee_desc::i_self))
== callee_desc::i_synchronized && (attr & m_wait))
{
int callee_attr = callee_desc::i_self|callee_desc::i_wait_deadlock;
callee_desc* up = caller;
while (true) {
callee_attr &= up->attr;
if (up->backtrace == NULL
|| (!(callee_attr & callee_desc::i_self) &&
((up->attr & callee_desc::i_synchronized)
|| (((callee_desc*)up->backtrace)->method->attr
& m_synchronized))))
{
break;
}
up = (callee_desc*)up->backtrace;
}
// Check if this pass was already found
if (!(callee_attr & callee_desc::i_wait_deadlock)) {
message_at(msg_wait, cls->source_file, wait_line, this);
callee_desc* bt = caller;
while (true) {
bt->message(msg_wait_path, bt->method);
bt->attr |= callee_desc::i_wait_deadlock;
if (bt == up) break;
bt = (callee_desc*)bt->backtrace;
}
}
}
attr |= m_concurrent;
if ((caller_attr & (callee_desc::i_synchronized|callee_desc::i_self))
== callee_desc::i_synchronized && !(attr & m_visited))
{
attr |= m_visited;
for (callee_desc* callee = callees;
callee != NULL;
callee = callee->next)
{
if (callee->attr & callee_desc::i_self) {
callee->backtrace = caller;
callee->method->add_to_concurrent_closure
(callee, callee_desc::i_synchronized, 0);
}
}
attr &= ~m_visited;
}
}
else if (!(attr & m_visited)
&& !((depth != 0 || (caller_attr & callee_desc::i_self))
&& (attr & m_concurrent)))
{
if (attr & m_concurrent) {
depth += 1;
}
attr |= m_visited|m_concurrent;
for (callee_desc* callee=callees; callee != NULL; callee=callee->next){
int callee_attr = caller_attr;
if (callee->attr & callee_desc::i_synchronized) {
callee_attr = callee_desc::i_synchronized;
} else {
callee_attr &= callee->attr|~callee_desc::i_self;
}
callee->backtrace = caller;
callee->method->add_to_concurrent_closure(callee, callee_attr,
depth);
}
attr &= ~m_visited;
}
}
void method_desc::build_concurrent_closure()
{
//
// Check if "run" method of class implementing Runnable interface
// is synchronized and mark this method as concurrent.
//
int caller_attr = 0;
attr |= m_visited;
if (attr & m_synchronized) {
caller_attr = callee_desc::i_synchronized;
}
else if (name == "run" && (cls->implements("java/lang/Runnable")
|| cls->isa("java/lang/Thread")))
{
if (cls->implements("java/lang/Runnable")) {
message_at(msg_run_nosync, cls->source_file, first_line, this);
}
} else {
for (callee_desc* callee=callees; callee != NULL; callee=callee->next){
if (callee->attr & callee_desc::i_synchronized) {
callee->backtrace = NULL;
callee->method->
add_to_concurrent_closure(callee,
callee_desc::i_synchronized, 0);
}
}
attr &= ~m_visited;
return;
}
for (callee_desc* callee=callees; callee != NULL; callee=callee->next) {
int callee_attr = callee->attr;
if (callee_attr & callee_desc::i_synchronized) {
// Synchronized construction was used. Clear "i_self" bit,
// because two monitors are already locked
callee_attr &= ~callee_desc::i_self;
}
callee->backtrace = NULL;
callee->method->add_to_concurrent_closure(callee,
callee_attr|caller_attr, 0);
}
attr &= ~m_visited;
}
void method_desc::calculate_attributes()
{
vertex = (attr & m_static) ? cls->metaclass_vertex : cls->class_vertex;
//
// Find out all "self" static invocations
//
for (callee_desc* callee = callees; callee != NULL; callee=callee->next) {
if ((attr & callee->method->attr & m_static)
&& cls->isa(callee->method->cls))
{
callee->attr |= callee_desc::i_self;
}
}
}
int method_desc::get_line_number(int pc)
{
while (line_table[pc] == 0 && pc > 0) {
pc -= 1;
}
return line_table[pc];
}
void method_desc::message(int mycode, int pc, ...)
{
va_list ap;
va_start(ap, pc);
#ifdef PRINT_PC
printf("In %s.%s pc=%d\n", cls->name.as_asciz(), name.as_asciz(), pc);
#endif
format_message(mycode, cls->source_file, get_line_number(pc), ap);
va_end(ap);
}
void method_desc::check_variable_for_null(int pc, vbm_operand* sp)
{
if (!(sp->mask & var_desc::vs_not_null)) {
if (sp->index >= 0) {
message(msg_null_var, pc, &vars[sp->index].name);
} else {
message(msg_null_ptr, pc);
}
}
else if ((unsigned)sp->index < 32
&& (sp->mask & var_desc::vs_not_null) != var_desc::vs_not_null)
{
// formal parameter was not assigned value
// and was not checked for NULL
if (null_parameter_mask & (1 << sp->index)) {
message(msg_null_param, pc, this, sp->index);
} else {
unchecked_use_mask |= 1 << sp->index;
}
}
}
void method_desc::check_array_index(int pc, vbm_operand* sp)
{
check_variable_for_null(pc, sp);
if (sp[1].min < 0) {
if (sp[1].max < 0) {
message(msg_bad_index, pc, sp[1].min, sp[1].max);
} else if (sp[1].min > -128) {
message(msg_maybe_bad_index, pc, sp[1].min, sp[1].max);
}
}
if (sp[1].max >= sp->max && sp->max != MAX_ARRAY_LENGTH) {
if (sp[1].min >= sp->max) {
message(msg_bad_index, pc, sp[1].min, sp[1].max);
} else if (sp[1].max - sp->max < 127) {
message(msg_maybe_bad_index, pc, sp[1].min, sp[1].max);
}
}
}
void method_desc::basic_blocks_analysis()
{
byte* pc = code;
byte* end = pc + code_length;
int i;
var_store_count = n_vars > 0 ? new int[n_vars] : NULL;
for (i = n_vars; --i >= 0;) {
vars[i].type = tp_void;
vars[i].name = utf_string("???");
vars[i].min = 0;
vars[i].max = MAX_ARRAY_LENGTH;
var_store_count[i] = 0;
}
while (pc != end) {
int addr = pc - code;
int offs;
switch (*pc) {
case jsr:
case ifeq:
case ifne:
case iflt:
case ifge:
case ifgt:
case ifle:
case if_icmpeq:
case if_icmpne:
case if_icmplt:
case if_icmpge:
case if_icmpgt:
case if_icmple:
case if_acmpeq:
case if_acmpne:
case ifnull:
case ifnonnull:
case goto_near:
offs = (short)unpack2(pc+1);
if (offs < 0) { // backward jump
new ctx_reset(&context[addr+offs], var_store_count, n_vars);
new ctx_split(&context[addr], ctx_split::jmp_backward);
} else if (offs > 0) { // forward jump
new ctx_merge(&context[addr+offs],
new ctx_split(&context[addr], ctx_split::jmp_forward));
}
pc += 3;
break;
case jsr_w:
case goto_w:
offs = unpack4(pc+1);
if (offs < 0) { // backward jump
new ctx_reset(&context[addr+offs], var_store_count, n_vars);
} else if (offs > 0) { // forward jump
new ctx_merge(&context[addr+offs],
new ctx_split(&context[addr], ctx_split::jmp_forward));
}
pc += 5;
break;
case tableswitch:
{
pc += 4 - (addr & 3);
offs = unpack4(pc); // default label
int low = unpack4(pc+4);
int high = unpack4(pc+8);
int n_forward_jumps = 0;
pc += 12;
ctx_split* select = new ctx_split(&context[addr]);
if (offs < 0) {
new ctx_reset(&context[addr+offs], var_store_count, n_vars);
} else if (offs > 0) {
new ctx_merge(&context[addr+offs], select);
n_forward_jumps += 1;
}
while (low <= high) {
offs = unpack4(pc);
if (offs < 0) {
new ctx_reset(&context[addr+offs],
var_store_count, n_vars);
} else if (offs > 0) {
new ctx_merge(&context[addr+offs], select, low);
n_forward_jumps += 1;
}
pc += 4;
low += 1;
}
select->n_branches = n_forward_jumps;
}
break;
case lookupswitch:
{
pc += 4 - (addr & 3);
offs = unpack4(pc); // default label
int n_pairs = unpack4(pc+4);
int n_forward_jumps = 0;
pc += 8;
ctx_split* select = new ctx_split(&context[addr]);
if (offs < 0) {
new ctx_reset(&context[addr+offs], var_store_count, n_vars);
} else if (offs > 0) {
new ctx_merge(&context[addr+offs], select);
n_forward_jumps += 1;
}
while (--n_pairs >= 0) {
offs = unpack4(pc+4);
if (offs < 0) {
new ctx_reset(&context[addr+offs],
var_store_count, n_vars);
} else if (offs > 0) {
new ctx_merge(&context[addr+offs], select, unpack4(pc));
n_forward_jumps += 1;
}
pc += 8;
}
select->n_branches = n_forward_jumps;
}
break;
case istore:
case lstore:
case astore:
pc += 1;
var_store_count[*pc++] += 1;
break;
case istore_0:
case istore_1:
case istore_2:
case istore_3:
var_store_count[*pc++ - istore_0] += 1;
break;
case lstore_0:
case lstore_1:
case lstore_2:
case lstore_3:
var_store_count[*pc++ - lstore_0] += 1;
break;
case astore_0:
case astore_1:
case astore_2:
case astore_3:
var_store_count[*pc++ - astore_0] += 1;
break;
case iinc:
var_store_count[pc[1]] += 1;
pc += 3;
break;
case wide:
pc += 1;
switch (*pc++) {
case istore:
case lstore:
case astore:
var_store_count[unpack2(pc)] += 1;
break;
case iinc:
var_store_count[unpack2(pc)] += 1;
pc += 2;
}
pc += 2;
break;
default:
pc += vbm_instruction_length[*pc];
}
}
for (i = n_vars; --i >= 0;) {
var_store_count[i] = 0;
}
}
void method_desc::parse_code(constant** constant_pool,
const field_desc* is_this)
{
#ifdef DEBUG
printf("Method %s\n", name.as_asciz());
#endif
const int indirect = 0x100;
byte* pc = code;
byte* end = pc + code_length;
const int max_stack_size = 256;
vbm_operand stack[max_stack_size+2];
int i;
for (i = 0; i < max_stack_size+2; i++) {
stack[i].equals = NULL;
}
vbm_operand* stack_bottom = stack+2; // avoid checks for non-empty stack
vbm_operand* sp = stack_bottom;
local_context* ctx;
byte prev_cop = nop;
bool super_finalize = false;
#ifdef INT8_DEFINED
int8 left_min;
int8 left_max;
int8 left_mask;
int8 right_min;
int8 right_max;
int8 right_mask;
#define LOAD_INT8_OPERANDS() \
left_min = LOAD_INT8(sp-4, min);\
left_max = LOAD_INT8(sp-4, max);\
left_mask = LOAD_INT8(sp-4, mask);\
right_min = LOAD_INT8(sp-2, min);\
right_max = LOAD_INT8(sp-2, max);\
right_mask = LOAD_INT8(sp-2, mask)
#define LOAD_INT8_OPERAND() \
left_min = LOAD_INT8(sp-2, min);\
left_max = LOAD_INT8(sp-2, max);\
left_mask = LOAD_INT8(sp-2, mask)
#endif
in_monitor = false;
stack[0].type = stack[1].type = tp_void;
cls->locks.clear();
basic_blocks_analysis();
for (i = 0; i < 32; i++) {
if (null_parameter_mask & (1 << i)) {
assert(i < n_vars);
vars[i].mask = 0;
vars[i].min = 0;
vars[i].max = MAX_ARRAY_LENGTH;
if (vars[i].type == tp_void) {
vars[i].type = tp_object;
}
}
}
if (!(attr & m_static)) {
vars[0].type = tp_self;
vars[0].mask = var_desc::vs_not_null;
vars[0].min = 0;
vars[0].max = MAX_ARRAY_LENGTH;
vars[0].equals = is_this;
}
if (attr & m_synchronized) { // add "this" to lock set if needed
cls->locks.acquire(is_this);
locksAtEntry.acquire(is_this);
}
while (pc < end) {
int addr = pc - code;
byte cop = *pc++;
#ifdef DUMP_BYTE_CODES
printf("%s: min=%d, max=%d, mask=0x%x\n",
vbm_instruction_mnemonic[cop],
sp[-1].min, sp[-1].max, sp[-1].mask);
#endif
for (ctx = context[addr]; ctx != NULL; ctx = ctx->next) {
sp = ctx->transfer(this, sp, cop, prev_cop);
}
switch (cop) {
case nop:
break;
case aconst_null:
sp->type = tp_object;
sp->mask = 0;
sp->min = sp->max = 0;
sp->index = NO_ASSOC_VAR;
sp += 1;
break;
case iconst_m1:
case iconst_0:
case iconst_1:
case iconst_2:
case iconst_3:
case iconst_4:
case iconst_5:
sp->type = tp_byte;
sp->mask = sp->min = sp->max = cop - iconst_0;
sp->index = NO_ASSOC_VAR;
sp += 1;
break;
case fconst_0:
case fconst_1:
case fconst_2:
sp->type = tp_float;
sp->index = NO_ASSOC_VAR;
sp += 1;
break;
case lconst_0:
case lconst_1:
sp[0].type = sp[1].type = tp_long;
sp[0].min = sp[0].max = sp[0].mask = 0;
sp[1].min = sp[1].max = sp[1].mask = cop - lconst_0;
sp[0].index = sp[1].index = NO_ASSOC_VAR;
sp += 2;
break;
case dconst_0:
case dconst_1:
sp[0].type = sp[1].type = tp_double;
sp[0].index = sp[1].index = NO_ASSOC_VAR;
sp += 2;
break;
case bipush:
sp->type = tp_int;
sp->mask = sp->min = sp->max = (signed char)*pc++;
sp->index = NO_ASSOC_VAR;
sp += 1;
break;
case sipush:
sp->type = tp_int;
sp->mask = sp->min = sp->max = (short)unpack2(pc);
sp->index = NO_ASSOC_VAR;
pc += 2;
sp += 1;
break;
case ldc:
{
constant* cp = constant_pool[*pc++];
sp->type = cp->type();
if (sp->type == tp_int) {
sp->mask = sp->min = sp->max = ((const_int*)cp)->value;
} else {
if (sp->type == tp_string) {
sp->min = sp->max = ((const_string*)cp)->length();
} else {
sp->min = 0;
sp->max = MAX_ARRAY_LENGTH;
}
sp->mask = var_desc::vs_not_null;
}
sp->index = NO_ASSOC_VAR;
sp->equals = is_const;
sp += 1;
}
break;
case ldc_w:
{
constant* cp = constant_pool[unpack2(pc)];
sp->type = cp->type();
if (sp->type == tp_int) {
sp->mask = sp->min = sp->max = ((const_int*)cp)->value;
} else {
if (sp->type == tp_string) {
sp->min = sp->max = ((const_string*)cp)->length();
} else {
sp->min = 0;
sp->max = MAX_ARRAY_LENGTH;
}
sp->mask = var_desc::vs_not_null;
}
sp->index = NO_ASSOC_VAR;
pc += 2;
sp += 1;
}
break;
case ldc2_w:
{
const_long* cp = (const_long*)constant_pool[unpack2(pc)];
sp->type = tp_long;
sp->index = NO_ASSOC_VAR;
sp->mask = sp->min = sp->max = cp->value.high;
sp += 1;
sp->type = tp_long;
sp->index = NO_ASSOC_VAR;
sp->mask = sp->min = sp->max = cp->value.low;
sp += 1;
pc += 2;
}
break;
case iload:
if (vars[*pc].type == tp_void) {
vars[*pc].type = tp_int;
vars[*pc].min = ranges[tp_int].min;
vars[*pc].max = ranges[tp_int].max;
vars[*pc].mask = ALL_BITS;
}
sp->type = vars[*pc].type;
sp->min = vars[*pc].min;
sp->max = vars[*pc].max;
sp->mask = vars[*pc].mask;
sp->index = *pc++;
sp += 1;
break;
case aload:
if (vars[*pc].type == tp_void) {
vars[*pc].type = tp_object;
vars[*pc].min = 0;
vars[*pc].max = MAX_ARRAY_LENGTH;
vars[*pc].mask = var_desc::vs_unknown;
}
sp->type = vars[*pc].type;
sp->mask = vars[*pc].mask;
sp->min = vars[*pc].min;
sp->max = vars[*pc].max;
sp->equals = vars[*pc].equals;
#ifdef DUMP_STACK
printf("<stack_top> := %x %s\n",
(int)sp->equals,
sp->equals == NULL ?
"<unknown>" : sp->equals->name.as_asciz()
);
#endif
sp->index = *pc++;
sp += 1;
break;
case lload:
{
int index = *pc++;
if (vars[index].type == tp_void) {
vars[index].type = tp_long;
vars[index].min = 0x80000000;
vars[index].max = 0x7fffffff;
vars[index].mask = 0xffffffff;
vars[index+1].min = 0x00000000;
vars[index+1].max = 0xffffffff;
vars[index+1].mask = 0xffffffff;
}
sp->type = tp_long;
sp->min = vars[index].min;
sp->max = vars[index].max;
sp->mask = vars[index].mask;
sp->index = index;
sp += 1;
index += 1;
sp->type = tp_long;
sp->min = vars[index].min;
sp->max = vars[index].max;
sp->mask = vars[index].mask;
sp += 1;
}
break;
case dload:
sp[0].type = sp[1].type = tp_double;
sp[0].index = sp[1].index = NO_ASSOC_VAR;
sp += 2; pc += 1;
break;
case fload:
sp->type = tp_float;
sp->index = NO_ASSOC_VAR;
sp += 1;
pc += 1;
break;
case iload_0:
case iload_1:
case iload_2:
case iload_3:
{
var_desc* var = &vars[cop - iload_0];
if (var->type == tp_void) {
var->type = tp_int;
var->min = ranges[tp_int].min;
var->max = ranges[tp_int].max;
var->mask = ALL_BITS;
}
sp->type = var->type;
sp->min = var->min;
sp->max = var->max;
sp->mask = var->mask;
sp->index = cop - iload_0;
sp += 1;
}
break;
case lload_0:
case lload_1:
case lload_2:
case lload_3:
{
int index = cop - lload_0;
if (vars[index].type == tp_void) {
vars[index].type = tp_long;
vars[index].min = 0x80000000;
vars[index].max = 0x7fffffff;
vars[index].mask = 0xffffffff;
vars[index+1].min = 0x00000000;
vars[index+1].max = 0xffffffff;
vars[index+1].mask = 0xffffffff;
}
sp->type = tp_long;
sp->min = vars[index].min;
sp->max = vars[index].max;
sp->mask = vars[index].mask;
sp->index = index;
sp += 1;
index += 1;
sp->type = tp_long;
sp->min = vars[index].min;
sp->max = vars[index].max;
sp->mask = vars[index].mask;
sp += 1;
}
break;
case dload_0:
case dload_1:
case dload_2:
case dload_3:
sp[0].type = sp[1].type = tp_double;
sp[0].index = sp[1].index = NO_ASSOC_VAR;
sp += 2;
break;
case fload_0:
case fload_1:
case fload_2:
case fload_3:
sp->type = tp_float;
sp->index = NO_ASSOC_VAR;
sp += 1;
break;
case aload_0:
case aload_1:
case aload_2:
case aload_3:
{
var_desc* var = &vars[cop - aload_0];
if (var->type == tp_void) {
if (cop == aload_0 && !(attr & m_static)) {
var->type = tp_self;
var->mask = var_desc::vs_not_null;
} else {
var->type = tp_object;
var->mask = var_desc::vs_unknown;
}
sp->min = 0;
sp->max = MAX_ARRAY_LENGTH;
}
sp->type = var->type;
sp->mask = var->mask;
sp->min = var->min;
sp->max = var->max;
sp->index = cop - aload_0;
sp->equals = vars[cop - aload_0].equals;
#ifdef DUMP_STACK
printf("<stack_top> := %x %s\n",
(int)sp->equals,
sp->equals == NULL ?
"<unknown>" : sp->equals->name.as_asciz()
);
#endif
sp += 1;
}
break;
case iaload:
case faload:
case aaload:
case baload:
case caload:
case saload:
sp -= 2;
check_array_index(addr, sp);
if (IS_ARRAY_TYPE(sp->type)) {
sp->type -= indirect;
} else {
sp->type =
(cop == aaload) ? tp_object :
(cop == baload) ? tp_byte :
(cop == caload) ? tp_char :
(cop == iaload) ? tp_int :
(cop == saload) ? tp_short : tp_float;
}
if (IS_INT_TYPE(sp->type)) {
sp->min = ranges[sp->type].min;
sp->max = ranges[sp->type].max;