MCPcopy Create free account
hub / github.com/ReadyTalk/avian / updatePackageMap

Function updatePackageMap

src/machine.cpp:3562–3611  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3560}
3561
3562void updatePackageMap(Thread* t, GcClass* class_)
3563{
3564 PROTECT(t, class_);
3565
3566 if (roots(t)->packageMap() == 0) {
3567 GcHashMap* map = makeHashMap(t, 0, 0);
3568 // sequence point, for gc (don't recombine statements)
3569 roots(t)->setPackageMap(t, map);
3570 }
3571
3572 GcByteArray* className = class_->name();
3573 if ('[' != className->body()[0]) {
3574 THREAD_RUNTIME_ARRAY(t, char, packageName, className->length());
3575
3576 char* s = reinterpret_cast<char*>(className->body().begin());
3577 char* p = strrchr(s, '/');
3578
3579 if (p) {
3580 int length = (p - s) + 1;
3581 memcpy(
3582 RUNTIME_ARRAY_BODY(packageName), className->body().begin(), length);
3583 RUNTIME_ARRAY_BODY(packageName)[length] = 0;
3584
3585 GcByteArray* key
3586 = vm::makeByteArray(t, "%s", RUNTIME_ARRAY_BODY(packageName));
3587 PROTECT(t, key);
3588
3589 hashMapRemove(
3590 t, roots(t)->packageMap(), key, byteArrayHash, byteArrayEqual);
3591
3592 GcByteArray* source = class_->source();
3593 if (source) {
3594 // note that we strip the "file:" prefix, since OpenJDK's
3595 // Package.defineSystemPackage expects an unadorned filename:
3596 const unsigned PrefixLength = 5;
3597 unsigned sourceNameLength = source->length() - PrefixLength;
3598 THREAD_RUNTIME_ARRAY(t, char, sourceName, sourceNameLength);
3599 memcpy(RUNTIME_ARRAY_BODY(sourceName),
3600 &source->body()[PrefixLength],
3601 sourceNameLength);
3602
3603 source = vm::makeByteArray(t, "%s", RUNTIME_ARRAY_BODY(sourceName));
3604 } else {
3605 source = vm::makeByteArray(t, "avian-dummy-package-source");
3606 }
3607
3608 hashMapInsert(t, roots(t)->packageMap(), key, source, byteArrayHash);
3609 }
3610 }
3611}
3612
3613} // namespace
3614

Callers 1

resolveSystemClassFunction · 0.85

Calls 8

rootsFunction · 0.85
makeByteArrayFunction · 0.85
hashMapRemoveFunction · 0.85
hashMapInsertFunction · 0.85
bodyMethod · 0.80
lengthMethod · 0.65
nameMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected