forked from dcevm/dcevm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
light-jdk8u5-b13.patch
3679 lines (3563 loc) · 148 KB
/
light-jdk8u5-b13.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/share/vm/ci/ciObjectFactory.cpp b/src/share/vm/ci/ciObjectFactory.cpp
--- a/src/share/vm/ci/ciObjectFactory.cpp
+++ b/src/share/vm/ci/ciObjectFactory.cpp
@@ -750,3 +750,27 @@
_unloaded_instances->length(),
_unloaded_klasses->length());
}
+
+int ciObjectFactory::compare_cimetadata(ciMetadata** a, ciMetadata** b) {
+ Metadata* am = (*a)->constant_encoding();
+ Metadata* bm = (*b)->constant_encoding();
+ return ((am > bm) ? 1 : ((am == bm) ? 0 : -1));
+}
+
+// (DCEVM) Resoring the ciObject arrays after class redefinition
+void ciObjectFactory::resort_shared_ci_metadata() {
+ if (_shared_ci_metadata == NULL) return;
+ _shared_ci_metadata->sort(ciObjectFactory::compare_cimetadata);
+
+#ifdef ASSERT
+ if (CIObjectFactoryVerify) {
+ Metadata* last = NULL;
+ for (int j = 0; j< _shared_ci_metadata->length(); j++) {
+ Metadata* o = _shared_ci_metadata->at(j)->constant_encoding();
+ 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
--- a/src/share/vm/ci/ciObjectFactory.hpp
+++ b/src/share/vm/ci/ciObjectFactory.hpp
@@ -90,6 +90,7 @@
ciInstance* get_unloaded_instance(ciInstanceKlass* klass);
+ static int compare_cimetadata(ciMetadata** a, ciMetadata** b);
public:
static bool is_initialized() { return _initialized; }
@@ -145,6 +146,8 @@
void print_contents();
void print();
+
+ static void resort_shared_ci_metadata();
};
#endif // SHARE_VM_CI_CIOBJECTFACTORY_HPP
diff --git a/src/share/vm/classfile/classFileParser.cpp b/src/share/vm/classfile/classFileParser.cpp
--- a/src/share/vm/classfile/classFileParser.cpp
+++ b/src/share/vm/classfile/classFileParser.cpp
@@ -759,6 +759,7 @@
Array<Klass*>* ClassFileParser::parse_interfaces(int length,
Handle protection_domain,
Symbol* class_name,
+ bool pick_newest,
bool* has_default_methods,
TRAPS) {
if (length == 0) {
@@ -777,7 +778,11 @@
"Interface name has bad constant pool index %u in class file %s",
interface_index, CHECK_NULL);
if (_cp->tag_at(interface_index).is_klass()) {
- interf = KlassHandle(THREAD, _cp->resolved_klass_at(interface_index));
+ Klass* resolved_klass = _cp->resolved_klass_at(interface_index);
+ if (pick_newest) {
+ resolved_klass = resolved_klass->newest_version();
+ }
+ interf = KlassHandle(THREAD, resolved_klass);
} else {
Symbol* unresolved_klass = _cp->klass_name_at(interface_index);
@@ -791,6 +796,9 @@
Klass* k = SystemDictionary::resolve_super_or_fail(class_name,
unresolved_klass, class_loader, protection_domain,
false, CHECK_NULL);
+ if (pick_newest) {
+ k = k->newest_version();
+ }
interf = KlassHandle(THREAD, k);
}
@@ -3093,6 +3101,7 @@
}
instanceKlassHandle ClassFileParser::parse_super_class(int super_class_index,
+ bool pick_newest,
TRAPS) {
instanceKlassHandle super_klass;
if (super_class_index == 0) {
@@ -3109,7 +3118,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));
+ Klass* resolved_klass = _cp->resolved_klass_at(super_class_index);
+ if (pick_newest) {
+ resolved_klass = resolved_klass->newest_version();
+ }
+ super_klass = instanceKlassHandle(THREAD, resolved_klass);
if (_need_verify)
is_array = super_klass->oop_is_array();
} else if (_need_verify) {
@@ -3658,8 +3671,10 @@
instanceKlassHandle ClassFileParser::parseClassFile(Symbol* name,
ClassLoaderData* loader_data,
Handle protection_domain,
+ KlassHandle old_klass,
KlassHandle host_klass,
GrowableArray<Handle>* cp_patches,
+ GrowableArray<Symbol*>* parsed_super_symbols,
TempNewSymbol& parsed_name,
bool verify,
TRAPS) {
@@ -3672,6 +3687,7 @@
JvmtiCachedClassFileData *cached_class_file = NULL;
Handle class_loader(THREAD, loader_data->class_loader());
bool has_default_methods = false;
+ bool pick_newest = !old_klass.is_null();
ResourceMark rm(THREAD);
ClassFileStream* cfs = stream();
@@ -3688,7 +3704,7 @@
init_parsed_class_attributes(loader_data);
- 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
@@ -3823,6 +3839,26 @@
CHECK_(nullHandle));
}
+ // (DCEVM) 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();
+ Array<Klass*>* local_interfaces =
+ parse_interfaces(itfs_len, protection_domain, _class_name, pick_newest, &has_default_methods, CHECK_NULL);
+
+ for (int i = 0; i < local_interfaces->length(); i++) {
+ Klass* o = local_interfaces->at(i);
+ parsed_super_symbols->append(o->name());
+ }
+ return NULL;
+ }
+
Klass* preserve_this_klass; // for storing result across HandleMark
// release all handles when parsing is done
@@ -3849,13 +3885,14 @@
u2 super_class_index = cfs->get_u2_fast();
instanceKlassHandle super_klass = parse_super_class(super_class_index,
+ pick_newest,
CHECK_NULL);
// Interfaces
u2 itfs_len = cfs->get_u2_fast();
Array<Klass*>* local_interfaces =
parse_interfaces(itfs_len, protection_domain, _class_name,
- &has_default_methods, CHECK_(nullHandle));
+ pick_newest, &has_default_methods, CHECK_(nullHandle));
u2 java_fields_count = 0;
// Fields (offsets are filled in later)
@@ -3897,6 +3934,9 @@
true,
CHECK_(nullHandle));
+ if (pick_newest) {
+ k = k->newest_version();
+ }
KlassHandle kh (THREAD, k);
super_klass = instanceKlassHandle(THREAD, kh());
}
@@ -4056,7 +4096,7 @@
fill_oop_maps(this_klass, info.nonstatic_oop_map_count, info.nonstatic_oop_offsets, info.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));
@@ -4283,7 +4323,7 @@
}
-void ClassFileParser::set_precomputed_flags(instanceKlassHandle k) {
+void ClassFileParser::set_precomputed_flags(instanceKlassHandle k, KlassHandle old_klass) {
Klass* super = k->super();
// Check if this klass has an empty finalize method (i.e. one with return bytecode only),
@@ -4291,7 +4331,9 @@
if (!_has_empty_finalizer) {
if (_has_finalizer ||
(super != NULL && super->has_finalizer())) {
- k->set_has_finalizer();
+ if (old_klass.is_null() || old_klass->has_finalizer()) {
+ k->set_has_finalizer();
+ }
}
}
@@ -4307,7 +4349,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()->newest_version())) {
k->set_is_cloneable();
}
}
diff --git a/src/share/vm/classfile/classFileParser.hpp b/src/share/vm/classfile/classFileParser.hpp
--- a/src/share/vm/classfile/classFileParser.hpp
+++ b/src/share/vm/classfile/classFileParser.hpp
@@ -214,11 +214,12 @@
Array<Klass*>* parse_interfaces(int length,
Handle protection_domain,
Symbol* class_name,
+ bool pick_newest,
bool* has_default_methods,
TRAPS);
void record_defined_class_dependencies(instanceKlassHandle defined_klass, TRAPS);
- instanceKlassHandle parse_super_class(int super_class_index, TRAPS);
+ instanceKlassHandle parse_super_class(int super_class_index, bool pick_newest, TRAPS);
// Field parsing
void parse_field_attributes(u2 attributes_count,
bool is_static, u2 signature_index,
@@ -299,7 +300,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);
Array<Klass*>* compute_transitive_interfaces(instanceKlassHandle super,
Array<Klass*>* local_ifs, TRAPS);
@@ -461,17 +462,20 @@
instanceKlassHandle parseClassFile(Symbol* name,
ClassLoaderData* loader_data,
Handle protection_domain,
+ KlassHandle old_klass,
TempNewSymbol& parsed_name,
bool verify,
TRAPS) {
KlassHandle no_host_klass;
- return parseClassFile(name, loader_data, protection_domain, no_host_klass, NULL, parsed_name, verify, THREAD);
+ return parseClassFile(name, loader_data, protection_domain, old_klass, no_host_klass, NULL, NULL, parsed_name, verify, THREAD);
}
instanceKlassHandle parseClassFile(Symbol* name,
ClassLoaderData* loader_data,
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
--- a/src/share/vm/classfile/classLoader.cpp
+++ b/src/share/vm/classfile/classLoader.cpp
@@ -926,6 +926,7 @@
instanceKlassHandle result = parser.parseClassFile(h_name,
loader_data,
protection_domain,
+ KlassHandle(),
parsed_name,
false,
CHECK_(h));
diff --git a/src/share/vm/classfile/dictionary.cpp b/src/share/vm/classfile/dictionary.cpp
--- a/src/share/vm/classfile/dictionary.cpp
+++ b/src/share/vm/classfile/dictionary.cpp
@@ -145,7 +145,7 @@
InstanceKlass* ik = InstanceKlass::cast(e);
// Non-unloadable classes were handled in always_strong_oops_do
- if (!is_strongly_reachable(loader_data, e)) {
+ if (!ik->is_redefining() && !is_strongly_reachable(loader_data, e)) {
// Entry was not visited in phase1 (negated test from phase1)
assert(!loader_data->is_the_null_class_loader_data(), "unloading entry with null class loader");
ClassLoaderData* k_def_class_loader_data = ik->class_loader_data();
@@ -336,6 +336,32 @@
add_entry(index, entry);
}
+// (DCEVM) Updates the klass entry to point to the new Klass*. Necessary only for class redefinition.
+bool Dictionary::update_klass(int index, unsigned int hash, Symbol* name, ClassLoaderData* loader_data, 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;
+}
+
+// (DCEVM) 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()->is_redefining()) {
+ entry->set_literal(entry->klass()->old_version());
+ }
+ }
+ }
+}
// This routine does not lock the system dictionary.
//
@@ -366,7 +392,7 @@
ClassLoaderData* loader_data, Handle protection_domain, TRAPS) {
DictionaryEntry* entry = get_entry(index, hash, name, loader_data);
if (entry != NULL && entry->is_valid_protection_domain(protection_domain)) {
- return entry->klass();
+ return intercept_for_version(entry->klass());
} else {
return NULL;
}
@@ -379,7 +405,7 @@
assert (index == index_for(name, loader_data), "incorrect index?");
DictionaryEntry* entry = get_entry(index, hash, name, loader_data);
- return (entry != NULL) ? entry->klass() : (Klass*)NULL;
+ return intercept_for_version((entry != NULL) ? entry->klass() : (Klass*)NULL);
}
@@ -391,7 +417,7 @@
assert (index == index_for(name, NULL), "incorrect index?");
DictionaryEntry* entry = get_entry(index, hash, name, NULL);
- return (entry != NULL) ? entry->klass() : (Klass*)NULL;
+ return intercept_for_version((entry != NULL) ? entry->klass() : (Klass*)NULL);
}
diff --git a/src/share/vm/classfile/dictionary.hpp b/src/share/vm/classfile/dictionary.hpp
--- a/src/share/vm/classfile/dictionary.hpp
+++ b/src/share/vm/classfile/dictionary.hpp
@@ -78,6 +78,10 @@
void add_klass(Symbol* class_name, ClassLoaderData* loader_data,KlassHandle obj);
+ bool update_klass(int index, unsigned int hash, Symbol* name, ClassLoaderData* loader_data, KlassHandle k, KlassHandle old_class);
+
+ void rollback_redefinition();
+
Klass* find_class(int index, unsigned int hash,
Symbol* name, ClassLoaderData* loader_data);
@@ -107,6 +111,11 @@
return (loader_data->is_the_null_class_loader_data() || !ClassUnloading);
}
+ // (DCEVM) During enhanced class redefinition we want old version if new is being redefined
+ static Klass* intercept_for_version(Klass* k) {
+ return (k != NULL && k->is_redefining()) ? k->old_version() : k;
+ }
+
// Unload (that is, break root links to) all unmarked classes and
// loaders. Returns "true" iff something was unloaded.
bool do_unloading();
diff --git a/src/share/vm/classfile/javaClasses.cpp b/src/share/vm/classfile/javaClasses.cpp
--- a/src/share/vm/classfile/javaClasses.cpp
+++ b/src/share/vm/classfile/javaClasses.cpp
@@ -1629,6 +1629,8 @@
skip_throwableInit_check = true;
}
}
+ // (DCEVM): Line numbers from newest version must be used for EMCP-swapped methods
+ method = method->newest_version();
if (method->is_hidden()) {
if (skip_hidden) continue;
}
diff --git a/src/share/vm/classfile/loaderConstraints.cpp b/src/share/vm/classfile/loaderConstraints.cpp
--- a/src/share/vm/classfile/loaderConstraints.cpp
+++ b/src/share/vm/classfile/loaderConstraints.cpp
@@ -446,7 +446,7 @@
if (k != NULL) {
// We found the class in the system dictionary, so we should
// make sure that the Klass* matches what we already have.
- guarantee(k == probe->klass(), "klass should be in dictionary");
+ guarantee(k == probe->klass()->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
--- a/src/share/vm/classfile/systemDictionary.cpp
+++ b/src/share/vm/classfile/systemDictionary.cpp
@@ -174,6 +174,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->is_newest_version() || klass->newest_version()->is_redefining(), "must be");
return klass;
}
@@ -216,7 +217,7 @@
// Forwards to resolve_instance_class_or_null
Klass* 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()->name()->as_C_string()));
@@ -1029,8 +1030,10 @@
instanceKlassHandle k = ClassFileParser(st).parseClassFile(class_name,
loader_data,
protection_domain,
+ KlassHandle(),
host_klass,
cp_patches,
+ NULL,
parsed_name,
true,
THREAD);
@@ -1085,6 +1088,7 @@
Handle protection_domain,
ClassFileStream* st,
bool verify,
+ KlassHandle old_class,
TRAPS) {
// Classloaders that support parallelism, e.g. bootstrap classloader,
@@ -1112,9 +1116,15 @@
instanceKlassHandle k = ClassFileParser(st).parseClassFile(class_name,
loader_data,
protection_domain,
+ old_class,
parsed_name,
verify,
THREAD);
+ // (DCEVM) During enhanced class redefinition, mark loaded class as being redefined
+ 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 &&
@@ -1149,10 +1159,11 @@
// 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)) {
+ // (DCEVM) 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);
}
}
@@ -1166,7 +1177,7 @@
MutexLocker mu(SystemDictionary_lock, THREAD);
Klass* check = find_class(parsed_name, loader_data);
- 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");
Klass* check2 = find_class(h_name, defining_loader_data);
assert(check == check2, "name inconsistancy in SystemDictionary");
@@ -1386,7 +1397,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) {
ClassLoaderData* loader_data = k->class_loader_data();
Handle class_loader_h(THREAD, loader_data->class_loader());
@@ -1416,7 +1431,17 @@
Symbol* name_h = k->name();
unsigned int d_hash = dictionary()->compute_hash(name_h, loader_data);
int d_index = dictionary()->hash_to_index(d_hash);
- check_constraints(d_index, d_hash, k, class_loader_h, true, CHECK);
+
+ // (DCEVM) Update version of the Klass* 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, loader_data, 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);
+
+ // FIXME: (DCEVM) clean this...
+ 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
@@ -1449,8 +1474,9 @@
}
k->eager_initialize(THREAD);
+ // (DCEVM) 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());
@@ -1524,7 +1550,7 @@
}
}
- define_instance_class(k, THREAD);
+ define_instance_class(k, KlassHandle(), THREAD);
Handle linkage_exception = Handle(); // null handle
@@ -1654,6 +1680,14 @@
Universe::flush_dependents_on(k);
}
+// (DCEVM) Remove from hierarchy - Undo add_to_hierarchy.
+void SystemDictionary::remove_from_hierarchy(instanceKlassHandle k) {
+ assert(k.not_null(), "just checking");
+
+ // remove receiver from sibling list
+ k->remove_from_sibling_list();
+ // TODO (DCEVM): Remove from interfaces.
+}
// ----------------------------------------------------------------------------
// GC support
@@ -2000,7 +2034,7 @@
// also holds array classes
assert(check->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 {
diff --git a/src/share/vm/classfile/systemDictionary.hpp b/src/share/vm/classfile/systemDictionary.hpp
--- a/src/share/vm/classfile/systemDictionary.hpp
+++ b/src/share/vm/classfile/systemDictionary.hpp
@@ -271,7 +271,7 @@
// Resolve from stream (called by jni_DefineClass and JVM_DefineClass)
static Klass* 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 Klass* find(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS);
@@ -341,6 +341,8 @@
// System loader lock
static oop system_loader_lock() { return _system_loader_lock_obj; }
+ // (DCEVM) Remove link to hierarchy
+ static void remove_from_hierarchy(instanceKlassHandle k);
private:
// Extended Redefine classes support (tbi)
static void preloaded_classes_do(KlassClosure* f);
@@ -410,6 +412,9 @@
initialize_wk_klasses_until((WKID) limit, start_id, THREAD);
}
+ // (DCEVM) rollback class redefinition
+ static void rollback_redefinition();
+
public:
#define WK_KLASS_DECLARE(name, symbol, option) \
static Klass* name() { return check_klass_##option(_well_known_klasses[WK_KLASS_ENUM_NAME(name)]); } \
@@ -615,7 +620,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
--- a/src/share/vm/classfile/verifier.cpp
+++ b/src/share/vm/classfile/verifier.cpp
@@ -189,7 +189,7 @@
Symbol* name = klass->name();
Klass* refl_magic_klass = SystemDictionary::reflect_MagicAccessorImpl_klass();
- bool is_reflect = refl_magic_klass != NULL && klass->is_subtype_of(refl_magic_klass);
+ bool is_reflect = refl_magic_klass != NULL && (klass->is_subtype_of(refl_magic_klass) || klass->is_subtype_of(refl_magic_klass->newest_version()));
return (should_verify_for(klass->class_loader(), should_verify_class) &&
// return if the class is a bootstrapping class
@@ -518,7 +518,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);
@@ -548,7 +548,7 @@
_klass->external_name());
}
- Array<Method*>* methods = _klass->methods();
+ Array<Method*>* methods = _klass_to_verify->methods();
int num_methods = methods->length();
for (int index = 0; index < num_methods; index++) {
diff --git a/src/share/vm/classfile/verifier.hpp b/src/share/vm/classfile/verifier.hpp
--- a/src/share/vm/classfile/verifier.hpp
+++ b/src/share/vm/classfile/verifier.hpp
@@ -331,6 +331,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/interpreter/linkResolver.cpp b/src/share/vm/interpreter/linkResolver.cpp
--- a/src/share/vm/interpreter/linkResolver.cpp
+++ b/src/share/vm/interpreter/linkResolver.cpp
@@ -215,8 +215,8 @@
// Klass resolution
void LinkResolver::check_klass_accessability(KlassHandle ref_klass, KlassHandle sel_klass, TRAPS) {
- if (!Reflection::verify_class_access(ref_klass(),
- sel_klass(),
+ if (!Reflection::verify_class_access(ref_klass()->newest_version(),
+ sel_klass()->newest_version(),
true)) {
ResourceMark rm(THREAD);
Exceptions::fthrow(
@@ -444,7 +444,7 @@
// We'll check for the method name first, as that's most likely
// to be false (so we'll short-circuit out of these tests).
if (sel_method->name() == vmSymbols::clone_name() &&
- sel_klass() == SystemDictionary::Object_klass() &&
+ sel_klass()->newest_version() == SystemDictionary::Object_klass()->newest_version() &&
resolved_klass->oop_is_array()) {
// We need to change "protected" to "public".
assert(flags.is_protected(), "clone not protected?");
@@ -802,7 +802,7 @@
}
// Final fields can only be accessed from its own class.
- if (is_put && fd.access_flags().is_final() && sel_klass() != current_klass()) {
+ if (is_put && fd.access_flags().is_final() && sel_klass() != current_klass() && sel_klass() != current_klass()->active_version()) {
THROW(vmSymbols::java_lang_IllegalAccessError());
}
@@ -1199,6 +1199,8 @@
// recv_klass might be an arrayKlassOop but all vtables start at
// the same place. The cast is to avoid virtual call and assertion.
InstanceKlass* inst = (InstanceKlass*)recv_klass();
+ // (DCEVM) Check that the receiver is a subtype of the holder of the resolved method.
+ assert(inst->is_subtype_of(resolved_method->method_holder()), "receiver and resolved method holder are inconsistent");
selected_method = methodHandle(THREAD, inst->method_at_vtable(vtable_index));
}
}
diff --git a/src/share/vm/memory/universe.cpp b/src/share/vm/memory/universe.cpp
--- a/src/share/vm/memory/universe.cpp
+++ b/src/share/vm/memory/universe.cpp
@@ -159,6 +159,42 @@
f(doubleArrayKlassObj());
}
+// (DCEVM) This method should iterate all pointers that are not within heap objects.
+void Universe::root_oops_do(OopClosure *oopClosure) {
+
+ class AlwaysTrueClosure: public BoolObjectClosure {
+ public:
+ void do_object(oop p) { ShouldNotReachHere(); }
+ bool do_object_b(oop p) { return true; }
+ };
+ AlwaysTrueClosure always_true;
+
+ Universe::oops_do(oopClosure);
+// ReferenceProcessor::oops_do(oopClosure); (tw) check why no longer there
+ JNIHandles::oops_do(oopClosure); // Global (strong) JNI handles
+ Threads::oops_do(oopClosure, NULL, NULL);
+ ObjectSynchronizer::oops_do(oopClosure);
+ FlatProfiler::oops_do(oopClosure);
+ JvmtiExport::oops_do(oopClosure);
+
+ // Now adjust pointers in remaining weak roots. (All of which should
+ // have been cleared if they pointed to non-surviving objects.)
+ // Global (weak) JNI handles
+ JNIHandles::weak_oops_do(&always_true, oopClosure);
+
+ CodeCache::oops_do(oopClosure);
+ StringTable::oops_do(oopClosure);
+
+ // (DCEVM) TODO: Check if this is correct?
+ //CodeCache::scavenge_root_nmethods_oops_do(oopClosure);
+ //Management::oops_do(oopClosure);
+ //ref_processor()->weak_oops_do(&oopClosure);
+ //PSScavenge::reference_processor()->weak_oops_do(&oopClosure);
+
+ // SO_AllClasses
+ SystemDictionary::oops_do(oopClosure);
+}
+
void Universe::oops_do(OopClosure* f, bool do_all) {
f->do_oop((oop*) &_int_mirror);
diff --git a/src/share/vm/memory/universe.hpp b/src/share/vm/memory/universe.hpp
--- a/src/share/vm/memory/universe.hpp
+++ b/src/share/vm/memory/universe.hpp
@@ -407,6 +407,7 @@
static void run_finalizers_on_exit();
// Iteration
+ static void root_oops_do(OopClosure *f);
// Apply "f" to the addresses of all the direct heap pointers maintained
// as static fields of "Universe".
diff --git a/src/share/vm/oops/cpCache.cpp b/src/share/vm/oops/cpCache.cpp
--- a/src/share/vm/oops/cpCache.cpp
+++ b/src/share/vm/oops/cpCache.cpp
@@ -336,7 +336,8 @@
if (has_appendix) {
const int appendix_index = f2_as_index() + _indy_resolved_references_appendix_offset;
assert(appendix_index >= 0 && appendix_index < resolved_references->length(), "oob");
- assert(resolved_references->obj_at(appendix_index) == NULL, "init just once");
+ // FIXME (DCEVM) relaxing for now...
+ //assert(resolved_references->obj_at(appendix_index) == NULL, "init just once");
resolved_references->obj_at_put(appendix_index, appendix());
}
@@ -344,7 +345,8 @@
if (has_method_type) {
const int method_type_index = f2_as_index() + _indy_resolved_references_method_type_offset;
assert(method_type_index >= 0 && method_type_index < resolved_references->length(), "oob");
- assert(resolved_references->obj_at(method_type_index) == NULL, "init just once");
+ // FIXME (DCEVM) relaxing for now...
+ //assert(resolved_references->obj_at(method_type_index) == NULL, "init just once");
resolved_references->obj_at_put(method_type_index, method_type());
}
@@ -532,6 +534,27 @@
// the method is in the interesting class so the entry is interesting
return true;
}
+
+// Enhanced RedefineClasses() API support (DCEVM):
+// Clear cached entry, let it be re-resolved
+void ConstantPoolCacheEntry::clear_entry() {
+ if (_indices == constant_pool_index() ||
+ bytecode_1() == Bytecodes::_invokehandle ||
+ bytecode_1() == Bytecodes::_invokedynamic) {
+ // Entry wasn't initialized yet or was initialized for invokehandle/invokedynamic.
+ // Don't clear it since f2 will not be reset during entry re-resolution.
+ return;
+ }
+ _indices = constant_pool_index();
+ _f1 = NULL;
+ _f2 = 0;
+
+ // FIXME: (DCEVM) we want to clear flags, but parameter size is actually used
+ // after we return from the method, before entry is re-initialized. So let's
+ // keep parameter size the same.
+ // For example, it's used in TemplateInterpreterGenerator::generate_return_entry_for
+ _flags &= 0x0000000f;
+}
#endif // INCLUDE_JVMTI
void ConstantPoolCacheEntry::print(outputStream* st, int index) const {
@@ -660,6 +683,14 @@
}
}
}
+
+// Enhanced RedefineClasses() API support (DCEVM):
+// Clear all entries
+void ConstantPoolCache::clear_entries() {
+ for (int i = 0; i < length(); i++) {
+ entry_at(i)->clear_entry();
+ }
+}
#endif // INCLUDE_JVMTI
diff --git a/src/share/vm/oops/cpCache.hpp b/src/share/vm/oops/cpCache.hpp
--- a/src/share/vm/oops/cpCache.hpp
+++ b/src/share/vm/oops/cpCache.hpp
@@ -373,6 +373,10 @@
bool * trace_name_printed);
bool check_no_old_or_obsolete_entries();
bool is_interesting_method_entry(Klass* k);
+
+ // Enhanced RedefineClasses() API support (DCEVM):
+ // Clear cached entry, let it be re-resolved
+ void clear_entry();
#endif // INCLUDE_JVMTI
// Debugging & Printing
@@ -472,6 +476,10 @@
int methods_length, bool * trace_name_printed);
bool check_no_old_or_obsolete_entries();
void dump_cache();
+
+ // Enhanced RedefineClasses() API support (DCEVM):
+ // Clear all entries
+ void clear_entries();
#endif // INCLUDE_JVMTI
// Deallocate - no fields to deallocate
diff --git a/src/share/vm/oops/instanceKlass.cpp b/src/share/vm/oops/instanceKlass.cpp
--- a/src/share/vm/oops/instanceKlass.cpp
+++ b/src/share/vm/oops/instanceKlass.cpp
@@ -718,7 +718,8 @@
}
#endif
this_oop->set_init_state(linked);
- if (JvmtiExport::should_post_class_prepare()) {
+ // (DCEVM) Must check for old version in order to prevent infinite loops.
+ if (JvmtiExport::should_post_class_prepare() && this_oop->old_version() == NULL /* JVMTI deadlock otherwise */) {
Thread *thread = THREAD;
assert(thread->is_Java_thread(), "thread->is_Java_thread()");
JvmtiExport::post_class_prepare((JavaThread *) thread, this_oop());
@@ -795,7 +796,9 @@
// If we were to use wait() instead of waitInterruptibly() then
// we might end up throwing IE from link/symbol resolution sites
// that aren't expected to throw. This would wreak havoc. See 6320309.
- while(this_oop->is_being_initialized() && !this_oop->is_reentrant_initialization(self)) {
+ // (DCEVM) Wait also for the old class version to be fully initialized.
+ while((this_oop->is_being_initialized() && !this_oop->is_reentrant_initialization(self))
+ || (this_oop->old_version() != NULL && InstanceKlass::cast(this_oop->old_version())->is_being_initialized())) {
wait = true;
ol.waitUninterruptibly(CHECK);
}
@@ -1051,6 +1054,18 @@
return false;
}
+bool InstanceKlass::implements_interface_any_version(Klass* k) const {
+ k = k->newest_version();
+ if (this->newest_version() == k) return true;
+ assert(k->is_interface(), "should be an interface class");
+ for (int i = 0; i < transitive_interfaces()->length(); i++) {
+ if (transitive_interfaces()->at(i)->newest_version() == k) {
+ return true;
+ }
+ }
+ return false;
+}
+
bool InstanceKlass::is_same_or_direct_interface(Klass *k) const {
// Verify direct super interface
if (this == k) return true;
@@ -1314,6 +1329,18 @@
}
}
+void InstanceKlass::store_update_information(GrowableArray<int> &values) {
+ int *arr = NEW_C_HEAP_ARRAY(int, values.length(), mtClass);
+ for (int i=0; i<values.length(); i++) {
+ arr[i] = values.at(i);
+ }
+ set_update_information(arr);
+}
+
+void InstanceKlass::clear_update_information() {
+ FREE_C_HEAP_ARRAY(int, update_information(), mtClass);
+ set_update_information(NULL);
+}
void InstanceKlass::do_local_static_fields(FieldClosure* cl) {
for (JavaFieldStream fs(this); !fs.done(); fs.next()) {
@@ -1797,6 +1824,18 @@
return id;
}
+bool InstanceKlass::update_jmethod_id(Method* method, jmethodID newMethodID) {
+ size_t idnum = (size_t)method->method_idnum();
+ jmethodID* jmeths = methods_jmethod_ids_acquire();
+ size_t length; // length assigned as debugging crumb
+ jmethodID id = NULL;
+ if (jmeths != NULL && // If there is a cache
+ (length = (size_t)jmeths[0]) > idnum) { // and if it is long enough,
+ jmeths[idnum+1] = newMethodID; // Set method id (may be NULL)
+ return true;
+ }
+ return false;
+}
//
// Walk the list of dependent nmethods searching for nmethods which
@@ -1875,6 +1914,13 @@
last = b;
b = b->next();
}
+
+ // (DCEVM) Hack as dependencies get wrong version of Klass*
+ if (this->old_version() != NULL) {
+ InstanceKlass::cast(this->old_version())->remove_dependent_nmethod(nm);
+ return;
+ }
+
#ifdef ASSERT
tty->print_cr("### %s can't find dependent nmethod:", this->external_name());
nm->print();
@@ -2884,6 +2930,24 @@
assert(is_klass(), "must be klass");
Klass::print_on(st);
+ // (DCEVM) Output revision number and revision numbers of older / newer and oldest / newest version of this class.
+ if (AllowEnhancedClassRedefinition) {
+ st->print(BULLET"revision: %d", revision_number());
+ if (new_version() != NULL) {
+ st->print(" (newer=%d)", new_version()->revision_number());
+ }
+ if (newest_version() != new_version() && newest_version() != this) {
+ st->print(" (newest=%d)", newest_version()->revision_number());
+ }
+ if (old_version() != NULL) {
+ st->print(" (old=%d)", old_version()->revision_number());
+ }
+ if (oldest_version() != old_version() && oldest_version() != this) {
+ st->print(" (oldest=%d)", oldest_version()->revision_number());
+ }
+ st->cr();
+ }
+
st->print(BULLET"instance size: %d", size_helper()); st->cr();
st->print(BULLET"klass size: %d", size()); st->cr();
st->print(BULLET"access: "); access_flags().print_on(st); st->cr();
@@ -3219,7 +3283,7 @@
}
guarantee(sib->is_klass(), "should be klass");
- guarantee(sib->super() == super, "siblings should have same superklass");
+ guarantee(sib->super() == super || super->newest_version() == SystemDictionary::Object_klass(), "siblings should have same superklass");
}
// Verify implementor fields
@@ -3384,6 +3448,7 @@
// Purge previous versions
static void purge_previous_versions_internal(InstanceKlass* ik, int emcp_method_count) {
+ // FIXME: (DCEVM) Should we purge something?
if (ik->previous_versions() != NULL) {
// This klass has previous versions so see what we can cleanup
// while it is safe to do so.
@@ -3621,7 +3686,7 @@
// Determine if InstanceKlass has a previous version.
bool InstanceKlass::has_previous_version() const {
- return (_previous_versions != NULL && _previous_versions->length() > 0);
+ return _old_version != NULL || (_previous_versions != NULL && _previous_versions->length() > 0);
} // end has_previous_version()
diff --git a/src/share/vm/oops/instanceKlass.hpp b/src/share/vm/oops/instanceKlass.hpp
--- a/src/share/vm/oops/instanceKlass.hpp
+++ b/src/share/vm/oops/instanceKlass.hpp
@@ -139,6 +139,7 @@
friend class VMStructs;
friend class ClassFileParser;
friend class CompileReplay;
+ friend class VM_EnhancedRedefineClasses;
protected:
// Constructor
@@ -637,7 +638,7 @@
// If the _previous_versions array is non-NULL, then this klass
// has been redefined at least once even if we aren't currently
// tracking a previous version.
- bool has_been_redefined() const { return _previous_versions != NULL; }
+ bool has_been_redefined() const { return _old_version != NULL || _previous_versions != NULL; }
bool has_previous_version() const;
void init_previous_versions() {
_previous_versions = NULL;
@@ -711,6 +712,7 @@
static void get_jmethod_id_length_value(jmethodID* cache, size_t idnum,
size_t *length_p, jmethodID* id_p);
jmethodID jmethod_id_or_null(Method* method);