As Japan's construction firms are squeezed by the tightest labor market since the 1970s and a rapidly aging population, they are pouring investment into technology — and providing unexpected support to an economy reeling from the bitter U.S.-China trade war.

The industry sees artificial intelligence and robots — which can scurry around building sites day and night, preparing equipment and moving materials for the next day's construction — as a way to future-proof and close the labor gap.

But a side effect is that one of the country's least-productive sectors is bolstering capital expenditures even as the world's third-largest economy flirts with recession amid a global growth slowdown.