Shark
Upcoming SlideShare
Loading in...5
×

Like this? Share it with your network

Share

Shark

  • 1,027 views
Uploaded on

Memo for JVM source code reading event #6 on 2012-02-18.

Memo for JVM source code reading event #6 on 2012-02-18.

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
1,027
On Slideshare
1,027
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
12
Comments
0
Likes
3

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. 6 JVM (OpenJDK6) Zero/Sharkhttp://today.java.net/pub/a/today/2009/05/21/zero-and-shark-openjdk-port.html
  • 2. hg clone http://icedtea.classpath.org/hg/release/icedtea6-1.11sh autogen.sh./configure --enable-zero --enable-shark:checking for a JamVM source zip... not specifiedchecking whether to disable optimizations and buildwith -O0 -g... nochecking whether to use the Shark JIT... yesconfigure: error: shark is unsupported in thisrelease
  • 3. void TemplateTable::initialize() {  def(Bytecodes::_iadd , ____|____|____|____, itos, itos,iop2                , add          );  def(Bytecodes::_ladd , ____|____|____|____, ltos, ltos,lop2                , add          );0 templateTable.hpp        <global>       267 static void invokevirtual(intbyte_no);1 templateTable_sparc.cpp  invokevirtual 2947 voidTemplateTable::invokevirtual(int byte_no)                                              {2 templateTable_x86_32.cpp invokevirtual 2993 voidTemplateTable::invokevirtual(int byte_no)                                              {3 templateTable_x86_64.cpp invokevirtual 3001 voidTemplateTable::invokevirtual(int byte_no)                                              {4 templateTable.cpp        initialize     441 def(Bytecodes::_invokevirtual ,                                              ubcp|disp|clvm|____, vtos,vtos, invokevirtual                                              , f2_byte );
  • 4. 0 cpu/sparc/vm/templateTable_sparc.cpp1 cpu/sparc/vm/templateTable_sparc.hpp2 cpu/x86/vm/templateTable_x86_32.cpp3 cpu/x86/vm/templateTable_x86_32.hpp4 cpu/x86/vm/templateTable_x86_64.cpp5 cpu/x86/vm/templateTable_x86_64.hpp6 cpu/zero/vm/templateTable_zero.cpp          // empty7 cpu/zero/vm/templateTable_zero.hpp          // empty8 share/vm/interpreter/templateTable.cpp9 share/vm/interpreter/templateTable.hpp
  • 5. No template interpreter for zero...$ more cpu/zero/vm/*...SharkFrame : public ZeroFrameZeroStack$ ls share/vm/sharkllvmHeaders.hpp          sharkEntry.hpp          sharkStack.cppllvmValue.hpp          sharkFunction.cpp     sharkStack.hppsharkBlock.cpp          sharkFunction.hpp     sharkState.cppsharkBlock.hpp          sharkInliner.cpp     sharkState.hppsharkBuilder.cpp     sharkInliner.hpp     sharkStateScanner.cpp
  • 6. ** llvmHeaders.hpp#include <llvm/Argument.h>#include <llvm/Constants.h>#include <llvm/DerivedTypes.h>#include <llvm/ExecutionEngine/ExecutionEngine.h>#include <llvm/Instructions.h>#include <llvm/LLVMContext.h>#include <llvm/Module.h>#if SHARK_LLVM_VERSION < 27#include <llvm/ModuleProvider.h>#endif
  • 7. IRBuilderBuilder.CreateAddBuilder.CreateCallBuilder.CreateRetFunction::CreateBasicBlock::Createfcmpuitofpsitofpcallret  FunctionPassManager OurFPM(TheModule);  // Set up the optimizer pipeline.  Start with registering info about howthe  // target lays out data structures.  OurFPM.add(new TargetData(*TheExecutionEngine->getTargetData()));  // Do simple "peephole" optimizations and bit-twiddling optzns.  OurFPM.add(createInstructionCombiningPass());
  • 8.   // Create the JIT.  This takes ownership of the module.  TheExecutionEngine = EngineBuilder(TheModule).create();--- back to shark$ grep ExecutionEngine *llvmHeaders.hpp:#include <llvm/ExecutionEngine/ExecutionEngine.h>llvmHeaders.hpp:#include <llvm/ExecutionEngine/JITMemoryManager.h>llvmHeaders.hpp:#include <llvm/ExecutionEngine/JIT.h>sharkCompiler.cpp:  _execution_engine_lock = new Monitor(Mutex::leaf,"SharkExecutionEngineLock");sharkCompiler.cpp:  _execution_engine = ExecutionEngine::createJIT(sharkCompiler.hpp:  llvm::ExecutionEngine* _execution_engine;sharkCompiler.hpp:  llvm::ExecutionEngine* execution_engine() const {
  • 9. SharkCompiler::compile_method()SharkFunction::build() native code register_method.class SharkFunction : public SharkTargetInvariants { friend class SharkStackWithNormalFrame; public:  static llvm::Function* build(ciEnv*        env,                               SharkBuilder* builder,                               ciTypeFlow*   flow,                               const char*   name) {    SharkFunction function(env, builder, flow, name);    return function.function();  }
  • 10. sharkBlock.cpp:void SharkBlock::parse_bytecode(int start, int limit)    case Bytecodes::_iadd:      b = pop();      a = pop();      push(SharkValue::create_jint(        builder()->CreateAdd(a->jint_value(), b->jint_value()), false)); // Create the JIT  std::string ErrorMsg;  EngineBuilder builder(_normal_context->module());  builder.setMCPU(MCPU);  builder.setMAttrs(MAttrs);  builder.setJITMemoryManager(memory_manager());  builder.setEngineKind(EngineKind::JIT);  builder.setErrorStr(&ErrorMsg);  _execution_engine = builder.create();