forked from dcevm/dcevm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
light-jdk7u79-b15.patch
10339 lines (9981 loc) · 424 KB
/
light-jdk7u79-b15.patch
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
diff --git a/src/cpu/x86/vm/interp_masm_x86_32.cpp b/src/cpu/x86/vm/interp_masm_x86_32.cpp
index b0ebcfd..6366d68 100644
--- a/src/cpu/x86/vm/interp_masm_x86_32.cpp
+++ b/src/cpu/x86/vm/interp_masm_x86_32.cpp
@@ -1364,7 +1364,7 @@
}
// RedefineClasses() tracing support for obsolete method entry
- if (RC_TRACE_IN_RANGE(0x00001000, 0x00002000)) {
+ IF_TRACE_RC4 {
get_thread(rcx);
get_method(rbx);
call_VM_leaf(
diff --git a/src/cpu/x86/vm/interp_masm_x86_64.cpp b/src/cpu/x86/vm/interp_masm_x86_64.cpp
index 2790c2a..c315b18 100644
--- a/src/cpu/x86/vm/interp_masm_x86_64.cpp
+++ b/src/cpu/x86/vm/interp_masm_x86_64.cpp
@@ -1427,7 +1427,7 @@
}
// RedefineClasses() tracing support for obsolete method entry
- if (RC_TRACE_IN_RANGE(0x00001000, 0x00002000)) {
+ IF_TRACE_RC4 {
get_method(c_rarg1);
call_VM_leaf(
CAST_FROM_FN_PTR(address, SharedRuntime::rc_trace_method_entry),
diff --git a/src/cpu/x86/vm/sharedRuntime_x86_32.cpp b/src/cpu/x86/vm/sharedRuntime_x86_32.cpp
index 16958cd..09d6300 100644
--- a/src/cpu/x86/vm/sharedRuntime_x86_32.cpp
+++ b/src/cpu/x86/vm/sharedRuntime_x86_32.cpp
@@ -1976,7 +1976,7 @@
}
// RedefineClasses() tracing support for obsolete method entry
- if (RC_TRACE_IN_RANGE(0x00001000, 0x00002000)) {
+ IF_TRACE_RC4 {
__ movoop(rax, JNIHandles::make_local(method()));
__ call_VM_leaf(
CAST_FROM_FN_PTR(address, SharedRuntime::rc_trace_method_entry),
diff --git a/src/cpu/x86/vm/sharedRuntime_x86_64.cpp b/src/cpu/x86/vm/sharedRuntime_x86_64.cpp
index 7dc4e62..86c8c95 100644
--- a/src/cpu/x86/vm/sharedRuntime_x86_64.cpp
+++ b/src/cpu/x86/vm/sharedRuntime_x86_64.cpp
@@ -2235,7 +2235,7 @@
}
// RedefineClasses() tracing support for obsolete method entry
- if (RC_TRACE_IN_RANGE(0x00001000, 0x00002000)) {
+ IF_TRACE_RC4 {
// protect the args we've loaded
save_args(masm, total_c_args, c_arg, out_regs);
__ movoop(c_rarg1, JNIHandles::make_local(method()));
diff --git a/src/share/vm/c1/c1_Compilation.hpp b/src/share/vm/c1/c1_Compilation.hpp
index 9a8ca61..83e6f54 100644
--- a/src/share/vm/c1/c1_Compilation.hpp
+++ b/src/share/vm/c1/c1_Compilation.hpp
@@ -242,8 +242,9 @@
#define BAILOUT(msg) { bailout(msg); return; }
#define BAILOUT_(msg, res) { bailout(msg); return res; }
-#define CHECK_BAILOUT() { if (bailed_out()) return; }
-#define CHECK_BAILOUT_(res) { if (bailed_out()) return res; }
+// (tw) Also checks a thread local flag that can be set to trigger compiler bailout from another thread.
+#define CHECK_BAILOUT() { if (((CompilerThread *)Thread::current())->should_bailout()) bailout("Aborted externally"); if (bailed_out()) return; }
+#define CHECK_BAILOUT_(res) { if (((CompilerThread *)Thread::current())->should_bailout()) bailout("Aborted externally"); if (bailed_out()) return res; }
class InstructionMark: public StackObj {
diff --git a/src/share/vm/ci/ciObjectFactory.cpp b/src/share/vm/ci/ciObjectFactory.cpp
index e0ab96b..db8e551 100644
--- a/src/share/vm/ci/ciObjectFactory.cpp
+++ b/src/share/vm/ci/ciObjectFactory.cpp
@@ -764,3 +764,26 @@
_unloaded_instances->length(),
_unloaded_klasses->length());
}
+
+int ciObjectFactory::compare_ciobjects(ciObject** a, ciObject** b) {
+ oop oop1 = (*a)->get_oop();
+ oop oop2 = (*b)->get_oop();
+ return ((oop1 > oop2) ? 1 : ((oop1 == oop2) ? 0 : -1));
+}
+
+// (DCEVM) Resoring the ciObject arrays after class redefinition
+void ciObjectFactory::resort_shared_ci_objects() {
+ _shared_ci_objects->sort(ciObjectFactory::compare_ciobjects);
+
+#ifdef ASSERT
+ if (CIObjectFactoryVerify) {
+ oop last = NULL;
+ for (int j = 0; j < _shared_ci_objects->length(); j++) {
+ oop o = _shared_ci_objects->at(j)->get_oop();
+ assert(last < o, "out of order");
+ last = o;
+ }
+ }
+#endif // ASSERT
+}
+
diff --git a/src/share/vm/ci/ciObjectFactory.hpp b/src/share/vm/ci/ciObjectFactory.hpp
index 26cc2c3..d99d3d6 100644
--- a/src/share/vm/ci/ciObjectFactory.hpp
+++ b/src/share/vm/ci/ciObjectFactory.hpp
@@ -88,6 +88,7 @@
ciInstance* get_unloaded_instance(ciInstanceKlass* klass);
+ static int compare_ciobjects(ciObject** a, ciObject** b);
public:
static bool is_initialized() { return _initialized; }
@@ -137,6 +138,8 @@
void print_contents();
void print();
+
+ static void resort_shared_ci_objects();
};
#endif // SHARE_VM_CI_CIOBJECTFACTORY_HPP
diff --git a/src/share/vm/classfile/classFileParser.cpp b/src/share/vm/classfile/classFileParser.cpp
index 505bad1..4d172fd 100644
--- a/src/share/vm/classfile/classFileParser.cpp
+++ b/src/share/vm/classfile/classFileParser.cpp
@@ -795,6 +795,7 @@
Handle class_loader,
Handle protection_domain,
Symbol* class_name,
+ KlassHandle old_klass,
TRAPS) {
ClassFileStream* cfs = stream();
assert(length > 0, "only called for length>0");
@@ -813,6 +814,9 @@
interface_index, CHECK_(nullHandle));
if (cp->tag_at(interface_index).is_klass()) {
interf = KlassHandle(THREAD, cp->resolved_klass_at(interface_index));
+ if (!old_klass.is_null() && !interf->is_newest_version()) {
+ interf = KlassHandle(THREAD, interf->newest_version());
+ }
} else {
Symbol* unresolved_klass = cp->klass_name_at(interface_index);
@@ -825,6 +829,9 @@
klassOop k = SystemDictionary::resolve_super_or_fail(class_name,
unresolved_klass, class_loader, protection_domain,
false, CHECK_(nullHandle));
+ if (!old_klass.is_null()) {
+ k = k->klass_part()->newest_version();
+ }
interf = KlassHandle(THREAD, k);
}
@@ -2955,8 +2962,10 @@
instanceKlassHandle ClassFileParser::parseClassFile(Symbol* name,
Handle class_loader,
Handle protection_domain,
+ KlassHandle old_klass,
KlassHandle host_klass,
GrowableArray<Handle>* cp_patches,
+ GrowableArray<Symbol*>* parsed_super_symbols,
TempNewSymbol& parsed_name,
bool verify,
TRAPS) {
@@ -2982,7 +2991,7 @@
init_parsed_class_attributes();
- if (JvmtiExport::should_post_class_file_load_hook()) {
+ if (parsed_super_symbols == NULL && JvmtiExport::should_post_class_file_load_hook()) {
// Get the cached class file bytes (if any) from the class that
// is being redefined or retransformed. We use jvmti_thread_state()
// instead of JvmtiThreadState::state_for(jt) so we don't allocate
@@ -3005,10 +3014,13 @@
unsigned char* ptr = cfs->buffer();
unsigned char* end_ptr = cfs->buffer() + cfs->length();
+ bool pretend_new_universe = Thread::current()->pretend_new_universe();
+ Thread::current()->set_pretend_new_universe(false);
JvmtiExport::post_class_file_load_hook(name, class_loader, protection_domain,
&ptr, &end_ptr,
&cached_class_file_bytes,
&cached_class_file_length);
+ Thread::current()->set_pretend_new_universe(pretend_new_universe);
if (ptr != cfs->buffer()) {
// JVMTI agent has modified class file data.
@@ -3124,6 +3136,30 @@
CHECK_(nullHandle));
}
+ // (tw) Do not parse full class file, only get super symbols and return.
+ if (parsed_super_symbols != NULL) {
+ u2 super_class_index = cfs->get_u2_fast();
+
+ if (super_class_index != 0) {
+ parsed_super_symbols->append(cp->klass_name_at(super_class_index));
+ }
+
+ // Interfaces
+ u2 itfs_len = cfs->get_u2_fast();
+ objArrayHandle local_interfaces;
+ if (itfs_len == 0) {
+ local_interfaces = objArrayHandle(THREAD, Universe::the_empty_system_obj_array());
+ } else {
+ local_interfaces = parse_interfaces(cp, itfs_len, class_loader, protection_domain, _class_name, old_klass, CHECK_NULL);
+ }
+
+ for (int i=0; i<local_interfaces->length(); i++) {
+ oop o = local_interfaces->obj_at(i);
+ parsed_super_symbols->append(((klassOop)o)->klass_part()->name());
+ }
+ return NULL;
+ }
+
klassOop preserve_this_klass; // for storing result across HandleMark
// release all handles when parsing is done
@@ -3164,7 +3200,11 @@
// However, make sure it is not an array type.
bool is_array = false;
if (cp->tag_at(super_class_index).is_klass()) {
- super_klass = instanceKlassHandle(THREAD, cp->resolved_klass_at(super_class_index));
+ klassOop resolved_klass = cp->resolved_klass_at(super_class_index);
+ if (!old_klass.is_null()) {
+ resolved_klass = resolved_klass->klass_part()->newest_version();
+ }
+ super_klass = instanceKlassHandle(THREAD, resolved_klass);
if (_need_verify)
is_array = super_klass->oop_is_array();
} else if (_need_verify) {
@@ -3182,7 +3222,7 @@
if (itfs_len == 0) {
local_interfaces = objArrayHandle(THREAD, Universe::the_empty_system_obj_array());
} else {
- local_interfaces = parse_interfaces(cp, itfs_len, class_loader, protection_domain, _class_name, CHECK_(nullHandle));
+ local_interfaces = parse_interfaces(cp, itfs_len, class_loader, protection_domain, _class_name, old_klass, CHECK_(nullHandle));
}
u2 java_fields_count = 0;
@@ -3237,7 +3277,9 @@
protection_domain,
true,
CHECK_(nullHandle));
-
+ if (!old_klass.is_null()) {
+ k = k->klass_part()->newest_version();
+ }
KlassHandle kh (THREAD, k);
super_klass = instanceKlassHandle(THREAD, kh());
}
@@ -3626,6 +3668,19 @@
rt = REF_NONE;
} else {
rt = super_klass->reference_type();
+
+ // (tw) With class redefinition, it can also happen that special classes are loaded.
+ if (name == vmSymbols::java_lang_ref_Reference()) {
+ rt = REF_OTHER;
+ } else if (name == vmSymbols::java_lang_ref_SoftReference()) {
+ rt = REF_SOFT;
+ } else if (name == vmSymbols::java_lang_ref_WeakReference()) {
+ rt = REF_WEAK;
+ } else if (name == vmSymbols::java_lang_ref_FinalReference()) {
+ rt = REF_FINAL;
+ } else if (name == vmSymbols::java_lang_ref_PhantomReference()) {
+ rt = REF_PHANTOM;
+ }
}
// We can now create the basic klassOop for this klass
@@ -3634,6 +3689,7 @@
total_oop_map_count,
access_flags,
rt, host_klass,
+ old_klass,
CHECK_(nullHandle));
instanceKlassHandle this_klass (THREAD, ik);
@@ -3726,7 +3782,7 @@
fill_oop_maps(this_klass, nonstatic_oop_map_count, nonstatic_oop_offsets, nonstatic_oop_counts);
// Fill in has_finalizer, has_vanilla_constructor, and layout_helper
- set_precomputed_flags(this_klass);
+ set_precomputed_flags(this_klass, old_klass);
// reinitialize modifiers, using the InnerClasses attribute
int computed_modifiers = this_klass->compute_modifier_flags(CHECK_(nullHandle));
@@ -3744,6 +3800,10 @@
// check that if this class is an interface then it doesn't have static methods
if (this_klass->is_interface()) {
check_illegal_static_method(this_klass, CHECK_(nullHandle));
+ }
+
+ if (rt == REF_OTHER) {
+ instanceRefKlass::update_nonstatic_oop_maps(ik);
}
// Allocate mirror and initialize static fields
@@ -3891,7 +3951,7 @@
}
-void ClassFileParser::set_precomputed_flags(instanceKlassHandle k) {
+void ClassFileParser::set_precomputed_flags(instanceKlassHandle k, KlassHandle old_klass) {
klassOop super = k->super();
// Check if this klass has an empty finalize method (i.e. one with return bytecode only),
@@ -3899,7 +3959,9 @@
if (!_has_empty_finalizer) {
if (_has_finalizer ||
(super != NULL && super->klass_part()->has_finalizer())) {
- k->set_has_finalizer();
+ if (old_klass.is_null() || old_klass->has_finalizer()) {
+ k->set_has_finalizer();
+ }
}
}
@@ -3915,7 +3977,7 @@
// Check if this klass supports the java.lang.Cloneable interface
if (SystemDictionary::Cloneable_klass_loaded()) {
- if (k->is_subtype_of(SystemDictionary::Cloneable_klass())) {
+ if (k->is_subtype_of(SystemDictionary::Cloneable_klass()) || k->is_subtype_of(SystemDictionary::Cloneable_klass()->klass_part()->newest_version())) {
k->set_is_cloneable();
}
}
diff --git a/src/share/vm/classfile/classFileParser.hpp b/src/share/vm/classfile/classFileParser.hpp
index a95a784..ebf08b3 100644
--- a/src/share/vm/classfile/classFileParser.hpp
+++ b/src/share/vm/classfile/classFileParser.hpp
@@ -151,6 +151,7 @@
Handle class_loader,
Handle protection_domain,
Symbol* class_name,
+ KlassHandle old_klass,
TRAPS);
// Field parsing
@@ -239,7 +240,7 @@
unsigned int nonstatic_oop_map_count,
int* nonstatic_oop_offsets,
unsigned int* nonstatic_oop_counts);
- void set_precomputed_flags(instanceKlassHandle k);
+ void set_precomputed_flags(instanceKlassHandle k, KlassHandle old_klass);
objArrayHandle compute_transitive_interfaces(instanceKlassHandle super,
objArrayHandle local_ifs, TRAPS);
@@ -357,17 +358,20 @@
instanceKlassHandle parseClassFile(Symbol* name,
Handle class_loader,
Handle protection_domain,
+ KlassHandle old_klass,
TempNewSymbol& parsed_name,
bool verify,
TRAPS) {
KlassHandle no_host_klass;
- return parseClassFile(name, class_loader, protection_domain, no_host_klass, NULL, parsed_name, verify, THREAD);
+ return parseClassFile(name, class_loader, protection_domain, old_klass, no_host_klass, NULL, NULL, parsed_name, verify, THREAD);
}
instanceKlassHandle parseClassFile(Symbol* name,
Handle class_loader,
Handle protection_domain,
+ KlassHandle old_klass,
KlassHandle host_klass,
GrowableArray<Handle>* cp_patches,
+ GrowableArray<Symbol*>* parsed_super_symbols,
TempNewSymbol& parsed_name,
bool verify,
TRAPS);
diff --git a/src/share/vm/classfile/classLoader.cpp b/src/share/vm/classfile/classLoader.cpp
index a2e61a4..450e19f 100644
--- a/src/share/vm/classfile/classLoader.cpp
+++ b/src/share/vm/classfile/classLoader.cpp
@@ -915,6 +915,7 @@
instanceKlassHandle result = parser.parseClassFile(h_name,
class_loader,
protection_domain,
+ KlassHandle(),
parsed_name,
false,
CHECK_(h));
diff --git a/src/share/vm/classfile/dictionary.cpp b/src/share/vm/classfile/dictionary.cpp
index 78e76cc..d167c98 100644
--- a/src/share/vm/classfile/dictionary.cpp
+++ b/src/share/vm/classfile/dictionary.cpp
@@ -144,87 +144,10 @@
probe = *p;
klassOop e = probe->klass();
oop class_loader = probe->loader();
-
instanceKlass* ik = instanceKlass::cast(e);
- if (ik->previous_versions() != NULL) {
- // This klass has previous versions so see what we can cleanup
- // while it is safe to do so.
-
- int gc_count = 0; // leave debugging breadcrumbs
- int live_count = 0;
-
- // RC_TRACE macro has an embedded ResourceMark
- RC_TRACE(0x00000200, ("unload: %s: previous version length=%d",
- ik->external_name(), ik->previous_versions()->length()));
-
- for (int i = ik->previous_versions()->length() - 1; i >= 0; i--) {
- // check the previous versions array for GC'ed weak refs
- PreviousVersionNode * pv_node = ik->previous_versions()->at(i);
- jobject cp_ref = pv_node->prev_constant_pool();
- assert(cp_ref != NULL, "cp ref was unexpectedly cleared");
- if (cp_ref == NULL) {
- delete pv_node;
- ik->previous_versions()->remove_at(i);
- // Since we are traversing the array backwards, we don't have to
- // do anything special with the index.
- continue; // robustness
- }
-
- constantPoolOop pvcp = (constantPoolOop)JNIHandles::resolve(cp_ref);
- if (pvcp == NULL) {
- // this entry has been GC'ed so remove it
- delete pv_node;
- ik->previous_versions()->remove_at(i);
- // Since we are traversing the array backwards, we don't have to
- // do anything special with the index.
- gc_count++;
- continue;
- } else {
- RC_TRACE(0x00000200, ("unload: previous version @%d is alive", i));
- if (is_alive->do_object_b(pvcp)) {
- live_count++;
- } else {
- guarantee(false, "sanity check");
- }
- }
-
- GrowableArray<jweak>* method_refs = pv_node->prev_EMCP_methods();
- if (method_refs != NULL) {
- RC_TRACE(0x00000200, ("unload: previous methods length=%d",
- method_refs->length()));
- for (int j = method_refs->length() - 1; j >= 0; j--) {
- jweak method_ref = method_refs->at(j);
- assert(method_ref != NULL, "weak method ref was unexpectedly cleared");
- if (method_ref == NULL) {
- method_refs->remove_at(j);
- // Since we are traversing the array backwards, we don't have to
- // do anything special with the index.
- continue; // robustness
- }
-
- methodOop method = (methodOop)JNIHandles::resolve(method_ref);
- if (method == NULL) {
- // this method entry has been GC'ed so remove it
- JNIHandles::destroy_weak_global(method_ref);
- method_refs->remove_at(j);
- } else {
- // RC_TRACE macro has an embedded ResourceMark
- RC_TRACE(0x00000200,
- ("unload: %s(%s): prev method @%d in version @%d is alive",
- method->name()->as_C_string(),
- method->signature()->as_C_string(), j, i));
- }
- }
- }
- }
- assert(ik->previous_versions()->length() == live_count, "sanity check");
- RC_TRACE(0x00000200,
- ("unload: previous version stats: live=%d, GC'ed=%d", live_count,
- gc_count));
- }
-
+
// Non-unloadable classes were handled in always_strong_oops_do
- if (!is_strongly_reachable(class_loader, e)) {
+ if (!ik->is_redefining() && !is_strongly_reachable(class_loader, e)) {
// Entry was not visited in phase1 (negated test from phase1)
assert(class_loader != NULL, "unloading entry with null class loader");
oop k_def_class_loader = ik->class_loader();
@@ -325,6 +248,7 @@
}
}
}
+
// Added for initialize_itable_for_klass to handle exceptions
// Just the classes from defining class loaders
@@ -433,6 +357,33 @@
add_entry(index, entry);
}
+// (tw) Updates the klass entry to point to the new klassOop. Necessary only for class redefinition.
+bool Dictionary::update_klass(int index, unsigned int hash, Symbol* name, Handle loader, KlassHandle k, KlassHandle old_class) {
+
+ // There are several entries for the same class in the dictionary: One extra entry for each parent classloader of the classloader of the class.
+ bool found = false;
+ for (int index = 0; index < table_size(); index++) {
+ for (DictionaryEntry* entry = bucket(index); entry != NULL; entry = entry->next()) {
+ if (entry->klass() == old_class()) {
+ entry->set_literal(k());
+ found = true;
+ }
+ }
+ }
+
+ return found;
+}
+
+// (tw) Undo previous updates to the system dictionary
+void Dictionary::rollback_redefinition() {
+ for (int index = 0; index < table_size(); index++) {
+ for (DictionaryEntry* entry = bucket(index); entry != NULL; entry = entry->next()) {
+ if (entry->klass()->klass_part()->is_redefining()) {
+ entry->set_literal(entry->klass()->klass_part()->old_version());
+ }
+ }
+ }
+}
// This routine does not lock the system dictionary.
//
@@ -459,12 +410,21 @@
return NULL;
}
+klassOop Dictionary::intercept_for_version(klassOop k) {
+ if (k == NULL) return k;
+
+ if (k->klass_part()->is_redefining() && !Thread::current()->pretend_new_universe()) {
+ return k->klass_part()->old_version();
+ }
+
+ return k;
+}
klassOop Dictionary::find(int index, unsigned int hash, Symbol* name,
Handle loader, Handle protection_domain, TRAPS) {
DictionaryEntry* entry = get_entry(index, hash, name, loader);
if (entry != NULL && entry->is_valid_protection_domain(protection_domain)) {
- return entry->klass();
+ return intercept_for_version(entry->klass());
} else {
return NULL;
}
@@ -477,7 +437,7 @@
assert (index == index_for(name, loader), "incorrect index?");
DictionaryEntry* entry = get_entry(index, hash, name, loader);
- return (entry != NULL) ? entry->klass() : (klassOop)NULL;
+ return intercept_for_version((entry != NULL) ? entry->klass() : (klassOop)NULL);
}
@@ -489,7 +449,7 @@
assert (index == index_for(name, Handle()), "incorrect index?");
DictionaryEntry* entry = get_entry(index, hash, name, Handle());
- return (entry != NULL) ? entry->klass() : (klassOop)NULL;
+ return intercept_for_version((entry != NULL) ? entry->klass() : (klassOop)NULL);
}
diff --git a/src/share/vm/classfile/dictionary.hpp b/src/share/vm/classfile/dictionary.hpp
index bd33760..ea1fe3c 100644
--- a/src/share/vm/classfile/dictionary.hpp
+++ b/src/share/vm/classfile/dictionary.hpp
@@ -73,6 +73,10 @@
void add_klass(Symbol* class_name, Handle class_loader,KlassHandle obj);
+ bool update_klass(int index, unsigned int hash, Symbol* name, Handle loader, KlassHandle k, KlassHandle old_class);
+
+ void rollback_redefinition();
+
klassOop find_class(int index, unsigned int hash,
Symbol* name, Handle loader);
@@ -105,6 +109,7 @@
bool do_unloading(BoolObjectClosure* is_alive);
// Protection domains
+ static klassOop intercept_for_version(klassOop k);
klassOop find(int index, unsigned int hash, Symbol* name,
Handle loader, Handle protection_domain, TRAPS);
bool is_valid_protection_domain(int index, unsigned int hash,
diff --git a/src/share/vm/classfile/javaClasses.cpp b/src/share/vm/classfile/javaClasses.cpp
index 7dd5f1b..1ac23a9 100644
--- a/src/share/vm/classfile/javaClasses.cpp
+++ b/src/share/vm/classfile/javaClasses.cpp
@@ -621,6 +621,10 @@
assert(java_lang_Class::is_instance(java_class), "must be a Class object");
klassOop k = klassOop(java_class->obj_field(_klass_offset));
assert(k == NULL || k->is_klass(), "type check");
+ // Necessary to make old verifier work.
+ if (Thread::current()->pretend_new_universe()) {
+ k = k->klass_part()->newest_version();
+ }
return k;
}
@@ -1541,6 +1545,7 @@
skip_throwableInit_check = true;
}
}
+ method = method->newest_version();
if (method->is_hidden()) {
if (skip_hidden) continue;
}
diff --git a/src/share/vm/classfile/javaClasses.hpp b/src/share/vm/classfile/javaClasses.hpp
index 36d1cec..4699301 100644
--- a/src/share/vm/classfile/javaClasses.hpp
+++ b/src/share/vm/classfile/javaClasses.hpp
@@ -213,6 +213,7 @@
class java_lang_Class : AllStatic {
friend class VMStructs;
+ friend class VM_RedefineClasses;
private:
// The fake offsets are added by the class loader when java.lang.Class is loaded
@@ -248,7 +249,7 @@
static void print_signature(oop java_class, outputStream *st);
// Testing
static bool is_instance(oop obj) {
- return obj != NULL && obj->klass() == SystemDictionary::Class_klass();
+ return obj != NULL && (obj->klass()->klass_part()->newest_version() == SystemDictionary::Class_klass()->klass_part()->newest_version());
}
static bool is_primitive(oop java_class);
static BasicType primitive_type(oop java_class);
diff --git a/src/share/vm/classfile/loaderConstraints.cpp b/src/share/vm/classfile/loaderConstraints.cpp
index 8650cd9..965cce2 100644
--- a/src/share/vm/classfile/loaderConstraints.cpp
+++ b/src/share/vm/classfile/loaderConstraints.cpp
@@ -449,7 +449,7 @@
if (k != NULL) {
// We found the class in the system dictionary, so we should
// make sure that the klassOop matches what we already have.
- guarantee(k == probe->klass(), "klass should be in dictionary");
+ guarantee(k == probe->klass()->klass_part()->newest_version(), "klass should be in dictionary");
} else {
// If we don't find the class in the system dictionary, it
// has to be in the placeholders table.
diff --git a/src/share/vm/classfile/systemDictionary.cpp b/src/share/vm/classfile/systemDictionary.cpp
index 2fa221b..475aef9 100644
--- a/src/share/vm/classfile/systemDictionary.cpp
+++ b/src/share/vm/classfile/systemDictionary.cpp
@@ -157,6 +157,7 @@
// can return a null klass
klass = handle_resolution_exception(class_name, class_loader, protection_domain, throw_error, k_h, THREAD);
}
+ assert(klass == NULL || klass->klass_part()->is_newest_version() || klass->klass_part()->newest_version()->klass_part()->is_redefining(), "must be");
return klass;
}
@@ -199,7 +200,7 @@
// Forwards to resolve_instance_class_or_null
klassOop SystemDictionary::resolve_or_null(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS) {
- assert(!THREAD->is_Compiler_thread(),
+ assert(!THREAD->is_Compiler_thread() || JvmtiThreadState::state_for(JavaThread::current())->get_class_being_redefined() != NULL,
err_msg("can not load classes with compiler thread: class=%s, classloader=%s",
class_name->as_C_string(),
class_loader.is_null() ? "null" : class_loader->klass()->klass_part()->name()->as_C_string()));
@@ -961,8 +962,10 @@
instanceKlassHandle k = ClassFileParser(st).parseClassFile(class_name,
class_loader,
protection_domain,
+ KlassHandle(),
host_klass,
cp_patches,
+ NULL,
parsed_name,
true,
THREAD);
@@ -1022,7 +1025,15 @@
Handle protection_domain,
ClassFileStream* st,
bool verify,
+ KlassHandle old_class,
TRAPS) {
+
+ bool redefine_classes_locked = false;
+ if (!Thread::current()->redefine_classes_mutex()->owned_by_self()) {
+ Thread::current()->redefine_classes_mutex()->lock();
+ redefine_classes_locked = true;
+ }
+
// Classloaders that support parallelism, e.g. bootstrap classloader,
// or all classloaders with UnsyncloadClass do not acquire lock here
bool DoObjectLock = true;
@@ -1050,9 +1061,14 @@
instanceKlassHandle k = ClassFileParser(st).parseClassFile(class_name,
class_loader,
protection_domain,
+ old_class,
parsed_name,
verify,
THREAD);
+ if (!old_class.is_null() && !k.is_null()) {
+ k->set_redefining(true);
+ k->set_old_version(old_class());
+ }
const char* pkg = "java/";
if (!HAS_PENDING_EXCEPTION &&
@@ -1087,11 +1103,16 @@
// Add class just loaded
// If a class loader supports parallel classloading handle parallel define requests
// find_or_define_instance_class may return a different instanceKlass
- if (is_parallelCapable(class_loader)) {
+ // (tw) TODO: for class redefinition the parallel version does not work, check if this is a problem?
+ if (is_parallelCapable(class_loader) && old_class.is_null()) {
k = find_or_define_instance_class(class_name, class_loader, k, THREAD);
} else {
- define_instance_class(k, THREAD);
+ define_instance_class(k, old_class, THREAD);
}
+ }
+
+ if (redefine_classes_locked) {
+ Thread::current()->redefine_classes_mutex()->unlock();
}
// If parsing the class file or define_instance_class failed, we
@@ -1122,7 +1143,7 @@
MutexLocker mu(SystemDictionary_lock, THREAD);
klassOop check = find_class(parsed_name, class_loader);
- assert(check == k(), "should be present in the dictionary");
+ assert((check == k() && !k->is_redefining()) || (k->is_redefining() && check == k->old_version()), "should be present in the dictionary");
klassOop check2 = find_class(h_name, h_loader);
assert(check == check2, "name inconsistancy in SystemDictionary");
@@ -1349,7 +1370,11 @@
}
}
-void SystemDictionary::define_instance_class(instanceKlassHandle k, TRAPS) {
+void SystemDictionary::rollback_redefinition() {
+ dictionary()->rollback_redefinition();
+}
+
+void SystemDictionary::define_instance_class(instanceKlassHandle k, KlassHandle old_class, TRAPS) {
Handle class_loader_h(THREAD, k->class_loader());
@@ -1376,13 +1401,23 @@
Symbol* name_h = k->name();
unsigned int d_hash = dictionary()->compute_hash(name_h, class_loader_h);
int d_index = dictionary()->hash_to_index(d_hash);
- check_constraints(d_index, d_hash, k, class_loader_h, true, CHECK);
+
+ // (tw) Update version of the klassOop in the system dictionary
+ // TODO: Check for thread safety!
+ if (!old_class.is_null()) {
+ bool ok = dictionary()->update_klass(d_index, d_hash, name_h, class_loader_h, k, old_class);
+ assert (ok, "must have found old class and updated!");
+ }
+ check_constraints(d_index, d_hash, k, class_loader_h, old_class.is_null(), CHECK);
+
+ if(!old_class.is_null() && TraceRedefineClasses >= 3){ tty->print_cr("Class has been updated!"); }
// Register class just loaded with class loader (placed in Vector)
// Note we do this before updating the dictionary, as this can
// fail with an OutOfMemoryError (if it does, we will *not* put this
// class in the dictionary and will not update the class hierarchy).
- if (k->class_loader() != NULL) {
+ // (tw) Only register if not redefining a class.
+ if (k->class_loader() != NULL && old_class.is_null()) {
methodHandle m(THREAD, Universe::loader_addClass_method());
JavaValue result(T_VOID);
JavaCallArguments args(class_loader_h);
@@ -1408,8 +1443,9 @@
}
k->eager_initialize(THREAD);
+ // (tw) Only notify jvmti if not redefining a class.
// notify jvmti
- if (JvmtiExport::should_post_class_load()) {
+ if (JvmtiExport::should_post_class_load() && old_class.is_null()) {
assert(THREAD->is_Java_thread(), "thread->is_Java_thread()");
JvmtiExport::post_class_load((JavaThread *) THREAD, k());
@@ -1482,7 +1518,7 @@
}
}
- define_instance_class(k, THREAD);
+ define_instance_class(k, KlassHandle(), THREAD);
Handle linkage_exception = Handle(); // null handle
@@ -1613,6 +1649,14 @@
Universe::flush_dependents_on(k);
}
+// (tw) Remove from hierarchy - Undo add_to_hierarchy.
+void SystemDictionary::remove_from_hierarchy(instanceKlassHandle k) {
+ assert(k.not_null(), "just checking");
+
+ k->remove_from_sibling_list();
+
+ // TODO (tw): Remove from interfaces.
+}
// ----------------------------------------------------------------------------
// GC support
@@ -1870,9 +1914,12 @@
// Preload ref klasses and set reference types
instanceKlass::cast(WK_KLASS(Reference_klass))->set_reference_type(REF_OTHER);
- instanceRefKlass::update_nonstatic_oop_maps(WK_KLASS(Reference_klass));
+
+ // (tw) This is now done in parseClassFile in order to support class redefinition
+ // instanceRefKlass::update_nonstatic_oop_maps(WK_KLASS(Reference_klass));
initialize_wk_klasses_through(WK_KLASS_ENUM_NAME(Cleaner_klass), scan, CHECK);
+ // TODO(tw): Check that the following is also not necessary?
instanceKlass::cast(WK_KLASS(SoftReference_klass))->set_reference_type(REF_SOFT);
instanceKlass::cast(WK_KLASS(WeakReference_klass))->set_reference_type(REF_WEAK);
instanceKlass::cast(WK_KLASS(FinalReference_klass))->set_reference_type(REF_FINAL);
@@ -1957,7 +2004,7 @@
// also holds array classes
assert(check->klass_part()->oop_is_instance(), "noninstance in systemdictionary");
- if ((defining == true) || (k() != check)) {
+ if ((defining == true) && ((k() != check) && k->old_version() != check)) {
linkage_error = "loader (instance of %s): attempted duplicate class "
"definition for name: \"%s\"";
} else {
@@ -2617,8 +2664,10 @@
name = find_placeholder(class_name, class_loader);
}
}
- guarantee(probe != NULL || name != NULL,
- "Loaded klasses should be in SystemDictionary");
+ // (tw) Relaxed assertion to allow different class versions. Also allow redefining classes lie around (because of rollback).
+ guarantee(probe != NULL &&
+ (!probe->is_klass() || (!((klassOop)(obj()))->klass_part()->is_redefining()) || ((klassOop)probe)->klass_part()->is_same_or_older_version((klassOop)(obj()))) || ((klassOop)(obj()))->klass_part()->is_redefining(),
+ "Loaded klasses should be in SystemDictionary");
}
// utility function for posting class load event
diff --git a/src/share/vm/classfile/systemDictionary.hpp b/src/share/vm/classfile/systemDictionary.hpp
index 85474c5..570606f 100644
--- a/src/share/vm/classfile/systemDictionary.hpp
+++ b/src/share/vm/classfile/systemDictionary.hpp
@@ -270,7 +270,7 @@
// Resolve from stream (called by jni_DefineClass and JVM_DefineClass)
static klassOop resolve_from_stream(Symbol* class_name, Handle class_loader,
Handle protection_domain,
- ClassFileStream* st, bool verify, TRAPS);
+ ClassFileStream* st, bool verify, KlassHandle old_class, TRAPS);
// Lookup an already loaded class. If not found NULL is returned.
static klassOop find(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS);
@@ -345,6 +345,8 @@
// System loader lock
static oop system_loader_lock() { return _system_loader_lock_obj; }
+ // Remove link to hierarchy
+ static void remove_from_hierarchy(instanceKlassHandle k);
private:
// Traverses preloaded oops: various system classes. These are
// guaranteed to be in the perm gen.
@@ -416,6 +418,8 @@
int limit = (int)end_id + 1;
initialize_wk_klasses_until((WKID) limit, start_id, THREAD);
}
+
+ static void rollback_redefinition();
public:
#define WK_KLASS_DECLARE(name, symbol, option) \
@@ -598,7 +602,7 @@
// after waiting, but before reentering SystemDictionary_lock
// to preserve lock order semantics.
static void double_lock_wait(Handle lockObject, TRAPS);
- static void define_instance_class(instanceKlassHandle k, TRAPS);
+ static void define_instance_class(instanceKlassHandle k, KlassHandle old_class, TRAPS);
static instanceKlassHandle find_or_define_instance_class(Symbol* class_name,
Handle class_loader,
instanceKlassHandle k, TRAPS);
diff --git a/src/share/vm/classfile/verifier.cpp b/src/share/vm/classfile/verifier.cpp
index 49c4b2c..937f4f6 100644
--- a/src/share/vm/classfile/verifier.cpp
+++ b/src/share/vm/classfile/verifier.cpp
@@ -106,7 +106,7 @@
return !need_verify;
}
-bool Verifier::verify(instanceKlassHandle klass, Verifier::Mode mode, bool should_verify_class, TRAPS) {
+bool Verifier::verify(instanceKlassHandle klass, Verifier::Mode mode, bool should_verify_class, bool may_use_old_verifier, TRAPS) {
HandleMark hm;
ResourceMark rm(THREAD);
@@ -117,6 +117,7 @@
const char* klassName = klass->external_name();
bool can_failover = FailOverToOldVerifier &&
+ may_use_old_verifier &&
klass->major_version() < NOFAILOVER_MAJOR_VERSION;
// If the class should be verified, first see if we can use the split
@@ -138,6 +139,7 @@
tty->print_cr(
"Fail over class verification to old verifier for: %s", klassName);
}
+ assert(may_use_old_verifier, "");
exception_name = inference_verify(
klass, message_buffer, message_buffer_len, THREAD);
}
@@ -145,6 +147,7 @@
exception_message = split_verifier.exception_message();
}
} else {
+ assert(may_use_old_verifier, "");
exception_name = inference_verify(
klass, message_buffer, message_buffer_len, THREAD);
}
@@ -210,7 +213,7 @@
// NOTE: this is called too early in the bootstrapping process to be
// guarded by Universe::is_gte_jdk14x_version()/UseNewReflection.
(refl_magic_klass == NULL ||
- !klass->is_subtype_of(refl_magic_klass) ||
+ !(klass->is_subtype_of(refl_magic_klass) || klass->is_subtype_of(refl_magic_klass->klass_part()->newest_version())) ||
VerifyReflectionBytecodes)
);
}
@@ -517,7 +520,7 @@
ClassVerifier::ClassVerifier(
instanceKlassHandle klass, TRAPS)
- : _thread(THREAD), _exception_type(NULL), _message(NULL), _klass(klass) {
+ : _thread(THREAD), _exception_type(NULL), _message(NULL), _klass(klass->newest_version()), _klass_to_verify(klass) {
_this_type = VerificationType::reference_type(klass->name());
// Create list to hold symbols in reference area.
_symbols = new GrowableArray<Symbol*>(100, 0, NULL);
@@ -547,7 +550,7 @@
_klass->external_name());
}
- objArrayHandle methods(THREAD, _klass->methods());
+ objArrayHandle methods(THREAD, _klass_to_verify->methods());
int num_methods = methods->length();
for (int index = 0; index < num_methods; index++) {
@@ -2668,7 +2671,8 @@
VerificationType stack_object_type =
current_frame->pop_stack(ref_class_type, CHECK_VERIFY(this));
if (current_type() != stack_object_type) {
- assert(cp->cache() == NULL, "not rewritten yet");
+ // (tw) TODO: Check if relaxing the following assertion is correct. For class redefinition we might call the verifier twice.
+ //assert(cp->cache() == NULL, "not rewritten yet");
Symbol* ref_class_name =
cp->klass_name_at(cp->klass_ref_index_at(index));
// See the comments in verify_field_instructions() for
diff --git a/src/share/vm/classfile/verifier.hpp b/src/share/vm/classfile/verifier.hpp
index 92c4fd2..5e8e0da 100644
--- a/src/share/vm/classfile/verifier.hpp
+++ b/src/share/vm/classfile/verifier.hpp
@@ -48,7 +48,7 @@
* Otherwise, no exception is thrown and the return indicates the
* error.
*/
- static bool verify(instanceKlassHandle klass, Mode mode, bool should_verify_class, TRAPS);
+ static bool verify(instanceKlassHandle klass, Mode mode, bool should_verify_class, bool may_use_old_verifier, TRAPS);
// Return false if the class is loaded by the bootstrap loader,
// or if defineClass was called requesting skipping verification
@@ -257,7 +257,10 @@
ErrorContext _error_context; // contains information about an error
+public:
void verify_method(methodHandle method, TRAPS);
+
+private:
char* generate_code_data(methodHandle m, u4 code_length, TRAPS);
void verify_exception_handler_table(u4 code_length, char* code_data,
int& min, int& max, TRAPS);
@@ -341,6 +344,7 @@
VerificationType object_type() const;
+ instanceKlassHandle _klass_to_verify;
instanceKlassHandle _klass; // the class being verified
methodHandle _method; // current method being verified
VerificationType _this_type; // the verification type of the current class
diff --git a/src/share/vm/code/nmethod.cpp b/src/share/vm/code/nmethod.cpp
index dddbea2..d5918cd 100644
--- a/src/share/vm/code/nmethod.cpp
+++ b/src/share/vm/code/nmethod.cpp
@@ -2083,15 +2083,14 @@
methodOop method = deps.method_argument(0);
for (int j = 0; j < dependee_methods->length(); j++) {
if ((methodOop) dependee_methods->obj_at(j) == method) {
- // RC_TRACE macro has an embedded ResourceMark
- RC_TRACE(0x01000000,
- ("Found evol dependency of nmethod %s.%s(%s) compile_id=%d on method %s.%s(%s)",
+ ResourceMark rm(Thread::current());
+ TRACE_RC3("Found evol dependency of nmethod %s.%s(%s) compile_id=%d on method %s.%s(%s)",
_method->method_holder()->klass_part()->external_name(),