Package com.google.gwt.dev.util.log.speedtracer.SpeedTracerLogger

Examples of com.google.gwt.dev.util.log.speedtracer.SpeedTracerLogger.Event


        // TODO(stalcup): hide metrics gathering in a callback or subclass
        logAstTypeMetrics(precompilationMetrics);

        // (6) Construct and return a value.
        Event createUnifiedAstEvent = SpeedTracerLogger.start(CompilerEventType.CREATE_UNIFIED_AST);
        UnifiedAst result = new UnifiedAst(
            options, new AST(jprogram, jsProgram), singlePermutation, RecordRebinds.exec(jprogram));
        createUnifiedAstEvent.end();
        return result;
      } catch (Throwable e) {
        throw CompilationProblemReporter.logAndTranslateException(logger, e);
      } finally {
        logTrackingStats();
View Full Code Here


    }

    private void unifyJavaAst(Set<String> allRootTypes, String entryMethodHolderTypeName)
        throws UnableToCompleteException {

      Event event = SpeedTracerLogger.start(CompilerEventType.UNIFY_AST);

      UnifyAst unifyAst;
      try {
        unifyAst = new UnifyAst(logger, compilerContext, jprogram, jsProgram, rpo);
      } catch (CollidingCompilationUnitException e) {
        logger.log(TreeLogger.ERROR, e.getMessage());
        throw new UnableToCompleteException();
      }
      // Makes JProgram aware of these types so they can be accessed via index.
      unifyAst.addRootTypes(allRootTypes);
      // Must synthesize entryPoint.onModuleLoad() calls because some EntryPoint classes are
      // private.
      if (entryMethodHolderTypeName != null) {
        // Only synthesize the init method in the EntryMethodHolder class, if there is an
        // EntryMethodHolder class.
        synthesizeEntryMethodHolderInit(unifyAst, entryMethodHolderTypeName);
      }
      if (entryMethodHolderTypeName != null) {
        // Only register the init method in the EntryMethodHolder class as an entry method, if there
        // is an EntryMethodHolder class.
        jprogram.addEntryMethod(jprogram.getIndexedMethod(
            SourceName.getShortClassName(entryMethodHolderTypeName) + ".init"));
      }
      unifyAst.exec();

      event.end();
    }
View Full Code Here

  private void injectJsniMethods(CompilationUnit unit) {
    if (unit == null || unit.getJsniMethods() == null) {
      return;
    }
    Event event = SpeedTracerLogger.start(DevModeEventType.LOAD_JSNI, "unit",
        unit.getTypeName());
    try {
      shellJavaScriptHost.createNativeMethods(logger, unit.getJsniMethods(),
          this);
    } finally {
      event.end();
    }
  }
View Full Code Here

  protected final boolean startUp() {
    if (started) {
      throw new IllegalStateException("Startup code has already been run");
    }

    Event startupEvent = SpeedTracerLogger.start(DevModeEventType.STARTUP);
    try {
      // See if there was a UI specified by command-line args
      ui = createUI();

      started = true;

      if (!doStartup()) {
        /*
         * TODO (amitmanjhi): Adding this redundant logging to narrow down a
         * failure. Remove soon.
         */
        getTopLogger().log(TreeLogger.ERROR, "shell failed in doStartup method");
        return false;
      }

      if (!options.isNoServer()) {
        int resultPort = doStartUpServer();
        if (resultPort < 0) {
          /*
           * TODO (amitmanjhi): Adding this redundant logging to narrow down a
           * failure. Remove soon.
           */
          getTopLogger().log(TreeLogger.ERROR, "shell failed in doStartupServer method");
          return false;
        }
        options.setPort(resultPort);
        getTopLogger().log(TreeLogger.TRACE, "Started web server on port " + resultPort);
      }

      if (options.getStartupURLs().isEmpty()) {
        // if no URLs were supplied, try and find plausible ones
        inferStartupUrls();
      }

      if (options.getStartupURLs().isEmpty()) {
        // TODO(jat): we could walk public resources to find plausible URLs
        // after the module(s) are loaded
        warnAboutNoStartupUrls();
      }

      setStartupUrls(getTopLogger());

      if (!doSlowStartup()) {
        /*
         * TODO (amitmanjhi): Adding this redundant logging to narrow down a
         * failure. Remove soon.
         */
        getTopLogger().log(TreeLogger.ERROR, "shell failed in doSlowStartup method");
        return false;
      }

      return true;
    } finally {
      startupEvent.end();
    }
  }
View Full Code Here

   * Create the UI and set the base log level for the UI.
   */
  private DevModeUI createUI() {
    DevModeUI newUI = null;

    Event createUIEvent = SpeedTracerLogger.start(DevModeEventType.CREATE_UI);

    if (headlessMode) {
      newUI = new HeadlessUI(options);
    } else {
      if (options.useRemoteUI()) {
        try {
          newUI =
              new RemoteUI(options.getRemoteUIHost(), options.getRemoteUIHostPort(), options
                  .getClientId());
          baseLogLevelForUI = TreeLogger.Type.TRACE;
        } catch (Throwable t) {
          System.err.println("Could not connect to remote UI listening at "
              + options.getRemoteUIHost() + ":" + options.getRemoteUIHostPort()
              + ". Using default UI instead.");
        }
      }
    }

    if (newUI == null) {
      newUI = new SwingUI(options);
    }

    if (baseLogLevelForUI == null) {
      baseLogLevelForUI = TreeLogger.Type.INFO;
    }

    createUIEvent.end();
    return newUI;
  }
View Full Code Here

    }

    @Override
    public ModuleSpaceHost createModuleSpaceHost(ModuleHandle module, String moduleName)
        throws UnableToCompleteException {
      Event moduleSpaceHostCreateEvent =
          SpeedTracerLogger.start(DevModeEventType.MODULE_SPACE_HOST_CREATE, "Module Name",
              moduleName);
      // TODO(jat): add support for closing an active module
      TreeLogger logger = module.getLogger();
      try {
        // Try to find an existing loaded version of the module def.
        ModuleDef moduleDef = loadModule(logger, moduleName, true);
        assert (moduleDef != null);

        ArchivePreloader.preloadArchives(logger, compilerContext);

        CompilationState compilationState = moduleDef.getCompilationState(logger, compilerContext);
        ShellModuleSpaceHost host =
            doCreateShellModuleSpaceHost(logger, compilationState, moduleDef);
        return host;
      } catch (RuntimeException e) {
        logger.log(TreeLogger.ERROR, "Exception initializing module", e);
        module.unload();
        throw e;
      } finally {
        moduleSpaceHostCreateEvent.end();
      }
    }
View Full Code Here

    if (type == null) {
      type = CompilerEventType.GENERATOR_OTHER;
    }

    Event generatorEvent =
        SpeedTracerLogger.start(type, "class", generatorClassName, "type", typeName);

    PropertyOracle originalPropertyOracle = propertyOracle;
    try {
      RebindResult result;
      // TODO(stalcup): refactor the Generator/PropertyOracle system (in a potentially backwards
      // incompatible way) so that all Generators are forced to accurately declare the names of
      // properties they care about.
      propertyOracle = new SubsetFilteringPropertyOracle(
          RuleGenerateWith.getAccessedPropertyNames(generator.getClass()), originalPropertyOracle,
          generatorClassName + "'s RunsLocal annotation may need to be updated.");
      if (generator instanceof IncrementalGenerator) {
        IncrementalGenerator incGenerator = (IncrementalGenerator) generator;

        // check version id for any previously cached rebind result
        if (cachedRebindResult != null) {
          Long cachedVersionId = (Long) cachedRebindResult.getClientData(GENERATOR_VERSION_ID_KEY);
          if (cachedVersionId != null && cachedVersionId != incGenerator.getVersionId()) {
            // remove from context
            if (logger.isLoggable(TreeLogger.TRACE)) {
              logger.log(TreeLogger.TRACE, "Got version mismatch with cached generator result for "
                  + typeName + ", invalidating cached result");
            }
            cachedRebindResult = null;
          }
        }

        // run the generator
        result = incGenerator.generateIncrementally(logger, this, typeName);

        // add version id to the returned result
        result.putClientData(GENERATOR_VERSION_ID_KEY, incGenerator.getVersionId());
      } else {
        // run a non-incremental generator
        result = IncrementalGenerator.generateNonIncrementally(logger, generator, this, typeName);
      }

      if (loggable) {
        long after = System.currentTimeMillis();
        msg =
            "Generator returned type '" + result.getResultTypeName() + "; mode "
                + result.getRebindMode() + "; in " + (after - before) + " ms";
        logger.log(TreeLogger.DEBUG, msg, null);
      }
      return result;
    } catch (AssertionError e) {
      // Catch and log the assertion as a convenience to the developer
      logger.log(TreeLogger.ERROR, "Generator '" + generatorClass.getName()
          + "' failed an assertion while rebinding '" + typeName + "'", e);
      throw new UnableToCompleteException();
    } catch (RuntimeException e) {
      logger.log(TreeLogger.ERROR, "Generator '" + generatorClass.getName()
          + "' threw an exception while rebinding '" + typeName + "'", e);
      throw new UnableToCompleteException();
    } finally {
      propertyOracle = originalPropertyOracle;
      generatorEvent.end();
    }
  }
View Full Code Here

   * Invoke a method on a server object in from client code.
   */
  @Override
  public ExceptionOrReturnValue invoke(BrowserChannelServer channel,
      Value thisVal, int methodDispatchId, Value[] args) {
    Event jsToJavaCallEvent =
        SpeedTracerLogger.start(channel.getDevModeSession(), DevModeEventType.JS_TO_JAVA_CALL);
    ServerObjectsTable localObjects = channel.getJavaObjectsExposedInBrowser();
    ModuleSpace moduleSpace = moduleMap.get(channel);
    ModuleHandle moduleHandle = moduleHandleMap.get(channel);
    assert moduleSpace != null && moduleHandle != null;
    TreeLogger logger = moduleHandle.getLogger();
    CompilingClassLoader cl = moduleSpace.getIsolatedClassLoader();

    // Treat dispatch id 0 as toString()
    if (methodDispatchId == 0) {
      methodDispatchId = cl.getDispId("java.lang.Object::toString()");
    }

    JsValueOOPHM jsThis = new JsValueOOPHM();
    channel.convertToJsValue(cl, localObjects, thisVal, jsThis);

    if (SpeedTracerLogger.jsniCallLoggingEnabled()) {
      DispatchClassInfo clsInfo = cl.getClassInfoByDispId(methodDispatchId);
      if (clsInfo != null) {
        Member member = clsInfo.getMember(methodDispatchId);
        if (member != null) {
          jsToJavaCallEvent.addData("name", member.toString());
        }
      }
    }

    TreeLogger branch = TreeLogger.NULL;
    if (logger.isLoggable(TreeLogger.SPAM)) {
      StringBuffer logMsg = new StringBuffer();
      logMsg.append("Client invoke of ");
      logMsg.append(methodDispatchId);
      DispatchClassInfo classInfo = cl.getClassInfoByDispId(methodDispatchId);
      if (classInfo != null) {
        Member member = classInfo.getMember(methodDispatchId);
        if (member != null) {
          logMsg.append(" (");
          logMsg.append(member.getName());
          logMsg.append(")");
        }
      }
      logMsg.append(" on ");
      logMsg.append(jsThis.toString());
      branch = logger.branch(TreeLogger.SPAM, logMsg.toString(), null);
    }
    JsValueOOPHM[] jsArgs = new JsValueOOPHM[args.length];
    for (int i = 0; i < args.length; ++i) {
      jsArgs[i] = new JsValueOOPHM();
      channel.convertToJsValue(cl, localObjects, args[i], jsArgs[i]);
      if (logger.isLoggable(TreeLogger.SPAM)) {
        branch.log(TreeLogger.SPAM, " arg " + i + " = " + jsArgs[i].toString(),
            null);
      }
    }
    JsValueOOPHM jsRetVal = new JsValueOOPHM();
    JsValueOOPHM jsMethod;
    DispatchObject dispObj;
    if (jsThis.isWrappedJavaObject()) {
      // If this is a wrapped object, get get the method off it.
      dispObj = jsThis.getJavaObjectWrapper();
    } else {
      // Look it up on the static dispatcher.
      dispObj = (DispatchObject) moduleSpace.getStaticDispatcher();
    }
    jsMethod = (JsValueOOPHM) dispObj.getField(methodDispatchId);
    DispatchMethod dispMethod = jsMethod.getWrappedJavaFunction();
    boolean exception;
    try {
      exception = dispMethod.invoke(jsThis, jsArgs, jsRetVal);
    } catch (Throwable t) {
      exception = true;
      JsValueGlue.set(jsRetVal, moduleSpace.getIsolatedClassLoader(),
          t.getClass(), t);
    }
    Value retVal = channel.convertFromJsValue(localObjects, jsRetVal);
    jsToJavaCallEvent.end();
    return new ExceptionOrReturnValue(exception, retVal);
  }
View Full Code Here

  @Override
  public synchronized TreeLogger loadModule(BrowserChannelServer channel,
      String moduleName, String userAgent, String url, String tabKey,
      String sessionKey, byte[] userAgentIcon) {
    Event moduleInit =
        SpeedTracerLogger.start(channel.getDevModeSession(), DevModeEventType.MODULE_INIT,
            "Module Name", moduleName);
    ModuleHandle moduleHandle = host.createModuleLogger(moduleName, userAgent,
        url, tabKey, sessionKey, channel, userAgentIcon);
    TreeLogger logger = moduleHandle.getLogger();
    moduleHandleMap.put(channel, moduleHandle);
    ModuleSpace moduleSpace = null;
    try {
      // Attach a new ModuleSpace to make it programmable.
      ModuleSpaceHost msh = host.createModuleSpaceHost(moduleHandle, moduleName);
      moduleSpace = new ModuleSpaceOOPHM(msh, moduleName, channel);
      moduleMap.put(channel, moduleSpace);
      moduleSpace.onLoad(logger);
      if (logger.isLoggable(TreeLogger.INFO)) {
        moduleHandle.getLogger().log(TreeLogger.INFO,
            "Module " + moduleName + " has been loaded");
      }
    } catch (Throwable e) {
      // We do catch Throwable intentionally because there are a ton of things
      // that can go wrong trying to load a module, including Error-derived
      // things like NoClassDefFoundError.
      //
      moduleHandle.getLogger().log(
          TreeLogger.ERROR,
          "Failed to load module '" + moduleName + "' from user agent '"
              + userAgent + "' at " + channel.getRemoteEndpoint(), e);
      if (moduleSpace != null) {
        moduleSpace.dispose();
      }
      moduleHandle.unload();
      moduleMap.remove(channel);
      moduleHandleMap.remove(channel);
      return null;
    } finally {
      moduleInit.end();
    }
    return moduleHandle.getLogger();
  }
View Full Code Here

     * Significant amounts of visitors implementing the intended above stages are triggered here but
     * in the wrong order. They have been noted for future cleanup.
     */
    public PermutationResult compilePermutation(UnifiedAst unifiedAst)
        throws UnableToCompleteException {
      Event jjsCompilePermutationEvent = SpeedTracerLogger.start(
          CompilerEventType.JJS_COMPILE_PERMUTATION, "name", permutation.getProps().prettyPrint()
      );
      /*
       * Do not introduce any new pass here unless it is logically a part of one of the 9 defined
       * stages and is physically located in that stage.
       */

      long permStartMs = System.currentTimeMillis();
      try {
        Event javaEvent = SpeedTracerLogger.start(CompilerEventType.PERMUTATION_JAVA);

        // (1) Initialize local state.
        long startTimeMs = System.currentTimeMillis();
        PermProps props = permutation.getProps();
        int permutationId = permutation.getId();
        AST ast = unifiedAst.getFreshAst();
        jprogram = ast.getJProgram();
        jsProgram = ast.getJsProgram();
        Map<StandardSymbolData, JsName> symbolTable =
            new TreeMap<StandardSymbolData, JsName>(new SymbolData.ClassIdentComparator());

        // TODO(stalcup): hide metrics gathering in a callback or subclass
        if (compilerContext.shouldCompileMonolithic() && logger.isLoggable(TreeLogger.INFO)) {
          logger.log(TreeLogger.INFO, "Compiling permutation " + permutationId + "...");
        }
        printPermutationTrace(permutation);

        // (2) Transform unresolved Java AST to resolved Java AST
        ResolveRebinds.exec(jprogram, permutation.getGwtCreateAnswers());

        // TODO(stalcup): hide metrics gathering in a callback or subclass
        // This has to happen before optimizations because functions might
        // be optimized out; we want those marked as "not executed", not "not
        // instrumentable".
        Multimap<String, Integer> instrumentableLines = null;
        if (System.getProperty("gwt.coverage") != null) {
          instrumentableLines = BaselineCoverageGatherer.exec(jprogram);
        }

        // TypeOracle needs this to make decisions in several optimization passes
        jprogram.typeOracle.setJsInteropMode(compilerContext.getOptions().getJsInteropMode());

        // Record initial set of type->type references.
        // type->type references need to be collected in two phases, 1) before any process to the
        // AST has happened (to record for example reference to types declaring compile-time
        // constants) and 2) after all normalizations to collect synthetic references (e.g. to
        // record references to runtime classes like LongLib).
        maybeRecordTypeReferences(false);

        // Replace compile time constants by their values.
        // TODO(rluble): eventually move to normizeSemantics.
        CompileTimeConstantsReplacer.exec(jprogram);

        // TODO(stalcup): move to after normalize.
        // (3) Optimize the resolved Java AST
        optimizeJava();

        // TODO(stalcup): move to before optimize.
        // (4) Normalize the resolved Java AST
        TypeMapper<?> typeMapper = normalizeSemantics();

        // TODO(stalcup): this stage shouldn't exist, move into optimize.
        postNormalizationOptimizeJava();

        // Now that the AST has stopped mutating update with the final references.
        maybeRecordTypeReferences(true);

        jprogram.typeOracle.recomputeAfterOptimizations(jprogram.getDeclaredTypes());

        javaEvent.end();

        Event javaScriptEvent = SpeedTracerLogger.start(CompilerEventType.PERMUTATION_JAVASCRIPT);

        // (5) Construct the Js AST
        Pair<? extends JavaToJavaScriptMap, Set<JsNode>> jjsMapAndInlineableFunctions =
            GenerateJavaScriptAST.exec(logger, jprogram, jsProgram,
                compilerContext, typeMapper, symbolTable, props);
        JavaToJavaScriptMap jjsmap = jjsMapAndInlineableFunctions.getLeft();

        // TODO(stalcup): hide metrics gathering in a callback or subclass
        if (System.getProperty("gwt.coverage") != null) {
          CoverageInstrumentor.exec(jsProgram, instrumentableLines);
        }

        // (6) Normalize the Js AST
        JsNormalizer.exec(jsProgram);

        // TODO(stalcup): move to AST construction
        JsSymbolResolver.exec(jsProgram);
        if (options.getNamespace() == JsNamespaceOption.PACKAGE) {
          JsNamespaceChooser.exec(jsProgram, jjsmap);
        }

        // TODO(stalcup): move to normalization
        EvalFunctionsAtTopScope.exec(jsProgram, jjsmap);

        // (7) Optimize the JS AST.
        final Set<JsNode> inlinableJsFunctions = jjsMapAndInlineableFunctions.getRight();
        optimizeJs(inlinableJsFunctions);

        // TODO(stalcup): move to normalization
        // Must run before code splitter and namer.
        JsStackEmulator.exec(jprogram, jsProgram, props, jjsmap);

        // TODO(stalcup): move to normalization
        Pair<SyntheticArtifact, MultipleDependencyGraphRecorder> dependenciesAndRecorder =
            splitJsIntoFragments(props, permutationId, jjsmap);

        // TODO(stalcup): move to optimize.
        Map<JsName, JsLiteral> internedLiteralByVariableName = renameJsSymbols(props);

        // TODO(stalcup): move to normalization
        JsBreakUpLargeVarStatements.exec(jsProgram, props.getConfigProps());

        // (8) Generate Js source
        List<JsSourceMap> sourceInfoMaps = new ArrayList<JsSourceMap>();
        boolean isSourceMapsEnabled = props.isTrueInAnyPermutation("compiler.useSourceMaps");
        String[] jsFragments = new String[jsProgram.getFragmentCount()];
        StatementRanges[] ranges = new StatementRanges[jsFragments.length];
        SizeBreakdown[] sizeBreakdowns = options.isJsonSoycEnabled() || options.isSoycEnabled()
            || options.isCompilerMetricsEnabled() ? new SizeBreakdown[jsFragments.length] : null;
        generateJavaScriptCode(jjsmap, jsFragments, ranges, sizeBreakdowns, sourceInfoMaps,
            isSourceMapsEnabled || options.isJsonSoycEnabled());

        javaScriptEvent.end();

        // (9) Construct and return a value
        PermutationResult permutationResult =
            new PermutationResultImpl(jsFragments, permutation, makeSymbolMap(symbolTable), ranges);

View Full Code Here

TOP

Related Classes of com.google.gwt.dev.util.log.speedtracer.SpeedTracerLogger.Event

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.