55use PHPJava \Exceptions \NotImplementedException ;
66use PHPJava \Exceptions \UnableToCatchException ;
77use PHPJava \Kernel \Attributes \CodeAttribute ;
8+ use PHPJava \Kernel \Internal \InstanceDeferredLoader ;
89use PHPJava \Kernel \Structures \_ExceptionTable ;
910use PHPJava \Utilities \AttributionResolver ;
1011use PHPJava \Utilities \BinaryTool ;
@@ -30,22 +31,20 @@ public function execute(): void
3031 $ parsedSignature = Formatter::parseSignature ($ signature );
3132
3233 // POP with right-to-left (objectref + arguments)
33- $ collection = array_fill (0 , $ parsedSignature ['arguments_count ' ] + 1 , null );
34- for ($ i = count ($ collection ) - 1 ; $ i >= 0 ; $ i --) {
35- $ collection [$ i ] = $ this ->popFromOperandStack ();
34+ $ arguments = array_fill (0 , $ parsedSignature ['arguments_count ' ], null );
35+ for ($ i = count ($ arguments ) - 1 ; $ i >= 0 ; $ i --) {
36+ $ arguments [$ i ] = $ this ->popFromOperandStack ();
3637 }
3738
38- $ objectref = $ collection [0 ];
39-
39+ /**
40+ * @var InstanceDeferredLoader $objectref
41+ */
42+ $ objectref = $ this ->popFromOperandStack ();
43+ $ newObject = null ;
4044 try {
41-
42- // NOTE: first arguments is a class object. (PHPJava does not needed.)
43- $ arguments = array_values (array_slice ($ collection , 1 ));
4445 $ methodName = $ cpInfo [$ nameAndTypeIndex ->getNameIndex ()]->getString ();
4546
46- if ($ objectref instanceof JavaClass &&
47- $ objectref ->getClassName () !== $ className
48- ) {
47+ if ($ objectref ->getClassName () !== $ className ) {
4948 // If $objectref is not match $className, then change current class (I have no confidence).
5049 // See also: https://docs.oracle.com/javase/specs/jvms/se11/html/jvms-6.html#jvms-6.5.invokespecial
5150
@@ -57,16 +56,18 @@ public function execute(): void
5756
5857 switch ($ resourceType ) {
5958 case ClassResolver::RESOLVED_TYPE_PACKAGES :
60- $ objectref = new $ classObject (...$ arguments );
59+ $ newObject = new $ classObject (...$ arguments );
6160 break ;
6261 case ClassResolver::RESOLVED_TYPE_CLASS :
63- throw new NotImplementedException ('This section is not implementation. ' );
62+ $ newObject = $ classObject (...$ arguments );
63+ break ;
6464 }
65- } elseif ($ objectref instanceof JavaClass) {
66- $ objectref = $ objectref (...$ arguments );
6765 } else {
68- $ objectref = new $ objectref (...$ arguments );
66+ $ newObject = $ objectref-> instantiate (...$ arguments );
6967 }
68+
69+ // NOTE: PHP has a problem which a reference object cannot replace to an object.
70+ $ this ->replaceReferredObject ($ objectref , $ newObject );
7071 } catch (\Exception $ e ) {
7172 /**
7273 * @var $codeAttribute CodeAttribute
0 commit comments