Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions doc/MANAGEMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ MayaaではJMX(Java Management Extensions)を経由して内部状態の監視

| ObjectName | 説明 |
|------------------------------------------------------------|-----|
| org.seasar.mayaa:type=CacheControl,name=SpecificationCache | Page および Template のビルド結果のキャッシュ |
| org.seasar.mayaa:type=CacheControl,name=specificationCache | Page および Template のビルド結果のキャッシュ |
| org.seasar.mayaa:type=CacheControl,name=CompiledScript | スクリプトのコンパイル結果のキャッシュ |
| org.seasar.mayaa:type=CacheControl,name=SourceCompiledScript | ソーススクリプトコンパイル結果のキャッシュ |
| org.seasar.mayaa:type=CacheControl,name=JspTagPool | JSPタグライブラリのインスタンスプール |
| org.seasar.mayaa:type=CacheControl,name=PrefixAwareName | 名前空間付きの属性名のキャッシュ |
| org.seasar.mayaa:type=MayaaEngine | Mayaa全体の挙動 |
Expand All @@ -22,13 +23,22 @@ MayaaではJMX(Java Management Extensions)を経由して内部状態の監視
|-------------|----------------------------------------------|---------|
| ClassName | キャッシュの実装クラス名。 | |
| CurrentSize | 現在キャッシュとして保持されているオブジェクト数。 | |
| RequestCount | キャッシュ参照回数。 | |
| HitCount | キャッシュヒットした回数。 | |
| HitRate | キャッシュヒット率。 | |
| MissCount | キャッシュミスした回数。 | |
| MissRate | キャッシュミス率。 | |
| LoadSuccessCount | ロード成功回数。 | |
| LoadFailureCount | ロード失敗回数。 | |
| TotalLoadTime | ロード時間合計(ナノ秒)。 | |
| EvictionCount | 追い出し回数。 | |
| StatsEnabled | 統計取得が有効かどうか。 | |
| MaximumSizeManageable | 最大保持数の動的変更に対応しているか。 | |
| RetainSize | キャッシュから追い出さずに保持する最大オブジェクト数。 | O |

| 操作名 | 説明 |
|-------------|----------------------------------------------|
| (なし) | |
| invalidateAll | 全エントリを破棄する。 |

#### 属性・操作 (type=CacheControl)

Expand Down
10 changes: 5 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -479,16 +479,16 @@
</build>

<dependencies>
<dependency>
<groupId>com.github.ben-manes.caffeine</groupId>
<artifactId>caffeine</artifactId>
<version>2.9.3</version>
</dependency>
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>1.11.0</version>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.2</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
Expand Down
5 changes: 5 additions & 0 deletions src-api/org/seasar/mayaa/engine/Engine.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,9 @@ public interface Engine extends ParameterAware {
*/
void destroy();

/**
* Engineを初期化します。
*/
void reset();

}
10 changes: 10 additions & 0 deletions src-api/org/seasar/mayaa/management/CacheControlMXBean.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,17 @@ public interface CacheControlMXBean {
int getRetainSize();
void setRetainSize(int retainSize);
long getCurrentSize();
long getRequestCount();
long getHitCount();
double getHitRate();
long getMissCount();
double getMissRate();
long getLoadSuccessCount();
long getLoadFailureCount();
long getTotalLoadTime();
long getEvictionCount();
boolean isStatsEnabled();
boolean isMaximumSizeManageable();
void invalidateAll();
String getClassName();
}
2 changes: 0 additions & 2 deletions src-impl/org/seasar/mayaa/impl/MayaaServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.seasar.mayaa.impl.engine.processor.JspProcessor;
import org.seasar.mayaa.impl.provider.ProviderUtil;
import org.seasar.mayaa.impl.util.ObjectUtil;
import org.seasar.mayaa.impl.util.ReferenceCache;
import org.seasar.mayaa.impl.util.StringUtil;

/**
Expand Down Expand Up @@ -99,7 +98,6 @@ protected void initAutoPageBuilder() {
}

public void destroy() {
ReferenceCache.finishThreads();
AutoPageBuilder.INSTANCE.destroy();
ProviderUtil.getEngine().destroy();
JspProcessor.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,6 @@ protected void walkTreeOptimizeNode(
} else {
if (processor instanceof ElementProcessor == false
&& processor instanceof AttributeProcessor == false) {
//Namespace root = NamespaceImpl.getInstance("/null\n");
processor.getOriginalNode().setParentSpace(null);
processor.getInjectedNode().setParentSpace(null);
//System.out.println(processor.getClass().getName());
Expand Down
18 changes: 2 additions & 16 deletions src-impl/org/seasar/mayaa/impl/cycle/AbstractServiceCycle.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,9 @@
*/
package org.seasar.mayaa.impl.cycle;

import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import org.apache.commons.collections.map.AbstractReferenceMap;
import org.apache.commons.collections.map.ReferenceMap;
import org.seasar.mayaa.cycle.ServiceCycle;
import org.seasar.mayaa.cycle.scope.AttributeScope;
import org.seasar.mayaa.cycle.script.CompiledScript;
Expand All @@ -47,9 +43,6 @@ public abstract class AbstractServiceCycle

private static final long serialVersionUID = -4084527796306356704L;

@SuppressWarnings("unchecked")
private static final Map<String, CompiledScript> _scriptCache =
Collections.synchronizedMap(new ReferenceMap(AbstractReferenceMap.SOFT, AbstractReferenceMap.SOFT, true));
private AttributeScope _page;
private NodeTreeWalker _originalNode;
private NodeTreeWalker _injectedNode;
Expand Down Expand Up @@ -81,13 +74,8 @@ public void load(String systemID, String encoding) {
}

protected CompiledScript getScript(String systemID, String encoding) {
CompiledScript script = (CompiledScript) _scriptCache.get(systemID);
if (script != null) {
return script;
}
ApplicationSourceDescriptor appSource = new ApplicationSourceDescriptor();

ApplicationSourceDescriptor appSource =
new ApplicationSourceDescriptor();
if (systemID.startsWith("/") == false) {
appSource.setRoot(ApplicationSourceDescriptor.WEB_INF);
}
Expand All @@ -103,9 +91,7 @@ protected CompiledScript getScript(String systemID, String encoding) {
}

ScriptEnvironment env = ProviderUtil.getScriptEnvironment();
script = env.compile(source, encoding);
_scriptCache.put(systemID, script);
return script;
return env.compile(source, encoding);
}

public Iterator<AttributeScope> iterateAttributeScope() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package org.seasar.mayaa.impl.cycle.script.rhino;

import java.util.Map;

import org.mozilla.javascript.Context;
import org.mozilla.javascript.NativeArray;
import org.mozilla.javascript.Scriptable;
Expand All @@ -38,19 +37,27 @@
import org.seasar.mayaa.impl.management.CacheControllerRegistry;
import org.seasar.mayaa.impl.util.ObjectUtil;
import org.seasar.mayaa.impl.util.StringUtil;
import org.seasar.mayaa.impl.util.WeakValueHashMap;
import org.seasar.mayaa.source.SourceDescriptor;

import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;

/**
* Rhino用のスクリプト環境。
*
* @author Masataka Kurihara (Gluegent, Inc.)
*/
public class ScriptEnvironmentImpl extends AbstractScriptEnvironment {
private static final int DEFAULT_HARD_SIZE = 128;

private static Scriptable _standardObjects;
private WeakValueHashMap<String, CompiledScript> scriptCache = new WeakValueHashMap<>(DEFAULT_HARD_SIZE);
private static final Cache<String, CompiledScript> _scriptCache = Caffeine.newBuilder()
.maximumSize(10_000)
.recordStats()
.build();
private static final Cache<String, CompiledScript> _sourceScriptCache = Caffeine.newBuilder()
.maximumSize(1_000)
.recordStats()
.build();

private static final boolean CONSTRAINT_GLOBAL_PROPERTY_DEFINE = true;

Expand All @@ -61,7 +68,10 @@ public class ScriptEnvironmentImpl extends AbstractScriptEnvironment {

public ScriptEnvironmentImpl() {
super();
CacheControllerRegistry.registerCacheController("CompiledScript", scriptCache);
_scriptCache.invalidateAll();
_sourceScriptCache.invalidateAll();
CacheControllerRegistry.registerCacheController("CompiledScript", _scriptCache);
CacheControllerRegistry.registerCacheController("SourceCompiledScript", _sourceScriptCache);
}

protected CompiledScript compile(
Expand All @@ -73,21 +83,16 @@ protected CompiledScript compile(
if (scriptBlock.isLiteral()) {
return new LiteralScript(text);
} else {
CompiledScript script = (CompiledScript) scriptCache.get(text);
if (script == null) {
synchronized (scriptCache) {
script = (CompiledScript) scriptCache.get(text);
if (script == null) {
if (_useGetterScriptEmulation) {
script = GetterScriptFactory.create(text, position, offsetLine);
}
if (script == null) {
script = new TextCompiledScriptImpl(text, position, offsetLine);
}
scriptCache.put(text, script);
}
}
}
CompiledScript script = (CompiledScript) _scriptCache.get(text, key -> {
CompiledScript s = null;
if (_useGetterScriptEmulation) {
s = GetterScriptFactory.create(text, position, offsetLine);
}
if (s == null) {
s = new TextCompiledScriptImpl(text, position, offsetLine);
}
return s;
});
return script;
}
}
Expand All @@ -104,12 +109,18 @@ protected String getSourceMimeType(SourceDescriptor source) {
return application.getMimeType(systemID);
}

public CompiledScript compile(
SourceDescriptor source, String encoding) {
public CompiledScript compile(SourceDescriptor source, String encoding) {
if (source == null) {
throw new IllegalArgumentException();
}
return new SourceCompiledScriptImpl(source, encoding);
if (source.exists() == false) {
return null;
}
String cacheKey = source.getSystemID() + "\n" + (encoding == null ? "" : encoding);
CompiledScript script = _sourceScriptCache.get(cacheKey, key -> {
return new SourceCompiledScriptImpl(source, encoding);
});
return script;
}

protected static Scriptable getStandardObjects() {
Expand Down Expand Up @@ -252,14 +263,6 @@ private boolean conversionRequires(Object scriptObject, Class<?> expectedClass)
return (scriptObject instanceof Scriptable);
}

public void setScriptCacheSize(int cacheSize) {
scriptCache.setHardSize(cacheSize);
}

public int getScriptCacheSize() {
return scriptCache.getHardSize();
}

static void setWrapFactory(WrapFactory wrap) {
_wrap = wrap;
}
Expand Down Expand Up @@ -287,11 +290,6 @@ public void setParameter(String name, String value) {
throw new IllegalParameterValueException(getClass(), name);
}
_useGetterScriptEmulation = ObjectUtil.booleanValue(value, false);
} else if ("cacheSize".equals(name)) {
if (StringUtil.isEmpty(value)) {
throw new IllegalParameterValueException(getClass(), name);
}
setScriptCacheSize(Integer.parseInt(value));
}
super.setParameter(name, value);
}
Expand Down
35 changes: 19 additions & 16 deletions src-impl/org/seasar/mayaa/impl/engine/EngineImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -59,6 +60,9 @@
import org.seasar.mayaa.impl.util.StringUtil;
import org.seasar.mayaa.source.SourceDescriptor;

import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;

/**
* @author Masataka Kurihara (Gluegent, Inc)
*/
Expand All @@ -79,7 +83,12 @@ public class EngineImpl extends NonSerializableParameterAwareImpl implements Eng
private transient AtomicReference<Specification> _defaultSpecification = new AtomicReference<>(null);

private transient ErrorHandler _errorHandler;
private transient SpecificationCache _specCache;
private final Cache<String, Specification> _specCache = Caffeine.newBuilder()
.expireAfterWrite(10, TimeUnit.MINUTES)
.maximumSize(10_000)
.recordStats()
.build();

private transient SerializeExecutor _serializeExecutor;
/** Engineが破棄されていればtrue。破棄後はサービスを保証しない。 */
private volatile boolean _destroyed = false;
Expand All @@ -103,6 +112,7 @@ public class EngineImpl extends NonSerializableParameterAwareImpl implements Eng

public EngineImpl() {
EngineRegistory.registerEngine(this);
CacheControllerRegistry.registerCacheController("specificationCache", _specCache);
CycleUtil.registVariableFactory(CONST_IMPL.DEFAULT_SPECIFICATION_KEY, new DefaultCycleLocalInstantiator(){
/**
* デフォルトSpecificationをCycleに貼り付ける。
Expand Down Expand Up @@ -139,7 +149,7 @@ public ErrorHandler getErrorHandler() {
}

public Specification findSpecificationFromCache(String systemID) {
return getCache().get(systemID);
return _specCache.getIfPresent(systemID);
}

/**
Expand Down Expand Up @@ -457,14 +467,6 @@ protected void dump(ServiceCycle cycle) {
dump.printSource(page);
}

protected SpecificationCache getCache() {
if (_specCache == null) {
_specCache = new SpecificationCache(_surviveLimit);
CacheControllerRegistry.registerCacheController("SpecificationCache", _specCache);
}
return _specCache;
}

private static interface SpecificationGenerator {
Class<?> getInstantiator(SourceDescriptor source);
void initialize(Specification instance);
Expand All @@ -480,7 +482,7 @@ protected Specification createSpecificationInstance(String systemID,
if (spec != null) {
if (spec.isDeprecated() == false) {
if (registerCache) {
getCache().add(spec);
_specCache.put(spec.getSystemID(), spec);
}
return spec;
}
Expand Down Expand Up @@ -515,7 +517,7 @@ protected Specification createSpecificationInstance(String systemID,
throw e;
}
if (registerCache) {
getCache().add(spec);
_specCache.put(spec.getSystemID(), spec);
}
return spec;
}
Expand Down Expand Up @@ -577,14 +579,15 @@ protected String getSuffixSeparator() {
return EngineUtil.getEngineSetting(CONST_IMPL.SUFFIX_SEPARATOR, "$");
}

public synchronized void destroy() {
public void destroy() {
_destroyed = true;
if (_specCache != null) {
_specCache.release();
}
disableSerialize();
}

public void reset() {
_specCache.invalidateAll();
}

protected void finalize() throws Throwable {
destroy();
}
Expand Down
Loading
Loading