China's President Xi Jinping shakes hands with Japan's Prime Minister Shinzo Abe in Nov 10, 2014 during their meeting at the Great Hall of the People, on the sidelines of the Asia Pacific Economic Cooperation. Kim Kyung-Hoon-Pool | Getty Images

Chinese President Xi Jinping and Japanese Prime Minister Shinzo Abe have come a long way since their now-famous icy handshake in November 2014. That painfully awkward moment between the two leaders led to the creation of a cartoon meme. Yet it was a symbolic first step in a long — and so far successful — process of tamping down soaring tensions between the Asian economic giants. Now, they will be trying to keep that going when Xi heads to Japan on Thursday to meet Abe, ahead of the Group of 20 summit in Osaka this weekend. It will be the first visit to the country by a Chinese president since 2010. Analysts say reasons for the rapprochement include economic interdependence, a need to focus on the future and the emergence of an unforeseen wild card: the 2016 election of U.S. President Donald Trump, whose presence in Osaka looms large for both men. "The greatest impetus for warming Sino-Japanese relations is their realization that China and Japan need to cooperate with each other more closely in the face of their changing relations with the United States," Victor Teo, an assistant professor in the Department of Japanese Studies at the University of Hong Kong, told CNBC in an email. Japan is a loyal U.S. ally and the countries are tightly bound economically. But Abe is wary of Trump's protectionist "America First" tendencies and has — so far, at least — deftly avoided becoming a major tariff target. Not so Xi, who has been forced to fight back in a damaging trade war launched by the Trump administration.

Almost smiling

While Trump has provided Abe and Xi with reasons to move closer, the effort long predates his arrival. Already high bilateral tensions between China and Japan were spiraling higher just before the two Asian leaders took power, around the same time more than six years ago. The escalation was due in part to a simmering dispute over control of uninhabited islands in the East China Sea, which spilled into anti-Japanese protests in Chinese cities.

There are few countries equipped with Japan's credentials and connections to be able to mediate between China and the United States. Victor Teo assistant professor, University of Hong Kong

Ties remained rocky and were further inflamed in late 2013 when Abe, a staunch nationalist, visited a Tokyo shrine honoring Japan's war dead, including from World War II, which infuriated Beijing. China and Japan are major trade and investment partners. While they are also rivals for political and economic influence in the Asia-Pacific region and beyond, they have come to realize the need to work together, analysts say. A major step in the cooling off process was a wording compromise on the dispute over the small islands that both claim, but which are effectively controlled by Japan. That was immediately followed by the grim-looking leaders clasping hands in Beijing in November 2014 just ahead of the Asia-Pacific Economic Cooperation forum summit hosted by Xi. While neither side has given up its claims to those islands — and their ships and planes continue to play cat-and-mouse in the area — they have successfully lowered the temperature and avoided escalation. Japan's Abe too has refrained from further shrine visits. By the time Abe and Xi met in Vietnam in 2017, they were almost smiling, underscoring their steadily improving ties.

Chinese President Xi Jinping meets with Japanese Prime Minister Shinzo Abe in Da Nang, Vietnam, on Nov. 11, 2017. Xinhua | Lan Hongguang | Getty Images

"Our relations are back on a normal track," Chen Deming, a former Chinese commerce minister, declared in a speech in Tokyo last month, in wording that was similar to that used by Abe in January. Japan politics expert Brad Glosserman pointed out that there was a significant shift last year which highlighted their thawing ties: An agreement to cooperate in so-called third countries, such as those involved with China's massive Belt and Road infrastructure project and the Beijing-backed Asian Infrastructure Investment Bank (AIIB). "That's a really important development in so far as it changes thinking about innate hostility in both capitals towards each other," Glosserman, deputy director and visiting professor at the Center for Rule Making Strategies at Tama University in Tokyo, told CNBC. The Belt and Road and the AIIB, which finances transportation networks, power stations and other infrastructure, are key symbols of China's growing global stature. Japan, which has long backed the Manila-based Asian Development Bank, was initially wary of the Chinese initiatives but increasingly sees potential for opportunity. "I think that was really a key shift in the way that the Japanese were thinking and it was duly noted in China," said Glosserman, who is also a non-resident senior adviser at Honolulu-based think tank Pacific Forum. While Xi's G-20 attendance is not a state visit, it comes after Abe went to Beijing last year in another fresh milestone in their warming ties. This week's trip will also mark Xi's first to Japan since becoming Chinese president in March 2013.

US-China mediator?

China certainly won't be the only topic on Abe's mind. As host, he will be chairing a broad agenda of global economic issues while also tending to other key relationships, such as with Trump and Russian President Vladimir Putin. He will also be keeping a close watch on whether the U.S. and Chinese leaders can achieve a breakthrough in their trade conflict.