147 tty->print_cr("[ [%d]: %s", i,
148 probe->loader_data(i)->loader_name());
149 }
150 }
151
152 continue; // current element replaced, so restart without
153 // incrementing n
154 }
155 n++;
156 }
157 // Check whether entry should be purged
158 if (probe->num_loaders() < 2) {
159 if (TraceLoaderConstraints) {
160 ResourceMark rm;
161 tty->print("[Purging complete constraint for name %s\n",
162 probe->name()->as_C_string());
163 }
164
165 // Purge entry
166 *p = probe->next();
167 FREE_C_HEAP_ARRAY(oop, probe->loaders(), mtClass);
168 free_entry(probe);
169 } else {
170 #ifdef ASSERT
171 if (probe->klass() != NULL) {
172 ClassLoaderData* loader_data =
173 probe->klass()->class_loader_data();
174 assert(!loader_data->is_unloading(), "klass should be live");
175 }
176 #endif
177 // Go to next entry
178 p = probe->next_addr();
179 }
180 }
181 }
182 }
183
184 bool LoaderConstraintTable::add_entry(Symbol* class_name,
185 Klass* klass1, Handle class_loader1,
186 Klass* klass2, Handle class_loader2) {
187 int failure_code = 0; // encode different reasons for failing
323 if (p->klass()->oop_is_instance() && !InstanceKlass::cast(p->klass())->is_loaded()) {
324 // Only return fully loaded classes. Classes found through the
325 // constraints might still be in the process of loading.
326 return NULL;
327 }
328 return p->klass();
329 }
330
331 // No constraints, or else no klass loaded yet.
332 return NULL;
333 }
334
335 void LoaderConstraintTable::ensure_loader_constraint_capacity(
336 LoaderConstraintEntry *p,
337 int nfree) {
338 if (p->max_loaders() - p->num_loaders() < nfree) {
339 int n = nfree + p->num_loaders();
340 ClassLoaderData** new_loaders = NEW_C_HEAP_ARRAY(ClassLoaderData*, n, mtClass);
341 memcpy(new_loaders, p->loaders(), sizeof(ClassLoaderData*) * p->num_loaders());
342 p->set_max_loaders(n);
343 FREE_C_HEAP_ARRAY(ClassLoaderData*, p->loaders(), mtClass);
344 p->set_loaders(new_loaders);
345 }
346 }
347
348
349 void LoaderConstraintTable::extend_loader_constraint(LoaderConstraintEntry* p,
350 Handle loader,
351 Klass* klass) {
352 ensure_loader_constraint_capacity(p, 1);
353 int num = p->num_loaders();
354 p->set_loader(num, loader());
355 p->set_num_loaders(num + 1);
356 if (TraceLoaderConstraints) {
357 ResourceMark rm;
358 tty->print("[Extending constraint for name %s by adding loader[%d]: %s %s",
359 p->name()->as_C_string(),
360 num,
361 SystemDictionary::loader_name(loader()),
362 (p->klass() == NULL ? " and setting class object ]\n" : " ]\n")
363 );
405 if (p1->klass() == NULL) {
406 tty->print_cr("[... and setting class object]");
407 }
408 }
409
410 // p1->klass() will hold NULL if klass, p2->klass(), and old
411 // p1->klass() are all NULL. In addition, all three must have
412 // matching non-NULL values, otherwise either the constraints would
413 // have been violated, or the constraints had been corrupted (and an
414 // assertion would fail).
415 if (p2->klass() != NULL) {
416 assert(p2->klass() == klass, "constraints corrupted");
417 }
418 if (p1->klass() == NULL) {
419 p1->set_klass(klass);
420 } else {
421 assert(p1->klass() == klass, "constraints corrupted");
422 }
423
424 *pp2 = p2->next();
425 FREE_C_HEAP_ARRAY(oop, p2->loaders(), mtClass);
426 free_entry(p2);
427 return;
428 }
429
430
431 void LoaderConstraintTable::verify(Dictionary* dictionary,
432 PlaceholderTable* placeholders) {
433 Thread *thread = Thread::current();
434 for (int cindex = 0; cindex < _loader_constraint_size; cindex++) {
435 for (LoaderConstraintEntry* probe = bucket(cindex);
436 probe != NULL;
437 probe = probe->next()) {
438 if (probe->klass() != NULL) {
439 InstanceKlass* ik = InstanceKlass::cast(probe->klass());
440 guarantee(ik->name() == probe->name(), "name should match");
441 Symbol* name = ik->name();
442 ClassLoaderData* loader_data = ik->class_loader_data();
443 unsigned int d_hash = dictionary->compute_hash(name, loader_data);
444 int d_index = dictionary->hash_to_index(d_hash);
445 Klass* k = dictionary->find_class(d_index, d_hash, name, loader_data);
|
147 tty->print_cr("[ [%d]: %s", i,
148 probe->loader_data(i)->loader_name());
149 }
150 }
151
152 continue; // current element replaced, so restart without
153 // incrementing n
154 }
155 n++;
156 }
157 // Check whether entry should be purged
158 if (probe->num_loaders() < 2) {
159 if (TraceLoaderConstraints) {
160 ResourceMark rm;
161 tty->print("[Purging complete constraint for name %s\n",
162 probe->name()->as_C_string());
163 }
164
165 // Purge entry
166 *p = probe->next();
167 FREE_C_HEAP_ARRAY(oop, probe->loaders());
168 free_entry(probe);
169 } else {
170 #ifdef ASSERT
171 if (probe->klass() != NULL) {
172 ClassLoaderData* loader_data =
173 probe->klass()->class_loader_data();
174 assert(!loader_data->is_unloading(), "klass should be live");
175 }
176 #endif
177 // Go to next entry
178 p = probe->next_addr();
179 }
180 }
181 }
182 }
183
184 bool LoaderConstraintTable::add_entry(Symbol* class_name,
185 Klass* klass1, Handle class_loader1,
186 Klass* klass2, Handle class_loader2) {
187 int failure_code = 0; // encode different reasons for failing
323 if (p->klass()->oop_is_instance() && !InstanceKlass::cast(p->klass())->is_loaded()) {
324 // Only return fully loaded classes. Classes found through the
325 // constraints might still be in the process of loading.
326 return NULL;
327 }
328 return p->klass();
329 }
330
331 // No constraints, or else no klass loaded yet.
332 return NULL;
333 }
334
335 void LoaderConstraintTable::ensure_loader_constraint_capacity(
336 LoaderConstraintEntry *p,
337 int nfree) {
338 if (p->max_loaders() - p->num_loaders() < nfree) {
339 int n = nfree + p->num_loaders();
340 ClassLoaderData** new_loaders = NEW_C_HEAP_ARRAY(ClassLoaderData*, n, mtClass);
341 memcpy(new_loaders, p->loaders(), sizeof(ClassLoaderData*) * p->num_loaders());
342 p->set_max_loaders(n);
343 FREE_C_HEAP_ARRAY(ClassLoaderData*, p->loaders());
344 p->set_loaders(new_loaders);
345 }
346 }
347
348
349 void LoaderConstraintTable::extend_loader_constraint(LoaderConstraintEntry* p,
350 Handle loader,
351 Klass* klass) {
352 ensure_loader_constraint_capacity(p, 1);
353 int num = p->num_loaders();
354 p->set_loader(num, loader());
355 p->set_num_loaders(num + 1);
356 if (TraceLoaderConstraints) {
357 ResourceMark rm;
358 tty->print("[Extending constraint for name %s by adding loader[%d]: %s %s",
359 p->name()->as_C_string(),
360 num,
361 SystemDictionary::loader_name(loader()),
362 (p->klass() == NULL ? " and setting class object ]\n" : " ]\n")
363 );
405 if (p1->klass() == NULL) {
406 tty->print_cr("[... and setting class object]");
407 }
408 }
409
410 // p1->klass() will hold NULL if klass, p2->klass(), and old
411 // p1->klass() are all NULL. In addition, all three must have
412 // matching non-NULL values, otherwise either the constraints would
413 // have been violated, or the constraints had been corrupted (and an
414 // assertion would fail).
415 if (p2->klass() != NULL) {
416 assert(p2->klass() == klass, "constraints corrupted");
417 }
418 if (p1->klass() == NULL) {
419 p1->set_klass(klass);
420 } else {
421 assert(p1->klass() == klass, "constraints corrupted");
422 }
423
424 *pp2 = p2->next();
425 FREE_C_HEAP_ARRAY(oop, p2->loaders());
426 free_entry(p2);
427 return;
428 }
429
430
431 void LoaderConstraintTable::verify(Dictionary* dictionary,
432 PlaceholderTable* placeholders) {
433 Thread *thread = Thread::current();
434 for (int cindex = 0; cindex < _loader_constraint_size; cindex++) {
435 for (LoaderConstraintEntry* probe = bucket(cindex);
436 probe != NULL;
437 probe = probe->next()) {
438 if (probe->klass() != NULL) {
439 InstanceKlass* ik = InstanceKlass::cast(probe->klass());
440 guarantee(ik->name() == probe->name(), "name should match");
441 Symbol* name = ik->name();
442 ClassLoaderData* loader_data = ik->class_loader_data();
443 unsigned int d_hash = dictionary->compute_hash(name, loader_data);
444 int d_index = dictionary->hash_to_index(d_hash);
445 Klass* k = dictionary->find_class(d_index, d_hash, name, loader_data);
|