comparison src/share/vm/code/dependencies.hpp @ 7101:0778b04fc682

better encoding of dependencies during dependency recording by Graal
author Doug Simon <doug.simon@oracle.com>
date Thu, 29 Nov 2012 22:53:03 +0100
parents eec7173947a1
children 707b20dd9512
comparison
equal deleted inserted replaced
7100:35568cbc6a43 7101:0778b04fc682
57 class DepChange; 57 class DepChange;
58 class KlassDepChange; 58 class KlassDepChange;
59 class CallSiteDepChange; 59 class CallSiteDepChange;
60 class No_Safepoint_Verifier; 60 class No_Safepoint_Verifier;
61 61
62 #ifdef GRAAL
63
64 // Dependency values that don't rely on the ciBaseObject types.
65 class DepValue VALUE_OBJ_CLASS_SPEC {
66 private:
67 OopRecorder* _oop_recorder;
68 int _index; // positive -> metadata, negative -> object
69
70 public:
71 DepValue() : _oop_recorder(NULL), _index(max_jint) {}
72 DepValue(OopRecorder* oop_recorder, Metadata* metadata) : _oop_recorder(oop_recorder) {
73 int index = oop_recorder->find_index(metadata);
74 _index = index;
75 }
76 DepValue(OopRecorder* oop_recorder, jobject obj) : _oop_recorder(oop_recorder) {
77 int index = oop_recorder->find_index(obj);
78 _index = -(index + 1);
79 }
80
81 // Used to sort values in order of index with metadata values preceding object values
82 int sort_key() const { return -_index; }
83
84 bool operator == (const DepValue& dv) const { return dv._oop_recorder == _oop_recorder && dv._index == _index; }
85
86 bool is_valid() const { return _index != max_jint; }
87 int index() const { assert(is_valid(), "oops"); return _index < 0 ? -(_index + 1) : _index; }
88 bool is_metadata() const { assert(is_valid(), "oops"); return _index >= 0; }
89 bool is_method() const { assert(is_valid(), "oops"); return as_metadata()->is_method(); }
90 bool is_klass() const { assert(is_valid(), "oops"); return as_metadata()->is_klass(); }
91 bool is_object() const { return !is_metadata(); }
92
93 Metadata* as_metadata() const { assert(is_metadata(), "oops"); return _oop_recorder->metadata_at(index()); }
94 Klass* as_klass() const { assert(is_klass(), "oops"); return (Klass*) as_metadata(); }
95 Method* as_method() const { assert(is_method(), "oops"); return (Method*) as_metadata(); }
96 };
97 #endif
98
99 class Dependencies: public ResourceObj { 62 class Dependencies: public ResourceObj {
100 public: 63 public:
101 // Note: In the comments on dependency types, most uses of the terms 64 // Note: In the comments on dependency types, most uses of the terms
102 // subtype and supertype are used in a "non-strict" or "inclusive" 65 // subtype and supertype are used in a "non-strict" or "inclusive"
103 // sense, and are starred to remind the reader of this fact. 66 // sense, and are starred to remind the reader of this fact.
234 197
235 static int dep_context_arg(DepType dept) { return has_explicit_context_arg(dept) ? 0 : -1; } 198 static int dep_context_arg(DepType dept) { return has_explicit_context_arg(dept) ? 0 : -1; }
236 static int dep_implicit_context_arg(DepType dept) { return has_implicit_context_arg(dept) ? 0 : -1; } 199 static int dep_implicit_context_arg(DepType dept) { return has_implicit_context_arg(dept) ? 0 : -1; }
237 200
238 static void check_valid_dependency_type(DepType dept); 201 static void check_valid_dependency_type(DepType dept);
202
203 #ifdef GRAAL
204 // A Metadata* or object value recorded in an OopRecorder
205 class DepValue VALUE_OBJ_CLASS_SPEC {
206 private:
207 // Unique identifier of the value within the associated OopRecorder that
208 // encodes both the category of the value (0: invalid, positive: metadata, negative: object)
209 // and the index within a category specific array (metadata: index + 1, object: -(index + 1))
210 int _id;
211
212 public:
213 DepValue() : _id(0) {}
214 DepValue(OopRecorder* rec, Metadata* metadata, DepValue* candidate = NULL) {
215 assert(candidate == NULL || candidate->is_metadata(), "oops");
216 if (candidate != NULL && candidate->as_metadata(rec) == metadata) {
217 _id = candidate->_id;
218 } else {
219 _id = rec->find_index(metadata) + 1;
220 }
221 }
222 DepValue(OopRecorder* rec, jobject obj, DepValue* candidate = NULL) {
223 assert(candidate == NULL || candidate->is_object(), "oops");
224 if (candidate != NULL && candidate->as_object(rec) == obj) {
225 _id = candidate->_id;
226 } else {
227 _id = -(rec->find_index(obj) + 1);
228 }
229 }
230
231 // Used to sort values in ascending order of index() with metadata values preceding object values
232 int sort_key() const { return -_id; }
233
234 bool operator == (const DepValue& other) const { return other._id == _id; }
235
236 bool is_valid() const { return _id != 0; }
237 int index() const { assert(is_valid(), "oops"); return _id < 0 ? -(_id + 1) : _id - 1; }
238 bool is_metadata() const { assert(is_valid(), "oops"); return _id > 0; }
239 bool is_object() const { assert(is_valid(), "oops"); return _id < 0; }
240
241 Metadata* as_metadata(OopRecorder* rec) const { assert(is_metadata(), "oops"); return rec->metadata_at(index()); }
242 Klass* as_klass(OopRecorder* rec) const { assert(as_metadata(rec)->is_klass(), "oops"); return (Klass*) as_metadata(rec); }
243 Method* as_method(OopRecorder* rec) const { assert(as_metadata(rec)->is_method(), "oops"); return (Method*) as_metadata(rec); }
244 jobject as_object(OopRecorder* rec) const { assert(is_object(), "oops"); return rec->oop_at(index()); }
245 };
246 #endif
239 247
240 private: 248 private:
241 // State for writing a new set of dependencies: 249 // State for writing a new set of dependencies:
242 GrowableArray<int>* _dep_seen; // (seen[h->ident] & (1<<dept)) 250 GrowableArray<int>* _dep_seen; // (seen[h->ident] & (1<<dept))
243 GrowableArray<ciBaseObject*>* _deps[TYPE_LIMIT]; 251 GrowableArray<ciBaseObject*>* _deps[TYPE_LIMIT];
349 } 357 }
350 void assert_common_1(DepType dept, DepValue x); 358 void assert_common_1(DepType dept, DepValue x);
351 void assert_common_2(DepType dept, DepValue x0, DepValue x1); 359 void assert_common_2(DepType dept, DepValue x0, DepValue x1);
352 360
353 public: 361 public:
354 void assert_evol_method(DepValue m); 362 void assert_evol_method(Method* m);
355 void assert_leaf_type(DepValue ctxk); 363 void assert_leaf_type(Klass* ctxk);
356 void assert_unique_concrete_method(DepValue ctxk, DepValue uniqm); 364 void assert_unique_concrete_method(Klass* ctxk, Method* uniqm);
357 void assert_abstract_with_unique_concrete_subtype(DepValue ctxk, DepValue conck); 365 void assert_abstract_with_unique_concrete_subtype(Klass* ctxk, Klass* conck);
358 #endif // GRAAL 366 #endif // GRAAL
359 367
360 // Define whether a given method or type is concrete. 368 // Define whether a given method or type is concrete.
361 // These methods define the term "concrete" as used in this module. 369 // These methods define the term "concrete" as used in this module.
362 // For this module, an "abstract" class is one which is non-concrete. 370 // For this module, an "abstract" class is one which is non-concrete.