{"record":{"id":"a952c9eb62efd048","repo":"openjdk/jdk","slug":"used-mask-is-0","errorCode":null,"errorMessage":"*** used_mask is 0 ***\n","messagePattern":"\\*\\*\\* used_mask is 0 \\*\\*\\*\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/hotspot/share/adlc/output_c.cpp","lineNumber":481,"sourceCode":"  static const char* pipeline_use_element    = \"Pipeline_Use_Element\";\n\n  templen = 1 +\n    (int)(strlen(pipeline_use_cycle_mask) + (int)strlen(pipeline_use_element) +\n     (cyclemasksize * 12) + masklen + (cycledigit * 2) + 30) * element_count;\n\n  // Allocate space for the resource list\n  const size_t resource_mask_size = templen;\n  char * resource_mask = new char [resource_mask_size];\n  char * last_comma = nullptr;\n\n  templen = 0;\n\n  for (pipeclass->_resUsage.reset();\n       (piperesource = (const PipeClassResourceForm*)pipeclass->_resUsage.iter()) != nullptr; ) {\n    int used_mask = pipeline->_resdict[piperesource->_resource]->is_resource()->mask();\n\n    if (!used_mask) {\n      fprintf(stderr, \"*** used_mask is 0 ***\\n\");\n    }\n\n    resources_used |= used_mask;\n\n    uint lb, ub;\n\n    for (lb =  0; (used_mask & (1 << lb)) == 0; lb++);\n    for (ub = 31; (used_mask & (1 << ub)) == 0; ub--);\n\n    if (lb == ub) {\n      resources_used_exclusively |= used_mask;\n    }\n\n    int formatlen =\n      snprintf_checked(&resource_mask[templen], resource_mask_size - templen, \"  %s(0x%0*x, %*d, %*d, %s %s(\",\n        pipeline_use_element,\n        masklen, used_mask,\n        cycledigit, lb, cycledigit, ub,","sourceCodeStart":463,"sourceCodeEnd":499,"githubUrl":"https://github.com/openjdk/jdk/blob/88dfb74bbeefcf2b0aa11835183bcd949998fc8f/src/hotspot/share/adlc/output_c.cpp#L463-L499","documentation":"Printed by adlc's pipeline-adventure generator (output_c.cpp, pipeline_res_mask_initializer). For each resource a pipeline class uses, it looks up the resource's mask from the pipeline's resource description; if that mask is 0 the message is printed but generation continues, and the zero mask then skews the lb/ub bit scans (the loops at minimum find lb=0..31 range only if bits set — with mask 0, 'for (lb = 0; (used_mask & (1 << lb)) == 0; lb++);' actually runs off the end of the int, undefined behavior).","triggerScenarios":"A .ad file pipeline section where a resource referenced by a pipe class (resource usage in the instruction's ins_pipe pipe class definition) has an empty/zero mask — i.e. the resource was declared with no stage list, or the resource declaration 'resource <name>' carries no bits (e.g. declared with no functional-unit assignment).","commonSituations":"Writing a new pipeline model for a port; declaring resources in the 'resources' block of the pipeline description but forgetting to give them stage masks / functional unit bits; referencing an undeclared-shape resource from an ins_pipe class.","solutions":["Open the .ad file's pipeline description and find the resource named in the failing pipe class's resUsage","Give the resource a non-empty definition, e.g. resources( INS_FLAG='0:1' ) style bit assignments, so its mask is non-zero","If the resource is intentionally unused, remove it from the pipe class instead of leaving a zero-mask resource","Re-run the build and confirm adlc stderr no longer prints '*** used_mask is 0 ***'"],"exampleFix":"// before\npipe_class myPipe(...) %{ ...; myRes; %}\n// resources section declares: resource myRes; // no bits -> mask 0\n\n// after\nresources( MYRES='0:1' );\npipe_class myPipe(...) %{ ...; MYRES; %}","handlingStrategy":"validation","validationCode":"# Check every resource referenced by a pipe class is declared with bits in the\n# pipeline description; a quick audit before building:\n# 1) list resources used:  grep -oE 'resource [A-Za-z0-9_]+' <arch>.ad\n# 2) list declared masks:  grep -A3 'resources\\\\(' <arch>.ad\n# ensure every used name has a non-empty mask assignment","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep the resources(...) declaration and every pipe_class resource usage in the same edit set","Treat 'used_mask is 0' as fatal in CI (grep adlc stderr) because the subsequent bit-scan is undefined behavior","Model unused resources by deleting references, not by leaving zero masks"],"tags":["hotspot","adlc","pipeline-model","ad-file","codegen"],"backgroundTag":null,"analyzedSha":"88dfb74bbeefcf2b0aa11835183bcd949998fc8f","analyzedAt":"2026-08-14T11:45:09.665Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}