Example #1
0
void
shutdownJit()
   {
   auto fe = TestCompiler::FrontEnd::instance();

   TR::CodeCacheManager &codeCacheManager = fe->codeCacheManager();
   codeCacheManager.destroy();
#if defined(TR_TARGET_POWER)
   delete fe->getPersistentInfo()->getPersistentTOC();
   fe->getPersistentInfo()->setPersistentTOC(NULL);
#endif

   }
Example #2
0
uint8_t *
compileMethodFromDetails(
      OMR_VMThread *omrVMThread,
      TR::IlGeneratorMethodDetails & details,
      TR_Hotness hotness,
      int32_t &rc)
   {
   uint64_t translationStartTime = TR::Compiler->vm.getUSecClock();
   OMR::FrontEnd &fe = OMR::FrontEnd::singleton();
   auto jitConfig = fe.jitConfig();
   TR::RawAllocator rawAllocator;
   TR::SystemSegmentProvider defaultSegmentProvider(1 << 16, rawAllocator);
   TR::DebugSegmentProvider debugSegmentProvider(1 << 16, rawAllocator);
   TR::SegmentAllocator &scratchSegmentProvider =
      TR::Options::getCmdLineOptions()->getOption(TR_EnableScratchMemoryDebugging) ?
         static_cast<TR::SegmentAllocator &>(debugSegmentProvider) :
         static_cast<TR::SegmentAllocator &>(defaultSegmentProvider);
   TR::Region dispatchRegion(scratchSegmentProvider, rawAllocator);
   TR_Memory trMemory(*fe.persistentMemory(), dispatchRegion);
   TR_ResolvedMethod & compilee = *((TR_ResolvedMethod *)details.getMethod());

   TR::CompileIlGenRequest request(details);

   // initialize return code before compilation starts
   rc = COMPILATION_REQUESTED;

   uint8_t *startPC = 0;

   TR_FilterBST *filterInfo = 0;
   TR_OptimizationPlan *plan = 0;
   if (!methodCanBeCompiled(&fe, compilee, filterInfo, &trMemory))
      {
      if (TR::Options::getCmdLineOptions()->getVerboseOption(TR_VerboseCompileExclude))
         {
         TR_VerboseLog::write("<JIT: %s cannot be translated>\n",
                              compilee.signature(&trMemory));
         }
      return 0;
      }

   if (0 == (plan = TR_OptimizationPlan::alloc(hotness, false, false)))
      {
      // FIXME: maybe it would be better to allocate the plan on the stack
      // so that we don't have to deal with OOM ugliness below
      if (TR::Options::getCmdLineOptions()->getVerboseOption(TR_VerboseCompileExclude))
         {
         TR_VerboseLog::write("<JIT: %s out-of-memory allocating optimization plan>\n",
                              compilee.signature(&trMemory));
         }
      return 0;
      }

   int32_t optionSetIndex = filterInfo ? filterInfo->getOptionSet() : 0;
   int32_t lineNumber = filterInfo ? filterInfo->getLineNumber() : 0;
   TR::Options options(
         &trMemory,
         optionSetIndex,
         lineNumber,
         &compilee,
         0,
         plan,
         false);

   // FIXME: once we can do recompilation , we need to pass in the old start PC  -----------------------^

   // FIXME: what happens if we can't allocate memory at the new above?
   // FIXME: perhaps use stack memory instead

   TR_ASSERT(TR::comp() == NULL, "there seems to be a current TLS TR::Compilation object %p for this thread. At this point there should be no current TR::Compilation object", TR::comp());
   TR::Compilation compiler(0, omrVMThread, &fe, &compilee, request, options, dispatchRegion, &trMemory, plan);
   TR_ASSERT(TR::comp() == &compiler, "the TLS TR::Compilation object %p for this thread does not match the one %p just created.", TR::comp(), &compiler);

   try
      {
      //fprintf(stderr,"loading JIT debug\n");
      if (TR::Options::requiresDebugObject()
          || options.getLogFileName()
          || options.enableDebugCounters())
         {
         compiler.setDebug(createDebugObject(&compiler));
         }

      compiler.setIlVerifier(details.getIlVerifier());

      if (TR::Options::getCmdLineOptions()->getVerboseOption(TR_VerboseCompileStart))
         {
         const char *signature = compilee.signature(&trMemory);
         TR_VerboseLog::writeLineLocked(TR_Vlog_COMPSTART,"compiling %s",
                                                          signature);
         }

      if (compiler.getOutFile() != NULL && compiler.getOption(TR_TraceAll))
         {
         const char *signature = compilee.signature(&trMemory);
         traceMsg((&compiler), "<compile hotness=\"%s\" method=\"%s\">\n",
                               compiler.getHotnessName(compiler.getMethodHotness()),
                               signature);
         }

      compiler.getJittedMethodSymbol()->setLinkage(TR_System);

      // --------------------------------------------------------------------
      // Compile the method
      //
      rc = compiler.compile();

      if (rc == COMPILATION_SUCCEEDED) // success!
         {

         // not ready yet...
         //OMR::MethodMetaDataPOD *metaData = fe.createMethodMetaData(&compiler);

         startPC = compiler.cg()->getCodeStart();
         uint64_t translationTime = TR::Compiler->vm.getUSecClock() - translationStartTime;

         if (TR::Options::isAnyVerboseOptionSet(TR_VerboseCompileEnd, TR_VerbosePerformance))
            {
            const char *signature = compilee.signature(&trMemory);
            TR_VerboseLog::vlogAcquire();
            TR_VerboseLog::writeLine(TR_Vlog_COMP,"(%s) %s @ " POINTER_PRINTF_FORMAT "-" POINTER_PRINTF_FORMAT,
                                           compiler.getHotnessName(compiler.getMethodHotness()),
                                           signature,
                                           startPC,
                                           compiler.cg()->getCodeEnd());

            if (TR::Options::getVerboseOption(TR_VerbosePerformance))
               {
               TR_VerboseLog::write(
                  " time=%llu mem=%lluKB",
                  translationTime,
                  static_cast<unsigned long long>(scratchSegmentProvider.bytesAllocated()) / 1024
                  );
               }

            TR_VerboseLog::vlogRelease();
            trfflush(jitConfig->options.vLogFile);
            }

         if (
               TR::Options::getCmdLineOptions()->getOption(TR_PerfTool) 
            || TR::Options::getCmdLineOptions()->getOption(TR_EmitExecutableELFFile)
            || TR::Options::getCmdLineOptions()->getOption(TR_EmitRelocatableELFFile)
            )
            {
            TR::CodeCacheManager &codeCacheManager(fe.codeCacheManager());
            TR::CodeGenerator &codeGenerator(*compiler.cg());
            codeCacheManager.registerCompiledMethod(compiler.externalName(), startPC, codeGenerator.getCodeLength());
            if (TR::Options::getCmdLineOptions()->getOption(TR_EmitRelocatableELFFile))
               {
               auto &relocations = codeGenerator.getStaticRelocations();
               for (auto it = relocations.begin(); it != relocations.end(); ++it)
                  {
                  codeCacheManager.registerStaticRelocation(*it);
                  }
               }
            if (TR::Options::getCmdLineOptions()->getOption(TR_PerfTool))
               {
               generatePerfToolEntry(startPC, codeGenerator.getCodeEnd(), compiler.signature(), compiler.getHotnessName(compiler.getMethodHotness()));
               }
            }

         if (compiler.getOutFile() != NULL && compiler.getOption(TR_TraceAll))
            traceMsg((&compiler), "<result success=\"true\" startPC=\"%#p\" time=\"%lld.%lldms\"/>\n",
                                  startPC,
                                  translationTime/1000,
                                  translationTime%1000);
         }
      else /* of rc == COMPILATION_SUCCEEDED */
         {
         TR_ASSERT(false, "compiler error code %d returned\n", rc);
         }

      if (compiler.getOption(TR_BreakAfterCompile))
         {
         TR::Compiler->debug.breakPoint();
         }

      }
   catch (const TR::ILValidationFailure &exception)
      {
      rc = COMPILATION_IL_VALIDATION_FAILURE;
#if defined(J9ZOS390)
      // Compiling with -Wc,lp64 results in a crash on z/OS when trying
      // to call the what() virtual method of the exception.
      printCompFailureInfo(jitConfig, &compiler, "");
#else
      printCompFailureInfo(jitConfig, &compiler, exception.what());
#endif
      } 
   catch (const std::exception &exception)
      {
      // failed! :-(

#if defined(J9ZOS390)
      // Compiling with -Wc,lp64 results in a crash on z/OS when trying
      // to call the what() virtual method of the exception.
      printCompFailureInfo(jitConfig, &compiler, "");
#else
      printCompFailureInfo(jitConfig, &compiler, exception.what());
#endif
      }

   // A better place to do this would have been the destructor for
   // TR::Compilation. We'll need exceptions working instead of setjmp
   // before we can get working, and we need to make sure the other
   // frontends are properly calling the destructor
   TR::CodeCacheManager::instance()->unreserveCodeCache(compiler.getCurrentCodeCache());

   TR_OptimizationPlan::freeOptimizationPlan(plan);


   return startPC;
   }