433 List<DebugVerifyHandler> verifyHandlers = new ArrayList<>();
434 for (DebugHandlersFactory factory : factories) {
435 for (DebugHandler handler : factory.createHandlers(options)) {
436 if (handler instanceof DebugDumpHandler) {
437 dumpHandlers.add((DebugDumpHandler) handler);
438 } else {
439 assert handler instanceof DebugVerifyHandler;
440 verifyHandlers.add((DebugVerifyHandler) handler);
441 }
442 }
443 }
444 currentConfig = new DebugConfigImpl(options, logStream, dumpHandlers, verifyHandlers);
445 currentScope = new ScopeImpl(this, Thread.currentThread());
446 currentScope.updateFlags(currentConfig);
447 metricsEnabled = true;
448 } else {
449 metricsEnabled = immutable.hasUnscopedMetrics() || immutable.listMetrics;
450 }
451 }
452
453 public Path getDumpPath(String extension, boolean directory) {
454 try {
455 String id = description == null ? null : description.identifier;
456 String label = description == null ? null : description.getLabel();
457 Path result = PathUtilities.createUnique(immutable.options, DumpPath, id, label, extension, directory);
458 if (ShowDumpFiles.getValue(immutable.options)) {
459 TTY.println("Dumping debug output to %s", result.toAbsolutePath().toString());
460 }
461 return result;
462 } catch (IOException ex) {
463 throw rethrowSilently(RuntimeException.class, ex);
464 }
465 }
466
467 /**
468 * A special dump level that indicates the dumping machinery is enabled but no dumps will be
469 * produced except through other options.
470 */
471 public static final int ENABLED_LEVEL = 0;
472
473 /**
474 * Basic debug level.
475 *
476 * For HIR dumping, only ~5 graphs per method: after parsing, after inlining, after high tier,
477 * after mid tier, after low tier.
790 if (config == null) {
791 return disable();
792 }
793 if (currentScope != null) {
794 return enterScope(name, config, context);
795 } else {
796 return null;
797 }
798 }
799
800 /**
801 * Determines if scopes are enabled and this context is in a non-top-level scope.
802 */
803 public boolean inNestedScope() {
804 if (immutable.scopesEnabled) {
805 if (currentScope == null) {
806 // In an active DisabledScope
807 return true;
808 }
809 return !currentScope.isTopLevel();
810 }
811 return immutable.scopesEnabled && currentScope == null;
812 }
813
814 class DisabledScope implements DebugContext.Scope {
815 final boolean savedMetricsEnabled;
816 final ScopeImpl savedScope;
817 final DebugConfigImpl savedConfig;
818
819 DisabledScope() {
820 this.savedMetricsEnabled = metricsEnabled;
821 this.savedScope = currentScope;
822 this.savedConfig = currentConfig;
823 metricsEnabled = false;
824 currentScope = null;
825 currentConfig = null;
826 }
827
828 @Override
829 public String getQualifiedName() {
830 return "";
831 }
|
433 List<DebugVerifyHandler> verifyHandlers = new ArrayList<>();
434 for (DebugHandlersFactory factory : factories) {
435 for (DebugHandler handler : factory.createHandlers(options)) {
436 if (handler instanceof DebugDumpHandler) {
437 dumpHandlers.add((DebugDumpHandler) handler);
438 } else {
439 assert handler instanceof DebugVerifyHandler;
440 verifyHandlers.add((DebugVerifyHandler) handler);
441 }
442 }
443 }
444 currentConfig = new DebugConfigImpl(options, logStream, dumpHandlers, verifyHandlers);
445 currentScope = new ScopeImpl(this, Thread.currentThread());
446 currentScope.updateFlags(currentConfig);
447 metricsEnabled = true;
448 } else {
449 metricsEnabled = immutable.hasUnscopedMetrics() || immutable.listMetrics;
450 }
451 }
452
453 public Path getDumpPath(String extension, boolean createMissingDirectory) {
454 try {
455 String id = description == null ? null : description.identifier;
456 String label = description == null ? null : description.getLabel();
457 Path result = PathUtilities.createUnique(immutable.options, DumpPath, id, label, extension, createMissingDirectory);
458 if (ShowDumpFiles.getValue(immutable.options)) {
459 TTY.println("Dumping debug output to %s", result.toAbsolutePath().toString());
460 }
461 return result;
462 } catch (IOException ex) {
463 throw rethrowSilently(RuntimeException.class, ex);
464 }
465 }
466
467 /**
468 * A special dump level that indicates the dumping machinery is enabled but no dumps will be
469 * produced except through other options.
470 */
471 public static final int ENABLED_LEVEL = 0;
472
473 /**
474 * Basic debug level.
475 *
476 * For HIR dumping, only ~5 graphs per method: after parsing, after inlining, after high tier,
477 * after mid tier, after low tier.
790 if (config == null) {
791 return disable();
792 }
793 if (currentScope != null) {
794 return enterScope(name, config, context);
795 } else {
796 return null;
797 }
798 }
799
800 /**
801 * Determines if scopes are enabled and this context is in a non-top-level scope.
802 */
803 public boolean inNestedScope() {
804 if (immutable.scopesEnabled) {
805 if (currentScope == null) {
806 // In an active DisabledScope
807 return true;
808 }
809 return !currentScope.isTopLevel();
810 } else {
811 return false;
812 }
813 }
814
815 class DisabledScope implements DebugContext.Scope {
816 final boolean savedMetricsEnabled;
817 final ScopeImpl savedScope;
818 final DebugConfigImpl savedConfig;
819
820 DisabledScope() {
821 this.savedMetricsEnabled = metricsEnabled;
822 this.savedScope = currentScope;
823 this.savedConfig = currentConfig;
824 metricsEnabled = false;
825 currentScope = null;
826 currentConfig = null;
827 }
828
829 @Override
830 public String getQualifiedName() {
831 return "";
832 }
|