From: <ls...@us...> - 2010-03-28 19:26:44
|
Revision: 5741 http://jnode.svn.sourceforge.net/jnode/?rev=5741&view=rev Author: lsantha Date: 2010-03-28 19:26:38 +0000 (Sun, 28 Mar 2010) Log Message: ----------- Added support for releasing the bytecode visitor, other fixes in reusing bytecode visitors. Modified Paths: -------------- trunk/core/src/core/org/jnode/vm/compiler/NativeCodeCompiler.java trunk/core/src/core/org/jnode/vm/x86/compiler/l1a/X86Level1ACompiler.java Modified: trunk/core/src/core/org/jnode/vm/compiler/NativeCodeCompiler.java =================================================================== --- trunk/core/src/core/org/jnode/vm/compiler/NativeCodeCompiler.java 2010-03-28 19:12:41 UTC (rev 5740) +++ trunk/core/src/core/org/jnode/vm/compiler/NativeCodeCompiler.java 2010-03-28 19:26:38 UTC (rev 5741) @@ -240,38 +240,49 @@ protected CompiledMethod doCompile(VmMethod method, NativeStream os, int level, boolean isBootstrap) { final CompiledMethod cm = new CompiledMethod(level); - if (method.isNative()) { - Object label = new Label(method.getMangledName()); - cm.setCodeStart(os.getObjectRef(label)); - } else { - // Create the visitor - CompilerBytecodeVisitor bcv = createBytecodeVisitor(method, - cm, os, level, isBootstrap); - // Wrap in verifier if needed - if (!(bcv instanceof VerifyingCompilerBytecodeVisitor)) { - bcv = new VerifyingCompilerBytecodeVisitor<CompilerBytecodeVisitor>(bcv); + try { + if (method.isNative()) { + Object label = new Label(method.getMangledName()); + cm.setCodeStart(os.getObjectRef(label)); + } else { + // Create the visitor + CompilerBytecodeVisitor bcv = getBytecodeVisitor(method, cm, os, level, isBootstrap); + + try { + // Wrap in verifier if needed + if (!(bcv instanceof VerifyingCompilerBytecodeVisitor)) { + bcv = new VerifyingCompilerBytecodeVisitor<CompilerBytecodeVisitor>(bcv); + } + // Get the bytecode + final VmByteCode bc = method.getBytecode(); + // Create the control flow graph + ControlFlowGraph cfg = (ControlFlowGraph) bc.getCompilerData(); + if (cfg == null) { + cfg = new ControlFlowGraph(bc); + bc.setCompilerData(cfg); + } + // Compile the code 1 basic block at a time + final CompilerBytecodeParser parser = new CompilerBytecodeParser(bc, cfg, bcv); + bcv.startMethod(method); + for (BasicBlock bb : cfg) { + bcv.startBasicBlock(bb); + parser.parse(bb.getStartPC(), bb.getEndPC(), false); + bcv.endBasicBlock(); + } + bcv.endMethod(); + + //remove the compiler data to save memory, will be regenerated if needed + bc.setCompilerData(null); + } finally { + releaseBytecodeVisitor(bcv); + } } - // Get the bytecode - final VmByteCode bc = method.getBytecode(); - // Create the control flow graph - ControlFlowGraph cfg = (ControlFlowGraph) bc.getCompilerData(); - if (cfg == null) { - cfg = new ControlFlowGraph(bc); - bc.setCompilerData(cfg); - } - // Compile the code 1 basic block at a time - final CompilerBytecodeParser parser = new CompilerBytecodeParser( - bc, cfg, bcv); - bcv.startMethod(method); - for (BasicBlock bb : cfg) { - bcv.startBasicBlock(bb); - parser.parse(bb.getStartPC(), bb.getEndPC(), false); - bcv.endBasicBlock(); - } - bcv.endMethod(); - - //remove the compiler data to save memory, will be regenerated if needed - bc.setCompilerData(null); + } catch (RuntimeException x) { + System.err.println("ERROR in compilation of " + method.getFullName()); + throw x; + } catch (Error x) { + System.err.println("ERROR in compilation of " + method.getFullName()); + throw x; } return cm; @@ -286,8 +297,8 @@ * @param isBootstrap * @return The compiled method */ - protected abstract CompiledMethod doCompileAbstract(VmMethod method, - NativeStream os, int level, boolean isBootstrap); + protected abstract CompiledMethod doCompileAbstract(VmMethod method, NativeStream os, int level, + boolean isBootstrap); /** * Create the visitor that converts bytecodes into native code. @@ -299,10 +310,17 @@ * @param isBootstrap * @return The new bytecode visitor. */ - protected abstract CompilerBytecodeVisitor createBytecodeVisitor( - VmMethod method, CompiledMethod cm, NativeStream os, int level, - boolean isBootstrap); + protected abstract CompilerBytecodeVisitor createBytecodeVisitor(VmMethod method, CompiledMethod cm, + NativeStream os, int level, boolean isBootstrap); + protected CompilerBytecodeVisitor getBytecodeVisitor(VmMethod method, CompiledMethod cm, NativeStream os, + int level, boolean isBootstrap) { + return createBytecodeVisitor(method, cm, os, level, isBootstrap); + } + + protected void releaseBytecodeVisitor(CompilerBytecodeVisitor visitor) { + + } /** * Initialize this compiler * Modified: trunk/core/src/core/org/jnode/vm/x86/compiler/l1a/X86Level1ACompiler.java =================================================================== --- trunk/core/src/core/org/jnode/vm/x86/compiler/l1a/X86Level1ACompiler.java 2010-03-28 19:12:41 UTC (rev 5740) +++ trunk/core/src/core/org/jnode/vm/x86/compiler/l1a/X86Level1ACompiler.java 2010-03-28 19:26:38 UTC (rev 5741) @@ -20,8 +20,6 @@ package org.jnode.vm.x86.compiler.l1a; -import java.util.ArrayList; -import java.util.List; import org.jnode.assembler.NativeStream; import org.jnode.assembler.ObjectResolver; import org.jnode.assembler.x86.X86BinaryAssembler; @@ -96,8 +94,6 @@ private final ThreadLocal<X86BytecodeVisitor> byteCodeVisitorHolder = new ThreadLocal<X86BytecodeVisitor>(); - private final ThreadLocal<List<X86BytecodeVisitor>> byteCodeVisitorListHolder = - new ThreadLocal<List<X86BytecodeVisitor>>(); /** * Create the visitor that converts bytecodes into native code. * @@ -115,37 +111,14 @@ final EntryPoints entryPoints = getEntryPoints(); X86BytecodeVisitor byteCodeVisitor = byteCodeVisitorHolder.get(); if (byteCodeVisitor == null) { - byteCodeVisitor = new X86BytecodeVisitor(os, cm, isBootstrap, entryPoints, - getMagicHelper(), getTypeSizeInfo()); - byteCodeVisitorHolder.set(byteCodeVisitor); + byteCodeVisitor = new X86BytecodeVisitor(os, cm, isBootstrap, entryPoints, getMagicHelper(), + getTypeSizeInfo()); } else { - if (byteCodeVisitor.isWorking()) { - //slow path - List<X86BytecodeVisitor> vlist = byteCodeVisitorListHolder.get(); - if (vlist == null) { - vlist = new ArrayList<X86BytecodeVisitor>(); - byteCodeVisitorListHolder.set(vlist); - } - byteCodeVisitor = null; - for (X86BytecodeVisitor bv : vlist) { - if (!bv.isWorking()) { - byteCodeVisitor = bv; - break; - } - } - if (byteCodeVisitor == null) { - byteCodeVisitor = new X86BytecodeVisitor(os, cm, isBootstrap, entryPoints, - getMagicHelper(), getTypeSizeInfo()); - vlist.add(byteCodeVisitor); - } else { - byteCodeVisitor.reset(os, cm, isBootstrap, entryPoints, getMagicHelper(), getTypeSizeInfo()); - } - } else { - byteCodeVisitor.reset(os, cm, isBootstrap, entryPoints, getMagicHelper(), getTypeSizeInfo()); - } + byteCodeVisitorHolder.remove(); + byteCodeVisitor.reset(os, cm, isBootstrap, entryPoints, getMagicHelper(), getTypeSizeInfo()); } cbv = byteCodeVisitor; - if (inlineMethods /*&& ((X86Assembler)os).isCode32()*/) { + if (inlineMethods) { final VmClassLoader loader = method.getDeclaringClass().getLoader(); return new OptimizingBytecodeVisitor(entryPoints, cbv, loader); } else { @@ -153,7 +126,18 @@ } } - private final MagicHelper getMagicHelper() { + @Override + protected synchronized void releaseBytecodeVisitor(CompilerBytecodeVisitor visitor) { + X86BytecodeVisitor bv; + if (inlineMethods) { + bv = (X86BytecodeVisitor) ((OptimizingBytecodeVisitor) visitor).getDelegate(); + } else { + bv = (X86BytecodeVisitor) visitor; + } + byteCodeVisitorHolder.set(bv); + } + + private MagicHelper getMagicHelper() { final MagicHelper helper = magicHelperHolder.get(); if (helper != null) { return helper; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |