Lazily initialize members in NativeJavaObject/NativeJavaMethod#2262
Lazily initialize members in NativeJavaObject/NativeJavaMethod#2262ZZZank wants to merge 9 commits intomozilla:masterfrom
NativeJavaObject/NativeJavaMethod#2262Conversation
|
I like the laziness approach in general (we have a lot of reflected members that are never normally used but consume memory), but it hasn't gone far enough yet to resolve the serialisation issues. Have a look at the extra assertions I've added to I think the solution might be to make This would require a little work to handle sealed cases correctly, and raises a question of what the initial state of the property map should be. Maybe we should initially gather a list of reflected member names, and populate them with values lazily? |
It seems this can be fixed by implementing a proper
I don't quite understand this, is the code below a valid example of this issue? let obj1, obj2; // instances of the same java class
obj1.someMethod.someProp = 42
obj2.someMethod.someProp // gives 42My next step will probably be introduce some intermediate representation, between |
Yeah. If you look at @Override
public void put(String name, Scriptable start, Object value) {
// We could be asked to modify the value of a property in the
// prototype. Since we can't add a property to a Java object,
// we modify it in the prototype rather than copy it down.
if (prototype == null || members.has(name, false))
members.put(this, name, javaObject, value, false);
else prototype.put(name, prototype, value);
}We should probably treat these objects as sealed, i.e. you cannot add new properties to them, even you can edit existing ones.
I think we're in agreement here that |
|
Heh @ZZZank, would you be open to a PR to make JavaMembers a pure cache for member boxes and similar, and never serialised? I'm happy to work on it if so. |
|
#2298 , though I'm not sure whether NativeJavaMethod reference should also be stripped, sinve we will never mutate this |
This PR is made for implementing serialization of
NativeJavaMethod, and provide another possible solution to #2248 .NativeJavaMethod(and its subclassNativeJavaField)To support serialization of them, a new field
parentis added, representing the class that holds this member, which will then be used for getting the correctJavaMembersduring initialization.But initialization will not happen immediately after deserialization, instead, initialization is deferred to the first usage, so that initialization will happen after the
scopeused for gettingJavaMembershave been deserialized enough.membersinNativeJavaObjectSimilar to
NativeJavaMethod, its initialization is deferred to the first usage. For me this is a valid solution to #2248 , but I'm not familiar with all the scope thingy after all, so reviews and analysis are welcomed.You may have noticed that there's no thread safety measure, and I'm not sure if this actually matters. From my perspective
JavaMembersis read-only, and identity ofJavaMembersand members ofJavaMembersdoesn't matter.