Skip to content

Commit b2af708

Browse files
committed
Big performance update.
1 parent db4e385 commit b2af708

File tree

66 files changed

+825
-238
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+825
-238
lines changed

bench/build.gradle

Lines changed: 0 additions & 25 deletions
This file was deleted.

bench/package-server.php.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
3+
app:
4+
jvm-args:
5+
- '-Djphp.benchServer=true'

bench/package.php.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ deps:
77
jphp-core: '*'
88
jphp-zend-ext: '*'
99
jphp-json-ext: '*'
10+
jphp-httpserver-ext: '*'
1011

1112
app:
1213
encoding: UTF-8

bench/src/JPHP-INF/launcher.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11

2-
env.concurrent = 0
2+
env.concurrent = 1
33
bootstrap.file = res://bench.php

bench/src/benchmarks/Benchmark.php

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22
namespace benchmarks;
33

4+
use php\http\HttpServer;
45
use php\lang\System;
56
//use php\webserver\WebRequest;
67
//use php\webserver\WebServer;
@@ -27,25 +28,15 @@ static function register(Benchmark $benchmark) {
2728
}
2829

2930
static function startServer() {
30-
/*$server = new WebServer(function (WebRequest $request) {
31-
self::registerAll();
31+
self::registerAll();
3232

33-
if ($request->servletPath == '/bench') {
34-
self::showResult(self::startBench());
35-
} else {
36-
$t = microtime(1);
37-
foreach (self::$benchmarks as $benchmark) {
38-
$benchmark->run();
39-
}
40-
41-
echo "----- total: " . (microtime(1) - $t);
42-
}
43-
});
33+
$server = new HttpServer(9999);
34+
$server->get('/', function () {
35+
self::showResult(self::startBench());
36+
});
4437

45-
$server->hotReload = false;
46-
$server->isolated = false;
47-
48-
$server->run();*/
38+
echo "Bench Server has been started at http://localhost:9999/", "\n", " -> result will be in console output.";
39+
$server->run();
4940
}
5041

5142
static function registerAll() {
@@ -95,6 +86,7 @@ static function start() {
9586
self::startServer();
9687
return [];
9788
}
89+
9890
return self::startBench();
9991
}
10092

exts/jphp-zend-ext/src/main/tests/zend/ClassesTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public void testMagicCall(){
2121
check("zend/classes/__call_004.php");
2222
check("zend/classes/__call_005.php");
2323
check("zend/classes/__call_006.php");
24-
check("zend/classes/__call_007.php");
24+
check("zend/classes/__call_007.php", true);
2525
}
2626

2727
@Test

jphp-core/src/org/develnext/jphp/core/compiler/jvm/JvmCompiler.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
package org.develnext.jphp.core.compiler.jvm;
22

3-
import org.develnext.jphp.core.tokenizer.token.expr.value.CallExprToken;
4-
import org.develnext.jphp.core.tokenizer.token.expr.value.StringExprToken;
3+
import org.develnext.jphp.core.tokenizer.token.expr.value.*;
54
import org.develnext.jphp.core.tokenizer.token.expr.value.StringExprToken.Quote;
6-
import org.develnext.jphp.core.tokenizer.token.expr.value.YieldExprToken;
75
import org.develnext.jphp.core.tokenizer.token.stmt.ConstStmtToken.Item;
86
import php.runtime.Memory;
97
import php.runtime.env.Context;
@@ -21,8 +19,6 @@
2119
import org.develnext.jphp.core.tokenizer.TokenType;
2220
import org.develnext.jphp.core.tokenizer.Tokenizer;
2321
import org.develnext.jphp.core.tokenizer.token.Token;
24-
import org.develnext.jphp.core.tokenizer.token.expr.value.ClosureStmtToken;
25-
import org.develnext.jphp.core.tokenizer.token.expr.value.NameToken;
2622
import org.develnext.jphp.core.tokenizer.token.stmt.*;
2723
import php.runtime.reflection.helper.GeneratorEntity;
2824

@@ -319,6 +315,10 @@ public String getSourceFile() {
319315
return context.getFileName();
320316
}
321317

318+
public boolean isSuperGlobal(VariableExprToken value) {
319+
return getScope().superGlobals.contains(value.getName());
320+
}
321+
322322
public class ClassInitEnvironment extends StmtToken {
323323
protected final ClassStmtToken token;
324324
protected final ClassEntity entity;

jphp-core/src/org/develnext/jphp/core/compiler/jvm/misc/LocalVariable.java

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@
77
import java.util.List;
88

99
public class LocalVariable {
10+
public static final String THIS = "~this";
11+
1012
public final String name;
1113
public final int index;
1214
public final LabelNode label;
1315
private LabelNode endLabel;
1416
private Class clazz;
1517

16-
private boolean isImmutable;
18+
private Boolean hasImmutableValue;
1719
private boolean isReference;
1820
private int level;
1921
private List<Memory> values;
@@ -25,9 +27,17 @@ public LocalVariable(String name, int index, LabelNode label, Class clazz){
2527
this.label = label;
2628
this.clazz = clazz;
2729
this.level = 0;
28-
this.isImmutable = true;
2930
this.values = new ArrayList<Memory>();
3031
this.frames = new ArrayList<StackFrame>();
32+
this.hasImmutableValue = null;
33+
}
34+
35+
public Boolean isHasImmutableValue() {
36+
return hasImmutableValue;
37+
}
38+
39+
public void setHasImmutableValue(Boolean hasImmutableValue) {
40+
this.hasImmutableValue = hasImmutableValue;
3141
}
3242

3343
public void addStackFrame(StackFrame frame){
@@ -46,8 +56,9 @@ public boolean isReference() {
4656
return isReference;
4757
}
4858

49-
public void setReference(boolean reference) {
59+
public LocalVariable setReference(boolean reference) {
5060
isReference = reference;
61+
return this;
5162
}
5263

5364
public void pushLevel(){
@@ -82,13 +93,6 @@ public Memory getValue(){
8293
return values.isEmpty() ? null : values.get(values.size() - 1);
8394
}
8495

85-
public boolean isImmutable() {
86-
return isImmutable;
87-
}
88-
89-
public void setImmutable(boolean immutable) {
90-
isImmutable = immutable;
91-
}
9296

9397
public LabelNode getEndLabel() {
9498
return endLabel;

jphp-core/src/org/develnext/jphp/core/compiler/jvm/statement/ClassStmtCompiler.java

Lines changed: 49 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import php.runtime.invoke.cache.*;
3636
import php.runtime.lang.BaseObject;
3737
import php.runtime.lang.IObject;
38+
import php.runtime.memory.ObjectMemory;
3839
import php.runtime.memory.UninitializedMemory;
3940
import php.runtime.reflection.*;
4041
import php.runtime.reflection.helper.ClosureEntity;
@@ -50,9 +51,12 @@ public class ClassStmtCompiler extends StmtCompiler<ClassEntity> {
5051
protected JPHPClassWriter cw;
5152
public final ClassNode node;
5253
public final ClassStmtToken statement;
53-
public final List<TraceInfo> traceList = new ArrayList<TraceInfo>();
54-
public final List<Memory> memoryConstants = new ArrayList<Memory>();
55-
public final List<Collection<Memory>> memoryArrayConstants = new ArrayList<Collection<Memory>>();
54+
public final List<TraceInfo> traceList = new ArrayList<>();
55+
56+
public final List<Memory> memoryConstants = new ArrayList<>();
57+
public final Map<Memory, Integer> memoryConstantsMap = new HashMap<>();
58+
59+
public final List<Collection<Memory>> memoryArrayConstants = new ArrayList<>();
5660

5761
private boolean external = false;
5862
private boolean isSystem = false;
@@ -182,8 +186,17 @@ int addTraceInfo(Token token) {
182186
}
183187

184188
int addMemoryConstant(Memory memory) {
185-
memoryConstants.add(memory);
186-
return memoryConstants.size() - 1;
189+
Integer oldIndex = memoryConstantsMap.get(memory);
190+
191+
if (oldIndex == null) {
192+
memoryConstants.add(memory);
193+
int index = memoryConstants.size() - 1;
194+
195+
memoryConstantsMap.put(memory, index);
196+
return index;
197+
} else {
198+
return oldIndex;
199+
}
187200
}
188201

189202
int addMemoryArray(Collection<Memory> memories) {
@@ -205,14 +218,14 @@ protected void writeDestructor() {
205218

206219
LabelNode end = new LabelNode();
207220
LabelNode l0 = writeLabel(destructor, statement.getMeta().getStartLine());
208-
methodCompiler.addLocalVariable("~this", l0);
221+
methodCompiler.addLocalVariable(LocalVariable.THIS, l0);
209222

210-
expressionCompiler.writeVarLoad("~this");
223+
expressionCompiler.writeVarLoad(LocalVariable.THIS);
211224
expressionCompiler.writeSysDynamicCall(null, "isFinalized", Boolean.TYPE);
212225
destructor.instructions.add(new JumpInsnNode(IFEQ, end));
213226

214227
// --- if (!__finalized__) {
215-
expressionCompiler.writeVarLoad("~this");
228+
expressionCompiler.writeVarLoad(LocalVariable.THIS);
216229
expressionCompiler.writePushDup();
217230
expressionCompiler.writeSysDynamicCall(null, "doFinalize", void.class);
218231

@@ -264,7 +277,7 @@ protected void writeDefaultConstructors()
264277
ExpressionStmtCompiler expressionCompiler = new ExpressionStmtCompiler(methodCompiler, null);
265278

266279
LabelNode l0 = writeLabel(constructor, statement.getMeta().getStartLine());
267-
methodCompiler.addLocalVariable("~this", l0);
280+
methodCompiler.addLocalVariable(LocalVariable.THIS, l0);
268281

269282
Type[] argumentTypes = new Type[parameterTypes.length];
270283

@@ -281,7 +294,7 @@ protected void writeDefaultConstructors()
281294

282295
methodCompiler.writeHeader();
283296

284-
expressionCompiler.writeVarLoad("~this");
297+
expressionCompiler.writeVarLoad(LocalVariable.THIS);
285298
for (i = 0; i < argumentTypes.length; i++) {
286299
expressionCompiler.writeVarLoad("arg" + (i + 1));
287300
}
@@ -382,13 +395,33 @@ protected void writeConstructor() {
382395
false
383396
));
384397

385-
LabelNode label = expressionCompiler.writeLabel(methodCompiler.node);
386-
LocalVariable local = methodCompiler.addLocalVariable("$THIS", label, Memory.class);
387-
expressionCompiler.writeDefineThis(local, null);
398+
LabelNode endLabel = new LabelNode();
399+
LabelNode elseLabel = new LabelNode();
388400

389-
expressionCompiler.writeVarLoad("~this");
390-
expressionCompiler.writeVarLoad("$THIS");
391-
expressionCompiler.writePutDynamic("$THIS", Memory.class);
401+
if (!entity.isTrait() && !isSystem()) {
402+
// if this.isMock() {
403+
expressionCompiler.writeVarLoad(LocalVariable.THIS);
404+
expressionCompiler.writeSysDynamicCall(IObject.class, "isMock", Boolean.TYPE);
405+
406+
expressionCompiler.writeJumpIfEqual(elseLabel);
407+
expressionCompiler.stackPop();
408+
409+
expressionCompiler.writeVarLoad(LocalVariable.THIS);
410+
expressionCompiler.writePushMemory(Memory.UNDEFINED);
411+
expressionCompiler.writePutDynamic("$THIS", Memory.class);
412+
413+
expressionCompiler.writeJumpGoto(endLabel);
414+
//} else {
415+
expressionCompiler.writeLabel(elseLabel);
416+
417+
expressionCompiler.writeVarLoad(LocalVariable.THIS);
418+
expressionCompiler.writePushDup();
419+
expressionCompiler.writeSysStaticCall(ObjectMemory.class, "valueOf", Memory.class, IObject.class);
420+
expressionCompiler.writePutDynamic("$THIS", Memory.class);
421+
422+
expressionCompiler.writeLabel(endLabel);
423+
// }
424+
}
392425

393426
// PROPERTIES
394427
for (ClassVarStmtToken property : statement.getProperties()) {

0 commit comments

Comments
 (0)